有些时候发布出去的程序被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信息的文件]