[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Libunwind-devel] Libunwind support for NULL IP
From: |
Prabhat Verma |
Subject: |
Re: [Libunwind-devel] Libunwind support for NULL IP |
Date: |
Thu, 5 Apr 2012 21:24:25 +0000 |
Great suggestion and it works like a charm!
Inside my SEGV handler:
ucontext_t* temp_uc = reinterpret_cast<ucontext_t *> (<the context passed by
the OS>);
size_t rsp(*reinterpret_cast<size_t *> (temp_uc->uc_mcontext.gregs[REG_RSP]));
check if rsp is valid and if it is, let libunwind do the heavy lifting...
On a side note, you may disagree, but IMO there is value in moving this inside
of libunwind. Many uses still rely on function pointers for state -machines and
this will be a useful capability when things go wild....
Thanks a ton Arun and apologies for the trouble :)
Regards,
Prabhat
-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of Arun Sharma
Sent: Thursday, April 05, 2012 12:04 PM
To: Prabhat Verma
Cc: address@hidden
Subject: Re: [Libunwind-devel] Libunwind support for NULL IP
On Wed, Apr 4, 2012 at 8:45 PM, Arun Sharma <address@hidden> wrote:
> If you want all of this to work without -fno-omit-frame-pointer,
> things become a bit more complicated. We'll somehow have to
> (heuristically?) unwind up to the point where IP is valid. libunwind
> knows what to do after that.
Here's one way to make it work:
In the signal handler, you can compare the faulting address to %rip and infer
that this was a SIGSEGV caused by a bad function pointer.
Then you can special case this (i.e. unwind the inner most frame "manually" --
by changing %rip in the ucontext to the return address pointed to by %rsp).
libunwind should be able to do the rest of the work for you.
Why not have this code inside of libunwind? The interfaces do so would be icky
and this is best done in the signal handler, rather than another library.
-Arun