ifn*_*ull 6 c++ linux linker gdb
我想构建一个二进制文件并将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
Run Code Online (Sandbox Code Playgroud)
我想在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.
Run Code Online (Sandbox Code Playgroud)
但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
...
Run Code Online (Sandbox Code Playgroud)