請教,在Linux上,如何知道一個可執行檔是否包含調試資訊呢?我的意思是是否該檔案是使用如gcc -g 這樣的參數編譯的。
2樓 發表於 2008-12-3 15:44
nm -a binary_file
3樓 發表於 2008-12-3 15:46
gdb試一下就知道了
4樓 發表於 2008-12-3 15:47
同意LS的,直接gdb測試一下就知道了。
5樓 發表於 2008-12-3 15:51
nm不太直觀
還是readelf比較好
readelf -S filename | grep debug
帶-g的會有.debug_info .debug_line等資訊
6樓 發表於 2008-12-3 15:55
man 1 file
7樓 發表於 2008-12-3 16:03
QUOTE:
原帖由 deadlylight 於 2008-12-3 15:51 發表
nm不太直觀
還是readelf比較好
readelf -S filename | grep debug
帶-g的會有.debug_info .debug_line等資訊
不使用-g的時候,也由於.debug_info和.debug_line。經過我的測試,一個Hello World的小程式,不帶-g編譯,readelf -S a.out | grep debug的輸出如下:
[26] .debug_aranges PROGBITS 00000000 000ba0 000078 00 0 0 8
[27] .debug_pubnames PROGBITS 00000000 000c18 000025 00 0 0 1
[28] .debug_info PROGBITS 00000000 000c3d 000236 00 0 0 1
[29] .debug_abbrev PROGBITS 00000000 000e73 000076 00 0 0 1
[30] .debug_line PROGBITS 00000000 000ee9 0001a4 00 0 0 1
[31] .debug_str PROGBITS 00000000 00108d 0000d3 01 MS 0 0 1
帶-g編譯後,eadelf -S a.out | grep debug的輸出如下:
[26] .debug_aranges PROGBITS 00000000 000ba0 000098 00 0 0 8
[27] .debug_pubnames PROGBITS 00000000 000c38 000040 00 0 0 1
[28] .debug_info PROGBITS 00000000 000c78 00695d 00 0 0 1
[29] .debug_abbrev PROGBITS 00000000 0075d5 000733 00 0 0 1
[30] .debug_line PROGBITS 00000000 007d08 00056c 00 0 0 1
[31] .debug_frame PROGBITS 00000000 008274 000084 00 0 0 4
[32] .debug_str PROGBITS 00000000 0082f8 00094a 00 0 0 1
[33] .debug_loc PROGBITS 00000000 008c42 0000c7 00 0 0 1
比較發現多出了.debug_frame和.debug_loc。
比較nm -a a.out | grep debug 對帶-g和不帶-g的檔案的輸出結果也顯示,只是多出了.debug_frame和.debug_loc。
直接使用gdb試,感覺不夠爽!僅自己的看法,呵呵,不要拍磚!
8樓 發表於 2008-12-3 16:20
QUOTE:
原帖由 JohnBull 於 2008-12-3 15:55 發表
man 1 file
file我試過,好像顯示不出任何與此有關的資訊。如果你確定,能不能說的具體一點。
9樓 發表於 2008-12-3 21:24
file 不同版本可能有所不同
10樓 發表於 2008-12-4 01:17
readelf --debug-dump <prog>