您的位置:首页 > 运维架构 > Linux

在Linux上,如何知道一个可执行文件是否包含调试信息呢?

2016-11-01 14:59 1041 查看
请教,在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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux 信息 如何
相关文章推荐