[Lldb-commits] [lldb] ec50d35 - [lldb] [DynamicRegisterInfo] Unset value_regs/invalidate_regs before Finalize()
Michał Górny via lldb-commits
lldb-commits at lists.llvm.org
Mon Sep 20 06:02:57 PDT 2021
Author: Michał Górny
Date: 2021-09-20T15:02:20+02:00
New Revision: ec50d351ffdd4559ccce6013d3ab4a3f41c42cee
URL: https://github.com/llvm/llvm-project/commit/ec50d351ffdd4559ccce6013d3ab4a3f41c42cee
DIFF: https://github.com/llvm/llvm-project/commit/ec50d351ffdd4559ccce6013d3ab4a3f41c42cee.diff
LOG: [lldb] [DynamicRegisterInfo] Unset value_regs/invalidate_regs before Finalize()
Set value_regs and invalidate_regs in RegisterInfo pushed onto m_regs
to nullptr, to ensure that the temporaries passed there are not
accidentally used.
Differential Revision: https://reviews.llvm.org/D109879
Added:
Modified:
lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.h
lldb/unittests/Process/Utility/DynamicRegisterInfoTest.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp b/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
index cc79260d0797..2755e5f93d5a 100644
--- a/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
+++ b/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
@@ -395,7 +395,7 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
return m_regs.size();
}
-void DynamicRegisterInfo::AddRegister(RegisterInfo ®_info,
+void DynamicRegisterInfo::AddRegister(RegisterInfo reg_info,
ConstString &set_name) {
assert(!m_finalized);
const uint32_t reg_num = m_regs.size();
@@ -404,10 +404,16 @@ void DynamicRegisterInfo::AddRegister(RegisterInfo ®_info,
if (reg_info.value_regs) {
for (i = 0; reg_info.value_regs[i] != LLDB_INVALID_REGNUM; ++i)
m_value_regs_map[reg_num].push_back(reg_info.value_regs[i]);
+
+ // invalidate until Finalize() is called
+ reg_info.value_regs = nullptr;
}
if (reg_info.invalidate_regs) {
for (i = 0; reg_info.invalidate_regs[i] != LLDB_INVALID_REGNUM; ++i)
m_invalidate_regs_map[reg_num].push_back(reg_info.invalidate_regs[i]);
+
+ // invalidate until Finalize() is called
+ reg_info.invalidate_regs = nullptr;
}
if (reg_info.dynamic_size_dwarf_expr_bytes) {
for (i = 0; i < reg_info.dynamic_size_dwarf_len; ++i)
diff --git a/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.h b/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.h
index 663fbab57810..a6495dcda608 100644
--- a/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.h
+++ b/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.h
@@ -35,7 +35,7 @@ class DynamicRegisterInfo {
size_t SetRegisterInfo(const lldb_private::StructuredData::Dictionary &dict,
const lldb_private::ArchSpec &arch);
- void AddRegister(lldb_private::RegisterInfo ®_info,
+ void AddRegister(lldb_private::RegisterInfo reg_info,
lldb_private::ConstString &set_name);
void Finalize(const lldb_private::ArchSpec &arch);
diff --git a/lldb/unittests/Process/Utility/DynamicRegisterInfoTest.cpp b/lldb/unittests/Process/Utility/DynamicRegisterInfoTest.cpp
index 68c1ee3517c0..5f2b278b9b75 100644
--- a/lldb/unittests/Process/Utility/DynamicRegisterInfoTest.cpp
+++ b/lldb/unittests/Process/Utility/DynamicRegisterInfoTest.cpp
@@ -100,3 +100,27 @@ TEST_F(DynamicRegisterInfoTest, finalize_regs) {
ASSERT_REG(i1, 16, {}, {b1});
ASSERT_REG(i2, 8, {b2}, {b1, i1});
}
+
+TEST_F(DynamicRegisterInfoTest, no_finalize_regs) {
+ // Add regular registers
+ uint32_t b1 = AddTestRegister("b1", 8);
+ uint32_t b2 = AddTestRegister("b2", 8);
+
+ // Add a few sub-registers
+ uint32_t s1 = AddTestRegister("s1", 4, {b1});
+ uint32_t s2 = AddTestRegister("s2", 4, {b2});
+
+ // Add a register with invalidate_regs
+ uint32_t i1 = AddTestRegister("i1", 8, {}, {b1});
+
+ // Add a register with indirect invalidate regs to be expanded
+ // TODO: why is it done conditionally to value_regs?
+ uint32_t i2 = AddTestRegister("i2", 4, {b2}, {i1});
+
+ ASSERT_REG(b1, LLDB_INVALID_INDEX32);
+ ASSERT_REG(b2, LLDB_INVALID_INDEX32);
+ ASSERT_REG(s1, LLDB_INVALID_INDEX32);
+ ASSERT_REG(s2, LLDB_INVALID_INDEX32);
+ ASSERT_REG(i1, LLDB_INVALID_INDEX32);
+ ASSERT_REG(i2, LLDB_INVALID_INDEX32);
+}
More information about the lldb-commits
mailing list