/callpath

CallPath lets you see all the paths your code take until a specified function.

Primary LanguageRubyGNU General Public License v2.0GPL-2.0

CallPath (or cpath)

CallPath lets you see all the paths your code take until a specified function. 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.

Dependencies and Installation

Certify that you have all the following tools installed and acessible at your $PATH:

  • gdb
  • dot
  • ruby

Then, just place cpath somewhere covered by your $PATH. You may also need to run chmod +x cpath.

Usage

$ 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.

Tips

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.