LLDB mainline
DynamicLoaderFreeBSDKernel.h
Go to the documentation of this file.
1//===-- DynamicLoaderFreeBSDKernel.h -----------------------*- C++ -*-===//
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
9#ifndef LLDB_SOURCE_PLUGINS_DYNAMICLOADER_FREEBSD_KERNEL_DYNAMICLOADERFREEBSDKERNEL_H
10#define LLDB_SOURCE_PLUGINS_DYNAMICLOADER_FREEBSD_KERNEL_DYNAMICLOADERFREEBSDKERNEL_H
11
12#include <mutex>
13#include <string>
14#include <vector>
15
17#include "lldb/Target/Process.h"
19#include "lldb/Utility/UUID.h"
20#include "llvm/BinaryFormat/ELF.h"
21
23public:
25 lldb::addr_t kernel_addr);
26
28
29 // Static Functions
30
31 static void Initialize();
32
33 static void Terminate();
34
35 static llvm::StringRef GetPluginNameStatic() { return "freebsd-kernel"; }
36
37 static llvm::StringRef GetPluginDescriptionStatic();
38
40 CreateInstance(lldb_private::Process *process, bool force);
41
42 static void DebuggerInit(lldb_private::Debugger &debugger);
43
45
46 // Hooks for time point that after attach to some proccess
47 void DidAttach() override;
48
49 void DidLaunch() override;
50
52 bool stop_others) override;
53
55
56 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
57
58protected:
60 public:
63
64 void Clear() {
66 m_name.clear();
67 m_uuid.Clear();
68 m_module_sp.reset();
69 m_memory_module_sp.reset();
71 m_path.clear();
72 }
73
74 void SetLoadAddress(lldb::addr_t load_address) {
75 m_load_address = load_address;
76 }
77
79
80 void SetUUID(const lldb_private::UUID uuid) { m_uuid = uuid; }
81
82 lldb_private::UUID GetUUID() const { return m_uuid; }
83
84 void SetName(const char *name) { m_name = name; }
85
86 std::string GetName() const { return m_name; }
87
88 void SetPath(const char *path) { m_path = path; }
89
90 std::string GetPath() const { return m_path; }
91
92 void SetModule(lldb::ModuleSP module) { m_module_sp = module; }
93
95
97
98 bool IsKernel() const { return m_is_kernel; };
99
100 void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; }
101
102 uint32_t GetStopID() { return m_stop_id; }
103
104 bool IsLoaded() const { return m_stop_id != UINT32_MAX; };
105
107
109
111
112 using collection_type = std::vector<KModImageInfo>;
113
114 private:
119 bool m_is_kernel = false;
120 std::string m_name;
121 std::string m_path;
123 };
124
126
127 void Clear(bool clear_process);
128
129 void Update();
130
131 void LoadKernelModules();
132
133 void ReadAllKmods();
134
135 bool ReadAllKmods(lldb_private::Address linker_files_head_address,
137
138 bool ReadKmodsListHeader();
139
140 bool ParseKmods(lldb_private::Address linker_files_head_address);
141
143
144 static lldb_private::UUID
146 lldb::addr_t address,
147 bool *read_error = nullptr);
148
150
151 static bool ReadELFHeader(lldb_private::Process *process,
152 lldb::addr_t address, llvm::ELF::Elf32_Ehdr &header,
153 bool *read_error = nullptr);
154
161 std::recursive_mutex m_mutex;
162 std::unordered_map<std::string, lldb_private::UUID> m_kld_name_to_uuid;
163
164private:
166
169};
170
171#endif
static bool is_kernel(Module *module)
bool LoadImageUsingFileAddress(lldb_private::Process *process)
bool ReadMemoryModule(lldb_private::Process *process)
bool LoadImageUsingMemoryModule(lldb_private::Process *process)
void SetUUID(const lldb_private::UUID uuid)
void DidAttach() override
Called after attaching a process.
KModImageInfo::collection_type m_linker_files_list
llvm::StringRef GetPluginName() override
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.
const DynamicLoaderFreeBSDKernel & operator=(const DynamicLoaderFreeBSDKernel &)=delete
static lldb::addr_t FindKernelAtLoadAddress(lldb_private::Process *process)
DynamicLoaderFreeBSDKernel(const DynamicLoaderFreeBSDKernel &)=delete
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
A class to manage flag bits.
Definition: Debugger.h:79
A plug-in interface definition class for dynamic loaders.
Definition: DynamicLoader.h:52
A plug-in interface definition class for debugging a process.
Definition: Process.h:341
An error handling class.
Definition: Status.h:44
void Clear()
Definition: UUID.h:62
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
#define UINT32_MAX
Definition: lldb-defines.h:19
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
Definition: lldb-forward.h:441
uint64_t addr_t
Definition: lldb-types.h:79
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:365