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"
18 #include "lldb/Core/ModuleList.h"
20 
21 class AuxVector;
22 
24 public:
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 
46  lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
47  bool stop_others) override;
48 
50 
51  lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module,
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 
58  lldb::ModuleSP LoadModuleAtAddress(const lldb_private::FileSpec &file,
59  lldb::addr_t link_map_addr,
60  lldb::addr_t base_addr,
61  bool base_addr_is_offset) override;
62 
63 protected:
64  /// Runtime linker rendezvous structure.
66 
67  /// Virtual load address of the inferior process.
69 
70  /// Virtual entry address of the inferior process.
72 
73  /// Auxiliary vector of the inferior process.
74  std::unique_ptr<AuxVector> m_auxv;
75 
76  /// Rendezvous breakpoint.
78 
79  /// Contains AT_SYSINFO_EHDR, which means a vDSO has been
80  /// mapped to the address space
82 
83  /// Contains AT_BASE, which means a dynamic loader has been
84  /// mapped to the address space
86 
87  /// Contains the pointer to the interpret module, if loaded.
88  std::weak_ptr<lldb_private::Module> m_interpreter_module;
89 
90  /// Loaded module list. (link map for each module)
91  std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>>
93 
94  /// If possible sets a breakpoint on a function called by the runtime
95  /// linker each time a module is loaded or unloaded.
97 
98  /// Callback routine which updates the current list of loaded modules based
99  /// on the information supplied by the runtime linker.
100  static bool RendezvousBreakpointHit(
101  void *baton, lldb_private::StoppointCallbackContext *context,
102  lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
103 
104  /// Indicates whether the initial set of modules was reported added.
106 
107  /// Helper method for RendezvousBreakpointHit. Updates LLDB's current set
108  /// of loaded modules.
109  void RefreshModules();
110 
111  /// Updates the load address of every allocatable section in \p module.
112  ///
113  /// \param module The module to traverse.
114  ///
115  /// \param link_map_addr The virtual address of the link map for the @p
116  /// module.
117  ///
118  /// \param base_addr The virtual base address \p module is loaded at.
119  void UpdateLoadedSections(lldb::ModuleSP module, lldb::addr_t link_map_addr,
120  lldb::addr_t base_addr,
121  bool base_addr_is_offset) override;
122 
123  /// Removes the loaded sections from the target in \p module.
124  ///
125  /// \param module The module to traverse.
126  void UnloadSections(const lldb::ModuleSP module) override;
127 
128  /// Resolves the entry point for the current inferior process and sets a
129  /// breakpoint at that address.
130  void ProbeEntry();
131 
132  /// Callback routine invoked when we hit the breakpoint on process entry.
133  ///
134  /// This routine is responsible for resolving the load addresses of all
135  /// dependent modules required by the inferior and setting up the rendezvous
136  /// breakpoint.
137  static bool
138  EntryBreakpointHit(void *baton,
140  lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
141 
142  /// Helper for the entry breakpoint callback. Resolves the load addresses
143  /// of all dependent modules.
144  virtual void LoadAllCurrentModules();
145 
146  void LoadVDSO();
147 
148  // Loading an interpreter module (if present) assuming m_interpreter_base
149  // already points to its base address.
150  lldb::ModuleSP LoadInterpreterModule();
151 
152  /// Computes a value for m_load_offset returning the computed address on
153  /// success and LLDB_INVALID_ADDRESS on failure.
155 
156  /// Computes a value for m_entry_point returning the computed address on
157  /// success and LLDB_INVALID_ADDRESS on failure.
159 
160  /// Evaluate if Aux vectors contain vDSO and LD information
161  /// in case they do, read and assign the address to m_vdso_base
162  /// and m_interpreter_base.
164 
165  /// Loads Module from inferior process.
166  void ResolveExecutableModule(lldb::ModuleSP &module_sp);
167 
169 
170 private:
172  const DynamicLoaderPOSIXDYLD &
173  operator=(const DynamicLoaderPOSIXDYLD &) = delete;
174 };
175 
176 #endif // LLDB_SOURCE_PLUGINS_DYNAMICLOADER_POSIX_DYLD_DYNAMICLOADERPOSIXDYLD_H
DynamicLoaderPOSIXDYLD::DidLaunch
void DidLaunch() override
Called after launching a process.
Definition: DynamicLoaderPOSIXDYLD.cpp:165
lldb_private::StoppointCallbackContext
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
Definition: StoppointCallbackContext.h:26
DynamicLoaderPOSIXDYLD::m_initial_modules_added
bool m_initial_modules_added
Indicates whether the initial set of modules was reported added.
Definition: DynamicLoaderPOSIXDYLD.h:105
DynamicLoaderPOSIXDYLD::Terminate
static void Terminate()
Definition: DynamicLoaderPOSIXDYLD.cpp:40
DynamicLoaderPOSIXDYLD::GetEntryPoint
lldb::addr_t GetEntryPoint()
Computes a value for m_entry_point returning the computed address on success and LLDB_INVALID_ADDRESS...
Definition: DynamicLoaderPOSIXDYLD.cpp:697
DynamicLoaderPOSIXDYLD::m_load_offset
lldb::addr_t m_load_offset
Virtual load address of the inferior process.
Definition: DynamicLoaderPOSIXDYLD.h:68
lldb_private::Process
Definition: Process.h:338
StoppointCallbackContext.h
DynamicLoaderPOSIXDYLD
Definition: DynamicLoaderPOSIXDYLD.h:23
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
DynamicLoaderPOSIXDYLD::RefreshModules
void RefreshModules()
Helper method for RendezvousBreakpointHit.
Definition: DynamicLoaderPOSIXDYLD.cpp:409
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb_private::FileSpec
Definition: FileSpec.h:56
DynamicLoaderPOSIXDYLD::LoadVDSO
void LoadVDSO()
Definition: DynamicLoaderPOSIXDYLD.cpp:534
ModuleList.h
AuxVector
Definition: AuxVector.h:16
lldb_private::Thread
Definition: Thread.h:61
AuxVector.h
DynamicLoaderPOSIXDYLD::m_loaded_modules
std::map< lldb::ModuleWP, lldb::addr_t, std::owner_less< lldb::ModuleWP > > m_loaded_modules
Loaded module list. (link map for each module)
Definition: DynamicLoaderPOSIXDYLD.h:92
DynamicLoaderPOSIXDYLD::m_interpreter_base
lldb::addr_t m_interpreter_base
Contains AT_BASE, which means a dynamic loader has been mapped to the address space.
Definition: DynamicLoaderPOSIXDYLD.h:85
DynamicLoaderPOSIXDYLD::operator=
const DynamicLoaderPOSIXDYLD & operator=(const DynamicLoaderPOSIXDYLD &)=delete
lldb::break_id_t
int32_t break_id_t
Definition: lldb-types.h:88
DynamicLoaderPOSIXDYLD::m_vdso_base
lldb::addr_t m_vdso_base
Contains AT_SYSINFO_EHDR, which means a vDSO has been mapped to the address space.
Definition: DynamicLoaderPOSIXDYLD.h:81
DynamicLoaderPOSIXDYLD::EntryBreakpointHit
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.
Definition: DynamicLoaderPOSIXDYLD.cpp:250
DynamicLoaderPOSIXDYLD::Initialize
static void Initialize()
Definition: DynamicLoaderPOSIXDYLD.cpp:35
DynamicLoaderPOSIXDYLD::DynamicLoaderPOSIXDYLD
DynamicLoaderPOSIXDYLD(lldb_private::Process *process)
Definition: DynamicLoaderPOSIXDYLD.cpp:64
lldb_private::DynamicLoader
Definition: DynamicLoader.h:52
DynamicLoaderPOSIXDYLD::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: DynamicLoaderPOSIXDYLD.h:33
DYLDRendezvous.h
DynamicLoaderPOSIXDYLD::RendezvousBreakpointHit
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...
Definition: DynamicLoaderPOSIXDYLD.cpp:380
DynamicLoaderPOSIXDYLD::ComputeLoadOffset
lldb::addr_t ComputeLoadOffset()
Computes a value for m_load_offset returning the computed address on success and LLDB_INVALID_ADDRESS...
Definition: DynamicLoaderPOSIXDYLD.cpp:661
DynamicLoaderPOSIXDYLD::ResolveExecutableModule
void ResolveExecutableModule(lldb::ModuleSP &module_sp)
Loads Module from inferior process.
Definition: DynamicLoaderPOSIXDYLD.cpp:772
DynamicLoaderPOSIXDYLD::GetPluginName
llvm::StringRef GetPluginName() override
Definition: DynamicLoaderPOSIXDYLD.h:56
lldb_private::Status
Definition: Status.h:44
DynamicLoaderPOSIXDYLD::SetRendezvousBreakpoint
bool SetRendezvousBreakpoint()
If possible sets a breakpoint on a function called by the runtime linker each time a module is loaded...
Definition: DynamicLoaderPOSIXDYLD.cpp:298
DynamicLoaderPOSIXDYLD::GetPluginDescriptionStatic
static llvm::StringRef GetPluginDescriptionStatic()
Definition: DynamicLoaderPOSIXDYLD.cpp:42
DynamicLoaderPOSIXDYLD::GetStepThroughTrampolinePlan
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.
Definition: DynamicLoaderPOSIXDYLD.cpp:484
DynamicLoaderPOSIXDYLD::AlwaysRelyOnEHUnwindInfo
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...
Definition: DynamicLoaderPOSIXDYLD.cpp:819
DynamicLoaderPOSIXDYLD::EvalSpecialModulesStatus
void EvalSpecialModulesStatus()
Evaluate if Aux vectors contain vDSO and LD information in case they do, read and assign the address ...
Definition: DynamicLoaderPOSIXDYLD.cpp:687
DynamicLoaderPOSIXDYLD::m_auxv
std::unique_ptr< AuxVector > m_auxv
Auxiliary vector of the inferior process.
Definition: DynamicLoaderPOSIXDYLD.h:74
DynamicLoaderPOSIXDYLD::LoadModuleAtAddress
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 ...
Definition: DynamicLoaderPOSIXDYLD.cpp:582
DYLDRendezvous
Definition: DYLDRendezvous.h:34
DynamicLoaderPOSIXDYLD::UnloadSections
void UnloadSections(const lldb::ModuleSP module) override
Removes the loaded sections from the target in module.
Definition: DynamicLoaderPOSIXDYLD.cpp:207
DynamicLoaderPOSIXDYLD::m_entry_point
lldb::addr_t m_entry_point
Virtual entry address of the inferior process.
Definition: DynamicLoaderPOSIXDYLD.h:71
DynamicLoaderPOSIXDYLD::CreateInstance
static lldb_private::DynamicLoader * CreateInstance(lldb_private::Process *process, bool force)
Definition: DynamicLoaderPOSIXDYLD.cpp:47
DynamicLoaderPOSIXDYLD::m_rendezvous
DYLDRendezvous m_rendezvous
Runtime linker rendezvous structure.
Definition: DynamicLoaderPOSIXDYLD.h:65
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
DynamicLoaderPOSIXDYLD::UpdateLoadedSections
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.
Definition: DynamicLoaderPOSIXDYLD.cpp:199
DynamicLoaderPOSIXDYLD::CanLoadImage
lldb_private::Status CanLoadImage() override
Ask if it is ok to try and load or unload an shared library (image).
Definition: DynamicLoaderPOSIXDYLD.cpp:197
DynamicLoaderPOSIXDYLD::LoadInterpreterModule
lldb::ModuleSP LoadInterpreterModule()
Definition: DynamicLoaderPOSIXDYLD.cpp:555
DynamicLoaderPOSIXDYLD::LoadAllCurrentModules
virtual void LoadAllCurrentModules()
Helper for the entry breakpoint callback.
Definition: DynamicLoaderPOSIXDYLD.cpp:614
DynamicLoaderPOSIXDYLD::~DynamicLoaderPOSIXDYLD
~DynamicLoaderPOSIXDYLD() override
Definition: DynamicLoaderPOSIXDYLD.cpp:72
DynamicLoaderPOSIXDYLD::m_dyld_bid
lldb::break_id_t m_dyld_bid
Rendezvous breakpoint.
Definition: DynamicLoaderPOSIXDYLD.h:77
DynamicLoaderPOSIXDYLD::ProbeEntry
void ProbeEntry()
Resolves the entry point for the current inferior process and sets a breakpoint at that address.
Definition: DynamicLoaderPOSIXDYLD.cpp:213
DynamicLoaderPOSIXDYLD::DidAttach
void DidAttach() override
Called after attaching a process.
Definition: DynamicLoaderPOSIXDYLD.cpp:79
DynamicLoader.h
DynamicLoaderPOSIXDYLD::GetThreadLocalData
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.
Definition: DynamicLoaderPOSIXDYLD.cpp:721
DynamicLoaderPOSIXDYLD::m_interpreter_module
std::weak_ptr< lldb_private::Module > m_interpreter_module
Contains the pointer to the interpret module, if loaded.
Definition: DynamicLoaderPOSIXDYLD.h:88