[Lldb-commits] [PATCH] D111489: [lldb] [DynamicRegisterInfo] Support value_regs with offset
Michał Górny via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Sat Oct 9 06:53:05 PDT 2021
mgorny created this revision.
mgorny added reviewers: labath, teemperor, krytarowski, emaste.
Herald added a subscriber: pengfei.
mgorny requested review of this revision.
Support specifying an offset for value_regs[0], and add the offset
to the computed derived register offset. This makes it possible to
e.g. create the "ah" register on x86.
https://reviews.llvm.org/D111489
Files:
lldb/include/lldb/Target/DynamicRegisterInfo.h
lldb/source/Target/DynamicRegisterInfo.cpp
lldb/unittests/Target/DynamicRegisterInfoTest.cpp
Index: lldb/unittests/Target/DynamicRegisterInfoTest.cpp
===================================================================
--- lldb/unittests/Target/DynamicRegisterInfoTest.cpp
+++ lldb/unittests/Target/DynamicRegisterInfoTest.cpp
@@ -196,12 +196,22 @@
};
uint32_t eax = AddTestRegister("eax", "supplementary", 4, suppl_adder, {rax});
uint32_t ax = AddTestRegister("ax", "supplementary", 2, suppl_adder, {rax});
+ uint32_t ah = AddTestRegister("ah", "supplementary", 1, suppl_adder, {rax});
uint32_t al = AddTestRegister("al", "supplementary", 1, suppl_adder, {rax});
+ m_regs[ah].value_reg_offset = 1;
- ASSERT_REG(rax, {}, {eax, ax, al});
- ASSERT_REG(eax, {rax}, {rax, ax, al});
- ASSERT_REG(ax, {rax}, {rax, eax, al});
- ASSERT_REG(al, {rax}, {rax, eax, ax});
+ ASSERT_REG(rax, {}, {eax, ax, ah, al});
+ ASSERT_REG(eax, {rax}, {rax, ax, ah, al});
+ ASSERT_REG(ax, {rax}, {rax, eax, ah, al});
+ ASSERT_REG(ah, {rax}, {rax, eax, ax, al});
+ ASSERT_REG(al, {rax}, {rax, eax, ax, ah});
+
+ EXPECT_EQ(m_dyninfo.SetRegisterInfo(m_regs, ArchSpec()), m_regs.size());
+ ASSERT_REG(rax, 0, {}, {eax, ax, ah, al});
+ ASSERT_REG(eax, 0, {rax}, {rax, ax, ah, al});
+ ASSERT_REG(ax, 0, {rax}, {rax, eax, ah, al});
+ ASSERT_REG(ah, 1, {rax}, {rax, eax, ax, al});
+ ASSERT_REG(al, 0, {rax}, {rax, eax, ax, ah});
}
TEST_F(DynamicRegisterInfoRegisterTest, SetRegisterInfo) {
Index: lldb/source/Target/DynamicRegisterInfo.cpp
===================================================================
--- lldb/source/Target/DynamicRegisterInfo.cpp
+++ lldb/source/Target/DynamicRegisterInfo.cpp
@@ -395,6 +395,10 @@
m_value_regs_map[local_regnum].push_back(value_reg);
for (uint32_t invalidate_reg : reg.invalidate_regs)
m_invalidate_regs_map[local_regnum].push_back(invalidate_reg);
+ if (reg.value_reg_offset != 0) {
+ assert(reg.value_regs.size() == 1);
+ m_value_reg_offset_map[local_regnum] = reg.value_reg_offset;
+ }
struct RegisterInfo reg_info {
reg.name.AsCString(), reg.alt_name.AsCString(), reg.byte_size,
@@ -679,8 +683,12 @@
// as that of their corresponding primary register in value_regs list.
if (reg.byte_offset == LLDB_INVALID_INDEX32) {
uint32_t value_regnum = reg.value_regs[0];
- if (value_regnum != LLDB_INVALID_INDEX32)
+ if (value_regnum != LLDB_INVALID_INDEX32) {
reg.byte_offset = GetRegisterInfoAtIndex(value_regnum)->byte_offset;
+ auto it = m_value_reg_offset_map.find(reg.kinds[eRegisterKindLLDB]);
+ if (it != m_value_reg_offset_map.end())
+ reg.byte_offset += it->second;
+ }
}
}
Index: lldb/include/lldb/Target/DynamicRegisterInfo.h
===================================================================
--- lldb/include/lldb/Target/DynamicRegisterInfo.h
+++ lldb/include/lldb/Target/DynamicRegisterInfo.h
@@ -38,6 +38,7 @@
uint32_t regnum_remote = LLDB_INVALID_REGNUM;
std::vector<uint32_t> value_regs;
std::vector<uint32_t> invalidate_regs;
+ uint32_t value_reg_offset = 0;
};
DynamicRegisterInfo() = default;
@@ -101,6 +102,7 @@
typedef std::vector<reg_num_collection> set_reg_num_collection;
typedef std::vector<lldb_private::ConstString> name_collection;
typedef std::map<uint32_t, reg_num_collection> reg_to_regs_map;
+ typedef std::map<uint32_t, uint32_t> reg_offset_map;
llvm::Expected<uint32_t> ByteOffsetFromSlice(uint32_t index,
llvm::StringRef slice_str,
@@ -122,6 +124,7 @@
name_collection m_set_names;
reg_to_regs_map m_value_regs_map;
reg_to_regs_map m_invalidate_regs_map;
+ reg_offset_map m_value_reg_offset_map;
size_t m_reg_data_byte_size = 0u; // The number of bytes required to store
// all registers
bool m_finalized = false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111489.378444.patch
Type: text/x-patch
Size: 3883 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211009/eb2075e9/attachment-0001.bin>
More information about the lldb-commits
mailing list