diff options
Diffstat (limited to 'llvm/lib/Support/Windows/Signals.inc')
-rw-r--r-- | llvm/lib/Support/Windows/Signals.inc | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/llvm/lib/Support/Windows/Signals.inc b/llvm/lib/Support/Windows/Signals.inc index 8b525f1bd4ac4..0c3681fa96548 100644 --- a/llvm/lib/Support/Windows/Signals.inc +++ b/llvm/lib/Support/Windows/Signals.inc @@ -23,7 +23,7 @@ #include "llvm/Support/raw_ostream.h" // The Windows.h header must be after LLVM and standard headers. -#include "WindowsSupport.h" +#include "llvm/Support/Windows/WindowsSupport.h" #ifdef __MINGW32__ #include <imagehlp.h> @@ -460,7 +460,7 @@ bool sys::RemoveFileOnSignal(StringRef Filename, std::string* ErrMsg) { if (FilesToRemove == NULL) FilesToRemove = new std::vector<std::string>; - FilesToRemove->push_back(Filename); + FilesToRemove->push_back(std::string(Filename)); LeaveCriticalSection(&CriticalSection); return false; @@ -584,7 +584,7 @@ void llvm::sys::AddSignalHandler(sys::SignalHandlerCallback FnPtr, LeaveCriticalSection(&CriticalSection); } -static void Cleanup() { +static void Cleanup(bool ExecuteSignalHandlers) { if (CleanupExecuted) return; @@ -600,7 +600,10 @@ static void Cleanup() { llvm::sys::fs::remove(FilesToRemove->back()); FilesToRemove->pop_back(); } - llvm::sys::RunSignalHandlers(); + + if (ExecuteSignalHandlers) + llvm::sys::RunSignalHandlers(); + LeaveCriticalSection(&CriticalSection); } @@ -610,7 +613,7 @@ void llvm::sys::RunInterruptHandlers() { // error handler). We must ensure that the critical section is properly // initialized. InitializeThreading(); - Cleanup(); + Cleanup(true); } /// Find the Windows Registry Key for a given location. @@ -803,7 +806,7 @@ void sys::CleanupOnSignal(uintptr_t Context) { } static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) { - Cleanup(); + Cleanup(true); // We'll automatically write a Minidump file here to help diagnose // the nasty sorts of crashes that aren't 100% reproducible from a set of @@ -820,7 +823,13 @@ static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) { << "\n"; } - LocalPrintStackTrace(llvm::errs(), ep ? ep->ContextRecord : nullptr); + // Stack unwinding appears to modify the context. Copy it to preserve the + // caller's context. + CONTEXT ContextCopy; + if (ep) + memcpy(&ContextCopy, ep->ContextRecord, sizeof(ContextCopy)); + + LocalPrintStackTrace(llvm::errs(), ep ? &ContextCopy : nullptr); return EXCEPTION_EXECUTE_HANDLER; } @@ -828,7 +837,10 @@ static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) { static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType) { // We are running in our very own thread, courtesy of Windows. EnterCriticalSection(&CriticalSection); - Cleanup(); + // This function is only ever called when a CTRL-C or similar control signal + // is fired. Killing a process in this way is normal, so don't trigger the + // signal handlers. + Cleanup(false); // If an interrupt function has been set, go and run one it; otherwise, // the process dies. |