1 //===-- DynamicLoaderPOSIX.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_DynamicLoaderPOSIX_H_ 11 #define liblldb_DynamicLoaderPOSIX_H_ 12 13 // C Includes 14 // C++ Includes 15 // Other libraries and framework includes 16 #include "lldb/Breakpoint/StoppointCallbackContext.h" 17 #include "lldb/Target/DynamicLoader.h" 18 19 #include "DYLDRendezvous.h" 20 21 class AuxVector; 22 23 class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader 24 { 25 public: 26 27 static void 28 Initialize(); 29 30 static void 31 Terminate(); 32 33 static lldb_private::ConstString 34 GetPluginNameStatic(); 35 36 static const char * 37 GetPluginDescriptionStatic(); 38 39 static lldb_private::DynamicLoader * 40 CreateInstance(lldb_private::Process *process, bool force); 41 42 DynamicLoaderPOSIXDYLD(lldb_private::Process *process); 43 44 virtual 45 ~DynamicLoaderPOSIXDYLD(); 46 47 //------------------------------------------------------------------ 48 // DynamicLoader protocol 49 //------------------------------------------------------------------ 50 51 virtual void 52 DidAttach(); 53 54 virtual void 55 DidLaunch(); 56 57 virtual lldb::ThreadPlanSP 58 GetStepThroughTrampolinePlan(lldb_private::Thread &thread, 59 bool stop_others); 60 61 virtual lldb_private::Error 62 CanLoadImage(); 63 64 //------------------------------------------------------------------ 65 // PluginInterface protocol 66 //------------------------------------------------------------------ 67 virtual lldb_private::ConstString 68 GetPluginName(); 69 70 virtual uint32_t 71 GetPluginVersion(); 72 73 virtual void 74 GetPluginCommandHelp(const char *command, lldb_private::Stream *strm); 75 76 virtual lldb_private::Error 77 ExecutePluginCommand(lldb_private::Args &command, lldb_private::Stream *strm); 78 79 virtual lldb_private::Log * 80 EnablePluginLogging(lldb_private::Stream *strm, lldb_private::Args &command); 81 82 protected: 83 /// Runtime linker rendezvous structure. 84 DYLDRendezvous m_rendezvous; 85 86 /// Virtual load address of the inferior process. 87 lldb::addr_t m_load_offset; 88 89 /// Virtual entry address of the inferior process. 90 lldb::addr_t m_entry_point; 91 92 /// Auxiliary vector of the inferior process. 93 std::unique_ptr<AuxVector> m_auxv; 94 95 /// Enables a breakpoint on a function called by the runtime 96 /// linker each time a module is loaded or unloaded. 97 void 98 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 103 RendezvousBreakpointHit(void *baton, 104 lldb_private::StoppointCallbackContext *context, 105 lldb::user_id_t break_id, 106 lldb::user_id_t break_loc_id); 107 108 /// Helper method for RendezvousBreakpointHit. Updates LLDB's current set 109 /// of loaded modules. 110 void 111 RefreshModules(); 112 113 /// Updates the load address of every allocatable section in @p module. 114 /// 115 /// @param module The module to traverse. 116 /// 117 /// @param base_addr The virtual base address @p module is loaded at. 118 void 119 UpdateLoadedSections(lldb::ModuleSP module, 120 lldb::addr_t base_addr = 0); 121 122 /// Locates or creates a module given by @p file and updates/loads the 123 /// resulting module at the virtual base address @p base_addr. 124 lldb::ModuleSP 125 LoadModuleAtAddress(const lldb_private::FileSpec &file, lldb::addr_t base_addr); 126 127 /// Resolves the entry point for the current inferior process and sets a 128 /// breakpoint at that address. 129 void 130 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, 139 lldb_private::StoppointCallbackContext *context, 140 lldb::user_id_t break_id, 141 lldb::user_id_t break_loc_id); 142 143 /// Helper for the entry breakpoint callback. Resolves the load addresses 144 /// of all dependent modules. 145 void 146 LoadAllCurrentModules(); 147 148 /// Computes a value for m_load_offset returning the computed address on 149 /// success and LLDB_INVALID_ADDRESS on failure. 150 lldb::addr_t 151 ComputeLoadOffset(); 152 153 /// Computes a value for m_entry_point returning the computed address on 154 /// success and LLDB_INVALID_ADDRESS on failure. 155 lldb::addr_t 156 GetEntryPoint(); 157 158 /// Checks to see if the target module has changed, updates the target 159 /// accordingly and returns the target executable module. 160 lldb::ModuleSP 161 GetTargetExecutable(); 162 163 private: 164 DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD); 165 }; 166 167 #endif // liblldb_DynamicLoaderPOSIXDYLD_H_ 168