1 //===-- DynamicLoaderPOSIXDYLD.cpp ------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Main header include
11 #include "DynamicLoaderPOSIXDYLD.h"
13 #include "AuxVector.h"
15 #include "lldb/Breakpoint/BreakpointLocation.h"
16 #include "lldb/Core/Module.h"
17 #include "lldb/Core/ModuleSpec.h"
18 #include "lldb/Core/PluginManager.h"
19 #include "lldb/Core/Section.h"
20 #include "lldb/Symbol/Function.h"
21 #include "lldb/Symbol/ObjectFile.h"
22 #include "lldb/Target/MemoryRegionInfo.h"
23 #include "lldb/Target/Platform.h"
24 #include "lldb/Target/Process.h"
25 #include "lldb/Target/Target.h"
26 #include "lldb/Target/Thread.h"
27 #include "lldb/Target/ThreadPlanRunToAddress.h"
28 #include "lldb/Utility/Log.h"
32 using namespace lldb_private;
34 void DynamicLoaderPOSIXDYLD::Initialize() {
35 PluginManager::RegisterPlugin(GetPluginNameStatic(),
36 GetPluginDescriptionStatic(), CreateInstance);
39 void DynamicLoaderPOSIXDYLD::Terminate() {}
41 lldb_private::ConstString DynamicLoaderPOSIXDYLD::GetPluginName() {
42 return GetPluginNameStatic();
45 lldb_private::ConstString DynamicLoaderPOSIXDYLD::GetPluginNameStatic() {
46 static ConstString g_name("linux-dyld");
50 const char *DynamicLoaderPOSIXDYLD::GetPluginDescriptionStatic() {
51 return "Dynamic loader plug-in that watches for shared library "
52 "loads/unloads in POSIX processes.";
55 uint32_t DynamicLoaderPOSIXDYLD::GetPluginVersion() { return 1; }
57 DynamicLoader *DynamicLoaderPOSIXDYLD::CreateInstance(Process *process,
61 const llvm::Triple &triple_ref =
62 process->GetTarget().GetArchitecture().GetTriple();
63 if (triple_ref.getOS() == llvm::Triple::FreeBSD ||
64 triple_ref.getOS() == llvm::Triple::Linux ||
65 triple_ref.getOS() == llvm::Triple::NetBSD)
70 return new DynamicLoaderPOSIXDYLD(process);
74 DynamicLoaderPOSIXDYLD::DynamicLoaderPOSIXDYLD(Process *process)
75 : DynamicLoader(process), m_rendezvous(process),
76 m_load_offset(LLDB_INVALID_ADDRESS), m_entry_point(LLDB_INVALID_ADDRESS),
77 m_auxv(), m_dyld_bid(LLDB_INVALID_BREAK_ID),
78 m_vdso_base(LLDB_INVALID_ADDRESS),
79 m_interpreter_base(LLDB_INVALID_ADDRESS) {}
81 DynamicLoaderPOSIXDYLD::~DynamicLoaderPOSIXDYLD() {
82 if (m_dyld_bid != LLDB_INVALID_BREAK_ID) {
83 m_process->GetTarget().RemoveBreakpointByID(m_dyld_bid);
84 m_dyld_bid = LLDB_INVALID_BREAK_ID;
88 void DynamicLoaderPOSIXDYLD::DidAttach() {
89 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
91 log->Printf("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64, __FUNCTION__,
92 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);
94 m_auxv.reset(new AuxVector(m_process));
96 log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " reloaded auxv data",
98 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);
100 // ask the process if it can load any of its own modules
101 m_process->LoadModules();
103 ModuleSP executable_sp = GetTargetExecutable();
104 ResolveExecutableModule(executable_sp);
106 // find the main process load offset
107 addr_t load_offset = ComputeLoadOffset();
109 log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
110 " executable '%s', load_offset 0x%" PRIx64,
112 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID,
113 executable_sp ? executable_sp->GetFileSpec().GetPath().c_str()
114 : "<null executable>",
117 EvalSpecialModulesStatus();
119 // if we dont have a load address we cant re-base
120 bool rebase_exec = load_offset != LLDB_INVALID_ADDRESS;
122 // if we have a valid executable
123 if (executable_sp.get()) {
124 lldb_private::ObjectFile *obj = executable_sp->GetObjectFile();
126 // don't rebase if the module already has a load address
127 Target &target = m_process->GetTarget();
128 Address addr = obj->GetImageInfoAddress(&target);
129 if (addr.GetLoadAddress(&target) != LLDB_INVALID_ADDRESS)
133 // no executable, nothing to re-base
137 // if the target executable should be re-based
139 ModuleList module_list;
141 module_list.Append(executable_sp);
143 log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
144 " added executable '%s' to module load list",
146 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID,
147 executable_sp->GetFileSpec().GetPath().c_str());
149 UpdateLoadedSections(executable_sp, LLDB_INVALID_ADDRESS, load_offset,
152 LoadAllCurrentModules();
153 if (!SetRendezvousBreakpoint()) {
154 // If we cannot establish rendezvous breakpoint right now we'll try again
159 m_process->GetTarget().ModulesDidLoad(module_list);
161 log->Printf("DynamicLoaderPOSIXDYLD::%s told the target about the "
162 "modules that loaded:",
164 for (auto module_sp : module_list.Modules()) {
165 log->Printf("-- [module] %s (pid %" PRIu64 ")",
166 module_sp ? module_sp->GetFileSpec().GetPath().c_str()
168 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);
174 void DynamicLoaderPOSIXDYLD::DidLaunch() {
175 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
177 log->Printf("DynamicLoaderPOSIXDYLD::%s()", __FUNCTION__);
182 m_auxv.reset(new AuxVector(m_process));
184 executable = GetTargetExecutable();
185 load_offset = ComputeLoadOffset();
186 EvalSpecialModulesStatus();
188 if (executable.get() && load_offset != LLDB_INVALID_ADDRESS) {
189 ModuleList module_list;
190 module_list.Append(executable);
191 UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, load_offset, true);
194 log->Printf("DynamicLoaderPOSIXDYLD::%s about to call ProbeEntry()",
197 if (!SetRendezvousBreakpoint()) {
198 // If we cannot establish rendezvous breakpoint right now we'll try again
204 m_process->GetTarget().ModulesDidLoad(module_list);
208 Status DynamicLoaderPOSIXDYLD::CanLoadImage() { return Status(); }
210 void DynamicLoaderPOSIXDYLD::UpdateLoadedSections(ModuleSP module,
211 addr_t link_map_addr,
213 bool base_addr_is_offset) {
214 m_loaded_modules[module] = link_map_addr;
215 UpdateLoadedSectionsCommon(module, base_addr, base_addr_is_offset);
218 void DynamicLoaderPOSIXDYLD::UnloadSections(const ModuleSP module) {
219 m_loaded_modules.erase(module);
221 UnloadSectionsCommon(module);
224 void DynamicLoaderPOSIXDYLD::ProbeEntry() {
225 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
227 const addr_t entry = GetEntryPoint();
228 if (entry == LLDB_INVALID_ADDRESS) {
231 "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
232 " GetEntryPoint() returned no address, not setting entry breakpoint",
234 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);
239 log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
240 " GetEntryPoint() returned address 0x%" PRIx64
241 ", setting entry breakpoint",
243 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID,
247 Breakpoint *const entry_break =
248 m_process->GetTarget().CreateBreakpoint(entry, true, false).get();
249 entry_break->SetCallback(EntryBreakpointHit, this, true);
250 entry_break->SetBreakpointKind("shared-library-event");
252 // Shoudn't hit this more than once.
253 entry_break->SetOneShot(true);
257 // The runtime linker has run and initialized the rendezvous structure once the
258 // process has hit its entry point. When we hit the corresponding breakpoint
259 // we interrogate the rendezvous structure to get the load addresses of all
260 // dependent modules for the process. Similarly, we can discover the runtime
261 // linker function and setup a breakpoint to notify us of any dynamically
262 // loaded modules (via dlopen).
263 bool DynamicLoaderPOSIXDYLD::EntryBreakpointHit(
264 void *baton, StoppointCallbackContext *context, user_id_t break_id,
265 user_id_t break_loc_id) {
266 assert(baton && "null baton");
270 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
271 DynamicLoaderPOSIXDYLD *const dyld_instance =
272 static_cast<DynamicLoaderPOSIXDYLD *>(baton);
274 log->Printf("DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64,
276 dyld_instance->m_process ? dyld_instance->m_process->GetID()
277 : LLDB_INVALID_PROCESS_ID);
279 // Disable the breakpoint --- if a stop happens right after this, which we've
280 // seen on occasion, we don't want the breakpoint stepping thread-plan logic
281 // to show a breakpoint instruction at the disassembled entry point to the
282 // program. Disabling it prevents it. (One-shot is not enough - one-shot
283 // removal logic only happens after the breakpoint goes public, which wasn't
284 // happening in our scenario).
285 if (dyld_instance->m_process) {
286 BreakpointSP breakpoint_sp =
287 dyld_instance->m_process->GetTarget().GetBreakpointByID(break_id);
290 log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
291 " disabling breakpoint id %" PRIu64,
292 __FUNCTION__, dyld_instance->m_process->GetID(), break_id);
293 breakpoint_sp->SetEnabled(false);
296 log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
297 " failed to find breakpoint for breakpoint id %" PRIu64,
298 __FUNCTION__, dyld_instance->m_process->GetID(), break_id);
302 log->Printf("DynamicLoaderPOSIXDYLD::%s breakpoint id %" PRIu64
303 " no Process instance! Cannot disable breakpoint",
304 __FUNCTION__, break_id);
307 dyld_instance->LoadAllCurrentModules();
308 dyld_instance->SetRendezvousBreakpoint();
309 return false; // Continue running.
312 bool DynamicLoaderPOSIXDYLD::SetRendezvousBreakpoint() {
313 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
314 if (m_dyld_bid != LLDB_INVALID_BREAK_ID) {
316 "Rendezvous breakpoint breakpoint id {0} for pid {1}"
319 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);
324 Target &target = m_process->GetTarget();
325 BreakpointSP dyld_break;
326 if (m_rendezvous.IsValid()) {
327 break_addr = m_rendezvous.GetBreakAddress();
328 LLDB_LOG(log, "Setting rendezvous break address for pid {0} at {1:x}",
329 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID,
331 dyld_break = target.CreateBreakpoint(break_addr, true, false);
333 LLDB_LOG(log, "Rendezvous structure is not set up yet. "
334 "Trying to locate rendezvous breakpoint in the interpreter "
336 ModuleSP interpreter = LoadInterpreterModule();
338 LLDB_LOG(log, "Can't find interpreter, rendezvous breakpoint isn't set.");
342 // Function names from different dynamic loaders that are known to be used
343 // as rendezvous between the loader and debuggers.
344 static std::vector<std::string> DebugStateCandidates{
345 "_dl_debug_state", "rtld_db_dlactivity", "__dl_rtld_db_dlactivity",
346 "r_debug_state", "_r_debug_state", "_rtld_debug_state",
349 FileSpecList containingModules;
350 containingModules.Append(interpreter->GetFileSpec());
351 dyld_break = target.CreateBreakpoint(
352 &containingModules, nullptr /* containingSourceFiles */,
353 DebugStateCandidates, eFunctionNameTypeFull, eLanguageTypeC,
355 eLazyBoolNo, /* skip_prologue */
357 false /* request_hardware */);
360 if (dyld_break->GetNumResolvedLocations() != 1) {
363 "Rendezvous breakpoint has abnormal number of"
364 " resolved locations ({0}) in pid {1}. It's supposed to be exactly 1.",
365 dyld_break->GetNumResolvedLocations(),
366 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);
368 target.RemoveBreakpointByID(dyld_break->GetID());
372 BreakpointLocationSP location = dyld_break->GetLocationAtIndex(0);
374 "Successfully set rendezvous breakpoint at address {0:x} "
376 location->GetLoadAddress(),
377 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);
379 dyld_break->SetCallback(RendezvousBreakpointHit, this, true);
380 dyld_break->SetBreakpointKind("shared-library-event");
381 m_dyld_bid = dyld_break->GetID();
385 bool DynamicLoaderPOSIXDYLD::RendezvousBreakpointHit(
386 void *baton, StoppointCallbackContext *context, user_id_t break_id,
387 user_id_t break_loc_id) {
388 assert(baton && "null baton");
392 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
393 DynamicLoaderPOSIXDYLD *const dyld_instance =
394 static_cast<DynamicLoaderPOSIXDYLD *>(baton);
396 log->Printf("DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64,
398 dyld_instance->m_process ? dyld_instance->m_process->GetID()
399 : LLDB_INVALID_PROCESS_ID);
401 dyld_instance->RefreshModules();
403 // Return true to stop the target, false to just let the target run.
404 const bool stop_when_images_change = dyld_instance->GetStopWhenImagesChange();
406 log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
407 " stop_when_images_change=%s",
409 dyld_instance->m_process ? dyld_instance->m_process->GetID()
410 : LLDB_INVALID_PROCESS_ID,
411 stop_when_images_change ? "true" : "false");
412 return stop_when_images_change;
415 void DynamicLoaderPOSIXDYLD::RefreshModules() {
416 if (!m_rendezvous.Resolve())
419 DYLDRendezvous::iterator I;
420 DYLDRendezvous::iterator E;
422 ModuleList &loaded_modules = m_process->GetTarget().GetImages();
424 if (m_rendezvous.ModulesDidLoad()) {
425 ModuleList new_modules;
427 E = m_rendezvous.loaded_end();
428 for (I = m_rendezvous.loaded_begin(); I != E; ++I) {
430 LoadModuleAtAddress(I->file_spec, I->link_addr, I->base_addr, true);
431 if (module_sp.get()) {
432 loaded_modules.AppendIfNeeded(module_sp);
433 new_modules.Append(module_sp);
436 m_process->GetTarget().ModulesDidLoad(new_modules);
439 if (m_rendezvous.ModulesDidUnload()) {
440 ModuleList old_modules;
442 E = m_rendezvous.unloaded_end();
443 for (I = m_rendezvous.unloaded_begin(); I != E; ++I) {
444 ModuleSpec module_spec{I->file_spec};
445 ModuleSP module_sp = loaded_modules.FindFirstModule(module_spec);
447 if (module_sp.get()) {
448 old_modules.Append(module_sp);
449 UnloadSections(module_sp);
452 loaded_modules.Remove(old_modules);
453 m_process->GetTarget().ModulesDidUnload(old_modules, false);
458 DynamicLoaderPOSIXDYLD::GetStepThroughTrampolinePlan(Thread &thread,
460 ThreadPlanSP thread_plan_sp;
462 StackFrame *frame = thread.GetStackFrameAtIndex(0).get();
463 const SymbolContext &context = frame->GetSymbolContext(eSymbolContextSymbol);
464 Symbol *sym = context.symbol;
466 if (sym == NULL || !sym->IsTrampoline())
467 return thread_plan_sp;
469 ConstString sym_name = sym->GetName();
471 return thread_plan_sp;
473 SymbolContextList target_symbols;
474 Target &target = thread.GetProcess()->GetTarget();
475 const ModuleList &images = target.GetImages();
477 images.FindSymbolsWithNameAndType(sym_name, eSymbolTypeCode, target_symbols);
478 size_t num_targets = target_symbols.GetSize();
480 return thread_plan_sp;
482 typedef std::vector<lldb::addr_t> AddressVector;
484 for (size_t i = 0; i < num_targets; ++i) {
485 SymbolContext context;
487 if (target_symbols.GetContextAtIndex(i, context)) {
488 context.GetAddressRange(eSymbolContextEverything, 0, false, range);
489 lldb::addr_t addr = range.GetBaseAddress().GetLoadAddress(&target);
490 if (addr != LLDB_INVALID_ADDRESS)
491 addrs.push_back(addr);
495 if (addrs.size() > 0) {
496 AddressVector::iterator start = addrs.begin();
497 AddressVector::iterator end = addrs.end();
499 llvm::sort(start, end);
500 addrs.erase(std::unique(start, end), end);
501 thread_plan_sp.reset(new ThreadPlanRunToAddress(thread, addrs, stop));
504 return thread_plan_sp;
507 void DynamicLoaderPOSIXDYLD::LoadVDSO() {
508 if (m_vdso_base == LLDB_INVALID_ADDRESS)
511 FileSpec file("[vdso]");
513 MemoryRegionInfo info;
514 Status status = m_process->GetMemoryRegionInfo(m_vdso_base, info);
516 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
517 LLDB_LOG(log, "Failed to get vdso region info: {0}", status);
521 if (ModuleSP module_sp = m_process->ReadModuleFromMemory(
522 file, m_vdso_base, info.GetRange().GetByteSize())) {
523 UpdateLoadedSections(module_sp, LLDB_INVALID_ADDRESS, m_vdso_base, false);
524 m_process->GetTarget().GetImages().AppendIfNeeded(module_sp);
528 ModuleSP DynamicLoaderPOSIXDYLD::LoadInterpreterModule() {
529 if (m_interpreter_base == LLDB_INVALID_ADDRESS)
532 MemoryRegionInfo info;
533 Target &target = m_process->GetTarget();
534 Status status = m_process->GetMemoryRegionInfo(m_interpreter_base, info);
535 if (status.Fail() || info.GetMapped() != MemoryRegionInfo::eYes ||
536 info.GetName().IsEmpty()) {
537 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
538 LLDB_LOG(log, "Failed to get interpreter region info: {0}", status);
542 FileSpec file(info.GetName().GetCString());
543 ModuleSpec module_spec(file, target.GetArchitecture());
545 if (ModuleSP module_sp = target.GetSharedModule(module_spec)) {
546 UpdateLoadedSections(module_sp, LLDB_INVALID_ADDRESS, m_interpreter_base,
553 void DynamicLoaderPOSIXDYLD::LoadAllCurrentModules() {
554 DYLDRendezvous::iterator I;
555 DYLDRendezvous::iterator E;
556 ModuleList module_list;
557 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
561 if (!m_rendezvous.Resolve()) {
563 log->Printf("DynamicLoaderPOSIXDYLD::%s unable to resolve POSIX DYLD "
564 "rendezvous address",
569 // The rendezvous class doesn't enumerate the main module, so track that
571 ModuleSP executable = GetTargetExecutable();
572 m_loaded_modules[executable] = m_rendezvous.GetLinkMapAddress();
574 std::vector<FileSpec> module_names;
575 for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I)
576 module_names.push_back(I->file_spec);
577 m_process->PrefetchModuleSpecs(
578 module_names, m_process->GetTarget().GetArchitecture().GetTriple());
580 for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I) {
582 LoadModuleAtAddress(I->file_spec, I->link_addr, I->base_addr, true);
583 if (module_sp.get()) {
584 LLDB_LOG(log, "LoadAllCurrentModules loading module: {0}",
585 I->file_spec.GetFilename());
586 module_list.Append(module_sp);
588 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
591 "DynamicLoaderPOSIXDYLD::%s failed loading module %s at 0x%" PRIx64,
592 __FUNCTION__, I->file_spec.GetCString(), I->base_addr);
596 m_process->GetTarget().ModulesDidLoad(module_list);
599 addr_t DynamicLoaderPOSIXDYLD::ComputeLoadOffset() {
602 if (m_load_offset != LLDB_INVALID_ADDRESS)
603 return m_load_offset;
605 if ((virt_entry = GetEntryPoint()) == LLDB_INVALID_ADDRESS)
606 return LLDB_INVALID_ADDRESS;
608 ModuleSP module = m_process->GetTarget().GetExecutableModule();
610 return LLDB_INVALID_ADDRESS;
612 ObjectFile *exe = module->GetObjectFile();
614 return LLDB_INVALID_ADDRESS;
616 Address file_entry = exe->GetEntryPointAddress();
618 if (!file_entry.IsValid())
619 return LLDB_INVALID_ADDRESS;
621 m_load_offset = virt_entry - file_entry.GetFileAddress();
622 return m_load_offset;
625 void DynamicLoaderPOSIXDYLD::EvalSpecialModulesStatus() {
626 auto I = m_auxv->FindEntry(AuxVector::AUXV_AT_SYSINFO_EHDR);
627 if (I != m_auxv->end() && I->value != 0)
628 m_vdso_base = I->value;
630 I = m_auxv->FindEntry(AuxVector::AUXV_AT_BASE);
631 if (I != m_auxv->end() && I->value != 0)
632 m_interpreter_base = I->value;
635 addr_t DynamicLoaderPOSIXDYLD::GetEntryPoint() {
636 if (m_entry_point != LLDB_INVALID_ADDRESS)
637 return m_entry_point;
639 if (m_auxv.get() == NULL)
640 return LLDB_INVALID_ADDRESS;
642 AuxVector::iterator I = m_auxv->FindEntry(AuxVector::AUXV_AT_ENTRY);
644 if (I == m_auxv->end())
645 return LLDB_INVALID_ADDRESS;
647 m_entry_point = static_cast<addr_t>(I->value);
649 const ArchSpec &arch = m_process->GetTarget().GetArchitecture();
651 // On ppc64, the entry point is actually a descriptor. Dereference it.
652 if (arch.GetMachine() == llvm::Triple::ppc64)
653 m_entry_point = ReadUnsignedIntWithSizeInBytes(m_entry_point, 8);
655 return m_entry_point;
659 DynamicLoaderPOSIXDYLD::GetThreadLocalData(const lldb::ModuleSP module_sp,
660 const lldb::ThreadSP thread,
661 lldb::addr_t tls_file_addr) {
662 auto it = m_loaded_modules.find(module_sp);
663 if (it == m_loaded_modules.end())
664 return LLDB_INVALID_ADDRESS;
666 addr_t link_map = it->second;
667 if (link_map == LLDB_INVALID_ADDRESS)
668 return LLDB_INVALID_ADDRESS;
670 const DYLDRendezvous::ThreadInfo &metadata = m_rendezvous.GetThreadInfo();
672 return LLDB_INVALID_ADDRESS;
674 // Get the thread pointer.
675 addr_t tp = thread->GetThreadPointer();
676 if (tp == LLDB_INVALID_ADDRESS)
677 return LLDB_INVALID_ADDRESS;
679 // Find the module's modid.
680 int modid_size = 4; // FIXME(spucci): This isn't right for big-endian 64-bit
681 int64_t modid = ReadUnsignedIntWithSizeInBytes(
682 link_map + metadata.modid_offset, modid_size);
684 return LLDB_INVALID_ADDRESS;
686 // Lookup the DTV structure for this thread.
687 addr_t dtv_ptr = tp + metadata.dtv_offset;
688 addr_t dtv = ReadPointer(dtv_ptr);
689 if (dtv == LLDB_INVALID_ADDRESS)
690 return LLDB_INVALID_ADDRESS;
692 // Find the TLS block for this module.
693 addr_t dtv_slot = dtv + metadata.dtv_slot_size * modid;
694 addr_t tls_block = ReadPointer(dtv_slot + metadata.tls_offset);
696 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
698 log->Printf("DynamicLoaderPOSIXDYLD::Performed TLS lookup: "
699 "module=%s, link_map=0x%" PRIx64 ", tp=0x%" PRIx64
700 ", modid=%" PRId64 ", tls_block=0x%" PRIx64 "\n",
701 module_sp->GetObjectName().AsCString(""), link_map, tp,
702 (int64_t)modid, tls_block);
704 if (tls_block == LLDB_INVALID_ADDRESS)
705 return LLDB_INVALID_ADDRESS;
707 return tls_block + tls_file_addr;
710 void DynamicLoaderPOSIXDYLD::ResolveExecutableModule(
711 lldb::ModuleSP &module_sp) {
712 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
714 if (m_process == nullptr)
717 auto &target = m_process->GetTarget();
718 const auto platform_sp = target.GetPlatform();
720 ProcessInstanceInfo process_info;
721 if (!m_process->GetProcessInfo(process_info)) {
723 log->Printf("DynamicLoaderPOSIXDYLD::%s - failed to get process info for "
725 __FUNCTION__, m_process->GetID());
730 log->Printf("DynamicLoaderPOSIXDYLD::%s - got executable by pid %" PRIu64
732 __FUNCTION__, m_process->GetID(),
733 process_info.GetExecutableFile().GetPath().c_str());
735 ModuleSpec module_spec(process_info.GetExecutableFile(),
736 process_info.GetArchitecture());
737 if (module_sp && module_sp->MatchesModuleSpec(module_spec))
740 const auto executable_search_paths(Target::GetDefaultExecutableSearchPaths());
741 auto error = platform_sp->ResolveExecutable(
742 module_spec, module_sp,
743 !executable_search_paths.IsEmpty() ? &executable_search_paths : nullptr);
746 module_spec.Dump(stream);
749 log->Printf("DynamicLoaderPOSIXDYLD::%s - failed to resolve executable "
750 "with module spec \"%s\": %s",
751 __FUNCTION__, stream.GetData(), error.AsCString());
755 target.SetExecutableModule(module_sp, eLoadDependentsNo);
758 bool DynamicLoaderPOSIXDYLD::AlwaysRelyOnEHUnwindInfo(
759 lldb_private::SymbolContext &sym_ctx) {
762 module_sp = sym_ctx.symbol->GetAddressRef().GetModule();
763 if (!module_sp && sym_ctx.function)
765 sym_ctx.function->GetAddressRange().GetBaseAddress().GetModule();
769 return module_sp->GetFileSpec().GetPath() == "[vdso]";