@weixin
        
        2015-04-17T22:41:07.000000Z
        字数 2567
        阅读 1533
    compileon mac, the gdb has been replaced with lldb, here is some debug tips.
I wrote a file for command aliases, here is the script:
command alias bfl breakpoint set -f %1 -l %2bfl main.c 21
then start program :
lldb --source br_aliases crowbar test2.crb
--source would specify which file would be used.
There is a very good tool for c code static analysis - doxygen 
here is the webiste : doxygen, just follow the instruction, compile and install it. the path would be /usr/local/bin/doxygen.
doxygen -g crowbar_config , crowbar_config is the doxygen configure file, it would generate a template config file.
CALL_GRAPH = YESCALLER_GRAPH = YESRECURSIVE = YESEXTRACT_ALL = YESEXTRACT_STATIC = YESOUTPUT_DIRECTORY= ./call_graph
I make a directory named call_graph for holding all the doucments doxygen generated. be aware that you need dot, ie , graphviz as prerequsite. 
doxygen crowbar_config to generate documents.  
 
 for linux user, there are some choices, such as gprof, codeviz and ncc, egypt, etc. but most of them are gnu based. on my mac, it is clang compiler so those tool could not be used. I tried to install egypt but failed, don't want to spend much time on it. so I choose use the osx instruments directly.

 
this is also a good tool for analysis the code.
instrument.c into the projectinstrument.o ,  
util.o\ 
native.o\ 
instrument.o\ 
error.o\ 
 
#CFLAGS = -c -g -Wall -Wswitch-enum -ansi -pedantic -DDEBUG 
CFLAGS = -c -g -finstrument-functions -Wall -Wswitch-enum -ansi -pedantic -DDEBUG 
 -finstrument-functions flag./crowbar test/test.crb, then a file trace.txt would be generated, in this file, all the function enter and leave address is recorded.pvtrace crowbar, in fact, pvtrace call addr2line to find the symbol line # . unfortunately, mac doesn't have addr2line, the alternative atos doens't work. so I have to use vmware to start an opensuse box. a file, graph.dot would be generated.dot -Tpng graph.dot -o graph.png to generate a png file. it looks like this : 