From 93ecf2126b572ceaad5eac0468ba872f61026cc4 Mon Sep 17 00:00:00 2001 From: Xavier Deguillard Date: Wed, 16 Nov 2022 23:22:50 -0800 Subject: [PATCH] fs: ensure that a minidump is created on crash Summary: After printing the exception backtrace, EdenFS terminates manually. Unfortunately, this means that Windows can't detect that the process crashed as it thinks it terminated correctly. In turn, this prevents minidumps from being created which makes debugging the crash impossible. Fixing this is no easy task as returning from the exception handler would always trigger an infinite recursion of unwind somewhere in the CRT code. This would produce a minidump, but it wouldn't be handy to use. The only solution I found is to reset the exception handler and invoke one as by default, this creates a minidump. After that, we can exit EdenFS in the same way as before, being careful to not call `std::abort` or `std::terminate`. Reviewed By: chadaustin Differential Revision: D41362303 fbshipit-source-id: 42422db66a5f8033796ed8cb5b3ccf1a235f1da5 --- eden/fs/utils/WinStackTrace.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/eden/fs/utils/WinStackTrace.cpp b/eden/fs/utils/WinStackTrace.cpp index add2c9f476..2fd30b7311 100644 --- a/eden/fs/utils/WinStackTrace.cpp +++ b/eden/fs/utils/WinStackTrace.cpp @@ -238,6 +238,11 @@ LONG WINAPI windowsExceptionFilter(LPEXCEPTION_POINTERS excep) { size = backtrace(frames, kMaxFrames); backtraceSymbols(frames, size, err); + // Call an exception that bypass all exception handlers. This will create a + // crash dump on disk by default. + SetUnhandledExceptionFilter(nullptr); + UnhandledExceptionFilter(excep); + // Terminate the process. // msvcrt abort() ultimately calls exit(3), so we shortcut that. // Ideally we'd just exit() or ExitProcess() and be done, but it