【问题标题】:default linker script for debugging information用于调试信息的默认链接描述文件
【发布时间】:2017-10-28 01:55:11
【问题描述】:

我正在尝试使用 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

但是当我用gcc 给出-g 标志时,会看到以下输出:

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

如何找出问题所在并查看链接器是否在某处启用了调试信息的剥离?

【问题讨论】:

  • 我们需要完整的构建跟踪(编译器+链接器)和/或使用的命令行/makefile。
  • 我没有明确使用任何makefile

标签: c debugging gcc default ld


【解决方案1】:

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

-g 选项是必需以启用调试信息。

默认情况下(没有任何选项),调试信息嵌入到目标文件中

所以正确的做法是:启用-g 告诉编译器嵌入调试符号,否则不包括在内,gdb 找不到它们。

(是的,避免调试器找到它们的另一种方法是将-Wl,--strip-debug 传递给链接器,但这是另一回事)

【讨论】:

    【解决方案2】:

    但是当我用gcc 给出-g 标志时,会看到以下输出:

    Reading symbols from a.out...done.

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

    【讨论】:

      猜你喜欢
      • 2015-04-25
      • 1970-01-01
      • 2019-12-13
      • 1970-01-01
      • 2014-12-13
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 2018-11-15
      相关资源
      最近更新 更多