[Lldb-commits] [lldb] d2b9d0f - Round XML register bitsize to byte boundary
Muhammad Omair Javaid via lldb-commits
lldb-commits at lists.llvm.org
Wed Oct 6 02:04:04 PDT 2021
Author: Muhammad Omair Javaid
Date: 2021-10-06T14:03:49+05:00
New Revision: d2b9d0fdda5e8295a2a81276fa6be8ea8d1fd022
URL: https://github.com/llvm/llvm-project/commit/d2b9d0fdda5e8295a2a81276fa6be8ea8d1fd022
DIFF: https://github.com/llvm/llvm-project/commit/d2b9d0fdda5e8295a2a81276fa6be8ea8d1fd022.diff
LOG: Round XML register bitsize to byte boundary
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.
Reviewed By: labath
Differential Revision: https://reviews.llvm.org/D111131
Added:
Modified:
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/test/API/functionalities/gdb_remote_client/TestArmRegisterDefinition.py
Removed:
################################################################################
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 4d3a4c7a072a7..66e33592ba632 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -4257,7 +4257,8 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info,
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 =
+ llvm::divideCeil(reg_info.byte_size, CHAR_BIT);
} else if (name == "type") {
gdb_type = value.str();
} else if (name == "group") {
@@ -4319,7 +4320,11 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info,
assert(dwarf_opcode_len == ret_val);
UNUSED_IF_ASSERT_DISABLED(ret_val);
} else {
- printf("unhandled attribute %s = %s\n", name.data(), value.data());
+ Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(
+ GDBR_LOG_PROCESS));
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s unhandled reg attribute %s = %s",
+ __FUNCTION__, name.data(), value.data());
}
return true; // Keep iterating through all attributes
});
@@ -4353,8 +4358,15 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info,
}
}
- assert(reg_info.byte_size != 0);
- registers.push_back(reg_info);
+ if (reg_info.byte_size == 0) {
+ Log *log(
+ ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
+ LLDB_LOGF(log,
+ "ProcessGDBRemote::%s Skipping zero bitsize register %s",
+ __FUNCTION__, reg_info.name.AsCString());
+ } else
+ registers.push_back(reg_info);
+
return true; // Keep iterating through all "reg" elements
});
return true;
diff --git a/lldb/test/API/functionalities/gdb_remote_client/TestArmRegisterDefinition.py b/lldb/test/API/functionalities/gdb_remote_client/TestArmRegisterDefinition.py
index 28424f0f36263..1f4489374c778 100644
--- a/lldb/test/API/functionalities/gdb_remote_client/TestArmRegisterDefinition.py
+++ b/lldb/test/API/functionalities/gdb_remote_client/TestArmRegisterDefinition.py
@@ -38,6 +38,10 @@ def qXferRead(self, obj, annex, offset, length):
<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 @@ def readRegister(self, regnum):
return "E01"
def readRegisters(self):
- return "20000000f8360020001000002fcb0008f8360020a0360020200c0020000000000000000000000000000000000000000000000000b87f0120b7d100082ed2000800000001b87f01200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
+ return "20000000f8360020001000002fcb0008f8360020a0360020200c0020000000000000000000000000000000000000000000000000b87f0120b7d100082ed20008addebeafbc00000001b87f01200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
def haltReason(self):
return "S05"
@@ -129,3 +133,15 @@ def QListThreadsInStopReply(self):
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)
More information about the lldb-commits
mailing list