2017-05-27 41 views
-1

我正在尝试使用gdb进行调试。当我使用无选项编译下面的代码时,gdb指出没有找到调试符号。用于调试信息的默认链接描述文件

int main() 
{ 
    return 0; 
} 

$gcc debug.c 
$gdb a.out 
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1 
Copyright (C) 2016 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 "i686-linux-gnu". 
Type "show configuration" for configuration details. 
For bug reporting instructions, please see: 
<http://www.gnu.org/software/gdb/bugs/>. 
Find the GDB manual and other documentation resources online at: 
<http://www.gnu.org/software/gdb/documentation/>. 
For help, type "help". 
Type "apropos word" to search for commands related to "word"... 
Reading symbols from a.out...(no debugging symbols found)...done. 
(gdb) quit 

但是,当我给-g国旗gcc,以下输出看到:

GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1 
Copyright (C) 2016 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 "i686-linux-gnu". 
Type "show configuration" for configuration details. 
For bug reporting instructions, please see: 
<http://www.gnu.org/software/gdb/bugs/>. 
Find the GDB manual and other documentation resources online at: 
<http://www.gnu.org/software/gdb/documentation/>. 
For help, type "help". 
Type "apropos word" to search for commands related to "word"... 
Reading symbols from a.out...done. 
(gdb) Quit 
(gdb) quit 

如何弄清楚什么是错的,看看链接器启用的调试信息剥离某处?

+2

我们需要完整的构建跟踪(编译器+链接器)和/或使用的命令行/ makefile。 –

+0

我不明确使用任何makefile – anushka

回答

0

这里没有涉及剥离,因为首先没有调试包含。

-g选项是需要来启用调试信息。

默认情况下(不使用任何选项),调试信息嵌入到目标文件

所以,正确的做法是:让-g告诉编译器嵌入调试符号,否则他们不包括和gdb没有找到它们。

(是的,另一种方式,以避免调试器来发现它们是通过-Wl,--strip-debug给连接器,但那是另一回事)

0

但是,当我给-g国旗gcc,下面的输出所示:

Reading symbols from a.out...done.

这就是你当gdb读取调试符号没有错误的输出。它成功了,那时调试器已经准备好告诉它在哪里放置断点并运行正在调试的程序。