LLDB mainline
DYLDRendezvous.cpp
Go to the documentation of this file.
1//===-- DYLDRendezvous.cpp ------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/Core/Module.h"
11#include "lldb/Symbol/Symbol.h"
14#include "lldb/Target/Process.h"
15#include "lldb/Target/Target.h"
18#include "lldb/Utility/Log.h"
19#include "lldb/Utility/Status.h"
20
21#include "llvm/Support/Error.h"
22#include "llvm/Support/Path.h"
23
24#include "DYLDRendezvous.h"
25
26using namespace lldb;
27using namespace lldb_private;
28
30 switch (state) {
32 return "eConsistent";
34 return "eAdd";
36 return "eDelete";
37 }
38 return "<invalid RendezvousState>";
39}
40
42 switch (action) {
44 return "eTakeSnapshot";
46 return "eAddModules";
48 return "eRemoveModules";
50 return "eNoAction";
51 }
52 return "<invalid RendezvousAction>";
53}
54
63
66 addr_t info_location;
67 addr_t info_addr;
68
69 if (!m_process) {
70 LLDB_LOGF(log, "%s null process provided", __FUNCTION__);
72 }
73
74 // Try to get it from our process. This might be a remote process and might
75 // grab it via some remote-specific mechanism.
76 info_location = m_process->GetImageInfoAddress();
77 LLDB_LOGF(log, "%s info_location = 0x%" PRIx64, __FUNCTION__, info_location);
78
79 // If the process fails to return an address, fall back to seeing if the
80 // local object file can help us find it.
81 if (info_location == LLDB_INVALID_ADDRESS) {
82 Target &target = m_process->GetTarget();
83 if (ModuleSP executable_sp = target.GetExecutableModule()) {
84 ObjectFile *obj_file = executable_sp->GetObjectFile();
85 Address addr = obj_file->GetImageInfoAddress(&target);
86
87 if (addr.IsValid()) {
88 info_location = addr.GetLoadAddress(&target);
89 LLDB_LOGF(log,
90 "%s resolved via direct object file approach to 0x%" PRIx64,
91 __FUNCTION__, info_location);
92 } else {
93 const Symbol *_r_debug = executable_sp->FindFirstSymbolWithNameAndType(
94 ConstString("_r_debug"));
95 if (_r_debug) {
96 info_addr = _r_debug->GetAddress().GetLoadAddress(&target);
97 if (info_addr != LLDB_INVALID_ADDRESS) {
98 LLDB_LOGF(log,
99 "%s resolved by finding symbol '_r_debug' whose value is "
100 "0x%" PRIx64,
101 __FUNCTION__, info_addr);
103 return info_addr;
104 }
105 }
106 LLDB_LOGF(log,
107 "%s FAILED - direct object file approach did not yield a "
108 "valid address",
109 __FUNCTION__);
110 }
111 }
112 }
113
114 if (info_location == LLDB_INVALID_ADDRESS) {
115 LLDB_LOGF(log, "%s FAILED - invalid info address", __FUNCTION__);
117 }
118
119 LLDB_LOGF(log, "%s reading pointer (%" PRIu32 " bytes) from 0x%" PRIx64,
120 __FUNCTION__, m_process->GetAddressByteSize(), info_location);
121
122 llvm::Expected<lldb::addr_t> info_addr_or_err =
123 m_process->ReadPointerFromMemory(info_location);
124 if (!info_addr_or_err) {
125 LLDB_LOG_ERROR(log, info_addr_or_err.takeError(),
126 "{1} FAILED - could not read from the info location: {0}",
127 __FUNCTION__);
129 }
130 info_addr = *info_addr_or_err;
131
132 if (info_addr == 0) {
133 LLDB_LOGF(log,
134 "%s FAILED - the rendezvous address contained at 0x%" PRIx64
135 " returned a null value",
136 __FUNCTION__, info_location);
138 }
139
140 return info_addr;
141}
142
144 if (m_process) {
146 Module *exe_mod = m_process->GetTarget().GetExecutableModulePointer();
147 if (exe_mod) {
149 LLDB_LOGF(log, "DYLDRendezvous::%s exe module executable path set: '%s'",
150 __FUNCTION__, m_exe_file_spec.GetPath().c_str());
151 } else {
152 LLDB_LOGF(log,
153 "DYLDRendezvous::%s cannot cache exe module path: null "
154 "executable module pointer",
155 __FUNCTION__);
156 }
157 }
158}
159
160void DYLDRendezvous::Rendezvous::DumpToLog(Log *log, const char *label) {
161 LLDB_LOGF(log, "%s Rendezvous: version = %" PRIu64 ", map_addr = 0x%16.16"
162 PRIx64 ", brk = 0x%16.16" PRIx64 ", state = %" PRIu64
163 " (%s), ldbase = 0x%16.16" PRIx64, label ? label : "", version,
165}
166
169
170 const size_t word_size = 4;
171 Rendezvous info;
172 size_t address_size;
173 size_t padding;
174 addr_t info_addr;
175 addr_t cursor;
176
177 address_size = m_process->GetAddressByteSize();
178 padding = address_size - word_size;
179 LLDB_LOGF(log,
180 "DYLDRendezvous::%s address size: %" PRIu64 ", padding %" PRIu64,
181 __FUNCTION__, uint64_t(address_size), uint64_t(padding));
182
184 cursor = info_addr =
186 else
187 cursor = info_addr = m_rendezvous_addr;
188 LLDB_LOGF(log, "DYLDRendezvous::%s cursor = 0x%" PRIx64, __FUNCTION__,
189 cursor);
190
191 if (cursor == LLDB_INVALID_ADDRESS)
192 return false;
193
194 if (!(cursor = ReadWord(cursor, &info.version, word_size)))
195 return false;
196
197 if (!(cursor = ReadPointer(cursor + padding, &info.map_addr)))
198 return false;
199
200 if (!(cursor = ReadPointer(cursor, &info.brk)))
201 return false;
202
203 if (!(cursor = ReadWord(cursor, &info.state, word_size)))
204 return false;
205
206 if (!(cursor = ReadPointer(cursor + padding, &info.ldbase)))
207 return false;
208
209 // The rendezvous was successfully read. Update our internal state.
210 m_rendezvous_addr = info_addr;
212 m_current = info;
213
214 m_previous.DumpToLog(log, "m_previous");
215 m_current.DumpToLog(log, "m_current ");
216
217 if (m_current.map_addr == 0)
218 return false;
219
221 return true;
222
223 return UpdateSOEntries();
224}
225
229
231 // If we have a core file, we will read the current rendezvous state
232 // from the core file's memory into m_current which can be in an inconsistent
233 // state, so we can't rely on its state to determine what we should do. We
234 // always need it to load all of the shared libraries one time when we attach
235 // to a core file.
236 if (IsCoreFile())
237 return eTakeSnapshot;
238
239 switch (m_current.state) {
240
241 case eConsistent:
242 switch (m_previous.state) {
243 // When the previous and current states are consistent this is the first
244 // time we have been asked to update. Just take a snapshot of the
245 // currently loaded modules.
246 case eConsistent:
247 return eTakeSnapshot;
248 // If we are about to add or remove a shared object clear out the current
249 // state and take a snapshot of the currently loaded images.
250 case eAdd:
251 return eAddModules;
252 case eDelete:
253 return eRemoveModules;
254 }
255 break;
256
257 case eAdd:
258 // If the main executable or a shared library defines a publicly visible
259 // symbol named "_r_debug", then it will cause problems once the executable
260 // that contains the symbol is loaded into the process. The correct
261 // "_r_debug" structure is currently found by LLDB by looking through
262 // the .dynamic section in the main executable and finding the DT_DEBUG tag
263 // entry.
264 //
265 // An issue comes up if someone defines another publicly visible "_r_debug"
266 // struct in their program. Sample code looks like:
267 //
268 // #include <link.h>
269 // r_debug _r_debug;
270 //
271 // If code like this is in an executable or shared library, this creates a
272 // new "_r_debug" structure and it causes problems once the executable is
273 // loaded due to the way symbol lookups happen in linux: the shared library
274 // list from _r_debug.r_map will be searched for a symbol named "_r_debug"
275 // and the first match will be the new version that is used. The dynamic
276 // loader is always last in this list. So at some point the dynamic loader
277 // will start updating the copy of "_r_debug" that gets found first. The
278 // issue is that LLDB will only look at the copy that is pointed to by the
279 // DT_DEBUG entry, or the initial version from the ld.so binary.
280 //
281 // Steps that show the problem are:
282 //
283 // - LLDB finds the "_r_debug" structure via the DT_DEBUG entry in the
284 // .dynamic section and this points to the "_r_debug" in ld.so
285 // - ld.so uodates its copy of "_r_debug" with "state = eAdd" before it
286 // loads the dependent shared libraries for the main executable and
287 // any dependencies of all shared libraries from the executable's list
288 // and ld.so code calls the debugger notification function
289 // that LLDB has set a breakpoint on.
290 // - LLDB hits the breakpoint and the breakpoint has a callback function
291 // where we read the _r_debug.state (eAdd) state and we do nothing as the
292 // "eAdd" state indicates that the shared libraries are about to be added.
293 // - ld.so finishes loading the main executable and any dependent shared
294 // libraries and it will update the "_r_debug.state" member with a
295 // "eConsistent", but it now updates the "_r_debug" in the a.out program
296 // and it calls the debugger notification function.
297 // - lldb hits the notification breakpoint and checks the ld.so copy of
298 // "_r_debug.state" which still has a state of "eAdd", but LLDB needs to see a
299 // "eConsistent" state to trigger the shared libraries to get loaded into
300 // the debug session, but LLDB the ld.so _r_debug.state which still
301 // contains "eAdd" and doesn't do anyhing and library load is missed.
302 // The "_r_debug" in a.out has the state set correctly to "eConsistent"
303 // but LLDB is still looking at the "_r_debug" from ld.so.
304 //
305 // So if we detect two "eAdd" states in a row, we assume this is the issue
306 // and we now load shared libraries correctly and will emit a log message
307 // in the "log enable lldb dyld" log channel which states there might be
308 // multiple "_r_debug" structs causing problems.
309 //
310 // The correct solution is that no one should be adding a duplicate
311 // publicly visible "_r_debug" symbols to their binaries, but we have
312 // programs that are doing this already and since it can be done, we should
313 // be able to work with this and keep debug sessions working as expected.
314 //
315 // If a user includes the <link.h> file, they can just use the existing
316 // "_r_debug" structure as it is defined in this header file as "extern
317 // struct r_debug _r_debug;" and no local copies need to be made.
318 if (m_previous.state == eAdd) {
320 LLDB_LOG(log, "DYLDRendezvous::GetAction() found two eAdd states in a "
321 "row, check process for multiple \"_r_debug\" symbols. "
322 "Returning eAddModules to ensure shared libraries get loaded "
323 "correctly");
324 return eAddModules;
325 }
326 return eNoAction;
327 case eDelete:
328 return eNoAction;
329 }
330
331 return eNoAction;
332}
333
335 const auto action = GetAction();
337 LLDB_LOG(log, "{0} action = {1}", LLVM_PRETTY_FUNCTION, ActionToCStr(action));
338
339 if (action == eNoAction)
340 return false;
341
342 m_added_soentries.clear();
343 m_removed_soentries.clear();
344 if (action == eTakeSnapshot) {
345 // We already have the loaded list from the previous update so no need to
346 // find all the modules again.
347 if (!m_loaded_modules.m_list.empty())
348 return true;
349 }
350
351 llvm::Expected<LoadedModuleInfoList> module_list =
352 m_process->GetLoadedModuleList();
353 if (!module_list) {
354 llvm::consumeError(module_list.takeError());
355 return false;
356 }
357
358 switch (action) {
359 case eTakeSnapshot:
360 m_soentries.clear();
361 return SaveSOEntriesFromRemote(*module_list);
362 case eAddModules:
363 return AddSOEntriesFromRemote(*module_list);
364 case eRemoveModules:
365 return RemoveSOEntriesFromRemote(*module_list);
366 case eNoAction:
367 return false;
368 }
369 llvm_unreachable("Fully covered switch above!");
370}
371
373 m_added_soentries.clear();
374 m_removed_soentries.clear();
375 const auto action = GetAction();
377 LLDB_LOG(log, "{0} action = {1}", LLVM_PRETTY_FUNCTION, ActionToCStr(action));
378 switch (action) {
379 case eTakeSnapshot:
380 m_soentries.clear();
382 case eAddModules:
383 return AddSOEntries();
384 case eRemoveModules:
385 return RemoveSOEntries();
386 case eNoAction:
387 return false;
388 }
389 llvm_unreachable("Fully covered switch above!");
390}
391
393 LoadedModuleInfoList::LoadedModuleInfo const &modInfo, SOEntry &entry) {
394 addr_t link_map_addr;
395 addr_t base_addr;
396 addr_t dyn_addr;
397 std::string name;
398
399 if (!modInfo.get_link_map(link_map_addr) || !modInfo.get_base(base_addr) ||
400 !modInfo.get_dynamic(dyn_addr) || !modInfo.get_name(name))
401 return false;
402
403 entry.link_addr = link_map_addr;
404 entry.base_addr = base_addr;
405 entry.dyn_addr = dyn_addr;
406
407 entry.file_spec.SetFile(name, FileSpec::Style::native);
408
409 UpdateBaseAddrIfNecessary(entry, name);
410
411 // not needed if we're using ModuleInfos
412 entry.next = 0;
413 entry.prev = 0;
414 entry.path_addr = 0;
415
416 return true;
417}
418
420 const LoadedModuleInfoList &module_list) {
421 for (auto const &modInfo : module_list.m_list) {
422 SOEntry entry;
423 if (!FillSOEntryFromModuleInfo(modInfo, entry))
424 return false;
425
426 // Only add shared libraries and not the executable.
427 if (!SOEntryIsMainExecutable(entry)) {
429 m_soentries.push_back(entry);
430 }
431 }
432
433 m_loaded_modules = module_list;
434 return true;
435}
436
438 const LoadedModuleInfoList &module_list) {
439 for (auto const &modInfo : module_list.m_list) {
440 bool found = false;
441 for (auto const &existing : m_loaded_modules.m_list) {
442 if (modInfo == existing) {
443 found = true;
444 break;
445 }
446 }
447
448 if (found)
449 continue;
450
451 SOEntry entry;
452 if (!FillSOEntryFromModuleInfo(modInfo, entry))
453 return false;
454
455 // Only add shared libraries and not the executable.
456 if (!SOEntryIsMainExecutable(entry)) {
458 m_soentries.push_back(entry);
459 m_added_soentries.push_back(entry);
460 }
461 }
462
463 m_loaded_modules = module_list;
464 return true;
465}
466
468 const LoadedModuleInfoList &module_list) {
469 for (auto const &existing : m_loaded_modules.m_list) {
470 bool found = false;
471 for (auto const &modInfo : module_list.m_list) {
472 if (modInfo == existing) {
473 found = true;
474 break;
475 }
476 }
477
478 if (found)
479 continue;
480
481 SOEntry entry;
482 if (!FillSOEntryFromModuleInfo(existing, entry))
483 return false;
484
485 // Only add shared libraries and not the executable.
486 if (!SOEntryIsMainExecutable(entry)) {
487 auto pos = llvm::find(m_soentries, entry);
488 if (pos == m_soentries.end())
489 return false;
490
491 m_soentries.erase(pos);
492 m_removed_soentries.push_back(entry);
493 }
494 }
495
496 m_loaded_modules = module_list;
497 return true;
498}
499
501 SOEntry entry;
502
503 assert(m_previous.state == eAdd);
504
505 if (m_current.map_addr == 0)
506 return false;
507
508 for (addr_t cursor = m_current.map_addr; cursor != 0; cursor = entry.next) {
509 if (!ReadSOEntryFromMemory(cursor, entry))
510 return false;
511
512 // Only add shared libraries and not the executable.
513 if (SOEntryIsMainExecutable(entry))
514 continue;
515
517
518 if (!llvm::is_contained(m_soentries, entry)) {
519 m_soentries.push_back(entry);
520 m_added_soentries.push_back(entry);
521 }
522 }
523
524 return true;
525}
526
528 SOEntryList entry_list;
529
530 assert(m_previous.state == eDelete);
531
532 if (!TakeSnapshot(entry_list))
533 return false;
534
535 for (iterator I = begin(); I != end(); ++I) {
536 if (!llvm::is_contained(entry_list, *I))
537 m_removed_soentries.push_back(*I);
538 }
539
540 m_soentries = entry_list;
541 return true;
542}
543
545 // On some systes the executable is indicated by an empty path in the entry.
546 // On others it is the full path to the executable.
547
548 auto triple = m_process->GetTarget().GetArchitecture().GetTriple();
549 switch (triple.getOS()) {
550 case llvm::Triple::FreeBSD:
551 case llvm::Triple::NetBSD:
552 case llvm::Triple::OpenBSD:
553 return entry.file_spec == m_exe_file_spec;
554 case llvm::Triple::Linux:
555 if (triple.isAndroid())
556 return entry.file_spec == m_exe_file_spec;
557 // If we are debugging ld.so, then all SOEntries should be treated as
558 // libraries, including the "main" one (denoted by an empty string).
560 return false;
561 return !entry.file_spec;
562 default:
563 return false;
564 }
565}
566
568 SOEntry entry;
569
570 if (m_current.map_addr == 0)
571 return false;
572
573 // Clear previous entries since we are about to obtain an up to date list.
574 entry_list.clear();
575
576 for (addr_t cursor = m_current.map_addr; cursor != 0; cursor = entry.next) {
577 if (!ReadSOEntryFromMemory(cursor, entry))
578 return false;
579
580 // Only add shared libraries and not the executable.
581 if (SOEntryIsMainExecutable(entry))
582 continue;
583
585
586 entry_list.push_back(entry);
587 }
588
589 return true;
590}
591
592addr_t DYLDRendezvous::ReadWord(addr_t addr, uint64_t *dst, size_t size) {
594
595 *dst = m_process->ReadUnsignedIntegerFromMemory(addr, size, 0, error);
596 if (error.Fail())
597 return 0;
598
599 return addr + size;
600}
601
603 llvm::Expected<lldb::addr_t> dst_or_err =
604 m_process->ReadPointerFromMemory(addr);
605 if (!dst_or_err) {
606 llvm::consumeError(dst_or_err.takeError());
607 return 0;
608 }
609 *dst = *dst_or_err;
610
611 return addr + m_process->GetAddressByteSize();
612}
613
615 std::string str;
617
618 if (addr == LLDB_INVALID_ADDRESS)
619 return std::string();
620
621 m_process->ReadCStringFromMemory(addr, str, error);
622
623 return str;
624}
625
626// Returns true if the load bias reported by the linker is incorrect for the
627// given entry. This function is used to handle cases where we want to work
628// around a bug in the system linker.
629static bool isLoadBiasIncorrect(Target &target, const std::string &file_path) {
630 // On Android L (API 21, 22) the load address of the "/system/bin/linker"
631 // isn't filled in correctly.
632 unsigned os_major = target.GetPlatform()->GetOSVersion().getMajor();
633 return target.GetArchitecture().GetTriple().isAndroid() &&
634 (os_major == 21 || os_major == 22) &&
635 (file_path == "/system/bin/linker" ||
636 file_path == "/system/bin/linker64");
637}
638
640 std::string const &file_path) {
641 // If the load bias reported by the linker is incorrect then fetch the load
642 // address of the file from the proc file system.
643 if (isLoadBiasIncorrect(m_process->GetTarget(), file_path)) {
645 bool is_loaded = false;
646 Status error =
647 m_process->GetFileLoadAddress(entry.file_spec, is_loaded, load_addr);
648 if (error.Success() && is_loaded)
649 entry.base_addr = load_addr;
650 }
651}
652
654 // Updates filename if empty. It is useful while debugging ld.so,
655 // when the link map returns empty string for the main executable.
656 if (!entry.file_spec) {
657 MemoryRegionInfo region;
658 Status region_status =
659 m_process->GetMemoryRegionInfo(entry.dyn_addr, region);
660 if (!region.GetName().IsEmpty())
661 entry.file_spec.SetFile(region.GetName().GetStringRef(),
662 FileSpec::Style::native);
663 }
664}
665
667 entry.clear();
668
669 entry.link_addr = addr;
670
671 if (!(addr = ReadPointer(addr, &entry.base_addr)))
672 return false;
673
674 // mips adds an extra load offset field to the link map struct on FreeBSD and
675 // NetBSD (need to validate other OSes).
676 // http://svnweb.freebsd.org/base/head/sys/sys/link_elf.h?revision=217153&view=markup#l57
677 const ArchSpec &arch = m_process->GetTarget().GetArchitecture();
678 if ((arch.GetTriple().getOS() == llvm::Triple::FreeBSD ||
679 arch.GetTriple().getOS() == llvm::Triple::NetBSD) &&
680 arch.IsMIPS()) {
681 addr_t mips_l_offs;
682 if (!(addr = ReadPointer(addr, &mips_l_offs)))
683 return false;
684 if (mips_l_offs != 0 && mips_l_offs != entry.base_addr)
685 return false;
686 }
687
688 if (!(addr = ReadPointer(addr, &entry.path_addr)))
689 return false;
690
691 if (!(addr = ReadPointer(addr, &entry.dyn_addr)))
692 return false;
693
694 if (!(addr = ReadPointer(addr, &entry.next)))
695 return false;
696
697 if (!(addr = ReadPointer(addr, &entry.prev)))
698 return false;
699
700 std::string file_path = ReadStringFromMemory(entry.path_addr);
701 entry.file_spec.SetFile(file_path, FileSpec::Style::native);
702
703 UpdateBaseAddrIfNecessary(entry, file_path);
704
705 return true;
706}
707
708bool DYLDRendezvous::FindMetadata(const char *name, PThreadField field,
709 uint32_t &value) {
710 Target &target = m_process->GetTarget();
711
714 eSymbolTypeAny, list);
715 if (list.IsEmpty())
716 return false;
717
718 Address address = list[0].symbol->GetAddress();
719 // eSize, eNElem, and eOffset correspond to the fields of the DESC structure.
720 // eStructSize instructs to read a value generated by DB_STRUCT.
721 int field_num = (field == eStructSize) ? 0 : field;
722 address.Slide(field_num * sizeof(uint32_t));
723
724 // Read from target memory as this allows us to try process memory and
725 // fallback to reading from read only sections from the object files. Here we
726 // are reading read only data from libpthread.so to find data in the thread
727 // specific area for the data we want and this won't be saved into process
728 // memory due to it being read only.
730 value =
731 target.ReadUnsignedIntegerFromMemory(address, sizeof(uint32_t), 0, error);
732 if (error.Fail())
733 return false;
734
735 if (field == eSize)
736 value /= 8; // convert bits to bytes
737
738 return true;
739}
740
742 if (!m_thread_info.valid) {
743 bool ok = true;
744
745 ok &= FindMetadata("_thread_db_sizeof_pthread", eStructSize,
746 m_thread_info.pthread_size);
747 ok &= FindMetadata("_thread_db_pthread_dtvp", eOffset,
748 m_thread_info.dtv_offset);
749 ok &=
750 FindMetadata("_thread_db_dtv_dtv", eSize, m_thread_info.dtv_slot_size);
751 ok &= FindMetadata("_thread_db_link_map_l_tls_modid", eOffset,
752 m_thread_info.modid_offset);
753 ok &= FindMetadata("_thread_db_dtv_t_pointer_val", eOffset,
754 m_thread_info.tls_offset);
755
756 if (ok)
757 m_thread_info.valid = true;
758 }
759
760 return m_thread_info;
761}
762
764 int state = GetState();
765
766 if (!log)
767 return;
768
769 log->PutCString("DYLDRendezvous:");
770 LLDB_LOGF(log, " Address: %" PRIx64, GetRendezvousAddress());
771 LLDB_LOGF(log, " Version: %" PRIu64, GetVersion());
772 LLDB_LOGF(log, " Link : %" PRIx64, GetLinkMapAddress());
773 LLDB_LOGF(log, " Break : %" PRIx64, GetBreakAddress());
774 LLDB_LOGF(log, " LDBase : %" PRIx64, GetLDBase());
775 LLDB_LOGF(log, " State : %s",
776 (state == eConsistent)
777 ? "consistent"
778 : (state == eAdd) ? "add"
779 : (state == eDelete) ? "delete" : "unknown");
780
781 iterator I = begin();
782 iterator E = end();
783
784 if (I != E)
785 log->PutCString("DYLDRendezvous SOEntries:");
786
787 for (int i = 1; I != E; ++I, ++i) {
788 LLDB_LOGF(log, "\n SOEntry [%d] %s", i, I->file_spec.GetPath().c_str());
789 LLDB_LOGF(log, " Base : %" PRIx64, I->base_addr);
790 LLDB_LOGF(log, " Path : %" PRIx64, I->path_addr);
791 LLDB_LOGF(log, " Dyn : %" PRIx64, I->dyn_addr);
792 LLDB_LOGF(log, " Next : %" PRIx64, I->next);
793 LLDB_LOGF(log, " Prev : %" PRIx64, I->prev);
794 }
795}
796
798 return !m_process->IsLiveDebugSession();
799}
static const size_t word_size
static llvm::raw_ostream & error(Stream &strm)
static bool isLoadBiasIncorrect(Target &target, const std::string &file_path)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:375
#define LLDB_LOGF(log,...)
Definition Log.h:389
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:405
bool FindMetadata(const char *name, PThreadField field, uint32_t &value)
lldb::addr_t ReadPointer(lldb::addr_t addr, lldb::addr_t *dst)
Reads an address from the inferior's address space starting at addr.
static const char * ActionToCStr(RendezvousAction action)
std::string ReadStringFromMemory(lldb::addr_t addr)
Reads a null-terminated C string from the memory location starting at addr.
std::list< SOEntry > SOEntryList
bool ReadSOEntryFromMemory(lldb::addr_t addr, SOEntry &entry)
Reads an SOEntry starting at addr.
lldb::addr_t GetBreakAddress() const
A breakpoint should be set at this address and Resolve called on each hit.
lldb_private::Process * m_process
void UpdateExecutablePath()
Update the cached executable path.
bool UpdateSOEntries()
Updates the current set of SOEntries, the set of added entries, and the set of removed entries.
bool m_executable_interpreter
uint64_t GetState() const
Returns the current state of the rendezvous structure.
lldb::addr_t GetLinkMapAddress() const
DYLDRendezvous(lldb_private::Process *process)
LoadedModuleInfoList m_loaded_modules
List of currently loaded SO modules.
bool UpdateSOEntriesFromRemote()
Same as UpdateSOEntries but it gets the list of loaded modules from the remote debug server (faster w...
bool IsCoreFile() const
static const char * StateToCStr(RendezvousState state)
bool Resolve()
Update the internal snapshot of runtime linker rendezvous and recompute the currently loaded modules.
RendezvousAction GetAction() const
Returns the current action to be taken given the current and previous state.
bool AddSOEntriesFromRemote(const LoadedModuleInfoList &module_list)
SOEntryList m_added_soentries
List of SOEntry's added to the link map since the last call to Resolve().
lldb::addr_t ResolveRendezvousAddress()
Locates the address of the rendezvous structure.
bool FillSOEntryFromModuleInfo(LoadedModuleInfoList::LoadedModuleInfo const &modInfo, SOEntry &entry)
RendezvousState
Constants describing the state of the rendezvous.
lldb::addr_t m_rendezvous_addr
Location of the r_debug structure in the inferiors address space.
iterator begin() const
Iterators over all currently loaded modules.
SOEntryList m_soentries
List of SOEntry objects corresponding to the current link map state.
void DumpToLog(lldb_private::Log *log) const
uint64_t GetVersion() const
lldb_private::FileSpec m_exe_file_spec
const ThreadInfo & GetThreadInfo()
void UpdateBaseAddrIfNecessary(SOEntry &entry, std::string const &file_path)
Rendezvous m_previous
lldb::addr_t GetLDBase() const
bool TakeSnapshot(SOEntryList &entry_list)
Reads the current list of shared objects according to the link map supplied by the runtime linker.
void UpdateFileSpecIfNecessary(SOEntry &entry)
bool SOEntryIsMainExecutable(const SOEntry &entry)
PThreadField
For the definitions of the metadata entries, see <glibc>/nptl_db/(db_info.c, structs....
lldb::addr_t GetRendezvousAddress() const
lldb::addr_t ReadWord(lldb::addr_t addr, uint64_t *dst, size_t size)
Reads an unsigned integer of size bytes from the inferior's address space starting at addr.
Rendezvous m_current
Current and previous snapshots of the rendezvous structure.
bool RemoveSOEntriesFromRemote(const LoadedModuleInfoList &module_list)
SOEntryList m_removed_soentries
List of SOEntry's removed from the link map since the last call to Resolve().
bool SaveSOEntriesFromRemote(const LoadedModuleInfoList &module_list)
SOEntryList::const_iterator iterator
ThreadInfo m_thread_info
Threading metadata read from the inferior.
iterator end() const
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:303
bool Slide(int64_t offset)
Definition Address.h:446
bool IsValid() const
Check if the object state is valid.
Definition Address.h:355
An architecture specification class.
Definition ArchSpec.h:32
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:545
bool IsMIPS() const
if MIPS architecture return true.
Definition ArchSpec.cpp:749
A uniqued constant string class.
Definition ConstString.h:40
bool IsEmpty() const
Test for empty string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition FileSpec.cpp:174
std::vector< LoadedModuleInfo > m_list
void PutCString(const char *cstr)
Definition Log.cpp:162
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:91
const FileSpec & GetPlatformFileSpec() const
Get accessor for the module platform file specification.
Definition Module.h:461
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
virtual lldb_private::Address GetImageInfoAddress(Target *target)
Similar to Process::GetImageInfoAddress().
Definition ObjectFile.h:448
A plug-in interface definition class for debugging a process.
Definition Process.h:368
An error handling class.
Definition Status.h:118
Defines a list of symbol context objects.
Address GetAddress() const
Definition Symbol.h:98
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition Target.cpp:1630
lldb::PlatformSP GetPlatform()
Definition Target.h:1998
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1273
const ArchSpec & GetArchitecture() const
Definition Target.h:1315
uint64_t ReadUnsignedIntegerFromMemory(const Address &addr, size_t integer_byte_size, uint64_t fail_value, Status &error, bool force_live_memory=false)
Definition Target.cpp:2429
#define LLDB_INVALID_ADDRESS
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.
Definition Log.h:338
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
void DumpToLog(lldb_private::Log *log, const char *label)
Structure representing the shared objects currently loaded into the inferior process.
lldb::addr_t path_addr
String naming the shared object.
lldb::addr_t base_addr
Base address of the loaded object.
lldb::addr_t link_addr
Address of this link_map.
lldb_private::FileSpec file_spec
File spec of shared object.
lldb::addr_t prev
Address of previous so_entry.
lldb::addr_t next
Address of next so_entry.
lldb::addr_t dyn_addr
Dynamic section of shared object.