Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 1 | //===-- DynamicLoaderPOSIXDYLD.h --------------------------------*- C++ -*-===// |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 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 | |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 10 | #ifndef liblldb_DynamicLoaderPOSIXDYLD_h_ |
| 11 | #define liblldb_DynamicLoaderPOSIXDYLD_h_ |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 12 | |
| 13 | // C Includes |
| 14 | // C++ Includes |
| 15 | // Other libraries and framework includes |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 16 | // Project includes |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 17 | #include "lldb/Breakpoint/StoppointCallbackContext.h" |
| 18 | #include "lldb/Target/DynamicLoader.h" |
| 19 | |
| 20 | #include "DYLDRendezvous.h" |
| 21 | |
| 22 | class AuxVector; |
| 23 | |
| 24 | class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader |
| 25 | { |
| 26 | public: |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 27 | DynamicLoaderPOSIXDYLD(lldb_private::Process *process); |
| 28 | |
| 29 | ~DynamicLoaderPOSIXDYLD() override; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 30 | |
| 31 | static void |
| 32 | Initialize(); |
| 33 | |
| 34 | static void |
| 35 | Terminate(); |
| 36 | |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 37 | static lldb_private::ConstString |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 38 | GetPluginNameStatic(); |
| 39 | |
| 40 | static const char * |
| 41 | GetPluginDescriptionStatic(); |
| 42 | |
| 43 | static lldb_private::DynamicLoader * |
| 44 | CreateInstance(lldb_private::Process *process, bool force); |
| 45 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 46 | //------------------------------------------------------------------ |
| 47 | // DynamicLoader protocol |
| 48 | //------------------------------------------------------------------ |
| 49 | |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 50 | void |
Enrico Granata | 7539b02 | 2015-08-26 21:39:52 +0000 | [diff] [blame] | 51 | DidAttach() override; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 52 | |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 53 | void |
Enrico Granata | 7539b02 | 2015-08-26 21:39:52 +0000 | [diff] [blame] | 54 | DidLaunch() override; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 55 | |
Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 56 | lldb::ThreadPlanSP |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 57 | GetStepThroughTrampolinePlan(lldb_private::Thread &thread, |
Enrico Granata | 7539b02 | 2015-08-26 21:39:52 +0000 | [diff] [blame] | 58 | bool stop_others) override; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 59 | |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 60 | lldb_private::Error |
Enrico Granata | 7539b02 | 2015-08-26 21:39:52 +0000 | [diff] [blame] | 61 | CanLoadImage() override; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 62 | |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 63 | lldb::addr_t |
| 64 | GetThreadLocalData(const lldb::ModuleSP module, const lldb::ThreadSP thread) override; |
Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 65 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 66 | //------------------------------------------------------------------ |
| 67 | // PluginInterface protocol |
| 68 | //------------------------------------------------------------------ |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 69 | lldb_private::ConstString |
Enrico Granata | 7539b02 | 2015-08-26 21:39:52 +0000 | [diff] [blame] | 70 | GetPluginName() override; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 71 | |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 72 | uint32_t |
Enrico Granata | 7539b02 | 2015-08-26 21:39:52 +0000 | [diff] [blame] | 73 | GetPluginVersion() override; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 74 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 75 | protected: |
| 76 | /// Runtime linker rendezvous structure. |
| 77 | DYLDRendezvous m_rendezvous; |
| 78 | |
| 79 | /// Virtual load address of the inferior process. |
| 80 | lldb::addr_t m_load_offset; |
| 81 | |
| 82 | /// Virtual entry address of the inferior process. |
| 83 | lldb::addr_t m_entry_point; |
| 84 | |
| 85 | /// Auxiliary vector of the inferior process. |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 86 | std::unique_ptr<AuxVector> m_auxv; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 87 | |
Michael Sartain | c87e752 | 2013-07-16 21:22:53 +0000 | [diff] [blame] | 88 | /// Rendezvous breakpoint. |
| 89 | lldb::break_id_t m_dyld_bid; |
| 90 | |
Ravitheja Addepally | f546b41 | 2015-10-28 09:47:29 +0000 | [diff] [blame] | 91 | /// Contains AT_SYSINFO_EHDR, which means a vDSO has been |
| 92 | /// mapped to the address space |
| 93 | lldb::addr_t m_vdso_base; |
| 94 | |
Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 95 | /// Loaded module list. (link map for each module) |
| 96 | std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>> m_loaded_modules; |
| 97 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 98 | /// Enables a breakpoint on a function called by the runtime |
| 99 | /// linker each time a module is loaded or unloaded. |
Tamas Berghammer | 42ecef3 | 2015-08-24 10:21:55 +0000 | [diff] [blame] | 100 | virtual void |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 101 | SetRendezvousBreakpoint(); |
| 102 | |
| 103 | /// Callback routine which updates the current list of loaded modules based |
| 104 | /// on the information supplied by the runtime linker. |
| 105 | static bool |
| 106 | RendezvousBreakpointHit(void *baton, |
| 107 | lldb_private::StoppointCallbackContext *context, |
| 108 | lldb::user_id_t break_id, |
| 109 | lldb::user_id_t break_loc_id); |
| 110 | |
| 111 | /// Helper method for RendezvousBreakpointHit. Updates LLDB's current set |
| 112 | /// of loaded modules. |
| 113 | void |
| 114 | RefreshModules(); |
| 115 | |
| 116 | /// Updates the load address of every allocatable section in @p module. |
| 117 | /// |
| 118 | /// @param module The module to traverse. |
| 119 | /// |
Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 120 | /// @param link_map_addr The virtual address of the link map for the @p module. |
| 121 | /// |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 122 | /// @param base_addr The virtual base address @p module is loaded at. |
Tamas Berghammer | 42ecef3 | 2015-08-24 10:21:55 +0000 | [diff] [blame] | 123 | void |
Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 124 | UpdateLoadedSections(lldb::ModuleSP module, |
| 125 | lldb::addr_t link_map_addr, |
Tamas Berghammer | 42ecef3 | 2015-08-24 10:21:55 +0000 | [diff] [blame] | 126 | lldb::addr_t base_addr, |
| 127 | bool base_addr_is_offset) override; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 128 | |
Matt Kopec | d678d30 | 2013-09-13 22:14:50 +0000 | [diff] [blame] | 129 | /// Removes the loaded sections from the target in @p module. |
| 130 | /// |
| 131 | /// @param module The module to traverse. |
Tamas Berghammer | 42ecef3 | 2015-08-24 10:21:55 +0000 | [diff] [blame] | 132 | void |
| 133 | UnloadSections(const lldb::ModuleSP module) override; |
Matt Kopec | d678d30 | 2013-09-13 22:14:50 +0000 | [diff] [blame] | 134 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 135 | /// Resolves the entry point for the current inferior process and sets a |
| 136 | /// breakpoint at that address. |
| 137 | void |
| 138 | ProbeEntry(); |
| 139 | |
| 140 | /// Callback routine invoked when we hit the breakpoint on process entry. |
| 141 | /// |
| 142 | /// This routine is responsible for resolving the load addresses of all |
| 143 | /// dependent modules required by the inferior and setting up the rendezvous |
| 144 | /// breakpoint. |
| 145 | static bool |
| 146 | EntryBreakpointHit(void *baton, |
| 147 | lldb_private::StoppointCallbackContext *context, |
| 148 | lldb::user_id_t break_id, |
| 149 | lldb::user_id_t break_loc_id); |
| 150 | |
| 151 | /// Helper for the entry breakpoint callback. Resolves the load addresses |
| 152 | /// of all dependent modules. |
Tamas Berghammer | 42ecef3 | 2015-08-24 10:21:55 +0000 | [diff] [blame] | 153 | virtual void |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 154 | LoadAllCurrentModules(); |
| 155 | |
| 156 | /// Computes a value for m_load_offset returning the computed address on |
| 157 | /// success and LLDB_INVALID_ADDRESS on failure. |
| 158 | lldb::addr_t |
| 159 | ComputeLoadOffset(); |
| 160 | |
| 161 | /// Computes a value for m_entry_point returning the computed address on |
| 162 | /// success and LLDB_INVALID_ADDRESS on failure. |
| 163 | lldb::addr_t |
| 164 | GetEntryPoint(); |
| 165 | |
Ravitheja Addepally | f546b41 | 2015-10-28 09:47:29 +0000 | [diff] [blame] | 166 | /// Evaluate if Aux vectors contain vDSO information |
| 167 | /// in case they do, read and assign the address to m_vdso_base |
| 168 | void |
| 169 | EvalVdsoStatus(); |
| 170 | |
Oleksiy Vyalov | 6474721 | 2015-03-13 18:44:56 +0000 | [diff] [blame] | 171 | /// Loads Module from inferior process. |
| 172 | void |
| 173 | ResolveExecutableModule(lldb::ModuleSP &module_sp); |
Oleksiy Vyalov | 0ddd41c | 2015-01-07 01:28:37 +0000 | [diff] [blame] | 174 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 175 | private: |
| 176 | DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 177 | }; |
| 178 | |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 179 | #endif // liblldb_DynamicLoaderPOSIXDYLD_h_ |