C and C++ Binaries

Description: Control Flow Graph (CFG)

CodeSonar can construct control flow graphs (CFGs). With these graphs enabled, you can navigate through a program's control flow structure as well as its dependence structure.



Overview

The sequential flow of control through the program is represented by control-flow edges (CFG_EDGE) between points (PDG_VERTEX), a structure known as a control flow graph, or CFG for short.

For example, consider the following example program and its corresponding CFG (with printf() calls collapsed to 'print' points).

/* Return a+b */
static int add(int a, int b){
    return a + b;
}

/* Sum 0 through 10. */
void main()
{
    int sum, i;
    sum = 0;
    i = 1;
    while ( i<11 ) {
        sum = add(sum, i);
        i = add(i, 1);
    }
    printf("sum = %d\n", sum);
    printf("i = %d\n", i);
}
Control-Flow Graph for Sample Program

API Functionality

Intraprocedural and Interprocedural CFGs

Each function is associated with an intraprocedural CFG that models control flow between points strictly within the function based on the assumption that all function calls are atomic operations.

The inter-procedural CFG is a single graph that models the control flow between points in the entire project.

Control-Flow Edge

Edges in the CFG are called control flow edges.

Language CFG Edges from a point Types
Intraprocedural Interprocedural CFG Edge CFG Edge Set
C++ point::cfg_targets() point::cfg_inter_targets() typedef cfg_edge class cfg_edge_set
Python point.cfg_targets() point.cfg_inter_targets() pair (point, edge_label) class cfg_edge_set
C cs_pdg_vertex_cfg_targets() cs_pdg_vertex_cfg_inter_targets() typedef cs_cfg_edge typedef cs_cfg_edge_set, typedef cs_const_cfg_edge_set

Example CFGs

Example C/C++ CFGs are provided in section Control Flow Graphs for C/C++ Programs.

Links

See also: