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

时间:2014-01-12 21:09:15

标签: linux debugging gcc gdb

我正在开发一个项目,似乎我无法调试我的代码。首先我认为这是我的IDE(Eclipse)中的配置错误, 但后来事实证明它根本不起作用,即使是像下面这样的单一程序的gdb也没有。

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]

你知道这里出了什么问题吗?为什么我无法看到我放置断点的源代码行? 为什么gdb在使用step时不显示正在运行的源代码行? 为什么它会在第二步命令退出程序?它仍然应该在b = c + 3行!

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

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

我有gcc 4.8.1和gdb 7.4-2012.04。

1 个答案:

答案 0 :(得分:3)

你很清楚地看到GDB中的一个错误:

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

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

Breakpoint 1, 0x00000000004004e9 in main ()

某种程度上GDB忘记了它刚刚知道的事情(假设你没有在设置断点和运行二进制文件之间替换./test。)

由于gdb 7.4-2012.04已经过时了,首先要做的是尝试更新它(可能是从源代码构建gdb-7.6)并查看问题是否仍然存在。

如果是,请在GDB bugzilla中提交错误,并将二进制文件附加到该错误。