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