[Lldb-commits] [lldb] 81832af - [LLDB] Switch to RegisterInfo& for EmulateInstruction::WriteRegister

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 11 06:25:04 PDT 2022


Author: David Spickett
Date: 2022-10-11T13:24:55Z
New Revision: 81832afc04e130a386a89f57d3f4f2d7f19006f7

URL: https://github.com/llvm/llvm-project/commit/81832afc04e130a386a89f57d3f4f2d7f19006f7
DIFF: https://github.com/llvm/llvm-project/commit/81832afc04e130a386a89f57d3f4f2d7f19006f7.diff

LOG: [LLDB] Switch to RegisterInfo& for EmulateInstruction::WriteRegister

WriteRegister and WriteRegisterUnsigned were never pased nullptr,
and only one of them appeared to handle it. Switch to ref to make
the intent clear.

Depends on D134962

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D134963

Added: 
    

Modified: 
    lldb/include/lldb/Core/EmulateInstruction.h
    lldb/source/Core/EmulateInstruction.cpp
    lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
    lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
    lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
    lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Core/EmulateInstruction.h b/lldb/include/lldb/Core/EmulateInstruction.h
index 444059d94b6e1..68b40673faab2 100644
--- a/lldb/include/lldb/Core/EmulateInstruction.h
+++ b/lldb/include/lldb/Core/EmulateInstruction.h
@@ -393,11 +393,11 @@ class EmulateInstruction : public PluginInterface {
   uint64_t ReadRegisterUnsigned(const RegisterInfo &reg_info,
                                 uint64_t fail_value, bool *success_ptr);
 
-  bool WriteRegister(const Context &context, const RegisterInfo *ref_info,
+  bool WriteRegister(const Context &context, const RegisterInfo &ref_info,
                      const RegisterValue &reg_value);
 
   bool WriteRegisterUnsigned(const Context &context,
-                             const RegisterInfo *reg_info, uint64_t reg_value);
+                             const RegisterInfo &reg_info, uint64_t reg_value);
 
   // Register kind and number variants
   bool ReadRegister(lldb::RegisterKind reg_kind, uint32_t reg_num,

diff  --git a/lldb/source/Core/EmulateInstruction.cpp b/lldb/source/Core/EmulateInstruction.cpp
index 54d4d93fb4d06..73cbcc722ef64 100644
--- a/lldb/source/Core/EmulateInstruction.cpp
+++ b/lldb/source/Core/EmulateInstruction.cpp
@@ -112,10 +112,10 @@ uint64_t EmulateInstruction::ReadRegisterUnsigned(const RegisterInfo &reg_info,
 }
 
 bool EmulateInstruction::WriteRegister(const Context &context,
-                                       const RegisterInfo *reg_info,
+                                       const RegisterInfo &reg_info,
                                        const RegisterValue &reg_value) {
   if (m_write_reg_callback != nullptr)
-    return m_write_reg_callback(this, m_baton, context, reg_info, reg_value);
+    return m_write_reg_callback(this, m_baton, context, &reg_info, reg_value);
   return false;
 }
 
@@ -125,7 +125,7 @@ bool EmulateInstruction::WriteRegister(const Context &context,
                                        const RegisterValue &reg_value) {
   llvm::Optional<RegisterInfo> reg_info = GetRegisterInfo(reg_kind, reg_num);
   if (reg_info)
-    return WriteRegister(context, &(*reg_info), reg_value);
+    return WriteRegister(context, *reg_info, reg_value);
   return false;
 }
 
@@ -137,19 +137,17 @@ bool EmulateInstruction::WriteRegisterUnsigned(const Context &context,
   if (reg_info) {
     RegisterValue reg_value;
     if (reg_value.SetUInt(uint_value, reg_info->byte_size))
-      return WriteRegister(context, &(*reg_info), reg_value);
+      return WriteRegister(context, *reg_info, reg_value);
   }
   return false;
 }
 
 bool EmulateInstruction::WriteRegisterUnsigned(const Context &context,
-                                               const RegisterInfo *reg_info,
+                                               const RegisterInfo &reg_info,
                                                uint64_t uint_value) {
-  if (reg_info != nullptr) {
-    RegisterValue reg_value;
-    if (reg_value.SetUInt(uint_value, reg_info->byte_size))
-      return WriteRegister(context, reg_info, reg_value);
-  }
+  RegisterValue reg_value;
+  if (reg_value.SetUInt(uint_value, reg_info.byte_size))
+    return WriteRegister(context, reg_info, reg_value);
   return false;
 }
 

diff  --git a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
index 14a30a5857fcf..a9ea14aee06a6 100644
--- a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
+++ b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
@@ -2713,7 +2713,7 @@ bool EmulateInstructionARM::EmulateVPOP(const uint32_t opcode,
       data = MemARead(context, addr, reg_byte_size, 0, &success);
       if (!success)
         return false;
-      if (!WriteRegisterUnsigned(context, &(*dwarf_reg), data))
+      if (!WriteRegisterUnsigned(context, *dwarf_reg, data))
         return false;
       addr += reg_byte_size;
     }

diff  --git a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
index e8a77a3c86519..7a8bd02a2d465 100644
--- a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
+++ b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
@@ -876,7 +876,7 @@ bool EmulateInstructionARM64::EmulateLDPSTP(const uint32_t opcode) {
     if (!vector && is_signed && !data_Rt.SignExtend(datasize))
       return false;
 
-    if (!WriteRegister(context_t, &(*reg_info_Rt), data_Rt))
+    if (!WriteRegister(context_t, *reg_info_Rt, data_Rt))
       return false;
 
     if (!rt_unknown) {
@@ -893,7 +893,7 @@ bool EmulateInstructionARM64::EmulateLDPSTP(const uint32_t opcode) {
     if (!vector && is_signed && !data_Rt2.SignExtend(datasize))
       return false;
 
-    if (!WriteRegister(context_t2, &(*reg_info_Rt2), data_Rt2))
+    if (!WriteRegister(context_t2, *reg_info_Rt2, data_Rt2))
       return false;
   } break;
 
@@ -910,7 +910,7 @@ bool EmulateInstructionARM64::EmulateLDPSTP(const uint32_t opcode) {
       context.type = eContextAdjustStackPointer;
     else
       context.type = eContextAdjustBaseRegister;
-    WriteRegisterUnsigned(context, &(*reg_info_base), wb_address);
+    WriteRegisterUnsigned(context, *reg_info_base, wb_address);
   }
   return true;
 }
@@ -1023,7 +1023,7 @@ bool EmulateInstructionARM64::EmulateLDRSTRImm(const uint32_t opcode) {
                                   error) == 0)
       return false;
 
-    if (!WriteRegister(context, &(*reg_info_Rt), data_Rt))
+    if (!WriteRegister(context, *reg_info_Rt, data_Rt))
       return false;
     break;
   default:
@@ -1040,7 +1040,7 @@ bool EmulateInstructionARM64::EmulateLDRSTRImm(const uint32_t opcode) {
       context.type = eContextAdjustBaseRegister;
     context.SetImmediateSigned(offset);
 
-    if (!WriteRegisterUnsigned(context, &(*reg_info_base), address))
+    if (!WriteRegisterUnsigned(context, *reg_info_base, address))
       return false;
   }
   return true;

diff  --git a/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp b/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
index d8a05fb19f783..ef9d94e8c4478 100644
--- a/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
+++ b/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
@@ -1321,7 +1321,7 @@ bool EmulateInstructionMIPS::Emulate_LW(llvm::MCInst &insn) {
     context.type = eContextPopRegisterOffStack;
     context.SetAddress(address);
 
-    return WriteRegister(context, &(*reg_info_src), data_src);
+    return WriteRegister(context, *reg_info_src, data_src);
   }
 
   return false;
@@ -1661,7 +1661,7 @@ bool EmulateInstructionMIPS::Emulate_LWSP(llvm::MCInst &insn) {
     context.type = eContextPopRegisterOffStack;
     context.SetAddress(base_address);
 
-    return WriteRegister(context, &(*reg_info_src), data_src);
+    return WriteRegister(context, *reg_info_src, data_src);
   }
 
   return false;
@@ -1723,7 +1723,7 @@ bool EmulateInstructionMIPS::Emulate_LWM16_32(llvm::MCInst &insn) {
     context.type = eContextPopRegisterOffStack;
     context.SetAddress(base_address + (i * 4));
 
-    if (!WriteRegister(context, &(*reg_info_dst), data_dst))
+    if (!WriteRegister(context, *reg_info_dst, data_dst))
       return false;
   }
 

diff  --git a/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp b/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp
index b699ae892ad4f..497d0a99fec20 100644
--- a/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp
+++ b/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp
@@ -1217,7 +1217,7 @@ bool EmulateInstructionMIPS64::Emulate_LD(llvm::MCInst &insn) {
     Context context;
     context.type = eContextRegisterLoad;
 
-    return WriteRegister(context, &(*reg_info_src), data_src);
+    return WriteRegister(context, *reg_info_src, data_src);
   }
 
   return false;


        


More information about the lldb-commits mailing list