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
DynamicRegisterInfo() = default;
- DynamicRegisterInfo(const lldb_private::StructuredData::Dictionary &dict,
- const lldb_private::ArchSpec &arch);
+ static std::unique_ptr<DynamicRegisterInfo>
+ Create(const StructuredData::Dictionary &dict, const ArchSpec &arch);
virtual ~DynamicRegisterInfo() = default;
if (!dictionary)
return nullptr;
- m_register_info_up = std::make_unique<DynamicRegisterInfo>(
+ 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);
}
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::Create(
*reg_info, m_scripted_process.GetTarget().GetArchitecture());
}
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::Create(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) {