gpt4 book ai didi

c - 用于调试信息的默认链接描述文件

转载 作者:行者123 更新时间:2023-11-30 19:34:12 26 4
gpt4 key购买 nike

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

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

最佳答案

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

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

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

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

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

关于c - 用于调试信息的默认链接描述文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44213981/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com