1 //===-- DynamicLoaderPOSIXDYLD.h --------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_DynamicLoaderPOSIXDYLD_h_
11 #define liblldb_DynamicLoaderPOSIXDYLD_h_
18 // Other libraries and framework includes
20 #include "DYLDRendezvous.h"
21 #include "lldb/Breakpoint/StoppointCallbackContext.h"
22 #include "lldb/Core/ModuleList.h"
23 #include "lldb/Target/DynamicLoader.h"
27 class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader {
29 DynamicLoaderPOSIXDYLD(lldb_private::Process *process);
31 ~DynamicLoaderPOSIXDYLD() override;
33 static void Initialize();
35 static void Terminate();
37 static lldb_private::ConstString GetPluginNameStatic();
39 static const char *GetPluginDescriptionStatic();
41 static lldb_private::DynamicLoader *
42 CreateInstance(lldb_private::Process *process, bool force);
44 //------------------------------------------------------------------
45 // DynamicLoader protocol
46 //------------------------------------------------------------------
48 void DidAttach() override;
50 void DidLaunch() override;
52 lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
53 bool stop_others) override;
55 lldb_private::Status CanLoadImage() override;
57 lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module,
58 const lldb::ThreadSP thread,
59 lldb::addr_t tls_file_addr) override;
61 //------------------------------------------------------------------
62 // PluginInterface protocol
63 //------------------------------------------------------------------
64 lldb_private::ConstString GetPluginName() override;
66 uint32_t GetPluginVersion() override;
69 /// Runtime linker rendezvous structure.
70 DYLDRendezvous m_rendezvous;
72 /// Virtual load address of the inferior process.
73 lldb::addr_t m_load_offset;
75 /// Virtual entry address of the inferior process.
76 lldb::addr_t m_entry_point;
78 /// Auxiliary vector of the inferior process.
79 std::unique_ptr<AuxVector> m_auxv;
81 /// Rendezvous breakpoint.
82 lldb::break_id_t m_dyld_bid;
84 /// Contains AT_SYSINFO_EHDR, which means a vDSO has been
85 /// mapped to the address space
86 lldb::addr_t m_vdso_base;
88 /// Loaded module list. (link map for each module)
89 std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>>
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();
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);
102 /// Helper method for RendezvousBreakpointHit. Updates LLDB's current set
103 /// of loaded modules.
104 void RefreshModules();
106 /// Updates the load address of every allocatable section in @p module.
108 /// @param module The module to traverse.
110 /// @param link_map_addr The virtual address of the link map for the @p
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;
118 /// Removes the loaded sections from the target in @p module.
120 /// @param module The module to traverse.
121 void UnloadSections(const lldb::ModuleSP module) override;
123 /// Resolves the entry point for the current inferior process and sets a
124 /// breakpoint at that address.
127 /// Callback routine invoked when we hit the breakpoint on process entry.
129 /// This routine is responsible for resolving the load addresses of all
130 /// dependent modules required by the inferior and setting up the rendezvous
133 EntryBreakpointHit(void *baton,
134 lldb_private::StoppointCallbackContext *context,
135 lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
137 /// Helper for the entry breakpoint callback. Resolves the load addresses
138 /// of all dependent modules.
139 virtual void LoadAllCurrentModules();
141 void LoadVDSO(lldb_private::ModuleList &modules);
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();
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();
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();
155 /// Loads Module from inferior process.
156 void ResolveExecutableModule(lldb::ModuleSP &module_sp);
158 bool AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override;
161 DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD);
164 #endif // liblldb_DynamicLoaderPOSIXDYLD_h_