Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

debugging - Force GDB to use frame-pointer based unwinding

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...