https://github.com/robk-dev updated 
https://github.com/llvm/llvm-project/pull/216710

>From aa37a5f56e0ac3280bc8f5f925d7d0c2a777425d Mon Sep 17 00:00:00 2001
From: Rob <[email protected]>
Date: Tue, 11 Aug 2026 20:10:00 +0100
Subject: [PATCH] [lldb] Guard CRT debug report calls with _MSC_VER

mingw-w64's crtdbg.h expands _CrtSetReportMode and _CrtSetReportFile to
no-ops unless _DEBUG is set, and declares them as real debug-CRT imports
when it is. That macro means both "this code is built in debug mode" and
"a debug CRT is linked", which go together for MSVC but not for MinGW,
where a debug build normally still links the release CRT. So a debug
MinGW build compiles the LLDB_DISABLE_CRASH_DIALOG path but fails to
link it; release MinGW builds get the no-op macros, which is why the
distributed MinGW packages never hit this.

Guard the calls with _MSC_VER. SetErrorMode above them is a Win32 API
and stays unconditional.

Assisted-by: Claude Fable 5
---
 lldb/source/Initialization/SystemInitializerCommon.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lldb/source/Initialization/SystemInitializerCommon.cpp 
b/lldb/source/Initialization/SystemInitializerCommon.cpp
index b5d1c25e15008..97aad944ece93 100644
--- a/lldb/source/Initialization/SystemInitializerCommon.cpp
+++ b/lldb/source/Initialization/SystemInitializerCommon.cpp
@@ -53,12 +53,19 @@ llvm::Error SystemInitializerCommon::Initialize() {
     ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |
                    SEM_NOGPFAULTERRORBOX);
 
+#ifdef _MSC_VER
+    // crtdbg.h expands these to no-ops unless _DEBUG is set, in which case
+    // they become real calls into the debug CRT. That macro means both "this
+    // code is built in debug mode" and "a debug CRT is linked", which go
+    // together for MSVC but not for MinGW: a debug MinGW build normally still
+    // links the release CRT, which does not export them.
     _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
     _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
     _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
     _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
     _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
     _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
+#endif // _MSC_VER
   }
 #endif
 

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to