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