Path: blob/main/contrib/llvm-project/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.h
39644 views
//===-- DynamicLoaderFreeBSDKernel.h -----------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_DYNAMICLOADER_FREEBSD_KERNEL_DYNAMICLOADERFREEBSDKERNEL_H9#define LLDB_SOURCE_PLUGINS_DYNAMICLOADER_FREEBSD_KERNEL_DYNAMICLOADERFREEBSDKERNEL_H1011#include <mutex>12#include <string>13#include <vector>1415#include "lldb/Target/DynamicLoader.h"16#include "lldb/Target/Process.h"17#include "lldb/Utility/FileSpec.h"18#include "lldb/Utility/UUID.h"19#include "llvm/BinaryFormat/ELF.h"2021class DynamicLoaderFreeBSDKernel : public lldb_private::DynamicLoader {22public:23DynamicLoaderFreeBSDKernel(lldb_private::Process *process,24lldb::addr_t kernel_addr);2526~DynamicLoaderFreeBSDKernel() override;2728// Static Functions2930static void Initialize();3132static void Terminate();3334static llvm::StringRef GetPluginNameStatic() { return "freebsd-kernel"; }3536static llvm::StringRef GetPluginDescriptionStatic();3738static lldb_private::DynamicLoader *39CreateInstance(lldb_private::Process *process, bool force);4041static void DebuggerInit(lldb_private::Debugger &debugger);4243static lldb::addr_t FindFreeBSDKernel(lldb_private::Process *process);4445// Hooks for time point that after attach to some proccess46void DidAttach() override;4748void DidLaunch() override;4950lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread,51bool stop_others) override;5253lldb_private::Status CanLoadImage() override;5455llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }5657protected:58class KModImageInfo {59public:60KModImageInfo()61: m_module_sp(), m_memory_module_sp(), m_uuid(), m_name(), m_path() {}6263void Clear() {64m_load_address = LLDB_INVALID_ADDRESS;65m_name.clear();66m_uuid.Clear();67m_module_sp.reset();68m_memory_module_sp.reset();69m_stop_id = UINT32_MAX;70m_path.clear();71}7273void SetLoadAddress(lldb::addr_t load_address) {74m_load_address = load_address;75}7677lldb::addr_t GetLoadAddress() const { return m_load_address; }7879void SetUUID(const lldb_private::UUID uuid) { m_uuid = uuid; }8081lldb_private::UUID GetUUID() const { return m_uuid; }8283void SetName(const char *name) { m_name = name; }8485std::string GetName() const { return m_name; }8687void SetPath(const char *path) { m_path = path; }8889std::string GetPath() const { return m_path; }9091void SetModule(lldb::ModuleSP module) { m_module_sp = module; }9293lldb::ModuleSP GetModule() { return m_module_sp; }9495void SetIsKernel(bool is_kernel) { m_is_kernel = is_kernel; }9697bool IsKernel() const { return m_is_kernel; };9899void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; }100101uint32_t GetStopID() { return m_stop_id; }102103bool IsLoaded() const { return m_stop_id != UINT32_MAX; };104105bool ReadMemoryModule(lldb_private::Process *process);106107bool LoadImageUsingMemoryModule(lldb_private::Process *process);108109bool LoadImageUsingFileAddress(lldb_private::Process *process);110111using collection_type = std::vector<KModImageInfo>;112113private:114lldb::ModuleSP m_module_sp;115lldb::ModuleSP m_memory_module_sp;116lldb::addr_t m_load_address = LLDB_INVALID_ADDRESS;117lldb_private::UUID m_uuid;118bool m_is_kernel = false;119std::string m_name;120std::string m_path;121uint32_t m_stop_id = UINT32_MAX;122};123124void PrivateInitialize(lldb_private::Process *process);125126void Clear(bool clear_process);127128void Update();129130void LoadKernelModules();131132void ReadAllKmods();133134bool ReadAllKmods(lldb_private::Address linker_files_head_address,135KModImageInfo::collection_type &kmods_list);136137bool ReadKmodsListHeader();138139bool ParseKmods(lldb_private::Address linker_files_head_address);140141void SetNotificationBreakPoint();142143static lldb_private::UUID144CheckForKernelImageAtAddress(lldb_private::Process *process,145lldb::addr_t address,146bool *read_error = nullptr);147148static lldb::addr_t FindKernelAtLoadAddress(lldb_private::Process *process);149150static bool ReadELFHeader(lldb_private::Process *process,151lldb::addr_t address, llvm::ELF::Elf32_Ehdr &header,152bool *read_error = nullptr);153154lldb_private::Process *m_process;155lldb_private::Address m_linker_file_list_struct_addr;156lldb_private::Address m_linker_file_head_addr;157lldb::addr_t m_kernel_load_address;158KModImageInfo m_kernel_image_info;159KModImageInfo::collection_type m_linker_files_list;160std::recursive_mutex m_mutex;161std::unordered_map<std::string, lldb_private::UUID> m_kld_name_to_uuid;162163private:164DynamicLoaderFreeBSDKernel(const DynamicLoaderFreeBSDKernel &) = delete;165166const DynamicLoaderFreeBSDKernel &167operator=(const DynamicLoaderFreeBSDKernel &) = delete;168};169170#endif171172173