Skip to content

Commit 0d1705a

Browse files
committed
[lldb] [DynamicRegisterInfo] Support value_regs with offset
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. Differential Revision: https://reviews.llvm.org/D111489
1 parent 7b07c01 commit 0d1705a

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

lldb/include/lldb/Target/DynamicRegisterInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class DynamicRegisterInfo {
3838
uint32_t regnum_remote = LLDB_INVALID_REGNUM;
3939
std::vector<uint32_t> value_regs;
4040
std::vector<uint32_t> invalidate_regs;
41+
uint32_t value_reg_offset = 0;
4142
};
4243

4344
DynamicRegisterInfo() = default;
@@ -101,6 +102,7 @@ class DynamicRegisterInfo {
101102
typedef std::vector<reg_num_collection> set_reg_num_collection;
102103
typedef std::vector<lldb_private::ConstString> name_collection;
103104
typedef std::map<uint32_t, reg_num_collection> reg_to_regs_map;
105+
typedef std::map<uint32_t, uint32_t> reg_offset_map;
104106

105107
llvm::Expected<uint32_t> ByteOffsetFromSlice(uint32_t index,
106108
llvm::StringRef slice_str,
@@ -122,6 +124,7 @@ class DynamicRegisterInfo {
122124
name_collection m_set_names;
123125
reg_to_regs_map m_value_regs_map;
124126
reg_to_regs_map m_invalidate_regs_map;
127+
reg_offset_map m_value_reg_offset_map;
125128
size_t m_reg_data_byte_size = 0u; // The number of bytes required to store
126129
// all registers
127130
bool m_finalized = false;

lldb/source/Target/DynamicRegisterInfo.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ size_t DynamicRegisterInfo::SetRegisterInfo(
395395
m_value_regs_map[local_regnum] = std::move(reg.value_regs);
396396
if (!reg.invalidate_regs.empty())
397397
m_invalidate_regs_map[local_regnum] = std::move(reg.invalidate_regs);
398+
if (reg.value_reg_offset != 0) {
399+
assert(reg.value_regs.size() == 1);
400+
m_value_reg_offset_map[local_regnum] = reg.value_reg_offset;
401+
}
398402

399403
struct RegisterInfo reg_info {
400404
reg.name.AsCString(), reg.alt_name.AsCString(), reg.byte_size,
@@ -679,8 +683,12 @@ void DynamicRegisterInfo::ConfigureOffsets() {
679683
// as that of their corresponding primary register in value_regs list.
680684
if (reg.byte_offset == LLDB_INVALID_INDEX32) {
681685
uint32_t value_regnum = reg.value_regs[0];
682-
if (value_regnum != LLDB_INVALID_INDEX32)
686+
if (value_regnum != LLDB_INVALID_INDEX32) {
683687
reg.byte_offset = GetRegisterInfoAtIndex(value_regnum)->byte_offset;
688+
auto it = m_value_reg_offset_map.find(reg.kinds[eRegisterKindLLDB]);
689+
if (it != m_value_reg_offset_map.end())
690+
reg.byte_offset += it->second;
691+
}
684692
}
685693
}
686694

lldb/unittests/Target/DynamicRegisterInfoTest.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,23 @@ TEST_F(DynamicRegisterInfoRegisterTest, addSupplementaryRegister) {
203203
};
204204
uint32_t eax = AddTestRegister("eax", "supplementary", 4, suppl_adder, {rax});
205205
uint32_t ax = AddTestRegister("ax", "supplementary", 2, suppl_adder, {rax});
206+
uint32_t ah = AddTestRegister("ah", "supplementary", 1, suppl_adder, {rax});
206207
uint32_t al = AddTestRegister("al", "supplementary", 1, suppl_adder, {rax});
208+
m_regs[ah].value_reg_offset = 1;
207209

208-
EXPECT_IN_REGS(rax, {}, {eax, ax, al});
209-
EXPECT_IN_REGS(eax, {rax}, {rax, ax, al});
210-
EXPECT_IN_REGS(ax, {rax}, {rax, eax, al});
211-
EXPECT_IN_REGS(al, {rax}, {rax, eax, ax});
210+
EXPECT_IN_REGS(rax, {}, {eax, ax, ah, al});
211+
EXPECT_IN_REGS(eax, {rax}, {rax, ax, ah, al});
212+
EXPECT_IN_REGS(ax, {rax}, {rax, eax, ah, al});
213+
EXPECT_IN_REGS(ah, {rax}, {rax, eax, ax, al});
214+
EXPECT_IN_REGS(al, {rax}, {rax, eax, ax, ah});
215+
216+
EXPECT_EQ(m_dyninfo.SetRegisterInfo(std::move(m_regs), ArchSpec()),
217+
m_regs.size());
218+
EXPECT_IN_DYNINFO(rax, 0, {}, {eax, ax, ah, al});
219+
EXPECT_IN_DYNINFO(eax, 0, {rax}, {rax, ax, ah, al});
220+
EXPECT_IN_DYNINFO(ax, 0, {rax}, {rax, eax, ah, al});
221+
EXPECT_IN_DYNINFO(ah, 1, {rax}, {rax, eax, ax, al});
222+
EXPECT_IN_DYNINFO(al, 0, {rax}, {rax, eax, ax, ah});
212223
}
213224

214225
TEST_F(DynamicRegisterInfoRegisterTest, SetRegisterInfo) {

0 commit comments

Comments
 (0)