X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FWindows%2FSignals.inc;h=bce83b9686849f6523d1f1eae8e7b7009edd1a40;hb=b262556c45bb7b3add826bc3f050c99db6990c37;hp=473168edfcf6f5ea4d7fa06988af09c4fb2c65f7;hpb=0bcd9c70b12b684706fbc0e337a827fd73c4f30a;p=oota-llvm.git diff --git a/lib/Support/Windows/Signals.inc b/lib/Support/Windows/Signals.inc index 473168edfcf..bce83b96868 100644 --- a/lib/Support/Windows/Signals.inc +++ b/lib/Support/Windows/Signals.inc @@ -11,10 +11,12 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/FileSystem.h" + #include "Windows.h" +#include #include #include -#include #ifdef __MINGW32__ #include @@ -41,10 +43,11 @@ #pragma GCC diagnostic ignored "-Wformat" #pragma GCC diagnostic ignored "-Wformat-extra-args" - // MinGW does not have updated support for the 64-bit versions of the DebugHlp - // APIs. So we will have to load them manually. The structures and method - // signatures were pulled from DbgHelp.h in the Windows Platform SDK, and - // adjusted for brevity. + #if !defined(__MINGW64_VERSION_MAJOR) + // MinGW.org does not have updated support for the 64-bit versions of the + // DebugHlp APIs. So we will have to load them manually. The structures and + // method signatures were pulled from DbgHelp.h in the Windows Platform SDK, + // and adjusted for brevity. typedef struct _IMAGEHLP_LINE64 { DWORD SizeOfStruct; PVOID Key; @@ -147,6 +150,7 @@ static bool load64BitDebugHelp(void) { } return StackWalk64 != NULL; } + #endif // !defined(__MINGW64_VERSION_MAJOR) #endif // __MINGW32__ // Forward declare. @@ -156,7 +160,7 @@ static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType); // InterruptFunction - The function to call if ctrl-c is pressed. static void (*InterruptFunction)() = 0; -static std::vector *FilesToRemove = NULL; +static std::vector *FilesToRemove = NULL; static std::vector > *CallBacksToRun = 0; static bool RegisteredUnhandledExceptionFilter = false; static bool CleanupExecuted = false; @@ -176,39 +180,24 @@ namespace llvm { //===----------------------------------------------------------------------===// #ifdef _MSC_VER -/// CRTReportHook - Function called on a CRT debugging event. -static int CRTReportHook(int ReportType, char *Message, int *Return) { - // Don't cause a DebugBreak() on return. +/// AvoidMessageBoxHook - Emulates hitting "retry" from an "abort, retry, +/// ignore" CRT debug report dialog. "retry" raises an exception which +/// ultimately triggers our stack dumper. +static int AvoidMessageBoxHook(int ReportType, char *Message, int *Return) { + // Set *Return to the retry code for the return value of _CrtDbgReport: + // http://msdn.microsoft.com/en-us/library/8hyw4sy7(v=vs.71).aspx + // This may also trigger just-in-time debugging via DebugBreak(). if (Return) - *Return = 0; - - switch (ReportType) { - default: - case _CRT_ASSERT: - fprintf(stderr, "CRT assert: %s\n", Message); - // FIXME: Is there a way to just crash? Perhaps throw to the unhandled - // exception code? Perhaps SetErrorMode() handles this. - _exit(3); - break; - case _CRT_ERROR: - fprintf(stderr, "CRT error: %s\n", Message); - // FIXME: Is there a way to just crash? Perhaps throw to the unhandled - // exception code? Perhaps SetErrorMode() handles this. - _exit(3); - break; - case _CRT_WARN: - fprintf(stderr, "CRT warn: %s\n", Message); - break; - } - + *Return = 1; // Don't call _CrtDbgReport. return TRUE; } + #endif static void RegisterHandler() { -#if __MINGW32__ - // On MinGW, we need to load up the symbols explicitly, because the +#if __MINGW32__ && !defined(__MINGW64_VERSION_MAJOR) + // On MinGW.org, we need to load up the symbols explicitly, because the // Win32 framework they include does not have support for the 64-bit // versions of the APIs we need. If we cannot load up the APIs (which // would be unexpected as they should exist on every version of Windows @@ -237,9 +226,9 @@ static void RegisterHandler() { SetConsoleCtrlHandler(LLVMConsoleCtrlHandler, TRUE); // Environment variable to disable any kind of crash dialog. - if (getenv("LLVM_DISABLE_CRT_DEBUG")) { + if (getenv("LLVM_DISABLE_CRASH_REPORT")) { #ifdef _MSC_VER - _CrtSetReportHook(CRTReportHook); + _CrtSetReportHook(AvoidMessageBoxHook); #endif SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | @@ -252,7 +241,7 @@ static void RegisterHandler() { } // RemoveFileOnSignal - The public API -bool sys::RemoveFileOnSignal(const sys::Path &Filename, std::string* ErrMsg) { +bool sys::RemoveFileOnSignal(StringRef Filename, std::string* ErrMsg) { RegisterHandler(); if (CleanupExecuted) { @@ -262,7 +251,7 @@ bool sys::RemoveFileOnSignal(const sys::Path &Filename, std::string* ErrMsg) { } if (FilesToRemove == NULL) - FilesToRemove = new std::vector; + FilesToRemove = new std::vector; FilesToRemove->push_back(Filename); @@ -271,14 +260,14 @@ bool sys::RemoveFileOnSignal(const sys::Path &Filename, std::string* ErrMsg) { } // DontRemoveFileOnSignal - The public API -void sys::DontRemoveFileOnSignal(const sys::Path &Filename) { +void sys::DontRemoveFileOnSignal(StringRef Filename) { if (FilesToRemove == NULL) return; RegisterHandler(); FilesToRemove->push_back(Filename); - std::vector::reverse_iterator I = + std::vector::reverse_iterator I = std::find(FilesToRemove->rbegin(), FilesToRemove->rend(), Filename); if (I != FilesToRemove->rend()) FilesToRemove->erase(I.base()-1); @@ -293,6 +282,10 @@ void sys::PrintStackTraceOnErrorSignal() { LeaveCriticalSection(&CriticalSection); } +void llvm::sys::PrintStackTrace(FILE *) { + // FIXME: Implement. +} + void sys::SetInterruptFunction(void (*IF)()) { RegisterHandler(); @@ -324,7 +317,8 @@ static void Cleanup() { if (FilesToRemove != NULL) while (!FilesToRemove->empty()) { - FilesToRemove->back().eraseFromDisk(); + bool Existed; + llvm::sys::fs::remove(FilesToRemove->back(), Existed); FilesToRemove->pop_back(); } @@ -444,7 +438,7 @@ static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) { } if (ExitOnUnhandledExceptions) - _exit(-3); + _exit(ep->ExceptionRecord->ExceptionCode); // Allow dialog box to pop up allowing choice to start debugger. if (OldFilter)