[Lldb-commits] [PATCH] D152594: [lldb] Introduce DynamicRegisterInfo::CreateFromDict

Alex Langford via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 9 16:40:15 PDT 2023


bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, mib, jingham, jasonmolenda, mgorny.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152594

Files:
  lldb/include/lldb/Target/DynamicRegisterInfo.h
  lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Target/DynamicRegisterInfo.cpp


Index: lldb/source/Target/DynamicRegisterInfo.cpp
===================================================================
--- lldb/source/Target/DynamicRegisterInfo.cpp
+++ 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>
+DynamicRegisterInfo::CreateFromDict(const StructuredData::Dictionary &dict,
+                                    const ArchSpec &arch) {
+  auto dyn_reg_info = std::make_unique<DynamicRegisterInfo>();
+  if (!dyn_reg_info)
+    return nullptr;
+
+  if (dyn_reg_info->SetRegisterInfo(dict, arch) == 0)
+    return nullptr;
+
+  return dyn_reg_info;
 }
 
 DynamicRegisterInfo::DynamicRegisterInfo(DynamicRegisterInfo &&info) {
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===================================================================
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -341,7 +341,7 @@
           LLVM_PRETTY_FUNCTION, "Failed to get scripted thread registers info.",
           error, LLDBLog::Thread);
 
-    m_register_info_sp = std::make_shared<DynamicRegisterInfo>(
+    m_register_info_sp = DynamicRegisterInfo::CreateFromDict(
         *reg_info, m_scripted_process.GetTarget().GetArchitecture());
   }
 
Index: lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
===================================================================
--- lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
+++ lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
@@ -128,8 +128,9 @@
     if (!dictionary)
       return nullptr;
 
-    m_register_info_up = std::make_unique<DynamicRegisterInfo>(
+    m_register_info_up = DynamicRegisterInfo::CreateFromDict(
         *dictionary, m_process->GetTarget().GetArchitecture());
+    assert(m_register_info_up);
     assert(m_register_info_up->GetNumRegisters() > 0);
     assert(m_register_info_up->GetNumRegisterSets() > 0);
   }
Index: lldb/include/lldb/Target/DynamicRegisterInfo.h
===================================================================
--- lldb/include/lldb/Target/DynamicRegisterInfo.h
+++ lldb/include/lldb/Target/DynamicRegisterInfo.h
@@ -46,8 +46,8 @@
 
   DynamicRegisterInfo() = default;
 
-  DynamicRegisterInfo(const lldb_private::StructuredData::Dictionary &dict,
-                      const lldb_private::ArchSpec &arch);
+  static std::unique_ptr<DynamicRegisterInfo>
+  CreateFromDict(const StructuredData::Dictionary &dict, const ArchSpec &arch);
 
   virtual ~DynamicRegisterInfo() = default;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152594.530113.patch
Type: text/x-patch
Size: 2825 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230609/511b04ae/attachment.bin>


More information about the lldb-commits mailing list