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 #include <map> 14 #include <memory> 15 16 #include "DYLDRendezvous.h" 17 #include "lldb/Breakpoint/StoppointCallbackContext.h" 18 #include "lldb/Core/ModuleList.h" 19 #include "lldb/Target/DynamicLoader.h" 20 21 class AuxVector; 22 23 class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader { 24 public: 25 DynamicLoaderPOSIXDYLD(lldb_private::Process *process); 26 27 ~DynamicLoaderPOSIXDYLD() override; 28 29 static void Initialize(); 30 31 static void Terminate(); 32 33 static lldb_private::ConstString GetPluginNameStatic(); 34 35 static const char *GetPluginDescriptionStatic(); 36 37 static lldb_private::DynamicLoader * 38 CreateInstance(lldb_private::Process *process, bool force); 39 40 //------------------------------------------------------------------ 41 // DynamicLoader protocol 42 //------------------------------------------------------------------ 43 44 void DidAttach() override; 45 46 void DidLaunch() override; 47 48 lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread, 49 bool stop_others) override; 50 51 lldb_private::Status CanLoadImage() override; 52 53 lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module, 54 const lldb::ThreadSP thread, 55 lldb::addr_t tls_file_addr) override; 56 57 //------------------------------------------------------------------ 58 // PluginInterface protocol 59 //------------------------------------------------------------------ 60 lldb_private::ConstString GetPluginName() override; 61 62 uint32_t GetPluginVersion() override; 63 64 protected: 65 /// Runtime linker rendezvous structure. 66 DYLDRendezvous m_rendezvous; 67 68 /// Virtual load address of the inferior process. 69 lldb::addr_t m_load_offset; 70 71 /// Virtual entry address of the inferior process. 72 lldb::addr_t m_entry_point; 73 74 /// Auxiliary vector of the inferior process. 75 std::unique_ptr<AuxVector> m_auxv; 76 77 /// Rendezvous breakpoint. 78 lldb::break_id_t m_dyld_bid; 79 80 /// Contains AT_SYSINFO_EHDR, which means a vDSO has been 81 /// mapped to the address space 82 lldb::addr_t m_vdso_base; 83 84 /// Contains AT_BASE, which means a dynamic loader has been 85 /// mapped to the address space 86 lldb::addr_t m_interpreter_base; 87 88 /// Loaded module list. (link map for each module) 89 std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>> 90 m_loaded_modules; 91 92 /// If possible sets a breakpoint on a function called by the runtime 93 /// linker each time a module is loaded or unloaded. 94 bool SetRendezvousBreakpoint(); 95 96 /// Callback routine which updates the current list of loaded modules based 97 /// on the information supplied by the runtime linker. 98 static bool RendezvousBreakpointHit( 99 void *baton, lldb_private::StoppointCallbackContext *context, 100 lldb::user_id_t break_id, lldb::user_id_t break_loc_id); 101 102 /// Helper method for RendezvousBreakpointHit. Updates LLDB's current set 103 /// of loaded modules. 104 void RefreshModules(); 105 106 /// Updates the load address of every allocatable section in @p module. 107 /// 108 /// @param module The module to traverse. 109 /// 110 /// @param link_map_addr The virtual address of the link map for the @p 111 /// module. 112 /// 113 /// @param base_addr The virtual base address @p module is loaded at. 114 void UpdateLoadedSections(lldb::ModuleSP module, lldb::addr_t link_map_addr, 115 lldb::addr_t base_addr, 116 bool base_addr_is_offset) override; 117 118 /// Removes the loaded sections from the target in @p module. 119 /// 120 /// @param module The module to traverse. 121 void UnloadSections(const lldb::ModuleSP module) override; 122 123 /// Resolves the entry point for the current inferior process and sets a 124 /// breakpoint at that address. 125 void ProbeEntry(); 126 127 /// Callback routine invoked when we hit the breakpoint on process entry. 128 /// 129 /// This routine is responsible for resolving the load addresses of all 130 /// dependent modules required by the inferior and setting up the rendezvous 131 /// breakpoint. 132 static bool 133 EntryBreakpointHit(void *baton, 134 lldb_private::StoppointCallbackContext *context, 135 lldb::user_id_t break_id, lldb::user_id_t break_loc_id); 136 137 /// Helper for the entry breakpoint callback. Resolves the load addresses 138 /// of all dependent modules. 139 virtual void LoadAllCurrentModules(); 140 141 void LoadVDSO(); 142 143 // Loading an interpreter module (if present) assumming m_interpreter_base 144 // already points to its base address. 145 lldb::ModuleSP LoadInterpreterModule(); 146 147 /// Computes a value for m_load_offset returning the computed address on 148 /// success and LLDB_INVALID_ADDRESS on failure. 149 lldb::addr_t ComputeLoadOffset(); 150 151 /// Computes a value for m_entry_point returning the computed address on 152 /// success and LLDB_INVALID_ADDRESS on failure. 153 lldb::addr_t GetEntryPoint(); 154 155 /// Evaluate if Aux vectors contain vDSO and LD information 156 /// in case they do, read and assign the address to m_vdso_base 157 /// and m_interpreter_base. 158 void EvalSpecialModulesStatus(); 159 160 /// Loads Module from inferior process. 161 void ResolveExecutableModule(lldb::ModuleSP &module_sp); 162 163 bool AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override; 164 165 private: 166 DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD); 167 }; 168 169 #endif // liblldb_DynamicLoaderPOSIXDYLD_h_ 170