[Lldb-commits] [lldb] 6faa345 - [LLDB] Pass const RegisterInfo& to RegisterValue::SetValueFromData

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


Author: David Spickett
Date: 2022-10-12T08:19:30Z
New Revision: 6faa345da9d747c65c4d901c4ef26dfedf95da45

URL: https://github.com/llvm/llvm-project/commit/6faa345da9d747c65c4d901c4ef26dfedf95da45
DIFF: https://github.com/llvm/llvm-project/commit/6faa345da9d747c65c4d901c4ef26dfedf95da45.diff

LOG: [LLDB] Pass const RegisterInfo& to RegisterValue::SetValueFromData

Familiar story, callers are either checking upfront that the pointer
wasn't null or not checking at all. SetValueFromData itself didn't
check either.

So make the parameter a ref and fixup the few places where a nullptr
check seems needed.

Depends on D135668

Reviewed By: clayborg

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

Added: 
    

Modified: 
    lldb/include/lldb/Utility/RegisterValue.h
    lldb/source/Core/ValueObjectRegister.cpp
    lldb/source/Core/ValueObjectVariable.cpp
    lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
    lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp
    lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp
    lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
    lldb/source/Utility/RegisterValue.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Utility/RegisterValue.h b/lldb/include/lldb/Utility/RegisterValue.h
index 38decf4f9d883..3a3c0a07f8f4c 100644
--- a/lldb/include/lldb/Utility/RegisterValue.h
+++ b/lldb/include/lldb/Utility/RegisterValue.h
@@ -238,7 +238,7 @@ class RegisterValue {
   Status SetValueFromString(const RegisterInfo *reg_info,
                             const char *value_str) = delete;
 
-  Status SetValueFromData(const RegisterInfo *reg_info, DataExtractor &data,
+  Status SetValueFromData(const RegisterInfo &reg_info, DataExtractor &data,
                           lldb::offset_t offset, bool partial_data_ok);
 
   const void *GetBytes() const;

diff  --git a/lldb/source/Core/ValueObjectRegister.cpp b/lldb/source/Core/ValueObjectRegister.cpp
index 2aa0c68ba40f5..98fbbd62c6a78 100644
--- a/lldb/source/Core/ValueObjectRegister.cpp
+++ b/lldb/source/Core/ValueObjectRegister.cpp
@@ -282,7 +282,7 @@ bool ValueObjectRegister::SetValueFromCString(const char *value_str,
 }
 
 bool ValueObjectRegister::SetData(DataExtractor &data, Status &error) {
-  error = m_reg_value.SetValueFromData(&m_reg_info, data, 0, false);
+  error = m_reg_value.SetValueFromData(m_reg_info, data, 0, false);
   if (!error.Success())
     return false;
 

diff  --git a/lldb/source/Core/ValueObjectVariable.cpp b/lldb/source/Core/ValueObjectVariable.cpp
index 4e2bd12c10532..e98d117cb258b 100644
--- a/lldb/source/Core/ValueObjectVariable.cpp
+++ b/lldb/source/Core/ValueObjectVariable.cpp
@@ -398,7 +398,7 @@ bool ValueObjectVariable::SetData(DataExtractor &data, Status &error) {
       error.SetErrorString("unable to retrieve register info");
       return false;
     }
-    error = reg_value.SetValueFromData(reg_info, data, 0, true);
+    error = reg_value.SetValueFromData(*reg_info, data, 0, true);
     if (error.Fail())
       return false;
     if (reg_ctx->WriteRegister(reg_info, reg_value)) {

diff  --git a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
index d942d53376e86..6739cedcbc8bd 100644
--- a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
+++ b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
@@ -304,7 +304,7 @@ ABIMacOSX_arm64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
             if (byte_size <= 16) {
               if (byte_size <= RegisterValue::GetMaxByteSize()) {
                 RegisterValue reg_value;
-                error = reg_value.SetValueFromData(v0_info, data, 0, true);
+                error = reg_value.SetValueFromData(*v0_info, data, 0, true);
                 if (error.Success()) {
                   if (!reg_ctx->WriteRegister(v0_info, reg_value))
                     error.SetErrorString("failed to write register v0");
@@ -331,7 +331,7 @@ ABIMacOSX_arm64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
         if (v0_info) {
           if (byte_size <= v0_info->byte_size) {
             RegisterValue reg_value;
-            error = reg_value.SetValueFromData(v0_info, data, 0, true);
+            error = reg_value.SetValueFromData(*v0_info, data, 0, true);
             if (error.Success()) {
               if (!reg_ctx->WriteRegister(v0_info, reg_value))
                 error.SetErrorString("failed to write register v0");

diff  --git a/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp b/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp
index c8130e704ecc0..de54ddee826e6 100644
--- a/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp
+++ b/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp
@@ -277,7 +277,7 @@ Status ABISysV_arm64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
             if (byte_size <= 16) {
               if (byte_size <= RegisterValue::GetMaxByteSize()) {
                 RegisterValue reg_value;
-                error = reg_value.SetValueFromData(v0_info, data, 0, true);
+                error = reg_value.SetValueFromData(*v0_info, data, 0, true);
                 if (error.Success()) {
                   if (!reg_ctx->WriteRegister(v0_info, reg_value))
                     error.SetErrorString("failed to write register v0");
@@ -304,7 +304,7 @@ Status ABISysV_arm64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
         if (v0_info) {
           if (byte_size <= v0_info->byte_size) {
             RegisterValue reg_value;
-            error = reg_value.SetValueFromData(v0_info, data, 0, true);
+            error = reg_value.SetValueFromData(*v0_info, data, 0, true);
             if (error.Success()) {
               if (!reg_ctx->WriteRegister(v0_info, reg_value))
                 error.SetErrorString("failed to write register v0");

diff  --git a/lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp
index ead8c4b4a80d9..84a19d5b13035 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp
@@ -81,7 +81,7 @@ bool RegisterContextMemory::ReadRegister(const RegisterInfo *reg_info,
   }
   const bool partial_data_ok = false;
   return reg_value
-      .SetValueFromData(reg_info, m_reg_data, reg_info->byte_offset,
+      .SetValueFromData(*reg_info, m_reg_data, reg_info->byte_offset,
                         partial_data_ok)
       .Success();
 }

diff  --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
index f14173bdc0788..8ea93655d6bbf 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -112,7 +112,7 @@ bool GDBRemoteRegisterContext::ReadRegister(const RegisterInfo *reg_info,
     } else {
       const bool partial_data_ok = false;
       Status error(value.SetValueFromData(
-          reg_info, m_reg_data, reg_info->byte_offset, partial_data_ok));
+          *reg_info, m_reg_data, reg_info->byte_offset, partial_data_ok));
       return error.Success();
     }
   }

diff  --git a/lldb/source/Utility/RegisterValue.cpp b/lldb/source/Utility/RegisterValue.cpp
index 90ba2e0261227..f1d37b0e0cbe9 100644
--- a/lldb/source/Utility/RegisterValue.cpp
+++ b/lldb/source/Utility/RegisterValue.cpp
@@ -115,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;
 
@@ -150,16 +150,20 @@ bool RegisterValue::GetScalarValue(Scalar &scalar) const {
 void RegisterValue::Clear() { m_type = eTypeInvalid; }
 
 RegisterValue::Type RegisterValue::SetType(const RegisterInfo *reg_info) {
+  assert(reg_info && "Expected non null reg_info.");
   // To change the type, we simply copy the data in again, using the new format
   RegisterValue copy;
   DataExtractor copy_data;
-  if (copy.CopyValue(*this) && copy.GetData(copy_data))
-    SetValueFromData(reg_info, copy_data, 0, true);
+  if (copy.CopyValue(*this) && copy.GetData(copy_data)) {
+    Status error = SetValueFromData(*reg_info, copy_data, 0, true);
+    assert(error.Success() && "Expected SetValueFromData to succeed.");
+    UNUSED_IF_ASSERT_DISABLED(error);
+  }
 
   return m_type;
 }
 
-Status RegisterValue::SetValueFromData(const RegisterInfo *reg_info,
+Status RegisterValue::SetValueFromData(const RegisterInfo &reg_info,
                                        DataExtractor &src,
                                        lldb::offset_t src_offset,
                                        bool partial_data_ok) {
@@ -170,22 +174,22 @@ Status RegisterValue::SetValueFromData(const RegisterInfo *reg_info,
     return error;
   }
 
-  if (reg_info->byte_size == 0) {
+  if (reg_info.byte_size == 0) {
     error.SetErrorString("invalid register info.");
     return error;
   }
 
   uint32_t src_len = src.GetByteSize() - src_offset;
 
-  if (!partial_data_ok && (src_len < reg_info->byte_size)) {
+  if (!partial_data_ok && (src_len < reg_info.byte_size)) {
     error.SetErrorString("not enough data.");
     return error;
   }
 
   // Cap the data length if there is more than enough bytes for this register
   // value
-  if (src_len > reg_info->byte_size)
-    src_len = reg_info->byte_size;
+  if (src_len > reg_info.byte_size)
+    src_len = reg_info.byte_size;
 
   // Zero out the value in case we get partial data...
   memset(buffer.bytes, 0, sizeof(buffer.bytes));
@@ -193,20 +197,20 @@ Status RegisterValue::SetValueFromData(const RegisterInfo *reg_info,
   type128 int128;
 
   m_type = eTypeInvalid;
-  switch (reg_info->encoding) {
+  switch (reg_info.encoding) {
   case eEncodingInvalid:
     break;
   case eEncodingUint:
   case eEncodingSint:
-    if (reg_info->byte_size == 1)
+    if (reg_info.byte_size == 1)
       SetUInt8(src.GetMaxU32(&src_offset, src_len));
-    else if (reg_info->byte_size <= 2)
+    else if (reg_info.byte_size <= 2)
       SetUInt16(src.GetMaxU32(&src_offset, src_len));
-    else if (reg_info->byte_size <= 4)
+    else if (reg_info.byte_size <= 4)
       SetUInt32(src.GetMaxU32(&src_offset, src_len));
-    else if (reg_info->byte_size <= 8)
+    else if (reg_info.byte_size <= 8)
       SetUInt64(src.GetMaxU64(&src_offset, src_len));
-    else if (reg_info->byte_size <= 16) {
+    else if (reg_info.byte_size <= 16) {
       uint64_t data1 = src.GetU64(&src_offset);
       uint64_t data2 = src.GetU64(&src_offset);
       if (src.GetByteSize() == eByteOrderBig) {
@@ -220,16 +224,16 @@ Status RegisterValue::SetValueFromData(const RegisterInfo *reg_info,
     }
     break;
   case eEncodingIEEE754:
-    if (reg_info->byte_size == sizeof(float))
+    if (reg_info.byte_size == sizeof(float))
       SetFloat(src.GetFloat(&src_offset));
-    else if (reg_info->byte_size == sizeof(double))
+    else if (reg_info.byte_size == sizeof(double))
       SetDouble(src.GetDouble(&src_offset));
-    else if (reg_info->byte_size == sizeof(long double))
+    else if (reg_info.byte_size == sizeof(long double))
       SetLongDouble(src.GetLongDouble(&src_offset));
     break;
   case eEncodingVector: {
     m_type = eTypeBytes;
-    buffer.length = reg_info->byte_size;
+    buffer.length = reg_info.byte_size;
     buffer.byte_order = src.GetByteOrder();
     assert(buffer.length <= kMaxRegisterByteSize);
     if (buffer.length > kMaxRegisterByteSize)
@@ -242,7 +246,7 @@ Status RegisterValue::SetValueFromData(const RegisterInfo *reg_info,
             buffer.byte_order) == 0) // dst byte order
     {
       error.SetErrorStringWithFormat(
-          "failed to copy data for register write of %s", reg_info->name);
+          "failed to copy data for register write of %s", reg_info.name);
       return error;
     }
   }
@@ -250,7 +254,7 @@ Status RegisterValue::SetValueFromData(const RegisterInfo *reg_info,
 
   if (m_type == eTypeInvalid)
     error.SetErrorStringWithFormat(
-        "invalid register value type for register %s", reg_info->name);
+        "invalid register value type for register %s", reg_info.name);
   return error;
 }
 


        


More information about the lldb-commits mailing list