[Lldb-commits] [lldb] b0060c3 - [lldb] Make comparing RegisterInfo::[alt_]name's pointer value less footy-shooty
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Wed Feb 19 04:20:05 PST 2020
Author: Raphael Isemann
Date: 2020-02-19T13:19:41+01:00
New Revision: b0060c3a7868ef026d95d0cf8a076791ef74f474
URL: https://github.com/llvm/llvm-project/commit/b0060c3a7868ef026d95d0cf8a076791ef74f474
DIFF: https://github.com/llvm/llvm-project/commit/b0060c3a7868ef026d95d0cf8a076791ef74f474.diff
LOG: [lldb] Make comparing RegisterInfo::[alt_]name's pointer value less footy-shooty
Comparing those two `const char *` values relies on the assumption that both
strings were created by a ConstString. Let's check that assumption with an
assert as otherwise this code silently does nothing and that's not great.
Added:
Modified:
lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
lldb/source/Target/ABI.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp b/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
index 3675724deb36..443638aa39f6 100644
--- a/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
+++ b/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
@@ -742,6 +742,8 @@ const lldb_private::RegisterInfo *DynamicRegisterInfo::GetRegisterInfo(
for (auto ®_info : m_regs) {
// We can use pointer comparison since we used a ConstString to set the
// "name" member in AddRegister()
+ assert(ConstString(reg_info.name).GetCString() == reg_info.name &&
+ "reg_info.name not from a ConstString?");
if (reg_info.name == reg_name.GetCString()) {
return ®_info;
}
diff --git a/lldb/source/Target/ABI.cpp b/lldb/source/Target/ABI.cpp
index 47a46f401e61..cb7eca280a39 100644
--- a/lldb/source/Target/ABI.cpp
+++ b/lldb/source/Target/ABI.cpp
@@ -49,13 +49,20 @@ bool RegInfoBasedABI::GetRegisterInfoByName(ConstString name, RegisterInfo &info
const char *unique_name_cstr = name.GetCString();
uint32_t i;
for (i = 0; i < count; ++i) {
- if (register_info_array[i].name == unique_name_cstr) {
+ const char *reg_name = register_info_array[i].name;
+ assert(ConstString(reg_name).GetCString() == reg_name &&
+ "register_info_array[i].name not from a ConstString?");
+ if (reg_name == unique_name_cstr) {
info = register_info_array[i];
return true;
}
}
for (i = 0; i < count; ++i) {
- if (register_info_array[i].alt_name == unique_name_cstr) {
+ const char *reg_alt_name = register_info_array[i].alt_name;
+ assert((reg_alt_name == nullptr ||
+ ConstString(reg_alt_name).GetCString() == reg_alt_name) &&
+ "register_info_array[i].alt_name not from a ConstString?");
+ if (reg_alt_name == unique_name_cstr) {
info = register_info_array[i];
return true;
}
More information about the lldb-commits
mailing list