LLDB mainline
DynamicLoaderDarwinKernel.cpp
Go to the documentation of this file.
1//===-- DynamicLoaderDarwinKernel.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
12#include "lldb/Core/Debugger.h"
13#include "lldb/Core/Module.h"
16#include "lldb/Core/Progress.h"
17#include "lldb/Core/Section.h"
24#include "lldb/Target/Target.h"
25#include "lldb/Target/Thread.h"
31#include "lldb/Utility/Log.h"
32#include "lldb/Utility/State.h"
33
35
36#include <algorithm>
37#include <memory>
38
39//#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN
40#ifdef ENABLE_DEBUG_PRINTF
41#include <cstdio>
42#define DEBUG_PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__)
43#else
44#define DEBUG_PRINTF(fmt, ...)
45#endif
46
47using namespace lldb;
48using namespace lldb_private;
49
51
52// Progressively greater amounts of scanning we will allow For some targets
53// very early in startup, we can't do any random reads of memory or we can
54// crash the device so a setting is needed that can completely disable the
55// KASLR scans.
56
58 eKASLRScanNone = 0, // No reading into the inferior at all
59 eKASLRScanLowgloAddresses, // Check one word of memory for a possible kernel
60 // addr, then see if a kernel is there
61 eKASLRScanNearPC, // Scan backwards from the current $pc looking for kernel;
62 // checking at 96 locations total
63 eKASLRScanExhaustiveScan // Scan through the entire possible kernel address
64 // range looking for a kernel
65};
66
68 {
70 "none",
71 "Do not read memory looking for a Darwin kernel when attaching.",
72 },
73 {
75 "basic",
76 "Check for the Darwin kernel's load addr in the lowglo page "
77 "(boot-args=debug) only.",
78 },
79 {
81 "fast-scan",
82 "Scan near the pc value on attach to find the Darwin kernel's load "
83 "address.",
84 },
85 {
87 "exhaustive-scan",
88 "Scan through the entire potential address range of Darwin kernel "
89 "(only on 32-bit targets).",
90 },
91};
92
93#define LLDB_PROPERTIES_dynamicloaderdarwinkernel
94#include "DynamicLoaderDarwinKernelProperties.inc"
95
96enum {
97#define LLDB_PROPERTIES_dynamicloaderdarwinkernel
98#include "DynamicLoaderDarwinKernelPropertiesEnum.inc"
99};
100
102public:
103 static llvm::StringRef GetSettingName() {
104 static constexpr llvm::StringLiteral g_setting_name("darwin-kernel");
105 return g_setting_name;
106 }
107
109 m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
110 m_collection_sp->Initialize(g_dynamicloaderdarwinkernel_properties_def);
111 }
112
114
115 bool GetLoadKexts() const {
116 const uint32_t idx = ePropertyLoadKexts;
118 idx,
119 g_dynamicloaderdarwinkernel_properties[idx].default_uint_value != 0);
120 }
121
123 const uint32_t idx = ePropertyScanType;
125 idx,
126 static_cast<KASLRScanType>(
127 g_dynamicloaderdarwinkernel_properties[idx].default_uint_value));
128 }
129};
130
132 static DynamicLoaderDarwinKernelProperties g_settings;
133 return g_settings;
134}
135
136static bool is_kernel(Module *module) {
137 if (!module)
138 return false;
139 ObjectFile *objfile = module->GetObjectFile();
140 if (!objfile)
141 return false;
142 if (objfile->GetType() != ObjectFile::eTypeExecutable)
143 return false;
144 if (objfile->GetStrata() != ObjectFile::eStrataKernel)
145 return false;
146
147 return true;
148}
149
150// Create an instance of this class. This function is filled into the plugin
151// info class that gets handed out by the plugin factory and allows the lldb to
152// instantiate an instance of this class.
154 bool force) {
155 if (!force) {
156 // If the user provided an executable binary and it is not a kernel, this
157 // plugin should not create an instance.
158 Module *exec = process->GetTarget().GetExecutableModulePointer();
159 if (exec && !is_kernel(exec))
160 return nullptr;
161
162 // If the target's architecture does not look like an Apple environment,
163 // this plugin should not create an instance.
164 const llvm::Triple &triple_ref =
165 process->GetTarget().GetArchitecture().GetTriple();
166 switch (triple_ref.getOS()) {
167 case llvm::Triple::Darwin:
168 case llvm::Triple::MacOSX:
169 case llvm::Triple::IOS:
170 case llvm::Triple::TvOS:
171 case llvm::Triple::WatchOS:
172 case llvm::Triple::BridgeOS:
173 case llvm::Triple::DriverKit:
174 case llvm::Triple::XROS:
175 if (triple_ref.getVendor() != llvm::Triple::Apple) {
176 return nullptr;
177 }
178 break;
179 // If we have triple like armv7-unknown-unknown, we should try looking for
180 // a Darwin kernel.
181 case llvm::Triple::UnknownOS:
182 break;
183 default:
184 return nullptr;
185 break;
186 }
187 }
188
189 // At this point if there is an ExecutableModule, it is a kernel and the
190 // Target is some variant of an Apple system. If the Process hasn't provided
191 // the kernel load address, we need to look around in memory to find it.
192 const addr_t kernel_load_address = SearchForDarwinKernel(process);
193 if (CheckForKernelImageAtAddress(kernel_load_address, process).IsValid()) {
194 return new DynamicLoaderDarwinKernel(process, kernel_load_address);
195 }
196 return nullptr;
197}
198
201 addr_t kernel_load_address = process->GetImageInfoAddress();
202 if (kernel_load_address == LLDB_INVALID_ADDRESS)
203 kernel_load_address = SearchForKernelAtSameLoadAddr(process);
204 if (kernel_load_address == LLDB_INVALID_ADDRESS)
205 kernel_load_address = SearchForKernelWithDebugHints(process);
206 if (kernel_load_address == LLDB_INVALID_ADDRESS)
207 kernel_load_address = SearchForKernelNearPC(process);
208 if (kernel_load_address == LLDB_INVALID_ADDRESS)
209 kernel_load_address = SearchForKernelViaExhaustiveSearch(process);
210
211 return kernel_load_address;
212}
213
214// Check if the kernel binary is loaded in memory without a slide. First verify
215// that the ExecutableModule is a kernel before we proceed. Returns the address
216// of the kernel if one was found, else LLDB_INVALID_ADDRESS.
219 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
220
223
224 ObjectFile *exe_objfile = exe_module->GetObjectFile();
225
226 if (!exe_objfile->GetBaseAddress().IsValid())
228
230 exe_objfile->GetBaseAddress().GetFileAddress(), process) ==
231 exe_module->GetUUID())
232 return exe_objfile->GetBaseAddress().GetFileAddress();
233
235}
236
237// If the debug flag is included in the boot-args nvram setting, the kernel's
238// load address will be noted in the lowglo page at a fixed address Returns the
239// address of the kernel if one was found, else LLDB_INVALID_ADDRESS.
242 if (GetGlobalProperties().GetScanType() == eKASLRScanNone)
244
245 Status read_err;
246 addr_t kernel_addresses_64[] = {
247 0xfffffff000002010ULL,
248 0xfffffe0000004010ULL, // newest arm64 devices, large memory support
249 0xfffffff000004010ULL, // newest arm64 devices
250 0xffffff8000004010ULL, // 2014-2015-ish arm64 devices
251 0xffffff8000002010ULL, // oldest arm64 devices
253 addr_t kernel_addresses_32[] = {0xffff0110, // 2016 and earlier armv7 devices
254 0xffff1010, LLDB_INVALID_ADDRESS};
255
256 uint8_t uval[8];
257 if (process->GetAddressByteSize() == 8) {
258 for (size_t i = 0; kernel_addresses_64[i] != LLDB_INVALID_ADDRESS; i++) {
259 if (process->ReadMemoryFromInferior(kernel_addresses_64[i], uval, 8,
260 read_err) == 8) {
261 DataExtractor data(&uval, 8, process->GetByteOrder(),
262 process->GetAddressByteSize());
263 lldb::offset_t offset = 0;
264 uint64_t addr = data.GetU64(&offset);
265 if (CheckForKernelImageAtAddress(addr, process).IsValid()) {
266 return addr;
267 }
268 }
269 }
270 }
271
272 if (process->GetAddressByteSize() == 4) {
273 for (size_t i = 0; kernel_addresses_32[i] != LLDB_INVALID_ADDRESS; i++) {
274 if (process->ReadMemoryFromInferior(kernel_addresses_32[i], uval, 4,
275 read_err) == 4) {
276 DataExtractor data(&uval, 4, process->GetByteOrder(),
277 process->GetAddressByteSize());
278 lldb::offset_t offset = 0;
279 uint32_t addr = data.GetU32(&offset);
280 if (CheckForKernelImageAtAddress(addr, process).IsValid()) {
281 return addr;
282 }
283 }
284 }
285 }
286
288}
289
290// If the kernel is currently executing when lldb attaches, and we don't have a
291// better way of finding the kernel's load address, try searching backwards
292// from the current pc value looking for the kernel's Mach header in memory.
293// Returns the address of the kernel if one was found, else
294// LLDB_INVALID_ADDRESS.
297 if (GetGlobalProperties().GetScanType() == eKASLRScanNone ||
300 }
301
302 ThreadSP thread = process->GetThreadList().GetSelectedThread();
303 if (thread.get() == nullptr)
305 addr_t pc = thread->GetRegisterContext()->GetPC(LLDB_INVALID_ADDRESS);
306
307 int ptrsize = process->GetTarget().GetArchitecture().GetAddressByteSize();
308
309 // The kernel is always loaded in high memory, if the top bit is zero,
310 // this isn't a kernel.
311 if (ptrsize == 8) {
312 if ((pc & (1ULL << 63)) == 0) {
314 }
315 } else {
316 if ((pc & (1ULL << 31)) == 0) {
318 }
319 }
320
323
324 int pagesize = 0x4000; // 16k pages on 64-bit targets
325 if (ptrsize == 4)
326 pagesize = 0x1000; // 4k pages on 32-bit targets
327
328 // The kernel will be loaded on a page boundary.
329 // Round the current pc down to the nearest page boundary.
330 addr_t addr = pc & ~(pagesize - 1ULL);
331
332 // Search backwards for 128 megabytes, or first memory read error.
333 while (pc - addr < 128 * 0x100000) {
334 bool read_error;
335 if (CheckForKernelImageAtAddress(addr, process, &read_error).IsValid())
336 return addr;
337
338 // Stop scanning on the first read error we encounter; we've walked
339 // past this executable block of memory.
340 if (read_error == true)
341 break;
342
343 addr -= pagesize;
344 }
345
347}
348
349// Scan through the valid address range for a kernel binary. This is uselessly
350// slow in 64-bit environments so we don't even try it. This scan is not
351// enabled by default even for 32-bit targets. Returns the address of the
352// kernel if one was found, else LLDB_INVALID_ADDRESS.
354 Process *process) {
355 if (GetGlobalProperties().GetScanType() != eKASLRScanExhaustiveScan) {
357 }
358
359 addr_t kernel_range_low, kernel_range_high;
360 if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 8) {
361 kernel_range_low = 1ULL << 63;
362 kernel_range_high = UINT64_MAX;
363 } else {
364 kernel_range_low = 1ULL << 31;
365 kernel_range_high = UINT32_MAX;
366 }
367
368 // Stepping through memory at one-megabyte resolution looking for a kernel
369 // rarely works (fast enough) with a 64-bit address space -- for now, let's
370 // not even bother. We may be attaching to something which *isn't* a kernel
371 // and we don't want to spin for minutes on-end looking for a kernel.
372 if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 8)
374
375 addr_t addr = kernel_range_low;
376
377 while (addr >= kernel_range_low && addr < kernel_range_high) {
378 // x86_64 kernels are at offset 0
379 if (CheckForKernelImageAtAddress(addr, process).IsValid())
380 return addr;
381 // 32-bit arm kernels are at offset 0x1000 (one 4k page)
382 if (CheckForKernelImageAtAddress(addr + 0x1000, process).IsValid())
383 return addr + 0x1000;
384 // 64-bit arm kernels are at offset 0x4000 (one 16k page)
385 if (CheckForKernelImageAtAddress(addr + 0x4000, process).IsValid())
386 return addr + 0x4000;
387 addr += 0x100000;
388 }
390}
391
392// Read the mach_header struct out of memory and return it.
393// Returns true if the mach_header was successfully read,
394// Returns false if there was a problem reading the header, or it was not
395// a Mach-O header.
396
397bool
398DynamicLoaderDarwinKernel::ReadMachHeader(addr_t addr, Process *process, llvm::MachO::mach_header &header,
399 bool *read_error) {
401 if (read_error)
402 *read_error = false;
403
404 // Read the mach header and see whether it looks like a kernel
405 if (process->ReadMemory(addr, &header, sizeof(header), error) !=
406 sizeof(header)) {
407 if (read_error)
408 *read_error = true;
409 return false;
410 }
411
412 const uint32_t magicks[] = { llvm::MachO::MH_MAGIC_64, llvm::MachO::MH_MAGIC, llvm::MachO::MH_CIGAM, llvm::MachO::MH_CIGAM_64};
413
414 bool found_matching_pattern = false;
415 for (size_t i = 0; i < std::size(magicks); i++)
416 if (::memcmp (&header.magic, &magicks[i], sizeof (uint32_t)) == 0)
417 found_matching_pattern = true;
418
419 if (!found_matching_pattern)
420 return false;
421
422 if (header.magic == llvm::MachO::MH_CIGAM ||
423 header.magic == llvm::MachO::MH_CIGAM_64) {
424 header.magic = llvm::byteswap<uint32_t>(header.magic);
425 header.cputype = llvm::byteswap<uint32_t>(header.cputype);
426 header.cpusubtype = llvm::byteswap<uint32_t>(header.cpusubtype);
427 header.filetype = llvm::byteswap<uint32_t>(header.filetype);
428 header.ncmds = llvm::byteswap<uint32_t>(header.ncmds);
429 header.sizeofcmds = llvm::byteswap<uint32_t>(header.sizeofcmds);
430 header.flags = llvm::byteswap<uint32_t>(header.flags);
431 }
432
433 return true;
434}
435
436// Given an address in memory, look to see if there is a kernel image at that
437// address.
438// Returns a UUID; if a kernel was not found at that address, UUID.IsValid()
439// will be false.
442 Process *process,
443 bool *read_error) {
445 if (addr == LLDB_INVALID_ADDRESS) {
446 if (read_error)
447 *read_error = true;
448 return UUID();
449 }
450
451 LLDB_LOGF(log,
452 "DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress: "
453 "looking for kernel binary at 0x%" PRIx64,
454 addr);
455
456 llvm::MachO::mach_header header;
457
458 if (!ReadMachHeader(addr, process, header, read_error))
459 return UUID();
460
461 // First try a quick test -- read the first 4 bytes and see if there is a
462 // valid Mach-O magic field there
463 // (the first field of the mach_header/mach_header_64 struct).
464 // A kernel is an executable which does not have the dynamic link object flag
465 // set.
466 if (header.filetype == llvm::MachO::MH_EXECUTE &&
467 (header.flags & llvm::MachO::MH_DYLDLINK) == 0) {
468 // Create a full module to get the UUID
469 llvm::Expected<ModuleSP> memory_module_sp_or_err =
470 process->ReadModuleFromMemory(FileSpec("temp_mach_kernel"), addr);
471 if (auto err = memory_module_sp_or_err.takeError()) {
472 LLDB_LOG_ERROR(log, std::move(err),
473 "DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress: "
474 "Failed to read module in memory -- {0}");
475 return UUID();
476 }
477 ModuleSP memory_module_sp = *memory_module_sp_or_err;
478 if (!memory_module_sp.get())
479 return UUID();
480
481 ObjectFile *exe_objfile = memory_module_sp->GetObjectFile();
482 if (exe_objfile == nullptr) {
483 LLDB_LOGF(log,
484 "DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress "
485 "found a binary at 0x%" PRIx64
486 " but could not create an object file from memory",
487 addr);
488 return UUID();
489 }
490
491 if (is_kernel(memory_module_sp.get())) {
492 ArchSpec kernel_arch(eArchTypeMachO, header.cputype, header.cpusubtype);
494 kernel_arch)) {
495 process->GetTarget().SetArchitecture(kernel_arch);
496 }
497 if (log) {
498 std::string uuid_str;
499 if (memory_module_sp->GetUUID().IsValid()) {
500 uuid_str = "with UUID ";
501 uuid_str += memory_module_sp->GetUUID().GetAsString();
502 } else {
503 uuid_str = "and no LC_UUID found in load commands ";
504 }
505 LLDB_LOGF(
506 log,
507 "DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress: "
508 "kernel binary image found at 0x%" PRIx64 " with arch '%s' %s",
509 addr, kernel_arch.GetTriple().str().c_str(), uuid_str.c_str());
510 }
511 return memory_module_sp->GetUUID();
512 }
513 }
514
515 return UUID();
516}
517
518// Constructor
520 lldb::addr_t kernel_addr)
521 : DynamicLoader(process), m_kernel_load_address(kernel_addr), m_kernel(),
526 process->SetCanRunCode(false);
527 PlatformSP platform_sp =
528 process->GetTarget().GetDebugger().GetPlatformList().Create(
530 if (platform_sp.get())
531 process->GetTarget().SetPlatform(platform_sp);
532}
533
534// Destructor
536
541
542/// We've attached to a remote connection, or read a corefile.
543/// Now load the kernel binary and potentially the kexts, add
544/// them to the Target.
549
550/// Called after attaching a process.
551///
552/// Allow DynamicLoader plug-ins to execute some code after
553/// attaching to a process.
558
559// Clear out the state of this class.
560void DynamicLoaderDarwinKernel::Clear(bool clear_process) {
561 std::lock_guard<std::recursive_mutex> guard(m_mutex);
562
564 m_process->ClearBreakpointSiteByID(m_break_id);
565
566 if (clear_process)
567 m_process = nullptr;
568 m_kernel.Clear();
569 m_known_kexts.clear();
573}
574
576 Process *process) {
577 if (IsLoaded())
578 return true;
579
580 if (m_module_sp) {
581 bool changed = false;
582 if (m_module_sp->SetLoadAddress(process->GetTarget(), 0, true, changed))
584 }
585 return false;
586}
587
589 m_module_sp = module_sp;
590 m_kernel_image = is_kernel(module_sp.get());
591}
592
596
601
605
609
611 m_size = size;
612}
613
617
622
624 const KextImageInfo &rhs) const {
625 if (m_uuid.IsValid() || rhs.GetUUID().IsValid()) {
626 return m_uuid == rhs.GetUUID();
627 }
628
629 return m_name == rhs.GetName() && m_load_address == rhs.GetLoadAddress();
630}
631
633 m_name = name;
634}
635
637 return m_name;
638}
639
643
647
648// Given the m_load_address from the kext summaries, and a UUID, try to create
649// an in-memory Module at that address. Require that the MemoryModule have a
650// matching UUID and detect if this MemoryModule is a kernel or a kext.
651//
652// Returns true if m_memory_module_sp is now set to a valid Module.
653
655 Process *process) {
656 Log *log = GetLog(LLDBLog::Host);
657 if (m_memory_module_sp.get() != nullptr)
658 return true;
660 return false;
661
662 FileSpec file_spec(m_name.c_str());
663
664 llvm::MachO::mach_header mh;
665 size_t size_to_read = 512;
666 if (ReadMachHeader(m_load_address, process, mh)) {
667 if (mh.magic == llvm::MachO::MH_CIGAM || mh.magic == llvm::MachO::MH_MAGIC)
668 size_to_read = sizeof(llvm::MachO::mach_header) + mh.sizeofcmds;
669 if (mh.magic == llvm::MachO::MH_CIGAM_64 ||
670 mh.magic == llvm::MachO::MH_MAGIC_64)
671 size_to_read = sizeof(llvm::MachO::mach_header_64) + mh.sizeofcmds;
672 }
673
674 llvm::Expected<ModuleSP> memory_module_sp_or_err =
675 process->ReadModuleFromMemory(file_spec, m_load_address, size_to_read);
676 if (auto err = memory_module_sp_or_err.takeError()) {
677 LLDB_LOG_ERROR(log, std::move(err),
678 "KextImageInfo::ReadMemoryModule failed to read module from "
679 "memory: {0}");
680 return false;
681 }
682
683 ModuleSP memory_module_sp = *memory_module_sp_or_err;
684 if (memory_module_sp.get() == nullptr)
685 return false;
686
687 bool this_is_kernel = is_kernel(memory_module_sp.get());
688
689 // If this is a kext, and the kernel specified what UUID we should find at
690 // this load address, require that the memory module have a matching UUID or
691 // something has gone wrong and we should discard it.
692 if (m_uuid.IsValid()) {
693 if (m_uuid != memory_module_sp->GetUUID()) {
694 LLDB_LOGF(log,
695 "KextImageInfo::ReadMemoryModule the kernel said to find "
696 "uuid %s at 0x%" PRIx64
697 " but instead we found uuid %s, throwing it away",
698 m_uuid.GetAsString().c_str(), m_load_address,
699 memory_module_sp->GetUUID().GetAsString().c_str());
700 return false;
701 }
702 }
703
704 // If the in-memory Module has a UUID, let's use that.
705 if (!m_uuid.IsValid() && memory_module_sp->GetUUID().IsValid()) {
706 m_uuid = memory_module_sp->GetUUID();
707 }
708
709 m_memory_module_sp = memory_module_sp;
710 m_kernel_image = this_is_kernel;
711 if (this_is_kernel) {
712 // This is unusual and probably not intended
713 LLDB_LOGF(log, "KextImageInfo::ReadMemoryModule read the kernel binary out "
714 "of memory");
715 if (memory_module_sp->GetArchitecture().IsValid()) {
716 process->GetTarget().SetArchitecture(memory_module_sp->GetArchitecture());
717 }
718 }
719
720 return true;
721}
722
726
730
732 Process *process, Progress *progress) {
734 if (IsLoaded())
735 return true;
736
737 Target &target = process->GetTarget();
738
739 // kexts will have a uuid from the table.
740 // for the kernel, we'll need to read the load commands out of memory to get it.
741 if (m_uuid.IsValid() == false) {
742 if (ReadMemoryModule(process) == false) {
744 LLDB_LOGF(log,
745 "Unable to read '%s' from memory at address 0x%" PRIx64
746 " to get the segment load addresses.",
747 m_name.c_str(), m_load_address);
748 return false;
749 }
750 }
751
752 if (IsKernel() && m_uuid.IsValid()) {
754 s->Printf("Kernel UUID: %s\n", m_uuid.GetAsString().c_str());
755 s->Printf("Load Address: 0x%" PRIx64 "\n", m_load_address);
756
757 // Start of a kernel debug session, we have the UUID of the kernel.
758 // Go through the target's list of modules and if there are any kernel
759 // modules with non-matching UUIDs, remove them. The user may have added
760 // the wrong kernel binary manually and it will only confuse things.
761 ModuleList incorrect_kernels;
762 for (ModuleSP module_sp : target.GetImages().Modules()) {
763 if (is_kernel(module_sp.get()) && module_sp->GetUUID() != m_uuid)
764 incorrect_kernels.Append(module_sp);
765 }
766 target.GetImages().Remove(incorrect_kernels);
767 }
768
769 if (!m_module_sp) {
770 // See if the kext has already been loaded into the target, probably by the
771 // user doing target modules add.
772 const ModuleList &target_images = target.GetImages();
773 m_module_sp = target_images.FindModule(m_uuid);
774
775 StreamString prog_str;
776 // 'mach_kernel' is a fake name we make up to find kernels
777 // that were located by the local filesystem scan.
778 if (GetName() != "mach_kernel")
779 prog_str << GetName() << " ";
780 if (GetUUID().IsValid())
781 prog_str << GetUUID().GetAsString() << " ";
783 prog_str << "at 0x";
784 prog_str.PutHex64(GetLoadAddress());
785 }
786
787 std::unique_ptr<Progress> progress_up;
788 if (progress)
789 progress->Increment(1, prog_str.GetString().str());
790 else {
791 if (IsKernel())
792 progress_up = std::make_unique<Progress>("Loading kernel",
793 prog_str.GetString().str());
794 else
795 progress_up = std::make_unique<Progress>("Loading kext",
796 prog_str.GetString().str());
797 }
798
799 // Search for the kext on the local filesystem via the UUID
800 if (!m_module_sp && m_uuid.IsValid()) {
801 ModuleSpec module_spec;
802 module_spec.SetTarget(target.shared_from_this());
803 module_spec.GetUUID() = m_uuid;
804 module_spec.GetFileSpec() = FileSpec(m_name);
805
806 if (IsKernel()) {
807 // The platform's index has to win over the shared module list.
808 PlatformSP platform_sp(target.GetPlatform());
809 if (platform_sp) {
810 platform_sp->GetSharedModule(module_spec, target, m_module_sp,
811 nullptr, nullptr);
812 }
813
814 // Ask the Target to find this file on the local system, if possible.
815 // This will search in the list of currently-loaded files, look in the
816 // standard search paths on the system, and on a Mac it will try
817 // calling the DebugSymbols framework with the UUID to find the binary
818 // via its search methods.
819 if (!m_module_sp) {
821 target.GetOrCreateModule(module_spec, true /* notify */);
822 }
823 } else {
824 // SymbolLocator asks the platform first, and PlatformDarwinKernel
825 // answers from its kext index, using the bundle ID in the file name.
826 StatisticsMap statistics;
827 ModuleSP shared_module_sp;
828 ModuleList::GetSharedModule(module_spec, shared_module_sp, nullptr,
829 nullptr, /*invoke_locate_callback=*/false,
830 /*invoke_symbol_locators=*/false);
831 if (!shared_module_sp) {
833 request.module_spec = module_spec;
834 request.platform = target.GetPlatform();
835
836 llvm::Expected<SymbolLocator::Result> located =
838 if (located) {
839 module_spec = located->module_spec;
840 module_spec.SetTarget(target.shared_from_this());
841 statistics = std::move(located->statistics);
842 } else {
843 // The caller reports the kexts that failed to load.
844 llvm::consumeError(located.takeError());
845 }
846 }
847
848 // Already searched, so the Target must not search again.
850 target.GetOrCreateModule(module_spec, false /* notify */, nullptr,
851 /*invoke_symbol_locators=*/false);
852 if (m_module_sp)
853 m_module_sp->GetSymbolLocatorStatistics().merge(statistics);
854 }
855
856 // For the kernel, we really do need an on-disk file copy of the binary
857 // to do anything useful. This will force a call to dsymForUUID if it
858 // exists, instead of depending on the DebugSymbols preferences being
859 // set.
860 Status kernel_search_error;
861 if (IsKernel() &&
862 (!m_module_sp || !m_module_sp->GetSymbolFileFileSpec())) {
864 module_spec, kernel_search_error, true)) {
865 if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
866 m_module_sp = std::make_shared<Module>(module_spec.GetFileSpec(),
867 target.GetArchitecture());
868 }
869 }
870 }
871
872 if (IsKernel() && !m_module_sp) {
874 s->Printf("WARNING: Unable to locate kernel binary on the debugger "
875 "system.\n");
876 if (kernel_search_error.Fail() && kernel_search_error.AsCString("") &&
877 kernel_search_error.AsCString("")[0] != '\0') {
878 *s << kernel_search_error.AsCString();
879 }
880 }
881 }
882
883 if (m_module_sp && m_uuid.IsValid() && m_module_sp->GetUUID() == m_uuid &&
884 m_module_sp->GetObjectFile()) {
885 if (ObjectFileMachO *ondisk_objfile_macho =
886 llvm::dyn_cast<ObjectFileMachO>(m_module_sp->GetObjectFile())) {
887 if (!IsKernel() && !ondisk_objfile_macho->IsKext()) {
888 // We have a non-kext, non-kernel binary. If we already have this
889 // loaded in the Target with load addresses, don't re-load it again.
890 ModuleSP existing_module_sp = target.GetImages().FindModule(m_uuid);
891 if (existing_module_sp &&
892 existing_module_sp->IsLoadedInTarget(&target)) {
893 LLDB_LOGF(log,
894 "'%s' with UUID %s is not a kext or kernel, and is "
895 "already registered in target, not loading.",
896 m_name.c_str(), m_uuid.GetAsString().c_str());
897 // It's already loaded, return true.
898 return true;
899 }
900 }
901 }
902 }
903
904 // If we managed to find a module, append it to the target's list of
905 // images. If we also have a memory module, require that they have matching
906 // UUIDs
907 if (m_module_sp) {
908 if (m_uuid.IsValid() && m_module_sp->GetUUID() == m_uuid) {
909 target.GetImages().AppendIfNeeded(m_module_sp, false);
910 }
911 }
912 }
913
914 // If we've found a binary, read the load commands out of memory so we
915 // can set the segment load addresses.
916 if (m_module_sp)
917 ReadMemoryModule (process);
918
919 static ConstString g_section_name_LINKEDIT("__LINKEDIT");
920
922 if (m_module_sp->GetUUID() == m_memory_module_sp->GetUUID()) {
923 ObjectFile *ondisk_object_file = m_module_sp->GetObjectFile();
924 ObjectFile *memory_object_file = m_memory_module_sp->GetObjectFile();
925
926 if (memory_object_file && ondisk_object_file) {
927 // The memory_module for kexts may have an invalid __LINKEDIT seg; skip
928 // it.
929 const bool ignore_linkedit = !IsKernel();
930
931 // Normally a kext will have its segment load commands
932 // (LC_SEGMENT vmaddrs) corrected in memory to have their
933 // actual segment addresses.
934 // Userland proceses have their libraries updated the same way
935 // by dyld. The Mach-O load commands in memory are the canonical
936 // addresses.
937 //
938 // If the kernel gives us a binary where the in-memory segment
939 // vmaddr is incorrect, then this binary was put in memory without
940 // updating its Mach-O load commands. We should assume a static
941 // slide value will be applied to every segment; we don't have the
942 // correct addresses for each individual segment.
943 addr_t fixed_slide = LLDB_INVALID_ADDRESS;
944 if (ObjectFileMachO *memory_objfile_macho =
945 llvm::dyn_cast<ObjectFileMachO>(memory_object_file)) {
946 if (Section *header_sect =
947 memory_objfile_macho->GetMachHeaderSection()) {
948 if (header_sect->GetFileAddress() != m_load_address) {
949 fixed_slide = m_load_address - header_sect->GetFileAddress();
950 LLDB_LOGF(
951 log,
952 "kext %s in-memory LC_SEGMENT vmaddr is not correct, using a "
953 "fixed slide of 0x%" PRIx64,
954 m_name.c_str(), fixed_slide);
955 }
956 }
957 }
958
959 SectionList *ondisk_section_list = ondisk_object_file->GetSectionList();
960 SectionList *memory_section_list = memory_object_file->GetSectionList();
961 if (memory_section_list && ondisk_section_list) {
962 const uint32_t num_ondisk_sections = ondisk_section_list->GetSize();
963 // There may be CTF sections in the memory image so we can't always
964 // just compare the number of sections (which are actually segments
965 // in mach-o parlance)
966 uint32_t sect_idx = 0;
967
968 // Use the memory_module's addresses for each section to set the file
969 // module's load address as appropriate. We don't want to use a
970 // single slide value for the entire kext - different segments may be
971 // slid different amounts by the kext loader.
972
973 uint32_t num_sections_loaded = 0;
974 for (sect_idx = 0; sect_idx < num_ondisk_sections; ++sect_idx) {
975 SectionSP ondisk_section_sp(
976 ondisk_section_list->GetSectionAtIndex(sect_idx));
977 if (ondisk_section_sp) {
978 // Don't ever load __LINKEDIT as it may or may not be actually
979 // mapped into memory and there is no current way to tell. Until
980 // such an ability exists, do not load the __LINKEDIT.
981 if (ignore_linkedit &&
982 ondisk_section_sp->GetName() == g_section_name_LINKEDIT)
983 continue;
984
985 if (fixed_slide != LLDB_INVALID_ADDRESS) {
987 ondisk_section_sp,
988 ondisk_section_sp->GetFileAddress() + fixed_slide);
989 } else {
990 const Section *memory_section =
991 memory_section_list
992 ->FindSectionByName(ondisk_section_sp->GetName())
993 .get();
994 if (memory_section) {
996 ondisk_section_sp, memory_section->GetFileAddress());
997 ++num_sections_loaded;
998 }
999 }
1000 }
1001 }
1002 if (num_sections_loaded > 0)
1003 m_load_process_stop_id = process->GetStopID();
1004 else
1005 m_module_sp.reset(); // No sections were loaded
1006 } else
1007 m_module_sp.reset(); // One or both section lists
1008 } else
1009 m_module_sp.reset(); // One or both object files missing
1010 } else
1011 m_module_sp.reset(); // UUID mismatch
1012 }
1013
1014 bool is_loaded = IsLoaded();
1015
1016 if (is_loaded && m_module_sp && IsKernel()) {
1018 ObjectFile *kernel_object_file = m_module_sp->GetObjectFile();
1019 if (kernel_object_file) {
1020 addr_t file_address =
1021 kernel_object_file->GetBaseAddress().GetFileAddress();
1023 file_address != LLDB_INVALID_ADDRESS) {
1024 s->Printf("Kernel slid 0x%" PRIx64 " in memory.\n",
1025 m_load_address - file_address);
1026 }
1027 }
1028 s->Printf("Loaded kernel file %s\n",
1029 m_module_sp->GetFileSpec().GetPath().c_str());
1030 }
1031
1032 // Notify the target about the module being added;
1033 // set breakpoints, load dSYM scripts, etc. as needed.
1034 if (is_loaded && m_module_sp) {
1035 ModuleList loaded_module_list;
1036 loaded_module_list.Append(m_module_sp);
1037 target.ModulesDidLoad(loaded_module_list);
1038 }
1039
1040 return is_loaded;
1041}
1042
1045 return m_memory_module_sp->GetArchitecture().GetAddressByteSize();
1046 if (m_module_sp)
1047 return m_module_sp->GetArchitecture().GetAddressByteSize();
1048 return 0;
1049}
1050
1053 return m_memory_module_sp->GetArchitecture().GetByteOrder();
1054 if (m_module_sp)
1055 return m_module_sp->GetArchitecture().GetByteOrder();
1056 return endian::InlHostByteOrder();
1057}
1058
1062 return m_memory_module_sp->GetArchitecture();
1063 if (m_module_sp)
1064 return m_module_sp->GetArchitecture();
1065 return lldb_private::ArchSpec();
1066}
1067
1068// Load the kernel module and initialize the "m_kernel" member. Return true
1069// _only_ if the kernel is loaded the first time through (subsequent calls to
1070// this function should return false after the kernel has been already loaded).
1072 if (!m_kext_summary_header_ptr_addr.IsValid()) {
1073 m_kernel.Clear();
1074 ModuleSP module_sp = m_process->GetTarget().GetExecutableModule();
1075 if (is_kernel(module_sp.get())) {
1076 m_kernel.SetModule(module_sp);
1077 m_kernel.SetIsKernel(true);
1078 }
1079
1080 ConstString kernel_name("mach_kernel");
1081 if (m_kernel.GetModule().get() && m_kernel.GetModule()->GetObjectFile() &&
1082 !m_kernel.GetModule()
1083 ->GetObjectFile()
1084 ->GetFileSpec()
1085 .GetFilename()
1086 .empty()) {
1087 kernel_name = ConstString(
1088 m_kernel.GetModule()->GetObjectFile()->GetFileSpec().GetFilename());
1089 }
1090 m_kernel.SetName(kernel_name.AsCString(nullptr));
1091
1092 if (m_kernel.GetLoadAddress() == LLDB_INVALID_ADDRESS) {
1093 m_kernel.SetLoadAddress(m_kernel_load_address);
1094 if (m_kernel.GetLoadAddress() == LLDB_INVALID_ADDRESS &&
1095 m_kernel.GetModule()) {
1096 // We didn't get a hint from the process, so we will try the kernel at
1097 // the address that it exists at in the file if we have one
1098 ObjectFile *kernel_object_file = m_kernel.GetModule()->GetObjectFile();
1099 if (kernel_object_file) {
1100 addr_t load_address =
1101 kernel_object_file->GetBaseAddress().GetLoadAddress(
1102 &m_process->GetTarget());
1103 addr_t file_address =
1104 kernel_object_file->GetBaseAddress().GetFileAddress();
1105 if (load_address != LLDB_INVALID_ADDRESS && load_address != 0) {
1106 m_kernel.SetLoadAddress(load_address);
1107 if (load_address != file_address) {
1108 // Don't accidentally relocate the kernel to the File address --
1109 // the Load address has already been set to its actual in-memory
1110 // address. Mark it as IsLoaded.
1111 m_kernel.SetProcessStopId(m_process->GetStopID());
1112 }
1113 } else {
1114 m_kernel.SetLoadAddress(file_address);
1115 }
1116 }
1117 }
1118 }
1119 if (m_kernel.GetLoadAddress() != LLDB_INVALID_ADDRESS)
1120 if (!m_kernel.LoadImageUsingMemoryModule(m_process))
1121 m_kernel.LoadImageAtFileAddress(m_process);
1122
1123 // The operating system plugin gets loaded and initialized in
1124 // LoadImageUsingMemoryModule when we discover the kernel dSYM. For a core
1125 // file in particular, that's the wrong place to do this, since we haven't
1126 // fixed up the section addresses yet. So let's redo it here.
1128
1129 if (m_kernel.IsLoaded() && m_kernel.GetModule()) {
1130 static ConstString kext_summary_symbol("gLoadedKextSummaries");
1131 static ConstString arm64_T1Sz_value("gT1Sz");
1132 const Symbol *symbol =
1133 m_kernel.GetModule()->FindFirstSymbolWithNameAndType(
1134 kext_summary_symbol, eSymbolTypeAny);
1135 if (symbol) {
1137 // Update all image infos
1139 }
1140 // If the kernel global with the T1Sz setting is available,
1141 // update the target.process.virtual-addressable-bits to be correct.
1142 // NB the xnu kernel always has T0Sz and T1Sz the same value. If
1143 // it wasn't the same, we would need to set
1144 // target.process.virtual-addressable-bits = T0Sz
1145 // target.process.highmem-virtual-addressable-bits = T1Sz
1146 symbol = m_kernel.GetModule()->FindFirstSymbolWithNameAndType(
1147 arm64_T1Sz_value, eSymbolTypeData);
1148 if (symbol) {
1149 const addr_t orig_code_mask = m_process->GetCodeAddressMask();
1150 const addr_t orig_data_mask = m_process->GetDataAddressMask();
1151
1152 m_process->SetCodeAddressMask(0);
1153 m_process->SetDataAddressMask(0);
1154 Status error;
1155 // gT1Sz is 8 bytes. We may run on a stripped kernel binary
1156 // where we can't get the size accurately. Hardcode it.
1157 const size_t sym_bytesize = 8; // size of gT1Sz value
1158 uint64_t sym_value =
1159 m_process->GetTarget().ReadUnsignedIntegerFromMemory(
1160 symbol->GetAddress(), sym_bytesize, 0, error);
1161 if (error.Success()) {
1162 // 64 - T1Sz is the highest bit used for auth.
1163 // The value we pass in to SetVirtualAddressableBits is
1164 // the number of bits used for addressing, so if
1165 // T1Sz is 25, then 64-25 == 39, bits 0..38 are used for
1166 // addressing, bits 39..63 are used for PAC/TBI or whatever.
1167 uint32_t virt_addr_bits = 64 - sym_value;
1168 addr_t mask = AddressableBits::AddressableBitToMask(virt_addr_bits);
1169 m_process->SetCodeAddressMask(mask);
1170 m_process->SetDataAddressMask(mask);
1171 } else {
1172 m_process->SetCodeAddressMask(orig_code_mask);
1173 m_process->SetDataAddressMask(orig_data_mask);
1174 }
1175 }
1176 } else {
1177 m_kernel.Clear();
1178 }
1179 }
1180}
1181
1182// Static callback function that gets called when our DYLD notification
1183// breakpoint gets hit. We update all of our image infos and then let our super
1184// class DynamicLoader class decide if we should stop or not (based on global
1185// preference).
1187 void *baton, StoppointCallbackContext *context, user_id_t break_id,
1188 user_id_t break_loc_id) {
1189 return static_cast<DynamicLoaderDarwinKernel *>(baton)->BreakpointHit(
1190 context, break_id, break_loc_id);
1191}
1192
1194 user_id_t break_id,
1195 user_id_t break_loc_id) {
1197 LLDB_LOGF(log, "DynamicLoaderDarwinKernel::BreakpointHit (...)\n");
1198
1200
1201 if (log)
1202 PutToLog(log);
1203
1204 return GetStopWhenImagesChange();
1205}
1206
1208 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1209
1210 // the all image infos is already valid for this process stop ID
1211
1212 if (m_kext_summary_header_ptr_addr.IsValid()) {
1213 const uint32_t addr_size = m_kernel.GetAddressByteSize();
1214 const ByteOrder byte_order = m_kernel.GetByteOrder();
1215 Status error;
1216 // Read enough bytes for a "OSKextLoadedKextSummaryHeader" structure which
1217 // is currently 4 uint32_t and a pointer.
1218 uint8_t buf[24];
1219 DataExtractor data(buf, sizeof(buf), byte_order, addr_size);
1220 const size_t count = 4 * sizeof(uint32_t) + addr_size;
1221 const bool force_live_memory = true;
1222 if (m_process->GetTarget().ReadPointerFromMemory(
1224 m_kext_summary_header_addr, force_live_memory)) {
1225 // We got a valid address for our kext summary header and make sure it
1226 // isn't NULL
1227 if (m_kext_summary_header_addr.IsValid() &&
1228 m_kext_summary_header_addr.GetFileAddress() != 0) {
1229 const size_t bytes_read = m_process->GetTarget().ReadMemory(
1230 m_kext_summary_header_addr, buf, count, error, force_live_memory);
1231 if (bytes_read == count) {
1232 lldb::offset_t offset = 0;
1233 m_kext_summary_header.version = data.GetU32(&offset);
1234 if (m_kext_summary_header.version > 128) {
1235 lldb::StreamSP s =
1236 m_process->GetTarget().GetDebugger().GetAsyncOutputStream();
1237 s->Printf("WARNING: Unable to read kext summary header, got "
1238 "improbable version number %u\n",
1239 m_kext_summary_header.version);
1240 // If we get an improbably large version number, we're probably
1241 // getting bad memory.
1243 return false;
1244 }
1245 if (m_kext_summary_header.version >= 2) {
1246 m_kext_summary_header.entry_size = data.GetU32(&offset);
1247 if (m_kext_summary_header.entry_size > 4096) {
1248 // If we get an improbably large entry_size, we're probably
1249 // getting bad memory.
1250 lldb::StreamSP s =
1251 m_process->GetTarget().GetDebugger().GetAsyncOutputStream();
1252 s->Printf("WARNING: Unable to read kext summary header, got "
1253 "improbable entry_size %u\n",
1254 m_kext_summary_header.entry_size);
1256 return false;
1257 }
1258 } else {
1259 // Versions less than 2 didn't have an entry size, it was hard
1260 // coded
1261 m_kext_summary_header.entry_size =
1263 }
1264 m_kext_summary_header.entry_count = data.GetU32(&offset);
1265 if (m_kext_summary_header.entry_count > 10000) {
1266 // If we get an improbably large number of kexts, we're probably
1267 // getting bad memory.
1268 lldb::StreamSP s =
1269 m_process->GetTarget().GetDebugger().GetAsyncOutputStream();
1270 s->Printf("WARNING: Unable to read kext summary header, got "
1271 "improbable number of kexts %u\n",
1272 m_kext_summary_header.entry_count);
1274 return false;
1275 }
1276 return true;
1277 }
1278 }
1279 }
1280 }
1282 return false;
1283}
1284
1285// We've either (a) just attached to a new kernel, or (b) the kexts-changed
1286// breakpoint was hit and we need to figure out what kexts have been added or
1287// removed. Read the kext summaries from the inferior kernel memory, compare
1288// them against the m_known_kexts vector and update the m_known_kexts vector as
1289// needed to keep in sync with the inferior.
1290
1292 const Address &kext_summary_addr, uint32_t count) {
1293 KextImageInfo::collection kext_summaries;
1295 LLDB_LOGF(log,
1296 "Kexts-changed breakpoint hit, there are %d kexts currently.\n",
1297 count);
1298
1299 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1300
1301 if (!ReadKextSummaries(kext_summary_addr, count, kext_summaries))
1302 return false;
1303
1304 // read the plugin.dynamic-loader.darwin-kernel.load-kexts setting -- if the
1305 // user requested no kext loading, don't print any messages about kexts &
1306 // don't try to read them.
1307 const bool load_kexts = GetGlobalProperties().GetLoadKexts();
1308
1309 // By default, all kexts we've loaded in the past are marked as "remove" and
1310 // all of the kexts we just found out about from ReadKextSummaries are marked
1311 // as "add".
1312 std::vector<bool> to_be_removed(m_known_kexts.size(), true);
1313 std::vector<bool> to_be_added(count, true);
1314
1315 int number_of_new_kexts_being_added = 0;
1316 int number_of_old_kexts_being_removed = m_known_kexts.size();
1317
1318 const uint32_t new_kexts_size = kext_summaries.size();
1319 const uint32_t old_kexts_size = m_known_kexts.size();
1320
1321 // The m_known_kexts vector may have entries that have been Cleared, or are a
1322 // kernel.
1323 for (uint32_t old_kext = 0; old_kext < old_kexts_size; old_kext++) {
1324 bool ignore = false;
1325 KextImageInfo &image_info = m_known_kexts[old_kext];
1326 if (image_info.IsKernel()) {
1327 ignore = true;
1328 } else if (image_info.GetLoadAddress() == LLDB_INVALID_ADDRESS &&
1329 !image_info.GetModule()) {
1330 ignore = true;
1331 }
1332
1333 if (ignore) {
1334 number_of_old_kexts_being_removed--;
1335 to_be_removed[old_kext] = false;
1336 }
1337 }
1338
1339 // Scan over the list of kexts we just read from the kernel, note those that
1340 // need to be added and those already loaded.
1341 for (uint32_t new_kext = 0; new_kext < new_kexts_size; new_kext++) {
1342 bool add_this_one = true;
1343 for (uint32_t old_kext = 0; old_kext < old_kexts_size; old_kext++) {
1344 if (m_known_kexts[old_kext] == kext_summaries[new_kext]) {
1345 // We already have this kext, don't re-load it.
1346 to_be_added[new_kext] = false;
1347 // This kext is still present, do not remove it.
1348 to_be_removed[old_kext] = false;
1349
1350 number_of_old_kexts_being_removed--;
1351 add_this_one = false;
1352 break;
1353 }
1354 }
1355 // If this "kext" entry is actually an alias for the kernel -- the kext was
1356 // compiled into the kernel or something -- then we don't want to load the
1357 // kernel's text section at a different address. Ignore this kext entry.
1358 if (kext_summaries[new_kext].GetUUID().IsValid() &&
1359 m_kernel.GetUUID().IsValid() &&
1360 kext_summaries[new_kext].GetUUID() == m_kernel.GetUUID()) {
1361 to_be_added[new_kext] = false;
1362 break;
1363 }
1364 if (add_this_one) {
1365 number_of_new_kexts_being_added++;
1366 }
1367 }
1368
1369 if (number_of_new_kexts_being_added == 0 &&
1370 number_of_old_kexts_being_removed == 0)
1371 return true;
1372
1373 lldb::StreamSP s =
1374 m_process->GetTarget().GetDebugger().GetAsyncOutputStream();
1375 if (load_kexts) {
1376 if (number_of_new_kexts_being_added > 0 &&
1377 number_of_old_kexts_being_removed > 0) {
1378 s->Printf("Loading %d kext modules and unloading %d kext modules ",
1379 number_of_new_kexts_being_added,
1380 number_of_old_kexts_being_removed);
1381 } else if (number_of_new_kexts_being_added > 0) {
1382 s->Printf("Loading %d kext modules ", number_of_new_kexts_being_added);
1383 } else if (number_of_old_kexts_being_removed > 0) {
1384 s->Printf("Unloading %d kext modules ",
1385 number_of_old_kexts_being_removed);
1386 }
1387 }
1388
1389 if (load_kexts) {
1390 LLDB_LOGF(log,
1391 "DynamicLoaderDarwinKernel::ParseKextSummaries: %d kexts "
1392 "added, %d kexts removed",
1393 number_of_new_kexts_being_added,
1394 number_of_old_kexts_being_removed);
1395 } else {
1396 LLDB_LOGF(log,
1397 "DynamicLoaderDarwinKernel::ParseKextSummaries kext loading is "
1398 "disabled, else would have %d kexts added, %d kexts removed",
1399 number_of_new_kexts_being_added,
1400 number_of_old_kexts_being_removed);
1401 }
1402
1403 // Build up a list of <kext-name, uuid> for any kexts that fail to load
1404 std::vector<std::pair<std::string, UUID>> kexts_failed_to_load;
1405 if (number_of_new_kexts_being_added > 0) {
1406 ModuleList loaded_module_list;
1407 Progress progress("Loading kext", "", number_of_new_kexts_being_added);
1408
1409 const uint32_t num_of_new_kexts = kext_summaries.size();
1410 for (uint32_t new_kext = 0; new_kext < num_of_new_kexts; new_kext++) {
1411 if (to_be_added[new_kext]) {
1412 KextImageInfo &image_info = kext_summaries[new_kext];
1413 if (load_kexts) {
1414 if (!image_info.LoadImageUsingMemoryModule(m_process, &progress)) {
1415 kexts_failed_to_load.push_back(std::pair<std::string, UUID>(
1416 kext_summaries[new_kext].GetName(),
1417 kext_summaries[new_kext].GetUUID()));
1419 }
1420 }
1421
1422 m_known_kexts.push_back(image_info);
1423
1424 if (image_info.GetModule() &&
1425 m_process->GetStopID() == image_info.GetProcessStopId())
1426 loaded_module_list.AppendIfNeeded(image_info.GetModule());
1427
1428 if (log)
1429 kext_summaries[new_kext].PutToLog(log);
1430 }
1431 }
1432 m_process->GetTarget().ModulesDidLoad(loaded_module_list);
1433 }
1434
1435 if (number_of_old_kexts_being_removed > 0) {
1436 ModuleList loaded_module_list;
1437 const uint32_t num_of_old_kexts = m_known_kexts.size();
1438 for (uint32_t old_kext = 0; old_kext < num_of_old_kexts; old_kext++) {
1439 ModuleList unloaded_module_list;
1440 if (to_be_removed[old_kext]) {
1441 KextImageInfo &image_info = m_known_kexts[old_kext];
1442 // You can't unload the kernel.
1443 if (!image_info.IsKernel()) {
1444 if (image_info.GetModule()) {
1445 unloaded_module_list.AppendIfNeeded(image_info.GetModule());
1446 }
1447 s->Printf(".");
1448 image_info.Clear();
1449 // should pull it out of the KextImageInfos vector but that would
1450 // mutate the list and invalidate the to_be_removed bool vector;
1451 // leaving it in place once Cleared() is relatively harmless.
1452 }
1453 }
1454 m_process->GetTarget().ModulesDidUnload(unloaded_module_list, false);
1455 }
1456 }
1457
1458 if (load_kexts) {
1459 s->Printf(" done.\n");
1460 if (kexts_failed_to_load.size() > 0 && number_of_new_kexts_being_added > 0) {
1461 s->Printf("Failed to load %d of %d kexts:\n",
1462 (int)kexts_failed_to_load.size(),
1463 number_of_new_kexts_being_added);
1464 // print a sorted list of <kext-name, uuid> kexts which failed to load
1465 unsigned longest_name = 0;
1466 std::sort(kexts_failed_to_load.begin(), kexts_failed_to_load.end());
1467 for (const auto &ku : kexts_failed_to_load) {
1468 if (ku.first.size() > longest_name)
1469 longest_name = ku.first.size();
1470 }
1471 for (const auto &ku : kexts_failed_to_load) {
1472 std::string uuid;
1473 if (ku.second.IsValid())
1474 uuid = ku.second.GetAsString();
1475 s->Printf(" %-*s %s\n", longest_name, ku.first.c_str(), uuid.c_str());
1476 }
1477 }
1478 }
1479
1480 return true;
1481}
1482
1484 const Address &kext_summary_addr, uint32_t image_infos_count,
1485 KextImageInfo::collection &image_infos) {
1486 const ByteOrder endian = m_kernel.GetByteOrder();
1487 const uint32_t addr_size = m_kernel.GetAddressByteSize();
1488
1489 image_infos.resize(image_infos_count);
1490 const size_t count = image_infos.size() * m_kext_summary_header.entry_size;
1491 DataBufferHeap data(count, 0);
1492 Status error;
1493
1494 const bool force_live_memory = true;
1495 const size_t bytes_read = m_process->GetTarget().ReadMemory(
1496 kext_summary_addr, data.GetBytes(), data.GetByteSize(), error, force_live_memory);
1497 if (bytes_read == count) {
1498
1499 DataExtractor extractor(data.GetBytes(), data.GetByteSize(), endian,
1500 addr_size);
1501 uint32_t i = 0;
1502 for (uint32_t kext_summary_offset = 0;
1503 i < image_infos.size() &&
1504 extractor.ValidOffsetForDataOfSize(kext_summary_offset,
1505 m_kext_summary_header.entry_size);
1506 ++i, kext_summary_offset += m_kext_summary_header.entry_size) {
1507 lldb::offset_t offset = kext_summary_offset;
1508 const void *name_data =
1509 extractor.GetData(&offset, KERNEL_MODULE_MAX_NAME);
1510 if (name_data == nullptr)
1511 break;
1512 image_infos[i].SetName((const char *)name_data);
1513 UUID uuid(extractor.GetData(&offset, 16), 16);
1514 image_infos[i].SetUUID(uuid);
1515 image_infos[i].SetLoadAddress(extractor.GetU64(&offset));
1516 image_infos[i].SetSize(extractor.GetU64(&offset));
1517 }
1518 if (i < image_infos.size())
1519 image_infos.resize(i);
1520 } else {
1521 image_infos.clear();
1522 }
1523 return image_infos.size();
1524}
1525
1527 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1528
1529 if (ReadKextSummaryHeader()) {
1530 if (m_kext_summary_header.entry_count > 0 &&
1531 m_kext_summary_header_addr.IsValid()) {
1532 Address summary_addr(m_kext_summary_header_addr);
1533 summary_addr.Slide(m_kext_summary_header.GetSize());
1534 if (!ParseKextSummaries(summary_addr,
1535 m_kext_summary_header.entry_count)) {
1536 m_known_kexts.clear();
1537 }
1538 return true;
1539 }
1540 }
1541 return false;
1542}
1543
1544// Dump an image info structure to the file handle provided.
1547 LLDB_LOG(log, "uuid={0} name=\"{1}\" (UNLOADED)", m_uuid.GetAsString(),
1548 m_name);
1549 } else {
1550 LLDB_LOG(log, "addr={0:x+16} size={1:x+16} uuid={2} name=\"{3}\"",
1551 m_load_address, m_size, m_uuid.GetAsString(), m_name);
1552 }
1553}
1554
1555// Dump the _dyld_all_image_infos members and all current image infos that we
1556// have parsed to the file handle provided.
1558 if (log == nullptr)
1559 return;
1560
1561 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1562 LLDB_LOGF(log,
1563 "gLoadedKextSummaries = 0x%16.16" PRIx64
1564 " { version=%u, entry_size=%u, entry_count=%u }",
1565 m_kext_summary_header_addr.GetFileAddress(),
1566 m_kext_summary_header.version, m_kext_summary_header.entry_size,
1567 m_kext_summary_header.entry_count);
1568
1569 size_t i;
1570 const size_t count = m_known_kexts.size();
1571 if (count > 0) {
1572 log->PutCString("Loaded:");
1573 for (i = 0; i < count; i++)
1574 m_known_kexts[i].PutToLog(log);
1575 }
1576}
1577
1579 DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n",
1580 __FUNCTION__, StateAsCString(m_process->GetState()));
1581 Clear(true);
1582 m_process = process;
1583}
1584
1586 if (m_break_id == LLDB_INVALID_BREAK_ID && m_kernel.GetModule() &&
1587 m_process->IsLiveDebugSession()) {
1588 DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n",
1589 __FUNCTION__, StateAsCString(m_process->GetState()));
1590
1591 const bool internal_bp = true;
1592 const bool hardware = false;
1593 const LazyBool skip_prologue = eLazyBoolNo;
1594 FileSpecList module_spec_list;
1595 module_spec_list.Append(m_kernel.GetModule()->GetFileSpec());
1596 Breakpoint *bp =
1597 m_process->GetTarget()
1598 .CreateBreakpoint(&module_spec_list, nullptr,
1599 "OSKextLoadedKextSummariesUpdated",
1600 eFunctionNameTypeFull, eLanguageTypeUnknown, 0,
1601 /*offset_is_insn_count = */ false, skip_prologue,
1602 internal_bp, hardware)
1603 .get();
1604
1606 true);
1607 m_break_id = bp->GetID();
1608 }
1609}
1610
1611// Member function that gets called when the process state changes.
1613 StateType state) {
1614 DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s(%s)\n", __FUNCTION__,
1615 StateAsCString(state));
1616 switch (state) {
1617 case eStateConnected:
1618 case eStateAttaching:
1619 case eStateLaunching:
1620 case eStateInvalid:
1621 case eStateUnloaded:
1622 case eStateExited:
1623 case eStateDetached:
1624 Clear(false);
1625 break;
1626
1627 case eStateStopped:
1629 break;
1630
1631 case eStateRunning:
1632 case eStateStepping:
1633 case eStateCrashed:
1634 case eStateSuspended:
1635 break;
1636 }
1637}
1638
1641 bool stop_others) {
1642 ThreadPlanSP thread_plan_sp;
1643 Log *log = GetLog(LLDBLog::Step);
1644 LLDB_LOGF(log, "Could not find symbol for step through.");
1645 return thread_plan_sp;
1646}
1647
1649 Status error;
1651 "always unsafe to load or unload shared libraries in the darwin kernel");
1652 return error;
1653}
1654
1660
1664
1666 lldb_private::Debugger &debugger) {
1669 const bool is_global_setting = true;
1671 debugger, GetGlobalProperties().GetValueProperties(),
1672 "Properties for the DynamicLoaderDarwinKernel plug-in.",
1673 is_global_setting);
1674 }
1675}
1676
1678 return "Dynamic loader plug-in that watches for shared library loads/unloads "
1679 "in the MacOSX kernel.";
1680}
1681
1684 switch (magic) {
1685 case llvm::MachO::MH_MAGIC:
1686 case llvm::MachO::MH_MAGIC_64:
1687 return endian::InlHostByteOrder();
1688
1689 case llvm::MachO::MH_CIGAM:
1690 case llvm::MachO::MH_CIGAM_64:
1693 else
1694 return lldb::eByteOrderBig;
1695
1696 default:
1697 break;
1698 }
1700}
static llvm::raw_ostream & error(Stream &strm)
static constexpr OptionEnumValueElement g_kaslr_kernel_scan_enum_values[]
@ eKASLRScanLowgloAddresses
#define DEBUG_PRINTF(fmt,...)
static bool is_kernel(Module *module)
static DynamicLoaderDarwinKernelProperties & GetGlobalProperties()
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:375
#define LLDB_LOGF(log,...)
Definition Log.h:389
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:405
#define LLDB_PLUGIN_DEFINE(PluginName)
static llvm::StringRef GetName(XcodeSDK::Type type)
Definition XcodeSDK.cpp:21
~DynamicLoaderDarwinKernelProperties() override=default
bool operator==(const KextImageInfo &rhs) const
bool ReadMemoryModule(lldb_private::Process *process)
void SetUUID(const lldb_private::UUID &uuid)
bool LoadImageUsingMemoryModule(lldb_private::Process *process, lldb_private::Progress *progress=nullptr)
bool LoadImageAtFileAddress(lldb_private::Process *process)
void DidLaunch() override
Called after attaching a process.
lldb_private::Address m_kext_summary_header_ptr_addr
void PrivateProcessStateChanged(lldb_private::Process *process, lldb::StateType state)
lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread, bool stop_others) override
Provides a plan to step through the dynamic loader trampoline for the current state of thread.
static lldb_private::DynamicLoader * CreateInstance(lldb_private::Process *process, bool force)
lldb_private::Address m_kext_summary_header_addr
static void DebuggerInitialize(lldb_private::Debugger &debugger)
static bool ReadMachHeader(lldb::addr_t addr, lldb_private::Process *process, llvm::MachO::mach_header &mh, bool *read_error=nullptr)
void PutToLog(lldb_private::Log *log) const
static lldb::addr_t SearchForKernelViaExhaustiveSearch(lldb_private::Process *process)
static llvm::StringRef GetPluginDescriptionStatic()
lldb_private::Status CanLoadImage() override
Ask if it is ok to try and load or unload an shared library (image).
void DidAttach() override
Called after attaching a process.
static lldb::addr_t SearchForKernelAtSameLoadAddr(lldb_private::Process *process)
static llvm::StringRef GetPluginNameStatic()
OSKextLoadedKextSummaryHeader m_kext_summary_header
void PrivateInitialize(lldb_private::Process *process)
DynamicLoaderDarwinKernel(lldb_private::Process *process, lldb::addr_t kernel_addr)
static lldb_private::UUID CheckForKernelImageAtAddress(lldb::addr_t addr, lldb_private::Process *process, bool *read_error=nullptr)
static bool BreakpointHitCallback(void *baton, lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
static lldb::ByteOrder GetByteOrderFromMagic(uint32_t magic)
bool BreakpointHit(lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
static lldb::addr_t SearchForKernelNearPC(lldb_private::Process *process)
uint32_t ReadKextSummaries(const lldb_private::Address &kext_summary_addr, uint32_t image_infos_count, KextImageInfo::collection &image_infos)
static lldb::addr_t SearchForDarwinKernel(lldb_private::Process *process)
KextImageInfo::collection m_known_kexts
static lldb::addr_t SearchForKernelWithDebugHints(lldb_private::Process *process)
bool ParseKextSummaries(const lldb_private::Address &kext_summary_addr, uint32_t count)
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:303
bool Slide(int64_t offset)
Definition Address.h:446
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:283
bool IsValid() const
Check if the object state is valid.
Definition Address.h:355
static lldb::addr_t AddressableBitToMask(uint32_t addressable_bits)
An architecture specification class.
Definition ArchSpec.h:32
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition ArchSpec.cpp:894
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:547
bool IsCompatibleMatch(const ArchSpec &rhs) const
Shorthand for IsMatch(rhs, CompatibleMatch).
Definition ArchSpec.h:599
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
Definition Breakpoint.h:83
void SetCallback(BreakpointHitCallback callback, void *baton, bool is_synchronous=false)
Set the callback action invoked when the breakpoint is hit.
A uniqued constant string class.
Definition ConstString.h:40
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
A subclass of DataBuffer that stores a data buffer on the heap.
lldb::offset_t GetByteSize() const override
Get the number of bytes in the data buffer.
An data extractor class.
virtual const void * GetData(lldb::offset_t *offset_ptr, lldb::offset_t length) const
Extract length bytes from *offset_ptr.
uint64_t GetU64(lldb::offset_t *offset_ptr) const
Extract a uint64_t value from *offset_ptr.
bool ValidOffsetForDataOfSize(lldb::offset_t offset, lldb::offset_t length) const
Test the availability of length bytes of data from offset.
uint32_t GetU32(lldb::offset_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
A class to manage flag bits.
Definition Debugger.h:101
lldb::StreamUP GetAsyncErrorStream()
lldb::StreamUP GetAsyncOutputStream()
void LoadOperatingSystemPlugin(bool flush)
Process * m_process
The process that this dynamic loader plug-in is tracking.
bool GetStopWhenImagesChange() const
Get whether the process should stop when images change.
DynamicLoader(Process *process)
Construct with a process.
A file collection class.
void Append(const FileSpec &file)
Append a FileSpec object to the list.
A file utility class.
Definition FileSpec.h:56
static FileSystem & Instance()
void PutCString(const char *cstr)
Definition Log.cpp:162
A collection class for Module objects.
Definition ModuleList.h:128
static Status GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr, bool invoke_locate_callback=true, bool invoke_symbol_locators=true)
bool AppendIfNeeded(const lldb::ModuleSP &new_module, bool notify=true)
Append a module to the module list, if it is not already there.
lldb::ModuleSP FindModule(const Module *module_ptr) const
bool Remove(const lldb::ModuleSP &module_sp, bool notify=true)
Remove a module from the module list.
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
ModuleIterable Modules() const
Definition ModuleList.h:574
FileSpec & GetFileSpec()
Definition ModuleSpec.h:58
void SetTarget(lldb::TargetSP target)
Set the target to be used when resolving a module.
Definition ModuleSpec.h:151
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:91
const lldb_private::UUID & GetUUID()
Get a reference to the UUID value contained in this object.
Definition Module.cpp:337
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
Definition Module.cpp:1179
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
@ eTypeExecutable
A normal executable.
Definition ObjectFile.h:55
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
virtual lldb_private::Address GetBaseAddress()
Returns base address of this object file.
Definition ObjectFile.h:468
static llvm::StringRef GetPluginNameStatic()
static bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec, Status &error, bool force_lookup=true, bool copy_executable=true)
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static lldb::OptionValuePropertiesSP GetSettingForDynamicLoaderPlugin(Debugger &debugger, llvm::StringRef setting_name)
static bool CreateSettingForDynamicLoaderPlugin(Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, llvm::StringRef description, bool is_global_property)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A plug-in interface definition class for debugging a process.
Definition Process.h:369
ThreadList & GetThreadList()
Definition Process.h:2370
size_t ReadMemoryFromInferior(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition Process.cpp:2460
virtual size_t ReadMemory(const ProcessAddress &process_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition Process.cpp:2114
lldb::ByteOrder GetByteOrder() const
Definition Process.cpp:3949
llvm::Expected< lldb::ModuleSP > ReadModuleFromMemory(const FileSpec &file_spec, lldb::addr_t header_addr, size_t size_to_read=512)
Creates and populates a module using an in-memory object file.
Definition Process.cpp:2811
virtual lldb::addr_t GetImageInfoAddress()
Get the image information address for the current process.
Definition Process.cpp:1527
void SetCanRunCode(bool can_run_code)
Sets whether executing code in this process is possible.
Definition Process.cpp:2777
uint32_t GetAddressByteSize() const
Definition Process.cpp:3953
uint32_t GetStopID() const
Definition Process.h:1517
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1270
A Progress indicator helper class.
Definition Progress.h:60
void Increment(uint64_t amount=1, std::optional< std::string > updated_detail={})
Increment the progress and send a notification to the installed callback.
Definition Progress.cpp:63
lldb::OptionValuePropertiesSP m_collection_sp
T GetPropertyAtIndexAs(uint32_t idx, T default_value, const ExecutionContext *exe_ctx=nullptr) const
size_t GetSize() const
Definition Section.h:76
lldb::SectionSP FindSectionByName(llvm::StringRef section_name) const
Definition Section.cpp:562
lldb::SectionSP GetSectionAtIndex(size_t idx) const
Definition Section.cpp:555
lldb::addr_t GetFileAddress() const
Definition Section.cpp:194
A class to count time for plugins.
Definition Statistics.h:94
An error handling class.
Definition Status.h:118
static Status FromErrorString(const char *str)
Definition Status.h:141
bool Fail() const
Test for error condition.
Definition Status.cpp:293
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:194
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
llvm::StringRef GetString() const
size_t PutHex64(uint64_t uvalue, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
Definition Stream.cpp:307
static llvm::Expected< Result > Locate(const Request &request, const FileSpecList &search_paths)
Find a binary and, if possible, its symbols.
Address GetAddress() const
Definition Symbol.h:98
FileSpecList GetDebugFileSearchPaths()
Definition Target.cpp:5572
void ModulesDidLoad(ModuleList &module_list)
This call may preload module symbols, and may do so in parallel depending on the following target set...
Definition Target.cpp:1961
Module * GetExecutableModulePointer()
Definition Target.cpp:1650
Debugger & GetDebugger() const
Definition Target.h:1362
lldb::ModuleSP GetOrCreateModule(const ModuleSpec &module_spec, bool notify, Status *error_ptr=nullptr, bool invoke_symbol_locators=true)
Find a binary on the system and return its Module, or return an existing Module that is already in th...
Definition Target.cpp:2470
bool SetArchitecture(const ArchSpec &arch_spec, bool set_platform=false, bool merge=true)
Set the architecture for this target.
Definition Target.cpp:1807
lldb::PlatformSP GetPlatform()
Definition Target.h:2004
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1279
const ArchSpec & GetArchitecture() const
Definition Target.h:1321
void SetPlatform(const lldb::PlatformSP &platform_sp)
Definition Target.h:2006
bool SetSectionLoadAddress(const lldb::SectionSP &section, lldb::addr_t load_addr, bool warn_multiple=false)
Definition Target.cpp:3518
lldb::ThreadSP GetSelectedThread()
Represents UUID's of various sizes.
Definition UUID.h:27
bool IsValid() const
Definition UUID.h:69
uint8_t * GetBytes()
Get a pointer to the data.
Definition DataBuffer.h:108
#define UINT64_MAX
#define LLDB_INVALID_BREAK_ID
#define LLDB_BREAK_ID_IS_VALID(bid)
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
lldb::ByteOrder InlHostByteOrder()
Definition Endian.h:25
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition State.cpp:14
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::Platform > PlatformSP
uint64_t offset_t
Definition lldb-types.h:86
StateType
Process and Thread States.
@ eStateUnloaded
Process is object is valid, but not currently loaded.
@ eStateConnected
Process is connected to remote debug services, but not launched or attached to anything yet.
@ eStateDetached
Process has been detached and can't be examined.
@ eStateStopped
Process or thread is stopped and can be examined.
@ eStateSuspended
Process or thread is in a suspended state as far as the debugger is concerned while other processes o...
@ eStateRunning
Process or thread is running and can't be examined.
@ eStateLaunching
Process is in the process of launching.
@ eStateAttaching
Process is currently trying to attach.
@ eStateExited
Process has exited and can't be examined.
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
@ eStateCrashed
Process or thread has crashed and can be examined.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Stream > StreamSP
ByteOrder
Byte ordering definitions.
uint64_t user_id_t
Definition lldb-types.h:83
std::shared_ptr< lldb_private::Section > SectionSP
uint64_t addr_t
Definition lldb-types.h:80
std::unique_ptr< lldb_private::Stream > StreamUP
std::shared_ptr< lldb_private::Module > ModuleSP
One binary to search for.
lldb::PlatformSP platform
A platform that may know where the binary is.
ModuleSpec module_spec
What to look for.