aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support/Windows/Signals.inc
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2013-04-05 16:18:03 +0000
committerReid Kleckner <reid@kleckner.net>2013-04-05 16:18:03 +0000
commit9463c0f3da8e325fea96e36540da18cadaa3f303 (patch)
treefa42a0d7e51019ec5d894830b83017db18c76830 /lib/Support/Windows/Signals.inc
parent2bce4cc87a4021247636cc9a07e94cf467b995be (diff)
downloadexternal_llvm-9463c0f3da8e325fea96e36540da18cadaa3f303.zip
external_llvm-9463c0f3da8e325fea96e36540da18cadaa3f303.tar.gz
external_llvm-9463c0f3da8e325fea96e36540da18cadaa3f303.tar.bz2
[Support] Disable assertion dialogs from the MSVC debug CRT
Summary: Sets a report hook that emulates pressing "retry" in the "abort, retry, ignore" dialog box that _CrtDbgReport normally raises. There are many other ways to disable assertion reports, but this was the only way I could find that still calls our exception handler. Reviewers: Bigcheese CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D625 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178880 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Windows/Signals.inc')
-rw-r--r--lib/Support/Windows/Signals.inc22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/Support/Windows/Signals.inc b/lib/Support/Windows/Signals.inc
index 3dd6660..b18b4d1 100644
--- a/lib/Support/Windows/Signals.inc
+++ b/lib/Support/Windows/Signals.inc
@@ -178,6 +178,19 @@ namespace llvm {
//===----------------------------------------------------------------------===//
#ifdef _MSC_VER
+/// 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 = 1;
+ // Don't call _CrtDbgReport.
+ return TRUE;
+}
+
/// CRTReportHook - Function called on a CRT debugging event.
static int CRTReportHook(int ReportType, char *Message, int *Return) {
// Don't cause a DebugBreak() on return.
@@ -238,6 +251,15 @@ static void RegisterHandler() {
OldFilter = SetUnhandledExceptionFilter(LLVMUnhandledExceptionFilter);
SetConsoleCtrlHandler(LLVMConsoleCtrlHandler, TRUE);
+#ifdef _MSC_VER
+ const char *EnableMsgbox = getenv("LLVM_ENABLE_CRT_REPORT");
+ if (!EnableMsgbox || strcmp("0", EnableMsgbox) == 0) {
+ // Setting a report hook overrides the default behavior of popping an "abort,
+ // retry, or ignore" dialog.
+ _CrtSetReportHook(AvoidMessageBoxHook);
+ }
+#endif
+
// Environment variable to disable any kind of crash dialog.
if (getenv("LLVM_DISABLE_CRASH_REPORT")) {
#ifdef _MSC_VER