[Lldb-commits] [PATCH] D111131: [LLDB] Round XML register bitsize to byte boundary

Muhammad Omair Javaid via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 5 03:36:54 PDT 2021


omjavaid created this revision.
omjavaid added reviewers: labath, mgorny.
omjavaid requested review of this revision.

This patch allows LLDB to accept register sizes which are not aligned
to 8 bits bitsize boundary. This fixes a crash in LLDB when connecting
to OpenOCD stub. GDB xml description allows for non-aligned bit lengths
but they are rounded off to nearest byte during transfer. In case of
OpenOCD some of SOC specific system registers were less than a single
byte in length and were causing LLDB to crash.


https://reviews.llvm.org/D111131

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


Index: lldb/test/API/functionalities/gdb_remote_client/TestArmRegisterDefinition.py
===================================================================
--- lldb/test/API/functionalities/gdb_remote_client/TestArmRegisterDefinition.py
+++ lldb/test/API/functionalities/gdb_remote_client/TestArmRegisterDefinition.py
@@ -38,6 +38,10 @@
                         <reg name="sp" bitsize="32" type="data_ptr" group="general"/>
                         <reg name="lr" bitsize="32" type="uint32" group="general"/>
                         <reg name="pc" bitsize="32" type="code_ptr" group="general"/>
+                        <reg name="SYS0" bitsize="9" regnum="21" type="uint32" group="system"/>
+                        <reg name="SYS1" bitsize="8" regnum="22" type="uint32" group="system"/>
+                        <reg name="SYS2" bitsize="1" regnum="23" type="uint32" group="system"/>
+                        <reg name="SYS3" bitsize="7" regnum="24" type="uint32" group="system"/>
                         <reg name="xpsr" bitsize="32" regnum="25" type="uint32" group="general"/>
                         <reg name="MSP" bitsize="32" regnum="26" type="uint32" group="general"/>
                         <reg name="PSP" bitsize="32" regnum="27" type="uint32" group="general"/>
@@ -87,7 +91,7 @@
                 return "E01"
 
             def readRegisters(self):
-                return "20000000f8360020001000002fcb0008f8360020a0360020200c0020000000000000000000000000000000000000000000000000b87f0120b7d100082ed2000800000001b87f01200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
+                return "20000000f8360020001000002fcb0008f8360020a0360020200c0020000000000000000000000000000000000000000000000000b87f0120b7d100082ed20008addebeafbc00000001b87f01200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
 
             def haltReason(self):
                 return "S05"
@@ -129,3 +133,15 @@
 
         pc_valobj = process.GetThreadAtIndex(0).GetFrameAtIndex(0).FindRegister("pc")
         self.assertEqual(pc_valobj.GetValueAsUnsigned(), 0x0800d22e)
+
+        sys_valobj = process.GetThreadAtIndex(0).GetFrameAtIndex(0).FindRegister("SYS0")
+        self.assertEqual(sys_valobj.GetValueAsUnsigned(), 0xdead)
+
+        sys_valobj = process.GetThreadAtIndex(0).GetFrameAtIndex(0).FindRegister("SYS1")
+        self.assertEqual(sys_valobj.GetValueAsUnsigned(), 0xbe)
+
+        sys_valobj = process.GetThreadAtIndex(0).GetFrameAtIndex(0).FindRegister("SYS2")
+        self.assertEqual(sys_valobj.GetValueAsUnsigned(), 0xaf)
+
+        sys_valobj = process.GetThreadAtIndex(0).GetFrameAtIndex(0).FindRegister("SYS3")
+        self.assertEqual(sys_valobj.GetValueAsUnsigned(), 0xbc)
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -4257,7 +4257,8 @@
             reg_info.name.SetString(value);
           } else if (name == "bitsize") {
             if (llvm::to_integer(value, reg_info.byte_size))
-              reg_info.byte_size /= CHAR_BIT;
+              reg_info.byte_size =
+                  (reg_info.byte_size + CHAR_BIT - 1) / CHAR_BIT;
           } else if (name == "type") {
             gdb_type = value.str();
           } else if (name == "group") {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111131.377142.patch
Type: text/x-patch
Size: 3903 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211005/7e893b14/attachment.bin>


More information about the lldb-commits mailing list