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 /// 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 /// Enables a breakpoint on a function called by the runtime 93 /// linker each time a module is loaded or unloaded. 94 virtual void 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(lldb_private::ModuleList &modules); 142 143 /// Computes a value for m_load_offset returning the computed address on 144 /// success and LLDB_INVALID_ADDRESS on failure. 145 lldb::addr_t ComputeLoadOffset(); 146 147 /// Computes a value for m_entry_point returning the computed address on 148 /// success and LLDB_INVALID_ADDRESS on failure. 149 lldb::addr_t GetEntryPoint(); 150 151 /// Evaluate if Aux vectors contain vDSO information 152 /// in case they do, read and assign the address to m_vdso_base 153 void EvalVdsoStatus(); 154 155 /// Loads Module from inferior process. 156 void ResolveExecutableModule(lldb::ModuleSP &module_sp); 157 158 bool AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override; 159 160 private: 161 DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD); 162 }; 163 164 #endif // liblldb_DynamicLoaderPOSIXDYLD_h_ 165