blob: cb97bbf43ba925b85999e70107e72d89988d741c [file] [log] [blame]
Eugene Zelenko4c3f2b92015-10-21 01:03:30 +00001//===-- DynamicLoaderPOSIXDYLD.h --------------------------------*- C++ -*-===//
Johnny Chen9ed5b492012-01-05 21:48:15 +00002//
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 Zelenko4c3f2b92015-10-21 01:03:30 +000010#ifndef liblldb_DynamicLoaderPOSIXDYLD_h_
11#define liblldb_DynamicLoaderPOSIXDYLD_h_
Johnny Chen9ed5b492012-01-05 21:48:15 +000012
13// C Includes
14// C++ Includes
15// Other libraries and framework includes
Eugene Zelenko4c3f2b92015-10-21 01:03:30 +000016// Project includes
Johnny Chen9ed5b492012-01-05 21:48:15 +000017#include "lldb/Breakpoint/StoppointCallbackContext.h"
18#include "lldb/Target/DynamicLoader.h"
19
20#include "DYLDRendezvous.h"
21
22class AuxVector;
23
24class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader
25{
26public:
Eugene Zelenko4c3f2b92015-10-21 01:03:30 +000027 DynamicLoaderPOSIXDYLD(lldb_private::Process *process);
28
29 ~DynamicLoaderPOSIXDYLD() override;
Johnny Chen9ed5b492012-01-05 21:48:15 +000030
31 static void
32 Initialize();
33
34 static void
35 Terminate();
36
Greg Clayton57abc5d2013-05-10 21:47:16 +000037 static lldb_private::ConstString
Johnny Chen9ed5b492012-01-05 21:48:15 +000038 GetPluginNameStatic();
39
40 static const char *
41 GetPluginDescriptionStatic();
42
43 static lldb_private::DynamicLoader *
44 CreateInstance(lldb_private::Process *process, bool force);
45
Johnny Chen9ed5b492012-01-05 21:48:15 +000046 //------------------------------------------------------------------
47 // DynamicLoader protocol
48 //------------------------------------------------------------------
49
Eugene Zelenko4c3f2b92015-10-21 01:03:30 +000050 void
Enrico Granata7539b022015-08-26 21:39:52 +000051 DidAttach() override;
Johnny Chen9ed5b492012-01-05 21:48:15 +000052
Eugene Zelenko4c3f2b92015-10-21 01:03:30 +000053 void
Enrico Granata7539b022015-08-26 21:39:52 +000054 DidLaunch() override;
Johnny Chen9ed5b492012-01-05 21:48:15 +000055
Greg Clayton6071e6f2015-08-26 22:57:51 +000056 lldb::ThreadPlanSP
Johnny Chen9ed5b492012-01-05 21:48:15 +000057 GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
Enrico Granata7539b022015-08-26 21:39:52 +000058 bool stop_others) override;
Johnny Chen9ed5b492012-01-05 21:48:15 +000059
Eugene Zelenko4c3f2b92015-10-21 01:03:30 +000060 lldb_private::Error
Enrico Granata7539b022015-08-26 21:39:52 +000061 CanLoadImage() override;
Johnny Chen9ed5b492012-01-05 21:48:15 +000062
Eugene Zelenko4c3f2b92015-10-21 01:03:30 +000063 lldb::addr_t
64 GetThreadLocalData(const lldb::ModuleSP module, const lldb::ThreadSP thread) override;
Richard Mitton0a558352013-10-17 21:14:00 +000065
Johnny Chen9ed5b492012-01-05 21:48:15 +000066 //------------------------------------------------------------------
67 // PluginInterface protocol
68 //------------------------------------------------------------------
Eugene Zelenko4c3f2b92015-10-21 01:03:30 +000069 lldb_private::ConstString
Enrico Granata7539b022015-08-26 21:39:52 +000070 GetPluginName() override;
Johnny Chen9ed5b492012-01-05 21:48:15 +000071
Eugene Zelenko4c3f2b92015-10-21 01:03:30 +000072 uint32_t
Enrico Granata7539b022015-08-26 21:39:52 +000073 GetPluginVersion() override;
Johnny Chen9ed5b492012-01-05 21:48:15 +000074
Johnny Chen9ed5b492012-01-05 21:48:15 +000075protected:
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 Clayton7b0992d2013-04-18 22:45:39 +000086 std::unique_ptr<AuxVector> m_auxv;
Johnny Chen9ed5b492012-01-05 21:48:15 +000087
Michael Sartainc87e7522013-07-16 21:22:53 +000088 /// Rendezvous breakpoint.
89 lldb::break_id_t m_dyld_bid;
90
Ravitheja Addepallyf546b412015-10-28 09:47:29 +000091 /// 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 Mitton0a558352013-10-17 21:14:00 +000095 /// 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 Chen9ed5b492012-01-05 21:48:15 +000098 /// Enables a breakpoint on a function called by the runtime
99 /// linker each time a module is loaded or unloaded.
Tamas Berghammer42ecef32015-08-24 10:21:55 +0000100 virtual void
Johnny Chen9ed5b492012-01-05 21:48:15 +0000101 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 Mitton0a558352013-10-17 21:14:00 +0000120 /// @param link_map_addr The virtual address of the link map for the @p module.
121 ///
Johnny Chen9ed5b492012-01-05 21:48:15 +0000122 /// @param base_addr The virtual base address @p module is loaded at.
Tamas Berghammer42ecef32015-08-24 10:21:55 +0000123 void
Richard Mitton0a558352013-10-17 21:14:00 +0000124 UpdateLoadedSections(lldb::ModuleSP module,
125 lldb::addr_t link_map_addr,
Tamas Berghammer42ecef32015-08-24 10:21:55 +0000126 lldb::addr_t base_addr,
127 bool base_addr_is_offset) override;
Johnny Chen9ed5b492012-01-05 21:48:15 +0000128
Matt Kopecd678d302013-09-13 22:14:50 +0000129 /// Removes the loaded sections from the target in @p module.
130 ///
131 /// @param module The module to traverse.
Tamas Berghammer42ecef32015-08-24 10:21:55 +0000132 void
133 UnloadSections(const lldb::ModuleSP module) override;
Matt Kopecd678d302013-09-13 22:14:50 +0000134
Johnny Chen9ed5b492012-01-05 21:48:15 +0000135 /// 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 Berghammer42ecef32015-08-24 10:21:55 +0000153 virtual void
Johnny Chen9ed5b492012-01-05 21:48:15 +0000154 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 Addepallyf546b412015-10-28 09:47:29 +0000166 /// 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 Vyalov64747212015-03-13 18:44:56 +0000171 /// Loads Module from inferior process.
172 void
173 ResolveExecutableModule(lldb::ModuleSP &module_sp);
Oleksiy Vyalov0ddd41c2015-01-07 01:28:37 +0000174
Johnny Chen9ed5b492012-01-05 21:48:15 +0000175private:
176 DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD);
Johnny Chen9ed5b492012-01-05 21:48:15 +0000177};
178
Eugene Zelenko4c3f2b92015-10-21 01:03:30 +0000179#endif // liblldb_DynamicLoaderPOSIXDYLD_h_