Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 7 Jul 2017 16:01:08 -0400
From:      Marc Branchaud <marcnarc@xiplink.com>
To:        cem@freebsd.org
Cc:        "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>
Subject:   Re: libexecinfo backtrace() in a signal handler
Message-ID:  <fa4e9ddd-69f1-0793-4c13-4f2cbe4ebcb0@xiplink.com>
In-Reply-To: <CAG6CVpXMMWYniDUOGXakO=qiU%2BBBWCcTEknBjS%2BuQcAsPYB1VQ@mail.gmail.com>
References:  <4d662753-98bc-1275-9394-0cda95eedc65@xiplink.com> <CAG6CVpXMMWYniDUOGXakO=qiU%2BBBWCcTEknBjS%2BuQcAsPYB1VQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2017-07-06 06:58 PM, Conrad Meyer wrote:
> On Thu, Jul 6, 2017 at 2:02 PM, Marc Branchaud <marcnarc@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.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?fa4e9ddd-69f1-0793-4c13-4f2cbe4ebcb0>