强制GDB使用基于帧指针的展开 [英] Force GDB to use frame-pointer based unwinding
问题描述
我有一个进程,其中一个 .o
文件没有任何 .eh_frame
或 .debug_frame
部分(通过汇编程序),但使用其他类型的调试信息,如 .debug_info
。显然这会触发gdb停止使用基于帧的指针( rbp
)基于该对象的任何函数展开,并且它会产生无效的回溯(它不清楚它如何尝试)
现在这个二进制文件中的函数正确设置了堆栈框架(即 rbp
指向正确的框架底部),如果GDB只是用它来放松,一切都会很棒。有什么方法可以告诉它忽略 dwarf2
信息并使用基于帧指针的展开?
如果gcc只是用它来放松一切,那么一切都会很棒。
你的意思是GDB。
在我的〜/ .gdbinit
中使用以下例程来展开 $ rbp
frame frame:
define xbt
set $ xbp =(void **)$ arg0
while 1
x / 2a $ xbp
set $ xbp =(void **)$ xbp [0]
end
end
用你想要开始的初始基址指针地址来调用它,例如 xbt $ rbp
来使用当前的基址指针。
这不如允许GDB做到这一点(不能访问参数或本地化),但它确实至少获得了调用跟踪。
为了使GDB忽略现有的DWARF展开信息,您必须修补它并构建您r自己的GDB。
更新:
$ b
为什么剥离不可行?
那么, - strip-dwo
只有 .dwo
部分,这并不是展开的地方info(它位于 .eh_frame
和 .debug_frame
部分)。
也就是说,你应 试着用 strip -g bad.o去掉
- 如果你的文件只有 .debug_frame
.debug_frame
但是正确(或缺失) .eh_frame
,那么删除 .debug_frame
应该可以工作。
strip
doesn' t删除 .eh_frame
,因为通常需要展开这些信息。
$ b 如果 .eh_frame
也不好,你可以用 objcopy
来删除它。
有关展开的更多信息这里。
I have a process where one .o
file is built without any .eh_frame
or .debug_frame
section (via an assembler) but with other types of debug info such as .debug_info
. Apparently this triggers gdb to stop using frame-pointer (rbp
) based unwinding for any functions from that object, and it produces invalid backtraces (it isn't clear how it is trying to unwind the stack at all).
Now the functions in this binary set up the stack frame properly (i.e., rbp
points to correctly to the base of the frame) and if GDB were just to use that to unwind, everything would be great. Is there some way I can tell it to ignore the dwarf2
info and use frame-pointer based unwinding?
if gcc were just to use that to unwind, everything would be great.
You mean GDB.
I use the following routine in my ~/.gdbinit
to unwind $rbp
frame chain:
define xbt
set $xbp = (void **)$arg0
while 1
x/2a $xbp
set $xbp = (void **)$xbp[0]
end
end
Call it with the initial base pointer address you want to start from, e.g., xbt $rbp
to use the current base pointer.
This isn't as good as allowing GDB to do it (no access to parameters or locals), but it does get at least the call trace.
For making GDB to ignore existing DWARF unwind info, you'll have to patch it out and build your own GDB.
P.S. Using --strip-dwo
will not help.
Update:
why stripping isn't feasible?
Well, --strip-dwo
only strips .dwo
sections, and that's not where unwind info is (it's in .eh_frame
and .debug_frame
sections).
That said, you should try to strip .debug_frame
with strip -g bad.o
-- if your file only has bad .debug_frame
but correct (or missing) .eh_frame
, then removing .debug_frame
should work.
strip
doesn't remove .eh_frame
because that info is usually required for unwinding.
If .eh_frame
is also bad, you may be able to remove it with objcopy
.
Some more info on unwinding here.
这篇关于强制GDB使用基于帧指针的展开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!