38 GetPluginDescriptionStatic(), CreateInstance);
44 return "Dynamic loader plug-in that watches for shared library "
45 "loads/unloads in POSIX processes.";
52 const llvm::Triple &triple_ref =
54 if (triple_ref.getOS() == llvm::Triple::FreeBSD ||
55 triple_ref.getOS() == llvm::Triple::Linux ||
56 triple_ref.getOS() == llvm::Triple::NetBSD)
81 Log *log =
GetLog(LLDBLog::DynamicLoader);
82 LLDB_LOGF(log,
"DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64, __FUNCTION__,
87 log,
"DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
" reloaded auxv data",
97 "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
98 " executable '%s', load_offset 0x%" PRIx64,
101 executable_sp ? executable_sp->GetFileSpec().GetPath().c_str()
102 :
"<null executable>",
111 if (executable_sp.get()) {
129 module_list.
Append(executable_sp);
131 "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
132 " added executable '%s' to module load list",
135 executable_sp->GetFileSpec().GetPath().c_str());
145 "DynamicLoaderPOSIXDYLD::%s told the target about the "
146 "modules that loaded:",
148 for (
auto module_sp : module_list.
Modules()) {
149 LLDB_LOGF(log,
"-- [module] %s (pid %" PRIu64
")",
150 module_sp ? module_sp->GetFileSpec().GetPath().c_str()
157 if (executable_sp.get()) {
167 Log *log =
GetLog(LLDBLog::DynamicLoader);
168 LLDB_LOGF(log,
"DynamicLoaderPOSIXDYLD::%s()", __FUNCTION__);
181 module_list.
Append(executable);
184 LLDB_LOGF(log,
"DynamicLoaderPOSIXDYLD::%s about to call ProbeEntry()",
203 bool base_addr_is_offset) {
215 Log *log =
GetLog(LLDBLog::DynamicLoader);
225 "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
226 " GetEntryPoint() returned no address, not setting entry breakpoint",
232 "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
233 " GetEntryPoint() returned address 0x%" PRIx64
234 ", setting entry breakpoint",
258 assert(baton &&
"null baton");
262 Log *log =
GetLog(LLDBLog::DynamicLoader);
265 LLDB_LOGF(log,
"DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64,
281 "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
282 " disabling breakpoint id %" PRIu64,
284 breakpoint_sp->SetEnabled(
false);
287 "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
288 " failed to find breakpoint for breakpoint id %" PRIu64,
293 "DynamicLoaderPOSIXDYLD::%s breakpoint id %" PRIu64
294 " no Process instance! Cannot disable breakpoint",
295 __FUNCTION__, break_id);
304 Log *log =
GetLog(LLDBLog::DynamicLoader);
312 "Rendezvous breakpoint breakpoint id {0} for pid {1}"
324 LLDB_LOG(log,
"Setting rendezvous break address for pid {0} at {1:x}",
329 LLDB_LOG(log,
"Rendezvous structure is not set up yet. "
330 "Trying to locate rendezvous breakpoint in the interpreter "
334 static std::vector<std::string> DebugStateCandidates{
335 "_dl_debug_state",
"rtld_db_dlactivity",
"__dl_rtld_db_dlactivity",
336 "r_debug_state",
"_r_debug_state",
"_rtld_debug_state",
346 &containingModules,
nullptr,
354 containingModules.
Append(interpreter->GetFileSpec());
356 &containingModules,
nullptr,
365 if (dyld_break->GetNumResolvedLocations() != 1) {
368 "Rendezvous breakpoint has abnormal number of"
369 " resolved locations ({0}) in pid {1}. It's supposed to be exactly 1.",
370 dyld_break->GetNumResolvedLocations(),
379 "Successfully set rendezvous breakpoint at address {0:x} "
381 location->GetLoadAddress(),
385 dyld_break->SetBreakpointKind(
"shared-library-event");
393 assert(baton &&
"null baton");
397 Log *log =
GetLog(LLDBLog::DynamicLoader);
400 LLDB_LOGF(log,
"DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64,
410 "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
411 " stop_when_images_change=%s",
415 stop_when_images_change ?
"true" :
"false");
416 return stop_when_images_change;
443 for (; I != E; ++I) {
446 if (!module_sp.get())
449 if (module_sp->GetObjectFile()->GetBaseAddress().GetLoadAddress(
454 }
else if (module_sp == interpreter_sp) {
464 loaded_modules.
Remove(module_sp);
470 new_modules.
Append(module_sp);
483 if (module_sp.get()) {
484 old_modules.
Append(module_sp);
488 loaded_modules.
Remove(old_modules);
503 return thread_plan_sp;
507 return thread_plan_sp;
515 return thread_plan_sp;
517 typedef std::vector<lldb::addr_t> AddressVector;
524 addrs.push_back(addr);
527 if (addrs.size() > 0) {
528 AddressVector::iterator start = addrs.begin();
529 AddressVector::iterator end = addrs.end();
531 llvm::sort(start, end);
532 addrs.erase(std::unique(start, end), end);
534 std::make_shared<ThreadPlanRunToAddress>(thread, addrs, stop);
537 return thread_plan_sp;
549 Log *log =
GetLog(LLDBLog::DynamicLoader);
550 LLDB_LOG(log,
"Failed to get vdso region info: {0}", status);
570 Log *log =
GetLog(LLDBLog::DynamicLoader);
571 LLDB_LOG(log,
"Failed to get interpreter region info: {0}", status);
591 bool base_addr_is_offset) {
593 file, link_map_addr, base_addr, base_addr_is_offset))
612 base_addr, base_addr_is_offset))
624 Log *log =
GetLog(LLDBLog::DynamicLoader);
630 "DynamicLoaderPOSIXDYLD::%s unable to resolve POSIX DYLD "
631 "rendezvous address",
641 std::vector<FileSpec> module_names;
643 module_names.push_back(I->file_spec);
650 if (module_sp.get()) {
651 LLDB_LOG(log,
"LoadAllCurrentModules loading module: {0}",
652 I->file_spec.GetFilename());
653 module_list.
Append(module_sp);
655 Log *log =
GetLog(LLDBLog::DynamicLoader);
658 "DynamicLoaderPOSIXDYLD::%s failed loading module %s at 0x%" PRIx64,
659 __FUNCTION__, I->file_spec.GetPath().c_str(), I->base_addr);
694 if (std::optional<uint64_t> vdso_base =
698 if (std::optional<uint64_t> interpreter_base =
710 std::optional<uint64_t> entry_point =
734 addr_t link_map = it->second;
743 addr_t tp = thread->GetThreadPointer();
764 Log *log =
GetLog(LLDBLog::DynamicLoader);
766 "DynamicLoaderPOSIXDYLD::Performed TLS lookup: "
767 "module=%s, link_map=0x%" PRIx64
", tp=0x%" PRIx64
768 ", modid=%" PRId64
", tls_block=0x%" PRIx64
"\n",
769 module_sp->GetObjectName().AsCString(
""), link_map, tp,
770 (int64_t)modid, tls_block);
775 return tls_block + tls_file_addr;
780 Log *log =
GetLog(LLDBLog::DynamicLoader);
791 "DynamicLoaderPOSIXDYLD::%s - failed to get process info for "
798 log,
"DynamicLoaderPOSIXDYLD::%s - got executable by pid %" PRIu64
": %s",
804 if (module_sp && module_sp->MatchesModuleSpec(module_spec))
808 auto error = platform_sp->ResolveExecutable(
809 module_spec, module_sp,
810 !executable_search_paths.IsEmpty() ? &executable_search_paths :
nullptr);
813 module_spec.
Dump(stream);
816 "DynamicLoaderPOSIXDYLD::%s - failed to resolve executable "
817 "with module spec \"%s\": %s",
836 return module_sp->GetFileSpec().GetPath() ==
"[vdso]";
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
#define LLDB_PLUGIN_DEFINE_ADV(ClassName, PluginName)
@ AUXV_AT_ENTRY
Program entry point.
@ AUXV_AT_BASE
Interpreter base address.
bool ModulesDidUnload() const
bool ModulesDidLoad() const
lldb::addr_t GetBreakAddress() const
A breakpoint should be set at this address and Resolve called on each hit.
void UpdateExecutablePath()
Update the cached executable path.
iterator loaded_begin() const
Iterators over all modules loaded into the inferior since the last call to Resolve().
lldb::addr_t GetLinkMapAddress() const
bool Resolve()
Update the internal snapshot of runtime linker rendezvous and recompute the currently loaded modules.
iterator unloaded_begin() const
Iterators over all modules unloaded from the inferior since the last call to Resolve().
iterator begin() const
Iterators over all currently loaded modules.
iterator unloaded_end() const
const ThreadInfo & GetThreadInfo()
iterator loaded_end() const
SOEntryList::const_iterator iterator
static bool RendezvousBreakpointHit(void *baton, lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
Callback routine which updates the current list of loaded modules based on the information supplied b...
std::map< lldb::ModuleWP, lldb::addr_t, std::owner_less< lldb::ModuleWP > > m_loaded_modules
Loaded module list. (link map for each module)
static lldb_private::DynamicLoader * CreateInstance(lldb_private::Process *process, bool force)
bool m_initial_modules_added
Indicates whether the initial set of modules was reported added.
lldb::addr_t m_load_offset
Virtual load address of the inferior process.
lldb::break_id_t m_dyld_bid
Rendezvous breakpoint.
lldb::addr_t GetEntryPoint()
Computes a value for m_entry_point returning the computed address on success and LLDB_INVALID_ADDRESS...
std::unique_ptr< AuxVector > m_auxv
Auxiliary vector of the inferior process.
static llvm::StringRef GetPluginDescriptionStatic()
void EvalSpecialModulesStatus()
Evaluate if Aux vectors contain vDSO and LD information in case they do, read and assign the address ...
lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module, const lldb::ThreadSP thread, lldb::addr_t tls_file_addr) override
Retrieves the per-module TLS block for a given thread.
bool SetRendezvousBreakpoint()
If possible sets a breakpoint on a function called by the runtime linker each time a module is loaded...
lldb::ModuleSP LoadInterpreterModule()
void RefreshModules()
Helper method for RendezvousBreakpointHit.
bool AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override
Ask if the eh_frame information for the given SymbolContext should be relied on even when it's the fi...
lldb::addr_t m_interpreter_base
Contains AT_BASE, which means a dynamic loader has been mapped to the address space.
void ProbeEntry()
Resolves the entry point for the current inferior process and sets a breakpoint at that address.
lldb_private::Status CanLoadImage() override
Ask if it is ok to try and load or unload an shared library (image).
lldb::addr_t m_vdso_base
Contains AT_SYSINFO_EHDR, which means a vDSO has been mapped to the address space.
~DynamicLoaderPOSIXDYLD() override
void UpdateLoadedSections(lldb::ModuleSP module, lldb::addr_t link_map_addr, lldb::addr_t base_addr, bool base_addr_is_offset) override
Updates the load address of every allocatable section in module.
lldb::addr_t ComputeLoadOffset()
Computes a value for m_load_offset returning the computed address on success and LLDB_INVALID_ADDRESS...
void UnloadSections(const lldb::ModuleSP module) override
Removes the loaded sections from the target in module.
DYLDRendezvous m_rendezvous
Runtime linker rendezvous structure.
void DidLaunch() override
Called after launching a process.
lldb::ModuleSP LoadModuleAtAddress(const lldb_private::FileSpec &file, lldb::addr_t link_map_addr, lldb::addr_t base_addr, bool base_addr_is_offset) override
Locates or creates a module given by file and updates/loads the resulting module at the virtual base ...
static bool EntryBreakpointHit(void *baton, lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
Callback routine invoked when we hit the breakpoint on process entry.
void DidAttach() override
Called after attaching a process.
lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread, bool stop_others) override
Provides a plan to step through the dynamic loader trampoline for the current state of thread.
void ResolveExecutableModule(lldb::ModuleSP &module_sp)
Loads Module from inferior process.
lldb::addr_t m_entry_point
Virtual entry address of the inferior process.
virtual void LoadAllCurrentModules()
Helper for the entry breakpoint callback.
std::weak_ptr< lldb_private::Module > m_interpreter_module
Contains the pointer to the interpret module, if loaded.
bool IsCoreFile() const
Returns true if the process is for a core file.
DynamicLoaderPOSIXDYLD(lldb_private::Process *process)
A section + offset based address range class.
Address & GetBaseAddress()
Get accessor for the base address of the range.
A section + offset based address class.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
lldb::addr_t GetFileAddress() const
Get the file address.
bool IsValid() const
Check if the object state is valid.
An architecture specification class.
llvm::Triple & GetTriple()
Architecture triple accessor.
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
void SetOneShot(bool one_shot)
If one_shot is true, breakpoint will be deleted on first hit.
void SetBreakpointKind(const char *kind)
Set the "kind" description for a breakpoint.
void SetCallback(BreakpointHitCallback callback, void *baton, bool is_synchronous=false)
Set the callback action invoked when the breakpoint is hit.
A uniqued constant string class.
bool IsEmpty() const
Test for empty string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const char * GetCString() const
Get the string value as a C string.
A plug-in interface definition class for dynamic loaders.
int64_t ReadUnsignedIntWithSizeInBytes(lldb::addr_t addr, int size_in_bytes)
lldb::addr_t ReadPointer(lldb::addr_t addr)
Process * m_process
The process that this dynamic loader plug-in is tracking.
void UpdateLoadedSectionsCommon(lldb::ModuleSP module, lldb::addr_t base_addr, bool base_addr_is_offset)
lldb::ModuleSP GetTargetExecutable()
Checks to see if the target module has changed, updates the target accordingly and returns the target...
bool GetStopWhenImagesChange() const
Get whether the process should stop when images change.
virtual lldb::ModuleSP LoadModuleAtAddress(const lldb_private::FileSpec &file, lldb::addr_t link_map_addr, lldb::addr_t base_addr, bool base_addr_is_offset)
Locates or creates a module given by file and updates/loads the resulting module at the virtual base ...
void UnloadSectionsCommon(const lldb::ModuleSP module)
void Append(const FileSpec &file)
Append a FileSpec object to the list.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
const AddressRange & GetAddressRange()
ConstString GetName(NamePreference preference=ePreferDemangled) const
Best name get accessor.
OptionalBool GetMapped() const
ConstString GetName() const
A collection class for Module objects.
lldb::ModuleSP FindFirstModule(const ModuleSpec &module_spec) const
bool AppendIfNeeded(const lldb::ModuleSP &new_module, bool notify=true)
Append a module to the module list, if it is not already there.
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
bool Remove(const lldb::ModuleSP &module_sp, bool notify=true)
Remove a module from the module list.
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
ModuleIterable Modules() const
void Dump(Stream &strm) const
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
A plug-in interface definition class for object file parsers.
virtual lldb_private::Address GetImageInfoAddress(Target *target)
Similar to Process::GetImageInfoAddress().
virtual lldb_private::Address GetEntryPointAddress()
Returns the address of the Entry Point in this object file - if the object file doesn't have an entry...
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
FileSpec & GetExecutableFile()
ArchSpec & GetArchitecture()
A plug-in interface definition class for debugging a process.
lldb::pid_t GetID() const
Returns the pid of the process or LLDB_INVALID_PROCESS_ID if there is no known pid.
virtual DataExtractor GetAuxvData()
virtual void PrefetchModuleSpecs(llvm::ArrayRef< FileSpec > module_file_specs, const llvm::Triple &triple)
virtual bool GetProcessInfo(ProcessInstanceInfo &info)
virtual bool IsLiveDebugSession() const
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info)
Locate the memory region that contains load_addr.
lldb::ModuleSP ReadModuleFromMemory(const FileSpec &file_spec, lldb::addr_t header_addr, size_t size_to_read=512)
Target & GetTarget()
Get the target object pointer for this module.
This base class provides an interface to stack frames.
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
bool Fail() const
Test for error condition.
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
const char * GetData() const
Defines a list of symbol context objects.
uint32_t GetSize() const
Get accessor for a symbol context list size.
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
bool GetAddressRange(uint32_t scope, uint32_t range_idx, bool use_inline_block_range, AddressRange &range) const
Get the address range contained within a symbol context.
Symbol * symbol
The Symbol for a given query.
bool IsTrampoline() const
Address & GetAddressRef()
void ModulesDidLoad(ModuleList &module_list)
Module * GetExecutableModulePointer()
lldb::BreakpointSP GetBreakpointByID(lldb::break_id_t break_id)
bool RemoveBreakpointByID(lldb::break_id_t break_id)
lldb::ModuleSP GetOrCreateModule(const ModuleSpec &module_spec, bool notify, Status *error_ptr=nullptr)
Find a binary on the system and return its Module, or return an existing Module that is already in th...
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
void ModulesDidUnload(ModuleList &module_list, bool delete_locations)
static FileSpecList GetDefaultExecutableSearchPaths()
lldb::PlatformSP GetPlatform()
lldb::BreakpointSP CreateBreakpoint(const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, uint32_t column, lldb::addr_t offset, LazyBool check_inlines, LazyBool skip_prologue, bool internal, bool request_hardware, LazyBool move_to_nearest_code)
const ModuleList & GetImages() const
Get accessor for the images for this process.
const ArchSpec & GetArchitecture() const
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
lldb::ProcessSP GetProcess() const
#define LLDB_INVALID_BREAK_ID
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_PROCESS_ID
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
std::shared_ptr< lldb_private::Thread > ThreadSP
@ eLanguageTypeC
Non-standardized C, such as K&R.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
std::shared_ptr< lldb_private::Module > ModuleSP
BaseType GetRangeBase() const
SizeType GetByteSize() const