linux保存調試符號表

有些時候發佈出去的程序被strip後,出了core後無法調試。。由於缺少調試符號文件。

可以用

objcopy --only-keep-debug test test.debug

將test的調試信息保存到 test.debug文件中。需要的時候裝入就可。、


[root@localhost gxh]# objcopy --only-keep-debug t test.debug  

[root@localhost gxh]# strip -s t

[root@localhost gxh]# gdb t

GNU gdb Fedora (6.8-27.el5)

Copyright (C) 2008 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 "i386-redhat-linux-gnu"...

(no debugging symbols found)

(gdb) l

No symbol table is loaded.  Use the "file" command.

(gdb) file test.debug

Reading symbols from /root/gxh/test.debug...done.

(gdb) l

100        {

101            sum += i;

102        }

103        return sum;

104     }

105      #include <sys/time.h>

106     #include <fstream>

107

108     using namespace std;

109     int main(int argc,char* argv[])

(gdb)


#objcopy --only-keep-debug [被提取的文件] [提取出來的調試符號文件,建議加.debug後綴]

另外要把調試信息去掉是用strip命令。你可以man下看看。
strip --strip-debug [需要處理的文件]

把debug信息加回去:
objcopy --add-gnu-debuglink=[debug文件] [需要添加debug信息的文件]



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章