[Lldb-commits] [PATCH] D150235: [lldb] Change definition of DisassemblerCreateInstance
Alex Langford via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue May 9 17:06:05 PDT 2023
bulbazord created this revision.
bulbazord added reviewers: jingham, mib, JDevlieghere.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
DissassemblerCreateInstance is a function pointer whos return type is
`Disassembler *`. But Disassembler::FindPlugin always returns a
DisassemblerSP, so there's no reason why we can't just create a
DisassemblerSP in the first place.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D150235
Files:
lldb/include/lldb/lldb-private-interfaces.h
lldb/source/Core/Disassembler.cpp
lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
===================================================================
--- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
+++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
@@ -34,8 +34,8 @@
static llvm::StringRef GetPluginNameStatic() { return "llvm-mc"; }
- static lldb_private::Disassembler *
- CreateInstance(const lldb_private::ArchSpec &arch, const char *flavor);
+ static lldb::DisassemblerSP CreateInstance(const lldb_private::ArchSpec &arch,
+ const char *flavor);
size_t DecodeInstructions(const lldb_private::Address &base_addr,
const lldb_private::DataExtractor &data,
Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
===================================================================
--- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -1572,16 +1572,14 @@
DisassemblerLLVMC::~DisassemblerLLVMC() = default;
-Disassembler *DisassemblerLLVMC::CreateInstance(const ArchSpec &arch,
- const char *flavor) {
+lldb::DisassemblerSP DisassemblerLLVMC::CreateInstance(const ArchSpec &arch,
+ const char *flavor) {
if (arch.GetTriple().getArch() != llvm::Triple::UnknownArch) {
- std::unique_ptr<DisassemblerLLVMC> disasm_up(
- new DisassemblerLLVMC(arch, flavor));
-
- if (disasm_up.get() && disasm_up->IsValid())
- return disasm_up.release();
+ auto disasm_sp = std::make_shared<DisassemblerLLVMC>(arch, flavor);
+ if (disasm_sp && disasm_sp->IsValid())
+ return disasm_sp;
}
- return nullptr;
+ return lldb::DisassemblerSP();
}
size_t DisassemblerLLVMC::DecodeInstructions(const Address &base_addr,
Index: lldb/source/Core/Disassembler.cpp
===================================================================
--- lldb/source/Core/Disassembler.cpp
+++ lldb/source/Core/Disassembler.cpp
@@ -67,20 +67,16 @@
create_callback =
PluginManager::GetDisassemblerCreateCallbackForPluginName(plugin_name);
if (create_callback) {
- DisassemblerSP disassembler_sp(create_callback(arch, flavor));
-
- if (disassembler_sp)
- return disassembler_sp;
+ if (auto disasm_sp = create_callback(arch, flavor))
+ return disasm_sp;
}
} else {
for (uint32_t idx = 0;
(create_callback = PluginManager::GetDisassemblerCreateCallbackAtIndex(
idx)) != nullptr;
++idx) {
- DisassemblerSP disassembler_sp(create_callback(arch, flavor));
-
- if (disassembler_sp)
- return disassembler_sp;
+ if (auto disasm_sp = create_callback(arch, flavor))
+ return disasm_sp;
}
}
return DisassemblerSP();
Index: lldb/include/lldb/lldb-private-interfaces.h
===================================================================
--- lldb/include/lldb/lldb-private-interfaces.h
+++ lldb/include/lldb/lldb-private-interfaces.h
@@ -30,8 +30,8 @@
const ArchSpec &arch);
typedef std::unique_ptr<Architecture> (*ArchitectureCreateInstance)(
const ArchSpec &arch);
-typedef Disassembler *(*DisassemblerCreateInstance)(const ArchSpec &arch,
- const char *flavor);
+typedef lldb::DisassemblerSP (*DisassemblerCreateInstance)(const ArchSpec &arch,
+ const char *flavor);
typedef DynamicLoader *(*DynamicLoaderCreateInstance)(Process *process,
bool force);
typedef lldb::JITLoaderSP (*JITLoaderCreateInstance)(Process *process,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150235.520863.patch
Type: text/x-patch
Size: 3845 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230510/47f4a440/attachment.bin>
More information about the lldb-commits
mailing list