|
1 |
| -#define NUM_REGS 30 |
| 1 | +#include <execinfo.h> |
| 2 | +#include <signal.h> |
| 3 | +#include <unistd.h> |
| 4 | +#include <stdlib.h> |
| 5 | +#include <stdio.h> |
2 | 6 |
|
3 |
| -// Apply `macro` to "all" registers. Skip x18 since it's reserved, and x30 since |
4 |
| -// it's the link register. |
| 7 | +#define NUM_REGS 29 |
| 8 | + |
| 9 | +// Apply `macro` to "all" registers. Skip x18 since it's reserved, x29 |
| 10 | +// since it's the frame pointer, and x30 since it's the link register. |
5 | 11 | #define ALL_REGS(macro) \
|
6 | 12 | macro( 0) \
|
7 | 13 | macro( 1) \
|
|
30 | 36 | macro(25) \
|
31 | 37 | macro(26) \
|
32 | 38 | macro(27) \
|
33 |
| - macro(28) \ |
34 |
| - macro(29) |
| 39 | + macro(28) |
35 | 40 |
|
36 | 41 | // Apply `macro` with the given parameters to all registers that have
|
37 | 42 | // specialized entrypoints. That's the same as ALL_REGS, minus x0 (the standard
|
@@ -109,3 +114,24 @@ static inline void foreachRRFunction(void (*call)(void (*)(void **regs),
|
109 | 114 |
|
110 | 115 | ALL_FUNCTIONS(CALL_WITH_FUNCTIONS)
|
111 | 116 | }
|
| 117 | + |
| 118 | +static inline void signalHandler(int sig) { |
| 119 | + void* callstack[128]; |
| 120 | + int frames = backtrace(callstack, 128); |
| 121 | + backtrace_symbols_fd(callstack, frames, 2); |
| 122 | + extern const char* dyld_image_path_containing_address(const void* addr); |
| 123 | + const char *progpath = dyld_image_path_containing_address(signalHandler); |
| 124 | + char *command; |
| 125 | + asprintf(&command, "/usr/bin/otool -tV '%s'", progpath); |
| 126 | + system(command); |
| 127 | + extern void *swift_retain_x10(void); |
| 128 | + const char *libpath = dyld_image_path_containing_address(swift_retain_x10); |
| 129 | + asprintf(&command, "/usr/bin/otool -tV -p _swift_retain_x10 '%s' | /usr/bin/head -n 100", libpath); |
| 130 | + system(command); |
| 131 | + _exit(1); |
| 132 | +} |
| 133 | + |
| 134 | +static inline void installSignalHandlers(void) { |
| 135 | + signal(SIGSEGV, signalHandler); |
| 136 | + signal(SIGBUS, signalHandler); |
| 137 | +} |
0 commit comments