GNU Debug Link
来源:互联网 发布:软件爆破教程 编辑:程序博客网 时间:2024/06/05 16:10
有有些程序会包含一个特殊的 gnu link 的section:
$ objdump -h test.gnu_debuglink | grep debugtest.gnu_debuglink: file format elf32-i38626 .gnu_debuglink 00000020 00000000 00000000 00001044 2**0这个 gnu debug link 是为了调试用的。可以用如下的方法创建:
1) 写一个小程序 test.c 如下:
int i = 100;void fun(void){ i = 10; }int main(void){ fun(); return 0;}gcc -g test.c -o test
2) 把debug section 取出来,另存为一个文件:
objcopy --only-keep-debug test test.gnu_debuglink.debug
3)去掉 符号和debug 信息,
objcopy --strip-all test test.gnu_debuglink4)把 debug文件和 stripped 的文件关联:
objcopy --add-gnu-debuglink=test.gnu_debuglink.debug test.gnu_debuglink
可以用下面的方法来确认关联:
$ objdump -s -j .gnu_debuglink test.gnu_debuglinktest.gnu_debuglink: file format elf32-i386Contents of section .gnu_debuglink: 0000 74657374 2e676e75 5f646562 75676c69 test.gnu_debugli 0010 6e6b2e64 65627567 00000000 459748f2 nk.debug....E.H.
在调试的时候,gdb会去特定的目录下寻找 debug文件。
~/tmp$ gdb test.gnu_debuglink --quietReading symbols from test.gnu_debuglink...Reading symbols from /home/charles/tmp/test.gnu_debuglink.debug...done.done.(gdb) list main3{4 i = 10;5}67int main(void)8{9fun();10return 0;11}(gdb)
gdb是这样来搜索debug文件的:
gdb looks up the named file in the directory of the executable file, then in a subdirectory of that directory named.debug, and finally under each one of the global debug directories, in a subdirectory whose name is identical to the leading directories of the executable's absolute file name.
举例来说,假如可执行文件的当前目录是 /home/charles/tmp, 全局的调试目录是 /usr/lib/debug, 那么,gdb 将会依次在如下的目录中搜索debug 文件:
1) /home/charles/tmp
2)/home/charles/tmp/.debug
3)/usr/lib/debug/home/charles/tmp
GDB 设置的调试信息目录是通过配置选项 --with-separate-debug-dir 设定的,
(gdb) show configuration This GDB was configured as follows: configure --host=i686-linux-gnu --target=i686-linux-gnu --with-auto-load-dir=$debugdir:$datadir/auto-load --with-auto-load-safe-path=$debugdir:$datadir/auto-load --with-expat --with-gdb-datadir=/usr/share/gdb (relocatable) --with-jit-reader-dir=/usr/lib/gdb (relocatable) --without-libunwind-ia64 --with-lzma --with-python=/usr (relocatable) --with-separate-debug-dir=/usr/lib/debug (relocatable) --with-system-gdbinit=/etc/gdb/gdbinit --with-zlib --without-babeltrace
gdb在调试过程中,也可以用
set debug-file-directory
directories 设置全局的调试信息目录.(gdb) show debug-file-directory The directory where separate debug symbols are searched for is "/usr/lib/debug".
0 0
- GNU Debug Link
- GNU GDB Debug
- [Debug]GNU tools
- Debug,Masm,Link,ML
- GNU or MS? 此link非彼link !
- 异常debug之GNU工具使用
- the evil cmake -- gnu makefiles Debug Release adding post-fix
- LINK : fatal error LNK1104: cannot open file "Debug/test.exe"
- LINK : fatal error LNK1168: cannot open Debug/***.exe for writing
- LINK : fatal error LNK1104: cannot open file "Debug/Style.exe"
- LINK : warning LNK4076: invalid incremental status file "Debug/helloworld.il
- LINK : fatal error LNK1104: cannot open file "Debug/0123.exe"
- LINK : fatal error LNK1104: cannot open file "Debug/xxxxx.exe"
- GNU
- GNU
- GNU
- GNU
- GNU
- 【VB.NET程序设计】——总结篇
- Amr and Music
- 黑马程序员-IOS-OC基础-Block
- Amr and Pins
- 剑值offer(面试题目64)数据流中的中位数
- GNU Debug Link
- htons函数详解
- 神奇的素数_验证素数(程序员的数学思维修炼)
- Android开发之自动换行LinearLayout
- java debug体系为什么不能debug到jdk里所有的代码
- HDOJ 1312 Red and Black
- Fragment解析创建和传参,动态添加fragment
- Python命令行参数
- SpringMVC介绍之约定优于配置