backtrace-rs icon indicating copy to clipboard operation
backtrace-rs copied to clipboard

Allow tracing of stack given a signal handler's context

Open s1341 opened this issue 3 years ago • 2 comments

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?

s1341 avatar Apr 07 '21 15:04 s1341

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.

alexcrichton avatar Jun 18 '21 15:06 alexcrichton

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.

bjorn3 avatar Jun 18 '21 15:06 bjorn3