[Lldb-commits] [lldb] f464b7c - [lldb] Change definition of DisassemblerCreateInstance

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Mon May 15 13:55:56 PDT 2023


Author: Alex Langford
Date: 2023-05-15T13:31:26-07:00
New Revision: f464b7c764bcb8f29f28025919800f49405e4e93

URL: https://github.com/llvm/llvm-project/commit/f464b7c764bcb8f29f28025919800f49405e4e93
DIFF: https://github.com/llvm/llvm-project/commit/f464b7c764bcb8f29f28025919800f49405e4e93.diff

LOG: [lldb] Change definition of DisassemblerCreateInstance

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.

Differential Revision: https://reviews.llvm.org/D150235

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/lldb-private-interfaces.h b/lldb/include/lldb/lldb-private-interfaces.h
index 236a7f85c2c37..51bdfd360ab4a 100644
--- a/lldb/include/lldb/lldb-private-interfaces.h
+++ b/lldb/include/lldb/lldb-private-interfaces.h
@@ -30,8 +30,8 @@ typedef lldb::ABISP (*ABICreateInstance)(lldb::ProcessSP process_sp,
                                          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,

diff  --git a/lldb/source/Core/Disassembler.cpp b/lldb/source/Core/Disassembler.cpp
index bc9bf4f45f932..09eee082bc394 100644
--- a/lldb/source/Core/Disassembler.cpp
+++ b/lldb/source/Core/Disassembler.cpp
@@ -67,20 +67,16 @@ DisassemblerSP Disassembler::FindPlugin(const ArchSpec &arch,
     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();

diff  --git a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
index 8a4fd08a9268b..09115cc670da7 100644
--- a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -1572,16 +1572,14 @@ DisassemblerLLVMC::DisassemblerLLVMC(const ArchSpec &arch,
 
 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,

diff  --git a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
index 68ae3a32e18fd..30c69de81dfc8 100644
--- a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
+++ b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
@@ -34,8 +34,8 @@ class DisassemblerLLVMC : public lldb_private::Disassembler {
 
   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,


        


More information about the lldb-commits mailing list