| 12 | namespace crash_handler_execinfo { |
| 13 | |
| 14 | inline void print_stacktrace_execinfo() { |
| 15 | // Fallback to execinfo.h backtrace |
| 16 | void *buffer[100]; |
| 17 | int nptrs; |
| 18 | char **strings; |
| 19 | |
| 20 | printf("Stack trace (backtrace):\n"); |
| 21 | nptrs = backtrace(buffer, 100); |
| 22 | strings = backtrace_symbols(buffer, nptrs); |
| 23 | |
| 24 | if (strings == nullptr) { |
| 25 | printf("backtrace_symbols failed\n"); |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | for (int j = 0; j < nptrs; j++) { |
| 30 | printf("#%-2d %s\n", j, strings[j]); |
| 31 | } |
| 32 | |
| 33 | free(strings); |
| 34 | } |
| 35 | |
| 36 | inline void crash_handler(int sig) { |
| 37 | // Prevent recursion if handler crashes |
no test coverage detected