我们如何在GDB中跳过一个函数调用?

10
我想要了解如何跳过函数调用。例如,考虑以下程序:
 #include <iostream>
 #include "test.h"

 using std::cout;
 using std::endl;

 Uint u;

 int main()
 {
     cout << "execution starting..." << endl;
     cout << u.a << endl;
     cout << "execution completed" << endl;
 }

在GDB中,我在第11行设置了一个断点(cout << "execution starting..." << endl;),使用break 11
现在我想跳过所有将被调用来打印"execution starting..."的指令,并在打印endl符号的<<运算符调用处停止。
我应该如何做?我应该使用哪个命令?

2
下一个 [count]。这类似于step,但是出现在代码行中的函数调用会被执行而不会停止。https://sourceware.org/gdb/current/onlinedocs/gdb/Continuing-and-Stepping.html#Continuing-and-Stepping - Richard Critten
2个回答

15
在GDB中,step表示步入(将进入被调用的函数),而next表示步过(继续执行并停在下一行)。
但在您的特定情况下,next可能不是您想要的,我建议首先使用打印“execution starting…”的函数进行step,然后使用finish继续执行直到返回,这样程序将停在<< endl处。

1
如果您设置了断点,那么只需使用continue继续执行直到达到该断点。除非您想要完全跳过这些调用,那么您只需将$eip$rip设置为您断点的地址,例如: set $[e|r]ip=0x[your_address]

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接