我想构建一个二进制文件g++
并将调试信息分割到一个单独的文件中。所谓的DebugFission
.
假设您位于一个文件夹中。有一个文件src/main.cpp
内容琐碎:int main() {}
我想使用编译它-gsplit-dwarf
:
mkdir -p obj
(cd obj && g++ -c -g -gsplit-dwarf ../src/main.cpp -o main.o)
g++ -Wl,--gdb-index -fuse-ld=gold obj/*.o -o main
我想设置一个断点main
功能:
gdb main
(gdb) b main
Breakpoint 1 at 0x40058a: file ../src/main.cpp, line 2.
(gdb) r
Breakpoint 1, main () at ../src/main.cpp:2
2 ../src/main.cpp: No such file or directory.
But gdb
找不到符号。它试图寻找相对于的符号obj
目录。
我错过了一些论点吗?
我使用以下版本:gcc-4.9.3
, binutils-2.26.1
, gdb-7.11.1
.
一些额外的信息:
readelf -wi main
Contents of the .debug_info section:
...
<20> DW_AT_GNU_dwo_name: (indirect string, offset: 0x0): main.dwo
<24> DW_AT_comp_dir : (indirect string, offset: 0x9): /tmp/blah/obj
<2c> DW_AT_GNU_dwo_id : 0xf4f335f2e5c313e0
readelf -wi obj/main.dwo
Contents of the .debug_info.dwo section:
...
<c> DW_AT_producer : (indexed string: 0x0): GNU C++ 4.9.3 -mtune=generic -march=x86-64 -g -gsplit-dwarf -fstack-protector-strong
<d> DW_AT_language : 4 (C++)
<e> DW_AT_name : (indexed string: 0x3): ../src/main.cpp
<f> DW_AT_comp_dir : (indexed string: 0x1): /tmp/blah/obj
<10> DW_AT_GNU_dwo_id : 0xf4f335f2e5c313e0
...