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/Path.h"
22
23#include "DYLDRendezvous.h"
24
25using namespace lldb;
26using namespace lldb_private;
27
29 switch (state) {
31 return "eConsistent";
33 return "eAdd";
35 return "eDelete";
36 }
37 return "<invalid RendezvousState>";
38}
39
41 switch (action) {
43 return "eTakeSnapshot";
45 return "eAddModules";
47 return "eRemoveModules";
49 return "eNoAction";
50 }
51 return "<invalid RendezvousAction>";
52}
53
55 : m_process(process), m_rendezvous_addr(LLDB_INVALID_ADDRESS),
56 m_executable_interpreter(false), m_current(), m_previous(),
57 m_loaded_modules(), m_soentries(), m_added_soentries(),
58 m_removed_soentries() {
59 m_thread_info.valid = false;
61}
62
64 Log *log = GetLog(LLDBLog::DynamicLoader);
65 addr_t info_location;
66 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 (target) {
84 ObjectFile *obj_file = target->GetExecutableModule()->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 =
94 target->GetExecutableModule()->FindFirstSymbolWithNameAndType(
95 ConstString("_r_debug"));
96 if (_r_debug) {
97 info_addr = _r_debug->GetAddress().GetLoadAddress(target);
98 if (info_addr != LLDB_INVALID_ADDRESS) {
99 LLDB_LOGF(log,
100 "%s resolved by finding symbol '_r_debug' whose value is "
101 "0x%" PRIx64,
102 __FUNCTION__, info_addr);
104 return info_addr;
105 }
106 }
107 LLDB_LOGF(log,
108 "%s FAILED - direct object file approach did not yield a "
109 "valid address",
110 __FUNCTION__);
111 }
112 }
113 }
114
115 if (info_location == LLDB_INVALID_ADDRESS) {
116 LLDB_LOGF(log, "%s FAILED - invalid info address", __FUNCTION__);
118 }
119
120 LLDB_LOGF(log, "%s reading pointer (%" PRIu32 " bytes) from 0x%" PRIx64,
121 __FUNCTION__, m_process->GetAddressByteSize(), info_location);
122
123 info_addr = m_process->ReadPointerFromMemory(info_location, error);
124 if (error.Fail()) {
125 LLDB_LOGF(log, "%s FAILED - could not read from the info location: %s",
126 __FUNCTION__, error.AsCString());
128 }
129
130 if (info_addr == 0) {
131 LLDB_LOGF(log,
132 "%s FAILED - the rendezvous address contained at 0x%" PRIx64
133 " returned a null value",
134 __FUNCTION__, info_location);
136 }
137
138 return info_addr;
139}
140
142 if (m_process) {
143 Log *log = GetLog(LLDBLog::DynamicLoader);
145 if (exe_mod) {
147 LLDB_LOGF(log, "DYLDRendezvous::%s exe module executable path set: '%s'",
148 __FUNCTION__, m_exe_file_spec.GetPath().c_str());
149 } else {
150 LLDB_LOGF(log,
151 "DYLDRendezvous::%s cannot cache exe module path: null "
152 "executable module pointer",
153 __FUNCTION__);
154 }
155 }
156}
157
158void DYLDRendezvous::Rendezvous::DumpToLog(Log *log, const char *label) {
159 LLDB_LOGF(log, "%s Rendezvous: version = %" PRIu64 ", map_addr = 0x%16.16"
160 PRIx64 ", brk = 0x%16.16" PRIx64 ", state = %" PRIu64
161 " (%s), ldbase = 0x%16.16" PRIx64, label ? label : "", version,
163}
164
166 Log *log = GetLog(LLDBLog::DynamicLoader);
167
168 const size_t word_size = 4;
169 Rendezvous info;
170 size_t address_size;
171 size_t padding;
172 addr_t info_addr;
173 addr_t cursor;
174
175 address_size = m_process->GetAddressByteSize();
176 padding = address_size - word_size;
177 LLDB_LOGF(log,
178 "DYLDRendezvous::%s address size: %" PRIu64 ", padding %" PRIu64,
179 __FUNCTION__, uint64_t(address_size), uint64_t(padding));
180
182 cursor = info_addr =
184 else
185 cursor = info_addr = m_rendezvous_addr;
186 LLDB_LOGF(log, "DYLDRendezvous::%s cursor = 0x%" PRIx64, __FUNCTION__,
187 cursor);
188
189 if (cursor == LLDB_INVALID_ADDRESS)
190 return false;
191
192 if (!(cursor = ReadWord(cursor, &info.version, word_size)))
193 return false;
194
195 if (!(cursor = ReadPointer(cursor + padding, &info.map_addr)))
196 return false;
197
198 if (!(cursor = ReadPointer(cursor, &info.brk)))
199 return false;
200
201 if (!(cursor = ReadWord(cursor, &info.state, word_size)))
202 return false;
203
204 if (!(cursor = ReadPointer(cursor + padding, &info.ldbase)))
205 return false;
206
207 // The rendezvous was successfully read. Update our internal state.
208 m_rendezvous_addr = info_addr;
210 m_current = info;
211
212 m_previous.DumpToLog(log, "m_previous");
213 m_current.DumpToLog(log, "m_current ");
214
215 if (m_current.map_addr == 0)
216 return false;
217
219 return true;
220
221 return UpdateSOEntries();
222}
223
226}
227
229 // If we have a core file, we will read the current rendezvous state
230 // from the core file's memory into m_current which can be in an inconsistent
231 // state, so we can't rely on its state to determine what we should do. We
232 // always need it to load all of the shared libraries one time when we attach
233 // to a core file.
234 if (IsCoreFile())
235 return eTakeSnapshot;
236
237 switch (m_current.state) {
238
239 case eConsistent:
240 switch (m_previous.state) {
241 // When the previous and current states are consistent this is the first
242 // time we have been asked to update. Just take a snapshot of the
243 // currently loaded modules.
244 case eConsistent:
245 return eTakeSnapshot;
246 // If we are about to add or remove a shared object clear out the current
247 // state and take a snapshot of the currently loaded images.
248 case eAdd:
249 return eAddModules;
250 case eDelete:
251 return eRemoveModules;
252 }
253 break;
254
255 case eAdd:
256 // If the main executable or a shared library defines a publicly visible
257 // symbol named "_r_debug", then it will cause problems once the executable
258 // that contains the symbol is loaded into the process. The correct
259 // "_r_debug" structure is currently found by LLDB by looking through
260 // the .dynamic section in the main executable and finding the DT_DEBUG tag
261 // entry.
262 //
263 // An issue comes up if someone defines another publicly visible "_r_debug"
264 // struct in their program. Sample code looks like:
265 //
266 // #include <link.h>
267 // r_debug _r_debug;
268 //
269 // If code like this is in an executable or shared library, this creates a
270 // new "_r_debug" structure and it causes problems once the executable is
271 // loaded due to the way symbol lookups happen in linux: the shared library
272 // list from _r_debug.r_map will be searched for a symbol named "_r_debug"
273 // and the first match will be the new version that is used. The dynamic
274 // loader is always last in this list. So at some point the dynamic loader
275 // will start updating the copy of "_r_debug" that gets found first. The
276 // issue is that LLDB will only look at the copy that is pointed to by the
277 // DT_DEBUG entry, or the initial version from the ld.so binary.
278 //
279 // Steps that show the problem are:
280 //
281 // - LLDB finds the "_r_debug" structure via the DT_DEBUG entry in the
282 // .dynamic section and this points to the "_r_debug" in ld.so
283 // - ld.so uodates its copy of "_r_debug" with "state = eAdd" before it
284 // loads the dependent shared libraries for the main executable and
285 // any dependencies of all shared libraries from the executable's list
286 // and ld.so code calls the debugger notification function
287 // that LLDB has set a breakpoint on.
288 // - LLDB hits the breakpoint and the breakpoint has a callback function
289 // where we read the _r_debug.state (eAdd) state and we do nothing as the
290 // "eAdd" state indicates that the shared libraries are about to be added.
291 // - ld.so finishes loading the main executable and any dependent shared
292 // libraries and it will update the "_r_debug.state" member with a
293 // "eConsistent", but it now updates the "_r_debug" in the a.out program
294 // and it calls the debugger notification function.
295 // - lldb hits the notification breakpoint and checks the ld.so copy of
296 // "_r_debug.state" which still has a state of "eAdd", but LLDB needs to see a
297 // "eConsistent" state to trigger the shared libraries to get loaded into
298 // the debug session, but LLDB the ld.so _r_debug.state which still
299 // contains "eAdd" and doesn't do anyhing and library load is missed.
300 // The "_r_debug" in a.out has the state set correctly to "eConsistent"
301 // but LLDB is still looking at the "_r_debug" from ld.so.
302 //
303 // So if we detect two "eAdd" states in a row, we assume this is the issue
304 // and we now load shared libraries correctly and will emit a log message
305 // in the "log enable lldb dyld" log channel which states there might be
306 // multiple "_r_debug" structs causing problems.
307 //
308 // The correct solution is that no one should be adding a duplicate
309 // publicly visible "_r_debug" symbols to their binaries, but we have
310 // programs that are doing this already and since it can be done, we should
311 // be able to work with this and keep debug sessions working as expected.
312 //
313 // If a user includes the <link.h> file, they can just use the existing
314 // "_r_debug" structure as it is defined in this header file as "extern
315 // struct r_debug _r_debug;" and no local copies need to be made.
316 if (m_previous.state == eAdd) {
317 Log *log = GetLog(LLDBLog::DynamicLoader);
318 LLDB_LOG(log, "DYLDRendezvous::GetAction() found two eAdd states in a "
319 "row, check process for multiple \"_r_debug\" symbols. "
320 "Returning eAddModules to ensure shared libraries get loaded "
321 "correctly");
322 return eAddModules;
323 }
324 return eNoAction;
325 case eDelete:
326 return eNoAction;
327 }
328
329 return eNoAction;
330}
331
333 const auto action = GetAction();
334 Log *log = GetLog(LLDBLog::DynamicLoader);
335 LLDB_LOG(log, "{0} action = {1}", LLVM_PRETTY_FUNCTION, ActionToCStr(action));
336
337 if (action == eNoAction)
338 return false;
339
340 m_added_soentries.clear();
341 m_removed_soentries.clear();
342 if (action == eTakeSnapshot) {
343 // We already have the loaded list from the previous update so no need to
344 // find all the modules again.
345 if (!m_loaded_modules.m_list.empty())
346 return true;
347 }
348
349 llvm::Expected<LoadedModuleInfoList> module_list =
351 if (!module_list) {
352 llvm::consumeError(module_list.takeError());
353 return false;
354 }
355
356 switch (action) {
357 case eTakeSnapshot:
358 m_soentries.clear();
359 return SaveSOEntriesFromRemote(*module_list);
360 case eAddModules:
361 return AddSOEntriesFromRemote(*module_list);
362 case eRemoveModules:
363 return RemoveSOEntriesFromRemote(*module_list);
364 case eNoAction:
365 return false;
366 }
367 llvm_unreachable("Fully covered switch above!");
368}
369
371 m_added_soentries.clear();
372 m_removed_soentries.clear();
373 const auto action = GetAction();
374 Log *log = GetLog(LLDBLog::DynamicLoader);
375 LLDB_LOG(log, "{0} action = {1}", LLVM_PRETTY_FUNCTION, ActionToCStr(action));
376 switch (action) {
377 case eTakeSnapshot:
378 m_soentries.clear();
380 case eAddModules:
381 return AddSOEntries();
382 case eRemoveModules:
383 return RemoveSOEntries();
384 case eNoAction:
385 return false;
386 }
387 llvm_unreachable("Fully covered switch above!");
388}
389
391 LoadedModuleInfoList::LoadedModuleInfo const &modInfo, SOEntry &entry) {
392 addr_t link_map_addr;
393 addr_t base_addr;
394 addr_t dyn_addr;
395 std::string name;
396
397 if (!modInfo.get_link_map(link_map_addr) || !modInfo.get_base(base_addr) ||
398 !modInfo.get_dynamic(dyn_addr) || !modInfo.get_name(name))
399 return false;
400
401 entry.link_addr = link_map_addr;
402 entry.base_addr = base_addr;
403 entry.dyn_addr = dyn_addr;
404
405 entry.file_spec.SetFile(name, FileSpec::Style::native);
406
407 UpdateBaseAddrIfNecessary(entry, name);
408
409 // not needed if we're using ModuleInfos
410 entry.next = 0;
411 entry.prev = 0;
412 entry.path_addr = 0;
413
414 return true;
415}
416
418 const LoadedModuleInfoList &module_list) {
419 for (auto const &modInfo : module_list.m_list) {
420 SOEntry entry;
421 if (!FillSOEntryFromModuleInfo(modInfo, entry))
422 return false;
423
424 // Only add shared libraries and not the executable.
425 if (!SOEntryIsMainExecutable(entry)) {
427 m_soentries.push_back(entry);
428 }
429 }
430
431 m_loaded_modules = module_list;
432 return true;
433}
434
436 const LoadedModuleInfoList &module_list) {
437 for (auto const &modInfo : module_list.m_list) {
438 bool found = false;
439 for (auto const &existing : m_loaded_modules.m_list) {
440 if (modInfo == existing) {
441 found = true;
442 break;
443 }
444 }
445
446 if (found)
447 continue;
448
449 SOEntry entry;
450 if (!FillSOEntryFromModuleInfo(modInfo, entry))
451 return false;
452
453 // Only add shared libraries and not the executable.
454 if (!SOEntryIsMainExecutable(entry)) {
456 m_soentries.push_back(entry);
457 m_added_soentries.push_back(entry);
458 }
459 }
460
461 m_loaded_modules = module_list;
462 return true;
463}
464
466 const LoadedModuleInfoList &module_list) {
467 for (auto const &existing : m_loaded_modules.m_list) {
468 bool found = false;
469 for (auto const &modInfo : module_list.m_list) {
470 if (modInfo == existing) {
471 found = true;
472 break;
473 }
474 }
475
476 if (found)
477 continue;
478
479 SOEntry entry;
480 if (!FillSOEntryFromModuleInfo(existing, entry))
481 return false;
482
483 // Only add shared libraries and not the executable.
484 if (!SOEntryIsMainExecutable(entry)) {
485 auto pos = llvm::find(m_soentries, entry);
486 if (pos == m_soentries.end())
487 return false;
488
489 m_soentries.erase(pos);
490 m_removed_soentries.push_back(entry);
491 }
492 }
493
494 m_loaded_modules = module_list;
495 return true;
496}
497
499 SOEntry entry;
500 iterator pos;
501
502 assert(m_previous.state == eAdd);
503
504 if (m_current.map_addr == 0)
505 return false;
506
507 for (addr_t cursor = m_current.map_addr; cursor != 0; cursor = entry.next) {
508 if (!ReadSOEntryFromMemory(cursor, entry))
509 return false;
510
511 // Only add shared libraries and not the executable.
512 if (SOEntryIsMainExecutable(entry))
513 continue;
514
516
517 if (!llvm::is_contained(m_soentries, entry)) {
518 m_soentries.push_back(entry);
519 m_added_soentries.push_back(entry);
520 }
521 }
522
523 return true;
524}
525
527 SOEntryList entry_list;
528 iterator pos;
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 return entry.file_spec == m_exe_file_spec;
553 case llvm::Triple::Linux:
554 if (triple.isAndroid())
555 return entry.file_spec == m_exe_file_spec;
556 // If we are debugging ld.so, then all SOEntries should be treated as
557 // libraries, including the "main" one (denoted by an empty string).
559 return false;
560 return !entry.file_spec;
561 default:
562 return false;
563 }
564}
565
567 SOEntry entry;
568
569 if (m_current.map_addr == 0)
570 return false;
571
572 // Clear previous entries since we are about to obtain an up to date list.
573 entry_list.clear();
574
575 for (addr_t cursor = m_current.map_addr; cursor != 0; cursor = entry.next) {
576 if (!ReadSOEntryFromMemory(cursor, entry))
577 return false;
578
579 // Only add shared libraries and not the executable.
580 if (SOEntryIsMainExecutable(entry))
581 continue;
582
584
585 entry_list.push_back(entry);
586 }
587
588 return true;
589}
590
591addr_t DYLDRendezvous::ReadWord(addr_t addr, uint64_t *dst, size_t size) {
593
594 *dst = m_process->ReadUnsignedIntegerFromMemory(addr, size, 0, error);
595 if (error.Fail())
596 return 0;
597
598 return addr + size;
599}
600
603
605 if (error.Fail())
606 return 0;
607
608 return addr + m_process->GetAddressByteSize();
609}
610
612 std::string str;
614
615 if (addr == LLDB_INVALID_ADDRESS)
616 return std::string();
617
619
620 return str;
621}
622
623// Returns true if the load bias reported by the linker is incorrect for the
624// given entry. This function is used to handle cases where we want to work
625// around a bug in the system linker.
626static bool isLoadBiasIncorrect(Target &target, const std::string &file_path) {
627 // On Android L (API 21, 22) the load address of the "/system/bin/linker"
628 // isn't filled in correctly.
629 unsigned os_major = target.GetPlatform()->GetOSVersion().getMajor();
630 return target.GetArchitecture().GetTriple().isAndroid() &&
631 (os_major == 21 || os_major == 22) &&
632 (file_path == "/system/bin/linker" ||
633 file_path == "/system/bin/linker64");
634}
635
637 std::string const &file_path) {
638 // If the load bias reported by the linker is incorrect then fetch the load
639 // address of the file from the proc file system.
640 if (isLoadBiasIncorrect(m_process->GetTarget(), file_path)) {
642 bool is_loaded = false;
643 Status error =
644 m_process->GetFileLoadAddress(entry.file_spec, is_loaded, load_addr);
645 if (error.Success() && is_loaded)
646 entry.base_addr = load_addr;
647 }
648}
649
651 // Updates filename if empty. It is useful while debugging ld.so,
652 // when the link map returns empty string for the main executable.
653 if (!entry.file_spec) {
654 MemoryRegionInfo region;
655 Status region_status =
656 m_process->GetMemoryRegionInfo(entry.dyn_addr, region);
657 if (!region.GetName().IsEmpty())
658 entry.file_spec.SetFile(region.GetName().AsCString(),
659 FileSpec::Style::native);
660 }
661}
662
664 entry.clear();
665
666 entry.link_addr = addr;
667
668 if (!(addr = ReadPointer(addr, &entry.base_addr)))
669 return false;
670
671 // mips adds an extra load offset field to the link map struct on FreeBSD and
672 // NetBSD (need to validate other OSes).
673 // http://svnweb.freebsd.org/base/head/sys/sys/link_elf.h?revision=217153&view=markup#l57
674 const ArchSpec &arch = m_process->GetTarget().GetArchitecture();
675 if ((arch.GetTriple().getOS() == llvm::Triple::FreeBSD ||
676 arch.GetTriple().getOS() == llvm::Triple::NetBSD) &&
677 arch.IsMIPS()) {
678 addr_t mips_l_offs;
679 if (!(addr = ReadPointer(addr, &mips_l_offs)))
680 return false;
681 if (mips_l_offs != 0 && mips_l_offs != entry.base_addr)
682 return false;
683 }
684
685 if (!(addr = ReadPointer(addr, &entry.path_addr)))
686 return false;
687
688 if (!(addr = ReadPointer(addr, &entry.dyn_addr)))
689 return false;
690
691 if (!(addr = ReadPointer(addr, &entry.next)))
692 return false;
693
694 if (!(addr = ReadPointer(addr, &entry.prev)))
695 return false;
696
697 std::string file_path = ReadStringFromMemory(entry.path_addr);
698 entry.file_spec.SetFile(file_path, FileSpec::Style::native);
699
700 UpdateBaseAddrIfNecessary(entry, file_path);
701
702 return true;
703}
704
705bool DYLDRendezvous::FindMetadata(const char *name, PThreadField field,
706 uint32_t &value) {
707 Target &target = m_process->GetTarget();
708
711 eSymbolTypeAny, list);
712 if (list.IsEmpty())
713 return false;
714
715 Address address = list[0].symbol->GetAddress();
716 addr_t addr = address.GetLoadAddress(&target);
717 if (addr == LLDB_INVALID_ADDRESS)
718 return false;
719
721 value = (uint32_t)m_process->ReadUnsignedIntegerFromMemory(
722 addr + field * sizeof(uint32_t), sizeof(uint32_t), 0, error);
723 if (error.Fail())
724 return false;
725
726 if (field == eSize)
727 value /= 8; // convert bits to bytes
728
729 return true;
730}
731
733 if (!m_thread_info.valid) {
734 bool ok = true;
735
736 ok &= FindMetadata("_thread_db_pthread_dtvp", eOffset,
738 ok &=
739 FindMetadata("_thread_db_dtv_dtv", eSize, m_thread_info.dtv_slot_size);
740 ok &= FindMetadata("_thread_db_link_map_l_tls_modid", eOffset,
742 ok &= FindMetadata("_thread_db_dtv_t_pointer_val", eOffset,
744
745 if (ok)
746 m_thread_info.valid = true;
747 }
748
749 return m_thread_info;
750}
751
753 int state = GetState();
754
755 if (!log)
756 return;
757
758 log->PutCString("DYLDRendezvous:");
759 LLDB_LOGF(log, " Address: %" PRIx64, GetRendezvousAddress());
760 LLDB_LOGF(log, " Version: %" PRIu64, GetVersion());
761 LLDB_LOGF(log, " Link : %" PRIx64, GetLinkMapAddress());
762 LLDB_LOGF(log, " Break : %" PRIx64, GetBreakAddress());
763 LLDB_LOGF(log, " LDBase : %" PRIx64, GetLDBase());
764 LLDB_LOGF(log, " State : %s",
765 (state == eConsistent)
766 ? "consistent"
767 : (state == eAdd) ? "add"
768 : (state == eDelete) ? "delete" : "unknown");
769
770 iterator I = begin();
771 iterator E = end();
772
773 if (I != E)
774 log->PutCString("DYLDRendezvous SOEntries:");
775
776 for (int i = 1; I != E; ++I, ++i) {
777 LLDB_LOGF(log, "\n SOEntry [%d] %s", i, I->file_spec.GetPath().c_str());
778 LLDB_LOGF(log, " Base : %" PRIx64, I->base_addr);
779 LLDB_LOGF(log, " Path : %" PRIx64, I->path_addr);
780 LLDB_LOGF(log, " Dyn : %" PRIx64, I->dyn_addr);
781 LLDB_LOGF(log, " Next : %" PRIx64, I->next);
782 LLDB_LOGF(log, " Prev : %" PRIx64, I->prev);
783 }
784}
785
787 return !m_process->IsLiveDebugSession();
788}
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:342
#define LLDB_LOGF(log,...)
Definition: Log.h:349
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)
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:59
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:311
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:345
An architecture specification class.
Definition: ArchSpec.h:31
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:450
bool IsMIPS() const
if MIPS architecture return true.
Definition: ArchSpec.cpp:559
A uniqued constant string class.
Definition: ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:182
bool IsEmpty() const
Test for empty string.
Definition: ConstString.h:293
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition: FileSpec.cpp:174
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:367
std::vector< LoadedModuleInfo > m_list
void PutCString(const char *cstr)
Definition: Log.cpp:134
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
Definition: ModuleList.cpp:500
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:88
const FileSpec & GetPlatformFileSpec() const
Get accessor for the module platform file specification.
Definition: Module.h:511
A plug-in interface definition class for object file parsers.
Definition: ObjectFile.h:44
virtual lldb_private::Address GetImageInfoAddress(Target *target)
Similar to Process::GetImageInfoAddress().
Definition: ObjectFile.h:459
A plug-in interface definition class for debugging a process.
Definition: Process.h:336
size_t ReadCStringFromMemory(lldb::addr_t vm_addr, char *cstr, size_t cstr_max_len, Status &error)
Read a NULL terminated C string from memory.
Definition: Process.cpp:1992
virtual llvm::Expected< LoadedModuleInfoList > GetLoadedModuleList()
Query remote GDBServer for a detailed loaded library list.
Definition: Process.h:692
uint64_t ReadUnsignedIntegerFromMemory(lldb::addr_t load_addr, size_t byte_size, uint64_t fail_value, Status &error)
Reads an unsigned integer of the specified byte size from process memory.
Definition: Process.cpp:2067
virtual lldb::addr_t GetImageInfoAddress()
Get the image information address for the current process.
Definition: Process.cpp:1485
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
Definition: Process.cpp:2089
virtual Status GetFileLoadAddress(const FileSpec &file, bool &is_loaded, lldb::addr_t &load_addr)
Try to find the load address of a file.
Definition: Process.h:2496
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3403
virtual bool IsLiveDebugSession() const
Definition: Process.h:1470
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info)
Locate the memory region that contains load_addr.
Definition: Process.cpp:5971
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1242
An error handling class.
Definition: Status.h:44
Defines a list of symbol context objects.
Address GetAddress() const
Definition: Symbol.h:87
Module * GetExecutableModulePointer()
Definition: Target.cpp:1389
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition: Target.cpp:1375
lldb::PlatformSP GetPlatform()
Definition: Target.h:1428
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition: Target.h:967
const ArchSpec & GetArchitecture() const
Definition: Target.h:1009
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:76
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:314
Definition: SBAddress.h:15
uint64_t addr_t
Definition: lldb-types.h:79
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.