LLDB mainline
DynamicLoaderMacOS.cpp
Go to the documentation of this file.
1//===-- DynamicLoaderMacOS.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#include "lldb/Core/Debugger.h"
11#include "lldb/Core/Module.h"
13#include "lldb/Core/Section.h"
16#include "lldb/Target/ABI.h"
19#include "lldb/Target/Target.h"
20#include "lldb/Target/Thread.h"
22#include "lldb/Utility/Log.h"
23#include "lldb/Utility/State.h"
24
25#include "DynamicLoaderDarwin.h"
26#include "DynamicLoaderMacOS.h"
27
29
30using namespace lldb;
31using namespace lldb_private;
32
33// Create an instance of this class. This function is filled into the plugin
34// info class that gets handed out by the plugin factory and allows the lldb to
35// instantiate an instance of this class.
37 bool force) {
38 bool create = force;
39 if (!create) {
40 create = true;
41 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
42 if (exe_module) {
43 ObjectFile *object_file = exe_module->GetObjectFile();
44 if (object_file) {
45 create = (object_file->GetStrata() == ObjectFile::eStrataUser);
46 }
47 }
48
49 if (create) {
50 const llvm::Triple &triple_ref =
51 process->GetTarget().GetArchitecture().GetTriple();
52 switch (triple_ref.getOS()) {
53 case llvm::Triple::Darwin:
54 case llvm::Triple::MacOSX:
55 case llvm::Triple::IOS:
56 case llvm::Triple::TvOS:
57 case llvm::Triple::WatchOS:
58 case llvm::Triple::BridgeOS:
59 case llvm::Triple::DriverKit:
60 case llvm::Triple::XROS:
61 create = triple_ref.getVendor() == llvm::Triple::Apple;
62 break;
63 default:
64 create = false;
65 break;
66 }
67 }
68 }
69
70 if (!UseDYLDSPI(process)) {
71 create = false;
72 }
73
74 if (create)
75 return new DynamicLoaderMacOS(process);
76 return nullptr;
77}
78
79// Constructor
86
87// Destructor
94
96 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
97 bool did_exec = false;
98 if (m_process) {
99 // If we are stopped after an exec, we will have only one thread...
100 if (m_process->GetThreadList().GetSize() == 1) {
101 // Maybe we still have an image infos address around? If so see
102 // if that has changed, and if so we have exec'ed.
104 lldb::addr_t image_infos_address = m_process->GetImageInfoAddress();
105 if (image_infos_address != m_maybe_image_infos_address) {
106 // We don't really have to reset this here, since we are going to
107 // call DoInitialImageFetch right away to handle the exec. But in
108 // case anybody looks at it in the meantime, it can't hurt.
109 m_maybe_image_infos_address = image_infos_address;
110 did_exec = true;
111 }
112 }
113
114 if (!did_exec) {
115 // See if we are stopped at '_dyld_start'
116 ThreadSP thread_sp(m_process->GetThreadList().GetThreadAtIndex(0));
117 if (thread_sp) {
118 lldb::StackFrameSP frame_sp(thread_sp->GetStackFrameAtIndex(0));
119 if (frame_sp) {
120 const Symbol *symbol =
121 frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol;
122 if (symbol) {
123 if (symbol->GetName() == "_dyld_start")
124 did_exec = true;
125 }
126 }
127 }
128 }
129 }
130 }
131
132 if (did_exec) {
136 }
137 return did_exec;
138}
139
140// Clear out the state of this class.
142 std::lock_guard<std::recursive_mutex> guard(m_mutex);
143
145 m_process->GetTarget().RemoveBreakpointByID(m_break_id);
147 m_process->GetTarget().RemoveBreakpointByID(m_dyld_handover_break_id);
148
152}
153
156 return true;
157
158 StructuredData::ObjectSP process_state_sp(
159 m_process->GetDynamicLoaderProcessState());
160 if (!process_state_sp)
161 return true;
162 if (process_state_sp->GetAsDictionary()->HasKey("error"))
163 return true;
164 if (!process_state_sp->GetAsDictionary()->HasKey("process_state string"))
165 return true;
166 std::string proc_state = process_state_sp->GetAsDictionary()
167 ->GetValueForKey("process_state string")
168 ->GetAsString()
169 ->GetValue()
170 .str();
171 if (proc_state == "dyld_process_state_not_started" ||
172 proc_state == "dyld_process_state_dyld_initialized" ||
173 proc_state == "dyld_process_state_terminated_before_inits") {
174 return false;
175 }
177 return true;
178}
179
180// Check if we have found DYLD yet
184
191
194
195 // Remove any binaries we pre-loaded in the Target before
196 // launching/attaching. If the same binaries are present in the process,
197 // we'll get them from the shared module cache, we won't need to re-load them
198 // from disk.
200
201 StructuredData::ObjectSP all_image_info_json_sp(
202 m_process->GetLoadedDynamicLibrariesInfos(
204 ImageInfo::collection image_infos;
205 if (all_image_info_json_sp.get() &&
206 all_image_info_json_sp->GetAsDictionary() &&
207 all_image_info_json_sp->GetAsDictionary()->HasKey("images") &&
208 all_image_info_json_sp->GetAsDictionary()
209 ->GetValueForKey("images")
210 ->GetAsArray()) {
211
212 // Older debugserver (pre-2024-ish) will not recognize the
213 // eBinaryInformationLevelAddrOnly enum above, and
214 // will return the full binary information including mach
215 // header and segments/load commands. The response includes
216 // the full information on all binaries.
217 StructuredData::Array *images = all_image_info_json_sp->GetAsDictionary()
218 ->GetValueForKey("images")
219 ->GetAsArray();
220 if (images->GetSize() > 0 && images->GetItemAtIndex(0)->GetAsDictionary() &&
221 images->GetItemAtIndex(0)->GetAsDictionary()->HasKey("mach_header")) {
222 if (JSONImageInformationIntoImageInfo(all_image_info_json_sp,
223 image_infos)) {
224 LLDB_LOGF(log, "Initial module fetch: Adding %" PRIu64 " modules.\n",
225 (uint64_t)image_infos.size());
226
227 auto new_images = PreloadModulesFromImageInfos(image_infos);
230 }
231 } else {
232 // This is a newer debugserver which only replied with
233 // `load_address` for all binaries loaded in the process.
234 // We can request detailed information in smaller chunks,
235 // instead of one gigantic packet.
236 size_t image_count = images->GetSize();
237 std::vector<addr_t> load_addresses;
238 for (size_t i = 0; i < image_count; i++) {
240 images->GetItemAtIndex(i)->GetAsDictionary();
241 if (image && image->HasKey("load_address")) {
242 addr_t val = image->GetValueForKey("load_address")
243 ->GetUnsignedIntegerValue(LLDB_INVALID_ADDRESS);
244 if (val != LLDB_INVALID_ADDRESS)
245 load_addresses.push_back(val);
246 }
247 }
248 AddBinaries(load_addresses);
249 }
250 }
251
253 m_maybe_image_infos_address = m_process->GetImageInfoAddress();
254}
255
257
258// Static callback function that gets called when our DYLD notification
259// breakpoint gets hit. We update all of our image infos and then let our super
260// class DynamicLoader class decide if we should stop or not (based on global
261// preference).
264 lldb::user_id_t break_id,
265 lldb::user_id_t break_loc_id) {
266 //
267 // Our breakpoint on
268 //
269 // void lldb_image_notifier(enum dyld_image_mode mode, uint32_t infoCount,
270 // const dyld_image_info info[])
271 //
272 // has been hit. We need to read the arguments.
273
274 DynamicLoaderMacOS *dyld_instance = (DynamicLoaderMacOS *)baton;
275
276 ExecutionContext exe_ctx(context->exe_ctx_ref);
277 Process *process = exe_ctx.GetProcessPtr();
278
279 // This is a sanity check just in case this dyld_instance is an old dyld
280 // plugin's breakpoint still lying around.
281 if (process != dyld_instance->m_process)
282 return false;
283
284 if (dyld_instance->m_image_infos_stop_id != UINT32_MAX &&
285 process->GetStopID() < dyld_instance->m_image_infos_stop_id) {
286 return false;
287 }
288
289 const lldb::ABISP &abi = process->GetABI();
290 if (abi) {
291 // Build up the value array to store the three arguments given above, then
292 // get the values from the ABI:
293
294 TypeSystemClangSP scratch_ts_sp =
296 if (!scratch_ts_sp)
297 return false;
298
299 ValueList argument_values;
300
301 Value mode_value; // enum dyld_notify_mode { dyld_notify_adding=0,
302 // dyld_notify_removing=1, dyld_notify_remove_all=2,
303 // dyld_notify_dyld_moved=3 };
304 Value count_value; // uint32_t
305 Value headers_value; // struct dyld_image_info machHeaders[]
306
307 CompilerType clang_void_ptr_type =
308 scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType();
309 CompilerType clang_uint32_type =
310 scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(lldb::eEncodingUint,
311 32);
312 CompilerType clang_uint64_type =
313 scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(lldb::eEncodingUint,
314 32);
315
317 mode_value.SetCompilerType(clang_uint32_type);
318
320 count_value.SetCompilerType(clang_uint32_type);
321
323 headers_value.SetCompilerType(clang_void_ptr_type);
324
325 argument_values.PushValue(mode_value);
326 argument_values.PushValue(count_value);
327 argument_values.PushValue(headers_value);
328
329 if (abi->GetArgumentValues(exe_ctx.GetThreadRef(), argument_values)) {
330 uint32_t dyld_mode =
331 argument_values.GetValueAtIndex(0)->GetScalar().UInt(-1);
332 if (dyld_mode != static_cast<uint32_t>(-1)) {
333 // Okay the mode was right, now get the number of elements, and the
334 // array of new elements...
335 uint32_t image_infos_count =
336 argument_values.GetValueAtIndex(1)->GetScalar().UInt(-1);
337 if (image_infos_count != static_cast<uint32_t>(-1)) {
338 addr_t header_array =
339 argument_values.GetValueAtIndex(2)->GetScalar().ULongLong(-1);
340 if (header_array != static_cast<uint64_t>(-1)) {
341 std::vector<addr_t> image_load_addresses;
342 // header_array points to an array of image_infos_count elements,
343 // each is
344 // struct dyld_image_info {
345 // const struct mach_header* imageLoadAddress;
346 // const char* imageFilePath;
347 // uintptr_t imageFileModDate;
348 // };
349 //
350 // and we only need the imageLoadAddress fields.
351
352 const int addrsize =
354 for (uint64_t i = 0; i < image_infos_count; i++) {
356 addr_t dyld_image_info = header_array + (addrsize * 3 * i);
357 addr_t addr =
358 process->ReadPointerFromMemory(dyld_image_info, error);
359 if (error.Success()) {
360 image_load_addresses.push_back(addr);
361 } else {
363 "DynamicLoaderMacOS::NotifyBreakpointHit unable "
364 "to read binary mach-o load address at 0x%" PRIx64,
365 addr);
366 }
367 }
368 if (dyld_mode == 0) {
369 // dyld_notify_adding
370 if (process->GetTarget().GetImages().GetSize() == 0) {
371 // When all images have been removed, we're doing the
372 // dyld handover from a launch-dyld to a shared-cache-dyld,
373 // and we've just hit our one-shot address breakpoint in
374 // the sc-dyld. Note that the image addresses passed to
375 // this function are inferior sizeof(void*) not uint64_t's
376 // like our normal notification, so don't even look at
377 // image_load_addresses.
378
379 dyld_instance->ClearDYLDHandoverBreakpoint();
380
381 dyld_instance->DoInitialImageFetch();
382 dyld_instance->SetNotificationBreakpoint();
383 } else {
384 dyld_instance->AddBinaries(image_load_addresses);
385 }
386 } else if (dyld_mode == 1) {
387 // dyld_notify_removing
388 dyld_instance->UnloadImages(image_load_addresses);
389 } else if (dyld_mode == 2) {
390 // dyld_notify_remove_all
391 dyld_instance->UnloadAllImages();
392 } else if (dyld_mode == 3 && image_infos_count == 1) {
393 // dyld_image_dyld_moved
394
395 dyld_instance->ClearNotificationBreakpoint();
396 dyld_instance->UnloadAllImages();
397 dyld_instance->ClearDYLDModule();
398 process->GetTarget().GetImages().Clear();
399 process->GetTarget().ClearSectionLoadList();
400
401 addr_t all_image_infos = process->GetImageInfoAddress();
402 int addr_size =
404 addr_t notification_location = all_image_infos + 4 + // version
405 4 + // infoArrayCount
406 addr_size; // infoArray
408 addr_t notification_addr =
409 process->ReadPointerFromMemory(notification_location, error);
410 if (!error.Success()) {
412 "DynamicLoaderMacOS::NotifyBreakpointHit unable "
413 "to read address of dyld-handover notification function at "
414 "0x%" PRIx64,
415 notification_location);
416 } else {
417 notification_addr = process->FixCodeAddress(notification_addr);
418 dyld_instance->SetDYLDHandoverBreakpoint(notification_addr);
419 }
420 }
421 }
422 }
423 }
424 }
425 } else {
426 Target &target = process->GetTarget();
428 "no ABI plugin located for triple " +
429 target.GetArchitecture().GetTriple().getTriple() +
430 ": shared libraries will not be registered",
431 target.GetDebugger().GetID());
432 }
433
434 // Return true to stop the target, false to just let the target run
435 return dyld_instance->GetStopWhenImagesChange();
436}
437
439 const std::vector<lldb::addr_t> &load_addresses) {
441 ImageInfo::collection image_infos;
442
443 // For now, hardcode a limit of fetching 600 binaries at once.
444 // Fetching the full binary information for a large number of
445 // binaries can cause debugserver to use too much memory on
446 // memory-limited environments, and get killed.
447 const size_t image_fetch_max = 600;
448 size_t fetched = 0;
449 size_t total_image_size = load_addresses.size();
450 while (fetched < total_image_size) {
451 size_t this_fetch_amt =
452 std::min(image_fetch_max, total_image_size - fetched);
453 std::vector<addr_t> fetch_binaries(load_addresses.begin() + fetched,
454 load_addresses.begin() + fetched +
455 this_fetch_amt);
456
457 LLDB_LOGF(log, "Adding %" PRId64 " modules.",
458 (uint64_t)fetch_binaries.size());
459 image_infos.clear();
460 StructuredData::ObjectSP binaries_info_sp =
461 m_process->GetLoadedDynamicLibrariesInfos(eBinaryInformationLevelFull,
462 fetch_binaries);
463 if (binaries_info_sp && binaries_info_sp->GetAsDictionary() &&
464 binaries_info_sp->GetAsDictionary()->HasKey("images") &&
465 binaries_info_sp->GetAsDictionary()
466 ->GetValueForKey("images")
467 ->GetAsArray()) {
468 StructuredData::Array *images = binaries_info_sp->GetAsDictionary()
469 ->GetValueForKey("images")
470 ->GetAsArray();
471 if (images->GetSize() == fetch_binaries.size() &&
472 JSONImageInformationIntoImageInfo(binaries_info_sp, image_infos)) {
473 auto new_images = PreloadModulesFromImageInfos(image_infos);
476 }
477 }
478 fetched += this_fetch_amt;
479 }
481}
482
483// Dump the _dyld_all_image_infos members and all current image infos that we
484// have parsed to the file handle provided.
486 if (log == nullptr)
487 return;
488}
489
490// Look in dyld's dyld_all_image_infos structure for the address
491// of the notification function.
492// We can find the address of dyld_all_image_infos by a system
493// call, even if we don't have a dyld binary registered in lldb's
494// image list.
495// At process launch time - before dyld has executed any instructions -
496// the address of the notification function is not a resolved vm address
497// yet. dyld_all_image_infos also has a field with its own address
498// in it, and this will also be unresolved when we're at this state.
499// So we can compare the address of the object with this field and if
500// they differ, dyld hasn't started executing yet and we can't get the
501// notification address this way.
503 addr_t notification_addr = LLDB_INVALID_ADDRESS;
504 if (!m_process)
505 return notification_addr;
506
507 addr_t all_image_infos_addr = m_process->GetImageInfoAddress();
508 if (all_image_infos_addr == LLDB_INVALID_ADDRESS)
509 return notification_addr;
510
511 const uint32_t addr_size =
512 m_process->GetTarget().GetArchitecture().GetAddressByteSize();
513 offset_t registered_infos_addr_offset =
514 sizeof(uint32_t) + // version
515 sizeof(uint32_t) + // infoArrayCount
516 addr_size + // infoArray
517 addr_size + // notification
518 addr_size + // processDetachedFromSharedRegion +
519 // libSystemInitialized + pad
520 addr_size + // dyldImageLoadAddress
521 addr_size + // jitInfo
522 addr_size + // dyldVersion
523 addr_size + // errorMessage
524 addr_size + // terminationFlags
525 addr_size + // coreSymbolicationShmPage
526 addr_size + // systemOrderFlag
527 addr_size + // uuidArrayCount
528 addr_size; // uuidArray
529 // dyldAllImageInfosAddress
530
531 // If the dyldAllImageInfosAddress does not match
532 // the actual address of this struct, dyld has not started
533 // executing yet. The 'notification' field can't be used by
534 // lldb until it's resolved to an actual address.
536 addr_t registered_infos_addr = m_process->ReadPointerFromMemory(
537 all_image_infos_addr + registered_infos_addr_offset, error);
538 if (!error.Success())
539 return notification_addr;
540 if (registered_infos_addr != all_image_infos_addr)
541 return notification_addr;
542
543 offset_t notification_fptr_offset = sizeof(uint32_t) + // version
544 sizeof(uint32_t) + // infoArrayCount
545 addr_size; // infoArray
546
547 addr_t notification_fptr = m_process->ReadPointerFromMemory(
548 all_image_infos_addr + notification_fptr_offset, error);
549 if (error.Success())
550 notification_addr = m_process->FixCodeAddress(notification_fptr);
551 return notification_addr;
552}
553
554// We want to put a breakpoint on dyld's lldb_image_notifier()
555// but we may have attached to the process during the
556// transition from on-disk-dyld to shared-cache-dyld, so there's
557// officially no dyld binary loaded in the process (libdyld will
558// report none when asked), but the kernel can find the dyld_all_image_infos
559// struct and the function pointer for lldb_image_notifier is in
560// that struct.
562
563 // First try to find the notification breakpoint function by name
565 ModuleSP dyld_sp(GetDYLDModule());
566 if (dyld_sp) {
567 bool internal = true;
568 bool hardware = false;
569 LazyBool skip_prologue = eLazyBoolNo;
570 FileSpecList *source_files = nullptr;
571 FileSpecList dyld_filelist;
572 dyld_filelist.Append(dyld_sp->GetFileSpec());
573
574 Breakpoint *breakpoint =
575 m_process->GetTarget()
576 .CreateBreakpoint(&dyld_filelist, source_files,
577 "lldb_image_notifier", eFunctionNameTypeFull,
578 eLanguageTypeUnknown, 0, false, skip_prologue,
579 internal, hardware)
580 .get();
582 true);
583 breakpoint->SetBreakpointKind("shared-library-event");
584 if (breakpoint->HasResolvedLocations())
585 m_break_id = breakpoint->GetID();
586 else
587 m_process->GetTarget().RemoveBreakpointByID(breakpoint->GetID());
588
590 Breakpoint *breakpoint =
591 m_process->GetTarget()
592 .CreateBreakpoint(&dyld_filelist, source_files,
593 "gdb_image_notifier", eFunctionNameTypeFull,
595 /*offset_is_insn_count = */ false,
596 skip_prologue, internal, hardware)
597 .get();
599 true);
600 breakpoint->SetBreakpointKind("shared-library-event");
601 if (breakpoint->HasResolvedLocations())
602 m_break_id = breakpoint->GetID();
603 else
604 m_process->GetTarget().RemoveBreakpointByID(breakpoint->GetID());
605 }
606 }
607 }
608
609 // Failing that, find dyld_all_image_infos struct in memory,
610 // read the notification function pointer at the offset.
612 addr_t notification_addr = GetNotificationFuncAddrFromImageInfos();
613 if (notification_addr != LLDB_INVALID_ADDRESS) {
614 Address so_addr;
615 // We may not have a dyld binary mapped to this address yet;
616 // don't try to express the Address object as section+offset,
617 // only as a raw load address.
618 so_addr.SetRawAddress(notification_addr);
619 Breakpoint *dyld_break =
620 m_process->GetTarget().CreateBreakpoint(so_addr, true, false).get();
622 true);
623 dyld_break->SetBreakpointKind("shared-library-event");
624 if (dyld_break->HasResolvedLocations())
625 m_break_id = dyld_break->GetID();
626 else
627 m_process->GetTarget().RemoveBreakpointByID(dyld_break->GetID());
628 }
629 }
631}
632
634 addr_t notification_address) {
636 BreakpointSP dyld_handover_bp = m_process->GetTarget().CreateBreakpoint(
637 notification_address, true, false);
638 dyld_handover_bp->SetCallback(DynamicLoaderMacOS::NotifyBreakpointHit, this,
639 true);
640 dyld_handover_bp->SetOneShot(true);
641 m_dyld_handover_break_id = dyld_handover_bp->GetID();
642 return true;
643 }
644 return false;
645}
646
652
653addr_t
655 SymbolContext sc;
656 Target &target = m_process->GetTarget();
657 if (Symtab *symtab = module->GetSymtab()) {
658 std::vector<uint32_t> match_indexes;
659 ConstString g_symbol_name("_dyld_global_lock_held");
660 uint32_t num_matches = 0;
661 num_matches =
662 symtab->AppendSymbolIndexesWithName(g_symbol_name, match_indexes);
663 if (num_matches == 1) {
664 const Symbol *symbol = symtab->SymbolAtIndex(match_indexes[0]);
665 if (symbol &&
666 (symbol->ValueIsAddress() || symbol->GetAddressRef().IsValid())) {
667 return symbol->GetAddressRef().GetOpcodeLoadAddress(&target);
668 }
669 }
670 }
672}
673
674// Look for this symbol:
675//
676// int __attribute__((visibility("hidden"))) _dyld_global_lock_held =
677// 0;
678//
679// in libdyld.dylib.
682 addr_t symbol_address = LLDB_INVALID_ADDRESS;
683 ConstString g_libdyld_name("libdyld.dylib");
684 Target &target = m_process->GetTarget();
685 const ModuleList &target_modules = target.GetImages();
686 std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
687
688 // Find any modules named "libdyld.dylib" and look for the symbol there first
689 for (ModuleSP module_sp : target.GetImages().ModulesNoLocking()) {
690 if (module_sp) {
691 if (module_sp->GetFileSpec().GetFilename() == g_libdyld_name) {
692 symbol_address = GetDyldLockVariableAddressFromModule(module_sp.get());
693 if (symbol_address != LLDB_INVALID_ADDRESS)
694 break;
695 }
696 }
697 }
698
699 // Search through all modules looking for the symbol in them
700 if (symbol_address == LLDB_INVALID_ADDRESS) {
701 for (ModuleSP module_sp : target.GetImages().Modules()) {
702 if (module_sp) {
703 addr_t symbol_address =
705 if (symbol_address != LLDB_INVALID_ADDRESS)
706 break;
707 }
708 }
709 }
710
711 // Default assumption is that it is OK to load images. Only say that we
712 // cannot load images if we find the symbol in libdyld and it indicates that
713 // we cannot.
714
715 if (symbol_address != LLDB_INVALID_ADDRESS) {
716 {
717 int lock_held =
718 m_process->ReadUnsignedIntegerFromMemory(symbol_address, 4, 0, error);
719 if (lock_held != 0) {
720 error =
721 Status::FromErrorString("dyld lock held - unsafe to load images.");
722 }
723 }
724 } else {
725 // If we were unable to find _dyld_global_lock_held in any modules, or it
726 // is not loaded into memory yet, we may be at process startup (sitting at
727 // _dyld_start) - so we should not allow dlopen calls. But if we found more
728 // than one module then we are clearly past _dyld_start so in that case
729 // we'll default to "it's safe".
730 if (target.GetImages().GetSize() <= 1)
731 error = Status::FromErrorString("could not find the dyld library or "
732 "the dyld lock symbol");
733 }
734 return error;
735}
736
738 lldb::addr_t &base_address, UUID &uuid, LazyBool &using_shared_cache,
739 LazyBool &private_shared_cache, FileSpec &shared_cache_path,
740 std::optional<uint64_t> &size) {
741 base_address = LLDB_INVALID_ADDRESS;
742 uuid.Clear();
743 using_shared_cache = eLazyBoolCalculate;
744 private_shared_cache = eLazyBoolCalculate;
745 size.reset();
746
747 if (m_process) {
748 StructuredData::ObjectSP info = m_process->GetSharedCacheInfo();
749 StructuredData::Dictionary *info_dict = nullptr;
750 if (info.get() && info->GetAsDictionary()) {
751 info_dict = info->GetAsDictionary();
752 }
753
754 // { "shared_cache_base_address":6580879360,
755 // "shared_cache_uuid":"71E62C65-D8D9-32D0-9A0B-7F5154C8049F",
756 // "no_shared_cache":false,
757 // "shared_cache_private_cache":false,
758 // "shared_cache_path":"/S/V/P/C/OS/Sm/L/dyld/dyld_shared_cache_arm64e",
759 // "shared_cache_size":6012010496
760 // }
761
762 if (info_dict && info_dict->HasKey("shared_cache_uuid") &&
763 info_dict->HasKey("no_shared_cache") &&
764 info_dict->HasKey("shared_cache_private_cache") &&
765 info_dict->HasKey("shared_cache_base_address")) {
766 base_address = info_dict->GetValueForKey("shared_cache_base_address")
767 ->GetUnsignedIntegerValue(LLDB_INVALID_ADDRESS);
768 std::string uuid_str = std::string(
769 info_dict->GetValueForKey("shared_cache_uuid")->GetStringValue());
770 if (!uuid_str.empty())
771 uuid.SetFromStringRef(uuid_str);
772 if (!info_dict->GetValueForKey("no_shared_cache")->GetBooleanValue())
773 using_shared_cache = eLazyBoolYes;
774 else
775 using_shared_cache = eLazyBoolNo;
776 if (info_dict->GetValueForKey("shared_cache_private_cache")
777 ->GetBooleanValue())
778 private_shared_cache = eLazyBoolYes;
779 else
780 private_shared_cache = eLazyBoolNo;
781 if (info_dict->HasKey("shared_cache_path")) {
782 llvm::StringRef filepath =
783 info_dict->GetValueForKey("shared_cache_path")->GetStringValue();
784 shared_cache_path.SetPath(filepath);
785 }
786 if (info_dict->HasKey("shared_cache_size")) {
787 uint64_t val = info_dict->GetValueForKey("shared_cache_size")
788 ->GetUnsignedIntegerValue(LLDB_INVALID_ADDRESS);
789 if (val != LLDB_INVALID_ADDRESS)
790 size = val;
791 }
792 return true;
793 }
794 }
795 return false;
796}
797
802
806
808 return "Dynamic loader plug-in that watches for shared library loads/unloads "
809 "in MacOSX user processes.";
810}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition Log.h:378
bool SetNotificationBreakpoint() override
static lldb_private::DynamicLoader * CreateInstance(lldb_private::Process *process, bool force)
lldb_private::Status CanLoadImage() override
Ask if it is ok to try and load or unload an shared library (image).
void PutToLog(lldb_private::Log *log) const
bool IsFullyInitialized() override
Return whether the dynamic loader is fully initialized and it's safe to call its APIs.
lldb::addr_t GetDyldLockVariableAddressFromModule(lldb_private::Module *module)
bool NeedToDoInitialImageFetch() override
std::recursive_mutex m_mutex
void DoInitialImageFetch() override
static llvm::StringRef GetPluginNameStatic()
static llvm::StringRef GetPluginDescriptionStatic()
bool GetSharedCacheInformation(lldb::addr_t &base_address, lldb_private::UUID &uuid, lldb_private::LazyBool &using_shared_cache, lldb_private::LazyBool &private_shared_cache, lldb_private::FileSpec &shared_cache_path, std::optional< uint64_t > &size) override
Get information about the shared cache for a process, if possible.
lldb::user_id_t m_break_id
lldb::addr_t GetNotificationFuncAddrFromImageInfos()
bool SetDYLDHandoverBreakpoint(lldb::addr_t notification_address)
void AddBinaries(const std::vector< lldb::addr_t > &load_addresses)
void ClearNotificationBreakpoint() override
static bool NotifyBreakpointHit(void *baton, lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
lldb::addr_t m_maybe_image_infos_address
bool ProcessDidExec() override
Called after attaching a process.
lldb::user_id_t m_dyld_handover_break_id
DynamicLoaderMacOS(lldb_private::Process *process)
bool DidSetNotificationBreakpoint() override
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetOpcodeLoadAddress(Target *target, AddressClass addr_class=AddressClass::eInvalid) const
Get the load address as an opcode load address.
Definition Address.cpp:358
void SetRawAddress(lldb::addr_t addr)
Definition Address.h:447
bool IsValid() const
Check if the object state is valid.
Definition Address.h:355
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition ArchSpec.cpp:681
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:457
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
Definition Breakpoint.h:81
void SetBreakpointKind(const char *kind)
Set the "kind" description for a breakpoint.
Definition Breakpoint.h:482
bool HasResolvedLocations() const
Return whether this breakpoint has any resolved locations.
void SetCallback(BreakpointHitCallback callback, void *baton, bool is_synchronous=false)
Set the callback action invoked when the breakpoint is hit.
Generic representation of a type in a programming language.
A uniqued constant string class.
Definition ConstString.h:40
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
DynamicLoaderDarwin(lldb_private::Process *process)
std::recursive_mutex & GetMutex() const
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)
void UpdateSpecialBinariesFromPreloadedModules(std::vector< std::pair< ImageInfo, lldb::ModuleSP > > &images)
bool AddModulesUsingPreloadedModules(std::vector< std::pair< ImageInfo, lldb::ModuleSP > > &images)
static bool UseDYLDSPI(lldb_private::Process *process)
lldb_private::Address m_pthread_getspecific_addr
void UnloadImages(const std::vector< lldb::addr_t > &solib_addresses)
Process * m_process
The process that this dynamic loader plug-in is tracking.
bool GetStopWhenImagesChange() const
Get whether the process should stop when images change.
DynamicLoader(Process *process)
Construct with a process.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
Process * GetProcessPtr() const
Returns a pointer to the process object.
Thread & GetThreadRef() const
Returns a reference to the thread object.
A file collection class.
void Append(const FileSpec &file)
Append a FileSpec object to the list.
A file utility class.
Definition FileSpec.h:57
void SetPath(llvm::StringRef p)
Temporary helper for FileSystem change.
Definition FileSpec.h:289
A collection class for Module objects.
Definition ModuleList.h:125
ModuleIterableNoLocking ModulesNoLocking() const
Definition ModuleList.h:576
std::recursive_mutex & GetMutex() const
Definition ModuleList.h:252
void Clear()
Clear the object's state.
ModuleIterable Modules() const
Definition ModuleList.h:570
size_t GetSize() const
Gets the size of the module list.
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:90
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
Definition Module.cpp:1184
Symtab * GetSymtab(bool can_create=true)
Get the module's symbol table.
Definition Module.cpp:1011
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A plug-in interface definition class for debugging a process.
Definition Process.h:355
virtual lldb::addr_t GetImageInfoAddress()
Get the image information address for the current process.
Definition Process.cpp:1457
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
Definition Process.cpp:2377
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:6159
uint32_t GetStopID() const
Definition Process.h:1487
const lldb::ABISP & GetABI()
Definition Process.cpp:1459
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1251
unsigned int UInt(unsigned int fail_value=0) const
Definition Scalar.cpp:351
unsigned long long ULongLong(unsigned long long fail_value=0) const
Definition Scalar.cpp:365
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.
An error handling class.
Definition Status.h:118
static Status FromErrorString(const char *str)
Definition Status.h:141
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
lldb::break_id_t GetID() const
Definition Stoppoint.cpp:22
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 symbol context baton that can be handed other debug core functions.
bool ValueIsAddress() const
Definition Symbol.cpp:165
Address & GetAddressRef()
Definition Symbol.h:73
ConstString GetName() const
Definition Symbol.cpp:511
Module * GetExecutableModulePointer()
Definition Target.cpp:1541
Debugger & GetDebugger() const
Definition Target.h:1240
void ClearSectionLoadList()
Definition Target.cpp:5413
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1157
const ArchSpec & GetArchitecture() const
Definition Target.h:1199
Represents UUID's of various sizes.
Definition UUID.h:27
bool SetFromStringRef(llvm::StringRef str)
Definition UUID.cpp:101
void Clear()
Definition UUID.h:62
void PushValue(const Value &value)
Definition Value.cpp:694
Value * GetValueAtIndex(size_t idx)
Definition Value.cpp:698
const Scalar & GetScalar() const
See comment on m_scalar to understand what GetScalar returns.
Definition Value.h:113
@ Scalar
A raw scalar value.
Definition Value.h:45
void SetCompilerType(const CompilerType &compiler_type)
Definition Value.cpp:276
void SetValueType(ValueType value_type)
Definition Value.h:89
#define LLDB_INVALID_BREAK_ID
#define LLDB_BREAK_ID_IS_VALID(bid)
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
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:327
std::shared_ptr< lldb_private::ABI > ABISP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::Thread > ThreadSP
uint64_t offset_t
Definition lldb-types.h:85
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
@ eEncodingUint
unsigned integer
std::shared_ptr< lldb_private::TypeSystemClang > TypeSystemClangSP
uint64_t user_id_t
Definition lldb-types.h:82
uint64_t addr_t
Definition lldb-types.h:80
@ eBinaryInformationLevelFull
@ eBinaryInformationLevelAddrOnly
std::shared_ptr< lldb_private::Module > ModuleSP
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47