[Lldb-commits] [lldb] 0d1705a - [lldb] [DynamicRegisterInfo] Support value_regs with offset

Michał Górny via lldb-commits lldb-commits at lists.llvm.org
Fri Oct 15 03:55:10 PDT 2021


Author: Michał Górny
Date: 2021-10-15T12:55:02+02:00
New Revision: 0d1705a9d62301c84977abe6a986d9af1989072f

URL: https://github.com/llvm/llvm-project/commit/0d1705a9d62301c84977abe6a986d9af1989072f
DIFF: https://github.com/llvm/llvm-project/commit/0d1705a9d62301c84977abe6a986d9af1989072f.diff

LOG: [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

Added: 
    

Modified: 
    lldb/include/lldb/Target/DynamicRegisterInfo.h
    lldb/source/Target/DynamicRegisterInfo.cpp
    lldb/unittests/Target/DynamicRegisterInfoTest.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Target/DynamicRegisterInfo.h b/lldb/include/lldb/Target/DynamicRegisterInfo.h
index df4c1a64cb339..e5395f0171afc 100644
--- a/lldb/include/lldb/Target/DynamicRegisterInfo.h
+++ b/lldb/include/lldb/Target/DynamicRegisterInfo.h
@@ -38,6 +38,7 @@ class DynamicRegisterInfo {
     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 @@ class DynamicRegisterInfo {
   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 @@ class DynamicRegisterInfo {
   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;

diff  --git a/lldb/source/Target/DynamicRegisterInfo.cpp b/lldb/source/Target/DynamicRegisterInfo.cpp
index bd56c239a574c..d196c95c081d6 100644
--- a/lldb/source/Target/DynamicRegisterInfo.cpp
+++ b/lldb/source/Target/DynamicRegisterInfo.cpp
@@ -395,6 +395,10 @@ size_t DynamicRegisterInfo::SetRegisterInfo(
       m_value_regs_map[local_regnum] = std::move(reg.value_regs);
     if (!reg.invalidate_regs.empty())
       m_invalidate_regs_map[local_regnum] = std::move(reg.invalidate_regs);
+    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 @@ void DynamicRegisterInfo::ConfigureOffsets() {
       // 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;
+        }
       }
     }
 

diff  --git a/lldb/unittests/Target/DynamicRegisterInfoTest.cpp b/lldb/unittests/Target/DynamicRegisterInfoTest.cpp
index 94c533721ab9f..f027602d5a969 100644
--- a/lldb/unittests/Target/DynamicRegisterInfoTest.cpp
+++ b/lldb/unittests/Target/DynamicRegisterInfoTest.cpp
@@ -203,12 +203,23 @@ TEST_F(DynamicRegisterInfoRegisterTest, addSupplementaryRegister) {
   };
   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;
 
-  EXPECT_IN_REGS(rax, {}, {eax, ax, al});
-  EXPECT_IN_REGS(eax, {rax}, {rax, ax, al});
-  EXPECT_IN_REGS(ax, {rax}, {rax, eax, al});
-  EXPECT_IN_REGS(al, {rax}, {rax, eax, ax});
+  EXPECT_IN_REGS(rax, {}, {eax, ax, ah, al});
+  EXPECT_IN_REGS(eax, {rax}, {rax, ax, ah, al});
+  EXPECT_IN_REGS(ax, {rax}, {rax, eax, ah, al});
+  EXPECT_IN_REGS(ah, {rax}, {rax, eax, ax, al});
+  EXPECT_IN_REGS(al, {rax}, {rax, eax, ax, ah});
+
+  EXPECT_EQ(m_dyninfo.SetRegisterInfo(std::move(m_regs), ArchSpec()),
+            m_regs.size());
+  EXPECT_IN_DYNINFO(rax, 0, {}, {eax, ax, ah, al});
+  EXPECT_IN_DYNINFO(eax, 0, {rax}, {rax, ax, ah, al});
+  EXPECT_IN_DYNINFO(ax, 0, {rax}, {rax, eax, ah, al});
+  EXPECT_IN_DYNINFO(ah, 1, {rax}, {rax, eax, ax, al});
+  EXPECT_IN_DYNINFO(al, 0, {rax}, {rax, eax, ax, ah});
 }
 
 TEST_F(DynamicRegisterInfoRegisterTest, SetRegisterInfo) {


        


More information about the lldb-commits mailing list