从内核调用跟踪中获取行号
我正在尝试调试似乎是完成队列问题:
Apr 14 18:39:15 ST2035 kernel: Call Trace:
Apr 14 18:39:15 ST2035 kernel: [<ffffffff8049b295>] schedule_timeout+0x1e/0xad
Apr 14 18:39:15 ST2035 kernel: [<ffffffff8049a81c>] wait_for_common+0xd5/0x13c
Apr 14 18:39:15 ST2035 kernel: [<ffffffffa01ca32b>]
ib_unregister_mad_agent+0x376/0x4c9 [ib_mad]
Apr 14 18:39:16 ST2035 kernel: [<ffffffffa03058f4>] ib_umad_close+0xbd/0xfd
是否可以将这些十六进制数字转换为接近行号的数字?
I'm trying to debug what appears to be a completion queue issue:
Apr 14 18:39:15 ST2035 kernel: Call Trace:
Apr 14 18:39:15 ST2035 kernel: [<ffffffff8049b295>] schedule_timeout+0x1e/0xad
Apr 14 18:39:15 ST2035 kernel: [<ffffffff8049a81c>] wait_for_common+0xd5/0x13c
Apr 14 18:39:15 ST2035 kernel: [<ffffffffa01ca32b>]
ib_unregister_mad_agent+0x376/0x4c9 [ib_mad]
Apr 14 18:39:16 ST2035 kernel: [<ffffffffa03058f4>] ib_umad_close+0xbd/0xfd
Is it possible to turn those hex numbers into something close to line numbers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不完全是,但如果您构建了带有调试信息的 vmlinux 映像(例如,在 RHEL 中,您应该能够安装 kernel-debug 或 kernel-dbg 或类似的东西),您就可以接近。假设您有可用的 vmlinux 文件。执行以下操作:
objdump -S vmlinux
这将尽力将目标代码与源代码的各个行进行匹配。
例如,对于以下 C 代码:
使用 cc -g test.c 编译
,然后在生成的可执行文件上运行 objdump -S,我得到一个大型输出,描述可执行文件的各个部分,包括以下部分:
您可以匹配的地址第一列中的目标代码与堆栈跟踪中的地址相对应。将其与汇编输出中交错的行号信息结合起来......就可以了。
现在请记住,这并不总是 100% 成功,因为 kenrel 通常是在 -O2 优化级别编译的,并且编译器会进行大量代码重新排序等。但是如果您熟悉您所使用的代码尝试调试并解密您正在使用的平台的程序集......您应该能够确定大部分崩溃等。
Not exactly but if you have a vmlinux image built with debugging info, (e.g., in RHEL, you should be able to install the kernel-debug or kernel-dbg or something like that) you can get close. So assuming you have that vmlinux file available. Do the following:
objdump -S vmlinux
This will try it's hardest to match the object code to individual lines of source code.
e.g. for the following C code:
compiled with : cc -g test.c
and then running objdump -S on the resulting executable, I get a large output describing the various parts of the executable inclding the following section:
You can match the addresses of the object code in the first column against the addresses in your stack trace. Combine that with the line number info interleaved in the assembly output... and you're there.
Now keep in mind that this will not always succeed 100% because the kenrel is normally compiled at -O2 optimization level and the compiler would have done a lot of code re-ordering etc. But if you are familiar with the code that you're trying to debug and have some comfort with deciphering the assembly of the platform you're working on... you should be able to pin down most of your crashes etc.
您可以使用内核源代码中的scripts/decode_stacktrace.sh:
decode_stacktrace.sh current_vmlinux_file call_trace_text_file
You can use scripts/decode_stacktrace.sh from the kernel source:
decode_stacktrace.sh current_vmlinux_file < call_trace_text_file