libexecinfo backtrace() in a signal handler
Marc Branchaud
marcnarc at xiplink.com
Fri Jul 7 20:06:43 UTC 2017
On 2017-07-06 06:58 PM, Conrad Meyer wrote:
> On Thu, Jul 6, 2017 at 2:02 PM, Marc Branchaud <marcnarc at xiplink.com> wrote:
>> Howdy,
>>
>> (Please CC replies to me, as I am not subscribed. Apologies if I'm in the
>> wrong forum!)
>>
>> I'm trying to use libexecinfo's backtrace() in a SIGSEGV handler. It only
>> finds one single frame in the stack, for the signal handler function.
>> (Outside of the signal handler backtrace() does return the full stack from
>> the call point.)
>>
>> Is there any way to get the stack from where the SIGSEGV arose? A few hours
>> of Googling has proved fruitless.
>>
>> My overall goal is to intercept core-dumping signals to try to save a
>> textual backtrace instead of a full dump (as they can be quite large in my
>> application). So I'd also like to catch SIGBUS, and maybe SIGFPE too.
>
> Hi Marc,
>
> Signal handlers use a special stack frame that libexecinfo is too
> simple to understand. To get a stack from a signal handler, you might
> want to use libunwind instead.
Thanks Conrad, and everyone else.
libunwind does indeed find the frames past the signal handler stack, at
least in 10.3 when compiled with clang. (I tested with basically the
example show_backtrace() function from the libunwind(3) man page.)
I don't know what magic libunwind uses if, as Joerg suggests, the proper
annotation isn't registered. Intuitively I figured the information has
to be there somewhere, since a SIGSEGV coredump includes the full stack.
M.
More information about the freebsd-hackers
mailing list