LLDB mainline
DynamicLoaderDarwin.cpp
Go to the documentation of this file.
1//===-- DynamicLoaderDarwin.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
10
12#include "lldb/Core/Debugger.h"
13#include "lldb/Core/Module.h"
16#include "lldb/Core/Section.h"
19#include "lldb/Host/HostInfo.h"
22#include "lldb/Target/ABI.h"
25#include "lldb/Target/Target.h"
26#include "lldb/Target/Thread.h"
32#include "lldb/Utility/Log.h"
33#include "lldb/Utility/State.h"
34
37
38//#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN
39#ifdef ENABLE_DEBUG_PRINTF
40#include <cstdio>
41#define DEBUG_PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__)
42#else
43#define DEBUG_PRINTF(fmt, ...)
44#endif
45
46#include <memory>
47
48using namespace lldb;
49using namespace lldb_private;
50
51// Constructor
53 : DynamicLoader(process), m_dyld_module_wp(), m_libpthread_module_wp(),
54 m_pthread_getspecific_addr(), m_tid_to_tls_map(), m_dyld_image_infos(),
55 m_dyld_image_infos_stop_id(UINT32_MAX), m_dyld(), m_mutex() {}
56
57// Destructor
59
60/// Called after attaching a process.
61///
62/// Allow DynamicLoader plug-ins to execute some code after
63/// attaching to a process.
68}
69
70/// Called after attaching a process.
71///
72/// Allow DynamicLoader plug-ins to execute some code after
73/// attaching to a process.
78}
79
80// Clear out the state of this class.
81void DynamicLoaderDarwin::Clear(bool clear_process) {
82 std::lock_guard<std::recursive_mutex> guard(m_mutex);
83 if (clear_process)
84 m_process = nullptr;
85 m_dyld_image_infos.clear();
87 m_dyld.Clear(false);
88}
89
91 ImageInfo &image_info, bool can_create, bool *did_create_ptr) {
92 if (did_create_ptr)
93 *did_create_ptr = false;
94
95 Target &target = m_process->GetTarget();
96 const ModuleList &target_images = target.GetImages();
97 ModuleSpec module_spec(image_info.file_spec);
98 module_spec.GetUUID() = image_info.uuid;
99
100 // macCatalyst support: Request matching os/environment.
101 {
102 auto &target_triple = target.GetArchitecture().GetTriple();
103 if (target_triple.getOS() == llvm::Triple::IOS &&
104 target_triple.getEnvironment() == llvm::Triple::MacABI) {
105 // Request the macCatalyst variant of frameworks that have both
106 // a PLATFORM_MACOS and a PLATFORM_MACCATALYST load command.
107 module_spec.GetArchitecture() = ArchSpec(target_triple);
108 }
109 }
110
111 ModuleSP module_sp(target_images.FindFirstModule(module_spec));
112
113 if (module_sp && !module_spec.GetUUID().IsValid() &&
114 !module_sp->GetUUID().IsValid()) {
115 // No UUID, we must rely upon the cached module modification time and the
116 // modification time of the file on disk
117 if (module_sp->GetModificationTime() !=
118 FileSystem::Instance().GetModificationTime(module_sp->GetFileSpec()))
119 module_sp.reset();
120 }
121
122 if (module_sp || !can_create)
123 return module_sp;
124
125 if (HostInfo::GetArchitecture().IsCompatibleMatch(target.GetArchitecture())) {
126 // When debugging on the host, we are most likely using the same shared
127 // cache as our inferior. The dylibs from the shared cache might not
128 // exist on the filesystem, so let's use the images in our own memory
129 // to create the modules.
130 // Check if the requested image is in our shared cache.
131 SharedCacheImageInfo image_info =
132 HostInfo::GetSharedCacheImageInfo(module_spec.GetFileSpec().GetPath());
133
134 // If we found it and it has the correct UUID, let's proceed with
135 // creating a module from the memory contents.
136 if (image_info.uuid &&
137 (!module_spec.GetUUID() || module_spec.GetUUID() == image_info.uuid)) {
138 ModuleSpec shared_cache_spec(module_spec.GetFileSpec(), image_info.uuid,
139 image_info.data_sp);
140 module_sp =
141 target.GetOrCreateModule(shared_cache_spec, false /* notify */);
142 }
143 }
144 // We'll call Target::ModulesDidLoad after all the modules have been
145 // added to the target, don't let it be called for every one.
146 if (!module_sp)
147 module_sp = target.GetOrCreateModule(module_spec, false /* notify */);
148 if (!module_sp || module_sp->GetObjectFile() == nullptr)
149 module_sp = m_process->ReadModuleFromMemory(image_info.file_spec,
150 image_info.address);
151
152 if (did_create_ptr)
153 *did_create_ptr = (bool)module_sp;
154
155 return module_sp;
156}
157
159 const std::vector<lldb::addr_t> &solib_addresses) {
160 std::lock_guard<std::recursive_mutex> guard(m_mutex);
162 return;
163
165 Target &target = m_process->GetTarget();
166 LLDB_LOGF(log, "Removing %" PRId64 " modules.",
167 (uint64_t)solib_addresses.size());
168
169 ModuleList unloaded_module_list;
170
171 for (addr_t solib_addr : solib_addresses) {
172 Address header;
173 if (header.SetLoadAddress(solib_addr, &target)) {
174 if (header.GetOffset() == 0) {
175 ModuleSP module_to_remove(header.GetModule());
176 if (module_to_remove.get()) {
177 LLDB_LOGF(log, "Removing module at address 0x%" PRIx64, solib_addr);
178 // remove the sections from the Target
179 UnloadSections(module_to_remove);
180 // add this to the list of modules to remove
181 unloaded_module_list.AppendIfNeeded(module_to_remove);
182 // remove the entry from the m_dyld_image_infos
183 ImageInfo::collection::iterator pos, end = m_dyld_image_infos.end();
184 for (pos = m_dyld_image_infos.begin(); pos != end; pos++) {
185 if (solib_addr == (*pos).address) {
186 m_dyld_image_infos.erase(pos);
187 break;
188 }
189 }
190 }
191 }
192 }
193 }
194
195 if (unloaded_module_list.GetSize() > 0) {
196 if (log) {
197 log->PutCString("Unloaded:");
198 unloaded_module_list.LogUUIDAndPaths(
199 log, "DynamicLoaderDarwin::UnloadModules");
200 }
201 m_process->GetTarget().GetImages().Remove(unloaded_module_list);
203 }
204}
205
208 ModuleList unloaded_modules_list;
209
210 Target &target = m_process->GetTarget();
211 const ModuleList &target_modules = target.GetImages();
212 std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
213
214 ModuleSP dyld_sp(GetDYLDModule());
215 for (ModuleSP module_sp : target_modules.Modules()) {
216 // Don't remove dyld - else we'll lose our breakpoint notifying us about
217 // libraries being re-loaded...
218 if (module_sp && module_sp != dyld_sp) {
219 UnloadSections(module_sp);
220 unloaded_modules_list.Append(module_sp);
221 }
222 }
223
224 if (unloaded_modules_list.GetSize() != 0) {
225 if (log) {
226 log->PutCString("Unloaded:");
227 unloaded_modules_list.LogUUIDAndPaths(
228 log, "DynamicLoaderDarwin::UnloadAllImages");
229 }
230 target.GetImages().Remove(unloaded_modules_list);
231 m_dyld_image_infos.clear();
233 }
234}
235
236// Update the load addresses for all segments in MODULE using the updated INFO
237// that is passed in.
239 ImageInfo &info) {
240 bool changed = false;
241 if (module) {
242 ObjectFile *image_object_file = module->GetObjectFile();
243 if (image_object_file) {
244 SectionList *section_list = image_object_file->GetSectionList();
245 if (section_list) {
246 std::vector<uint32_t> inaccessible_segment_indexes;
247 // We now know the slide amount, so go through all sections and update
248 // the load addresses with the correct values.
249 const size_t num_segments = info.segments.size();
250 for (size_t i = 0; i < num_segments; ++i) {
251 // Only load a segment if it has protections. Things like __PAGEZERO
252 // don't have any protections, and they shouldn't be slid
253 SectionSP section_sp(
254 section_list->FindSectionByName(info.segments[i].name));
255
256 if (info.segments[i].maxprot == 0) {
257 inaccessible_segment_indexes.push_back(i);
258 } else {
259 const addr_t new_section_load_addr =
260 info.segments[i].vmaddr + info.slide;
261 static ConstString g_section_name_LINKEDIT("__LINKEDIT");
262
263 if (section_sp) {
264 // __LINKEDIT sections from files in the shared cache can overlap
265 // so check to see what the segment name is and pass "false" so
266 // we don't warn of overlapping "Section" objects, and "true" for
267 // all other sections.
268 const bool warn_multiple =
269 section_sp->GetName() != g_section_name_LINKEDIT;
270
272 section_sp, new_section_load_addr, warn_multiple);
273 }
274 }
275 }
276
277 // If the loaded the file (it changed) and we have segments that are
278 // not readable or writeable, add them to the invalid memory region
279 // cache for the process. This will typically only be the __PAGEZERO
280 // segment in the main executable. We might be able to apply this more
281 // generally to more sections that have no protections in the future,
282 // but for now we are going to just do __PAGEZERO.
283 if (changed && !inaccessible_segment_indexes.empty()) {
284 for (uint32_t i = 0; i < inaccessible_segment_indexes.size(); ++i) {
285 const uint32_t seg_idx = inaccessible_segment_indexes[i];
286 SectionSP section_sp(
287 section_list->FindSectionByName(info.segments[seg_idx].name));
288
289 if (section_sp) {
290 static ConstString g_pagezero_section_name("__PAGEZERO");
291 if (g_pagezero_section_name == section_sp->GetName()) {
292 // __PAGEZERO never slides...
293 const lldb::addr_t vmaddr = info.segments[seg_idx].vmaddr;
294 const lldb::addr_t vmsize = info.segments[seg_idx].vmsize;
295 Process::LoadRange pagezero_range(vmaddr, vmsize);
296 m_process->AddInvalidMemoryRegion(pagezero_range);
297 }
298 }
299 }
300 }
301 }
302 }
303 }
304 // We might have an in memory image that was loaded as soon as it was created
305 if (info.load_stop_id == m_process->GetStopID())
306 changed = true;
307 else if (changed) {
308 // Update the stop ID when this library was updated
310 }
311 return changed;
312}
313
314// Unload the segments in MODULE using the INFO that is passed in.
316 ImageInfo &info) {
317 bool changed = false;
318 if (module) {
319 ObjectFile *image_object_file = module->GetObjectFile();
320 if (image_object_file) {
321 SectionList *section_list = image_object_file->GetSectionList();
322 if (section_list) {
323 const size_t num_segments = info.segments.size();
324 for (size_t i = 0; i < num_segments; ++i) {
325 SectionSP section_sp(
326 section_list->FindSectionByName(info.segments[i].name));
327 if (section_sp) {
328 const addr_t old_section_load_addr =
329 info.segments[i].vmaddr + info.slide;
331 section_sp, old_section_load_addr))
332 changed = true;
333 } else {
335 llvm::formatv("unable to find and unload segment named "
336 "'{0}' in '{1}' in macosx dynamic loader plug-in",
337 info.segments[i].name.AsCString("<invalid>"),
338 image_object_file->GetFileSpec().GetPath()));
339 }
340 }
341 }
342 }
343 }
344 return changed;
345}
346
347// Given a JSON dictionary (from debugserver, most likely) of binary images
348// loaded in the inferior process, add the images to the ImageInfo collection.
349
351 StructuredData::ObjectSP image_details,
352 ImageInfo::collection &image_infos) {
353 StructuredData::ObjectSP images_sp =
354 image_details->GetAsDictionary()->GetValueForKey("images");
355 if (images_sp.get() == nullptr)
356 return false;
357
358 image_infos.resize(images_sp->GetAsArray()->GetSize());
359
360 for (size_t i = 0; i < image_infos.size(); i++) {
361 StructuredData::ObjectSP image_sp =
362 images_sp->GetAsArray()->GetItemAtIndex(i);
363 if (image_sp.get() == nullptr || image_sp->GetAsDictionary() == nullptr)
364 return false;
365 StructuredData::Dictionary *image = image_sp->GetAsDictionary();
366 // clang-format off
367 if (!image->HasKey("load_address") ||
368 !image->HasKey("pathname") ||
369 !image->HasKey("mach_header") ||
370 image->GetValueForKey("mach_header")->GetAsDictionary() == nullptr ||
371 !image->HasKey("segments") ||
372 image->GetValueForKey("segments")->GetAsArray() == nullptr ||
373 !image->HasKey("uuid")) {
374 return false;
375 }
376 // clang-format on
377 image_infos[i].address =
378 image->GetValueForKey("load_address")->GetUnsignedIntegerValue();
379 image_infos[i].file_spec.SetFile(
380 image->GetValueForKey("pathname")->GetAsString()->GetValue(),
381 FileSpec::Style::native);
382
384 image->GetValueForKey("mach_header")->GetAsDictionary();
385 image_infos[i].header.magic =
386 mh->GetValueForKey("magic")->GetUnsignedIntegerValue();
387 image_infos[i].header.cputype =
388 mh->GetValueForKey("cputype")->GetUnsignedIntegerValue();
389 image_infos[i].header.cpusubtype =
390 mh->GetValueForKey("cpusubtype")->GetUnsignedIntegerValue();
391 image_infos[i].header.filetype =
392 mh->GetValueForKey("filetype")->GetUnsignedIntegerValue();
393
394 if (image->HasKey("min_version_os_name")) {
395 std::string os_name =
396 std::string(image->GetValueForKey("min_version_os_name")
397 ->GetAsString()
398 ->GetValue());
399 if (os_name == "macosx")
400 image_infos[i].os_type = llvm::Triple::MacOSX;
401 else if (os_name == "ios" || os_name == "iphoneos")
402 image_infos[i].os_type = llvm::Triple::IOS;
403 else if (os_name == "tvos")
404 image_infos[i].os_type = llvm::Triple::TvOS;
405 else if (os_name == "watchos")
406 image_infos[i].os_type = llvm::Triple::WatchOS;
407 else if (os_name == "bridgeos")
408 image_infos[i].os_type = llvm::Triple::BridgeOS;
409 else if (os_name == "maccatalyst") {
410 image_infos[i].os_type = llvm::Triple::IOS;
411 image_infos[i].os_env = llvm::Triple::MacABI;
412 } else if (os_name == "iossimulator") {
413 image_infos[i].os_type = llvm::Triple::IOS;
414 image_infos[i].os_env = llvm::Triple::Simulator;
415 } else if (os_name == "tvossimulator") {
416 image_infos[i].os_type = llvm::Triple::TvOS;
417 image_infos[i].os_env = llvm::Triple::Simulator;
418 } else if (os_name == "watchossimulator") {
419 image_infos[i].os_type = llvm::Triple::WatchOS;
420 image_infos[i].os_env = llvm::Triple::Simulator;
421 }
422 }
423 if (image->HasKey("min_version_os_sdk")) {
424 image_infos[i].min_version_os_sdk =
425 std::string(image->GetValueForKey("min_version_os_sdk")
426 ->GetAsString()
427 ->GetValue());
428 }
429
430 // Fields that aren't used by DynamicLoaderDarwin so debugserver doesn't
431 // currently send them in the reply.
432
433 if (mh->HasKey("flags"))
434 image_infos[i].header.flags =
435 mh->GetValueForKey("flags")->GetUnsignedIntegerValue();
436 else
437 image_infos[i].header.flags = 0;
438
439 if (mh->HasKey("ncmds"))
440 image_infos[i].header.ncmds =
441 mh->GetValueForKey("ncmds")->GetUnsignedIntegerValue();
442 else
443 image_infos[i].header.ncmds = 0;
444
445 if (mh->HasKey("sizeofcmds"))
446 image_infos[i].header.sizeofcmds =
447 mh->GetValueForKey("sizeofcmds")->GetUnsignedIntegerValue();
448 else
449 image_infos[i].header.sizeofcmds = 0;
450
451 StructuredData::Array *segments =
452 image->GetValueForKey("segments")->GetAsArray();
453 uint32_t segcount = segments->GetSize();
454 for (size_t j = 0; j < segcount; j++) {
455 Segment segment;
457 segments->GetItemAtIndex(j)->GetAsDictionary();
458 segment.name =
459 ConstString(seg->GetValueForKey("name")->GetAsString()->GetValue());
460 segment.vmaddr = seg->GetValueForKey("vmaddr")->GetUnsignedIntegerValue();
461 segment.vmsize = seg->GetValueForKey("vmsize")->GetUnsignedIntegerValue();
462 segment.fileoff =
463 seg->GetValueForKey("fileoff")->GetUnsignedIntegerValue();
464 segment.filesize =
465 seg->GetValueForKey("filesize")->GetUnsignedIntegerValue();
466 segment.maxprot =
467 seg->GetValueForKey("maxprot")->GetUnsignedIntegerValue();
468
469 // Fields that aren't used by DynamicLoaderDarwin so debugserver doesn't
470 // currently send them in the reply.
471
472 if (seg->HasKey("initprot"))
473 segment.initprot =
474 seg->GetValueForKey("initprot")->GetUnsignedIntegerValue();
475 else
476 segment.initprot = 0;
477
478 if (seg->HasKey("flags"))
479 segment.flags = seg->GetValueForKey("flags")->GetUnsignedIntegerValue();
480 else
481 segment.flags = 0;
482
483 if (seg->HasKey("nsects"))
484 segment.nsects =
485 seg->GetValueForKey("nsects")->GetUnsignedIntegerValue();
486 else
487 segment.nsects = 0;
488
489 image_infos[i].segments.push_back(segment);
490 }
491
492 image_infos[i].uuid.SetFromStringRef(
493 image->GetValueForKey("uuid")->GetAsString()->GetValue());
494
495 // All sections listed in the dyld image info structure will all either be
496 // fixed up already, or they will all be off by a single slide amount that
497 // is determined by finding the first segment that is at file offset zero
498 // which also has bytes (a file size that is greater than zero) in the
499 // object file.
500
501 // Determine the slide amount (if any)
502 const size_t num_sections = image_infos[i].segments.size();
503 for (size_t k = 0; k < num_sections; ++k) {
504 // Iterate through the object file sections to find the first section
505 // that starts of file offset zero and that has bytes in the file...
506 if ((image_infos[i].segments[k].fileoff == 0 &&
507 image_infos[i].segments[k].filesize > 0) ||
508 (image_infos[i].segments[k].name == "__TEXT")) {
509 image_infos[i].slide =
510 image_infos[i].address - image_infos[i].segments[k].vmaddr;
511 // We have found the slide amount, so we can exit this for loop.
512 break;
513 }
514 }
515 }
516
517 return true;
518}
519
521 ImageInfo::collection &image_infos) {
522 uint32_t exe_idx = UINT32_MAX;
523 uint32_t dyld_idx = UINT32_MAX;
524 Target &target = m_process->GetTarget();
526 ConstString g_dyld_sim_filename("dyld_sim");
527
528 ArchSpec target_arch = target.GetArchitecture();
529 const size_t image_infos_size = image_infos.size();
530 for (size_t i = 0; i < image_infos_size; i++) {
531 if (image_infos[i].header.filetype == llvm::MachO::MH_DYLINKER) {
532 // In a "simulator" process we will have two dyld modules --
533 // a "dyld" that we want to keep track of, and a "dyld_sim" which
534 // we don't need to keep track of here. dyld_sim will have a non-macosx
535 // OS.
536 if (target_arch.GetTriple().getEnvironment() == llvm::Triple::Simulator &&
537 image_infos[i].os_type != llvm::Triple::OSType::MacOSX) {
538 continue;
539 }
540
541 dyld_idx = i;
542 }
543 if (image_infos[i].header.filetype == llvm::MachO::MH_EXECUTE) {
544 exe_idx = i;
545 }
546 }
547
548 // Set the target executable if we haven't found one so far.
549 if (exe_idx != UINT32_MAX && !target.GetExecutableModule()) {
550 const bool can_create = true;
551 ModuleSP exe_module_sp(FindTargetModuleForImageInfo(image_infos[exe_idx],
552 can_create, nullptr));
553 if (exe_module_sp) {
554 LLDB_LOGF(log, "Found executable module: %s",
555 exe_module_sp->GetFileSpec().GetPath().c_str());
556 target.GetImages().AppendIfNeeded(exe_module_sp);
557 UpdateImageLoadAddress(exe_module_sp.get(), image_infos[exe_idx]);
558 if (exe_module_sp.get() != target.GetExecutableModulePointer())
559 target.SetExecutableModule(exe_module_sp, eLoadDependentsNo);
560
561 // Update the target executable's arch if necessary.
562 auto exe_triple = exe_module_sp->GetArchitecture().GetTriple();
563 if (target_arch.GetTriple().isArm64e() &&
564 exe_triple.getArch() == llvm::Triple::aarch64 &&
565 !exe_triple.isArm64e()) {
566 // On arm64e-capable Apple platforms, the system libraries are
567 // always arm64e, but applications often are arm64. When a
568 // target is created from a file, LLDB recognizes it as an
569 // arm64 target, but debugserver will still (technically
570 // correct) report the process as being arm64e. For
571 // consistency, set the target to arm64 here, so attaching to
572 // a live process behaves the same as creating a process from
573 // file.
574 auto triple = target_arch.GetTriple();
575 triple.setArchName(exe_triple.getArchName());
576 target_arch.SetTriple(triple);
577 target.SetArchitecture(target_arch, /*set_platform=*/false,
578 /*merge=*/false);
579 }
580 }
581 }
582
583 if (dyld_idx != UINT32_MAX) {
584 const bool can_create = true;
585 ModuleSP dyld_sp = FindTargetModuleForImageInfo(image_infos[dyld_idx],
586 can_create, nullptr);
587 if (dyld_sp.get()) {
588 LLDB_LOGF(log, "Found dyld module: %s",
589 dyld_sp->GetFileSpec().GetPath().c_str());
590 target.GetImages().AppendIfNeeded(dyld_sp);
591 UpdateImageLoadAddress(dyld_sp.get(), image_infos[dyld_idx]);
592 SetDYLDModule(dyld_sp);
593 }
594 }
595}
596
598 ImageInfo &image_info) {
599 if (image_info.header.filetype == llvm::MachO::MH_DYLINKER) {
600 const bool can_create = true;
601 ModuleSP dyld_sp =
602 FindTargetModuleForImageInfo(image_info, can_create, nullptr);
603 if (dyld_sp.get()) {
604 Target &target = m_process->GetTarget();
605 target.GetImages().AppendIfNeeded(dyld_sp);
606 UpdateImageLoadAddress(dyld_sp.get(), image_info);
607 SetDYLDModule(dyld_sp);
608 }
609 }
610}
611
612std::optional<lldb_private::Address> DynamicLoaderDarwin::GetStartAddress() {
614
615 auto log_err = [log](llvm::StringLiteral err_msg) -> std::nullopt_t {
616 LLDB_LOGV(log, "{}", err_msg);
617 return std::nullopt;
618 };
619
620 ModuleSP dyld_sp = GetDYLDModule();
621 if (!dyld_sp)
622 return log_err("Couldn't retrieve DYLD module. Cannot get `start` symbol.");
623
624 const Symbol *symbol =
625 dyld_sp->FindFirstSymbolWithNameAndType(ConstString("_dyld_start"));
626 if (!symbol)
627 return log_err("Cannot find `start` symbol in DYLD module.");
628
629 return symbol->GetAddress();
630}
631
633 m_dyld_module_wp = dyld_module_sp;
634}
635
637 ModuleSP dyld_sp(m_dyld_module_wp.lock());
638 return dyld_sp;
639}
640
642
644 ImageInfo::collection &image_infos) {
645 std::lock_guard<std::recursive_mutex> guard(m_mutex);
646 // Now add these images to the main list.
647 ModuleList loaded_module_list;
649 Target &target = m_process->GetTarget();
650 ModuleList &target_images = target.GetImages();
651
652 for (uint32_t idx = 0; idx < image_infos.size(); ++idx) {
653 if (log) {
654 LLDB_LOGF(log, "Adding new image at address=0x%16.16" PRIx64 ".",
655 image_infos[idx].address);
656 image_infos[idx].PutToLog(log);
657 }
658
659 m_dyld_image_infos.push_back(image_infos[idx]);
660
661 ModuleSP image_module_sp(
662 FindTargetModuleForImageInfo(image_infos[idx], true, nullptr));
663
664 if (image_module_sp) {
665 ObjectFile *objfile = image_module_sp->GetObjectFile();
666 if (objfile) {
667 SectionList *sections = objfile->GetSectionList();
668 if (sections) {
669 ConstString commpage_dbstr("__commpage");
670 Section *commpage_section =
671 sections->FindSectionByName(commpage_dbstr).get();
672 if (commpage_section) {
673 ModuleSpec module_spec(objfile->GetFileSpec(),
674 image_infos[idx].GetArchitecture());
675 module_spec.GetObjectName() = commpage_dbstr;
676 ModuleSP commpage_image_module_sp(
677 target_images.FindFirstModule(module_spec));
678 if (!commpage_image_module_sp) {
679 module_spec.SetObjectOffset(objfile->GetFileOffset() +
680 commpage_section->GetFileOffset());
681 module_spec.SetObjectSize(objfile->GetByteSize());
682 commpage_image_module_sp = target.GetOrCreateModule(module_spec,
683 true /* notify */);
684 if (!commpage_image_module_sp ||
685 commpage_image_module_sp->GetObjectFile() == nullptr) {
686 commpage_image_module_sp = m_process->ReadModuleFromMemory(
687 image_infos[idx].file_spec, image_infos[idx].address);
688 // Always load a memory image right away in the target in case
689 // we end up trying to read the symbol table from memory... The
690 // __LINKEDIT will need to be mapped so we can figure out where
691 // the symbol table bits are...
692 bool changed = false;
693 UpdateImageLoadAddress(commpage_image_module_sp.get(),
694 image_infos[idx]);
695 target.GetImages().Append(commpage_image_module_sp);
696 if (changed) {
697 image_infos[idx].load_stop_id = m_process->GetStopID();
698 loaded_module_list.AppendIfNeeded(commpage_image_module_sp);
699 }
700 }
701 }
702 }
703 }
704 }
705
706 // UpdateImageLoadAddress will return true if any segments change load
707 // address. We need to check this so we don't mention that all loaded
708 // shared libraries are newly loaded each time we hit out dyld breakpoint
709 // since dyld will list all shared libraries each time.
710 if (UpdateImageLoadAddress(image_module_sp.get(), image_infos[idx])) {
711 target_images.AppendIfNeeded(image_module_sp);
712 loaded_module_list.AppendIfNeeded(image_module_sp);
713 }
714
715 // To support macCatalyst and legacy iOS simulator,
716 // update the module's platform with the DYLD info.
717 ArchSpec dyld_spec = image_infos[idx].GetArchitecture();
718 auto &dyld_triple = dyld_spec.GetTriple();
719 if ((dyld_triple.getEnvironment() == llvm::Triple::MacABI &&
720 dyld_triple.getOS() == llvm::Triple::IOS) ||
721 (dyld_triple.getEnvironment() == llvm::Triple::Simulator &&
722 (dyld_triple.getOS() == llvm::Triple::IOS ||
723 dyld_triple.getOS() == llvm::Triple::TvOS ||
724 dyld_triple.getOS() == llvm::Triple::WatchOS)))
725 image_module_sp->MergeArchitecture(dyld_spec);
726 }
727 }
728
729 if (loaded_module_list.GetSize() > 0) {
730 if (log)
731 loaded_module_list.LogUUIDAndPaths(log,
732 "DynamicLoaderDarwin::ModulesDidLoad");
733 m_process->GetTarget().ModulesDidLoad(loaded_module_list);
734 }
735 return true;
736}
737
738// On Mac OS X libobjc (the Objective-C runtime) has several critical dispatch
739// functions written in hand-written assembly, and also have hand-written
740// unwind information in the eh_frame section. Normally we prefer analyzing
741// the assembly instructions of a currently executing frame to unwind from that
742// frame -- but on hand-written functions this profiling can fail. We should
743// use the eh_frame instructions for these functions all the time.
744//
745// As an aside, it would be better if the eh_frame entries had a flag (or were
746// extensible so they could have an Apple-specific flag) which indicates that
747// the instructions are asynchronous -- accurate at every instruction, instead
748// of our normal default assumption that they are not.
749
751 ModuleSP module_sp;
752 if (sym_ctx.symbol) {
753 module_sp = sym_ctx.symbol->GetAddressRef().GetModule();
754 }
755 if (module_sp.get() == nullptr && sym_ctx.function) {
756 module_sp =
758 }
759 if (module_sp.get() == nullptr)
760 return false;
761
763 return objc_runtime != nullptr &&
764 objc_runtime->IsModuleObjCLibrary(module_sp);
765}
766
767// Dump a Segment to the file handle provided.
769 lldb::addr_t slide) const {
770 if (log) {
771 if (slide == 0)
772 LLDB_LOGF(log, "\t\t%16s [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")",
773 name.AsCString(""), vmaddr + slide, vmaddr + slide + vmsize);
774 else
775 LLDB_LOGF(log,
776 "\t\t%16s [0x%16.16" PRIx64 " - 0x%16.16" PRIx64
777 ") slide = 0x%" PRIx64,
778 name.AsCString(""), vmaddr + slide, vmaddr + slide + vmsize,
779 slide);
780 }
781}
782
784 // Update the module's platform with the DYLD info.
786 header.cpusubtype);
787 if (os_env == llvm::Triple::MacABI && os_type == llvm::Triple::IOS) {
788 llvm::Triple triple(llvm::Twine(arch_spec.GetArchitectureName()) +
789 "-apple-ios" + min_version_os_sdk + "-macabi");
790 ArchSpec maccatalyst_spec(triple);
791 if (arch_spec.IsCompatibleMatch(maccatalyst_spec))
792 arch_spec.MergeFrom(maccatalyst_spec);
793 }
794 if (os_env == llvm::Triple::Simulator &&
795 (os_type == llvm::Triple::IOS || os_type == llvm::Triple::TvOS ||
796 os_type == llvm::Triple::WatchOS)) {
797 llvm::Triple triple(llvm::Twine(arch_spec.GetArchitectureName()) +
798 "-apple-" + llvm::Triple::getOSTypeName(os_type) +
799 min_version_os_sdk + "-simulator");
800 ArchSpec sim_spec(triple);
801 if (arch_spec.IsCompatibleMatch(sim_spec))
802 arch_spec.MergeFrom(sim_spec);
803 }
804 return arch_spec;
805}
806
809 const size_t num_segments = segments.size();
810 for (size_t i = 0; i < num_segments; ++i) {
811 if (segments[i].name == name)
812 return &segments[i];
813 }
814 return nullptr;
815}
816
817// Dump an image info structure to the file handle provided.
819 if (!log)
820 return;
821 if (address == LLDB_INVALID_ADDRESS) {
822 LLDB_LOG(log, "uuid={1} path='{2}' (UNLOADED)", uuid.GetAsString(),
823 file_spec.GetPath());
824 } else {
825 LLDB_LOG(log, "address={0:x+16} uuid={1} path='{2}'", address,
826 uuid.GetAsString(), file_spec.GetPath());
827 for (uint32_t i = 0; i < segments.size(); ++i)
828 segments[i].PutToLog(log, slide);
829 }
830}
831
833 DEBUG_PRINTF("DynamicLoaderDarwin::%s() process state = %s\n", __FUNCTION__,
835 Clear(true);
836 m_process = process;
838}
839
840// Member function that gets called when the process state changes.
842 StateType state) {
843 DEBUG_PRINTF("DynamicLoaderDarwin::%s(%s)\n", __FUNCTION__,
844 StateAsCString(state));
845 switch (state) {
846 case eStateConnected:
847 case eStateAttaching:
848 case eStateLaunching:
849 case eStateInvalid:
850 case eStateUnloaded:
851 case eStateExited:
852 case eStateDetached:
853 Clear(false);
854 break;
855
856 case eStateStopped:
857 // Keep trying find dyld and set our notification breakpoint each time we
858 // stop until we succeed
862
864 }
865 break;
866
867 case eStateRunning:
868 case eStateStepping:
869 case eStateCrashed:
870 case eStateSuspended:
871 break;
872 }
873}
874
877 bool stop_others) {
878 ThreadPlanSP thread_plan_sp;
879 StackFrame *current_frame = thread.GetStackFrameAtIndex(0).get();
880 const SymbolContext &current_context =
881 current_frame->GetSymbolContext(eSymbolContextSymbol);
882 Symbol *current_symbol = current_context.symbol;
883 Log *log = GetLog(LLDBLog::Step);
884 TargetSP target_sp(thread.CalculateTarget());
885
886 if (current_symbol != nullptr) {
887 std::vector<Address> addresses;
888
889 if (current_symbol->IsTrampoline()) {
890 ConstString trampoline_name =
891 current_symbol->GetMangled().GetName(Mangled::ePreferMangled);
892
893 if (trampoline_name) {
894 const ModuleList &images = target_sp->GetImages();
895
896 SymbolContextList code_symbols;
897 images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeCode,
898 code_symbols);
899 for (const SymbolContext &context : code_symbols) {
900 AddressRange addr_range;
901 context.GetAddressRange(eSymbolContextEverything, 0, false,
902 addr_range);
903 addresses.push_back(addr_range.GetBaseAddress());
904 if (log) {
905 addr_t load_addr =
906 addr_range.GetBaseAddress().GetLoadAddress(target_sp.get());
907
908 LLDB_LOGF(log, "Found a trampoline target symbol at 0x%" PRIx64 ".",
909 load_addr);
910 }
911 }
912
913 SymbolContextList reexported_symbols;
915 trampoline_name, eSymbolTypeReExported, reexported_symbols);
916 for (const SymbolContext &context : reexported_symbols) {
917 if (context.symbol) {
918 Symbol *actual_symbol =
919 context.symbol->ResolveReExportedSymbol(*target_sp.get());
920 if (actual_symbol) {
921 const Address actual_symbol_addr = actual_symbol->GetAddress();
922 if (actual_symbol_addr.IsValid()) {
923 addresses.push_back(actual_symbol_addr);
924 if (log) {
925 lldb::addr_t load_addr =
926 actual_symbol_addr.GetLoadAddress(target_sp.get());
927 LLDB_LOGF(log,
928 "Found a re-exported symbol: %s at 0x%" PRIx64 ".",
929 actual_symbol->GetName().GetCString(), load_addr);
930 }
931 }
932 }
933 }
934 }
935
936 SymbolContextList indirect_symbols;
937 images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeResolver,
938 indirect_symbols);
939
940 for (const SymbolContext &context : indirect_symbols) {
941 AddressRange addr_range;
942 context.GetAddressRange(eSymbolContextEverything, 0, false,
943 addr_range);
944 addresses.push_back(addr_range.GetBaseAddress());
945 if (log) {
946 addr_t load_addr =
947 addr_range.GetBaseAddress().GetLoadAddress(target_sp.get());
948
949 LLDB_LOGF(log, "Found an indirect target symbol at 0x%" PRIx64 ".",
950 load_addr);
951 }
952 }
953 }
954 } else if (current_symbol->GetType() == eSymbolTypeReExported) {
955 // I am not sure we could ever end up stopped AT a re-exported symbol.
956 // But just in case:
957
958 const Symbol *actual_symbol =
959 current_symbol->ResolveReExportedSymbol(*(target_sp.get()));
960 if (actual_symbol) {
961 Address target_addr(actual_symbol->GetAddress());
962 if (target_addr.IsValid()) {
963 LLDB_LOGF(
964 log,
965 "Found a re-exported symbol: %s pointing to: %s at 0x%" PRIx64
966 ".",
967 current_symbol->GetName().GetCString(),
968 actual_symbol->GetName().GetCString(),
969 target_addr.GetLoadAddress(target_sp.get()));
970 addresses.push_back(target_addr.GetLoadAddress(target_sp.get()));
971 }
972 }
973 }
974
975 if (addresses.size() > 0) {
976 // First check whether any of the addresses point to Indirect symbols,
977 // and if they do, resolve them:
978 std::vector<lldb::addr_t> load_addrs;
979 for (Address address : addresses) {
980 Symbol *symbol = address.CalculateSymbolContextSymbol();
981 if (symbol && symbol->IsIndirect()) {
983 Address symbol_address = symbol->GetAddress();
984 addr_t resolved_addr = thread.GetProcess()->ResolveIndirectFunction(
985 &symbol_address, error);
986 if (error.Success()) {
987 load_addrs.push_back(resolved_addr);
988 LLDB_LOGF(log,
989 "ResolveIndirectFunction found resolved target for "
990 "%s at 0x%" PRIx64 ".",
991 symbol->GetName().GetCString(), resolved_addr);
992 }
993 } else {
994 load_addrs.push_back(address.GetLoadAddress(target_sp.get()));
995 }
996 }
997 thread_plan_sp = std::make_shared<ThreadPlanRunToAddress>(
998 thread, load_addrs, stop_others);
999 }
1000 } else {
1001 LLDB_LOGF(log, "Could not find symbol for step through.");
1002 }
1003
1004 return thread_plan_sp;
1005}
1006
1008 lldb_private::Symbol *original_symbol, lldb_private::ModuleList &images,
1009 lldb_private::SymbolContextList &equivalent_symbols) {
1010 ConstString trampoline_name =
1011 original_symbol->GetMangled().GetName(Mangled::ePreferMangled);
1012 if (!trampoline_name)
1013 return;
1014
1015 static const char *resolver_name_regex = "(_gc|_non_gc|\\$[A-Za-z0-9\\$]+)$";
1016 std::string equivalent_regex_buf("^");
1017 equivalent_regex_buf.append(trampoline_name.GetCString());
1018 equivalent_regex_buf.append(resolver_name_regex);
1019
1020 RegularExpression equivalent_name_regex(equivalent_regex_buf);
1021 images.FindSymbolsMatchingRegExAndType(equivalent_name_regex, eSymbolTypeCode,
1022 equivalent_symbols);
1023
1024}
1025
1027 ModuleSP module_sp = m_libpthread_module_wp.lock();
1028 if (!module_sp) {
1029 SymbolContextList sc_list;
1030 ModuleSpec module_spec;
1031 module_spec.GetFileSpec().SetFilename("libsystem_pthread.dylib");
1032 ModuleList module_list;
1033 m_process->GetTarget().GetImages().FindModules(module_spec, module_list);
1034 if (!module_list.IsEmpty()) {
1035 if (module_list.GetSize() == 1) {
1036 module_sp = module_list.GetModuleAtIndex(0);
1037 if (module_sp)
1038 m_libpthread_module_wp = module_sp;
1039 }
1040 }
1041 }
1042 return module_sp;
1043}
1044
1047 ModuleSP module_sp = GetPThreadLibraryModule();
1048 if (module_sp) {
1050 module_sp->FindSymbolsWithNameAndType(ConstString("pthread_getspecific"),
1051 eSymbolTypeCode, sc_list);
1052 SymbolContext sc;
1053 if (sc_list.GetContextAtIndex(0, sc)) {
1054 if (sc.symbol)
1056 }
1057 }
1058 }
1060}
1061
1064 const lldb::ThreadSP thread_sp,
1065 lldb::addr_t tls_file_addr) {
1066 if (!thread_sp || !module_sp)
1067 return LLDB_INVALID_ADDRESS;
1068
1069 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1070
1071 lldb_private::Address tls_addr;
1072 if (!module_sp->ResolveFileAddress(tls_file_addr, tls_addr))
1073 return LLDB_INVALID_ADDRESS;
1074
1075 Target &target = m_process->GetTarget();
1076 TypeSystemClangSP scratch_ts_sp =
1078 if (!scratch_ts_sp)
1079 return LLDB_INVALID_ADDRESS;
1080
1081 CompilerType clang_void_ptr_type =
1082 scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType();
1083
1084 auto evaluate_tls_address = [this, &thread_sp, &clang_void_ptr_type](
1085 Address func_ptr,
1086 llvm::ArrayRef<addr_t> args) -> addr_t {
1088
1089 lldb::ThreadPlanSP thread_plan_sp(new ThreadPlanCallFunction(
1090 *thread_sp, func_ptr, clang_void_ptr_type, args, options));
1091
1092 DiagnosticManager execution_errors;
1093 ExecutionContext exe_ctx(thread_sp);
1095 exe_ctx, thread_plan_sp, options, execution_errors);
1096
1097 if (results == lldb::eExpressionCompleted) {
1098 if (lldb::ValueObjectSP result_valobj_sp =
1099 thread_plan_sp->GetReturnValueObject()) {
1100 return result_valobj_sp->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
1101 }
1102 }
1103 return LLDB_INVALID_ADDRESS;
1104 };
1105
1106 // On modern apple platforms, there is a small data structure that looks
1107 // approximately like this:
1108 // struct TLS_Thunk {
1109 // void *(*get_addr)(struct TLS_Thunk *);
1110 // size_t key;
1111 // size_t offset;
1112 // }
1113 //
1114 // The strategy is to take get_addr, call it with the address of the
1115 // containing TLS_Thunk structure, and add the offset to the resulting
1116 // pointer to get the data block.
1117 //
1118 // On older apple platforms, the key is treated as a pthread_key_t and passed
1119 // to pthread_getspecific. The pointer returned from that call is added to
1120 // offset to get the relevant data block.
1121
1122 const uint32_t addr_size = m_process->GetAddressByteSize();
1123 uint8_t buf[sizeof(addr_t) * 3];
1124 Status error;
1125 const size_t tls_data_size = addr_size * 3;
1126 const size_t bytes_read = target.ReadMemory(
1127 tls_addr, buf, tls_data_size, error, /*force_live_memory = */ true);
1128 if (bytes_read != tls_data_size || error.Fail())
1129 return LLDB_INVALID_ADDRESS;
1130
1131 DataExtractor data(buf, sizeof(buf), m_process->GetByteOrder(), addr_size);
1132 lldb::offset_t offset = 0;
1133 const addr_t tls_thunk = data.GetAddress(&offset);
1134 const addr_t key = data.GetAddress(&offset);
1135 const addr_t tls_offset = data.GetAddress(&offset);
1136
1137 if (tls_thunk != 0) {
1138 const addr_t fixed_tls_thunk = m_process->FixCodeAddress(tls_thunk);
1139 Address thunk_load_addr;
1140 if (target.ResolveLoadAddress(fixed_tls_thunk, thunk_load_addr)) {
1141 const addr_t tls_load_addr = tls_addr.GetLoadAddress(&target);
1142 const addr_t tls_data = evaluate_tls_address(
1143 thunk_load_addr, llvm::ArrayRef<addr_t>(tls_load_addr));
1144 if (tls_data != LLDB_INVALID_ADDRESS)
1145 return tls_data + tls_offset;
1146 }
1147 }
1148
1149 if (key != 0) {
1150 // First check to see if we have already figured out the location of
1151 // TLS data for the pthread_key on a specific thread yet. If we have we
1152 // can re-use it since its location will not change unless the process
1153 // execs.
1154 const lldb::tid_t tid = thread_sp->GetID();
1155 auto tid_pos = m_tid_to_tls_map.find(tid);
1156 if (tid_pos != m_tid_to_tls_map.end()) {
1157 auto tls_pos = tid_pos->second.find(key);
1158 if (tls_pos != tid_pos->second.end()) {
1159 return tls_pos->second + tls_offset;
1160 }
1161 }
1162 Address pthread_getspecific_addr = GetPthreadSetSpecificAddress();
1163 if (pthread_getspecific_addr.IsValid()) {
1164 const addr_t tls_data = evaluate_tls_address(pthread_getspecific_addr,
1165 llvm::ArrayRef<addr_t>(key));
1166 if (tls_data != LLDB_INVALID_ADDRESS)
1167 return tls_data + tls_offset;
1168 }
1169 }
1170 return LLDB_INVALID_ADDRESS;
1171}
1172
1175 bool use_new_spi_interface = false;
1176
1177 llvm::VersionTuple version = process->GetHostOSVersion();
1178 if (!version.empty()) {
1179 const llvm::Triple::OSType os_type =
1180 process->GetTarget().GetArchitecture().GetTriple().getOS();
1181
1182 // macOS 10.12 and newer
1183 if (os_type == llvm::Triple::MacOSX &&
1184 version >= llvm::VersionTuple(10, 12))
1185 use_new_spi_interface = true;
1186
1187 // iOS 10 and newer
1188 if (os_type == llvm::Triple::IOS && version >= llvm::VersionTuple(10))
1189 use_new_spi_interface = true;
1190
1191 // tvOS 10 and newer
1192 if (os_type == llvm::Triple::TvOS && version >= llvm::VersionTuple(10))
1193 use_new_spi_interface = true;
1194
1195 // watchOS 3 and newer
1196 if (os_type == llvm::Triple::WatchOS && version >= llvm::VersionTuple(3))
1197 use_new_spi_interface = true;
1198
1199 // NEED_BRIDGEOS_TRIPLE // Any BridgeOS
1200 // NEED_BRIDGEOS_TRIPLE if (os_type == llvm::Triple::BridgeOS)
1201 // NEED_BRIDGEOS_TRIPLE use_new_spi_interface = true;
1202 }
1203
1204 if (log) {
1205 if (use_new_spi_interface)
1206 LLDB_LOGF(
1207 log, "DynamicLoaderDarwin::UseDYLDSPI: Use new DynamicLoader plugin");
1208 else
1209 LLDB_LOGF(
1210 log, "DynamicLoaderDarwin::UseDYLDSPI: Use old DynamicLoader plugin");
1211 }
1212 return use_new_spi_interface;
1213}
static llvm::raw_ostream & error(Stream &strm)
#define DEBUG_PRINTF(fmt,...)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:359
#define LLDB_LOGF(log,...)
Definition: Log.h:366
#define LLDB_LOGV(log,...)
Definition: Log.h:373
A section + offset based address range class.
Definition: AddressRange.h:25
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:211
A section + offset based address class.
Definition: Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:313
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
Definition: Address.cpp:1047
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition: Address.cpp:285
lldb::addr_t GetOffset() const
Get the section relative offset value.
Definition: Address.h:329
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:355
An architecture specification class.
Definition: ArchSpec.h:31
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:450
bool SetTriple(const llvm::Triple &triple)
Architecture triple setter.
Definition: ArchSpec.cpp:747
void MergeFrom(const ArchSpec &other)
Merges fields from another ArchSpec into this ArchSpec.
Definition: ArchSpec.cpp:809
bool IsCompatibleMatch(const ArchSpec &rhs) const
Shorthand for IsMatch(rhs, CompatibleMatch).
Definition: ArchSpec.h:502
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition: ArchSpec.cpp:552
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
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:188
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
An data extractor class.
Definition: DataExtractor.h:48
uint64_t GetAddress(lldb::offset_t *offset_ptr) const
Extract an address from *offset_ptr.
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
Definition: Debugger.cpp:1587
void PutToLog(lldb_private::Log *log, lldb::addr_t slide) const
lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module, const lldb::ThreadSP thread, lldb::addr_t tls_file_addr) override
Retrieves the per-module TLS block for a given thread.
void UpdateSpecialBinariesFromNewImageInfos(ImageInfo::collection &image_infos)
bool AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override
Ask if the eh_frame information for the given SymbolContext should be relied on even when it's the fi...
virtual bool NeedToDoInitialImageFetch()=0
ImageInfo::collection m_dyld_image_infos
virtual void DoInitialImageFetch()=0
DynamicLoaderDarwin(lldb_private::Process *process)
void UpdateDYLDImageInfoFromNewImageInfo(ImageInfo &image_info)
void PrivateProcessStateChanged(lldb_private::Process *process, lldb::StateType state)
void DidLaunch() override
Called after attaching a process.
void FindEquivalentSymbols(lldb_private::Symbol *original_symbol, lldb_private::ModuleList &module_list, lldb_private::SymbolContextList &equivalent_symbols) override
Some dynamic loaders provide features where there are a group of symbols "equivalent to" a given symb...
virtual bool SetNotificationBreakpoint()=0
bool AddModulesUsingImageInfos(ImageInfo::collection &image_infos)
void DidAttach() override
Called after attaching a process.
lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread, bool stop_others) override
Provides a plan to step through the dynamic loader trampoline for the current state of thread.
bool JSONImageInformationIntoImageInfo(lldb_private::StructuredData::ObjectSP image_details, ImageInfo::collection &image_infos)
bool UpdateImageLoadAddress(lldb_private::Module *module, ImageInfo &info)
std::optional< lldb_private::Address > GetStartAddress() override
Return the start address in the dynamic loader module.
lldb::ModuleSP FindTargetModuleForImageInfo(ImageInfo &image_info, bool can_create, bool *did_create_ptr)
void PrivateInitialize(lldb_private::Process *process)
lldb_private::Address GetPthreadSetSpecificAddress()
void SetDYLDModule(lldb::ModuleSP &dyld_module_sp)
static bool UseDYLDSPI(lldb_private::Process *process)
lldb_private::Address m_pthread_getspecific_addr
bool UnloadModuleSections(lldb_private::Module *module, ImageInfo &info)
void UnloadImages(const std::vector< lldb::addr_t > &solib_addresses)
virtual bool DidSetNotificationBreakpoint()=0
A plug-in interface definition class for dynamic loaders.
Definition: DynamicLoader.h:53
Process * m_process
The process that this dynamic loader plug-in is tracking.
virtual void UnloadSections(const lldb::ModuleSP module)
Removes the loaded sections from the target in module.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
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
void SetFilename(ConstString filename)
Filename string set accessor.
Definition: FileSpec.cpp:345
llvm::sys::TimePoint GetModificationTime(const FileSpec &file_spec) const
Returns the modification time of the given file.
static FileSystem & Instance()
const AddressRange & GetAddressRange()
Definition: Function.h:447
void PutCString(const char *cstr)
Definition: Log.cpp:135
ConstString GetName(NamePreference preference=ePreferDemangled) const
Best name get accessor.
Definition: Mangled.cpp:335
A collection class for Module objects.
Definition: ModuleList.h:103
std::recursive_mutex & GetMutex() const
Definition: ModuleList.h:230
lldb::ModuleSP FindFirstModule(const ModuleSpec &module_spec) const
Definition: ModuleList.cpp:626
bool AppendIfNeeded(const lldb::ModuleSP &new_module, bool notify=true)
Append a module to the module list, if it is not already there.
Definition: ModuleList.cpp:280
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
Definition: ModuleList.cpp:527
void FindModules(const ModuleSpec &module_spec, ModuleList &matching_module_list) const
Finds the first module whose file specification matches file_spec.
Definition: ModuleList.cpp:543
bool Remove(const lldb::ModuleSP &module_sp, bool notify=true)
Remove a module from the module list.
Definition: ModuleList.cpp:334
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
Definition: ModuleList.cpp:429
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
Definition: ModuleList.cpp:247
void FindSymbolsMatchingRegExAndType(const RegularExpression &regex, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
Definition: ModuleList.cpp:535
ModuleIterable Modules() const
Definition: ModuleList.h:527
size_t GetSize() const
Gets the size of the module list.
Definition: ModuleList.cpp:638
void LogUUIDAndPaths(Log *log, const char *prefix_cstr)
Definition: ModuleList.cpp:653
void SetObjectSize(uint64_t object_size)
Definition: ModuleSpec.h:115
ConstString & GetObjectName()
Definition: ModuleSpec.h:103
FileSpec & GetFileSpec()
Definition: ModuleSpec.h:53
ArchSpec & GetArchitecture()
Definition: ModuleSpec.h:89
void SetObjectOffset(uint64_t object_offset)
Definition: ModuleSpec.h:109
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:88
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
Definition: Module.cpp:1189
virtual bool IsModuleObjCLibrary(const lldb::ModuleSP &module_sp)=0
static ObjCLanguageRuntime * Get(Process &process)
A plug-in interface definition class for object file parsers.
Definition: ObjectFile.h:44
virtual lldb::addr_t GetFileOffset() const
Returns the offset into a file at which this object resides.
Definition: ObjectFile.h:266
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition: ObjectFile.h:275
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
Definition: ObjectFile.cpp:600
virtual lldb::addr_t GetByteSize() const
Definition: ObjectFile.h:268
A plug-in interface definition class for debugging a process.
Definition: Process.h:341
lldb::ExpressionResults RunThreadPlan(ExecutionContext &exe_ctx, lldb::ThreadPlanSP &thread_plan_sp, const EvaluateExpressionOptions &options, DiagnosticManager &diagnostic_manager)
Definition: Process.cpp:4941
void AddInvalidMemoryRegion(const LoadRange &region)
Definition: Process.cpp:5835
lldb::ByteOrder GetByteOrder() const
Definition: Process.cpp:3596
lldb::StateType GetState()
Get accessor for the current process state.
Definition: Process.cpp:1335
virtual llvm::VersionTuple GetHostOSVersion()
Sometimes the connection to a process can detect the host OS version that the process is running on.
Definition: Process.h:1275
virtual bool IsAlive()
Check if a process is still alive.
Definition: Process.cpp:1127
lldb::addr_t FixCodeAddress(lldb::addr_t pc)
Some targets might use bits in a code address to indicate a mode switch, ARM uses bit zero to signify...
Definition: Process.cpp:5952
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3600
uint32_t GetStopID() const
Definition: Process.h:1490
lldb::ModuleSP ReadModuleFromMemory(const FileSpec &file_spec, lldb::addr_t header_addr, size_t size_to_read=512)
Definition: Process.cpp:2545
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1285
static lldb::TypeSystemClangSP GetForTarget(Target &target, std::optional< IsolatedASTKind > ast_kind=DefaultAST, bool create_on_demand=true)
Returns the scratch TypeSystemClang for the given target.
lldb::SectionSP FindSectionByName(ConstString section_dstr) const
Definition: Section.cpp:552
lldb::offset_t GetFileOffset() const
Definition: Section.h:154
This base class provides an interface to stack frames.
Definition: StackFrame.h:43
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
Definition: StackFrame.cpp:300
An error handling class.
Definition: Status.h:44
ObjectSP GetItemAtIndex(size_t idx) const
ObjectSP GetValueForKey(llvm::StringRef key) const
bool HasKey(llvm::StringRef key) const
std::shared_ptr< Object > ObjectSP
Defines a list of symbol context objects.
bool GetContextAtIndex(size_t idx, SymbolContext &sc) const
Get accessor for a symbol context at index idx.
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:34
Function * function
The Function for a given query.
Symbol * symbol
The Symbol for a given query.
bool IsIndirect() const
Definition: Symbol.cpp:223
Mangled & GetMangled()
Definition: Symbol.h:146
bool IsTrampoline() const
Definition: Symbol.cpp:221
Address & GetAddressRef()
Definition: Symbol.h:72
ConstString GetName() const
Definition: Symbol.cpp:548
lldb::SymbolType GetType() const
Definition: Symbol.h:168
Address GetAddress() const
Definition: Symbol.h:88
Symbol * ResolveReExportedSymbol(Target &target) const
Definition: Symbol.cpp:520
Symbol * CalculateSymbolContextSymbol() override
Definition: Symbol.cpp:451
void ModulesDidLoad(ModuleList &module_list)
Definition: Target.cpp:1691
Module * GetExecutableModulePointer()
Definition: Target.cpp:1437
void ClearAllLoadedSections()
Definition: Target.cpp:3195
bool SetSectionUnloaded(const lldb::SectionSP &section_sp)
Definition: Target.cpp:3173
lldb::ModuleSP GetOrCreateModule(const ModuleSpec &module_spec, bool notify, Status *error_ptr=nullptr)
Find a binary on the system and return its Module, or return an existing Module that is already in th...
Definition: Target.cpp:2159
virtual size_t ReadMemory(const Address &addr, void *dst, size_t dst_len, Status &error, bool force_live_memory=false, lldb::addr_t *load_addr_ptr=nullptr)
Definition: Target.cpp:1829
bool SetArchitecture(const ArchSpec &arch_spec, bool set_platform=false, bool merge=true)
Set the architecture for this target.
Definition: Target.cpp:1539
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition: Target.cpp:1423
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow)
Definition: Target.cpp:3114
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition: Target.h:986
const ArchSpec & GetArchitecture() const
Definition: Target.h:1028
void SetExecutableModule(lldb::ModuleSP &module_sp, LoadDependentFiles load_dependent_files=eLoadDependentsDefault)
Set the main executable module.
Definition: Target.cpp:1472
bool SetSectionLoadAddress(const lldb::SectionSP &section, lldb::addr_t load_addr, bool warn_multiple=false)
Definition: Target.cpp:3124
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition: Thread.h:408
lldb::TargetSP CalculateTarget() override
Definition: Thread.cpp:1401
lldb::ProcessSP GetProcess() const
Definition: Thread.h:157
bool IsValid() const
Definition: UUID.h:69
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
#define UINT32_MAX
Definition: lldb-defines.h:19
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:331
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition: State.cpp:14
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
Definition: lldb-forward.h:449
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:446
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:480
uint64_t offset_t
Definition: lldb-types.h:85
StateType
Process and Thread States.
@ eStateUnloaded
Process is object is valid, but not currently loaded.
@ eStateConnected
Process is connected to remote debug services, but not launched or attached to anything yet.
@ eStateDetached
Process has been detached and can't be examined.
@ eStateStopped
Process or thread is stopped and can be examined.
@ eStateSuspended
Process or thread is in a suspended state as far as the debugger is concerned while other processes o...
@ eStateRunning
Process or thread is running and can't be examined.
@ eStateLaunching
Process is in the process of launching.
@ eStateAttaching
Process is currently trying to attach.
@ eStateExited
Process has exited and can't be examined.
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
@ eStateCrashed
Process or thread has crashed and can be examined.
ExpressionResults
The results of expression evaluation.
@ eExpressionCompleted
@ eSymbolTypeReExported
@ eSymbolTypeResolver
std::shared_ptr< lldb_private::TypeSystemClang > TypeSystemClangSP
Definition: lldb-forward.h:466
std::shared_ptr< lldb_private::Section > SectionSP
Definition: lldb-forward.h:414
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:444
uint64_t tid_t
Definition: lldb-types.h:84
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:371
lldb_private::UUID uuid
UUID for this dylib if it has one, else all zeros.
lldb::addr_t address
Address of mach header for this dylib.
lldb::addr_t slide
The amount to slide all segments by if there is a global slide.
llvm::MachO::mach_header header
The mach header for this image.
std::vector< Segment > segments
All segment vmaddr and vmsize pairs for this executable (from memory of inferior).
const Segment * FindSegment(lldb_private::ConstString name) const
lldb_private::FileSpec file_spec
Resolved path for this dylib.
uint32_t load_stop_id
The process stop ID that the sections for this image were loaded.
void PutToLog(lldb_private::Log *log) const