MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / exceptionFilter

Method exceptionFilter

source/utils/StackTraceWinMSVC.cpp:89–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89LONG WINAPI StackTracePrintPrivateData::exceptionFilter(LPEXCEPTION_POINTERS info)
90{
91 // We print the callstack in a stringstream. Then, we will print it to the crashStream
92 // and, then, to the log manager
93 std::stringstream crashStream;
94
95 if (!SymInitialize(GetCurrentProcess(), 0, TRUE))
96 return 0;
97
98 int depth = 128;
99 IMAGEHLP_LINE line = { 0 };
100
101 PCONTEXT context = info->ContextRecord;
102
103 char procname[MAX_PATH];
104 GetModuleFileNameA(nullptr, procname, sizeof procname);
105
106 STACKFRAME frame;
107 memset(&frame,0,sizeof(frame));
108
109 frame.AddrPC.Offset = context->Eip;
110 frame.AddrPC.Mode = AddrModeFlat;
111 frame.AddrStack.Offset = context->Esp;
112 frame.AddrStack.Mode = AddrModeFlat;
113 frame.AddrFrame.Offset = context->Ebp;
114 frame.AddrFrame.Mode = AddrModeFlat;
115
116 HANDLE process = GetCurrentProcess();
117 HANDLE thread = GetCurrentThread();
118
119 char symbol_buffer[sizeof(IMAGEHLP_SYMBOL) + 255];
120 DWORD symbolOffset = 0;
121
122 line.SizeOfStruct = sizeof line;
123
124 std::string symbolFile;
125 std::string symbolFunction;
126 std::string processName;
127 char processNameRaw[MAX_PATH];
128
129 while(StackWalk(IMAGE_FILE_MACHINE_I386, process, thread, &frame, context,
130 0, SymFunctionTableAccess, SymGetModuleBase, 0))
131 {
132 --depth;
133 if (depth < 0)
134 break;
135
136 if (frame.AddrReturn.Offset == 0)
137 break;
138
139 if (frame.AddrPC.Offset == 0)
140 {
141 crashStream << frame.AddrPC.Offset << ", " << procname << std::endl;
142 continue;
143 }
144
145 IMAGEHLP_SYMBOL *symbol = reinterpret_cast<IMAGEHLP_SYMBOL*>(symbol_buffer);
146 symbol->SizeOfStruct = (sizeof *symbol) + 255;

Callers

nothing calls this directly

Calls 3

readNextLineNotEmptyFunction · 0.85
logMessageMethod · 0.80
clearMethod · 0.80

Tested by

no test coverage detected