GDB超越功能(下一个)似乎不起作用 [英] GDB step over function (next) doesn't seem to work

查看:99
本文介绍了GDB超越功能(下一个)似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调试用C ++编写的程序.这是代码:

I'm trying to debug a program I wrote in C++. Here is the code:

void a() { }
void b() { a(); }
int main() { b(); return 0; }

我使用g++ -g3 -O0 -o cards.exe cards.cpp对其进行了编译.

I compiled it using: g++ -g3 -O0 -o cards.exe cards.cpp.

这是我的GDB会话的输出:

Here is the output of my GDB session:

(gdb) b main
Breakpoint 1 at 0x401421: file cards.cpp, line 10.
(gdb) r
Starting program: C:\workspace\Cards\src/cards.exe
[New thread 1624.0xa28]
Breakpoint 1, main () at cards.cpp:10
10    int main()
(gdb) n
12        b();
(gdb) n
b () at cards.cpp:5 5
void b()
(gdb) n
7        a();
(gdb) quit
The program is running.  Exit anyway? (y or n)

为什么向GDB发送下一条命令仍然会进入功能?

Why does sending a next command to GDB still step into a function?

我正在使用g ++ 4.2.1-sjlj和GDB 6.8.

I'm using g++ 4.2.1-sjlj and GDB 6.8.

推荐答案

stepnext命令一次运行一个源代码行,因此当所有内容全部都在一行上时,单个next就可以使我正确到main()的末尾.

The step and next commands work one source line at a time, so when everything is all on one line a single next takes me right to the end of main().

3   int main() { b(); return 0; }
(gdb) n
0x00001faa in start ()

代码格式化得不太密集,我仍然看不到您看到的结果.我将函数调用放在单独的行上,以使gdb一次跨过它们.这就是我得到的:

With the code formatted less densely I still do not see the results you see. I put the function calls on separate lines to get gdb to step over them one at a time. Here's what I get then:

jkugelman$ cat cards.cpp
void a() {
}

void b() {
    a();
}

int main() {
    b();
    return 0;
}
jkugelman$ g++ -g3 -O0 -o cards cards.cpp
jkugelman$ gdb ./cards
GNU gdb 6.3.50-20050815 (Apple version gdb-960) (Sun May 18 18:38:33 UTC 2008)
<snip>
Reading symbols for shared libraries .... done

(gdb) b main
Breakpoint 1 at 0x1ff2: file cards.cpp, line 9.
(gdb) r
Starting program: /Users/jkugelman/Development/StackOverflow/cards 
Reading symbols for shared libraries +++. done

Breakpoint 1, main () at cards.cpp:9
9       b();
(gdb) n
10      return 0;
(gdb) n
11  }
(gdb) n
0x00001faa in start ()

我没有答案,但我只想分享一下gdb在我的iMac上的预期行为.无论哪种情况,gdb都将对b()的调用视为一条指令,而从未输入函数调用.

I don't have an answer, but I just wanted to share that gdb behaves as expected on my iMac. In either case gdb treated the call to b() as one instruction and never entered the function call.

这篇关于GDB超越功能(下一个)似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆