I am trying to catch signals such as SIGSEGV in my Android NDK app for debugging purpose. For that, I have set up a sigaction that is called.
I am now trying to get the
You can get the stack base address with pthread_getattr_np
and pthread_attr_getstack
, but what you really need is the PC and SP at the time of the crash. On Linux, you can pull these out of the ucontext
.
If you set the SA_SIGINFO
flag when you configure the signal handler, your handler function gets three arguments instead of one. The third void*
argument is a ucontext
pointer. The accepted answer to this question explains a bit more.
Once you've got all that you can unwind the stack. If you don't mind stepping outside the bounds of what the NDK provides, Android's libcorkscrew has functions that can unwind stacks and output the results. This is used by the debuggerd daemon to dump native crashes to the log file.
It may be useful to know that native crashes logged by debuggerd generate stack dumps in /data/tombstones/
. The file permissions render it inaccessible to normal apps, but on a modified device you could just pull these out and send them.