diff --git a/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.h b/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.h --- a/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.h +++ b/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.h @@ -35,7 +35,7 @@ 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/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp b/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp --- a/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp +++ b/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp @@ -395,7 +395,7 @@ 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 @@ 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/unittests/Process/Utility/DynamicRegisterInfoTest.cpp b/lldb/unittests/Process/Utility/DynamicRegisterInfoTest.cpp --- a/lldb/unittests/Process/Utility/DynamicRegisterInfoTest.cpp +++ b/lldb/unittests/Process/Utility/DynamicRegisterInfoTest.cpp @@ -100,3 +100,27 @@ 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); +}