| 79 | } |
| 80 | |
| 81 | static uint32_t GetCallstackPointers(EXCEPTION_POINTERS* pep, void** ptrs, uint32_t num_ptrs) |
| 82 | { |
| 83 | if (!pep) |
| 84 | { |
| 85 | // The API only accepts 62 or less |
| 86 | uint32_t max = dmMath::Min(num_ptrs, (uint32_t)62); |
| 87 | num_ptrs = CaptureStackBackTrace(0, max, ptrs, 0); |
| 88 | } else |
| 89 | { |
| 90 | HANDLE process = ::GetCurrentProcess(); |
| 91 | HANDLE thread = ::GetCurrentThread(); |
| 92 | uint32_t count = 0; |
| 93 | |
| 94 | // Initialize stack walking. |
| 95 | STACKFRAME64 stack_frame; |
| 96 | memset(&stack_frame, 0, sizeof(stack_frame)); |
| 97 | #if defined(_WIN64) |
| 98 | int machine_type = IMAGE_FILE_MACHINE_AMD64; |
| 99 | stack_frame.AddrPC.Offset = pep->ContextRecord->Rip; |
| 100 | stack_frame.AddrFrame.Offset = pep->ContextRecord->Rbp; |
| 101 | stack_frame.AddrStack.Offset = pep->ContextRecord->Rsp; |
| 102 | #else |
| 103 | int machine_type = IMAGE_FILE_MACHINE_I386; |
| 104 | stack_frame.AddrPC.Offset = pep->ContextRecord->Eip; |
| 105 | stack_frame.AddrFrame.Offset = pep->ContextRecord->Ebp; |
| 106 | stack_frame.AddrStack.Offset = pep->ContextRecord->Esp; |
| 107 | #endif |
| 108 | stack_frame.AddrPC.Mode = AddrModeFlat; |
| 109 | stack_frame.AddrFrame.Mode = AddrModeFlat; |
| 110 | stack_frame.AddrStack.Mode = AddrModeFlat; |
| 111 | while (StackWalk64(machine_type, |
| 112 | process, |
| 113 | thread, |
| 114 | &stack_frame, |
| 115 | pep->ContextRecord, |
| 116 | NULL, |
| 117 | &SymFunctionTableAccess64, |
| 118 | &SymGetModuleBase64, |
| 119 | NULL) && |
| 120 | count < num_ptrs) { |
| 121 | ptrs[count++] = reinterpret_cast<void*>(stack_frame.AddrPC.Offset); |
| 122 | } |
| 123 | num_ptrs = count; |
| 124 | } |
| 125 | return num_ptrs; |
| 126 | } |
| 127 | |
| 128 | static void GenerateCallstack(EXCEPTION_POINTERS* pep) |
| 129 | { |
no test coverage detected