2017-04-03 168 views
0

我的操作系統是Arch Linux,而test.c程序很簡單:爲什麼在編譯期間文件命令報告「沒有剝離,帶有debug_info」的可執行文件沒有「-g」選項?

# 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」選項?

+0

仍然是最小的信息,可用於調試(全局函數和變量名)。您可以使用strip命令刪除它們。 –

回答

0

爲什麼在編譯期間文件命令報告「沒有剝離,帶debug_info」的可執行文件沒有「-g」選項?在libc_nonshared.a(例如C運行時啓動ctr0.o),其可以含有一些調試信息的部件

你的程序的鏈接。

你可以看到調試信息可用,並猜測它與傳來:

readelf -wl ./a.out 
+1

'readelf -wl。/ a.out'不輸出任何內容。 –

相關問題