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