The Control Flow graph is an extremely powerful tool within Understand that can give you new insights into your codebase, and the ability to analyze it more accurately than you could with the lexer. The graph can now be customized using both the Perl and Python API's as of the release of Understand 6.1.
To get started with Perl (necessary if your build is older than 1086), start by downloading the Perl Flowchart from the Custom Graphs page – save it to the scitools\conf\plugin\users\Graph directory so it doesn’t get overridden by the next upgrade. Then open it in your code editor.
That logical control flow structure is obtained by calling $entity->freetext(“CGraph”). That command returns a series of numbers representing the different nodes of the graph. Each node is delimited by a semicolon and the series of numbers inside of those semicolons describe the node. These numbers can be seen in the regular graph by right clicking on an empty area and enabling debug. Note that some of the nodes are hidden by default so disable the filter option to see them.
The numbers can be interpreted as follows: The first number is the node ID. The second line contains the serialized representation of the node: The Node Kind(see the array @names for a list of all of the kinds, or see the table below), Start Line, Start Column, End Line, End Column. The sixth number, if non-empty, is the End Structure Node. All remaining numbers are the successors (or children) of the node.
Same graph with debug options and unfiltered
List of Node Kinds
If you have Understand 6.1, you can go ahead and access the Control Flow Graph using the built-in Python API methods.
Simply call Understand.ent().control_flow_graph() to generate a CFGraph object for an entity. Note that only certain entities are supported, and if no control information is known then None will be returned.
Once you have your Control Flow Graph object, you can call CFGraph.nodes() to return a list of all nodes in the graph, or CFGraph.start() to return just the starting node of the graph.
From your node, there are many ways to navigate the graph or access information about the node, again using the built-in API functions. Here are a few examples:
cfnode.column_begin() will return the beginning file column of the node, or None if there is no location information for it.
cfnode.kind() will return the kind of the node, which can be any of the node kinds listed above
cfnode.children() will return the children of the given node, provided as a list of CFnode objects
For a complete list of the Control Flow Graph methods available with the API, please refer to the PDF attached.