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