简体   繁体   English

使用gdb跟踪C ++中的函数调用

[英]Tracing function calls in C++ using gdb

I have a system developed in C++ on Linux platform. 我有一个在Linux平台上用C ++开发的系统。 I am doing some debugging of this system. 我正在对这个系统进行一些调试。 I want to look for the complete sequence of function calls to a function. 我想查找函数的完整函数调用序列。 Lets assume the functions are called in the following sequence 让我们假设函数按以下顺序调用

function_1 -> function_2 -> function_3 -> function_4

If I put a break point at function_4, the execution will be holded at that point. 如果我在function_4上设置了一个断点,那么执行将在那时保持。 I want to see that functions_1, function_2 and function_3 are called before function_4. 我想看看在function_4之前调用functions_1,function_2和function_3。 If there any gdb command to trace these function calls? 如果有任何gdb命令来跟踪这些函数调用?

Thanks, Ankur 谢谢,Ankur

You want a backtrace. 你想要一个回溯。 The gdb command bt will show exactly what you are interested in. gdb命令bt将准确显示您感兴趣的内容。

If function_1() calls function_2() which calls function_3() etc 如果function_1()调用function_2()调用function_3()等

You can set your breakpoint in function_4() and you use the command 您可以在function_4()中设置断点,然后使用该命令

where

To print a backtrace of the stack 打印堆栈的回溯

Another tool that may be useful is valgrind with the callgrind tool 另一个可能有用的工具是使用callgrind工具的valgrind

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM