1 //===-- DynamicLoaderPOSIXDYLD.h --------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_DynamicLoaderPOSIXDYLD_h_ 11 #define liblldb_DynamicLoaderPOSIXDYLD_h_ 12 13 // C Includes 14 // C++ Includes 15 #include <map> 16 #include <memory> 17 18 // Other libraries and framework includes 19 // Project includes 20 #include "DYLDRendezvous.h" 21 #include "lldb/Breakpoint/StoppointCallbackContext.h" 22 #include "lldb/Core/ModuleList.h" 23 #include "lldb/Target/DynamicLoader.h" 24 25 class AuxVector; 26 27 class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader { 28 public: 29 DynamicLoaderPOSIXDYLD(lldb_private::Process *process); 30 31 ~DynamicLoaderPOSIXDYLD() override; 32 33 static void Initialize(); 34 35 static void Terminate(); 36 37 static lldb_private::ConstString GetPluginNameStatic(); 38 39 static const char *GetPluginDescriptionStatic(); 40 41 static lldb_private::DynamicLoader * 42 CreateInstance(lldb_private::Process *process, bool force); 43 44 //------------------------------------------------------------------ 45 // DynamicLoader protocol 46 //------------------------------------------------------------------ 47 48 void DidAttach() override; 49 50 void DidLaunch() override; 51 52 lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread, 53 bool stop_others) override; 54 55 lldb_private::Status CanLoadImage() override; 56 57 lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module, 58 const lldb::ThreadSP thread, 59 lldb::addr_t tls_file_addr) override; 60 61 //------------------------------------------------------------------ 62 // PluginInterface protocol 63 //------------------------------------------------------------------ 64 lldb_private::ConstString GetPluginName() override; 65 66 uint32_t GetPluginVersion() override; 67 68 protected: 69 /// Runtime linker rendezvous structure. 70 DYLDRendezvous m_rendezvous; 71 72 /// Virtual load address of the inferior process. 73 lldb::addr_t m_load_offset; 74 75 /// Virtual entry address of the inferior process. 76 lldb::addr_t m_entry_point; 77 78 /// Auxiliary vector of the inferior process. 79 std::unique_ptr<AuxVector> m_auxv; 80 81 /// Rendezvous breakpoint. 82 lldb::break_id_t m_dyld_bid; 83 84 /// Contains AT_SYSINFO_EHDR, which means a vDSO has been 85 /// mapped to the address space 86 lldb::addr_t m_vdso_base; 87 88 /// Contains AT_BASE, which means a dynamic loader has been 89 /// mapped to the address space 90 lldb::addr_t m_interpreter_base; 91 92 /// Loaded module list. (link map for each module) 93 std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>> 94 m_loaded_modules; 95 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(); 99 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); 105 106 /// Helper method for RendezvousBreakpointHit. Updates LLDB's current set 107 /// of loaded modules. 108 void RefreshModules(); 109 110 /// Updates the load address of every allocatable section in @p module. 111 /// 112 /// @param module The module to traverse. 113 /// 114 /// @param link_map_addr The virtual address of the link map for the @p 115 /// module. 116 /// 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; 121 122 /// Removes the loaded sections from the target in @p module. 123 /// 124 /// @param module The module to traverse. 125 void UnloadSections(const lldb::ModuleSP module) override; 126 127 /// Resolves the entry point for the current inferior process and sets a 128 /// breakpoint at that address. 129 void ProbeEntry(); 130 131 /// Callback routine invoked when we hit the breakpoint on process entry. 132 /// 133 /// This routine is responsible for resolving the load addresses of all 134 /// dependent modules required by the inferior and setting up the rendezvous 135 /// breakpoint. 136 static bool 137 EntryBreakpointHit(void *baton, 138 lldb_private::StoppointCallbackContext *context, 139 lldb::user_id_t break_id, lldb::user_id_t break_loc_id); 140 141 /// Helper for the entry breakpoint callback. Resolves the load addresses 142 /// of all dependent modules. 143 virtual void LoadAllCurrentModules(); 144 145 void LoadVDSO(); 146 147 // Loading an interpreter module (if present) assumming m_interpreter_base 148 // already points to its base address. 149 lldb::ModuleSP LoadInterpreterModule(); 150 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(); 154 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(); 158 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(); 163 164 /// Loads Module from inferior process. 165 void ResolveExecutableModule(lldb::ModuleSP &module_sp); 166 167 bool AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override; 168 169 private: 170 DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD); 171 }; 172 173 #endif // liblldb_DynamicLoaderPOSIXDYLD_h_ 174