1 //===-- DynamicLoaderPOSIXDYLD.h --------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_DynamicLoaderPOSIXDYLD_h_
11 #define liblldb_DynamicLoaderPOSIXDYLD_h_
18 // Other libraries and framework includes
20 #include "DYLDRendezvous.h"
21 #include "lldb/Breakpoint/StoppointCallbackContext.h"
22 #include "lldb/Core/ModuleList.h"
23 #include "lldb/Target/DynamicLoader.h"
27 class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader {
29 DynamicLoaderPOSIXDYLD(lldb_private::Process *process);
31 ~DynamicLoaderPOSIXDYLD() override;
33 static void Initialize();
35 static void Terminate();
37 static lldb_private::ConstString GetPluginNameStatic();
39 static const char *GetPluginDescriptionStatic();
41 static lldb_private::DynamicLoader *
42 CreateInstance(lldb_private::Process *process, bool force);
44 //------------------------------------------------------------------
45 // DynamicLoader protocol
46 //------------------------------------------------------------------
48 void DidAttach() override;
50 void DidLaunch() override;
52 lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
53 bool stop_others) override;
55 lldb_private::Status CanLoadImage() override;
57 lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module,
58 const lldb::ThreadSP thread,
59 lldb::addr_t tls_file_addr) override;
61 //------------------------------------------------------------------
62 // PluginInterface protocol
63 //------------------------------------------------------------------
64 lldb_private::ConstString GetPluginName() override;
66 uint32_t GetPluginVersion() override;
69 /// Runtime linker rendezvous structure.
70 DYLDRendezvous m_rendezvous;
72 /// Virtual load address of the inferior process.
73 lldb::addr_t m_load_offset;
75 /// Virtual entry address of the inferior process.
76 lldb::addr_t m_entry_point;
78 /// Auxiliary vector of the inferior process.
79 std::unique_ptr<AuxVector> m_auxv;
81 /// Rendezvous breakpoint.
82 lldb::break_id_t m_dyld_bid;
84 /// Contains AT_SYSINFO_EHDR, which means a vDSO has been
85 /// mapped to the address space
86 lldb::addr_t m_vdso_base;
88 /// Contains AT_BASE, which means a dynamic loader has been
89 /// mapped to the address space
90 lldb::addr_t m_interpreter_base;
92 /// Loaded module list. (link map for each module)
93 std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>>
96 /// If possible sets a breakpoint on a function called by the runtime
97 /// linker each time a module is loaded or unloaded.
98 bool SetRendezvousBreakpoint();
100 /// Callback routine which updates the current list of loaded modules based
101 /// on the information supplied by the runtime linker.
102 static bool RendezvousBreakpointHit(
103 void *baton, lldb_private::StoppointCallbackContext *context,
104 lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
106 /// Helper method for RendezvousBreakpointHit. Updates LLDB's current set
107 /// of loaded modules.
108 void RefreshModules();
110 /// Updates the load address of every allocatable section in @p module.
112 /// @param module The module to traverse.
114 /// @param link_map_addr The virtual address of the link map for the @p
117 /// @param base_addr The virtual base address @p module is loaded at.
118 void UpdateLoadedSections(lldb::ModuleSP module, lldb::addr_t link_map_addr,
119 lldb::addr_t base_addr,
120 bool base_addr_is_offset) override;
122 /// Removes the loaded sections from the target in @p module.
124 /// @param module The module to traverse.
125 void UnloadSections(const lldb::ModuleSP module) override;
127 /// Resolves the entry point for the current inferior process and sets a
128 /// breakpoint at that address.
131 /// Callback routine invoked when we hit the breakpoint on process entry.
133 /// This routine is responsible for resolving the load addresses of all
134 /// dependent modules required by the inferior and setting up the rendezvous
137 EntryBreakpointHit(void *baton,
138 lldb_private::StoppointCallbackContext *context,
139 lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
141 /// Helper for the entry breakpoint callback. Resolves the load addresses
142 /// of all dependent modules.
143 virtual void LoadAllCurrentModules();
147 // Loading an interpreter module (if present) assumming m_interpreter_base
148 // already points to its base address.
149 lldb::ModuleSP LoadInterpreterModule();
151 /// Computes a value for m_load_offset returning the computed address on
152 /// success and LLDB_INVALID_ADDRESS on failure.
153 lldb::addr_t ComputeLoadOffset();
155 /// Computes a value for m_entry_point returning the computed address on
156 /// success and LLDB_INVALID_ADDRESS on failure.
157 lldb::addr_t GetEntryPoint();
159 /// Evaluate if Aux vectors contain vDSO and LD information
160 /// in case they do, read and assign the address to m_vdso_base
161 /// and m_interpreter_base.
162 void EvalSpecialModulesStatus();
164 /// Loads Module from inferior process.
165 void ResolveExecutableModule(lldb::ModuleSP &module_sp);
167 bool AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override;
170 DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD);
173 #endif // liblldb_DynamicLoaderPOSIXDYLD_h_