C/C++ need a clever way to track function calls(C/C++ 需要一种聪明的方法来跟踪函数调用)
问题描述
我正在寻找一种聪明的方法来跟踪函数调用和返回.我知道我可以使用调试器,但我想要一种方法,让它在调用函数而不是单步执行代码时将某些内容打印到终端.
我在想我也许可以使用预处理器,但我不确定最好的方法是什么.
或者有没有办法使用 gdb 打印出有用的信息,而不必单步执行代码.
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 compilers 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. A nice article: http://www.drdobbs.com/184403601.
在 GCC 中,您将使用 -finstrument-functions 选项,请参阅 文档.
In GCC you would use the -finstrument-functions option, see the docs.
您可以使用调试库或映射文件来获取更多信息.
You can use debug libaries or map files to get more info.
这篇关于C/C++ 需要一种聪明的方法来跟踪函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C/C++ 需要一种聪明的方法来跟踪函数调用
基础教程推荐
- 我有静态或动态 boost 库吗? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
