backtrace from a SIGSEGV handler

Arne Steinarson asteinarson@gmail.com
Sun Jul 6 17:05:00 GMT 2008


Hello,

[gcc/g++ 4.3 on i386, linux]

In our SIGSEGV handler we want to make a backtrace to get some context
in a generated bug report.

This works fine in most cases. However, when doing a virtual function call on
an non initialized C++ object this can lead to calling an arbitrary address.
And in the backtrace call, GCC generates a new SIGSEGV when attempting
to trace around that address. GCC then shuts down the app.

I tried installing a local SIGSEGV handler guarding the call to backtrace,
to catch this case, but it never got invoked.

Is there some way to reliably make a backtrace from inside a SIGSEGV
handler?

The alternative I can think of is to do memcpy on a chunk of the
current stack and then call backtrace at some later point, using
this saved data, when a temporary SIGSEGV handler can detect
when backtrace does invalid memory access.

But, I cannot find a backtrace variant that works with a stack copy
in this way.

Advice?

Regards
// ATS.



More information about the Gcc-help mailing list