Skip to content

[lldb/Target] Add GetStartSymbol method to DynamicLoader plugins #8996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lldb/include/lldb/Target/DynamicLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -24,7 +25,6 @@ namespace lldb_private {
class ModuleList;
class Process;
class SectionList;
class Symbol;
class SymbolContext;
class SymbolContextList;
class Thread;
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down