| 25 | namespace libtas { |
| 26 | |
| 27 | void printBacktrace(void) |
| 28 | { |
| 29 | thread_local static int recurs = 0; |
| 30 | if (recurs) |
| 31 | return; |
| 32 | recurs = 1; |
| 33 | |
| 34 | void* addresses[256]; |
| 35 | const int n = backtrace(addresses, 256); |
| 36 | /* Use `backtrace_symbols_fd` instead of `backtrace_symbols` to avoid using |
| 37 | * `malloc`. Also, don't print the top three functions as those are libtas |
| 38 | * functions calling this */ |
| 39 | backtrace_symbols_fd(addresses+3, n-3, STDERR_FILENO); |
| 40 | recurs = 0; |
| 41 | } |
| 42 | |
| 43 | } |