Path: blob/main/contrib/llvm-project/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
39653 views
//===-- DynamicLoaderPOSIXDYLD.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_POSIX_DYLD_DYNAMICLOADERPOSIXDYLD_H9#define LLDB_SOURCE_PLUGINS_DYNAMICLOADER_POSIX_DYLD_DYNAMICLOADERPOSIXDYLD_H1011#include <map>12#include <memory>1314#include "DYLDRendezvous.h"15#include "Plugins/Process/Utility/AuxVector.h"16#include "lldb/Breakpoint/StoppointCallbackContext.h"17#include "lldb/Core/ModuleList.h"18#include "lldb/Target/DynamicLoader.h"1920class AuxVector;2122class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader {23public:24DynamicLoaderPOSIXDYLD(lldb_private::Process *process);2526~DynamicLoaderPOSIXDYLD() override;2728static void Initialize();2930static void Terminate();3132static llvm::StringRef GetPluginNameStatic() { return "posix-dyld"; }3334static llvm::StringRef GetPluginDescriptionStatic();3536static lldb_private::DynamicLoader *37CreateInstance(lldb_private::Process *process, bool force);3839// DynamicLoader protocol4041void DidAttach() override;4243void DidLaunch() override;4445lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread,46bool stop_others) override;4748lldb_private::Status CanLoadImage() override;4950lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module,51const lldb::ThreadSP thread,52lldb::addr_t tls_file_addr) override;5354// PluginInterface protocol55llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }5657lldb::ModuleSP LoadModuleAtAddress(const lldb_private::FileSpec &file,58lldb::addr_t link_map_addr,59lldb::addr_t base_addr,60bool base_addr_is_offset) override;6162protected:63/// Runtime linker rendezvous structure.64DYLDRendezvous m_rendezvous;6566/// Virtual load address of the inferior process.67lldb::addr_t m_load_offset;6869/// Virtual entry address of the inferior process.70lldb::addr_t m_entry_point;7172/// Auxiliary vector of the inferior process.73std::unique_ptr<AuxVector> m_auxv;7475/// Rendezvous breakpoint.76lldb::break_id_t m_dyld_bid;7778/// Contains AT_SYSINFO_EHDR, which means a vDSO has been79/// mapped to the address space80lldb::addr_t m_vdso_base;8182/// Contains AT_BASE, which means a dynamic loader has been83/// mapped to the address space84lldb::addr_t m_interpreter_base;8586/// Contains the pointer to the interpret module, if loaded.87std::weak_ptr<lldb_private::Module> m_interpreter_module;8889/// Loaded module list. (link map for each module)90std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>>91m_loaded_modules;9293/// Returns true if the process is for a core file.94bool IsCoreFile() const;9596/// If possible sets a breakpoint on a function called by the runtime97/// linker each time a module is loaded or unloaded.98bool SetRendezvousBreakpoint();99100/// Callback routine which updates the current list of loaded modules based101/// on the information supplied by the runtime linker.102static bool RendezvousBreakpointHit(103void *baton, lldb_private::StoppointCallbackContext *context,104lldb::user_id_t break_id, lldb::user_id_t break_loc_id);105106/// Indicates whether the initial set of modules was reported added.107bool m_initial_modules_added;108109/// Helper method for RendezvousBreakpointHit. Updates LLDB's current set110/// of loaded modules.111void RefreshModules();112113/// Updates the load address of every allocatable section in \p module.114///115/// \param module The module to traverse.116///117/// \param link_map_addr The virtual address of the link map for the @p118/// module.119///120/// \param base_addr The virtual base address \p module is loaded at.121void UpdateLoadedSections(lldb::ModuleSP module, lldb::addr_t link_map_addr,122lldb::addr_t base_addr,123bool base_addr_is_offset) override;124125/// Removes the loaded sections from the target in \p module.126///127/// \param module The module to traverse.128void UnloadSections(const lldb::ModuleSP module) override;129130/// Resolves the entry point for the current inferior process and sets a131/// breakpoint at that address.132void ProbeEntry();133134/// Callback routine invoked when we hit the breakpoint on process entry.135///136/// This routine is responsible for resolving the load addresses of all137/// dependent modules required by the inferior and setting up the rendezvous138/// breakpoint.139static bool140EntryBreakpointHit(void *baton,141lldb_private::StoppointCallbackContext *context,142lldb::user_id_t break_id, lldb::user_id_t break_loc_id);143144/// Helper for the entry breakpoint callback. Resolves the load addresses145/// of all dependent modules.146virtual void LoadAllCurrentModules();147148void LoadVDSO();149150// Loading an interpreter module (if present) assuming m_interpreter_base151// already points to its base address.152lldb::ModuleSP LoadInterpreterModule();153154/// Computes a value for m_load_offset returning the computed address on155/// success and LLDB_INVALID_ADDRESS on failure.156lldb::addr_t ComputeLoadOffset();157158/// Computes a value for m_entry_point returning the computed address on159/// success and LLDB_INVALID_ADDRESS on failure.160lldb::addr_t GetEntryPoint();161162/// Evaluate if Aux vectors contain vDSO and LD information163/// in case they do, read and assign the address to m_vdso_base164/// and m_interpreter_base.165void EvalSpecialModulesStatus();166167/// Loads Module from inferior process.168void ResolveExecutableModule(lldb::ModuleSP &module_sp);169170bool AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override;171172private:173DynamicLoaderPOSIXDYLD(const DynamicLoaderPOSIXDYLD &) = delete;174const DynamicLoaderPOSIXDYLD &175operator=(const DynamicLoaderPOSIXDYLD &) = delete;176};177178#endif // LLDB_SOURCE_PLUGINS_DYNAMICLOADER_POSIX_DYLD_DYNAMICLOADERPOSIXDYLD_H179180181