LLDB mainline
DynamicLoaderPOSIXDYLD.h
Go to the documentation of this file.
1//===-- DynamicLoaderPOSIXDYLD.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_POSIX_DYLD_DYNAMICLOADERPOSIXDYLD_H
10#define LLDB_SOURCE_PLUGINS_DYNAMICLOADER_POSIX_DYLD_DYNAMICLOADERPOSIXDYLD_H
11
12#include <map>
13#include <memory>
14
15#include "DYLDRendezvous.h"
20
21class AuxVector;
22
24public:
26
27 ~DynamicLoaderPOSIXDYLD() override;
28
29 static void Initialize();
30
31 static void Terminate();
32
33 static llvm::StringRef GetPluginNameStatic() { return "posix-dyld"; }
34
35 static llvm::StringRef GetPluginDescriptionStatic();
36
38 CreateInstance(lldb_private::Process *process, bool force);
39
40 // DynamicLoader protocol
41
42 void DidAttach() override;
43
44 void DidLaunch() override;
45
47 bool stop_others) override;
48
50
52 const lldb::ThreadSP thread,
53 lldb::addr_t tls_file_addr) override;
54
55 // PluginInterface protocol
56 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
57
59 lldb::addr_t link_map_addr,
60 lldb::addr_t base_addr,
61 bool base_addr_is_offset) override;
62
64 lldb_private::Process &process,
65 std::vector<lldb_private::MemoryRegionInfo> &ranges,
66 llvm::function_ref<bool(const lldb_private::Thread &)>
67 save_thread_predicate) override;
68
69protected:
70 /// Runtime linker rendezvous structure.
72
73 /// Virtual load address of the inferior process.
75
76 /// Virtual entry address of the inferior process.
78
79 /// Auxiliary vector of the inferior process.
80 std::unique_ptr<AuxVector> m_auxv;
81
82 /// Rendezvous breakpoint.
84
85 /// Contains AT_SYSINFO_EHDR, which means a vDSO has been
86 /// mapped to the address space
88
89 /// Contains AT_BASE, which means a dynamic loader has been
90 /// mapped to the address space
92
93 /// Contains the pointer to the interpret module, if loaded.
94 std::weak_ptr<lldb_private::Module> m_interpreter_module;
95
96 /// Loaded module list. (link map for each module)
97 std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>>
99
100 /// Returns true if the process is for a core file.
101 bool IsCoreFile() const;
102
103 /// If possible sets a breakpoint on a function called by the runtime
104 /// linker each time a module is loaded or unloaded.
106
107 /// Callback routine which updates the current list of loaded modules based
108 /// on the information supplied by the runtime linker.
109 static bool RendezvousBreakpointHit(
110 void *baton, lldb_private::StoppointCallbackContext *context,
111 lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
112
113 /// Indicates whether the initial set of modules was reported added.
115
116 /// Helper method for RendezvousBreakpointHit. Updates LLDB's current set
117 /// of loaded modules.
118 void RefreshModules();
119
120 /// Updates the load address of every allocatable section in \p module.
121 ///
122 /// \param module The module to traverse.
123 ///
124 /// \param link_map_addr The virtual address of the link map for the @p
125 /// module.
126 ///
127 /// \param base_addr The virtual base address \p module is loaded at.
128 void UpdateLoadedSections(lldb::ModuleSP module, lldb::addr_t link_map_addr,
129 lldb::addr_t base_addr,
130 bool base_addr_is_offset) override;
131
132 /// Removes the loaded sections from the target in \p module.
133 ///
134 /// \param module The module to traverse.
135 void UnloadSections(const lldb::ModuleSP module) override;
136
137 /// Resolves the entry point for the current inferior process and sets a
138 /// breakpoint at that address.
139 void ProbeEntry();
140
141 /// Callback routine invoked when we hit the breakpoint on process entry.
142 ///
143 /// This routine is responsible for resolving the load addresses of all
144 /// dependent modules required by the inferior and setting up the rendezvous
145 /// breakpoint.
146 static bool
147 EntryBreakpointHit(void *baton,
149 lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
150
151 /// Helper for the entry breakpoint callback. Resolves the load addresses
152 /// of all dependent modules.
153 virtual void LoadAllCurrentModules();
154
155 void LoadVDSO();
156
157 // Loading an interpreter module (if present) assuming m_interpreter_base
158 // already points to its base address.
160
161 /// Computes a value for m_load_offset returning the computed address on
162 /// success and LLDB_INVALID_ADDRESS on failure.
164
165 /// Computes a value for m_entry_point returning the computed address on
166 /// success and LLDB_INVALID_ADDRESS on failure.
168
169 /// Evaluate if Aux vectors contain vDSO and LD information
170 /// in case they do, read and assign the address to m_vdso_base
171 /// and m_interpreter_base.
173
174 /// Loads Module from inferior process.
176
178
179private:
183};
184
185#endif // LLDB_SOURCE_PLUGINS_DYNAMICLOADER_POSIX_DYLD_DYNAMICLOADERPOSIXDYLD_H
Interface to the runtime linker.
static bool RendezvousBreakpointHit(void *baton, lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
Callback routine which updates the current list of loaded modules based on the information supplied b...
std::map< lldb::ModuleWP, lldb::addr_t, std::owner_less< lldb::ModuleWP > > m_loaded_modules
Loaded module list. (link map for each module)
static lldb_private::DynamicLoader * CreateInstance(lldb_private::Process *process, bool force)
bool m_initial_modules_added
Indicates whether the initial set of modules was reported added.
lldb::addr_t m_load_offset
Virtual load address of the inferior process.
DynamicLoaderPOSIXDYLD(const DynamicLoaderPOSIXDYLD &)=delete
lldb::break_id_t m_dyld_bid
Rendezvous breakpoint.
lldb::addr_t GetEntryPoint()
Computes a value for m_entry_point returning the computed address on success and LLDB_INVALID_ADDRESS...
std::unique_ptr< AuxVector > m_auxv
Auxiliary vector of the inferior process.
static llvm::StringRef GetPluginDescriptionStatic()
void EvalSpecialModulesStatus()
Evaluate if Aux vectors contain vDSO and LD information in case they do, read and assign the address ...
lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module, const lldb::ThreadSP thread, lldb::addr_t tls_file_addr) override
Retrieves the per-module TLS block for a given thread.
bool SetRendezvousBreakpoint()
If possible sets a breakpoint on a function called by the runtime linker each time a module is loaded...
lldb::ModuleSP LoadInterpreterModule()
void RefreshModules()
Helper method for RendezvousBreakpointHit.
bool AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override
Ask if the eh_frame information for the given SymbolContext should be relied on even when it's the fi...
lldb::addr_t m_interpreter_base
Contains AT_BASE, which means a dynamic loader has been mapped to the address space.
void ProbeEntry()
Resolves the entry point for the current inferior process and sets a breakpoint at that address.
lldb_private::Status CanLoadImage() override
Ask if it is ok to try and load or unload an shared library (image).
const DynamicLoaderPOSIXDYLD & operator=(const DynamicLoaderPOSIXDYLD &)=delete
lldb::addr_t m_vdso_base
Contains AT_SYSINFO_EHDR, which means a vDSO has been mapped to the address space.
void UpdateLoadedSections(lldb::ModuleSP module, lldb::addr_t link_map_addr, lldb::addr_t base_addr, bool base_addr_is_offset) override
Updates the load address of every allocatable section in module.
lldb::addr_t ComputeLoadOffset()
Computes a value for m_load_offset returning the computed address on success and LLDB_INVALID_ADDRESS...
void UnloadSections(const lldb::ModuleSP module) override
Removes the loaded sections from the target in module.
DYLDRendezvous m_rendezvous
Runtime linker rendezvous structure.
void DidLaunch() override
Called after launching a process.
lldb::ModuleSP LoadModuleAtAddress(const lldb_private::FileSpec &file, lldb::addr_t link_map_addr, lldb::addr_t base_addr, bool base_addr_is_offset) override
Locates or creates a module given by file and updates/loads the resulting module at the virtual base ...
static bool EntryBreakpointHit(void *baton, lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
Callback routine invoked when we hit the breakpoint on process entry.
void DidAttach() override
Called after attaching a process.
llvm::StringRef GetPluginName() override
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 llvm::StringRef GetPluginNameStatic()
void ResolveExecutableModule(lldb::ModuleSP &module_sp)
Loads Module from inferior process.
lldb::addr_t m_entry_point
Virtual entry address of the inferior process.
virtual void LoadAllCurrentModules()
Helper for the entry breakpoint callback.
std::weak_ptr< lldb_private::Module > m_interpreter_module
Contains the pointer to the interpret module, if loaded.
bool IsCoreFile() const
Returns true if the process is for a core file.
void CalculateDynamicSaveCoreRanges(lldb_private::Process &process, std::vector< lldb_private::MemoryRegionInfo > &ranges, llvm::function_ref< bool(const lldb_private::Thread &)> save_thread_predicate) override
A plug-in interface definition class for dynamic loaders.
Definition: DynamicLoader.h:54
A file utility class.
Definition: FileSpec.h:56
A plug-in interface definition class for debugging a process.
Definition: Process.h:343
An error handling class.
Definition: Status.h:118
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:34
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
Definition: lldb-forward.h:453
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:450
int32_t break_id_t
Definition: lldb-types.h:86
uint64_t user_id_t
Definition: lldb-types.h:82
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:373