Skip to content

Commit a96c906

Browse files
authored
[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 <[email protected]>
1 parent a8b90c8 commit a96c906

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lldb/include/lldb/Target/DynamicLoader.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLDB_TARGET_DYNAMICLOADER_H
1111

1212
#include "lldb/Core/PluginInterface.h"
13+
#include "lldb/Symbol/Symbol.h"
1314
#include "lldb/Utility/FileSpec.h"
1415
#include "lldb/Utility/Status.h"
1516
#include "lldb/Utility/UUID.h"
@@ -24,7 +25,6 @@ namespace lldb_private {
2425
class ModuleList;
2526
class Process;
2627
class SectionList;
27-
class Symbol;
2828
class SymbolContext;
2929
class SymbolContextList;
3030
class Thread;
@@ -329,6 +329,13 @@ class DynamicLoader : public PluginInterface {
329329
/// safe to call certain APIs or SPIs.
330330
virtual bool IsFullyInitialized() { return true; }
331331

332+
/// Return the `start` function \b symbol in the dynamic loader module.
333+
/// This is the symbol the process will begin executing with
334+
/// `process launch --stop-at-entry`.
335+
virtual std::optional<lldb_private::Symbol> GetStartSymbol() {
336+
return std::nullopt;
337+
}
338+
332339
protected:
333340
// Utility methods for derived classes
334341

lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,26 @@ void DynamicLoaderDarwin::UpdateDYLDImageInfoFromNewImageInfo(
609609
}
610610
}
611611

612+
std::optional<lldb_private::Symbol> DynamicLoaderDarwin::GetStartSymbol() {
613+
Log *log = GetLog(LLDBLog::DynamicLoader);
614+
615+
auto log_err = [log](llvm::StringLiteral err_msg) -> std::nullopt_t {
616+
LLDB_LOGV(log, "{}", err_msg);
617+
return std::nullopt;
618+
};
619+
620+
ModuleSP dyld_sp = GetDYLDModule();
621+
if (!dyld_sp)
622+
return log_err("Couldn't retrieve DYLD module. Cannot get `start` symbol.");
623+
624+
const Symbol *symbol =
625+
dyld_sp->FindFirstSymbolWithNameAndType(ConstString("_dyld_start"));
626+
if (!symbol)
627+
return log_err("Cannot find `start` symbol in DYLD module.");
628+
629+
return *symbol;
630+
}
631+
612632
void DynamicLoaderDarwin::SetDYLDModule(lldb::ModuleSP &dyld_module_sp) {
613633
m_dyld_module_wp = dyld_module_sp;
614634
}

lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class DynamicLoaderDarwin : public lldb_private::DynamicLoader {
6767
// Clear method for classes derived from this one
6868
virtual void DoClear() = 0;
6969

70+
std::optional<lldb_private::Symbol> GetStartSymbol() override;
71+
7072
void SetDYLDModule(lldb::ModuleSP &dyld_module_sp);
7173

7274
lldb::ModuleSP GetDYLDModule();

0 commit comments

Comments
 (0)