gdb不显示非剥离的可执行文件的源代码。

时间:2021-03-06 02:28:01

I am working on a project and it seems I am unable to debug my code. First I thought it was a configuration error in my IDE (Eclipse), but then it turned out it is not working at all, not even with gdb for such a single program like below.

我正在做一个项目,似乎我无法调试我的代码。首先,我认为这是我的IDE (Eclipse)中的配置错误,但后来发现它根本就不工作,即使是gdb这样的单一程序也不行。

test.c

test.c

void main() {
  int a=1;
  int b=2;
  int c=3;
  a=b+2; // line 5: breakpoint is set here
  c=a+b;
  b=c+3;
  return;
}

user@mycomputer:/home/user/test$ gcc -g -O0 -c test.c
user@mycomputer:/home/user/test$ gcc -g -O0 test.o -o test
user@mycomputer:/home/user/test$ gdb test
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/user/test/test...done.

(gdb) b test.c:5
Breakpoint 1 at 0x4004e9: file test.c, line 5.

(gdb) run
Starting program: /home/user/test/test 
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000

Breakpoint 1, 0x00000000004004e9 in main ()

(gdb) step
Single stepping until exit from function main,
which has no line number information.
0x00007ffff7a3b76d in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6

(gdb) step
Single stepping until exit from function __libc_start_main,
which has no line number information.
[Inferior 1 (process 3306) exited with code 011]

Do you have any idea what goes wrong here? Why am I unable to see the source line where I put the breakpoint? Why won't gdb show the source line being run when using step? Also why would it exit the program at the second step command? It should still be at b=c+3 line!

你知道这里出了什么问题吗?为什么我不能看到我放断点的源行?为什么gdb不显示使用步骤时的源行?为什么它会在第二步命令中退出程序?应该还是在b=c+3行!

I have checked and the debug symbols are indeed in the executable.

我已经检查了,调试符号确实在可执行文件中。

user@mycomputer:/home/user/test$ file test
test: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x37bb8d43d3a8394ce3bb9031e1e090d6c6d5aea7, not stripped

I have gcc 4.8.1 and gdb 7.4-2012.04.

我有gcc 4.8.1和gdb 7.4-2012.04。

1 个解决方案

#1


3  

What you observe pretty clearly appears to be a bug in GDB:

你观察到的很明显是GDB中的一个bug:

(gdb) b test.c:5
Breakpoint 1 at 0x4004e9: file test.c, line 5.

Here GDB clearly knows that debug symbols are present, and that address 0x4004e9 corresponds to line 5 of test.cc. But when the breakpoint is actually hit:

这里GDB清楚地知道调试符号是存在的,地址0x4004e9对应于test.cc的第5行。但当断点实际上被击中时:

Breakpoint 1, 0x00000000004004e9 in main ()

somehow GDB forgot what it knew just moments ago (assuming you didn't replace ./test between setting the breakpoint and running the binary).

某种程度上,GDB忘记了刚才所知道的(假设您没有替换。/在设置断点和运行二进制文件之间进行测试)。

Since gdb 7.4-2012.04 is pretty old, the first thing to do is try to update it (perhaps build gdb-7.6 from source) and see if the problem persists.

因为gdb 7.4-2012.04很老,所以要做的第一件事就是尝试更新它(也许从源代码构建gdb-7.6),看看问题是否还在继续。

If it does, file a bug in GDB bugzilla, and attach your binary to that bug.

如果是这样,在GDB bugzilla中提交一个bug,并将二进制文件附加到该bug上。

#1


3  

What you observe pretty clearly appears to be a bug in GDB:

你观察到的很明显是GDB中的一个bug:

(gdb) b test.c:5
Breakpoint 1 at 0x4004e9: file test.c, line 5.

Here GDB clearly knows that debug symbols are present, and that address 0x4004e9 corresponds to line 5 of test.cc. But when the breakpoint is actually hit:

这里GDB清楚地知道调试符号是存在的,地址0x4004e9对应于test.cc的第5行。但当断点实际上被击中时:

Breakpoint 1, 0x00000000004004e9 in main ()

somehow GDB forgot what it knew just moments ago (assuming you didn't replace ./test between setting the breakpoint and running the binary).

某种程度上,GDB忘记了刚才所知道的(假设您没有替换。/在设置断点和运行二进制文件之间进行测试)。

Since gdb 7.4-2012.04 is pretty old, the first thing to do is try to update it (perhaps build gdb-7.6 from source) and see if the problem persists.

因为gdb 7.4-2012.04很老,所以要做的第一件事就是尝试更新它(也许从源代码构建gdb-7.6),看看问题是否还在继续。

If it does, file a bug in GDB bugzilla, and attach your binary to that bug.

如果是这样,在GDB bugzilla中提交一个bug,并将二进制文件附加到该bug上。