LLDB mainline
DynamicLoaderMacOSXDYLD.cpp
Go to the documentation of this file.
1//===-- DynamicLoaderMacOSXDYLD.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 "DynamicLoaderDarwin.h"
11#include "DynamicLoaderMacOS.h"
15#include "lldb/Core/Debugger.h"
16#include "lldb/Core/Module.h"
19#include "lldb/Core/Section.h"
22#include "lldb/Target/ABI.h"
25#include "lldb/Target/Target.h"
26#include "lldb/Target/Thread.h"
31#include "lldb/Utility/Log.h"
32#include "lldb/Utility/State.h"
33
34//#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN
35#ifdef ENABLE_DEBUG_PRINTF
36#include <cstdio>
37#define DEBUG_PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__)
38#else
39#define DEBUG_PRINTF(fmt, ...)
40#endif
41
42#ifndef __APPLE__
44#else
45#include <uuid/uuid.h>
46#endif
47
48using namespace lldb;
49using namespace lldb_private;
50
52
53namespace {
54/// Process::GetImageInfoAddress() returns either the address of dyld's
55/// mach_header or of the dyld_all_image_infos struct, depending on the
56/// debugserver. Both are distinguished by their first four bytes: a Mach-O
57/// magic number, or the dyld_all_image_infos version field.
58struct ImageInfoAddressContents {
59 enum Kind { Unknown, MachOHeader, AllImageInfos };
60 Kind kind = Unknown;
61 /// Only meaningful when kind is AllImageInfos.
62 uint32_t all_image_infos_version = 0;
63};
64} // namespace
65
66static ImageInfoAddressContents ReadImageInfoAddressContents(Process &process,
67 addr_t addr) {
68 ImageInfoAddressContents contents;
69 if (addr == LLDB_INVALID_ADDRESS)
70 return contents;
71
72 uint8_t buf[4];
74 if (process.ReadMemory(addr, buf, sizeof(buf), error) != sizeof(buf))
75 return contents;
76
77 DataExtractor data(buf, sizeof(buf), process.GetByteOrder(), 4);
78 lldb::offset_t offset = 0;
79 uint32_t magic_or_version = data.GetU32(&offset);
80 switch (magic_or_version) {
81 case llvm::MachO::MH_MAGIC:
82 case llvm::MachO::MH_MAGIC_64:
83 case llvm::MachO::MH_CIGAM:
84 case llvm::MachO::MH_CIGAM_64:
85 contents.kind = ImageInfoAddressContents::MachOHeader;
86 break;
87 default:
88 contents.kind = ImageInfoAddressContents::AllImageInfos;
89 contents.all_image_infos_version = magic_or_version;
90 break;
91 }
92 return contents;
93}
94
95// Create an instance of this class. This function is filled into the plugin
96// info class that gets handed out by the plugin factory and allows the lldb to
97// instantiate an instance of this class.
99 bool force) {
100 bool create = force;
101 if (!create) {
102 create = true;
103 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
104 if (exe_module) {
105 ObjectFile *object_file = exe_module->GetObjectFile();
106 if (object_file) {
107 create = (object_file->GetStrata() == ObjectFile::eStrataUser);
108 }
109 }
110
111 if (create) {
112 const llvm::Triple &triple_ref =
113 process->GetTarget().GetArchitecture().GetTriple();
114 switch (triple_ref.getOS()) {
115 case llvm::Triple::Darwin:
116 case llvm::Triple::MacOSX:
117 case llvm::Triple::IOS:
118 case llvm::Triple::TvOS:
119 case llvm::Triple::WatchOS:
120 case llvm::Triple::BridgeOS:
121 case llvm::Triple::DriverKit:
122 case llvm::Triple::XROS:
123 create = triple_ref.getVendor() == llvm::Triple::Apple;
124 break;
125 default:
126 create = false;
127 break;
128 }
129 }
130 }
131
132 if (UseDYLDSPI(process)) {
133 create = false;
134 }
135
136 if (create)
137 return new DynamicLoaderMacOSXDYLD(process);
138 return nullptr;
139}
140
141// Constructor
148
149// Destructor
154
156 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
157 bool did_exec = false;
158 if (m_process) {
159 // If we are stopped after an exec, we will have only one thread...
160 if (m_process->GetThreadList().GetSize() == 1) {
161 // We know if a process has exec'ed if our "m_dyld_all_image_infos_addr"
162 // value differs from the Process' image info address. When a process
163 // execs itself it might cause a change if ASLR is enabled.
164 const addr_t shlib_addr = m_process->GetImageInfoAddress();
166 shlib_addr != m_dyld_all_image_infos_addr) {
167 // The image info address from the process is the
168 // 'dyld_all_image_infos' address and it has changed.
169 did_exec = true;
171 shlib_addr == m_dyld.address) {
172 // The image info address from the process is the mach_header address
173 // for dyld and it has changed.
174 did_exec = true;
175 } else {
176 // ASLR might be disabled and dyld could have ended up in the same
177 // location. We should try and detect if we are stopped at
178 // '_dyld_start'
179 ThreadSP thread_sp(m_process->GetThreadList().GetThreadAtIndex(0));
180 if (thread_sp) {
181 lldb::StackFrameSP frame_sp(thread_sp->GetStackFrameAtIndex(0));
182 if (frame_sp) {
183 const Symbol *symbol =
184 frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol;
185 if (symbol) {
186 if (symbol->GetName() == "_dyld_start")
187 did_exec = true;
188 }
189 }
190 }
191 }
192
193 if (did_exec) {
196 }
197 }
198 }
199 return did_exec;
200}
201
202// Clear out the state of this class.
204 std::lock_guard<std::recursive_mutex> guard(m_mutex);
205
207 m_process->GetTarget().RemoveBreakpointByID(m_break_id);
208
212}
213
214// Check if we have found DYLD yet
218
221 m_process->GetTarget().RemoveBreakpointByID(m_break_id);
222 }
223}
224
225// Try and figure out where dyld is by first asking the Process if it knows
226// (which currently calls down in the lldb::Process to get the DYLD info
227// (available on SnowLeopard only). If that fails, then check in the default
228// addresses.
231 // Check the image info addr as it might point to the mach header for dyld,
232 // or it might point to the dyld_all_image_infos struct
233 const addr_t shlib_addr = m_process->GetImageInfoAddress();
234 if (shlib_addr != LLDB_INVALID_ADDRESS) {
235 if (ReadImageInfoAddressContents(*m_process, shlib_addr).kind ==
236 ImageInfoAddressContents::MachOHeader) {
239 return;
240 }
241 // Maybe it points to the all image infos?
242 m_dyld_all_image_infos_addr = shlib_addr;
244 }
245 }
246
249 if (m_dyld_all_image_infos.dyldImageLoadAddress != LLDB_INVALID_ADDRESS)
251 m_dyld_all_image_infos.dyldImageLoadAddress);
252 else
254 m_dyld_all_image_infos_addr & 0xfffffffffff00000ull);
255 return;
256 }
257 }
258
259 // Check some default values
260 Module *executable = m_process->GetTarget().GetExecutableModulePointer();
261
262 if (executable) {
263 const ArchSpec &exe_arch = executable->GetArchitecture();
264 if (exe_arch.GetAddressByteSize() == 8) {
266 } else if (exe_arch.GetMachine() == llvm::Triple::arm ||
267 exe_arch.GetMachine() == llvm::Triple::thumb ||
268 exe_arch.GetMachine() == llvm::Triple::aarch64 ||
269 exe_arch.GetMachine() == llvm::Triple::aarch64_32) {
271 } else {
273 }
274 }
275}
276
277// Assume that dyld is in memory at ADDR and try to parse it's load commands
279 lldb::addr_t addr) {
280 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
281 DataExtractor data; // Load command data
282 static ConstString g_dyld_all_image_infos("dyld_all_image_infos");
283 static ConstString g_new_dyld_all_image_infos("dyld4::dyld_all_image_infos");
284 if (ReadMachHeader(addr, &m_dyld.header, &data)) {
285 if (m_dyld.header.filetype == llvm::MachO::MH_DYLINKER) {
286 m_dyld.address = addr;
287 ModuleSP dyld_module_sp;
288 if (ParseLoadCommands(data, m_dyld, &m_dyld.file_spec)) {
289 if (m_dyld.file_spec) {
291 return false;
292 }
293 }
294 dyld_module_sp = GetDYLDModule();
295 if (!dyld_module_sp)
296 return false;
297
298 Target &target = m_process->GetTarget();
299
301 dyld_module_sp.get()) {
302 const Symbol *symbol = dyld_module_sp->FindFirstSymbolWithNameAndType(
303 g_dyld_all_image_infos, eSymbolTypeData);
304 if (!symbol) {
305 symbol = dyld_module_sp->FindFirstSymbolWithNameAndType(
306 g_new_dyld_all_image_infos, eSymbolTypeData);
307 }
308 if (symbol)
310 }
311
313 SectionSP dyld_aii_section_sp =
314 dyld_module_sp->GetSectionList()->FindSectionByName(
315 "__all_image_info");
316 if (dyld_aii_section_sp) {
317 Address dyld_aii_addr(dyld_aii_section_sp, 0);
318 m_dyld_all_image_infos_addr = dyld_aii_addr.GetLoadAddress(&target);
319 }
320 }
321
322 // Update all image infos
324
325 // If we didn't have an executable before, but now we do, then the dyld
326 // module shared pointer might be unique and we may need to add it again
327 // (since Target::RebuildModuleListWithExecutable() will clear the
328 // images). So append the dyld module back to the list if it is
329 /// unique!
330 if (dyld_module_sp) {
331 target.GetImages().AppendIfNeeded(dyld_module_sp);
332
333 // At this point we should have read in dyld's module, and so we should
334 // set breakpoints in it:
335 ModuleList modules;
336 modules.Append(dyld_module_sp);
337 target.ModulesDidLoad(modules);
338 SetDYLDModule(dyld_module_sp);
339 }
340
341 return true;
342 }
343 }
344 return false;
345}
346
350
351// Static callback function that gets called when our DYLD notification
352// breakpoint gets hit. We update all of our image infos and then let our super
353// class DynamicLoader class decide if we should stop or not (based on global
354// preference).
356 void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id,
357 lldb::user_id_t break_loc_id) {
358 // Let the event know that the images have changed
359 // DYLD passes three arguments to the notification breakpoint.
360 // Arg1: enum dyld_image_mode mode - 0 = adding, 1 = removing Arg2: uint32_t
361 // infoCount - Number of shared libraries added Arg3: dyld_image_info
362 // info[] - Array of structs of the form:
363 // const struct mach_header
364 // *imageLoadAddress
365 // const char *imageFilePath
366 // uintptr_t imageFileModDate (a time_t)
367
368 DynamicLoaderMacOSXDYLD *dyld_instance = (DynamicLoaderMacOSXDYLD *)baton;
369
370 // First step is to see if we've already initialized the all image infos. If
371 // we haven't then this function will do so and return true. In the course
372 // of initializing the all_image_infos it will read the complete current
373 // state, so we don't need to figure out what has changed from the data
374 // passed in to us.
375
376 ExecutionContext exe_ctx(context->exe_ctx_ref);
377 Process *process = exe_ctx.GetProcessPtr();
378
379 // This is a sanity check just in case this dyld_instance is an old dyld
380 // plugin's breakpoint still lying around.
381 if (process != dyld_instance->m_process)
382 return false;
383
384 if (dyld_instance->InitializeFromAllImageInfos())
385 return dyld_instance->GetStopWhenImagesChange();
386
387 const lldb::ABISP &abi = process->GetABI();
388 if (abi) {
389 // Build up the value array to store the three arguments given above, then
390 // get the values from the ABI:
391
392 TypeSystemClangSP scratch_ts_sp =
394 if (!scratch_ts_sp)
395 return false;
396
397 ValueList argument_values;
398 Value input_value;
399
400 CompilerType clang_void_ptr_type =
401 scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType();
402 CompilerType clang_uint32_type =
403 scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(lldb::eEncodingUint,
404 32);
406 input_value.SetCompilerType(clang_uint32_type);
407 // input_value.SetContext (Value::eContextTypeClangType,
408 // clang_uint32_type);
409 argument_values.PushValue(input_value);
410 argument_values.PushValue(input_value);
411 input_value.SetCompilerType(clang_void_ptr_type);
412 // input_value.SetContext (Value::eContextTypeClangType,
413 // clang_void_ptr_type);
414 argument_values.PushValue(input_value);
415
416 if (abi->GetArgumentValues(exe_ctx.GetThreadRef(), argument_values)) {
417 uint32_t dyld_mode =
418 argument_values.GetValueAtIndex(0)->GetScalar().UInt(-1);
419 if (dyld_mode != static_cast<uint32_t>(-1)) {
420 // Okay the mode was right, now get the number of elements, and the
421 // array of new elements...
422 uint32_t image_infos_count =
423 argument_values.GetValueAtIndex(1)->GetScalar().UInt(-1);
424 if (image_infos_count != static_cast<uint32_t>(-1)) {
425 // Got the number added, now go through the array of added elements,
426 // putting out the mach header address, and adding the image. Note,
427 // I'm not putting in logging here, since the AddModules &
428 // RemoveModules functions do all the logging internally.
429
430 lldb::addr_t image_infos_addr =
431 argument_values.GetValueAtIndex(2)->GetScalar().ULongLong();
432 if (dyld_mode == 0) {
433 // This is add:
434 dyld_instance->AddModulesUsingImageInfosAddress(image_infos_addr,
435 image_infos_count);
436 } else {
437 // This is remove:
439 image_infos_addr, image_infos_count);
440 }
441 }
442 }
443 }
444 } else {
445 Target &target = process->GetTarget();
447 "no ABI plugin located for triple " +
448 target.GetArchitecture().GetTriple().getTriple() +
449 ": shared libraries will not be registered",
450 target.GetDebugger().GetID());
451 }
452
453 // Return true to stop the target, false to just let the target run
454 return dyld_instance->GetStopWhenImagesChange();
455}
456
458 std::lock_guard<std::recursive_mutex> guard(m_mutex);
459
460 // the all image infos is already valid for this process stop ID
461 if (m_process->GetStopID() == m_dyld_all_image_infos_stop_id)
462 return true;
463
466 ByteOrder byte_order =
467 m_process->GetTarget().GetArchitecture().GetByteOrder();
468 uint32_t addr_size =
469 m_process->GetTarget().GetArchitecture().GetAddressByteSize();
470
471 uint8_t buf[256];
472 DataExtractor data(buf, sizeof(buf), byte_order, addr_size);
473 lldb::offset_t offset = 0;
474
475 const size_t count_v2 = sizeof(uint32_t) + // version
476 sizeof(uint32_t) + // infoArrayCount
477 addr_size + // infoArray
478 addr_size + // notification
479 addr_size + // processDetachedFromSharedRegion +
480 // libSystemInitialized + pad
481 addr_size; // dyldImageLoadAddress
482 const size_t count_v11 = count_v2 + addr_size + // jitInfo
483 addr_size + // dyldVersion
484 addr_size + // errorMessage
485 addr_size + // terminationFlags
486 addr_size + // coreSymbolicationShmPage
487 addr_size + // systemOrderFlag
488 addr_size + // uuidArrayCount
489 addr_size + // uuidArray
490 addr_size + // dyldAllImageInfosAddress
491 addr_size + // initialImageCount
492 addr_size + // errorKind
493 addr_size + // errorClientOfDylibPath
494 addr_size + // errorTargetDylibPath
495 addr_size; // errorSymbol
496 const size_t count_v13 = count_v11 + addr_size + // sharedCacheSlide
497 sizeof(uuid_t); // sharedCacheUUID
498 UNUSED_IF_ASSERT_DISABLED(count_v13);
499 assert(sizeof(buf) >= count_v13);
500
502 if (m_process->ReadMemory(m_dyld_all_image_infos_addr, buf, 4, error) ==
503 4) {
504 m_dyld_all_image_infos.version = data.GetU32(&offset);
505 // If anything in the high byte is set, we probably got the byte order
506 // incorrect (the process might not have it set correctly yet due to
507 // attaching to a program without a specified file).
508 if (m_dyld_all_image_infos.version & 0xff000000) {
509 // We have guessed the wrong byte order. Swap it and try reading the
510 // version again.
511 if (byte_order == eByteOrderLittle)
512 byte_order = eByteOrderBig;
513 else
514 byte_order = eByteOrderLittle;
515
516 data.SetByteOrder(byte_order);
517 offset = 0;
518 m_dyld_all_image_infos.version = data.GetU32(&offset);
519 }
520 } else {
521 return false;
522 }
523
524 const size_t count =
525 (m_dyld_all_image_infos.version >= 11) ? count_v11 : count_v2;
526
527 const size_t bytes_read =
528 m_process->ReadMemory(m_dyld_all_image_infos_addr, buf, count, error);
529 if (bytes_read == count) {
530 offset = 0;
531 m_dyld_all_image_infos.version = data.GetU32(&offset);
532 m_dyld_all_image_infos.dylib_info_count = data.GetU32(&offset);
533 m_dyld_all_image_infos.dylib_info_addr = data.GetAddress(&offset);
534 m_dyld_all_image_infos.notification = data.GetAddress(&offset);
535 m_dyld_all_image_infos.processDetachedFromSharedRegion =
536 data.GetU8(&offset);
537 m_dyld_all_image_infos.libSystemInitialized = data.GetU8(&offset);
538 // Adjust for padding.
539 offset += addr_size - 2;
540 m_dyld_all_image_infos.dyldImageLoadAddress = data.GetAddress(&offset);
541 if (m_dyld_all_image_infos.version >= 11) {
542 offset += addr_size * 8;
543 uint64_t dyld_all_image_infos_addr = data.GetAddress(&offset);
544
545 // When we started, we were given the actual address of the
546 // all_image_infos struct (probably via TASK_DYLD_INFO) in memory -
547 // this address is stored in m_dyld_all_image_infos_addr and is the
548 // most accurate address we have.
549
550 // We read the dyld_all_image_infos struct from memory; it contains its
551 // own address. If the address in the struct does not match the actual
552 // address, the dyld we're looking at has been loaded at a different
553 // location (slid) from where it intended to load. The addresses in
554 // the dyld_all_image_infos struct are the original, non-slid
555 // addresses, and need to be adjusted. Most importantly the address of
556 // dyld and the notification address need to be adjusted.
557
558 if (dyld_all_image_infos_addr != m_dyld_all_image_infos_addr) {
559 uint64_t image_infos_offset =
560 dyld_all_image_infos_addr -
561 m_dyld_all_image_infos.dyldImageLoadAddress;
562 uint64_t notification_offset =
563 m_dyld_all_image_infos.notification -
564 m_dyld_all_image_infos.dyldImageLoadAddress;
565 m_dyld_all_image_infos.dyldImageLoadAddress =
566 m_dyld_all_image_infos_addr - image_infos_offset;
567 m_dyld_all_image_infos.notification =
568 m_dyld_all_image_infos.dyldImageLoadAddress + notification_offset;
569 }
570 }
572 return true;
573 }
574 }
575 return false;
576}
577
579 lldb::addr_t image_infos_addr, uint32_t image_infos_count) {
580 ImageInfo::collection image_infos;
582 LLDB_LOGF(log, "Adding %d modules.\n", image_infos_count);
583
584 std::lock_guard<std::recursive_mutex> guard(m_mutex);
585 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
586 if (m_process->GetStopID() == m_dyld_image_infos_stop_id)
587 return true;
588
589 StructuredData::ObjectSP image_infos_json_sp =
590 m_process->GetLoadedDynamicLibrariesInfos(image_infos_addr,
591 image_infos_count);
592 if (image_infos_json_sp.get() && image_infos_json_sp->GetAsDictionary() &&
593 image_infos_json_sp->GetAsDictionary()->HasKey("images") &&
594 image_infos_json_sp->GetAsDictionary()
595 ->GetValueForKey("images")
596 ->GetAsArray() &&
597 image_infos_json_sp->GetAsDictionary()
598 ->GetValueForKey("images")
599 ->GetAsArray()
600 ->GetSize() == image_infos_count) {
601 bool return_value = false;
602 if (JSONImageInformationIntoImageInfo(image_infos_json_sp, image_infos)) {
603 auto images = PreloadModulesFromImageInfos(image_infos);
605 return_value = AddModulesUsingPreloadedModules(images);
606 }
608 return return_value;
609 }
610
611 if (!ReadImageInfos(image_infos_addr, image_infos_count, image_infos))
612 return false;
613
614 UpdateImageInfosHeaderAndLoadCommands(image_infos, image_infos_count, false);
615 bool return_value = AddModulesUsingImageInfos(image_infos);
617 return return_value;
618}
619
621 lldb::addr_t image_infos_addr, uint32_t image_infos_count) {
622 ImageInfo::collection image_infos;
624
625 std::lock_guard<std::recursive_mutex> guard(m_mutex);
626 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
627 if (m_process->GetStopID() == m_dyld_image_infos_stop_id)
628 return true;
629
630 // First read in the image_infos for the removed modules, and their headers &
631 // load commands.
632 if (!ReadImageInfos(image_infos_addr, image_infos_count, image_infos)) {
633 if (log)
634 log->PutCString("Failed reading image infos array.");
635 return false;
636 }
637
638 LLDB_LOGF(log, "Removing %d modules.", image_infos_count);
639
640 ModuleList unloaded_module_list;
641 for (uint32_t idx = 0; idx < image_infos.size(); ++idx) {
642 if (log) {
643 LLDB_LOGF(log, "Removing module at address=0x%16.16" PRIx64 ".",
644 image_infos[idx].address);
645 image_infos[idx].PutToLog(log);
646 }
647
648 // Remove this image_infos from the m_all_image_infos. We do the
649 // comparison by address rather than by file spec because we can have many
650 // modules with the same "file spec" in the case that they are modules
651 // loaded from memory.
652 //
653 // Also copy over the uuid from the old entry to the removed entry so we
654 // can use it to lookup the module in the module list.
655
656 bool found = false;
657
658 for (ImageInfo::collection::iterator pos = m_dyld_image_infos.begin();
659 pos != m_dyld_image_infos.end(); pos++) {
660 if (image_infos[idx].address == (*pos).address) {
661 image_infos[idx].uuid = (*pos).uuid;
662
663 // Add the module from this image_info to the "unloaded_module_list".
664 // We'll remove them all at one go later on.
665
666 ModuleSP unload_image_module_sp(
667 FindTargetModuleForImageInfo(image_infos[idx], false, nullptr));
668 if (unload_image_module_sp.get()) {
669 // When we unload, be sure to use the image info from the old list,
670 // since that has sections correctly filled in.
671 UnloadModuleSections(unload_image_module_sp.get(), *pos);
672 unloaded_module_list.AppendIfNeeded(unload_image_module_sp);
673 } else {
674 if (log) {
675 LLDB_LOGF(log, "Could not find module for unloading info entry:");
676 image_infos[idx].PutToLog(log);
677 }
678 }
679
680 // Then remove it from the m_dyld_image_infos:
681
682 m_dyld_image_infos.erase(pos);
683 found = true;
684 break;
685 }
686 }
687
688 if (!found) {
689 if (log) {
690 LLDB_LOGF(log, "Could not find image_info entry for unloading image:");
691 image_infos[idx].PutToLog(log);
692 }
693 }
694 }
695 if (unloaded_module_list.GetSize() > 0) {
696 if (log) {
697 log->PutCString("Unloaded:");
698 unloaded_module_list.LogUUIDAndPaths(
699 log, "DynamicLoaderMacOSXDYLD::ModulesDidUnload");
700 }
701 m_process->GetTarget().GetImages().Remove(unloaded_module_list);
702 }
704 return true;
705}
706
708 lldb::addr_t image_infos_addr, uint32_t image_infos_count,
709 ImageInfo::collection &image_infos) {
710 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
711 const ByteOrder endian = GetByteOrderFromMagic(m_dyld.header.magic);
712 const uint32_t addr_size = m_dyld.GetAddressByteSize();
713
714 image_infos.resize(image_infos_count);
715 const size_t count = image_infos.size() * 3 * addr_size;
716 DataBufferHeap info_data(count, 0);
718 const size_t bytes_read = m_process->ReadMemory(
719 image_infos_addr, info_data.GetBytes(), info_data.GetByteSize(), error);
720 if (bytes_read == count) {
721 lldb::offset_t info_data_offset = 0;
722 DataExtractor info_data_ref(info_data.GetBytes(), info_data.GetByteSize(),
723 endian, addr_size);
724 for (size_t i = 0;
725 i < image_infos.size() && info_data_ref.ValidOffset(info_data_offset);
726 i++) {
727 image_infos[i].address = info_data_ref.GetAddress(&info_data_offset);
728 lldb::addr_t path_addr = info_data_ref.GetAddress(&info_data_offset);
729 info_data_ref.GetAddress(&info_data_offset); // mod_date, unused */
730
731 char raw_path[PATH_MAX];
732 m_process->ReadCStringFromMemory(path_addr, raw_path, sizeof(raw_path),
733 error);
734 // don't resolve the path
735 if (error.Success()) {
736 image_infos[i].file_spec.SetFile(raw_path, FileSpec::Style::native);
737 }
738 }
739 return true;
740 } else {
741 return false;
742 }
743}
744
745// If we have found where the "_dyld_all_image_infos" lives in memory, read the
746// current info from it, and then update all image load addresses (or lack
747// thereof). Only do this if this is the first time we're reading the dyld
748// infos. Return true if we actually read anything, and false otherwise.
751
752 std::lock_guard<std::recursive_mutex> guard(m_mutex);
753 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
754 if (m_process->GetStopID() == m_dyld_image_infos_stop_id ||
755 m_dyld_image_infos.size() != 0)
756 return false;
757
759 // Nothing to load or unload?
760 if (m_dyld_all_image_infos.dylib_info_count == 0)
761 return true;
762
763 if (m_dyld_all_image_infos.dylib_info_addr == 0) {
764 // DYLD is updating the images now. So we should say we have no images,
765 // and then we'll
766 // figure it out when we hit the added breakpoint.
767 return false;
768 } else {
770 m_dyld_all_image_infos.dylib_info_addr,
771 m_dyld_all_image_infos.dylib_info_count)) {
772 DEBUG_PRINTF("%s", "unable to read all data for all_dylib_infos.");
773 m_dyld_image_infos.clear();
774 }
775 }
776
777 // Now we have one more bit of business. If there is a library left in the
778 // images for our target that doesn't have a load address, then it must be
779 // something that we were expecting to load (for instance we read a load
780 // command for it) but it didn't in fact load - probably because
781 // DYLD_*_PATH pointed to an equivalent version. We don't want it to stay
782 // in the target's module list or it will confuse us, so unload it here.
783 Target &target = m_process->GetTarget();
784 ModuleList not_loaded_modules;
785 for (ModuleSP module_sp : target.GetImages().Modules()) {
786 if (!module_sp->IsLoadedInTarget(&target)) {
787 if (log) {
788 StreamString s;
789 module_sp->GetDescription(s.AsRawOstream());
790 LLDB_LOGF(log, "Unloading pre-run module: %s.", s.GetData());
791 }
792 not_loaded_modules.Append(module_sp);
793 }
794 }
795
796 if (not_loaded_modules.GetSize() != 0) {
797 target.GetImages().Remove(not_loaded_modules);
798 }
799
800 return true;
801 } else
802 return false;
803}
804
805// Read a mach_header at ADDR into HEADER, and also fill in the load command
806// data into LOAD_COMMAND_DATA if it is non-NULL.
807//
808// Returns true if we succeed, false if we fail for any reason.
810 llvm::MachO::mach_header *header,
811 DataExtractor *load_command_data) {
812 DataBufferHeap header_bytes(sizeof(llvm::MachO::mach_header), 0);
814 size_t bytes_read = m_process->ReadMemory(addr, header_bytes.GetBytes(),
815 header_bytes.GetByteSize(), error);
816 if (bytes_read == sizeof(llvm::MachO::mach_header)) {
817 lldb::offset_t offset = 0;
818 ::memset(header, 0, sizeof(llvm::MachO::mach_header));
819
820 // Get the magic byte unswapped so we can figure out what we are dealing
821 // with
822 DataExtractor data(header_bytes.GetBytes(), header_bytes.GetByteSize(),
824 header->magic = data.GetU32(&offset);
825 lldb::addr_t load_cmd_addr = addr;
826 data.SetByteOrder(
828 switch (header->magic) {
829 case llvm::MachO::MH_MAGIC:
830 case llvm::MachO::MH_CIGAM:
831 data.SetAddressByteSize(4);
832 load_cmd_addr += sizeof(llvm::MachO::mach_header);
833 break;
834
835 case llvm::MachO::MH_MAGIC_64:
836 case llvm::MachO::MH_CIGAM_64:
837 data.SetAddressByteSize(8);
838 load_cmd_addr += sizeof(llvm::MachO::mach_header_64);
839 break;
840
841 default:
842 return false;
843 }
844
845 // Read the rest of dyld's mach header
846 if (data.GetU32(&offset, &header->cputype,
847 (sizeof(llvm::MachO::mach_header) / sizeof(uint32_t)) -
848 1)) {
849 if (load_command_data == nullptr)
850 return true; // We were able to read the mach_header and weren't asked
851 // to read the load command bytes
852
853 WritableDataBufferSP load_cmd_data_sp(
854 new DataBufferHeap(header->sizeofcmds, 0));
855
856 size_t load_cmd_bytes_read =
857 m_process->ReadMemory(load_cmd_addr, load_cmd_data_sp->GetBytes(),
858 load_cmd_data_sp->GetByteSize(), error);
859
860 if (load_cmd_bytes_read == header->sizeofcmds) {
861 // Set the load command data and also set the correct endian swap
862 // settings and the correct address size
863 load_command_data->SetData(load_cmd_data_sp, 0, header->sizeofcmds);
864 load_command_data->SetByteOrder(data.GetByteOrder());
865 load_command_data->SetAddressByteSize(data.GetAddressByteSize());
866 return true; // We successfully read the mach_header and the load
867 // command data
868 }
869
870 return false; // We weren't able to read the load command data
871 }
872 }
873 return false; // We failed the read the mach_header
874}
875
876// Parse the load commands for an image
878 ImageInfo &dylib_info,
879 FileSpec *lc_id_dylinker) {
880 lldb::offset_t offset = 0;
881 uint32_t cmd_idx;
882 Segment segment;
883 dylib_info.Clear(true);
884
885 for (cmd_idx = 0; cmd_idx < dylib_info.header.ncmds; cmd_idx++) {
886 // Clear out any load command specific data from DYLIB_INFO since we are
887 // about to read it.
888
889 if (data.ValidOffsetForDataOfSize(offset,
890 sizeof(llvm::MachO::load_command))) {
891 llvm::MachO::load_command load_cmd;
892 lldb::offset_t load_cmd_offset = offset;
893 load_cmd.cmd = data.GetU32(&offset);
894 load_cmd.cmdsize = data.GetU32(&offset);
895 switch (load_cmd.cmd) {
896 case llvm::MachO::LC_SEGMENT: {
897 data.CopyData(offset, 16, segment.name);
898 segment.name[16] = '\0';
899 offset += 16;
900 // We are putting 4 uint32_t values 4 uint64_t values so we have to use
901 // multiple 32 bit gets below.
902 segment.vmaddr = data.GetU32(&offset);
903 segment.vmsize = data.GetU32(&offset);
904 segment.fileoff = data.GetU32(&offset);
905 segment.filesize = data.GetU32(&offset);
906 // Extract maxprot, initprot, nsects and flags all at once
907 data.GetU32(&offset, &segment.maxprot, 4);
908 dylib_info.segments.push_back(segment);
909 } break;
910
911 case llvm::MachO::LC_SEGMENT_64: {
912 data.CopyData(offset, 16, segment.name);
913 segment.name[16] = '\0';
914 offset += 16;
915 // Extract vmaddr, vmsize, fileoff, and filesize all at once
916 data.GetU64(&offset, &segment.vmaddr, 4);
917 // Extract maxprot, initprot, nsects and flags all at once
918 data.GetU32(&offset, &segment.maxprot, 4);
919 dylib_info.segments.push_back(segment);
920 } break;
921
922 case llvm::MachO::LC_ID_DYLINKER:
923 if (lc_id_dylinker) {
924 const lldb::offset_t name_offset =
925 load_cmd_offset + data.GetU32(&offset);
926 if (std::optional<llvm::StringRef> path = data.PeekCStr(name_offset))
927 lc_id_dylinker->SetFile(*path, FileSpec::Style::native);
928 FileSystem::Instance().Resolve(*lc_id_dylinker);
929 }
930 break;
931
932 case llvm::MachO::LC_UUID:
933 dylib_info.uuid = UUID(data.GetData(&offset, 16), 16);
934 break;
935
936 default:
937 break;
938 }
939 // Set offset to be the beginning of the next load command.
940 offset = load_cmd_offset + load_cmd.cmdsize;
941 }
942 }
943
944 // All sections listed in the dyld image info structure will all either be
945 // fixed up already, or they will all be off by a single slide amount that is
946 // determined by finding the first segment that is at file offset zero which
947 // also has bytes (a file size that is greater than zero) in the object file.
948
949 // Determine the slide amount (if any)
950 const size_t num_sections = dylib_info.segments.size();
951 for (size_t i = 0; i < num_sections; ++i) {
952 // Iterate through the object file sections to find the first section that
953 // starts of file offset zero and that has bytes in the file...
954 if ((dylib_info.segments[i].fileoff == 0 &&
955 dylib_info.segments[i].filesize > 0) ||
956 (llvm::StringRef(dylib_info.segments[i].name) == "__TEXT")) {
957 dylib_info.slide = dylib_info.address - dylib_info.segments[i].vmaddr;
958 // We have found the slide amount, so we can exit this for loop.
959 break;
960 }
961 }
962 return cmd_idx;
963}
964
965// Read the mach_header and load commands for each image that the
966// _dyld_all_image_infos structure points to and cache the results.
967
969 ImageInfo::collection &image_infos, uint32_t infos_count,
970 bool update_executable) {
971 uint32_t exe_idx = UINT32_MAX;
972 // Read any UUID values that we can get
973 for (uint32_t i = 0; i < infos_count; i++) {
974 if (!image_infos[i].UUIDValid()) {
975 DataExtractor data; // Load command data
976 if (!ReadMachHeader(image_infos[i].address, &image_infos[i].header,
977 &data))
978 continue;
979
980 ParseLoadCommands(data, image_infos[i], nullptr);
981
982 if (image_infos[i].header.filetype == llvm::MachO::MH_EXECUTE)
983 exe_idx = i;
984 }
985 }
986
987 Target &target = m_process->GetTarget();
988
989 if (exe_idx < image_infos.size()) {
990 const bool can_create = true;
991 ModuleSP exe_module_sp(FindTargetModuleForImageInfo(image_infos[exe_idx],
992 can_create, nullptr));
993
994 if (exe_module_sp) {
995 UpdateImageLoadAddress(exe_module_sp.get(), image_infos[exe_idx]);
996
997 if (exe_module_sp.get() != target.GetExecutableModulePointer()) {
998 // Don't load dependent images since we are in dyld where we will know
999 // and find out about all images that are loaded. Also when setting the
1000 // executable module, it will clear the targets module list, and if we
1001 // have an in memory dyld module, it will get removed from the list so
1002 // we will need to add it back after setting the executable module, so
1003 // we first try and see if we already have a weak pointer to the dyld
1004 // module, make it into a shared pointer, then add the executable, then
1005 // re-add it back to make sure it is always in the list.
1006 ModuleSP dyld_module_sp(GetDYLDModule());
1007
1008 m_process->GetTarget().RebuildModuleListWithExecutable(
1009 exe_module_sp, eLoadDependentsNo);
1010
1011 if (dyld_module_sp) {
1012 if (target.GetImages().AppendIfNeeded(dyld_module_sp)) {
1013 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
1014
1015 // Also add it to the section list.
1016 UpdateImageLoadAddress(dyld_module_sp.get(), m_dyld);
1017 }
1018 }
1019 }
1020 }
1021 }
1022}
1023
1024// Dump the _dyld_all_image_infos members and all current image infos that we
1025// have parsed to the file handle provided.
1027 if (log == nullptr)
1028 return;
1029
1030 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1031 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
1032 LLDB_LOGF(log,
1033 "dyld_all_image_infos = { version=%d, count=%d, addr=0x%8.8" PRIx64
1034 ", notify=0x%8.8" PRIx64 " }",
1035 m_dyld_all_image_infos.version,
1036 m_dyld_all_image_infos.dylib_info_count,
1037 (uint64_t)m_dyld_all_image_infos.dylib_info_addr,
1038 (uint64_t)m_dyld_all_image_infos.notification);
1039 size_t i;
1040 const size_t count = m_dyld_image_infos.size();
1041 if (count > 0) {
1042 log->PutCString("Loaded:");
1043 for (i = 0; i < count; i++)
1045 }
1046}
1047
1049 DEBUG_PRINTF("DynamicLoaderMacOSXDYLD::%s() process state = %s\n",
1050 __FUNCTION__, StateAsCString(m_process->GetState()));
1052 if (m_dyld_all_image_infos.notification != LLDB_INVALID_ADDRESS) {
1053 Address so_addr;
1054 // Set the notification breakpoint and install a breakpoint callback
1055 // function that will get called each time the breakpoint gets hit. We
1056 // will use this to track when shared libraries get loaded/unloaded.
1057 bool resolved = m_process->GetTarget().ResolveLoadAddress(
1058 m_dyld_all_image_infos.notification, so_addr);
1059 if (!resolved) {
1060 ModuleSP dyld_module_sp = GetDYLDModule();
1061 if (dyld_module_sp) {
1062 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
1063
1064 UpdateImageLoadAddress(dyld_module_sp.get(), m_dyld);
1065 resolved = m_process->GetTarget().ResolveLoadAddress(
1066 m_dyld_all_image_infos.notification, so_addr);
1067 }
1068 }
1069
1070 if (resolved) {
1071 Breakpoint *dyld_break =
1072 m_process->GetTarget().CreateBreakpoint(so_addr, true, false).get();
1074 this, true);
1075 dyld_break->SetBreakpointKind("shared-library-event");
1076 m_break_id = dyld_break->GetID();
1077 }
1078 }
1079 }
1081}
1082
1084 Status error;
1085 // In order for us to tell if we can load a shared library we verify that the
1086 // dylib_info_addr isn't zero (which means no shared libraries have been set
1087 // yet, or dyld is currently mucking with the shared library list).
1089 // TODO: also check the _dyld_global_lock_held variable in
1090 // libSystem.B.dylib?
1091 // TODO: check the malloc lock?
1092 // TODO: check the objective C lock?
1093 if (m_dyld_all_image_infos.dylib_info_addr != 0)
1094 return error; // Success
1095 }
1096
1097 error = Status::FromErrorString("unsafe to load or unload shared libraries");
1098 return error;
1099}
1100
1102 lldb::addr_t &base_address, UUID &uuid, LazyBool &using_shared_cache,
1103 LazyBool &private_shared_cache, FileSpec &shared_cache_filepath,
1104 std::optional<uint64_t> &size) {
1105 base_address = LLDB_INVALID_ADDRESS;
1106 uuid.Clear();
1107 using_shared_cache = eLazyBoolCalculate;
1108 private_shared_cache = eLazyBoolCalculate;
1109 size.reset();
1110
1111 if (m_process) {
1112 addr_t all_image_infos = m_process->GetImageInfoAddress();
1113
1114 // The address returned by GetImageInfoAddress may be the address of dyld
1115 // (don't want) or it may be the address of the dyld_all_image_infos
1116 // structure (want). The first four bytes will be either the version field
1117 // (all_image_infos) or a Mach-O file magic constant. Version 13 and higher
1118 // of dyld_all_image_infos is required to get the sharedCacheUUID field.
1119
1120 ImageInfoAddressContents contents =
1121 ReadImageInfoAddressContents(*m_process, all_image_infos);
1122 if (contents.kind == ImageInfoAddressContents::AllImageInfos &&
1123 contents.all_image_infos_version >= 13) {
1124 Status err;
1125 addr_t sharedCacheUUID_address = LLDB_INVALID_ADDRESS;
1126 int wordsize = m_process->GetAddressByteSize();
1127 if (wordsize == 8) {
1128 sharedCacheUUID_address =
1129 all_image_infos + 160; // sharedCacheUUID <mach-o/dyld_images.h>
1130 }
1131 if (wordsize == 4) {
1132 sharedCacheUUID_address =
1133 all_image_infos + 84; // sharedCacheUUID <mach-o/dyld_images.h>
1134 }
1135 if (sharedCacheUUID_address != LLDB_INVALID_ADDRESS) {
1136 uuid_t shared_cache_uuid;
1137 if (m_process->ReadMemory(sharedCacheUUID_address, shared_cache_uuid,
1138 sizeof(uuid_t), err) == sizeof(uuid_t)) {
1139 uuid = UUID(shared_cache_uuid, 16);
1140 if (uuid.IsValid()) {
1141 using_shared_cache = eLazyBoolYes;
1142 }
1143 }
1144
1145 if (contents.all_image_infos_version >= 15) {
1146 // The sharedCacheBaseAddress field is the next one in the
1147 // dyld_all_image_infos struct.
1148 addr_t sharedCacheBaseAddr_address = sharedCacheUUID_address + 16;
1149 Status error;
1150 base_address = m_process->ReadUnsignedIntegerFromMemory(
1151 sharedCacheBaseAddr_address, wordsize, LLDB_INVALID_ADDRESS,
1152 error);
1153 if (error.Fail())
1154 base_address = LLDB_INVALID_ADDRESS;
1155 }
1156
1157 return true;
1158 }
1159
1160 //
1161 // add
1162 // NB: sharedCacheBaseAddress is the next field in dyld_all_image_infos
1163 // after
1164 // sharedCacheUUID -- that is, 16 bytes after it, if we wanted to fetch
1165 // it.
1166 }
1167 }
1168 return false;
1169}
1170
1172 // dyld_all_image_infos version 13 added the sharedCacheUUID field.
1173 ImageInfoAddressContents contents = ReadImageInfoAddressContents(
1174 *m_process, m_process->GetImageInfoAddress());
1175 return contents.kind == ImageInfoAddressContents::AllImageInfos &&
1176 contents.all_image_infos_version >= 13;
1177}
1178
1181 return m_dyld_all_image_infos.libSystemInitialized;
1182 return false;
1183}
1184
1190
1195
1197 return "Dynamic loader plug-in that watches for shared library loads/unloads "
1198 "in MacOSX user processes.";
1199}
1200
1202 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
1203
1204 switch (m_dyld.header.magic) {
1205 case llvm::MachO::MH_MAGIC:
1206 case llvm::MachO::MH_CIGAM:
1207 return 4;
1208
1209 case llvm::MachO::MH_MAGIC_64:
1210 case llvm::MachO::MH_CIGAM_64:
1211 return 8;
1212
1213 default:
1214 break;
1215 }
1216 return 0;
1217}
1218
1220 switch (magic) {
1221 case llvm::MachO::MH_MAGIC:
1222 case llvm::MachO::MH_MAGIC_64:
1223 return endian::InlHostByteOrder();
1224
1225 case llvm::MachO::MH_CIGAM:
1226 case llvm::MachO::MH_CIGAM_64:
1229 else
1230 return lldb::eByteOrderBig;
1231
1232 default:
1233 break;
1234 }
1236}
unsigned char uuid_t[16]
static llvm::raw_ostream & error(Stream &strm)
#define DEBUG_PRINTF(fmt,...)
static ImageInfoAddressContents ReadImageInfoAddressContents(Process &process, addr_t addr)
#define LLDB_LOGF(log,...)
Definition Log.h:389
#define LLDB_PLUGIN_DEFINE(PluginName)
bool ReadDYLDInfoFromMemoryAndSetNotificationCallback(lldb::addr_t addr)
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_filepath, std::optional< uint64_t > &size) override
Get information about the shared cache for a process, if possible.
void PutToLog(lldb_private::Log *log) const
bool RemoveModulesUsingImageInfosAddress(lldb::addr_t image_infos_addr, uint32_t image_infos_count)
static lldb_private::DynamicLoader * CreateInstance(lldb_private::Process *process, bool force)
void UpdateImageInfosHeaderAndLoadCommands(ImageInfo::collection &image_infos, uint32_t infos_count, bool update_executable)
static llvm::StringRef GetPluginNameStatic()
static llvm::StringRef GetPluginDescriptionStatic()
static lldb::ByteOrder GetByteOrderFromMagic(uint32_t magic)
DynamicLoaderMacOSXDYLD(lldb_private::Process *process)
bool ReadImageInfos(lldb::addr_t image_infos_addr, uint32_t image_infos_count, ImageInfo::collection &image_infos)
uint32_t ParseLoadCommands(const lldb_private::DataExtractor &data, ImageInfo &dylib_info, lldb_private::FileSpec *lc_id_dylinker)
bool SharedCacheInUse() override
Query if the process has a system shared cache.
lldb_private::Status CanLoadImage() override
Ask if it is ok to try and load or unload an shared library (image).
bool ReadMachHeader(lldb::addr_t addr, llvm::MachO::mach_header *header, lldb_private::DataExtractor *load_command_data)
bool ProcessDidExec() override
Called after attaching a process.
bool IsFullyInitialized() override
Return whether the dynamic loader is fully initialized and it's safe to call its APIs.
bool AddModulesUsingImageInfosAddress(lldb::addr_t image_infos_addr, uint32_t image_infos_count)
static bool NotifyBreakpointHit(void *baton, lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
DYLDAllImageInfos m_dyld_all_image_infos
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:303
An architecture specification class.
Definition ArchSpec.h:32
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition ArchSpec.cpp:710
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:465
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition ArchSpec.cpp:702
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
Definition Breakpoint.h:83
void SetBreakpointKind(const char *kind)
Set the "kind" description for a breakpoint.
Definition Breakpoint.h:485
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
A subclass of DataBuffer that stores a data buffer on the heap.
lldb::offset_t GetByteSize() const override
Get the number of bytes in the data buffer.
An data extractor class.
virtual const void * GetData(lldb::offset_t *offset_ptr, lldb::offset_t length) const
Extract length bytes from *offset_ptr.
uint64_t GetU64(lldb::offset_t *offset_ptr) const
Extract a uint64_t value from *offset_ptr.
bool ValidOffsetForDataOfSize(lldb::offset_t offset, lldb::offset_t length) const
Test the availability of length bytes of data from offset.
lldb::offset_t CopyData(lldb::offset_t offset, lldb::offset_t length, void *dst) const
Copy length bytes from *offset, without swapping bytes.
void SetByteOrder(lldb::ByteOrder byte_order)
Set the byte_order value.
uint32_t GetU32(lldb::offset_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
uint64_t GetAddress(lldb::offset_t *offset_ptr) const
Extract an address from *offset_ptr.
bool ValidOffset(lldb::offset_t offset) const
Test the validity of offset.
virtual lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
uint32_t GetAddressByteSize() const
Get the current address size.
lldb::ByteOrder GetByteOrder() const
Get the current byte order value.
void SetAddressByteSize(uint32_t addr_size)
Set the address byte size.
std::optional< llvm::StringRef > PeekCStr(lldb::offset_t offset) const
Peek at a null-terminated C string at offset.
uint8_t GetU8(lldb::offset_t *offset_ptr) const
Extract a uint8_t value from *offset_ptr.
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
bool UpdateDYLDImageInfoFromNewImageInfo(ImageInfo &image_info)
DynamicLoaderDarwin(lldb_private::Process *process)
std::recursive_mutex & GetMutex() const
lldb::ModuleSP FindTargetModuleForImageInfo(const ImageInfo &image_info, bool can_create, bool *did_create_ptr)
bool AddModulesUsingImageInfos(ImageInfo::collection &image_infos)
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)
void UpdateSpecialBinariesFromPreloadedModules(std::vector< std::pair< ImageInfo, lldb::ModuleSP > > &images)
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)
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 utility class.
Definition FileSpec.h:56
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition FileSpec.cpp:174
static FileSystem & Instance()
void Resolve(llvm::SmallVectorImpl< char > &path, bool force_make_absolute=false)
Resolve path to make it canonical.
void PutCString(const char *cstr)
Definition Log.cpp:162
A collection class for Module objects.
Definition ModuleList.h:139
bool AppendIfNeeded(const lldb::ModuleSP &new_module, bool notify=true)
Append a module to the module list, if it is not already there.
bool Remove(const lldb::ModuleSP &module_sp, bool notify=true)
Remove a module from the module list.
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
ModuleIterable Modules() const
Definition ModuleList.h:586
size_t GetSize() const
Gets the size of the module list.
void LogUUIDAndPaths(Log *log, const char *prefix_cstr)
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:92
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
Definition Module.cpp:1235
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
Definition Module.cpp:1070
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:47
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:370
size_t ReadMemory(const ProcessAddress &process_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition Process.cpp:2115
lldb::ByteOrder GetByteOrder() const
Definition Process.cpp:4090
const lldb::ABISP & GetABI()
Definition Process.cpp:1530
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1271
unsigned int UInt(unsigned int fail_value=0) const
Definition Scalar.cpp:352
unsigned long long ULongLong(unsigned long long fail_value=0) const
Definition Scalar.cpp:366
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
const char * GetData() const
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition Stream.h:405
std::shared_ptr< Object > ObjectSP
lldb::addr_t GetLoadAddress(Target *target) const
Definition Symbol.cpp:608
ConstString GetName() const
Definition Symbol.cpp:615
void ModulesDidLoad(ModuleList &module_list)
This call may preload module symbols, and may do so in parallel depending on the following target set...
Definition Target.cpp:2012
Module * GetExecutableModulePointer()
Definition Target.cpp:1668
Debugger & GetDebugger() const
Definition Target.h:1378
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1295
const ArchSpec & GetArchitecture() const
Definition Target.h:1337
Represents UUID's of various sizes.
Definition UUID.h:27
void Clear()
Definition UUID.h:62
bool IsValid() const
Definition UUID.h:69
void PushValue(const Value &value)
Definition Value.cpp:699
Value * GetValueAtIndex(size_t idx)
Definition Value.cpp:703
const Scalar & GetScalar() const
See comment on m_scalar to understand what GetScalar returns.
Definition Value.h:114
@ Scalar
A raw scalar value.
Definition Value.h:46
void SetCompilerType(const CompilerType &compiler_type)
Definition Value.cpp:277
void SetValueType(ValueType value_type)
Definition Value.h:90
uint8_t * GetBytes()
Get a pointer to the data.
Definition DataBuffer.h:108
#define LLDB_INVALID_BREAK_ID
#define UNUSED_IF_ASSERT_DISABLED(x)
#define LLDB_BREAK_ID_IS_VALID(bid)
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
lldb::ByteOrder InlHostByteOrder()
Definition Endian.h:25
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition State.cpp:14
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:86
@ eEncodingUint
unsigned integer
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::TypeSystemClang > TypeSystemClangSP
uint64_t user_id_t
Definition lldb-types.h:83
std::shared_ptr< lldb_private::Section > SectionSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
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).
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47
#define PATH_MAX