Author: Med Ismail Bennani Date: 2024-07-19T11:39:56-07:00 New Revision: a96c906102e8d0284c7a402eac4fa1ad9ab3e871
URL: https://github.com/llvm/llvm-project/commit/a96c906102e8d0284c7a402eac4fa1ad9ab3e871 DIFF: https://github.com/llvm/llvm-project/commit/a96c906102e8d0284c7a402eac4fa1ad9ab3e871.diff LOG: [lldb/Target] Add GetStartSymbol method to DynamicLoader plugins (#99673) This patch introduces a new method to the dynamic loader plugin, to fetch its `start` symbol. This can be useful to resolve the `start` symbol address for instance. Signed-off-by: Med Ismail Bennani <ism...@bennani.ma> Added: Modified: lldb/include/lldb/Target/DynamicLoader.h lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h Removed: ################################################################################ diff --git a/lldb/include/lldb/Target/DynamicLoader.h b/lldb/include/lldb/Target/DynamicLoader.h index e508d192d2759..15384245194b0 100644 --- a/lldb/include/lldb/Target/DynamicLoader.h +++ b/lldb/include/lldb/Target/DynamicLoader.h @@ -10,6 +10,7 @@ #define LLDB_TARGET_DYNAMICLOADER_H #include "lldb/Core/PluginInterface.h" +#include "lldb/Symbol/Symbol.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/UUID.h" @@ -24,7 +25,6 @@ namespace lldb_private { class ModuleList; class Process; class SectionList; -class Symbol; class SymbolContext; class SymbolContextList; class Thread; @@ -329,6 +329,13 @@ class DynamicLoader : public PluginInterface { /// safe to call certain APIs or SPIs. virtual bool IsFullyInitialized() { return true; } + /// Return the `start` function \b symbol in the dynamic loader module. + /// This is the symbol the process will begin executing with + /// `process launch --stop-at-entry`. + virtual std::optional<lldb_private::Symbol> GetStartSymbol() { + return std::nullopt; + } + protected: // Utility methods for derived classes diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp index 0e17d57fa9c4f..5c6331735bde8 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp @@ -609,6 +609,26 @@ void DynamicLoaderDarwin::UpdateDYLDImageInfoFromNewImageInfo( } } +std::optional<lldb_private::Symbol> DynamicLoaderDarwin::GetStartSymbol() { + Log *log = GetLog(LLDBLog::DynamicLoader); + + auto log_err = [log](llvm::StringLiteral err_msg) -> std::nullopt_t { + LLDB_LOGV(log, "{}", err_msg); + return std::nullopt; + }; + + ModuleSP dyld_sp = GetDYLDModule(); + if (!dyld_sp) + return log_err("Couldn't retrieve DYLD module. Cannot get `start` symbol."); + + const Symbol *symbol = + dyld_sp->FindFirstSymbolWithNameAndType(ConstString("_dyld_start")); + if (!symbol) + return log_err("Cannot find `start` symbol in DYLD module."); + + return *symbol; +} + void DynamicLoaderDarwin::SetDYLDModule(lldb::ModuleSP &dyld_module_sp) { m_dyld_module_wp = dyld_module_sp; } diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h index 8f9a29c94173f..4ac55fdf6f3af 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h @@ -67,6 +67,8 @@ class DynamicLoaderDarwin : public lldb_private::DynamicLoader { // Clear method for classes derived from this one virtual void DoClear() = 0; + std::optional<lldb_private::Symbol> GetStartSymbol() override; + void SetDYLDModule(lldb::ModuleSP &dyld_module_sp); lldb::ModuleSP GetDYLDModule(); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits