This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
mgorny marked an inline comment as done.
Closed by commit rGb1099120ff96: [lldb] [gdb-remote] Always send PID when 
detaching w/ multiprocess (authored by mgorny).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D110033?vs=373545&id=373551#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110033/new/

https://reviews.llvm.org/D110033

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py


Index: lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
===================================================================
--- lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
+++ lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
@@ -354,3 +354,46 @@
           "QEnvironmentHexEncoded:4e45454453454e43343d6623726f62",
           "QEnvironmentHexEncoded:455155414c533d666f6f3d626172",
         ])
+
+    def test_detach_no_multiprocess(self):
+        class MyResponder(MockGDBServerResponder):
+            def __init__(self):
+                super().__init__()
+                self.detached = None
+
+            def qfThreadInfo(self):
+                return "10200"
+
+            def D(self, packet):
+                self.detached = packet
+                return "OK"
+
+        self.server.responder = MyResponder()
+        target = self.dbg.CreateTarget('')
+        process = self.connect(target)
+        process.Detach()
+        self.assertEqual(self.server.responder.detached, "D")
+
+    def test_detach_pid(self):
+        class MyResponder(MockGDBServerResponder):
+            def __init__(self, test_case):
+                super().__init__()
+                self.test_case = test_case
+                self.detached = None
+
+            def qSupported(self, client_supported):
+                self.test_case.assertIn("multiprocess+", client_supported)
+                return "multiprocess+;" + super().qSupported(client_supported)
+
+            def qfThreadInfo(self):
+                return "mp400.10200"
+
+            def D(self, packet):
+                self.detached = packet
+                return "OK"
+
+        self.server.responder = MyResponder(self)
+        target = self.dbg.CreateTarget('')
+        process = self.connect(target)
+        process.Detach()
+        self.assertRegex(self.server.responder.detached, r"D;0*400")
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -1543,14 +1543,16 @@
     }
   }
 
-  if (pid != LLDB_INVALID_PROCESS_ID) {
-    if (!m_supports_multiprocess) {
-      error.SetErrorString(
-          "Multiprocess extension not supported by the server.");
-      return error;
-    }
+  if (m_supports_multiprocess) {
+    // Some servers (e.g. qemu) require specifying the PID even if only a 
single
+    // process is running.
+    if (pid == LLDB_INVALID_PROCESS_ID)
+      pid = GetCurrentProcessID();
     packet.PutChar(';');
     packet.PutHex64(pid);
+  } else if (pid != LLDB_INVALID_PROCESS_ID) {
+    error.SetErrorString("Multiprocess extension not supported by the 
server.");
+    return error;
   }
 
   StringExtractorGDBRemote response;


Index: lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
===================================================================
--- lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
+++ lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
@@ -354,3 +354,46 @@
           "QEnvironmentHexEncoded:4e45454453454e43343d6623726f62",
           "QEnvironmentHexEncoded:455155414c533d666f6f3d626172",
         ])
+
+    def test_detach_no_multiprocess(self):
+        class MyResponder(MockGDBServerResponder):
+            def __init__(self):
+                super().__init__()
+                self.detached = None
+
+            def qfThreadInfo(self):
+                return "10200"
+
+            def D(self, packet):
+                self.detached = packet
+                return "OK"
+
+        self.server.responder = MyResponder()
+        target = self.dbg.CreateTarget('')
+        process = self.connect(target)
+        process.Detach()
+        self.assertEqual(self.server.responder.detached, "D")
+
+    def test_detach_pid(self):
+        class MyResponder(MockGDBServerResponder):
+            def __init__(self, test_case):
+                super().__init__()
+                self.test_case = test_case
+                self.detached = None
+
+            def qSupported(self, client_supported):
+                self.test_case.assertIn("multiprocess+", client_supported)
+                return "multiprocess+;" + super().qSupported(client_supported)
+
+            def qfThreadInfo(self):
+                return "mp400.10200"
+
+            def D(self, packet):
+                self.detached = packet
+                return "OK"
+
+        self.server.responder = MyResponder(self)
+        target = self.dbg.CreateTarget('')
+        process = self.connect(target)
+        process.Detach()
+        self.assertRegex(self.server.responder.detached, r"D;0*400")
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -1543,14 +1543,16 @@
     }
   }
 
-  if (pid != LLDB_INVALID_PROCESS_ID) {
-    if (!m_supports_multiprocess) {
-      error.SetErrorString(
-          "Multiprocess extension not supported by the server.");
-      return error;
-    }
+  if (m_supports_multiprocess) {
+    // Some servers (e.g. qemu) require specifying the PID even if only a single
+    // process is running.
+    if (pid == LLDB_INVALID_PROCESS_ID)
+      pid = GetCurrentProcessID();
     packet.PutChar(';');
     packet.PutHex64(pid);
+  } else if (pid != LLDB_INVALID_PROCESS_ID) {
+    error.SetErrorString("Multiprocess extension not supported by the server.");
+    return error;
   }
 
   StringExtractorGDBRemote response;
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to