LLDB mainline
DynamicLoaderFreeBSDKernel.cpp
Go to the documentation of this file.
1//===-- DynamicLoaderFreeBSDKernel.cpp
2//------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
11#include "lldb/Core/Debugger.h"
12#include "lldb/Core/Module.h"
15#include "lldb/Core/Section.h"
22#include "lldb/Target/Target.h"
23#include "lldb/Target/Thread.h"
28#include "lldb/Utility/Log.h"
29#include "lldb/Utility/State.h"
30
32
34#include <memory>
35#include <mutex>
36
37using namespace lldb;
38using namespace lldb_private;
39
41
47
51
53 return "The Dynamic Loader Plugin For FreeBSD Kernel";
54}
55
56static bool is_kernel(Module *module) {
57 if (!module)
58 return false;
59
60 ObjectFile *objfile = module->GetObjectFile();
61 if (!objfile)
62 return false;
63 if (objfile->GetType() != ObjectFile::eTypeExecutable)
64 return false;
65 if (objfile->GetStrata() != ObjectFile::eStrataUnknown &&
67 return false;
68
69 return true;
70}
71
72static bool is_kmod(Module *module) {
73 if (!module)
74 return false;
75 if (!module->GetObjectFile())
76 return false;
77 ObjectFile *objfile = module->GetObjectFile();
78 if (objfile->GetType() != ObjectFile::eTypeObjectFile &&
80 return false;
81
82 return true;
83}
84
85static bool is_reloc(Module *module) {
86 if (!module)
87 return false;
88 if (!module->GetObjectFile())
89 return false;
90 ObjectFile *objfile = module->GetObjectFile();
91 if (objfile->GetType() != ObjectFile::eTypeObjectFile)
92 return false;
93
94 return true;
95}
96
97// Instantiate Function of the FreeBSD Kernel Dynamic Loader Plugin called when
98// Register the Plugin
101 bool force) {
102 // Check the environment when the plugin is not force loaded
103 Module *exec = process->GetTarget().GetExecutableModulePointer();
104 if (exec && !is_kernel(exec)) {
105 return nullptr;
106 }
107 if (!force) {
108 // Check if the target is kernel
109 const llvm::Triple &triple_ref =
110 process->GetTarget().GetArchitecture().GetTriple();
111 if (!triple_ref.isOSFreeBSD()) {
112 return nullptr;
113 }
114 }
115
116 // At this point we have checked the target is a FreeBSD kernel and all we
117 // have to do is to find the kernel address
118 const addr_t kernel_address = FindFreeBSDKernel(process);
119
120 if (CheckForKernelImageAtAddress(process, kernel_address).IsValid())
121 return new DynamicLoaderFreeBSDKernel(process, kernel_address);
122
123 return nullptr;
124}
125
126addr_t
128 addr_t kernel_addr = process->GetImageInfoAddress();
129 if (kernel_addr == LLDB_INVALID_ADDRESS)
130 kernel_addr = FindKernelAtLoadAddress(process);
131 return kernel_addr;
132}
133
134// Get the kernel address if the kernel is not loaded with a slide
136 lldb_private::Process *process) {
137 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
138
139 if (!is_kernel(exe_module))
141
142 ObjectFile *exe_objfile = exe_module->GetObjectFile();
143
144 if (!exe_objfile->GetBaseAddress().IsValid())
146
148 process, exe_objfile->GetBaseAddress().GetFileAddress())
149 .IsValid())
150 return exe_objfile->GetBaseAddress().GetFileAddress();
151
153}
154
155// Read ELF header from memry and return
157 lldb::addr_t addr,
158 llvm::ELF::Elf32_Ehdr &header,
159 bool *read_error) {
161 if (read_error)
162 *read_error = false;
163
164 if (process->ReadMemory(addr, &header, sizeof(header), error) !=
165 sizeof(header)) {
166 if (read_error)
167 *read_error = true;
168 return false;
169 }
170
171 if (!header.checkMagic())
172 return false;
173
174 return true;
175}
176
177// Check the correctness of Kernel and return UUID
179 Process *process, lldb::addr_t addr, bool *read_error) {
181
182 if (addr == LLDB_INVALID_ADDRESS) {
183 if (read_error)
184 *read_error = true;
185 return UUID();
186 }
187
188 LLDB_LOGF(log,
189 "DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress: "
190 "looking for kernel binary at 0x%" PRIx64,
191 addr);
192
193 llvm::ELF::Elf32_Ehdr header;
194 if (!ReadELFHeader(process, addr, header)) {
195 *read_error = true;
196 return UUID();
197 }
198
199 // Check header type
200 if (header.e_type != llvm::ELF::ET_EXEC)
201 return UUID();
202
203 llvm::Expected<ModuleSP> memory_module_sp_or_err =
204 process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
205 if (auto err = memory_module_sp_or_err.takeError()) {
206 LLDB_LOG_ERROR(log, std::move(err),
207 "DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress: "
208 "Failed to read module in memory -- {0}");
209 *read_error = true;
210 return UUID();
211 }
212
213 ModuleSP memory_module_sp = *memory_module_sp_or_err;
214 if (!memory_module_sp.get()) {
215 *read_error = true;
216 return UUID();
217 }
218
219 ObjectFile *exe_objfile = memory_module_sp->GetObjectFile();
220 if (exe_objfile == nullptr) {
221 LLDB_LOGF(log,
222 "DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress "
223 "found a binary at 0x%" PRIx64
224 " but could not create an object file from memory",
225 addr);
226 return UUID();
227 }
228
229 // In here, I should check is_kernel for memory_module_sp
230 // However, the ReadModuleFromMemory reads wrong section so that this check
231 // will failed
232 ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
233
234 if (!process->GetTarget().GetArchitecture().IsCompatibleMatch(kernel_arch))
235 process->GetTarget().SetArchitecture(kernel_arch);
236
237 std::string uuid_str;
238 if (memory_module_sp->GetUUID().IsValid()) {
239 uuid_str = "with UUID ";
240 uuid_str += memory_module_sp->GetUUID().GetAsString();
241 } else {
242 uuid_str = "and no LC_UUID found in load commands ";
243 }
244 LLDB_LOGF(log,
245 "DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress: "
246 "kernel binary image found at 0x%" PRIx64 " with arch '%s' %s",
247 addr, kernel_arch.GetTriple().str().c_str(), uuid_str.c_str());
248
249 return memory_module_sp->GetUUID();
250}
251
254
263
265
270
271// Create in memory Module at the load address
273 lldb_private::Process *process) {
276 return true;
278 return false;
279
280 FileSpec file_spec(m_name);
281
282 ModuleSP memory_module_sp;
283
284 llvm::ELF::Elf32_Ehdr elf_eheader;
285 size_t size_to_read = 512;
286
287 if (ReadELFHeader(process, m_load_address, elf_eheader)) {
288 if (elf_eheader.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS32) {
289 size_to_read = sizeof(llvm::ELF::Elf32_Ehdr) +
290 elf_eheader.e_phnum * elf_eheader.e_phentsize;
291 } else if (elf_eheader.e_ident[llvm::ELF::EI_CLASS] ==
292 llvm::ELF::ELFCLASS64) {
293 llvm::ELF::Elf64_Ehdr elf_eheader;
295 if (process->ReadMemory(m_load_address, &elf_eheader, sizeof(elf_eheader),
296 error) == sizeof(elf_eheader))
297 size_to_read = sizeof(llvm::ELF::Elf64_Ehdr) +
298 elf_eheader.e_phnum * elf_eheader.e_phentsize;
299 }
300 }
301
302 llvm::Expected<ModuleSP> memory_module_sp_or_err =
303 process->ReadModuleFromMemory(file_spec, m_load_address, size_to_read);
304 if (auto err = memory_module_sp_or_err.takeError()) {
305 LLDB_LOG_ERROR(log, std::move(err),
306 "KextImageInfo::ReadMemoryModule: Failed to read module "
307 "from memory -- {0}");
308 return false;
309 }
310 memory_module_sp = *memory_module_sp_or_err;
311
312 if (!memory_module_sp)
313 return false;
314
315 bool this_is_kernel = is_kernel(memory_module_sp.get());
316
317 if (!m_uuid.IsValid() && memory_module_sp->GetUUID().IsValid())
318 m_uuid = memory_module_sp->GetUUID();
319
320 m_memory_module_sp = memory_module_sp;
321 m_is_kernel = this_is_kernel;
322
323 // The kernel binary is from memory
324 if (this_is_kernel) {
325 LLDB_LOGF(log, "KextImageInfo::ReadMemoryModule read the kernel binary out "
326 "of memory");
327
328 if (memory_module_sp->GetArchitecture().IsValid())
329 process->GetTarget().SetArchitecture(memory_module_sp->GetArchitecture());
330 }
331
332 return true;
333}
334
336 lldb_private::Process *process) {
338
339 if (IsLoaded())
340 return true;
341
342 Target &target = process->GetTarget();
343
344 if (IsKernel() && m_uuid.IsValid()) {
346 s->Printf("Kernel UUID: %s\n", m_uuid.GetAsString().c_str());
347 s->Printf("Load Address: 0x%" PRIx64 "\n", m_load_address);
348 }
349
350 // Test if the module is loaded into the taget,
351 // maybe the module is loaded manually by user by doing target module add
352 // So that we have to create the module manually
353 if (!m_module_sp) {
354 const ModuleList &target_images = target.GetImages();
355 m_module_sp = target_images.FindModule(m_uuid);
356
357 // Search in the file system
358 if (!m_module_sp) {
359 ModuleSpec module_spec(FileSpec(GetPath()), target.GetArchitecture());
360 if (IsKernel()) {
363 true)) {
364 if (FileSystem::Instance().Exists(module_spec.GetFileSpec()))
365 m_module_sp = std::make_shared<Module>(module_spec.GetFileSpec(),
366 target.GetArchitecture());
367 }
368 }
369
370 if (!m_module_sp)
371 m_module_sp = target.GetOrCreateModule(module_spec, true);
372 if (IsKernel() && !m_module_sp) {
373 target.GetDebugger().GetAsyncOutputStream()->Printf(
374 "WARNING: Unable to locate kernel binary on the debugger "
375 "system.\n");
376 }
377 }
378
379 if (m_module_sp) {
380 // If the file is not kernel or kmod, the target should be loaded once and
381 // don't reload again
382 if (!IsKernel() && !is_kmod(m_module_sp.get())) {
383 ModuleSP existing_module_sp = target.GetImages().FindModule(m_uuid);
384 if (existing_module_sp &&
385 existing_module_sp->IsLoadedInTarget(&target)) {
386 LLDB_LOGF(log,
387 "'%s' with UUID %s is not a kmod or kernel, and is "
388 "already registered in target, not loading.",
389 m_name.c_str(), m_uuid.GetAsString().c_str());
390 return true;
391 }
392 }
393 m_uuid = m_module_sp->GetUUID();
394
395 // or append to the images
396 target.GetImages().AppendIfNeeded(m_module_sp, false);
397 }
398 }
399
400 // If this file is relocatable kernel module(x86_64), adjust it's
401 // section(PT_LOAD segment) and return Because the kernel module's load
402 // address is the text section. lldb cannot create full memory module upon
403 // relocatable file So what we do is to set the load address only.
404 if (is_kmod(m_module_sp.get()) && is_reloc(m_module_sp.get())) {
405 m_stop_id = process->GetStopID();
406 bool changed = false;
407 m_module_sp->SetLoadAddress(target, m_load_address, true, changed);
408 return true;
409 }
410
411 if (m_module_sp)
412 ReadMemoryModule(process);
413
414 // Calculate the slides of in memory module
416 m_module_sp.reset();
417 return false;
418 }
419
420 ObjectFile *ondisk_object_file = m_module_sp->GetObjectFile();
421 ObjectFile *memory_object_file = m_memory_module_sp->GetObjectFile();
422
423 if (!ondisk_object_file || !memory_object_file)
424 m_module_sp.reset();
425
426 // Find the slide address
427 addr_t fixed_slide = LLDB_INVALID_ADDRESS;
428 if (llvm::dyn_cast<ObjectFileELF>(memory_object_file)) {
429 addr_t load_address = memory_object_file->GetBaseAddress().GetFileAddress();
430
431 if (load_address != LLDB_INVALID_ADDRESS &&
432 m_load_address != load_address) {
433 fixed_slide = m_load_address - load_address;
434 LLDB_LOGF(log,
435 "kmod %s in-memory LOAD vmaddr is not correct, using a "
436 "fixed slide of 0x%" PRIx64,
437 m_name.c_str(), fixed_slide);
438 }
439 }
440
441 SectionList *ondisk_section_list = ondisk_object_file->GetSectionList();
442 SectionList *memory_section_list = memory_object_file->GetSectionList();
443
444 if (memory_section_list && ondisk_object_file) {
445 const uint32_t num_ondisk_sections = ondisk_section_list->GetSize();
446 uint32_t num_load_sections = 0;
447
448 for (uint32_t section_idx = 0; section_idx < num_ondisk_sections;
449 ++section_idx) {
450 SectionSP on_disk_section_sp =
451 ondisk_section_list->GetSectionAtIndex(section_idx);
452
453 if (!on_disk_section_sp)
454 continue;
455 if (fixed_slide != LLDB_INVALID_ADDRESS) {
456 target.SetSectionLoadAddress(on_disk_section_sp,
457 on_disk_section_sp->GetFileAddress() +
458 fixed_slide);
459
460 } else {
461 const Section *memory_section =
462 memory_section_list
463 ->FindSectionByName(on_disk_section_sp->GetName())
464 .get();
465 if (memory_section) {
466 target.SetSectionLoadAddress(on_disk_section_sp,
467 memory_section->GetFileAddress());
468 ++num_load_sections;
469 }
470 }
471 }
472
473 if (num_load_sections)
474 m_stop_id = process->GetStopID();
475 else
476 m_module_sp.reset();
477 } else {
478 m_module_sp.reset();
479 }
480
481 if (IsLoaded() && m_module_sp && IsKernel()) {
483 ObjectFile *kernel_object_file = m_module_sp->GetObjectFile();
484 if (kernel_object_file) {
485 addr_t file_address =
486 kernel_object_file->GetBaseAddress().GetFileAddress();
488 file_address != LLDB_INVALID_ADDRESS) {
489 s->Printf("Kernel slide 0x%" PRIx64 " in memory.\n",
490 m_load_address - file_address);
491 s->Printf("Loaded kernel file %s\n",
492 m_module_sp->GetFileSpec().GetPath().c_str());
493 }
494 }
495 }
496
497 return IsLoaded();
498}
499
500// This function is work for kernel file, others it wil reset load address and
501// return false
503 lldb_private::Process *process) {
504 if (IsLoaded())
505 return true;
506
507 if (m_module_sp) {
508 bool changed = false;
509 if (m_module_sp->SetLoadAddress(process->GetTarget(), 0, true, changed))
510 m_stop_id = process->GetStopID();
511 }
512
513 return false;
514}
515
516// Get the head of found_list
518 std::lock_guard<decltype(m_mutex)> guard(m_mutex);
519
520 if (m_linker_file_list_struct_addr.IsValid()) {
521 // Get tqh_first struct element from linker_files
523 addr_t address = m_process->ReadPointerFromMemory(
524 m_linker_file_list_struct_addr.GetLoadAddress(&m_process->GetTarget()),
525 error);
526 if (address != LLDB_INVALID_ADDRESS && error.Success()) {
528 } else {
530 return false;
531 }
532
533 if (!m_linker_file_head_addr.IsValid() ||
534 m_linker_file_head_addr.GetFileAddress() == 0) {
536 return false;
537 }
538 }
539 return true;
540}
541
542// Parse Kmod info in found_list
544 std::lock_guard<decltype(m_mutex)> guard(m_mutex);
545 KModImageInfo::collection_type linker_files_list;
547
548 if (!ReadAllKmods(linker_files_head_addr, linker_files_list))
549 return false;
550 LLDB_LOGF(
551 log,
552 "Kmod-changed breakpoint hit, there are %zu kernel modules currently.\n",
553 linker_files_list.size());
554
555 ModuleList &modules = m_process->GetTarget().GetImages();
556 ModuleList remove_modules;
557 ModuleList add_modules;
558
559 for (ModuleSP module : modules.Modules()) {
560 if (is_kernel(module.get()))
561 continue;
562 if (is_kmod(module.get()))
563 remove_modules.AppendIfNeeded(module);
564 }
565
566 m_process->GetTarget().ModulesDidUnload(remove_modules, false);
567
568 for (KModImageInfo &image_info : linker_files_list) {
569 auto it = m_kld_name_to_uuid.find(image_info.GetName());
570 if (it != m_kld_name_to_uuid.end())
571 image_info.SetUUID(it->second);
572 bool failed_to_load = false;
573 if (!image_info.LoadImageUsingMemoryModule(m_process)) {
574 image_info.LoadImageUsingFileAddress(m_process);
575 failed_to_load = true;
576 } else {
577 m_linker_files_list.push_back(image_info);
578 m_kld_name_to_uuid[image_info.GetName()] = image_info.GetUUID();
579 }
580
581 if (!failed_to_load)
582 add_modules.AppendIfNeeded(image_info.GetModule());
583 }
584 m_process->GetTarget().ModulesDidLoad(add_modules);
585 return true;
586}
587
588// Read all kmod from a given arrays of list
590 Address linker_files_head_addr,
591 KModImageInfo::collection_type &kmods_list) {
592
593 // Get offset of next member and load address symbol
594 static ConstString kld_off_address_symbol_name("kld_off_address");
595 static ConstString kld_off_next_symbol_name("kld_off_next");
596 static ConstString kld_off_filename_symbol_name("kld_off_filename");
597 static ConstString kld_off_pathname_symbol_name("kld_off_pathname");
598 const Symbol *kld_off_address_symbol =
599 m_kernel_image_info.GetModule()->FindFirstSymbolWithNameAndType(
600 kld_off_address_symbol_name, eSymbolTypeData);
601 const Symbol *kld_off_next_symbol =
602 m_kernel_image_info.GetModule()->FindFirstSymbolWithNameAndType(
603 kld_off_next_symbol_name, eSymbolTypeData);
604 const Symbol *kld_off_filename_symbol =
605 m_kernel_image_info.GetModule()->FindFirstSymbolWithNameAndType(
606 kld_off_filename_symbol_name, eSymbolTypeData);
607 const Symbol *kld_off_pathname_symbol =
608 m_kernel_image_info.GetModule()->FindFirstSymbolWithNameAndType(
609 kld_off_pathname_symbol_name, eSymbolTypeData);
610
611 if (!kld_off_address_symbol || !kld_off_next_symbol ||
612 !kld_off_filename_symbol || !kld_off_pathname_symbol)
613 return false;
614
616 const int32_t kld_off_address = m_process->ReadSignedIntegerFromMemory(
617 kld_off_address_symbol->GetAddress().GetLoadAddress(
618 &m_process->GetTarget()),
619 4, 0, error);
620 if (error.Fail())
621 return false;
622 const int32_t kld_off_next = m_process->ReadSignedIntegerFromMemory(
623 kld_off_next_symbol->GetAddress().GetLoadAddress(&m_process->GetTarget()),
624 4, 0, error);
625 if (error.Fail())
626 return false;
627 const int32_t kld_off_filename = m_process->ReadSignedIntegerFromMemory(
628 kld_off_filename_symbol->GetAddress().GetLoadAddress(
629 &m_process->GetTarget()),
630 4, 0, error);
631 if (error.Fail())
632 return false;
633
634 const int32_t kld_off_pathname = m_process->ReadSignedIntegerFromMemory(
635 kld_off_pathname_symbol->GetAddress().GetLoadAddress(
636 &m_process->GetTarget()),
637 4, 0, error);
638 if (error.Fail())
639 return false;
640
641 // Parse KMods
642 addr_t kld_load_addr(LLDB_INVALID_ADDRESS);
643 char kld_filename[255];
644 char kld_pathname[255];
645 addr_t current_kld =
646 linker_files_head_addr.GetLoadAddress(&m_process->GetTarget());
647
648 while (current_kld != 0) {
649 addr_t kld_filename_addr =
650 m_process->ReadPointerFromMemory(current_kld + kld_off_filename, error);
651 if (error.Fail())
652 return false;
653 addr_t kld_pathname_addr =
654 m_process->ReadPointerFromMemory(current_kld + kld_off_pathname, error);
655 if (error.Fail())
656 return false;
657
658 m_process->ReadCStringFromMemory(kld_filename_addr, kld_filename,
659 sizeof(kld_filename), error);
660 if (error.Fail())
661 return false;
662 m_process->ReadCStringFromMemory(kld_pathname_addr, kld_pathname,
663 sizeof(kld_pathname), error);
664 if (error.Fail())
665 return false;
666 kld_load_addr =
667 m_process->ReadPointerFromMemory(current_kld + kld_off_address, error);
668 if (error.Fail())
669 return false;
670
671 kmods_list.emplace_back();
672 KModImageInfo &kmod_info = kmods_list.back();
673 kmod_info.SetName(kld_filename);
674 kmod_info.SetLoadAddress(kld_load_addr);
675 kmod_info.SetPath(kld_pathname);
676
677 current_kld =
678 m_process->ReadPointerFromMemory(current_kld + kld_off_next, error);
679 if (kmod_info.GetName() == "kernel")
680 kmods_list.pop_back();
681 if (error.Fail())
682 return false;
683 }
684
685 return true;
686}
687
688// Read all kmods
690 std::lock_guard<decltype(m_mutex)> guard(m_mutex);
691
692 if (ReadKmodsListHeader()) {
693 if (m_linker_file_head_addr.IsValid()) {
695 m_linker_files_list.clear();
696 }
697 }
698}
699
700// Load all Kernel Modules
703 LLDB_LOGF(log, "DynamicLoaderFreeBSDKernel::LoadKernelModules "
704 "Start loading Kernel Module");
705
706 // Initialize Kernel Image Information at the first time
707 if (m_kernel_image_info.GetLoadAddress() == LLDB_INVALID_ADDRESS) {
708 ModuleSP module_sp = m_process->GetTarget().GetExecutableModule();
709 if (is_kernel(module_sp.get())) {
710 m_kernel_image_info.SetModule(module_sp);
711 m_kernel_image_info.SetIsKernel(true);
712 }
713
714 // Set name for kernel
715 llvm::StringRef kernel_name("freebsd_kernel");
716 module_sp = m_kernel_image_info.GetModule();
717 if (module_sp.get() && module_sp->GetObjectFile() &&
718 !module_sp->GetObjectFile()->GetFileSpec().GetFilename().IsEmpty())
719 kernel_name = module_sp->GetObjectFile()
720 ->GetFileSpec()
721 .GetFilename()
722 .GetStringRef();
723 m_kernel_image_info.SetName(kernel_name.data());
724
725 if (m_kernel_image_info.GetLoadAddress() == LLDB_INVALID_ADDRESS) {
727 }
728
729 // Build In memory Module
730 if (m_kernel_image_info.GetLoadAddress() != LLDB_INVALID_ADDRESS) {
731 // If the kernel is not loaded in the memory, use file to load
732 if (!m_kernel_image_info.LoadImageUsingMemoryModule(m_process))
733 m_kernel_image_info.LoadImageUsingFileAddress(m_process);
734 }
735 }
736
738
739 if (!m_kernel_image_info.IsLoaded() || !m_kernel_image_info.GetModule()) {
740 m_kernel_image_info.Clear();
741 return;
742 }
743
744 static ConstString modlist_symbol_name("linker_files");
745
746 const Symbol *symbol =
747 m_kernel_image_info.GetModule()->FindFirstSymbolWithNameAndType(
748 modlist_symbol_name, lldb::eSymbolTypeData);
749
750 if (symbol) {
752 ReadAllKmods();
753 } else {
754 LLDB_LOGF(log, "DynamicLoaderFreeBSDKernel::LoadKernelModules "
755 "cannot file modlist symbol");
756 }
757}
758
759// Update symbol when use kldload by setting callback function on kldload
761
762// Hook called when attach to a process
767
768// Hook called after attach to a process
773
774// Clear all member except kernel address
775void DynamicLoaderFreeBSDKernel::Clear(bool clear_process) {
776 std::lock_guard<decltype(m_mutex)> guard(m_mutex);
777 if (clear_process)
778 m_process = nullptr;
781 m_kernel_image_info.Clear();
782 m_linker_files_list.clear();
783}
784
785// Reinitialize class
787 Clear(true);
788 m_process = process;
789}
790
792 lldb_private::Thread &thread, bool stop_others) {
793 Log *log = GetLog(LLDBLog::Step);
794 LLDB_LOGF(log, "DynamicLoaderFreeBSDKernel::GetStepThroughTrampolinePlan is "
795 "not yet implemented.");
796 return {};
797}
798
800 return Status::FromErrorString("shared object cannot be loaded into kernel");
801}
static llvm::raw_ostream & error(Stream &strm)
static bool is_kernel(Module *module)
static bool is_reloc(Module *module)
static bool is_kernel(Module *module)
static bool is_kmod(Module *module)
#define LLDB_LOGF(log,...)
Definition Log.h:376
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:392
#define LLDB_PLUGIN_DEFINE(PluginName)
bool LoadImageUsingFileAddress(lldb_private::Process *process)
bool ReadMemoryModule(lldb_private::Process *process)
bool LoadImageUsingMemoryModule(lldb_private::Process *process)
void DidAttach() override
Called after attaching a process.
DynamicLoaderFreeBSDKernel(lldb_private::Process *process, lldb::addr_t kernel_addr)
KModImageInfo::collection_type m_linker_files_list
static llvm::StringRef GetPluginNameStatic()
lldb_private::Address m_linker_file_list_struct_addr
void PrivateInitialize(lldb_private::Process *process)
lldb_private::Address m_linker_file_head_addr
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.
bool ParseKmods(lldb_private::Address linker_files_head_address)
static void DebuggerInit(lldb_private::Debugger &debugger)
static lldb::addr_t FindFreeBSDKernel(lldb_private::Process *process)
lldb_private::Status CanLoadImage() override
Ask if it is ok to try and load or unload an shared library (image).
std::unordered_map< std::string, lldb_private::UUID > m_kld_name_to_uuid
void DidLaunch() override
Called after launching a process.
static lldb::addr_t FindKernelAtLoadAddress(lldb_private::Process *process)
static llvm::StringRef GetPluginDescriptionStatic()
static lldb_private::UUID CheckForKernelImageAtAddress(lldb_private::Process *process, lldb::addr_t address, bool *read_error=nullptr)
static lldb_private::DynamicLoader * CreateInstance(lldb_private::Process *process, bool force)
static bool ReadELFHeader(lldb_private::Process *process, lldb::addr_t address, llvm::ELF::Elf32_Ehdr &header, bool *read_error=nullptr)
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:301
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:281
bool IsValid() const
Check if the object state is valid.
Definition Address.h:355
An architecture specification class.
Definition ArchSpec.h:32
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:457
bool IsCompatibleMatch(const ArchSpec &rhs) const
Shorthand for IsMatch(rhs, CompatibleMatch).
Definition ArchSpec.h:509
A uniqued constant string class.
Definition ConstString.h:40
A class to manage flag bits.
Definition Debugger.h:87
lldb::StreamUP GetAsyncOutputStream()
A plug-in interface definition class for dynamic loaders.
void LoadOperatingSystemPlugin(bool flush)
DynamicLoader(Process *process)
Construct with a process.
A file utility class.
Definition FileSpec.h:57
static FileSystem & Instance()
A collection class for Module objects.
Definition ModuleList.h:125
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
ModuleIterable Modules() const
Definition ModuleList.h:566
FileSpec & GetFileSpec()
Definition ModuleSpec.h:57
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:90
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
Definition Module.cpp:1188
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
@ eTypeExecutable
A normal executable.
Definition ObjectFile.h:55
@ eTypeObjectFile
An intermediate object file.
Definition ObjectFile.h:61
@ eTypeSharedLibrary
A shared library that can be used during execution.
Definition ObjectFile.h:63
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:464
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 bool UnregisterPlugin(ABICreateInstance create_callback)
A plug-in interface definition class for debugging a process.
Definition Process.h:354
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition Process.cpp:1907
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:2599
virtual lldb::addr_t GetImageInfoAddress()
Get the image information address for the current process.
Definition Process.cpp:1455
void SetCanRunCode(bool can_run_code)
Sets whether executing code in this process is possible.
Definition Process.cpp:2566
uint32_t GetStopID() const
Definition Process.h:1455
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1250
lldb::SectionSP FindSectionByName(ConstString section_dstr) const
Definition Section.cpp:560
size_t GetSize() const
Definition Section.h:77
lldb::SectionSP GetSectionAtIndex(size_t idx) const
Definition Section.cpp:553
lldb::addr_t GetFileAddress() const
Definition Section.cpp:194
An error handling class.
Definition Status.h:118
static Status FromErrorString(const char *str)
Definition Status.h:141
Address GetAddress() const
Definition Symbol.h:89
Module * GetExecutableModulePointer()
Definition Target.cpp:1541
Debugger & GetDebugger() const
Definition Target.h:1224
lldb::ModuleSP GetOrCreateModule(const ModuleSpec &module_spec, bool notify, Status *error_ptr=nullptr)
Find a binary on the system and return its Module, or return an existing Module that is already in th...
Definition Target.cpp:2352
bool SetArchitecture(const ArchSpec &arch_spec, bool set_platform=false, bool merge=true)
Set the architecture for this target.
Definition Target.cpp:1705
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1141
const ArchSpec & GetArchitecture() const
Definition Target.h:1183
bool SetSectionLoadAddress(const lldb::SectionSP &section, lldb::addr_t load_addr, bool warn_multiple=false)
Definition Target.cpp:3333
Represents UUID's of various sizes.
Definition UUID.h:27
bool IsValid() const
Definition UUID.h:69
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
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