[Lldb-commits] [lldb] 812ad21 - [LLDB] Change RegisterValue::SetFromMemoryData to const RegisterInfo&

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 12 01:10:33 PDT 2022


Author: David Spickett
Date: 2022-10-12T08:10:24Z
New Revision: 812ad2167bd2e27f5d0dee07bb03a5910616e0b6

URL: https://github.com/llvm/llvm-project/commit/812ad2167bd2e27f5d0dee07bb03a5910616e0b6
DIFF: https://github.com/llvm/llvm-project/commit/812ad2167bd2e27f5d0dee07bb03a5910616e0b6.diff

LOG: [LLDB] Change RegisterValue::SetFromMemoryData to const RegisterInfo&

All callers were either assuming their pointer was not null before calling
this, or checking beforehand.

Reviewed By: clayborg

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

Added: 
    

Modified: 
    lldb/include/lldb/Utility/RegisterValue.h
    lldb/source/Host/common/NativeRegisterContext.cpp
    lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
    lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
    lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp
    lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
    lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
    lldb/source/Plugins/Process/minidump/RegisterContextMinidump_ARM.cpp
    lldb/source/Plugins/Process/minidump/RegisterContextMinidump_ARM64.cpp
    lldb/source/Target/RegisterContext.cpp
    lldb/source/Utility/RegisterValue.cpp
    lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Utility/RegisterValue.h b/lldb/include/lldb/Utility/RegisterValue.h
index b39e2980abacc..38decf4f9d883 100644
--- a/lldb/include/lldb/Utility/RegisterValue.h
+++ b/lldb/include/lldb/Utility/RegisterValue.h
@@ -99,7 +99,7 @@ class RegisterValue {
                            uint32_t dst_len, lldb::ByteOrder dst_byte_order,
                            Status &error) const;
 
-  uint32_t SetFromMemoryData(const RegisterInfo *reg_info, const void *src,
+  uint32_t SetFromMemoryData(const RegisterInfo &reg_info, const void *src,
                              uint32_t src_len, lldb::ByteOrder src_byte_order,
                              Status &error);
 

diff  --git a/lldb/source/Host/common/NativeRegisterContext.cpp b/lldb/source/Host/common/NativeRegisterContext.cpp
index 0110a8ac9e2d4..1be519d129eef 100644
--- a/lldb/source/Host/common/NativeRegisterContext.cpp
+++ b/lldb/source/Host/common/NativeRegisterContext.cpp
@@ -376,7 +376,7 @@ Status NativeRegisterContext::ReadRegisterValueFromMemory(
   // TODO: we might need to add a parameter to this function in case the byte
   // order of the memory data doesn't match the process. For now we are
   // assuming they are the same.
-  reg_value.SetFromMemoryData(reg_info, src, src_len, process.GetByteOrder(),
+  reg_value.SetFromMemoryData(*reg_info, src, src_len, process.GetByteOrder(),
                               error);
 
   return error;

diff  --git a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
index 070cc3112ab23..4488b45ef8abe 100644
--- a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
+++ b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
@@ -867,9 +867,8 @@ bool EmulateInstructionARM64::EmulateLDPSTP(const uint32_t opcode) {
         return false;
     }
 
-    if (data_Rt.SetFromMemoryData(&(*reg_info_Rt), buffer,
-                                  reg_info_Rt->byte_size, eByteOrderLittle,
-                                  error) == 0)
+    if (data_Rt.SetFromMemoryData(*reg_info_Rt, buffer, reg_info_Rt->byte_size,
+                                  eByteOrderLittle, error) == 0)
       return false;
 
     if (!vector && is_signed && !data_Rt.SignExtend(datasize))
@@ -884,7 +883,7 @@ bool EmulateInstructionARM64::EmulateLDPSTP(const uint32_t opcode) {
         return false;
     }
 
-    if (data_Rt2.SetFromMemoryData(&(*reg_info_Rt2), buffer,
+    if (data_Rt2.SetFromMemoryData(*reg_info_Rt2, buffer,
                                    reg_info_Rt2->byte_size, eByteOrderLittle,
                                    error) == 0)
       return false;
@@ -1017,9 +1016,8 @@ bool EmulateInstructionARM64::EmulateLDRSTRImm(const uint32_t opcode) {
     if (!ReadMemory(context, address, buffer, reg_info_Rt->byte_size))
       return false;
 
-    if (data_Rt.SetFromMemoryData(&(*reg_info_Rt), buffer,
-                                  reg_info_Rt->byte_size, eByteOrderLittle,
-                                  error) == 0)
+    if (data_Rt.SetFromMemoryData(*reg_info_Rt, buffer, reg_info_Rt->byte_size,
+                                  eByteOrderLittle, error) == 0)
       return false;
 
     if (!WriteRegister(context, *reg_info_Rt, data_Rt))

diff  --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
index 61e784e28ca68..6c04f77dbe268 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
@@ -284,7 +284,7 @@ NativeRegisterContextLinux_arm64::ReadRegister(const RegisterInfo *reg_info,
     return Status("failed - register wasn't recognized to be a GPR or an FPR, "
                   "write strategy unknown");
 
-  reg_value.SetFromMemoryData(reg_info, src, reg_info->byte_size,
+  reg_value.SetFromMemoryData(*reg_info, src, reg_info->byte_size,
                               eByteOrderLittle, error);
 
   return error;

diff  --git a/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp b/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp
index bb88ce9e9e502..22a9996b1a6e9 100644
--- a/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp
+++ b/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp
@@ -147,7 +147,7 @@ bool RegisterContextCorePOSIX_arm64::ReadRegister(const RegisterInfo *reg_info,
       // SVE is disabled take legacy route for FPU register access
       offset -= GetGPRSize();
       if (offset < m_fpr_data.GetByteSize()) {
-        value.SetFromMemoryData(reg_info, m_fpr_data.GetDataStart() + offset,
+        value.SetFromMemoryData(*reg_info, m_fpr_data.GetDataStart() + offset,
                                 reg_info->byte_size, lldb::eByteOrderLittle,
                                 error);
         return error.Success();
@@ -180,7 +180,7 @@ bool RegisterContextCorePOSIX_arm64::ReadRegister(const RegisterInfo *reg_info,
 
       assert(sve_reg_num != LLDB_INVALID_REGNUM);
       assert(offset < m_sve_data.GetByteSize());
-      value.SetFromMemoryData(reg_info, GetSVEBuffer(offset),
+      value.SetFromMemoryData(*reg_info, GetSVEBuffer(offset),
                               reg_info->byte_size, lldb::eByteOrderLittle,
                               error);
     }
@@ -204,13 +204,13 @@ bool RegisterContextCorePOSIX_arm64::ReadRegister(const RegisterInfo *reg_info,
         assert(offset < m_sve_data.GetByteSize());
         src = GetSVEBuffer(offset);
       }
-      value.SetFromMemoryData(reg_info, src, byte_size, lldb::eByteOrderLittle,
+      value.SetFromMemoryData(*reg_info, src, byte_size, lldb::eByteOrderLittle,
                               error);
     } break;
     case SVEState::Full:
       offset = CalculateSVEOffset(reg_info);
       assert(offset < m_sve_data.GetByteSize());
-      value.SetFromMemoryData(reg_info, GetSVEBuffer(offset),
+      value.SetFromMemoryData(*reg_info, GetSVEBuffer(offset),
                               reg_info->byte_size, lldb::eByteOrderLittle,
                               error);
       break;
@@ -221,7 +221,7 @@ bool RegisterContextCorePOSIX_arm64::ReadRegister(const RegisterInfo *reg_info,
   } else if (IsPAuth(reg)) {
     offset = reg_info->byte_offset - m_register_info_up->GetPAuthOffset();
     assert(offset < m_pac_data.GetByteSize());
-    value.SetFromMemoryData(reg_info, m_pac_data.GetDataStart() + offset,
+    value.SetFromMemoryData(*reg_info, m_pac_data.GetDataStart() + offset,
                             reg_info->byte_size, lldb::eByteOrderLittle, error);
   } else
     return false;

diff  --git a/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp b/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
index 6bc8edb9226f0..845312f4c1edd 100644
--- a/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
+++ b/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
@@ -73,7 +73,7 @@ bool RegisterContextCorePOSIX_x86_64::ReadRegister(const RegisterInfo *reg_info,
   }
 
   Status error;
-  value.SetFromMemoryData(reg_info, src + offset, reg_info->byte_size,
+  value.SetFromMemoryData(*reg_info, src + offset, reg_info->byte_size,
                           lldb::eByteOrderLittle, error);
 
   return error.Success();

diff  --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
index 7ad4f4968eac9..f14173bdc0788 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -107,7 +107,7 @@ bool GDBRemoteRegisterContext::ReadRegister(const RegisterInfo *reg_info,
 
       Status error;
       return value.SetFromMemoryData(
-                 reg_info, combined_data.data(), combined_data.size(),
+                 *reg_info, combined_data.data(), combined_data.size(),
                  m_reg_data.GetByteOrder(), error) == combined_data.size();
     } else {
       const bool partial_data_ok = false;

diff  --git a/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_ARM.cpp b/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_ARM.cpp
index f3261201264d8..9e1e4317cd14f 100644
--- a/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_ARM.cpp
+++ b/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_ARM.cpp
@@ -521,7 +521,7 @@ bool RegisterContextMinidump_ARM::ReadRegister(const RegisterInfo *reg_info,
                                                RegisterValue &reg_value) {
   Status error;
   reg_value.SetFromMemoryData(
-      reg_info, (const uint8_t *)&m_regs + reg_info->byte_offset,
+      *reg_info, (const uint8_t *)&m_regs + reg_info->byte_offset,
       reg_info->byte_size, lldb::eByteOrderLittle, error);
   return error.Success();
 }

diff  --git a/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_ARM64.cpp b/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_ARM64.cpp
index bceaaa8935d0d..78190182f548f 100644
--- a/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_ARM64.cpp
+++ b/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_ARM64.cpp
@@ -806,7 +806,7 @@ bool RegisterContextMinidump_ARM64::ReadRegister(const RegisterInfo *reg_info,
                                                  RegisterValue &reg_value) {
   Status error;
   reg_value.SetFromMemoryData(
-      reg_info, (const uint8_t *)&m_regs + reg_info->byte_offset,
+      *reg_info, (const uint8_t *)&m_regs + reg_info->byte_offset,
       reg_info->byte_size, lldb::eByteOrderLittle, error);
   return error.Success();
 }

diff  --git a/lldb/source/Target/RegisterContext.cpp b/lldb/source/Target/RegisterContext.cpp
index e66f0717cdd7c..ee344b01c6b8a 100644
--- a/lldb/source/Target/RegisterContext.cpp
+++ b/lldb/source/Target/RegisterContext.cpp
@@ -357,7 +357,7 @@ Status RegisterContext::ReadRegisterValueFromMemory(
     // TODO: we might need to add a parameter to this function in case the byte
     // order of the memory data doesn't match the process. For now we are
     // assuming they are the same.
-    reg_value.SetFromMemoryData(reg_info, src, src_len,
+    reg_value.SetFromMemoryData(*reg_info, src, src_len,
                                 process_sp->GetByteOrder(), error);
   } else
     error.SetErrorString("invalid process");

diff  --git a/lldb/source/Utility/RegisterValue.cpp b/lldb/source/Utility/RegisterValue.cpp
index b9489bf00be95..90ba2e0261227 100644
--- a/lldb/source/Utility/RegisterValue.cpp
+++ b/lldb/source/Utility/RegisterValue.cpp
@@ -76,15 +76,10 @@ uint32_t RegisterValue::GetAsMemoryData(const RegisterInfo &reg_info, void *dst,
   return bytes_copied;
 }
 
-uint32_t RegisterValue::SetFromMemoryData(const RegisterInfo *reg_info,
+uint32_t RegisterValue::SetFromMemoryData(const RegisterInfo &reg_info,
                                           const void *src, uint32_t src_len,
                                           lldb::ByteOrder src_byte_order,
                                           Status &error) {
-  if (reg_info == nullptr) {
-    error.SetErrorString("invalid register info argument.");
-    return 0;
-  }
-
   // Moving from addr into a register
   //
   // Case 1: src_len == dst_len
@@ -107,12 +102,12 @@ uint32_t RegisterValue::SetFromMemoryData(const RegisterInfo *reg_info,
     return 0;
   }
 
-  const uint32_t dst_len = reg_info->byte_size;
+  const uint32_t dst_len = reg_info.byte_size;
 
   if (src_len > dst_len) {
     error.SetErrorStringWithFormat(
         "%u bytes is too big to store in register %s (%u bytes)", src_len,
-        reg_info->name, dst_len);
+        reg_info.name, dst_len);
     return 0;
   }
 
@@ -120,7 +115,7 @@ uint32_t RegisterValue::SetFromMemoryData(const RegisterInfo *reg_info,
   // register value
   DataExtractor src_data(src, src_len, src_byte_order, 4);
 
-  error = SetValueFromData(reg_info, src_data, 0, true);
+  error = SetValueFromData(&reg_info, src_data, 0, true);
   if (error.Fail())
     return 0;
 

diff  --git a/lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp b/lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp
index 61d4e8147a39b..eb30aaa54180d 100644
--- a/lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp
+++ b/lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp
@@ -215,7 +215,7 @@ Expected<RegisterValue> parseRegisterValue(const RegisterInfo &Info,
   RegisterValue Value;
   Status ST;
   Value.SetFromMemoryData(
-      &Info, Bytes.data(), Bytes.size(),
+      Info, Bytes.data(), Bytes.size(),
       Endian == support::little ? eByteOrderLittle : eByteOrderBig, ST);
   if (ST.Fail())
     return ST.ToError();


        


More information about the lldb-commits mailing list