[Lldb-commits] [PATCH] D48868: [LLDB] In ProcessGDBRemote::UpdateThreadIDList(), the thread PCs should not be cleared after they are updated from the stop reply packet

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 16 15:34:03 PDT 2018


That's a good point Pavel.  I tried to write one (below) but I never saw what the original failure mode was.  Venkata, can you help to make a test case that fails before the patch and works after?  Or explain what bug was being fixed exactly?  I could see that the code was wrong from reading it, but I never understood how you got to this.


Index: packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestStopPCs.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestStopPCs.py	(nonexistent)
+++ packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestStopPCs.py	(working copy)
@@ -0,0 +1,45 @@
+from __future__ import print_function
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+from gdbclientutils import *
+
+
+class TestThreadSelectionBug(GDBRemoteTestBase):
+    def test(self):
+        class MyResponder(MockGDBServerResponder):
+            def haltReason(self):
+                return "T02thread:1ff0d;threads:1ff0d,2ff0d;thread-pcs:10001bc00,10002bc00;"
+
+            def threadStopInfo(self, threadnum):
+                if threadnum == 0x1ff0d:
+                    return "T02thread:1ff0d;threads:1ff0d,2ff0d;thread-pcs:10001bc00,10002bc00;0:0,1:00bc010001;"
+                if threadnum == 0x2ff0d:
+                    return "T00thread:2ff0d;threads:1ff0d,2ff0d;thread-pcs:10001bc00,10002bc00;0:0,1:00bc020001;"
+
+            def qXferRead(self, obj, annex, offset, length):
+                if annex == "target.xml":
+                    return """<?xml version="1.0"?>
+                        <target version="1.0">
+                          <architecture>i386:x86-64</architecture>
+                          <feature name="org.gnu.gdb.i386.core">
+                            <reg name="rax" bitsize="64" regnum="0" type="int" group="general"/>
+                            <reg name="rip" bitsize="64" regnum="1" type="code_ptr" group="general"/>
+                          </feature>
+                        </target>""", False
+                else:
+                    return None, False
+
+        self.server.responder = MyResponder()
+        target = self.dbg.CreateTarget('')
+        if self.TraceOn():
+          self.runCmd("log enable gdb-remote packets")
+        process = self.connect(target)
+
+        self.assertEqual(process.GetNumThreads(), 2)
+        th0 = process.GetThreadAtIndex(0)
+        th1 = process.GetThreadAtIndex(1)
+        self.assertEqual(th0.GetThreadID(), 0x1ff0d)
+        self.assertEqual(th1.GetThreadID(), 0x2ff0d)
+        self.assertEqual(th0.GetFrameAtIndex(0).GetPC(), 0x10001bc00)
+        self.assertEqual(th1.GetFrameAtIndex(0).GetPC(), 0x10002bc00)
Index: packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py	(revision 337215)
+++ packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py	(working copy)
@@ -130,6 +130,8 @@
             return self.QEnableErrorStrings()
         if packet == "?":
             return self.haltReason()
+        if packet == "s":
+            return self.haltReason()
         if packet[0] == "H":
             return self.selectThread(packet[1], int(packet[2:], 16))
         if packet[0:6] == "qXfer:":
@@ -144,6 +146,9 @@
             return self.vAttach(int(pid, 16))
         if packet[0] == "Z":
             return self.setBreakpoint(packet)
+        if packet.startswith("qThreadStopInfo"):
+            threadnum = int (packet[15:], 16)
+            return self.threadStopInfo(threadnum)
         return self.other(packet)
 
     def interrupt(self):
@@ -204,6 +209,9 @@
     def setBreakpoint(self, packet):
         raise self.UnexpectedPacketException()
 
+    def threadStopInfo(self, threadnum):
+        return ""
+
     def other(self, packet):
         # empty string means unsupported
         return ""


> On Jul 16, 2018, at 3:15 AM, Pavel Labath via Phabricator <reviews at reviews.llvm.org> wrote:
> 
> labath added a comment.
> 
> Could you also add a test case for this?
> I think it should be possible to test this via the gdb-client (`test/testcases/functionalities/gdb_remote_client/`) test suite. If I understood the previous comments correctly, you'll need to mock a server that sends a `thread-pcs` field, but does not implement a `jThreadsInfo` packet.
> 
> 
> Repository:
>  rL LLVM
> 
> https://reviews.llvm.org/D48868
> 
> 
> 



More information about the lldb-commits mailing list