This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[rfc] dwarf2 backtrace from setcontext


On Sun, Jan 11, 2004 at 09:29:01PM +0100, Andreas Jaeger wrote:
> 	cfi_def_cfa(%rsp, 8)
> 	cfi_same_value(%rbx)
> 	cfi_same_value(%rbp)
> 	cfi_same_value(%r12)
> 	cfi_same_value(%r13)
> 	cfi_same_value(%r14)
> 	cfi_same_value(%r15)
> 	cfi_offset(%rip,-8)

We an entry for rsp here as well.

It looks to me as if gcc's handling of same_value is broken, actually.
As is gcc's handling of DW_CFA_restore and DW_CFA_undefined.  :-(

Also problematic is gdb.  There's currently no way to get back to the
how = REG_CFA value that originally existed.  Not sure what to do about
this, exactly.  I might expect that moving that setting before decoding
the CIE and then using DW_CFA_restore for rsp would produce the expected
results.  But this is something that should be brought up with gdb...

GDB folk:

The problem is attempting to generate proper unwind info for setcontext
for amd64.  This function differs from longjmp in that it attempts to
restore *all* registers rather than just the call-saved ones.

At some point in the course of the function, it becomes impossible to
unwind to the caller of setcontext, so what we're trying to do is 
decide early to swap the unwind to the new context.  So, for a few
instructions, we describe the unwind data as being found in the middle
of the struct ucontext.

However, after those few instructions, we kill the pointer to the
ucontext and so we need to change the CFI data again for the few 
instructions before we arrive at our final destination.  For these
few insns, we have a minimal (but quite normal) stack frame.  The
stack pointer is set, and top-of-stack is the return address.

The problem is that we need to get back to the REG_CFA state that
the stack pointer is normally in for x86.  We had, in the middle of
the function, set the unwind info for the stack pointer to the 
value stored in the middle of the ucontext.  None of DW_CFA_restore,
DW_CFA_saved_value or DW_CFA_undefined will produce the value we want.

How would you suggest this be described?

The only thing I can think that would work with existing code (both
in GDB and GCC), actually, would be to close out the current FDE and
open a new one.  Pretend we fell through into a new function.



r~


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]