[LLDB] Change pointer to ref in EmulateInstruction::ReadRegister methods
authorDavid Spickett <david.spickett@linaro.org>
Wed, 28 Sep 2022 12:45:18 +0000 (12:45 +0000)
committerDavid Spickett <david.spickett@linaro.org>
Tue, 11 Oct 2022 12:31:55 +0000 (12:31 +0000)
ReadRegister and ReadRegisterAsUnsigned are always passed valid pointers,
so the parameter should be a ref to make the intent clear.

Reviewed By: clayborg

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

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

index dc15fe2..444059d 100644 (file)
@@ -388,9 +388,9 @@ public:
                                        uint32_t reg_num, std::string &reg_name);
 
   // RegisterInfo variants
-  bool ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value);
+  bool ReadRegister(const RegisterInfo &reg_info, RegisterValue &reg_value);
 
-  uint64_t ReadRegisterUnsigned(const RegisterInfo *reg_info,
+  uint64_t ReadRegisterUnsigned(const RegisterInfo &reg_info,
                                 uint64_t fail_value, bool *success_ptr);
 
   bool WriteRegister(const Context &context, const RegisterInfo *ref_info,
index b497b02..54d4d93 100644 (file)
@@ -72,10 +72,10 @@ EmulateInstruction::FindPlugin(const ArchSpec &arch,
 
 EmulateInstruction::EmulateInstruction(const ArchSpec &arch) : m_arch(arch) {}
 
-bool EmulateInstruction::ReadRegister(const RegisterInfo *reg_info,
+bool EmulateInstruction::ReadRegister(const RegisterInfo &reg_info,
                                       RegisterValue &reg_value) {
   if (m_read_reg_callback != nullptr)
-    return m_read_reg_callback(this, m_baton, reg_info, reg_value);
+    return m_read_reg_callback(this, m_baton, &reg_info, reg_value);
   return false;
 }
 
@@ -84,7 +84,7 @@ bool EmulateInstruction::ReadRegister(lldb::RegisterKind reg_kind,
                                       RegisterValue &reg_value) {
   llvm::Optional<RegisterInfo> reg_info = GetRegisterInfo(reg_kind, reg_num);
   if (reg_info)
-    return ReadRegister(&(*reg_info), reg_value);
+    return ReadRegister(*reg_info, reg_value);
   return false;
 }
 
@@ -100,7 +100,7 @@ uint64_t EmulateInstruction::ReadRegisterUnsigned(lldb::RegisterKind reg_kind,
   return fail_value;
 }
 
-uint64_t EmulateInstruction::ReadRegisterUnsigned(const RegisterInfo *reg_info,
+uint64_t EmulateInstruction::ReadRegisterUnsigned(const RegisterInfo &reg_info,
                                                   uint64_t fail_value,
                                                   bool *success_ptr) {
   RegisterValue reg_value;
index d71fff3..14a30a5 100644 (file)
@@ -2620,7 +2620,7 @@ bool EmulateInstructionARM::EmulateVPUSH(const uint32_t opcode,
           GetRegisterInfo(eRegisterKindDWARF, start_reg + d + i);
       context.SetRegisterToRegisterPlusOffset(*dwarf_reg, *sp_reg, addr - sp);
       // uint64_t to accommodate 64-bit registers.
-      uint64_t reg_value = ReadRegisterUnsigned(&(*dwarf_reg), 0, &success);
+      uint64_t reg_value = ReadRegisterUnsigned(*dwarf_reg, 0, &success);
       if (!success)
         return false;
       if (!MemAWrite(context, addr, reg_value, reg_byte_size))
index 92af4da..e8a77a3 100644 (file)
@@ -824,7 +824,7 @@ bool EmulateInstructionARM64::EmulateLDPSTP(const uint32_t opcode) {
     context_t2.SetRegisterToRegisterPlusOffset(*reg_info_Rt2, *reg_info_base,
                                                size);
 
-    if (!ReadRegister(&(*reg_info_Rt), data_Rt))
+    if (!ReadRegister(*reg_info_Rt, data_Rt))
       return false;
 
     if (data_Rt.GetAsMemoryData(&(*reg_info_Rt), buffer, reg_info_Rt->byte_size,
@@ -834,7 +834,7 @@ bool EmulateInstructionARM64::EmulateLDPSTP(const uint32_t opcode) {
     if (!WriteMemory(context_t, address + 0, buffer, reg_info_Rt->byte_size))
       return false;
 
-    if (!ReadRegister(&(*reg_info_Rt2), data_Rt2))
+    if (!ReadRegister(*reg_info_Rt2, data_Rt2))
       return false;
 
     if (data_Rt2.GetAsMemoryData(&(*reg_info_Rt2), buffer,
@@ -995,7 +995,7 @@ bool EmulateInstructionARM64::EmulateLDRSTRImm(const uint32_t opcode) {
     context.SetRegisterToRegisterPlusOffset(*reg_info_Rt, *reg_info_base,
                                             postindex ? 0 : offset);
 
-    if (!ReadRegister(&(*reg_info_Rt), data_Rt))
+    if (!ReadRegister(*reg_info_Rt, data_Rt))
       return false;
 
     if (data_Rt.GetAsMemoryData(&(*reg_info_Rt), buffer, reg_info_Rt->byte_size,
index 060b631..d8a05fb 100644 (file)
@@ -1266,7 +1266,7 @@ bool EmulateInstructionMIPS::Emulate_SW(llvm::MCInst &insn) {
     uint8_t buffer[RegisterValue::kMaxRegisterByteSize];
     Status error;
 
-    if (!ReadRegister(&(*reg_info_base), data_src))
+    if (!ReadRegister(*reg_info_base, data_src))
       return false;
 
     if (data_src.GetAsMemoryData(&(*reg_info_src), buffer,
@@ -1526,7 +1526,7 @@ bool EmulateInstructionMIPS::Emulate_SWSP(llvm::MCInst &insn) {
     uint8_t buffer[RegisterValue::kMaxRegisterByteSize];
     Status error;
 
-    if (!ReadRegister(&(*reg_info_base), data_src))
+    if (!ReadRegister(*reg_info_base, data_src))
       return false;
 
     if (data_src.GetAsMemoryData(&reg_info_src, buffer, reg_info_src.byte_size,
@@ -1608,7 +1608,7 @@ bool EmulateInstructionMIPS::Emulate_SWM16_32(llvm::MCInst &insn) {
     uint8_t buffer[RegisterValue::kMaxRegisterByteSize];
     Status error;
 
-    if (!ReadRegister(&(*reg_info_base), data_src))
+    if (!ReadRegister(*reg_info_base, data_src))
       return false;
 
     if (data_src.GetAsMemoryData(&(*reg_info_src), buffer,
index 14041c7..b699ae8 100644 (file)
@@ -1160,7 +1160,7 @@ bool EmulateInstructionMIPS64::Emulate_SD(llvm::MCInst &insn) {
     uint8_t buffer[RegisterValue::kMaxRegisterByteSize];
     Status error;
 
-    if (!ReadRegister(&(*reg_info_base), data_src))
+    if (!ReadRegister(*reg_info_base, data_src))
       return false;
 
     if (data_src.GetAsMemoryData(&(*reg_info_src), buffer,