gdb 在 Centos 上找不到调试信息
gdb can not find debug info on Centos
我想弄清楚一个非常奇怪的问题。我有 CentOS 6.5 系统 gdb:
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-75.el6)
和 gcc:
gcc (GCC) 4.8.2 20131212 (Red Hat 4.8.2-8)
我有这个文件:
#include<stdio.h>
int main()
{
printf("OK!");
return 0;
}
我用它编译:
gcc -o a a.c -g -O0
文件似乎没问题:
$ file a
a: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
但是当我尝试调试它时,发生了这种情况:
$ gdb a
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-75.el6)
Copyright (C) 2010 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from a...done.
(gdb) b main
Breakpoint 1 at 0x4004e4
(gdb) r
Starting program: a
Breakpoint 1, 0x00000000004004e4 in main ()
(gdb) l
1 /* Run time dynamic linker.
2 Copyright (C) 1995-2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
(gdb) l main
No line number known for main.
也就是说,gdb 拒绝查看任何调试信息。任何人都知道这里可能有什么问题?
你的 GDB 已经很旧了。您的 GCC 相当新。
我怀疑您的 GCC 正在发出 DWARF4
调试信息(根据 release notes,默认为 gcc-4.8),您的 GDB 无法识别。
-gdwarf-2
比 -g
效果更好吗?
如果是这样,请升级您的 GDB 或使用此编译器 -gdwarf-2
。
我想弄清楚一个非常奇怪的问题。我有 CentOS 6.5 系统 gdb:
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-75.el6)
和 gcc:
gcc (GCC) 4.8.2 20131212 (Red Hat 4.8.2-8)
我有这个文件:
#include<stdio.h>
int main()
{
printf("OK!");
return 0;
}
我用它编译:
gcc -o a a.c -g -O0
文件似乎没问题:
$ file a
a: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
但是当我尝试调试它时,发生了这种情况:
$ gdb a
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-75.el6)
Copyright (C) 2010 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from a...done.
(gdb) b main
Breakpoint 1 at 0x4004e4
(gdb) r
Starting program: a
Breakpoint 1, 0x00000000004004e4 in main ()
(gdb) l
1 /* Run time dynamic linker.
2 Copyright (C) 1995-2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
(gdb) l main
No line number known for main.
也就是说,gdb 拒绝查看任何调试信息。任何人都知道这里可能有什么问题?
你的 GDB 已经很旧了。您的 GCC 相当新。
我怀疑您的 GCC 正在发出 DWARF4
调试信息(根据 release notes,默认为 gcc-4.8),您的 GDB 无法识别。
-gdwarf-2
比 -g
效果更好吗?
如果是这样,请升级您的 GDB 或使用此编译器 -gdwarf-2
。