On Tue, Sep 18, 2012 at 07:23:37AM +0200, Lassi Tuura wrote:
> Hey Konstantin,
> 
> Could you expand on the circumstances which require this? The
> frame-based unwinder code just above checks for null RBP and the
> dwarf-based one should not require the check -- see around
> src/dwarf/Gparser.c comment "DWARF spec says undefined return address
> location means end of stack."
> 
In fact, I was unable to find a justification for exactly the statement
from the comment in the documentaion. The 0.99.6 revision of the amd64 ABI
document states

%rbp The content of this register is unspecified at process
initialization time, but the user code should mark the deepest stack
frame by setting the frame pointer to zero.

Which is not the same as setting the %rbp location to NULL. FreeBSD
startup sequence ATM is to enter usermmode with zero %rbp, which is
not compliant, but historically established.

Looking at the unpatched Gstep.c, I see the following sequence
of the events:

1. %rbp is zero, as read by DWARF_GET_LOC().
2. The rip_loc is set to DWARF_NULL_LOC, and then reassigned to cursor
   dwarf.loc[RIP].
3. The check !DWARF_IS_NULL_LOC (c->dwarf.loc[RIP] returns false, which
   causes assignment the c->dwarf.ip = 0.
4. The last non-return statement in unw_step() is executed, which verifies
   that stepper has made a progress. It would not on the next step,
   returning UNW_EBADFRAME.

My patch explicitely handles the case of zero %ebp if dwarf unwinder
already declained,


> Regards,
> Lassi
> 
> On Mon, Sep 17, 2012 at 4:39 PM, Konstantin Belousov <[email protected]> wrote:
> > From: Konstantin Belousov <[email protected]>
> >
> > ---
> >  src/x86_64/Gstep.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/src/x86_64/Gstep.c b/src/x86_64/Gstep.c
> > index e05fcae..9d8c2cf 100644
> > --- a/src/x86_64/Gstep.c
> > +++ b/src/x86_64/Gstep.c
> > @@ -196,6 +196,12 @@ unw_step (unw_cursor_t *cursor)
> >            c->dwarf.loc[RIP] = rip_loc;
> >         }
> >
> > +      if (DWARF_IS_NULL_LOC (c->dwarf.loc[RBP]))
> > +        {
> > +        ret = 0;
> > +        Debug (2, "NULL %rbp loc, returning %d\n", ret);
> > +        return ret;
> > +        }
> >        c->dwarf.ret_addr_column = RIP;
> >
> >        if (!DWARF_IS_NULL_LOC (c->dwarf.loc[RIP]))
> > --
> > 1.7.11.5
> >
> >
> > _______________________________________________
> > Libunwind-devel mailing list
> > [email protected]
> > https://lists.nongnu.org/mailman/listinfo/libunwind-devel
> 
> _______________________________________________
> Libunwind-devel mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/libunwind-devel

Attachment: pgpfYobcOkZi9.pgp
Description: PGP signature

_______________________________________________
Libunwind-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/libunwind-devel

Reply via email to