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_
15 // Other libraries and framework includes
17 #include "lldb/Breakpoint/StoppointCallbackContext.h"
18 #include "lldb/Target/DynamicLoader.h"
20 #include "DYLDRendezvous.h"
24 class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader {
26 DynamicLoaderPOSIXDYLD(lldb_private::Process *process);
28 ~DynamicLoaderPOSIXDYLD() override;
30 static void Initialize();
32 static void Terminate();
34 static lldb_private::ConstString GetPluginNameStatic();
36 static const char *GetPluginDescriptionStatic();
38 static lldb_private::DynamicLoader *
39 CreateInstance(lldb_private::Process *process, bool force);
41 //------------------------------------------------------------------
42 // DynamicLoader protocol
43 //------------------------------------------------------------------
45 void DidAttach() override;
47 void DidLaunch() override;
49 lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
50 bool stop_others) override;
52 lldb_private::Error CanLoadImage() override;
54 lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module,
55 const lldb::ThreadSP thread,
56 lldb::addr_t tls_file_addr) override;
58 //------------------------------------------------------------------
59 // PluginInterface protocol
60 //------------------------------------------------------------------
61 lldb_private::ConstString GetPluginName() override;
63 uint32_t GetPluginVersion() override;
66 /// Runtime linker rendezvous structure.
67 DYLDRendezvous m_rendezvous;
69 /// Virtual load address of the inferior process.
70 lldb::addr_t m_load_offset;
72 /// Virtual entry address of the inferior process.
73 lldb::addr_t m_entry_point;
75 /// Auxiliary vector of the inferior process.
76 std::unique_ptr<AuxVector> m_auxv;
78 /// Rendezvous breakpoint.
79 lldb::break_id_t m_dyld_bid;
81 /// Contains AT_SYSINFO_EHDR, which means a vDSO has been
82 /// mapped to the address space
83 lldb::addr_t m_vdso_base;
85 /// Loaded module list. (link map for each module)
86 std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>>
89 /// Enables a breakpoint on a function called by the runtime
90 /// linker each time a module is loaded or unloaded.
91 virtual void SetRendezvousBreakpoint();
93 /// Callback routine which updates the current list of loaded modules based
94 /// on the information supplied by the runtime linker.
95 static bool RendezvousBreakpointHit(
96 void *baton, lldb_private::StoppointCallbackContext *context,
97 lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
99 /// Helper method for RendezvousBreakpointHit. Updates LLDB's current set
100 /// of loaded modules.
101 void RefreshModules();
103 /// Updates the load address of every allocatable section in @p module.
105 /// @param module The module to traverse.
107 /// @param link_map_addr The virtual address of the link map for the @p
110 /// @param base_addr The virtual base address @p module is loaded at.
111 void UpdateLoadedSections(lldb::ModuleSP module, lldb::addr_t link_map_addr,
112 lldb::addr_t base_addr,
113 bool base_addr_is_offset) override;
115 /// Removes the loaded sections from the target in @p module.
117 /// @param module The module to traverse.
118 void UnloadSections(const lldb::ModuleSP module) override;
120 /// Resolves the entry point for the current inferior process and sets a
121 /// breakpoint at that address.
124 /// Callback routine invoked when we hit the breakpoint on process entry.
126 /// This routine is responsible for resolving the load addresses of all
127 /// dependent modules required by the inferior and setting up the rendezvous
130 EntryBreakpointHit(void *baton,
131 lldb_private::StoppointCallbackContext *context,
132 lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
134 /// Helper for the entry breakpoint callback. Resolves the load addresses
135 /// of all dependent modules.
136 virtual void LoadAllCurrentModules();
138 /// Computes a value for m_load_offset returning the computed address on
139 /// success and LLDB_INVALID_ADDRESS on failure.
140 lldb::addr_t ComputeLoadOffset();
142 /// Computes a value for m_entry_point returning the computed address on
143 /// success and LLDB_INVALID_ADDRESS on failure.
144 lldb::addr_t GetEntryPoint();
146 /// Evaluate if Aux vectors contain vDSO information
147 /// in case they do, read and assign the address to m_vdso_base
148 void EvalVdsoStatus();
150 /// Loads Module from inferior process.
151 void ResolveExecutableModule(lldb::ModuleSP &module_sp);
153 bool AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override;
156 DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD);
159 #endif // liblldb_DynamicLoaderPOSIXDYLD_h_