You can get the base address of the stack with pthread_getattr_np and pthread_attr_getstack , but what you really need is a PC and SP during the crash. On Linux, you can pull them out of ucontext .
If you set the SA_SIGINFO flag when setting up a signal handler, your handler function receives three arguments instead of one. The third argument to void* is the ucontext pointer. The accepted answer to this question explains a little more.
Once you have everything you can expand on the stack. If you don't mind going beyond what the NDK provides, Android libcorkscrew has features that can expand the stacks and output the results. This is used by the debuggerd daemons to dump their own failures into the log file.
It may be useful to know that the built-in failures logged by debuggerd generate stack dumps in /data/tombstones/ . File permissions make it inaccessible to regular applications, but on a modified device, you can just pull them out and send them.
source share