6月 252014
 

缘起

gcc编译程序的时候,如果没有使用-g选项,则没法调试,如果使用了-g选项,则debug信息太多,不适合线上使用,该怎么办?

解决办法

gcc的时候把符号信息放到单独的文件中,二进制文件中只保留符号文件的地址和校验值,调试的使用,把符号文件放到指定地址就OK了

 基本命令

1. 编译文件

gcc -g a.out

2. 生成debug信息文件

objcopy  –only-keep-debug a.out a.debug

3. 去掉a.out 中的调试信息

strip a.out

4. 将调试文件的名字添加到a.out 中

objcopy –add-gnu-debuglink=a.debug a.out

5. gdb调试的时候,可以通过 set debug-file-directory dir-of-debug-file  命令设置debug文件所在的目录,当然,也可以通过 symbol-file  debug-file 来读取调试符号

6.  调试信息文件究竟是个啥?

#file a.debug
a.debug: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

似乎和原来的可执行文件没太大差别

 

相关资料:

http://www.sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html

http://en.wikipedia.org/wiki/Debug_symbol

 

 Posted by at 下午 4:12

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据