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

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

问题描述

我试图调试我在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
这是我的gdb会话的输出:

I compiled it using: g++ -g3 -O0 -o cards.exe cards.cpp. 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仍然进入功能?我使用g ++ 4.2.1-sjlj和gdb 6.8。

My question is, why does sending a next command to gdb still step into a function? I'm using g++ 4.2.1-sjlj and gdb 6.8.

推荐答案

步骤下一个命令每次工作一个源代码行,所以当一切都在一行上单个下一个直接到 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的step over功能(下一个)似乎不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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