[Lldb-commits] [PATCH] D128639: [lldb] [llgs] Fix premature server exit if multiprocess+nonstop

Michał Górny via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 27 05:56:17 PDT 2022


mgorny created this revision.
mgorny added reviewers: labath, emaste, krytarowski, jingham.
Herald added a subscriber: arichardson.
Herald added a project: All.
mgorny requested review of this revision.

Fix lldb-server in the non-stop + multiprocess mode to exit on vStopped
only if all processes have exited, rather than when the first one exits.

Sponsored by: The FreeBSD Foundation


https://reviews.llvm.org/D128639

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
  lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py


Index: lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py
===================================================================
--- lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py
+++ lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py
@@ -392,17 +392,17 @@
     def test_vkill_both_nonstop(self):
         self.vkill_test(kill_parent=True, kill_child=True, nonstop=True)
 
-    def resume_one_test(self, run_order, use_vCont=False):
+    def resume_one_test(self, run_order, use_vCont=False, nonstop=False):
         parent_pid, parent_tid, child_pid, child_tid = (
-            self.start_fork_test(["fork", "trap"]))
+            self.start_fork_test(["fork", "trap"], nonstop=nonstop))
 
         parent_expect = [
-            "[$]T05thread:p{}.{};.*".format(parent_pid, parent_tid),
-            "[$]W00;process:{}#.*".format(parent_pid),
+            "T05thread:p{}.{};.*".format(parent_pid, parent_tid),
+            "W00;process:{}#.*".format(parent_pid),
         ]
         child_expect = [
-            "[$]T05thread:p{}.{};.*".format(child_pid, child_tid),
-            "[$]W00;process:{}#.*".format(child_pid),
+            "T05thread:p{}.{};.*".format(child_pid, child_tid),
+            "W00;process:{}#.*".format(child_pid),
         ]
 
         for x in run_order:
@@ -427,9 +427,17 @@
                     "send packet: $OK#00",
                     "read packet: $c#00",
                 ], True)
-            self.test_sequence.add_log_lines([
-                {"direction": "send", "regex": expect},
-            ], True)
+            if nonstop:
+                self.test_sequence.add_log_lines([
+                    "send packet: $OK#00",
+                    {"direction": "send", "regex": "%Stop:" + expect},
+                    "read packet: $vStopped#00",
+                    "send packet: $OK#00",
+                ], True)
+            else:
+                self.test_sequence.add_log_lines([
+                    {"direction": "send", "regex": "[$]" + expect},
+                ], True)
             # if at least one process remained, check both PIDs
             if parent_expect or child_expect:
                 self.test_sequence.add_log_lines([
@@ -460,6 +468,11 @@
     def test_c_interspersed(self):
         self.resume_one_test(run_order=["parent", "child", "parent", "child"])
 
+    @add_test_categories(["fork"])
+    def test_c_interspersed_nonstop(self):
+        self.resume_one_test(run_order=["parent", "child", "parent", "child"],
+                             nonstop=True)
+
     @add_test_categories(["fork"])
     def test_vCont_parent(self):
         self.resume_one_test(run_order=["parent", "parent"], use_vCont=True)
@@ -483,6 +496,11 @@
         self.resume_one_test(run_order=["parent", "child", "parent", "child"],
                              use_vCont=True)
 
+    @add_test_categories(["fork"])
+    def test_vCont_interspersed_nonstop(self):
+        self.resume_one_test(run_order=["parent", "child", "parent", "child"],
+                             use_vCont=True, nonstop=True)
+
     @add_test_categories(["fork"])
     def test_vCont_two_processes(self):
         parent_pid, parent_tid, child_pid, child_tid = (
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -3871,9 +3871,9 @@
   m_stop_notification_queue.pop_front();
   if (!m_stop_notification_queue.empty())
     return SendPacketNoLock(m_stop_notification_queue.front());
-  // If this was the last notification and the process exited, terminate
-  // the server.
-  if (m_inferior_prev_state == eStateExited) {
+  // If this was the last notification and all the processes exited,
+  // terminate the server.
+  if (m_debugged_processes.empty()) {
     m_exit_now = true;
     m_mainloop.RequestTermination();
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128639.440187.patch
Type: text/x-patch
Size: 4024 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220627/9815847a/attachment-0001.bin>


More information about the lldb-commits mailing list