Skip to content

Commit c3d2b4e

Browse files
committed
make windows crashlog print more useful information on access violation
1 parent f7d44f3 commit c3d2b4e

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

loader/src/platform/windows/crashlog.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,30 @@ static void printAddr(std::ostream& stream, void const* addr, bool fullPath = tr
191191
}
192192
}
193193

194+
static void printExtraParameters(std::ostream& stream, DWORD code, ULONG_PTR* params, size_t count) {
195+
switch (code) {
196+
case EXCEPTION_ACCESS_VIOLATION: {
197+
const char* what;
198+
switch (params[0]) {
199+
case 0: what = "read from memory"; break;
200+
case 1: what = "write to memory"; break;
201+
case 8: what = "execute memory (DEP violation)"; break;
202+
default: what = "???"; break;
203+
}
204+
205+
stream << fmt::format(
206+
"Exception Details: Failed to {} at 0x{:X}",
207+
what, params[1]
208+
) << "\n";
209+
} break;
210+
211+
default: {
212+
// if we can't deduce any useful information, just print the number of parameters
213+
stream << "Number Parameters: " << count << "\n";
214+
} break;
215+
}
216+
}
217+
194218
// https://stackoverflow.com/a/50208684/9124836
195219
static std::string getStacktrace(PCONTEXT context, Mod*& suspectedFaultyMod) {
196220
std::stringstream stream;
@@ -450,11 +474,16 @@ static std::string getInfo(LPEXCEPTION_POINTERS info, Mod* faultyMod, Mod* suspe
450474
<< getExceptionCodeString(info->ExceptionRecord->ExceptionCode) << ")" << std::dec
451475
<< "\n"
452476
<< "Exception Flags: " << info->ExceptionRecord->ExceptionFlags << "\n"
453-
<< "Exception Address: " << info->ExceptionRecord->ExceptionAddress << " (";
477+
<< "Instruction Address: " << info->ExceptionRecord->ExceptionAddress << " (";
454478
printAddr(stream, info->ExceptionRecord->ExceptionAddress, false);
455-
stream << ")"
456-
<< "\n"
457-
<< "Number Parameters: " << info->ExceptionRecord->NumberParameters << "\n";
479+
stream << ")\n";
480+
481+
printExtraParameters(
482+
stream,
483+
info->ExceptionRecord->ExceptionCode,
484+
info->ExceptionRecord->ExceptionInformation,
485+
info->ExceptionRecord->NumberParameters
486+
);
458487
}
459488

460489
// show the thread that crashed

0 commit comments

Comments
 (0)