1 //===-- DynamicLoaderHexagonDYLD.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_DynamicLoaderHexagonDYLD_h_ 11 #define liblldb_DynamicLoaderHexagonDYLD_h_ 12 13 #include "lldb/Breakpoint/StoppointCallbackContext.h" 14 #include "lldb/Target/DynamicLoader.h" 15 16 #include "HexagonDYLDRendezvous.h" 17 18 class DynamicLoaderHexagonDYLD : public lldb_private::DynamicLoader { 19 public: 20 DynamicLoaderHexagonDYLD(lldb_private::Process *process); 21 22 ~DynamicLoaderHexagonDYLD() override; 23 24 static void Initialize(); 25 26 static void Terminate(); 27 28 static lldb_private::ConstString GetPluginNameStatic(); 29 30 static const char *GetPluginDescriptionStatic(); 31 32 static lldb_private::DynamicLoader * 33 CreateInstance(lldb_private::Process *process, bool force); 34 35 //------------------------------------------------------------------ 36 // DynamicLoader protocol 37 //------------------------------------------------------------------ 38 39 void DidAttach() override; 40 41 void DidLaunch() override; 42 43 lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread, 44 bool stop_others) override; 45 46 lldb_private::Status CanLoadImage() override; 47 48 lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module, 49 const lldb::ThreadSP thread, 50 lldb::addr_t tls_file_addr) override; 51 52 //------------------------------------------------------------------ 53 // PluginInterface protocol 54 //------------------------------------------------------------------ 55 lldb_private::ConstString GetPluginName() override; 56 57 uint32_t GetPluginVersion() override; 58 59 protected: 60 /// Runtime linker rendezvous structure. 61 HexagonDYLDRendezvous m_rendezvous; 62 63 /// Virtual load address of the inferior process. 64 lldb::addr_t m_load_offset; 65 66 /// Virtual entry address of the inferior process. 67 lldb::addr_t m_entry_point; 68 69 /// Rendezvous breakpoint. 70 lldb::break_id_t m_dyld_bid; 71 72 /// Loaded module list. (link map for each module) 73 std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>> 74 m_loaded_modules; 75 76 /// Enables a breakpoint on a function called by the runtime 77 /// linker each time a module is loaded or unloaded. 78 bool SetRendezvousBreakpoint(); 79 80 /// Callback routine which updates the current list of loaded modules based 81 /// on the information supplied by the runtime linker. 82 static bool RendezvousBreakpointHit( 83 void *baton, lldb_private::StoppointCallbackContext *context, 84 lldb::user_id_t break_id, lldb::user_id_t break_loc_id); 85 86 /// Helper method for RendezvousBreakpointHit. Updates LLDB's current set 87 /// of loaded modules. 88 void RefreshModules(); 89 90 /// Updates the load address of every allocatable section in @p module. 91 /// 92 /// @param module The module to traverse. 93 /// 94 /// @param link_map_addr The virtual address of the link map for the @p 95 /// module. 96 /// 97 /// @param base_addr The virtual base address @p module is loaded at. 98 void UpdateLoadedSections(lldb::ModuleSP module, lldb::addr_t link_map_addr, 99 lldb::addr_t base_addr, 100 bool base_addr_is_offset) override; 101 102 /// Removes the loaded sections from the target in @p module. 103 /// 104 /// @param module The module to traverse. 105 void UnloadSections(const lldb::ModuleSP module) override; 106 107 /// Callback routine invoked when we hit the breakpoint on process entry. 108 /// 109 /// This routine is responsible for resolving the load addresses of all 110 /// dependent modules required by the inferior and setting up the rendezvous 111 /// breakpoint. 112 static bool 113 EntryBreakpointHit(void *baton, 114 lldb_private::StoppointCallbackContext *context, 115 lldb::user_id_t break_id, lldb::user_id_t break_loc_id); 116 117 /// Helper for the entry breakpoint callback. Resolves the load addresses 118 /// of all dependent modules. 119 void LoadAllCurrentModules(); 120 121 /// Computes a value for m_load_offset returning the computed address on 122 /// success and LLDB_INVALID_ADDRESS on failure. 123 lldb::addr_t ComputeLoadOffset(); 124 125 /// Computes a value for m_entry_point returning the computed address on 126 /// success and LLDB_INVALID_ADDRESS on failure. 127 lldb::addr_t GetEntryPoint(); 128 129 /// Checks to see if the target module has changed, updates the target 130 /// accordingly and returns the target executable module. 131 lldb::ModuleSP GetTargetExecutable(); 132 133 /// return the address of the Rendezvous breakpoint 134 lldb::addr_t FindRendezvousBreakpointAddress(); 135 136 private: 137 const lldb_private::SectionList * 138 GetSectionListFromModule(const lldb::ModuleSP module) const; 139 140 DISALLOW_COPY_AND_ASSIGN(DynamicLoaderHexagonDYLD); 141 }; 142 143 #endif // liblldb_DynamicLoaderHexagonDYLD_h_ 144