修改源码构建路径
编译好二进制后,查看源码路径信息:
$ objdump -Wi tmp/d68a018ca3f81dea-platform.o
<11> DW_AT_name : (indirect string, offset: 0x76b): ../example/src/platform.c
<15> DW_AT_comp_dir : (indirect string, offset: 0x32): /data/test/my_source/
然后可以修改源码路径:
$ debugedit -b "/data/test/" -d "/buildid" tmp/d68a018ca3f81dea-platform.o
$ objdump -Wi tmp/d68a018ca3f81dea-platform.o
<11> DW_AT_name : (indirect string, offset: 0x34f): ../example/src/platform.c
<15> DW_AT_comp_dir : (indirect string, offset: 0x561): /buildid/my_source/
可以看到,代码构建路径已经被改变
debuginfod
启动服务器:
debuginfod -F /data/infod/ -d 1.db
查找 executable:
$ export DEBUGINFOD_URLS=http://127.0.0.1:8002/
$ debuginfod-find executable 60a9e02a8bbe0633ca423a5c8922ad85094eb2a7
/data/.cache/debuginfod_client/60a9e02a8bbe0633ca423a5c8922ad85094eb2a7/executable
$ debuginfod-find source 60a9e02a8bbe0633ca423a5c8922ad85094eb2a7 /data/buildbot/release/my_source//../example/src/platform.c
/data/.cache/debuginfod_client/60a9e02a8bbe0633ca423a5c8922ad85094eb2a7/source##data##buildbot##release##my_source####..##example##src##platform.c
debuginfod-find 请求的必须为绝对路径,且此路径在服务器上存在。
总结
根据上面的结果,gdb 可以:
获取 elf 的 Build id。
通过 dwarf 获取源码的绝对路径。
则需要在构建时实现下面效果:
构建后将 构建路径修改为 /sources/buildid。
将源码拷贝到 /source/buildid 中即可
将 elf(带 dwarf)拷贝到任一路径并打开 debuginfod
然后启动 dbginfod 服务器即可。