Skip to main content

function call flow tool for C


1. tceetree (http://sourceforge.net/p/tceetree/wiki/Home/)

tceetree could be useful for you when:
  • you have the sources of an application written in C language;
  • you would like to have a graphical representation of the entire or partial function call tree.
If this is what you are looking for, follow these steps:
  1. Install (and compile) CScope. A compiled Windows executable can be found here. For a compiled Linux executable search the Web e.g. for a cscope RPM or Debian package.
  2. Install Graphviz.
  3. Go to your sources root directory and do:
    • under Windows: dir /B /S *.c > cscope.files (/B = bare format, no extra info);
    • under Linux: find . -name '*.c' > cscope.files;
      that will recurse subdirectories and list all C files in cscope.files.
  4. execute cscope -b -c -R (build the cross reference only, don't compress it, recurse);
  5. run tceetree with cscope.out as input (default) to get tceetree.out (DOT language representation of function call tree);
  6. execute dot -Tpng -O tceetree.out to get a graphical representation of the tree in tceetree.out.png.
There are a lot of options you can specify when invoking dot to customize the graph, for example:
  • you can change output format e.g. to pdf: dot -Tpdf -O tceetree.out;
  • you may modify layout from left to right instead of top to bottom: dot -Grankdir=LR -Tpng -O tceetree.out;
  • you may modify graph, nodes and edges font: dot -Gfontname=Helvetica -Nfontname=Helvetica -Efontname=Helvetica -Tpng -O tceetree.out;
  • see dot.1.pdf and dotguide.pdf within Graphviz documentation for many other options.
You may wish to give a try to one of the other tools provided by Graphviz instead of dot (see dot.1.pdf for a list).
This is the synopsis of tceetree:
tceetree [-c <depth>] [-C <depth>] [-d <file>] [-f] [-F] [-h] [-i <file>] [-o <file>] [-p <function>] [-r <root>] [-s <style>] [-v] [-V] [-x <function>]
OptionDescription
-c <depth>Depth of tree for called functions: default is max. Depth is measured starting from root(s) function(s).
-C <depth>Depth of tree for calling functions: default is 0. Depth is measured starting from root(s) function(s) in backward direction.
-d <file>Output a shortened cscope output file: default is no output. The shortened file includes only function information and can be used as input (-i) for following calls to tceetree to increase speed on big projects.
-fPrint the file name where the call is near to branch.
-FGroup functions into one cluster for each source file.
-hPrint help.
-i <file>Input cscope output file: default is cscope.out.
-o <file>Output file for graphviz: default is tceetree.out.
-p <function>Highlight call path till function. Path starts from root(s) till the specified function (only one), in backward or forward direction.
-r <root>Root function of tree: default is main. This option may occur more than once for multiple roots (max 5).
-s <style>Style for highlight call path: 0 = red color (default); 1 = blue color; 2 = green color; 3 = bold; 4 = dashed; 5 = dotted.
-vPrint version.
-VVerbose output (mainly for debugging purposes).
-x <function>Function to be excluded from tree. This option may occur more than once for multiple functions (max 20). -x LIBRARY is a special case for excluding all library functions, i.e. not found defined in any file. All the functions, called (calling) directly or indirectly from the excluded one(s) only, will be excluded too.
tceetree can be called with no option at all: default options will be used.
Examples:
  • Screenshot #1 was done with tceetree -F -x LIBRARY;
  • screenshot #2 was done with tceetree -C max -r gettree -p ttreefindnode.

2. cflow (http://www.gnu.org/software/cflow/)

# cflow main.c
# cflow -d 10 main.c
# cflow -m StartFunction main.c

-d : depth
-m : start function name

Comments

Popular posts from this blog

Redmine production.log to uri log

But.. It doesn't work well. (Because the sequence of line is not arranged.) It is better way to use ' redmine_access_logger' plugin than this #!/bin/bash # Setting LOG_FILE=/redmine-3.3.3/log/production.log #LOG_FILE=mylog.log PIDFILE=/var/run/redmine_info_log.pid # Program Variables OUTPUT_LOGDIR=`dirname ${LOG_FILE}` OPT_DEBUG=0 URI_FILTER_REGEX="(^\"/people/avatar)|(^/attachments/thumbnail/)|(^\"/issues/.*\.xml)" function echo_log() { if [ "$2" != "" ]; then echo "$1" >> $2 else echo "$1" fi } if [ -f $PIDFILE ] then PID=$(cat $PIDFILE) ps -p $PID > /dev/null 2>&1 if [ $? -eq 0 ] then echo "Process already running" exit 1 else ## Process not found assume not running echo $$ > $PIDFILE if [ $? -ne 0 ] then echo "Could not create PID file" exit 1 fi fi else echo $$ > $PIDFILE if [ $? -ne 0 ] ...

[scapy] Linux-Cooked pcap to ethernet

# The pcap file formatted by "Linux cooked" # tcpdump -r myfile.pcap -nn reading from file event1.pcap, link-type LINUX_SLL (Linux cooked) ... ... # step1. read myfile.pcap pkts = rdpcap("myfile.pcap"); # step2. read myfile.pcap pkts = [Ether(src='00:11:22:33:44:55', dst='22:33:44:55:66:77')/pkt[1:] for pkt in pkts] # step3. modify IP address and recalculate chksum for pkt in pkts:  pkt[1].dst='192.168.1.10';  pkt[1].src='192.168.1.1';  del pkt[IP].chksum  del pkt[UDP].chksum # step4. packet send sendp(pkts[0]); # step5. save pcap  wrpcap("output.pcap",pkts); # tcpdump -r output.pcap -nn reading from file output.pcap, link-type EN10MB (Ethernet) ... ... # pkt[1:] : It means IP layer 1) Before: Linux cooked / IP / UDP / UDP-Data 2) After: Ethernet / IP / UDP / UDP-Data

sanitize on in CMakeLists.txt

1. CMakeLists.txt set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") add_compile_options(-fsanitize=address) If a subdir is set with add_subdirectory and a module that does not support sanitize is imported from the path and needs to be removed, add -fno-sanitize=address to add_compile_options in CMakeLists.txt of the subdir to remove it. Basically, if you enable sanitize, sanitize will adjust ulimit's core to 0, so core will not occur. You can do this by putting the following part as an environment variable. (Below is the part you put in systemd's service) 2. service file in systemd [Service] LimitCORE=infinity Environment="ASAN_OPTIONS=handle_segv=0:handle_abort=1:abort_on_error=1:disable_coredump=0"