From 812ad2167bd2e27f5d0dee07bb03a5910616e0b6 Mon Sep 17 00:00:00 2001 From: David Spickett Date: Wed, 28 Sep 2022 14:24:57 +0000 Subject: [PATCH] [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 --- lldb/include/lldb/Utility/RegisterValue.h | 2 +- lldb/source/Host/common/NativeRegisterContext.cpp | 2 +- .../Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp | 12 +++++------- .../Process/Linux/NativeRegisterContextLinux_arm64.cpp | 2 +- .../Process/elf-core/RegisterContextPOSIXCore_arm64.cpp | 10 +++++----- .../Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp | 2 +- .../Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp | 2 +- .../Process/minidump/RegisterContextMinidump_ARM.cpp | 2 +- .../Process/minidump/RegisterContextMinidump_ARM64.cpp | 2 +- lldb/source/Target/RegisterContext.cpp | 2 +- lldb/source/Utility/RegisterValue.cpp | 13 ++++--------- lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp | 2 +- 12 files changed, 23 insertions(+), 30 deletions(-) diff --git a/lldb/include/lldb/Utility/RegisterValue.h b/lldb/include/lldb/Utility/RegisterValue.h index b39e298..38decf4 100644 --- a/lldb/include/lldb/Utility/RegisterValue.h +++ b/lldb/include/lldb/Utility/RegisterValue.h @@ -99,7 +99,7 @@ public: 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 ®_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 0110a8a..1be519d 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 070cc31..4488b45 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 61e784e..6c04f77 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 bb88ce9..22a9996 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 6bc8edb..845312f 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 7ad4f49..f14173b 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 f326120..9e1e431 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 ®_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 bceaaa8..7819018 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 ®_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 e66f071..ee344b0 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 b9489bf..90ba2e0 100644 --- a/lldb/source/Utility/RegisterValue.cpp +++ b/lldb/source/Utility/RegisterValue.cpp @@ -76,15 +76,10 @@ uint32_t RegisterValue::GetAsMemoryData(const RegisterInfo ®_info, void *dst, return bytes_copied; } -uint32_t RegisterValue::SetFromMemoryData(const RegisterInfo *reg_info, +uint32_t RegisterValue::SetFromMemoryData(const RegisterInfo ®_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(®_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 61d4e81..eb30aaa 100644 --- a/lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp +++ b/lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp @@ -215,7 +215,7 @@ Expected 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(); -- 2.7.4