1 //===-- DynamicLoaderPOSIX.h ------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // C Includes 11 // C++ Includes 12 // Other libraries and framework includes 13 #include "lldb/Core/PluginManager.h" 14 #include "lldb/Core/Log.h" 15 #include "lldb/Core/Module.h" 16 #include "lldb/Core/ModuleSpec.h" 17 #include "lldb/Core/Section.h" 18 #include "lldb/Symbol/ObjectFile.h" 19 #include "lldb/Target/Process.h" 20 #include "lldb/Target/Target.h" 21 #include "lldb/Target/Thread.h" 22 #include "lldb/Target/ThreadPlanRunToAddress.h" 23 #include "lldb/Breakpoint/BreakpointLocation.h" 24 25 #include "AuxVector.h" 26 #include "DynamicLoaderPOSIXDYLD.h" 27 28 using namespace lldb; 29 using namespace lldb_private; 30 31 void 32 DynamicLoaderPOSIXDYLD::Initialize() 33 { 34 PluginManager::RegisterPlugin(GetPluginNameStatic(), 35 GetPluginDescriptionStatic(), 36 CreateInstance); 37 } 38 39 void 40 DynamicLoaderPOSIXDYLD::Terminate() 41 { 42 } 43 44 lldb_private::ConstString 45 DynamicLoaderPOSIXDYLD::GetPluginName() 46 { 47 return GetPluginNameStatic(); 48 } 49 50 lldb_private::ConstString 51 DynamicLoaderPOSIXDYLD::GetPluginNameStatic() 52 { 53 static ConstString g_name("linux-dyld"); 54 return g_name; 55 } 56 57 const char * 58 DynamicLoaderPOSIXDYLD::GetPluginDescriptionStatic() 59 { 60 return "Dynamic loader plug-in that watches for shared library " 61 "loads/unloads in POSIX processes."; 62 } 63 64 void 65 DynamicLoaderPOSIXDYLD::GetPluginCommandHelp(const char *command, Stream *strm) 66 { 67 } 68 69 uint32_t 70 DynamicLoaderPOSIXDYLD::GetPluginVersion() 71 { 72 return 1; 73 } 74 75 DynamicLoader * 76 DynamicLoaderPOSIXDYLD::CreateInstance(Process *process, bool force) 77 { 78 bool create = force; 79 if (!create) 80 { 81 const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple(); 82 if (triple_ref.getOS() == llvm::Triple::Linux || 83 triple_ref.getOS() == llvm::Triple::FreeBSD) 84 create = true; 85 } 86 87 if (create) 88 return new DynamicLoaderPOSIXDYLD (process); 89 return NULL; 90 } 91 92 DynamicLoaderPOSIXDYLD::DynamicLoaderPOSIXDYLD(Process *process) 93 : DynamicLoader(process), 94 m_rendezvous(process), 95 m_load_offset(LLDB_INVALID_ADDRESS), 96 m_entry_point(LLDB_INVALID_ADDRESS), 97 m_auxv(), 98 m_dyld_bid(LLDB_INVALID_BREAK_ID) 99 { 100 } 101 102 DynamicLoaderPOSIXDYLD::~DynamicLoaderPOSIXDYLD() 103 { 104 if (m_dyld_bid != LLDB_INVALID_BREAK_ID) 105 { 106 m_process->GetTarget().RemoveBreakpointByID (m_dyld_bid); 107 m_dyld_bid = LLDB_INVALID_BREAK_ID; 108 } 109 } 110 111 void 112 DynamicLoaderPOSIXDYLD::DidAttach() 113 { 114 Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); 115 ModuleSP executable_sp; 116 addr_t load_offset; 117 118 if (log) 119 log->Printf ("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64, __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID); 120 121 m_auxv.reset(new AuxVector(m_process)); 122 if (log) 123 log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " reloaded auxv data", __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID); 124 125 executable_sp = GetTargetExecutable(); 126 load_offset = ComputeLoadOffset(); 127 if (log) 128 log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " executable '%s', load_offset 0x%" PRIx64, __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID, executable_sp ? executable_sp->GetFileSpec().GetPath().c_str () : "<null executable>", load_offset); 129 130 131 if (executable_sp && load_offset != LLDB_INVALID_ADDRESS) 132 { 133 ModuleList module_list; 134 135 module_list.Append(executable_sp); 136 if (log) 137 log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " added executable '%s' to module load list", 138 __FUNCTION__, 139 m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID, 140 executable_sp->GetFileSpec().GetPath().c_str ()); 141 142 UpdateLoadedSections(executable_sp, LLDB_INVALID_ADDRESS, load_offset); 143 144 // When attaching to a target, there are two possible states: 145 // (1) We already crossed the entry point and therefore the rendezvous 146 // structure is ready to be used and we can load the list of modules 147 // and place the rendezvous breakpoint. 148 // (2) We didn't cross the entry point yet, so these structures are not 149 // ready; we should behave as if we just launched the target and 150 // call ProbeEntry(). This will place a breakpoint on the entry 151 // point which itself will be hit after the rendezvous structure is 152 // set up and will perform actions described in (1). 153 if (m_rendezvous.Resolve()) 154 { 155 if (log) 156 log->Printf ("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64 " rendezvous could resolve: attach assuming dynamic loader info is available now", __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID); 157 LoadAllCurrentModules(); 158 SetRendezvousBreakpoint(); 159 } 160 else 161 { 162 if (log) 163 log->Printf ("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64 " rendezvous could not yet resolve: adding breakpoint to catch future rendezvous setup", __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID); 164 ProbeEntry(); 165 } 166 167 m_process->GetTarget().ModulesDidLoad(module_list); 168 if (log) 169 { 170 log->Printf ("DynamicLoaderPOSIXDYLD::%s told the target about the modules that loaded:", __FUNCTION__); 171 for (auto module_sp : module_list.Modules ()) 172 { 173 log->Printf ("-- [module] %s (pid %" PRIu64 ")", 174 module_sp ? module_sp->GetFileSpec().GetPath().c_str () : "<null>", 175 m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID); 176 } 177 } 178 } 179 } 180 181 void 182 DynamicLoaderPOSIXDYLD::DidLaunch() 183 { 184 Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); 185 if (log) 186 log->Printf ("DynamicLoaderPOSIXDYLD::%s()", __FUNCTION__); 187 188 ModuleSP executable; 189 addr_t load_offset; 190 191 m_auxv.reset(new AuxVector(m_process)); 192 193 executable = GetTargetExecutable(); 194 load_offset = ComputeLoadOffset(); 195 196 if (executable.get() && load_offset != LLDB_INVALID_ADDRESS) 197 { 198 ModuleList module_list; 199 module_list.Append(executable); 200 UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, load_offset); 201 202 if (log) 203 log->Printf ("DynamicLoaderPOSIXDYLD::%s about to call ProbeEntry()", __FUNCTION__); 204 ProbeEntry(); 205 206 m_process->GetTarget().ModulesDidLoad(module_list); 207 } 208 } 209 210 Error 211 DynamicLoaderPOSIXDYLD::ExecutePluginCommand(Args &command, Stream *strm) 212 { 213 return Error(); 214 } 215 216 Log * 217 DynamicLoaderPOSIXDYLD::EnablePluginLogging(Stream *strm, Args &command) 218 { 219 return NULL; 220 } 221 222 Error 223 DynamicLoaderPOSIXDYLD::CanLoadImage() 224 { 225 return Error(); 226 } 227 228 void 229 DynamicLoaderPOSIXDYLD::UpdateLoadedSections(ModuleSP module, addr_t link_map_addr, addr_t base_addr) 230 { 231 m_loaded_modules[module] = link_map_addr; 232 233 UpdateLoadedSectionsCommon(module, base_addr); 234 } 235 236 void 237 DynamicLoaderPOSIXDYLD::UnloadSections(const ModuleSP module) 238 { 239 m_loaded_modules.erase(module); 240 241 UnloadSectionsCommon(module); 242 } 243 244 void 245 DynamicLoaderPOSIXDYLD::ProbeEntry() 246 { 247 Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); 248 249 const addr_t entry = GetEntryPoint(); 250 if (entry == LLDB_INVALID_ADDRESS) 251 { 252 if (log) 253 log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " GetEntryPoint() returned no address, not setting entry breakpoint", __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID); 254 return; 255 } 256 257 if (log) 258 log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " GetEntryPoint() returned address 0x%" PRIx64 ", setting entry breakpoint", __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID, entry); 259 260 if (m_process) 261 { 262 Breakpoint *const entry_break = m_process->GetTarget().CreateBreakpoint(entry, true, false).get(); 263 entry_break->SetCallback(EntryBreakpointHit, this, true); 264 entry_break->SetBreakpointKind("shared-library-event"); 265 266 // Shoudn't hit this more than once. 267 entry_break->SetOneShot (true); 268 } 269 } 270 271 // The runtime linker has run and initialized the rendezvous structure once the 272 // process has hit its entry point. When we hit the corresponding breakpoint we 273 // interrogate the rendezvous structure to get the load addresses of all 274 // dependent modules for the process. Similarly, we can discover the runtime 275 // linker function and setup a breakpoint to notify us of any dynamically loaded 276 // modules (via dlopen). 277 bool 278 DynamicLoaderPOSIXDYLD::EntryBreakpointHit(void *baton, 279 StoppointCallbackContext *context, 280 user_id_t break_id, 281 user_id_t break_loc_id) 282 { 283 assert(baton && "null baton"); 284 if (!baton) 285 return false; 286 287 Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); 288 DynamicLoaderPOSIXDYLD *const dyld_instance = static_cast<DynamicLoaderPOSIXDYLD*>(baton); 289 if (log) 290 log->Printf ("DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64, __FUNCTION__, dyld_instance->m_process ? dyld_instance->m_process->GetID () : LLDB_INVALID_PROCESS_ID); 291 292 // Disable the breakpoint --- if a stop happens right after this, which we've seen on occasion, we don't 293 // want the breakpoint stepping thread-plan logic to show a breakpoint instruction at the disassembled 294 // entry point to the program. Disabling it prevents it. (One-shot is not enough - one-shot removal logic 295 // only happens after the breakpoint goes public, which wasn't happening in our scenario). 296 if (dyld_instance->m_process) 297 { 298 BreakpointSP breakpoint_sp = dyld_instance->m_process->GetTarget().GetBreakpointByID (break_id); 299 if (breakpoint_sp) 300 { 301 if (log) 302 log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " disabling breakpoint id %" PRIu64, __FUNCTION__, dyld_instance->m_process->GetID (), break_id); 303 breakpoint_sp->SetEnabled (false); 304 } 305 else 306 { 307 if (log) 308 log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " failed to find breakpoint for breakpoint id %" PRIu64, __FUNCTION__, dyld_instance->m_process->GetID (), break_id); 309 } 310 } 311 else 312 { 313 if (log) 314 log->Printf ("DynamicLoaderPOSIXDYLD::%s breakpoint id %" PRIu64 " no Process instance! Cannot disable breakpoint", __FUNCTION__, break_id); 315 } 316 317 dyld_instance->LoadAllCurrentModules(); 318 dyld_instance->SetRendezvousBreakpoint(); 319 return false; // Continue running. 320 } 321 322 void 323 DynamicLoaderPOSIXDYLD::SetRendezvousBreakpoint() 324 { 325 Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); 326 327 addr_t break_addr = m_rendezvous.GetBreakAddress(); 328 Target &target = m_process->GetTarget(); 329 330 if (m_dyld_bid == LLDB_INVALID_BREAK_ID) 331 { 332 if (log) 333 log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " setting rendezvous break address at 0x%" PRIx64, __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID, break_addr); 334 Breakpoint *dyld_break = target.CreateBreakpoint (break_addr, true, false).get(); 335 dyld_break->SetCallback(RendezvousBreakpointHit, this, true); 336 dyld_break->SetBreakpointKind ("shared-library-event"); 337 m_dyld_bid = dyld_break->GetID(); 338 } 339 else 340 { 341 if (log) 342 log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " reusing break id %" PRIu32 ", address at 0x%" PRIx64, __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID, m_dyld_bid, break_addr); 343 } 344 345 // Make sure our breakpoint is at the right address. 346 assert (target.GetBreakpointByID(m_dyld_bid)->FindLocationByAddress(break_addr)->GetBreakpoint().GetID() == m_dyld_bid); 347 } 348 349 bool 350 DynamicLoaderPOSIXDYLD::RendezvousBreakpointHit(void *baton, 351 StoppointCallbackContext *context, 352 user_id_t break_id, 353 user_id_t break_loc_id) 354 { 355 assert (baton && "null baton"); 356 if (!baton) 357 return false; 358 359 Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); 360 DynamicLoaderPOSIXDYLD *const dyld_instance = static_cast<DynamicLoaderPOSIXDYLD*>(baton); 361 if (log) 362 log->Printf ("DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64, __FUNCTION__, dyld_instance->m_process ? dyld_instance->m_process->GetID () : LLDB_INVALID_PROCESS_ID); 363 364 dyld_instance->RefreshModules(); 365 366 // Return true to stop the target, false to just let the target run. 367 const bool stop_when_images_change = dyld_instance->GetStopWhenImagesChange(); 368 if (log) 369 log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " stop_when_images_change=%s", __FUNCTION__, dyld_instance->m_process ? dyld_instance->m_process->GetID () : LLDB_INVALID_PROCESS_ID, stop_when_images_change ? "true" : "false"); 370 return stop_when_images_change; 371 } 372 373 void 374 DynamicLoaderPOSIXDYLD::RefreshModules() 375 { 376 if (!m_rendezvous.Resolve()) 377 return; 378 379 DYLDRendezvous::iterator I; 380 DYLDRendezvous::iterator E; 381 382 ModuleList &loaded_modules = m_process->GetTarget().GetImages(); 383 384 if (m_rendezvous.ModulesDidLoad()) 385 { 386 ModuleList new_modules; 387 388 E = m_rendezvous.loaded_end(); 389 for (I = m_rendezvous.loaded_begin(); I != E; ++I) 390 { 391 FileSpec file(I->path.c_str(), true); 392 ModuleSP module_sp = LoadModuleAtAddress(file, I->link_addr, I->base_addr); 393 if (module_sp.get()) 394 { 395 loaded_modules.AppendIfNeeded(module_sp); 396 new_modules.Append(module_sp); 397 } 398 } 399 m_process->GetTarget().ModulesDidLoad(new_modules); 400 } 401 402 if (m_rendezvous.ModulesDidUnload()) 403 { 404 ModuleList old_modules; 405 406 E = m_rendezvous.unloaded_end(); 407 for (I = m_rendezvous.unloaded_begin(); I != E; ++I) 408 { 409 FileSpec file(I->path.c_str(), true); 410 ModuleSpec module_spec (file); 411 ModuleSP module_sp = 412 loaded_modules.FindFirstModule (module_spec); 413 414 if (module_sp.get()) 415 { 416 old_modules.Append(module_sp); 417 UnloadSections(module_sp); 418 } 419 } 420 loaded_modules.Remove(old_modules); 421 m_process->GetTarget().ModulesDidUnload(old_modules, false); 422 } 423 } 424 425 ThreadPlanSP 426 DynamicLoaderPOSIXDYLD::GetStepThroughTrampolinePlan(Thread &thread, bool stop) 427 { 428 ThreadPlanSP thread_plan_sp; 429 430 StackFrame *frame = thread.GetStackFrameAtIndex(0).get(); 431 const SymbolContext &context = frame->GetSymbolContext(eSymbolContextSymbol); 432 Symbol *sym = context.symbol; 433 434 if (sym == NULL || !sym->IsTrampoline()) 435 return thread_plan_sp; 436 437 const ConstString &sym_name = sym->GetMangled().GetName(Mangled::ePreferMangled); 438 if (!sym_name) 439 return thread_plan_sp; 440 441 SymbolContextList target_symbols; 442 Target &target = thread.GetProcess()->GetTarget(); 443 const ModuleList &images = target.GetImages(); 444 445 images.FindSymbolsWithNameAndType(sym_name, eSymbolTypeCode, target_symbols); 446 size_t num_targets = target_symbols.GetSize(); 447 if (!num_targets) 448 return thread_plan_sp; 449 450 typedef std::vector<lldb::addr_t> AddressVector; 451 AddressVector addrs; 452 for (size_t i = 0; i < num_targets; ++i) 453 { 454 SymbolContext context; 455 AddressRange range; 456 if (target_symbols.GetContextAtIndex(i, context)) 457 { 458 context.GetAddressRange(eSymbolContextEverything, 0, false, range); 459 lldb::addr_t addr = range.GetBaseAddress().GetLoadAddress(&target); 460 if (addr != LLDB_INVALID_ADDRESS) 461 addrs.push_back(addr); 462 } 463 } 464 465 if (addrs.size() > 0) 466 { 467 AddressVector::iterator start = addrs.begin(); 468 AddressVector::iterator end = addrs.end(); 469 470 std::sort(start, end); 471 addrs.erase(std::unique(start, end), end); 472 thread_plan_sp.reset(new ThreadPlanRunToAddress(thread, addrs, stop)); 473 } 474 475 return thread_plan_sp; 476 } 477 478 void 479 DynamicLoaderPOSIXDYLD::LoadAllCurrentModules() 480 { 481 DYLDRendezvous::iterator I; 482 DYLDRendezvous::iterator E; 483 ModuleList module_list; 484 485 if (!m_rendezvous.Resolve()) 486 { 487 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); 488 if (log) 489 log->Printf("DynamicLoaderPOSIXDYLD::%s unable to resolve POSIX DYLD rendezvous address", 490 __FUNCTION__); 491 return; 492 } 493 494 // The rendezvous class doesn't enumerate the main module, so track 495 // that ourselves here. 496 ModuleSP executable = GetTargetExecutable(); 497 m_loaded_modules[executable] = m_rendezvous.GetLinkMapAddress(); 498 499 500 for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I) 501 { 502 const char *module_path = I->path.c_str(); 503 FileSpec file(module_path, false); 504 ModuleSP module_sp = LoadModuleAtAddress(file, I->link_addr, I->base_addr); 505 if (module_sp.get()) 506 { 507 module_list.Append(module_sp); 508 } 509 else 510 { 511 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); 512 if (log) 513 log->Printf("DynamicLoaderPOSIXDYLD::%s failed loading module %s at 0x%" PRIx64, 514 __FUNCTION__, module_path, I->base_addr); 515 } 516 } 517 518 m_process->GetTarget().ModulesDidLoad(module_list); 519 } 520 521 addr_t 522 DynamicLoaderPOSIXDYLD::ComputeLoadOffset() 523 { 524 addr_t virt_entry; 525 526 if (m_load_offset != LLDB_INVALID_ADDRESS) 527 return m_load_offset; 528 529 if ((virt_entry = GetEntryPoint()) == LLDB_INVALID_ADDRESS) 530 return LLDB_INVALID_ADDRESS; 531 532 ModuleSP module = m_process->GetTarget().GetExecutableModule(); 533 if (!module) 534 return LLDB_INVALID_ADDRESS; 535 536 ObjectFile *exe = module->GetObjectFile(); 537 Address file_entry = exe->GetEntryPointAddress(); 538 539 if (!file_entry.IsValid()) 540 return LLDB_INVALID_ADDRESS; 541 542 m_load_offset = virt_entry - file_entry.GetFileAddress(); 543 return m_load_offset; 544 } 545 546 addr_t 547 DynamicLoaderPOSIXDYLD::GetEntryPoint() 548 { 549 if (m_entry_point != LLDB_INVALID_ADDRESS) 550 return m_entry_point; 551 552 if (m_auxv.get() == NULL) 553 return LLDB_INVALID_ADDRESS; 554 555 AuxVector::iterator I = m_auxv->FindEntry(AuxVector::AT_ENTRY); 556 557 if (I == m_auxv->end()) 558 return LLDB_INVALID_ADDRESS; 559 560 m_entry_point = static_cast<addr_t>(I->value); 561 562 const ArchSpec &arch = m_process->GetTarget().GetArchitecture(); 563 564 // On ppc64, the entry point is actually a descriptor. Dereference it. 565 if (arch.GetMachine() == llvm::Triple::ppc64) 566 m_entry_point = ReadUnsignedIntWithSizeInBytes(m_entry_point, 8); 567 568 return m_entry_point; 569 } 570 571 lldb::addr_t 572 DynamicLoaderPOSIXDYLD::GetThreadLocalData (const lldb::ModuleSP module, const lldb::ThreadSP thread) 573 { 574 auto it = m_loaded_modules.find (module); 575 if (it == m_loaded_modules.end()) 576 return LLDB_INVALID_ADDRESS; 577 578 addr_t link_map = it->second; 579 if (link_map == LLDB_INVALID_ADDRESS) 580 return LLDB_INVALID_ADDRESS; 581 582 const DYLDRendezvous::ThreadInfo &metadata = m_rendezvous.GetThreadInfo(); 583 if (!metadata.valid) 584 return LLDB_INVALID_ADDRESS; 585 586 // Get the thread pointer. 587 addr_t tp = thread->GetThreadPointer (); 588 if (tp == LLDB_INVALID_ADDRESS) 589 return LLDB_INVALID_ADDRESS; 590 591 // Find the module's modid. 592 int modid_size = 4; // FIXME(spucci): This isn't right for big-endian 64-bit 593 int64_t modid = ReadUnsignedIntWithSizeInBytes (link_map + metadata.modid_offset, modid_size); 594 if (modid == -1) 595 return LLDB_INVALID_ADDRESS; 596 597 // Lookup the DTV structure for this thread. 598 addr_t dtv_ptr = tp + metadata.dtv_offset; 599 addr_t dtv = ReadPointer (dtv_ptr); 600 if (dtv == LLDB_INVALID_ADDRESS) 601 return LLDB_INVALID_ADDRESS; 602 603 // Find the TLS block for this module. 604 addr_t dtv_slot = dtv + metadata.dtv_slot_size*modid; 605 addr_t tls_block = ReadPointer (dtv_slot + metadata.tls_offset); 606 607 Module *mod = module.get(); 608 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); 609 if (log) 610 log->Printf("DynamicLoaderPOSIXDYLD::Performed TLS lookup: " 611 "module=%s, link_map=0x%" PRIx64 ", tp=0x%" PRIx64 ", modid=%" PRId64 ", tls_block=0x%" PRIx64 "\n", 612 mod->GetObjectName().AsCString(""), link_map, tp, (int64_t)modid, tls_block); 613 614 return tls_block; 615 } 616