| 94 | #include <DbgHelp.h> |
| 95 | |
| 96 | void handler(int sig) { |
| 97 | void *stack[10]; |
| 98 | HANDLE process = GetCurrentProcess(); |
| 99 | SymInitialize(process, nullptr, TRUE); |
| 100 | |
| 101 | // Capture the call stack |
| 102 | WORD frames = CaptureStackBackTrace(0, 10, stack, nullptr); |
| 103 | |
| 104 | // Print out the frames to stderr |
| 105 | fprintf(stderr, "Error: signal %d:\n", sig); |
| 106 | for (int i = 0; i < frames; ++i) { |
| 107 | DWORD64 address = reinterpret_cast<DWORD64>(stack[i]); |
| 108 | char symbolBuffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)]; |
| 109 | SYMBOL_INFO *symbol = reinterpret_cast<SYMBOL_INFO *>(symbolBuffer); |
| 110 | symbol->SizeOfStruct = sizeof(SYMBOL_INFO); |
| 111 | symbol->MaxNameLen = MAX_SYM_NAME; |
| 112 | |
| 113 | if (SymFromAddr(process, address, nullptr, symbol)) { |
| 114 | fprintf(stderr, "%d: %s\n", i, symbol->Name); |
| 115 | } else { |
| 116 | fprintf(stderr, "%d: [Unknown Symbol]\n", i); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | SymCleanup(process); |
| 121 | exit(1); |
| 122 | } |
| 123 | #else |
| 124 | void handler(int sig) { |
| 125 | void *array[10]; |
no outgoing calls
no test coverage detected