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 }
264 }
265 dyld_module_sp = GetDYLDModule();
266
267 Target &target = m_process->GetTarget();
268
270 dyld_module_sp.get()) {
271 const Symbol *symbol = dyld_module_sp->FindFirstSymbolWithNameAndType(
272 g_dyld_all_image_infos, eSymbolTypeData);
273 if (!symbol) {
274 symbol = dyld_module_sp->FindFirstSymbolWithNameAndType(
275 g_new_dyld_all_image_infos, eSymbolTypeData);
276 }
277 if (symbol)
279 }
280
282 ConstString g_sect_name("__all_image_info");
283 SectionSP dyld_aii_section_sp =
284 dyld_module_sp->GetSectionList()->FindSectionByName(g_sect_name);
285 if (dyld_aii_section_sp) {
286 Address dyld_aii_addr(dyld_aii_section_sp, 0);
287 m_dyld_all_image_infos_addr = dyld_aii_addr.GetLoadAddress(&target);
288 }
289 }
290
291 // Update all image infos
293
294 // If we didn't have an executable before, but now we do, then the dyld
295 // module shared pointer might be unique and we may need to add it again
296 // (since Target::SetExecutableModule() will clear the images). So append
297 // the dyld module back to the list if it is
298 /// unique!
299 if (dyld_module_sp) {
300 target.GetImages().AppendIfNeeded(dyld_module_sp);
301
302 // At this point we should have read in dyld's module, and so we should
303 // set breakpoints in it:
304 ModuleList modules;
305 modules.Append(dyld_module_sp);
306 target.ModulesDidLoad(modules);
307 SetDYLDModule(dyld_module_sp);
308 }
309
310 return true;
311 }
312 }
313 return false;
314}
315
318}
319
320// Static callback function that gets called when our DYLD notification
321// breakpoint gets hit. We update all of our image infos and then let our super
322// class DynamicLoader class decide if we should stop or not (based on global
323// preference).
325 void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id,
326 lldb::user_id_t break_loc_id) {
327 // Let the event know that the images have changed
328 // DYLD passes three arguments to the notification breakpoint.
329 // Arg1: enum dyld_image_mode mode - 0 = adding, 1 = removing Arg2: uint32_t
330 // infoCount - Number of shared libraries added Arg3: dyld_image_info
331 // info[] - Array of structs of the form:
332 // const struct mach_header
333 // *imageLoadAddress
334 // const char *imageFilePath
335 // uintptr_t imageFileModDate (a time_t)
336
337 DynamicLoaderMacOSXDYLD *dyld_instance = (DynamicLoaderMacOSXDYLD *)baton;
338
339 // First step is to see if we've already initialized the all image infos. If
340 // we haven't then this function will do so and return true. In the course
341 // of initializing the all_image_infos it will read the complete current
342 // state, so we don't need to figure out what has changed from the data
343 // passed in to us.
344
345 ExecutionContext exe_ctx(context->exe_ctx_ref);
346 Process *process = exe_ctx.GetProcessPtr();
347
348 // This is a sanity check just in case this dyld_instance is an old dyld
349 // plugin's breakpoint still lying around.
350 if (process != dyld_instance->m_process)
351 return false;
352
353 if (dyld_instance->InitializeFromAllImageInfos())
354 return dyld_instance->GetStopWhenImagesChange();
355
356 const lldb::ABISP &abi = process->GetABI();
357 if (abi) {
358 // Build up the value array to store the three arguments given above, then
359 // get the values from the ABI:
360
361 TypeSystemClangSP scratch_ts_sp =
363 if (!scratch_ts_sp)
364 return false;
365
366 ValueList argument_values;
367 Value input_value;
368
369 CompilerType clang_void_ptr_type =
370 scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType();
371 CompilerType clang_uint32_type =
372 scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(lldb::eEncodingUint,
373 32);
374 input_value.SetValueType(Value::ValueType::Scalar);
375 input_value.SetCompilerType(clang_uint32_type);
376 // input_value.SetContext (Value::eContextTypeClangType,
377 // clang_uint32_type);
378 argument_values.PushValue(input_value);
379 argument_values.PushValue(input_value);
380 input_value.SetCompilerType(clang_void_ptr_type);
381 // input_value.SetContext (Value::eContextTypeClangType,
382 // clang_void_ptr_type);
383 argument_values.PushValue(input_value);
384
385 if (abi->GetArgumentValues(exe_ctx.GetThreadRef(), argument_values)) {
386 uint32_t dyld_mode =
387 argument_values.GetValueAtIndex(0)->GetScalar().UInt(-1);
388 if (dyld_mode != static_cast<uint32_t>(-1)) {
389 // Okay the mode was right, now get the number of elements, and the
390 // array of new elements...
391 uint32_t image_infos_count =
392 argument_values.GetValueAtIndex(1)->GetScalar().UInt(-1);
393 if (image_infos_count != static_cast<uint32_t>(-1)) {
394 // Got the number added, now go through the array of added elements,
395 // putting out the mach header address, and adding the image. Note,
396 // I'm not putting in logging here, since the AddModules &
397 // RemoveModules functions do all the logging internally.
398
399 lldb::addr_t image_infos_addr =
400 argument_values.GetValueAtIndex(2)->GetScalar().ULongLong();
401 if (dyld_mode == 0) {
402 // This is add:
403 dyld_instance->AddModulesUsingImageInfosAddress(image_infos_addr,
404 image_infos_count);
405 } else {
406 // This is remove:
408 image_infos_addr, image_infos_count);
409 }
410 }
411 }
412 }
413 } else {
414 Target &target = process->GetTarget();
416 "no ABI plugin located for triple " +
417 target.GetArchitecture().GetTriple().getTriple() +
418 ": shared libraries will not be registered",
419 target.GetDebugger().GetID());
420 }
421
422 // Return true to stop the target, false to just let the target run
423 return dyld_instance->GetStopWhenImagesChange();
424}
425
427 std::lock_guard<std::recursive_mutex> guard(m_mutex);
428
429 // the all image infos is already valid for this process stop ID
431 return true;
432
435 ByteOrder byte_order =
437 uint32_t addr_size =
439
440 uint8_t buf[256];
441 DataExtractor data(buf, sizeof(buf), byte_order, addr_size);
442 lldb::offset_t offset = 0;
443
444 const size_t count_v2 = sizeof(uint32_t) + // version
445 sizeof(uint32_t) + // infoArrayCount
446 addr_size + // infoArray
447 addr_size + // notification
448 addr_size + // processDetachedFromSharedRegion +
449 // libSystemInitialized + pad
450 addr_size; // dyldImageLoadAddress
451 const size_t count_v11 = count_v2 + addr_size + // jitInfo
452 addr_size + // dyldVersion
453 addr_size + // errorMessage
454 addr_size + // terminationFlags
455 addr_size + // coreSymbolicationShmPage
456 addr_size + // systemOrderFlag
457 addr_size + // uuidArrayCount
458 addr_size + // uuidArray
459 addr_size + // dyldAllImageInfosAddress
460 addr_size + // initialImageCount
461 addr_size + // errorKind
462 addr_size + // errorClientOfDylibPath
463 addr_size + // errorTargetDylibPath
464 addr_size; // errorSymbol
465 const size_t count_v13 = count_v11 + addr_size + // sharedCacheSlide
466 sizeof(uuid_t); // sharedCacheUUID
467 UNUSED_IF_ASSERT_DISABLED(count_v13);
468 assert(sizeof(buf) >= count_v13);
469
472 4) {
473 m_dyld_all_image_infos.version = data.GetU32(&offset);
474 // If anything in the high byte is set, we probably got the byte order
475 // incorrect (the process might not have it set correctly yet due to
476 // attaching to a program without a specified file).
477 if (m_dyld_all_image_infos.version & 0xff000000) {
478 // We have guessed the wrong byte order. Swap it and try reading the
479 // version again.
480 if (byte_order == eByteOrderLittle)
481 byte_order = eByteOrderBig;
482 else
483 byte_order = eByteOrderLittle;
484
485 data.SetByteOrder(byte_order);
486 offset = 0;
487 m_dyld_all_image_infos.version = data.GetU32(&offset);
488 }
489 } else {
490 return false;
491 }
492
493 const size_t count =
494 (m_dyld_all_image_infos.version >= 11) ? count_v11 : count_v2;
495
496 const size_t bytes_read =
498 if (bytes_read == count) {
499 offset = 0;
500 m_dyld_all_image_infos.version = data.GetU32(&offset);
505 data.GetU8(&offset);
507 // Adjust for padding.
508 offset += addr_size - 2;
511 offset += addr_size * 8;
512 uint64_t dyld_all_image_infos_addr = data.GetAddress(&offset);
513
514 // When we started, we were given the actual address of the
515 // all_image_infos struct (probably via TASK_DYLD_INFO) in memory -
516 // this address is stored in m_dyld_all_image_infos_addr and is the
517 // most accurate address we have.
518
519 // We read the dyld_all_image_infos struct from memory; it contains its
520 // own address. If the address in the struct does not match the actual
521 // address, the dyld we're looking at has been loaded at a different
522 // location (slid) from where it intended to load. The addresses in
523 // the dyld_all_image_infos struct are the original, non-slid
524 // addresses, and need to be adjusted. Most importantly the address of
525 // dyld and the notification address need to be adjusted.
526
527 if (dyld_all_image_infos_addr != m_dyld_all_image_infos_addr) {
528 uint64_t image_infos_offset =
529 dyld_all_image_infos_addr -
531 uint64_t notification_offset =
535 m_dyld_all_image_infos_addr - image_infos_offset;
537 m_dyld_all_image_infos.dyldImageLoadAddress + notification_offset;
538 }
539 }
541 return true;
542 }
543 }
544 return false;
545}
546
548 lldb::addr_t image_infos_addr, uint32_t image_infos_count) {
549 ImageInfo::collection image_infos;
550 Log *log = GetLog(LLDBLog::DynamicLoader);
551 LLDB_LOGF(log, "Adding %d modules.\n", image_infos_count);
552
553 std::lock_guard<std::recursive_mutex> guard(m_mutex);
554 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
556 return true;
557
558 StructuredData::ObjectSP image_infos_json_sp =
560 image_infos_count);
561 if (image_infos_json_sp.get() && image_infos_json_sp->GetAsDictionary() &&
562 image_infos_json_sp->GetAsDictionary()->HasKey("images") &&
563 image_infos_json_sp->GetAsDictionary()
564 ->GetValueForKey("images")
565 ->GetAsArray() &&
566 image_infos_json_sp->GetAsDictionary()
567 ->GetValueForKey("images")
568 ->GetAsArray()
569 ->GetSize() == image_infos_count) {
570 bool return_value = false;
571 if (JSONImageInformationIntoImageInfo(image_infos_json_sp, image_infos)) {
573 return_value = AddModulesUsingImageInfos(image_infos);
574 }
576 return return_value;
577 }
578
579 if (!ReadImageInfos(image_infos_addr, image_infos_count, image_infos))
580 return false;
581
582 UpdateImageInfosHeaderAndLoadCommands(image_infos, image_infos_count, false);
583 bool return_value = AddModulesUsingImageInfos(image_infos);
585 return return_value;
586}
587
589 lldb::addr_t image_infos_addr, uint32_t image_infos_count) {
590 ImageInfo::collection image_infos;
591 Log *log = GetLog(LLDBLog::DynamicLoader);
592
593 std::lock_guard<std::recursive_mutex> guard(m_mutex);
594 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
596 return true;
597
598 // First read in the image_infos for the removed modules, and their headers &
599 // load commands.
600 if (!ReadImageInfos(image_infos_addr, image_infos_count, image_infos)) {
601 if (log)
602 log->PutCString("Failed reading image infos array.");
603 return false;
604 }
605
606 LLDB_LOGF(log, "Removing %d modules.", image_infos_count);
607
608 ModuleList unloaded_module_list;
609 for (uint32_t idx = 0; idx < image_infos.size(); ++idx) {
610 if (log) {
611 LLDB_LOGF(log, "Removing module at address=0x%16.16" PRIx64 ".",
612 image_infos[idx].address);
613 image_infos[idx].PutToLog(log);
614 }
615
616 // Remove this image_infos from the m_all_image_infos. We do the
617 // comparison by address rather than by file spec because we can have many
618 // modules with the same "file spec" in the case that they are modules
619 // loaded from memory.
620 //
621 // Also copy over the uuid from the old entry to the removed entry so we
622 // can use it to lookup the module in the module list.
623
624 bool found = false;
625
626 for (ImageInfo::collection::iterator pos = m_dyld_image_infos.begin();
627 pos != m_dyld_image_infos.end(); pos++) {
628 if (image_infos[idx].address == (*pos).address) {
629 image_infos[idx].uuid = (*pos).uuid;
630
631 // Add the module from this image_info to the "unloaded_module_list".
632 // We'll remove them all at one go later on.
633
634 ModuleSP unload_image_module_sp(
635 FindTargetModuleForImageInfo(image_infos[idx], false, nullptr));
636 if (unload_image_module_sp.get()) {
637 // When we unload, be sure to use the image info from the old list,
638 // since that has sections correctly filled in.
639 UnloadModuleSections(unload_image_module_sp.get(), *pos);
640 unloaded_module_list.AppendIfNeeded(unload_image_module_sp);
641 } else {
642 if (log) {
643 LLDB_LOGF(log, "Could not find module for unloading info entry:");
644 image_infos[idx].PutToLog(log);
645 }
646 }
647
648 // Then remove it from the m_dyld_image_infos:
649
650 m_dyld_image_infos.erase(pos);
651 found = true;
652 break;
653 }
654 }
655
656 if (!found) {
657 if (log) {
658 LLDB_LOGF(log, "Could not find image_info entry for unloading image:");
659 image_infos[idx].PutToLog(log);
660 }
661 }
662 }
663 if (unloaded_module_list.GetSize() > 0) {
664 if (log) {
665 log->PutCString("Unloaded:");
666 unloaded_module_list.LogUUIDAndPaths(
667 log, "DynamicLoaderMacOSXDYLD::ModulesDidUnload");
668 }
669 m_process->GetTarget().GetImages().Remove(unloaded_module_list);
670 }
672 return true;
673}
674
676 lldb::addr_t image_infos_addr, uint32_t image_infos_count,
677 ImageInfo::collection &image_infos) {
678 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
679 const ByteOrder endian = GetByteOrderFromMagic(m_dyld.header.magic);
680 const uint32_t addr_size = m_dyld.GetAddressByteSize();
681
682 image_infos.resize(image_infos_count);
683 const size_t count = image_infos.size() * 3 * addr_size;
684 DataBufferHeap info_data(count, 0);
686 const size_t bytes_read = m_process->ReadMemory(
687 image_infos_addr, info_data.GetBytes(), info_data.GetByteSize(), error);
688 if (bytes_read == count) {
689 lldb::offset_t info_data_offset = 0;
690 DataExtractor info_data_ref(info_data.GetBytes(), info_data.GetByteSize(),
691 endian, addr_size);
692 for (size_t i = 0;
693 i < image_infos.size() && info_data_ref.ValidOffset(info_data_offset);
694 i++) {
695 image_infos[i].address = info_data_ref.GetAddress(&info_data_offset);
696 lldb::addr_t path_addr = info_data_ref.GetAddress(&info_data_offset);
697 info_data_ref.GetAddress(&info_data_offset); // mod_date, unused */
698
699 char raw_path[PATH_MAX];
700 m_process->ReadCStringFromMemory(path_addr, raw_path, sizeof(raw_path),
701 error);
702 // don't resolve the path
703 if (error.Success()) {
704 image_infos[i].file_spec.SetFile(raw_path, FileSpec::Style::native);
705 }
706 }
707 return true;
708 } else {
709 return false;
710 }
711}
712
713// If we have found where the "_dyld_all_image_infos" lives in memory, read the
714// current info from it, and then update all image load addresses (or lack
715// thereof). Only do this if this is the first time we're reading the dyld
716// infos. Return true if we actually read anything, and false otherwise.
718 Log *log = GetLog(LLDBLog::DynamicLoader);
719
720 std::lock_guard<std::recursive_mutex> guard(m_mutex);
721 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
723 m_dyld_image_infos.size() != 0)
724 return false;
725
727 // Nothing to load or unload?
729 return true;
730
732 // DYLD is updating the images now. So we should say we have no images,
733 // and then we'll
734 // figure it out when we hit the added breakpoint.
735 return false;
736 } else {
740 DEBUG_PRINTF("%s", "unable to read all data for all_dylib_infos.");
741 m_dyld_image_infos.clear();
742 }
743 }
744
745 // Now we have one more bit of business. If there is a library left in the
746 // images for our target that doesn't have a load address, then it must be
747 // something that we were expecting to load (for instance we read a load
748 // command for it) but it didn't in fact load - probably because
749 // DYLD_*_PATH pointed to an equivalent version. We don't want it to stay
750 // in the target's module list or it will confuse us, so unload it here.
751 Target &target = m_process->GetTarget();
752 ModuleList not_loaded_modules;
753 for (ModuleSP module_sp : target.GetImages().Modules()) {
754 if (!module_sp->IsLoadedInTarget(&target)) {
755 if (log) {
756 StreamString s;
757 module_sp->GetDescription(s.AsRawOstream());
758 LLDB_LOGF(log, "Unloading pre-run module: %s.", s.GetData());
759 }
760 not_loaded_modules.Append(module_sp);
761 }
762 }
763
764 if (not_loaded_modules.GetSize() != 0) {
765 target.GetImages().Remove(not_loaded_modules);
766 }
767
768 return true;
769 } else
770 return false;
771}
772
773// Read a mach_header at ADDR into HEADER, and also fill in the load command
774// data into LOAD_COMMAND_DATA if it is non-NULL.
775//
776// Returns true if we succeed, false if we fail for any reason.
778 llvm::MachO::mach_header *header,
779 DataExtractor *load_command_data) {
780 DataBufferHeap header_bytes(sizeof(llvm::MachO::mach_header), 0);
782 size_t bytes_read = m_process->ReadMemory(addr, header_bytes.GetBytes(),
783 header_bytes.GetByteSize(), error);
784 if (bytes_read == sizeof(llvm::MachO::mach_header)) {
785 lldb::offset_t offset = 0;
786 ::memset(header, 0, sizeof(llvm::MachO::mach_header));
787
788 // Get the magic byte unswapped so we can figure out what we are dealing
789 // with
790 DataExtractor data(header_bytes.GetBytes(), header_bytes.GetByteSize(),
792 header->magic = data.GetU32(&offset);
793 lldb::addr_t load_cmd_addr = addr;
794 data.SetByteOrder(
796 switch (header->magic) {
797 case llvm::MachO::MH_MAGIC:
798 case llvm::MachO::MH_CIGAM:
799 data.SetAddressByteSize(4);
800 load_cmd_addr += sizeof(llvm::MachO::mach_header);
801 break;
802
803 case llvm::MachO::MH_MAGIC_64:
804 case llvm::MachO::MH_CIGAM_64:
805 data.SetAddressByteSize(8);
806 load_cmd_addr += sizeof(llvm::MachO::mach_header_64);
807 break;
808
809 default:
810 return false;
811 }
812
813 // Read the rest of dyld's mach header
814 if (data.GetU32(&offset, &header->cputype,
815 (sizeof(llvm::MachO::mach_header) / sizeof(uint32_t)) -
816 1)) {
817 if (load_command_data == nullptr)
818 return true; // We were able to read the mach_header and weren't asked
819 // to read the load command bytes
820
821 WritableDataBufferSP load_cmd_data_sp(
822 new DataBufferHeap(header->sizeofcmds, 0));
823
824 size_t load_cmd_bytes_read =
825 m_process->ReadMemory(load_cmd_addr, load_cmd_data_sp->GetBytes(),
826 load_cmd_data_sp->GetByteSize(), error);
827
828 if (load_cmd_bytes_read == header->sizeofcmds) {
829 // Set the load command data and also set the correct endian swap
830 // settings and the correct address size
831 load_command_data->SetData(load_cmd_data_sp, 0, header->sizeofcmds);
832 load_command_data->SetByteOrder(data.GetByteOrder());
833 load_command_data->SetAddressByteSize(data.GetAddressByteSize());
834 return true; // We successfully read the mach_header and the load
835 // command data
836 }
837
838 return false; // We weren't able to read the load command data
839 }
840 }
841 return false; // We failed the read the mach_header
842}
843
844// Parse the load commands for an image
846 ImageInfo &dylib_info,
847 FileSpec *lc_id_dylinker) {
848 lldb::offset_t offset = 0;
849 uint32_t cmd_idx;
850 Segment segment;
851 dylib_info.Clear(true);
852
853 for (cmd_idx = 0; cmd_idx < dylib_info.header.ncmds; cmd_idx++) {
854 // Clear out any load command specific data from DYLIB_INFO since we are
855 // about to read it.
856
857 if (data.ValidOffsetForDataOfSize(offset,
858 sizeof(llvm::MachO::load_command))) {
859 llvm::MachO::load_command load_cmd;
860 lldb::offset_t load_cmd_offset = offset;
861 load_cmd.cmd = data.GetU32(&offset);
862 load_cmd.cmdsize = data.GetU32(&offset);
863 switch (load_cmd.cmd) {
864 case llvm::MachO::LC_SEGMENT: {
866 (const char *)data.GetData(&offset, 16), 16);
867 // We are putting 4 uint32_t values 4 uint64_t values so we have to use
868 // multiple 32 bit gets below.
869 segment.vmaddr = data.GetU32(&offset);
870 segment.vmsize = data.GetU32(&offset);
871 segment.fileoff = data.GetU32(&offset);
872 segment.filesize = data.GetU32(&offset);
873 // Extract maxprot, initprot, nsects and flags all at once
874 data.GetU32(&offset, &segment.maxprot, 4);
875 dylib_info.segments.push_back(segment);
876 } break;
877
878 case llvm::MachO::LC_SEGMENT_64: {
880 (const char *)data.GetData(&offset, 16), 16);
881 // Extract vmaddr, vmsize, fileoff, and filesize all at once
882 data.GetU64(&offset, &segment.vmaddr, 4);
883 // Extract maxprot, initprot, nsects and flags all at once
884 data.GetU32(&offset, &segment.maxprot, 4);
885 dylib_info.segments.push_back(segment);
886 } break;
887
888 case llvm::MachO::LC_ID_DYLINKER:
889 if (lc_id_dylinker) {
890 const lldb::offset_t name_offset =
891 load_cmd_offset + data.GetU32(&offset);
892 const char *path = data.PeekCStr(name_offset);
893 lc_id_dylinker->SetFile(path, FileSpec::Style::native);
894 FileSystem::Instance().Resolve(*lc_id_dylinker);
895 }
896 break;
897
898 case llvm::MachO::LC_UUID:
899 dylib_info.uuid = UUID(data.GetData(&offset, 16), 16);
900 break;
901
902 default:
903 break;
904 }
905 // Set offset to be the beginning of the next load command.
906 offset = load_cmd_offset + load_cmd.cmdsize;
907 }
908 }
909
910 // All sections listed in the dyld image info structure will all either be
911 // fixed up already, or they will all be off by a single slide amount that is
912 // determined by finding the first segment that is at file offset zero which
913 // also has bytes (a file size that is greater than zero) in the object file.
914
915 // Determine the slide amount (if any)
916 const size_t num_sections = dylib_info.segments.size();
917 for (size_t i = 0; i < num_sections; ++i) {
918 // Iterate through the object file sections to find the first section that
919 // starts of file offset zero and that has bytes in the file...
920 if ((dylib_info.segments[i].fileoff == 0 &&
921 dylib_info.segments[i].filesize > 0) ||
922 (dylib_info.segments[i].name == "__TEXT")) {
923 dylib_info.slide = dylib_info.address - dylib_info.segments[i].vmaddr;
924 // We have found the slide amount, so we can exit this for loop.
925 break;
926 }
927 }
928 return cmd_idx;
929}
930
931// Read the mach_header and load commands for each image that the
932// _dyld_all_image_infos structure points to and cache the results.
933
935 ImageInfo::collection &image_infos, uint32_t infos_count,
936 bool update_executable) {
937 uint32_t exe_idx = UINT32_MAX;
938 // Read any UUID values that we can get
939 for (uint32_t i = 0; i < infos_count; i++) {
940 if (!image_infos[i].UUIDValid()) {
941 DataExtractor data; // Load command data
942 if (!ReadMachHeader(image_infos[i].address, &image_infos[i].header,
943 &data))
944 continue;
945
946 ParseLoadCommands(data, image_infos[i], nullptr);
947
948 if (image_infos[i].header.filetype == llvm::MachO::MH_EXECUTE)
949 exe_idx = i;
950 }
951 }
952
953 Target &target = m_process->GetTarget();
954
955 if (exe_idx < image_infos.size()) {
956 const bool can_create = true;
957 ModuleSP exe_module_sp(FindTargetModuleForImageInfo(image_infos[exe_idx],
958 can_create, nullptr));
959
960 if (exe_module_sp) {
961 UpdateImageLoadAddress(exe_module_sp.get(), image_infos[exe_idx]);
962
963 if (exe_module_sp.get() != target.GetExecutableModulePointer()) {
964 // Don't load dependent images since we are in dyld where we will know
965 // and find out about all images that are loaded. Also when setting the
966 // executable module, it will clear the targets module list, and if we
967 // have an in memory dyld module, it will get removed from the list so
968 // we will need to add it back after setting the executable module, so
969 // we first try and see if we already have a weak pointer to the dyld
970 // module, make it into a shared pointer, then add the executable, then
971 // re-add it back to make sure it is always in the list.
972 ModuleSP dyld_module_sp(GetDYLDModule());
973
974 m_process->GetTarget().SetExecutableModule(exe_module_sp,
976
977 if (dyld_module_sp) {
978 if (target.GetImages().AppendIfNeeded(dyld_module_sp)) {
979 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
980
981 // Also add it to the section list.
982 UpdateImageLoadAddress(dyld_module_sp.get(), m_dyld);
983 }
984 }
985 }
986 }
987 }
988}
989
990// Dump the _dyld_all_image_infos members and all current image infos that we
991// have parsed to the file handle provided.
993 if (log == nullptr)
994 return;
995
996 std::lock_guard<std::recursive_mutex> guard(m_mutex);
997 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
998 LLDB_LOGF(log,
999 "dyld_all_image_infos = { version=%d, count=%d, addr=0x%8.8" PRIx64
1000 ", notify=0x%8.8" PRIx64 " }",
1005 size_t i;
1006 const size_t count = m_dyld_image_infos.size();
1007 if (count > 0) {
1008 log->PutCString("Loaded:");
1009 for (i = 0; i < count; i++)
1011 }
1012}
1013
1015 DEBUG_PRINTF("DynamicLoaderMacOSXDYLD::%s() process state = %s\n",
1016 __FUNCTION__, StateAsCString(m_process->GetState()));
1019 Address so_addr;
1020 // Set the notification breakpoint and install a breakpoint callback
1021 // function that will get called each time the breakpoint gets hit. We
1022 // will use this to track when shared libraries get loaded/unloaded.
1023 bool resolved = m_process->GetTarget().ResolveLoadAddress(
1025 if (!resolved) {
1026 ModuleSP dyld_module_sp = GetDYLDModule();
1027 if (dyld_module_sp) {
1028 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
1029
1030 UpdateImageLoadAddress(dyld_module_sp.get(), m_dyld);
1033 }
1034 }
1035
1036 if (resolved) {
1037 Breakpoint *dyld_break =
1038 m_process->GetTarget().CreateBreakpoint(so_addr, true, false).get();
1040 this, true);
1041 dyld_break->SetBreakpointKind("shared-library-event");
1042 m_break_id = dyld_break->GetID();
1043 }
1044 }
1045 }
1047}
1048
1050 Status error;
1051 // In order for us to tell if we can load a shared library we verify that the
1052 // dylib_info_addr isn't zero (which means no shared libraries have been set
1053 // yet, or dyld is currently mucking with the shared library list).
1055 // TODO: also check the _dyld_global_lock_held variable in
1056 // libSystem.B.dylib?
1057 // TODO: check the malloc lock?
1058 // TODO: check the objective C lock?
1060 return error; // Success
1061 }
1062
1063 error.SetErrorString("unsafe to load or unload shared libraries");
1064 return error;
1065}
1066
1068 lldb::addr_t &base_address, UUID &uuid, LazyBool &using_shared_cache,
1069 LazyBool &private_shared_cache) {
1070 base_address = LLDB_INVALID_ADDRESS;
1071 uuid.Clear();
1072 using_shared_cache = eLazyBoolCalculate;
1073 private_shared_cache = eLazyBoolCalculate;
1074
1075 if (m_process) {
1076 addr_t all_image_infos = m_process->GetImageInfoAddress();
1077
1078 // The address returned by GetImageInfoAddress may be the address of dyld
1079 // (don't want) or it may be the address of the dyld_all_image_infos
1080 // structure (want). The first four bytes will be either the version field
1081 // (all_image_infos) or a Mach-O file magic constant. Version 13 and higher
1082 // of dyld_all_image_infos is required to get the sharedCacheUUID field.
1083
1084 Status err;
1085 uint32_t version_or_magic =
1086 m_process->ReadUnsignedIntegerFromMemory(all_image_infos, 4, -1, err);
1087 if (version_or_magic != static_cast<uint32_t>(-1) &&
1088 version_or_magic != llvm::MachO::MH_MAGIC &&
1089 version_or_magic != llvm::MachO::MH_CIGAM &&
1090 version_or_magic != llvm::MachO::MH_MAGIC_64 &&
1091 version_or_magic != llvm::MachO::MH_CIGAM_64 &&
1092 version_or_magic >= 13) {
1093 addr_t sharedCacheUUID_address = LLDB_INVALID_ADDRESS;
1094 int wordsize = m_process->GetAddressByteSize();
1095 if (wordsize == 8) {
1096 sharedCacheUUID_address =
1097 all_image_infos + 160; // sharedCacheUUID <mach-o/dyld_images.h>
1098 }
1099 if (wordsize == 4) {
1100 sharedCacheUUID_address =
1101 all_image_infos + 84; // sharedCacheUUID <mach-o/dyld_images.h>
1102 }
1103 if (sharedCacheUUID_address != LLDB_INVALID_ADDRESS) {
1104 uuid_t shared_cache_uuid;
1105 if (m_process->ReadMemory(sharedCacheUUID_address, shared_cache_uuid,
1106 sizeof(uuid_t), err) == sizeof(uuid_t)) {
1107 uuid = UUID(shared_cache_uuid, 16);
1108 if (uuid.IsValid()) {
1109 using_shared_cache = eLazyBoolYes;
1110 }
1111 }
1112
1113 if (version_or_magic >= 15) {
1114 // The sharedCacheBaseAddress field is the next one in the
1115 // dyld_all_image_infos struct.
1116 addr_t sharedCacheBaseAddr_address = sharedCacheUUID_address + 16;
1117 Status error;
1119 sharedCacheBaseAddr_address, wordsize, LLDB_INVALID_ADDRESS,
1120 error);
1121 if (error.Fail())
1122 base_address = LLDB_INVALID_ADDRESS;
1123 }
1124
1125 return true;
1126 }
1127
1128 //
1129 // add
1130 // NB: sharedCacheBaseAddress is the next field in dyld_all_image_infos
1131 // after
1132 // sharedCacheUUID -- that is, 16 bytes after it, if we wanted to fetch
1133 // it.
1134 }
1135 }
1136 return false;
1137}
1138
1142 return false;
1143}
1144
1149}
1150
1154}
1155
1157 return "Dynamic loader plug-in that watches for shared library loads/unloads "
1158 "in MacOSX user processes.";
1159}
1160
1162 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
1163
1164 switch (m_dyld.header.magic) {
1165 case llvm::MachO::MH_MAGIC:
1166 case llvm::MachO::MH_CIGAM:
1167 return 4;
1168
1169 case llvm::MachO::MH_MAGIC_64:
1170 case llvm::MachO::MH_CIGAM_64:
1171 return 8;
1172
1173 default:
1174 break;
1175 }
1176 return 0;
1177}
1178
1180 switch (magic) {
1181 case llvm::MachO::MH_MAGIC:
1182 case llvm::MachO::MH_MAGIC_64:
1183 return endian::InlHostByteOrder();
1184
1185 case llvm::MachO::MH_CIGAM:
1186 case llvm::MachO::MH_CIGAM_64:
1189 else
1190 return lldb::eByteOrderBig;
1191
1192 default:
1193 break;
1194 }
1196}
unsigned char uuid_t[16]
static llvm::raw_ostream & error(Stream &strm)
#define DEBUG_PRINTF(fmt,...)
#define LLDB_LOGF(log,...)
Definition: Log.h:349
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:31
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)
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:691
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:450
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Definition: ArchSpec.cpp:738
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:683
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:408
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.
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:1549
void UpdateSpecialBinariesFromNewImageInfos(ImageInfo::collection &image_infos)
ImageInfo::collection m_dyld_image_infos
std::recursive_mutex & GetMutex() const
void UpdateDYLDImageInfoFromNewImageInfo(ImageInfo &image_info)
bool AddModulesUsingImageInfos(ImageInfo::collection &image_infos)
bool JSONImageInformationIntoImageInfo(lldb_private::StructuredData::ObjectSP image_details, ImageInfo::collection &image_infos)
bool UpdateImageLoadAddress(lldb_private::Module *module, ImageInfo &info)
lldb::ModuleSP FindTargetModuleForImageInfo(ImageInfo &image_info, bool can_create, bool *did_create_ptr)
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:52
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:134
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:88
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
Definition: Module.cpp:1184
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
Definition: Module.cpp:1035
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:341
ThreadList & GetThreadList()
Definition: Process.h:2213
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:2005
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:1939
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:1353
lldb::StateType GetState()
Get accessor for the current process state.
Definition: Process.cpp:1301
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:2080
virtual lldb::addr_t GetImageInfoAddress()
Get the image information address for the current process.
Definition: Process.cpp:1495
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3404
uint32_t GetStopID() const
Definition: Process.h:1476
const lldb::ABISP & GetABI()
Definition: Process.cpp:1497
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1277
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:44
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:43
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:545
ConstString GetName() const
Definition: Symbol.cpp:552
void ModulesDidLoad(ModuleList &module_list)
Definition: Target.cpp:1690
Module * GetExecutableModulePointer()
Definition: Target.cpp:1436
Debugger & GetDebugger()
Definition: Target.h:1055
bool RemoveBreakpointByID(lldb::break_id_t break_id)
Definition: Target.cpp:1004
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:395
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow)
Definition: Target.cpp:3111
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition: Target.h:972
const ArchSpec & GetArchitecture() const
Definition: Target.h:1014
void SetExecutableModule(lldb::ModuleSP &module_sp, LoadDependentFiles load_dependent_files=eLoadDependentsDefault)
Set the main executable module.
Definition: Target.cpp:1471
uint32_t GetSize(bool can_update=true)
Definition: ThreadList.cpp:83
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
Definition: ThreadList.cpp:91
void Clear()
Definition: UUID.h:62
bool IsValid() const
Definition: UUID.h:69
void PushValue(const Value &value)
Definition: Value.cpp:682
Value * GetValueAtIndex(size_t idx)
Definition: Value.cpp:686
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.
Definition: SBAttachInfo.h:14
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:314
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:310
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
Definition: lldb-forward.h:412
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:438
uint64_t offset_t
Definition: lldb-types.h:83
@ eEncodingUint
unsigned integer
ByteOrder
Byte ordering definitions.
@ eByteOrderInvalid
@ eByteOrderLittle
std::shared_ptr< lldb_private::TypeSystemClang > TypeSystemClangSP
Definition: lldb-forward.h:458
uint64_t user_id_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Section > SectionSP
Definition: lldb-forward.h:406
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
Definition: lldb-forward.h:329
uint64_t addr_t
Definition: lldb-types.h:79
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:365
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