linux - 为什么不带 "not stripped, with debug_info"选项的可执行文件file命令在编译时报 "-g"?

标签 linux gdb archlinux debug-symbols

我的操作系统是Arch Linuxtest.c程序很简单:

# cat test.c
#include <stdio.h>

int main(void) {
        printf("Hello world!\n");
}

不带-g选项编译,使用file命令查看可执行文件信息:

# gcc test.c
# file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=c7a538046222b5209d2daafbfc246de341a652d9, not stripped, with debug_info

file 命令输出“not stripped, with debug_info”,但我在编译期间没有使用 -g 选项。使用gdb调试a.out:

# gdb a.out
GNU gdb (GDB) 7.12.1
Copyright (C) 2017 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-pc-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)

我可以看到 gdb 还提示“Reading symbols from a.out...(no debugging symbols found)...done.”。

为什么file命令在编译过程中报告“not stripped, with debug_info”没有“-g”选项的可执行文件?

最佳答案

Why does file command report "not stripped, with debug_info" of the executable file without "-g" option during compilation?

您的程序链接到 libc_nonshared.a 的部分(例如,c 运行时启动 ctr0.o),其中可能包含一些调试信息。

您可以看到可用的调试信息并猜测它来自哪里:

readelf -wl ./a.out

关于linux - 为什么不带 "not stripped, with debug_info"选项的可执行文件file命令在编译时报 "-g"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43181336/

相关文章:

c++ - 版本 `CXXABI_1.3.8' 未找到(...需要)

documentation - 在哪里可以找到有关早期版本 GDB 的文档?

linux - Linux 上的完整 tar 备份,不包括某些根文件夹

c++ - 如何在函数返回的 GDB 中设置断点?

c - 结构成员上的 free() 仅在调试中导致 Hardfault

archlinux - 使 yaourt 始终对某些包使用 ABS

lua - 很棒的 wm/恶意小部件 : using a format function throws a bad argument error

regex - 使用 Linux 控制台从文本文件创建 CSV

linux - 从 Bash 输出中隐藏 "Directory and Bash Directory"

linux - 如何使用uniq命令进行排序以删除第一个字符和后面的n个字符