|
1 | 1 | #include "openminecraft/vm/pixeltower/v1/om_pixeltower_tracing.hpp" |
| 2 | +#include "boost/stacktrace/stacktrace.hpp" |
2 | 3 | #include "openminecraft/log/om_log_common.hpp" |
3 | 4 | #include "sys/signal.h" |
4 | 5 | #include <csignal> |
5 | 6 | #include <sys/ucontext.h> |
6 | 7 | #include <unistd.h> |
| 8 | +#include <vector> |
7 | 9 |
|
8 | 10 | namespace openminecraft::vm::pixeltower::v1::tracing |
9 | 11 | { |
10 | | -std::map<std::string, void *> registers; |
11 | | - |
12 | 12 | static void crash_handler(int sig, siginfo_t *info, void *context) |
13 | 13 | { |
14 | 14 | ucontext_t *const uc = (ucontext_t *)context; |
15 | 15 | log::OMLogger l("Crash Handler"); |
16 | 16 | l.info("errno: {}, signo: {}, code: {}, {}", info->si_errno, info->si_signo, info->si_code, getpid()); |
17 | 17 |
|
18 | | - void *pc = nullptr; |
19 | | - |
20 | | -#ifdef __x86_64__ |
21 | | -#if defined(__APPLE__) |
22 | | - pc = (void *)uc->uc_mcontext->__ss.__rip; |
23 | | -#define storeReg(n, idx) registers[n] = (void *)uc->uc_mcontext->__ss.__##idx; |
24 | | - storeReg("r8", r8); |
25 | | - storeReg("r9", r9); |
26 | | - storeReg("r10", r10); |
27 | | - storeReg("r11", r11); |
28 | | - storeReg("r12", r12); |
29 | | - storeReg("r13", r13); |
30 | | - storeReg("r14", r14); |
31 | | - storeReg("r15", r15); |
32 | | - storeReg("rdi", rdi); |
33 | | - storeReg("rsi", rsi); |
34 | | - storeReg("rbp", rbp); |
35 | | - storeReg("rbx", rbx); |
36 | | - storeReg("rdx", rdx); |
37 | | - storeReg("rax", rax); |
38 | | - storeReg("rcx", rcx); |
39 | | - storeReg("rsp", rsp); |
40 | | - |
41 | | -#elif defined(OM_PLATFORM_BSD) |
42 | | - pc = (void *)uc->uc_mcontext->context_pc; |
43 | | -#else |
44 | | - pc = (void *)uc->uc_mcontext.gregs[REG_RIP]; |
45 | | -#define storeReg(n, idx) registers[n] = (void *)uc->uc_mcontext.gregs[REG_##idx]; |
46 | | - storeReg("r8", R8); |
47 | | - storeReg("r9", R9); |
48 | | - storeReg("r10", R10); |
49 | | - storeReg("r11", R11); |
50 | | - storeReg("r12", R12); |
51 | | - storeReg("r13", R13); |
52 | | - storeReg("r14", R14); |
53 | | - storeReg("r15", R15); |
54 | | - storeReg("rdi", RDI); |
55 | | - storeReg("rsi", RSI); |
56 | | - storeReg("rbp", RBP); |
57 | | - storeReg("rbx", RBX); |
58 | | - storeReg("rdx", RDX); |
59 | | - storeReg("rax", RAX); |
60 | | - storeReg("rcx", RCX); |
61 | | - storeReg("rsp", RSP); |
62 | | -#endif |
63 | | -#endif |
64 | | - |
65 | | - registers["pc"] = pc; |
| 18 | + std::vector<OMTracingFrame> frames; |
| 19 | + boost::stacktrace::stacktrace s; |
| 20 | + for (auto f : s) |
| 21 | + { |
| 22 | + frames.push_back(OMTracingFrame{(void *)f.address(), f.name()}); |
| 23 | + } |
66 | 24 |
|
67 | | - for (auto regs : registers) |
| 25 | + for (auto &ff : frames) |
68 | 26 | { |
69 | | - l.info("{}: {}", regs.first, regs.second); |
| 27 | + l.info("{} @ {}", ff.location, ff.name); |
70 | 28 | } |
71 | 29 |
|
72 | 30 | raise(SIGKILL); |
|
0 commit comments