C / C ++需要一个聪明的方法来跟踪函数调用 [英] C/C++ need a clever way to track function calls
问题描述
我要寻找一个聪明的方法来跟踪功能调用和返回。
我知道我可以使用调试器,但我想一个办法,只是有它打印出来的东西要调用一个函数VS不必步code的终端。结果
我在想,我也许能使用preprocessor,但我不知道什么是去对此的最佳途径。结果
或者是有使用gdb输出,将是有用的信息,而不必以逐步code的一种方式。
I am looking for a clever way to track function calls and returns.
I know I can use the debugger, but I would like a way to just have it print something out to the terminal when calling a function vs having to step through code.
I am thinking that I might be able to use the preprocessor, but I am not sure what would be the best way to go about this.
Or is there a way to use gdb to print out the information that would be useful, while not having to step through the code.
推荐答案
大多数编译器允许你之前和函数调用后注入的仪表功能。
Most compiler's allow you to inject an instrumentation function before and after the function call.
在MSVC他们_penter和_pexit结果
好文章
http://www.drdobbs.com/184403601
in msvc they are _penter and _pexit
nice article
http://www.drdobbs.com/184403601
在GCC你可以使用-finstrument函数结果
<一href=\"http://gcc.gnu.org/onlinedocs/gcc-4.4.4/gcc/$c$c-Gen-Options.html\">http://gcc.gnu.org/onlinedocs/gcc-4.4.4/gcc/$c$c-Gen-Options.html
in gcc you would use the -finstrument-functions
http://gcc.gnu.org/onlinedocs/gcc-4.4.4/gcc/Code-Gen-Options.html
您可以使用调试libaries或映射文件,以获得更多信息。
You can use debug libaries or map files to get more info.
这篇关于C / C ++需要一个聪明的方法来跟踪函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!