The stall report (issue #29, #35) can show where every pool thread is: each one is sent SIGUSR2, and its handler writes its own call stack ("module(+offset) [address]", what addr2line -e +offset reads) to stderr. Not async-signal-safe in theory, and it runs once, just before the abort of a process that is already lost.
| 47 | // The stall report (issue #29, #35) can show where every pool thread is: each one is sent SIGUSR2, and its handler writes its own call stack ("module(+offset) [address]", what |
| 48 | // addr2line -e <module> +offset reads) to stderr. Not async-signal-safe in theory, and it runs once, just before the abort of a process that is already lost. |
| 49 | void stall_stack_handler(int) { |
| 50 | void* frames[24]; |
| 51 | const int n = backtrace(frames, 24); |
| 52 | char head[64]; |
| 53 | const int len = std::snprintf(head, sizeof head, " stack of thread %ld:\n", (long) syscall(SYS_gettid)); |
| 54 | if (len > 0) { const ssize_t w = write(2, head, (size_t) len); (void) w; } |
| 55 | backtrace_symbols_fd(frames, n, 2); |
| 56 | } |
| 57 | void dump_thread_stacks(std::vector<std::thread>& threads) { |
| 58 | struct sigaction sa{}; |
| 59 | sa.sa_handler = stall_stack_handler; |