在Linux上,如何知道一個可執行檔是否包含調試資訊呢?

來源:互聯網
上載者:User

請教,在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>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.