[Issue 21066] New: Druntime SIGSEGV / SIGBUS unittest signal handler should emit the stack trace for all threads

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 23 10:37:58 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=21066

          Issue ID: 21066
           Summary: Druntime SIGSEGV / SIGBUS unittest signal handler
                    should emit the stack trace for all threads
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: andrej.mitrovich at gmail.com

The current segfault handler in -unittest mode is implemented as:

https://github.com/dlang/druntime/blob/86e5cf3fa15afda116994da0c91f40aa7a5e6c6e/src/core/runtime.d#L571

However in the current implementation if there was a segfault then only one of
the threads will emit its stack trace. If multiple threads are used then this
may not be enough information - a random thread will be selected which may not
be the thread which caused the segfault. It's also possible for external
processes to send such a signal (for example `timeout -s SEGV 5m ./test` for
timeouts with stack traces).

It /is/ possible to force all threads to dump their stack trace. First this
should be changed:

https://github.com/dlang/druntime/blob/86e5cf3fa15afda116994da0c91f40aa7a5e6c6e/src/core/runtime.d#L586

And `SA_RESETHAND` removed (so we can reuse the signal handler). And then the
thread which received the signal should dispatch the signal to all other
threads (being careful those threads don't try to send the signal back). 

----

I have a working prototype for MacOS, but not for Posix / Windows / other
platforms yet.

--


More information about the Digitalmars-d-bugs mailing list