backtrace-rs
backtrace-rs copied to clipboard
Allow tracing of stack given a signal handler's context
It would be really convenient to be able to trace the stack starting with a signal-handler's context, at least on posix platforms which support this.
Is there a way to do this currently? Are you open to accepting a PR to allow this?
Sorry for taking awhile to respond to this.
I do not personally really want to maintain bindings safe to get a stack trace from a signal handler. I honestly don't really know what that would entail. We call into libunwind and I have no idea what we need to do to make libunwind safe to run from a signal handler context.
I'm open to the idea of supporting this but this would need to be extremely carefully done and documented. I do not think this is a task to take on lightly, and ideally someone who's already an expert at signal handling and stack traces would take this on.
None of the existing code in this crate has been written to be safe to execute from a signal handler's context. This would need a pretty close audit to exactly specific what can and what can't be invoked from such a context.
According to https://www.nongnu.org/libunwind/man/libunwind(3).html all methods necessary for unwinding of the current thread (as opposed to a different thread of process) are signal safe.