================
@@ -0,0 +1,206 @@
+"""
+Test lldb-dap sends only a single stopped event when multiple threads
+stop simultaneously. This prevents VS Code race conditions where it
+cancels stack trace requests for the focus thread.
+
+Test cases:
+1. Multiple threads hit breakpoint simultaneously - only ONE stopped event.
+2. Focus thread exits - new valid focus thread selected.
+3. All threads visible via allThreadsStopped=true.
+"""
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+import lldbdap_testcase
+
+
+class TestDAP_stopEventSingle(lldbdap_testcase.DAPTestCaseBase):
+    @skipIfWindows
+    def test_single_stopped_event_multiple_threads(self):
+        """
+        Tests that when multiple threads hit a breakpoint simultaneously,
+        only a single stopped event is sent to VS Code.
+        """
+        program = self.getBuildArtifact("a.out")
+        self.build_and_launch(program)
+        source = "main.cpp"
+
+        # Set breakpoint where all threads will stop.
+        bp_line = line_number(source, "// break here")
+        breakpoint_ids = self.set_source_breakpoints(source, [bp_line])
+        self.assertEqual(len(breakpoint_ids), 1, "expect one breakpoint")
+
+        # Continue - all threads should hit breakpoint.
+        self.continue_to_breakpoints(breakpoint_ids)
+
+        # Should have 5 threads: main + 4 workers.
+        threads = self.dap_server.get_threads()
+        self.assertGreaterEqual(
+            len(threads), 5, "expect at least 5 threads (main + 4 workers)"
+        )
+
+        # Continue and collect stopped events.
+        self.dap_server.request_continue()
----------------
clayborg wrote:

You might need to continue a few times here and ensure that at least two 
threads have stop reason. Keep continuing until we do have that case and then 
verify the "stopped" packets received. This can ensure the test isn't flaky. If 
you continue N times and we never get two threads with a stop reason, then we 
can exit the test without failing as long as it succeeds when there are 
multiple.

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

Reply via email to