[Lldb-commits] [lldb] [lldb/Target] Add GetStartSymbol method to DynamicLoader plugins (PR #99673)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Jul 19 10:39:07 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Med Ismail Bennani (medismailben)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/99673.diff
3 Files Affected:
- (modified) lldb/include/lldb/Target/DynamicLoader.h (+7-1)
- (modified) lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp (+15)
- (modified) lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h (+2)
``````````diff
diff --git a/lldb/include/lldb/Target/DynamicLoader.h b/lldb/include/lldb/Target/DynamicLoader.h
index e508d192d2759..4ce3e053c5b1a 100644
--- a/lldb/include/lldb/Target/DynamicLoader.h
+++ b/lldb/include/lldb/Target/DynamicLoader.h
@@ -10,9 +10,11 @@
#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"
+#include "lldb/Utility/UnimplementedError.h"
#include "lldb/lldb-defines.h"
#include "lldb/lldb-forward.h"
#include "lldb/lldb-private-enumerations.h"
@@ -24,7 +26,6 @@ namespace lldb_private {
class ModuleList;
class Process;
class SectionList;
-class Symbol;
class SymbolContext;
class SymbolContextList;
class Thread;
@@ -329,6 +330,11 @@ 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.
+ virtual llvm::Expected<lldb_private::Symbol> GetStartSymbol() {
+ return llvm::make_error<UnimplementedError>();
+ }
+
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..f4a61fd02d93c 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -609,6 +609,21 @@ void DynamicLoaderDarwin::UpdateDYLDImageInfoFromNewImageInfo(
}
}
+llvm::Expected<lldb_private::Symbol> DynamicLoaderDarwin::GetStartSymbol() {
+ ModuleSP dyld_sp = GetDYLDModule();
+ if (!dyld_sp)
+ return llvm::createStringError(
+ "Couldn't retrieve DYLD module. Cannot get `start` symbol.");
+
+ const Symbol *symbol =
+ dyld_sp->FindFirstSymbolWithNameAndType(ConstString("_dyld_start"));
+ if (!symbol)
+ return llvm::createStringError(
+ "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..0cdaaf6532972 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;
+ llvm::Expected<lldb_private::Symbol> GetStartSymbol() override;
+
void SetDYLDModule(lldb::ModuleSP &dyld_module_sp);
lldb::ModuleSP GetDYLDModule();
``````````
</details>
https://github.com/llvm/llvm-project/pull/99673
More information about the lldb-commits
mailing list