From 35b0b244401aad5ca3a16c9e4d97a5892ca7592b Mon Sep 17 00:00:00 2001 From: Alex Langford Date: Fri, 9 Jun 2023 16:27:49 -0700 Subject: [PATCH] [lldb] Introduce DynamicRegisterInfo::CreateFromDict I want to add some error handling to DynamicRegisterInfo because there are many operations that can fail and many of these operations do not give meaningful information back to the caller. To begin that process, I want to add a static method that is responsible for creating a DynamicRegisterInfo from a StructuredData::Dictionary (and ArchSpec). This is meant to replace the equivalent constructor because constructors are ill-equipped to perform error handling. Differential Revision: https://reviews.llvm.org/D152594 --- lldb/include/lldb/Target/DynamicRegisterInfo.h | 4 ++-- .../OperatingSystem/Python/OperatingSystemPython.cpp | 3 ++- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp | 2 +- lldb/source/Target/DynamicRegisterInfo.cpp | 15 +++++++++++---- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lldb/include/lldb/Target/DynamicRegisterInfo.h b/lldb/include/lldb/Target/DynamicRegisterInfo.h index 1b1df84..22ad633 100644 --- a/lldb/include/lldb/Target/DynamicRegisterInfo.h +++ b/lldb/include/lldb/Target/DynamicRegisterInfo.h @@ -46,8 +46,8 @@ public: DynamicRegisterInfo() = default; - DynamicRegisterInfo(const lldb_private::StructuredData::Dictionary &dict, - const lldb_private::ArchSpec &arch); + static std::unique_ptr + Create(const StructuredData::Dictionary &dict, const ArchSpec &arch); virtual ~DynamicRegisterInfo() = default; diff --git a/lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp b/lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp index c22003f..9560ae1 100644 --- a/lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp +++ b/lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp @@ -128,8 +128,9 @@ DynamicRegisterInfo *OperatingSystemPython::GetDynamicRegisterInfo() { if (!dictionary) return nullptr; - m_register_info_up = std::make_unique( + m_register_info_up = DynamicRegisterInfo::Create( *dictionary, m_process->GetTarget().GetArchitecture()); + assert(m_register_info_up); assert(m_register_info_up->GetNumRegisters() > 0); assert(m_register_info_up->GetNumRegisterSets() > 0); } diff --git a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp index ac707ff..fa2ee72 100644 --- a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp +++ b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp @@ -341,7 +341,7 @@ std::shared_ptr ScriptedThread::GetDynamicRegisterInfo() { LLVM_PRETTY_FUNCTION, "Failed to get scripted thread registers info.", error, LLDBLog::Thread); - m_register_info_sp = std::make_shared( + m_register_info_sp = DynamicRegisterInfo::Create( *reg_info, m_scripted_process.GetTarget().GetArchitecture()); } diff --git a/lldb/source/Target/DynamicRegisterInfo.cpp b/lldb/source/Target/DynamicRegisterInfo.cpp index 7006199..d577e20 100644 --- a/lldb/source/Target/DynamicRegisterInfo.cpp +++ b/lldb/source/Target/DynamicRegisterInfo.cpp @@ -20,10 +20,17 @@ using namespace lldb; using namespace lldb_private; -DynamicRegisterInfo::DynamicRegisterInfo( - const lldb_private::StructuredData::Dictionary &dict, - const lldb_private::ArchSpec &arch) { - SetRegisterInfo(dict, arch); +std::unique_ptr +DynamicRegisterInfo::Create(const StructuredData::Dictionary &dict, + const ArchSpec &arch) { + auto dyn_reg_info = std::make_unique(); + if (!dyn_reg_info) + return nullptr; + + if (dyn_reg_info->SetRegisterInfo(dict, arch) == 0) + return nullptr; + + return dyn_reg_info; } DynamicRegisterInfo::DynamicRegisterInfo(DynamicRegisterInfo &&info) { -- 2.7.4