Understand软件的功能主要定位于代码的阅读理解。界面用Qt开发的。
一:具备如下特性: 1、支持多语言:Ada, C, C++, C#, Java, FORTRAN, Delphi, Jovial, and PL/M ,混合语言的project也支持 2、多平台: Windows/Linux/Solaris/HP-UX/IRIX/MAC OS X 3、代码语法高亮、代码折迭、交叉跳转、书签等基本阅读功能。 4、可以对整个project的architecture、metrics进行分析并输出报表。 5、可以对代码生成多种图(butterfly graph、call graph、called by graph、control flow graph、UML class graph等),在图上点击节点可以跳转到对应的源代码位置。 6、提供Perl API便于扩展。作图全部是用Perl插件实现的,直接读取分析好的数据库作图。 7、内置的目录和文件比较器。 8、支持project的snapshot,并能和自家的TrackBack集成便于监视project的变化。二:用understand获取函数调用关系:
use Understand; $db = Understand::open("newtank.udb"); foreach $method ($db->ents("Method")) { foreach $references ($method->refs("Call","Method")){ print $references->kind->longname()." ".$method->name()." ".$references->ent()->name()."\n"; } }
三:understand修改flowchart来获取函数控制流:
use base ("Understand::Graph::Gv");use Understand::Flowchart;use strict;sub name { return "Control Flow"; }sub description { return "A plugin for generation of simple flowcharts.";}sub test_entity { my $entity = shift; my $result = isValidFlowchartEntity($entity); return $result ? 1 : -1;}sub test_global { return -1; }sub init { my $graph = shift; $graph->options->define("Collapse", ["On", "Off"], "On"); $graph->options->define("Display Preceding Comments",["Off","IF Statements","On","On With Code"],"Off"); $graph->options->define("Display Assembly",["On","Off"],"Off"); $graph->options->define("Display Entity Name",["On","Off"],"Off"); $graph->options->define("Overview Mode",["On","Off"],"Off"); $graph->options->define("Macro Expansion",["Off","On (\"Save Macro Expansion Text\" must be enabled)"],"Off");}sub do_load { my $g = shift; my $entity = shift; my $expandmacros = $g->options->lookup("Macro Expansion") ne "Off"; my $collapse = $g->options->lookup("Collapse") eq "On"; my $comment_conditional = $g->options->lookup("Display Preceding Comments") eq "IF Statements"; my $allComments = $g->options->lookup("Display Preceding Comments") eq "On"; my $codeAndComments = $g->options->lookup("Display Preceding Comments") eq "On With Code"; my $displayAsm = $g->options->lookup("Display Assembly") eq "On"; my $overviewMode = $g->options->lookup("Overview Mode") eq "On"; $g->default("shape", "box", "node"); $g->default("color", "blue", "node"); $g->default("color", "black", "edge"); $g->default("style", "solid", "edge"); my @nodes = createFlowchart($entity,$expandmacros,$collapse); open CONTROLFLOW,">D:/controlflow.txt"; my @graphNodes; my @nodehash; #Draw the nodes foreach my $node(@nodes){ my $nodeid = $node->get("id"); my $startName = $nodeid eq 0 && $g->options->lookup("Display Entity Name") eq "On"; my $graphNode = $g->node($nodeid); $graphNode->sync($node->get("file_ent"), $node->get("line"), 0); #Node Text my $text = $node->get("label") ; $text .= "\n(".$entity->longname.")" if $startName; my $nodeComment = $node->get("comment"); if ($nodeComment){ $text = $nodeComment if $allComments; $text ="/*".$nodeComment."*/\n".$text if $codeAndComments; $text = $nodeComment if $comment_conditional && $node->get("type") eq "conditional"; } $text = "" if $overviewMode; $graphNode->set("label", $text); #Other node properties $graphNode->set("color", $node->get("color")) if $node->get("color"); $graphNode->set("shape", $node->get("shape")) if $node->get("shape"); $graphNode->set("color", "red") if $node->get("unreachable"); $graphNode->set("shape", "box") if $startName; $graphNodes[$nodeid] = $graphNode; $nodehash[$nodeid] = $node; } #Draw the edges foreach my $node(@nodes){ foreach my $edge ($node->edgeList()){ $source = $edge->get("source"); $target = $edge->get("target"); my $srcGraphNode = $graphNodes[$source]; my $targetGraphNode = $graphNodes[$target]; my $graphEdge = $g->edge($srcGraphNode, $targetGraphNode); $graphEdge->set("color",$edge->get("color")); $graphEdge->set("label",$edge->get("type")) unless $overviewMode; print CONTROLFLOW $nodehash[$source]->get("label")." ".$nodehash[$target]->get("label")."\n"; } } close HELLO; } 当用命令行运行函数的draw(“control flow”)方法时,内部调用上面这个文件,在D盘生成我们所需要的含有控制流信息的文件。