使用 gdb 调试 llvm 但找不到源代码
Debugging llvm with gdb but can't find source code
llvm 已在调试模式下编译。
➜ ~ file /usr/local/bin/llc
with debug_info, not stripped
在gdb中,我用dir
命令指定目录没用
➜ gdb -q llc
Reading symbols from llc...done.
pwndbg> set args memcpy.ll -o memcpy.s
pwndbg> directory ~/llvm-project/llvm/tools/llc
Source directories searched: /home/xxxx/llvm-project/llvm/tools/llc:$cdir:$cwd
pwndbg> b main
Breakpoint 1 at 0x1a2d7d8
pwndbg> r
pwndbg> info source
No current source file.
查看调试信息想更改构建目录发现所有路径都在~/llvm-project/llvm/lib/Support/
➜ readelf -p .debug_str /usr/local/bin/opt
String dump of section '.debug_str':
......
[ 25c] /home/xxxx/llvm-project/llvm/lib/Support
......
我翻阅了文档并搜索了其他类似问题,但没有找到解决方案
重新映射调试会话的源文件路径名。
如果您的源文件不再位于与构建程序时相同的位置---也许该程序是在不同的计算机上构建的---您需要告诉调试器如何在以下位置找到源代码他们的本地文件路径而不是构建系统的文件路径。
(gdb) set pathname-substitutions /buildbot/path /my/path
(lldb) settings set target.source-map /buildbot/path /my/path
具体到你的问题:
尝试:
(gdb) set pathname-substitutions /home/xxxx/llvm-project/llvm/lib/Support /home/xxxx/llvm-project/llvm/tools/llc
参考https://lldb.llvm.org/use/map.html了解更多详情或回复询问。
llvm 已在调试模式下编译。
➜ ~ file /usr/local/bin/llc
with debug_info, not stripped
在gdb中,我用dir
命令指定目录没用
➜ gdb -q llc
Reading symbols from llc...done.
pwndbg> set args memcpy.ll -o memcpy.s
pwndbg> directory ~/llvm-project/llvm/tools/llc
Source directories searched: /home/xxxx/llvm-project/llvm/tools/llc:$cdir:$cwd
pwndbg> b main
Breakpoint 1 at 0x1a2d7d8
pwndbg> r
pwndbg> info source
No current source file.
查看调试信息想更改构建目录发现所有路径都在~/llvm-project/llvm/lib/Support/
➜ readelf -p .debug_str /usr/local/bin/opt
String dump of section '.debug_str':
......
[ 25c] /home/xxxx/llvm-project/llvm/lib/Support
......
我翻阅了文档并搜索了其他类似问题,但没有找到解决方案
重新映射调试会话的源文件路径名。
如果您的源文件不再位于与构建程序时相同的位置---也许该程序是在不同的计算机上构建的---您需要告诉调试器如何在以下位置找到源代码他们的本地文件路径而不是构建系统的文件路径。
(gdb) set pathname-substitutions /buildbot/path /my/path
(lldb) settings set target.source-map /buildbot/path /my/path
具体到你的问题:
尝试:
(gdb) set pathname-substitutions /home/xxxx/llvm-project/llvm/lib/Support /home/xxxx/llvm-project/llvm/tools/llc
参考https://lldb.llvm.org/use/map.html了解更多详情或回复询问。