[Lldb-commits] [lldb] [lldb][windows] Fix second-chance exception delivery on lldb-server (PR #197956)

via lldb-commits lldb-commits at lists.llvm.org
Fri May 15 08:21:54 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Charles Zablit (charles-zablit)

<details>
<summary>Changes</summary>

Currently, all tests that wait for the debugger to stop when the process crashes time out on Windows under `LLDB_USE_LLDB_SERVER=1` because of 2 issues:

1. The first `SetState(eStateStopped, false)` silently advances `m_state` on every second-chance event. The `default:` branch later calls `SetState(eStateStopped, true)` but this is never reached because `state == m_state`. The client is waiting for a reply that is never sent.

2. The first-chance default branch stops all threads and then returns `SendToApplication`, which tells Windows `DBG_EXCEPTION_NOT_HANDLED`. This hangs the process, the second-chance event never arrives. `ProcessWindows` is a no-op on first-chance non-breakpoint exceptions because of this.

This patch fixes both issues.

---
Full diff: https://github.com/llvm/llvm-project/pull/197956.diff


1 Files Affected:

- (modified) lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp (+4-9) 


``````````diff
diff --git a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
index 0c95130147d1b..79e37f91018c2 100644
--- a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
@@ -458,9 +458,6 @@ NativeProcessWindows::OnDebugException(bool first_chance,
   ProcessDebugger::OnDebugException(first_chance, record);
 
   static bool initial_stop = false;
-  if (!first_chance) {
-    SetState(eStateStopped, false);
-  }
 
   switch (record.GetExceptionCode()) {
   case DWORD(STATUS_SINGLE_STEP):
@@ -582,6 +579,9 @@ NativeProcessWindows::OnDebugException(bool first_chance,
              record.GetExceptionCode(), record.GetExceptionAddress(),
              first_chance);
 
+    if (first_chance)
+      return ExceptionResult::SendToApplication;
+
     std::string desc;
     llvm::raw_string_ostream desc_stream(desc);
     desc_stream << "Exception "
@@ -593,12 +593,7 @@ NativeProcessWindows::OnDebugException(bool first_chance,
 
     SetState(eStateStopped, true);
 
-    // For non-breakpoints, give the application a chance to handle the
-    // exception first.
-    if (first_chance)
-      return ExceptionResult::SendToApplication;
-    else
-      return ExceptionResult::BreakInDebugger;
+    return ExceptionResult::BreakInDebugger;
   }
   }
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/197956


More information about the lldb-commits mailing list