CallPath lets you see all the paths your code take until a specified function,
in a particular execution. It does that running your code through gdb
,
parsing the output and feeding it to dot
. It was design to work with C code
but should work with any language supported by gdb
.
Note: If you want to see all possible paths, not only the ones found on a single execution, use gcc-callgraph-plugin, which performs a static analysis.
Certify that you have all the following tools installed and acessible at your
$PATH
:
- gdb
- dot (usually from the
graphviz
package) - ruby
Then, just place cpath
somewhere covered by your $PATH
. You may also need
to run chmod +x cpath
.
$ cpath [<options>] -b|--break func1[,func2,...] -r|--run '<command> [args]'
where:
-b|--break specifies a list of functions to backtrace
-r|--run specifies the command to run and its arguments
and the additional options are:
-v, --[no-]verbose Print progress messages (default)
-p, --[no-]print Print list of paths found at stdout (default)
-g, --[no-]graph Generate graph image at 'paths.png' using dot
-e, --redirect=FILENAME Redirect your command's output to FILENAME
-h, --help Show this message
The output of --print
will be a line for each path in the format:
A > B > ... > break_func (NUM)
Where NUM
represents how many times the path has occurred.
Don't forget to compile your code with -g
(or even better, with -g3
). Also,
you should use -O0
to disable compiler optimizations and have more reliable
callgraphs.