DynamicLoaderPOSIXDYLD.h revision 269024
1//===-- DynamicLoaderPOSIX.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_DynamicLoaderPOSIX_H_
11#define liblldb_DynamicLoaderPOSIX_H_
12
13// C Includes
14// C++ Includes
15// Other libraries and framework includes
16#include "lldb/Breakpoint/StoppointCallbackContext.h"
17#include "lldb/Target/DynamicLoader.h"
18
19#include "DYLDRendezvous.h"
20
21class AuxVector;
22
23class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader
24{
25public:
26
27    static void
28    Initialize();
29
30    static void
31    Terminate();
32
33    static lldb_private::ConstString
34    GetPluginNameStatic();
35
36    static const char *
37    GetPluginDescriptionStatic();
38
39    static lldb_private::DynamicLoader *
40    CreateInstance(lldb_private::Process *process, bool force);
41
42    DynamicLoaderPOSIXDYLD(lldb_private::Process *process);
43
44    virtual
45    ~DynamicLoaderPOSIXDYLD();
46
47    //------------------------------------------------------------------
48    // DynamicLoader protocol
49    //------------------------------------------------------------------
50
51    virtual void
52    DidAttach();
53
54    virtual void
55    DidLaunch();
56
57    virtual lldb::ThreadPlanSP
58    GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
59                                 bool stop_others);
60
61    virtual lldb_private::Error
62    CanLoadImage();
63
64    virtual lldb::addr_t
65    GetThreadLocalData (const lldb::ModuleSP module, const lldb::ThreadSP thread);
66
67    //------------------------------------------------------------------
68    // PluginInterface protocol
69    //------------------------------------------------------------------
70    virtual lldb_private::ConstString
71    GetPluginName();
72
73    virtual uint32_t
74    GetPluginVersion();
75
76    virtual void
77    GetPluginCommandHelp(const char *command, lldb_private::Stream *strm);
78
79    virtual lldb_private::Error
80    ExecutePluginCommand(lldb_private::Args &command, lldb_private::Stream *strm);
81
82    virtual lldb_private::Log *
83    EnablePluginLogging(lldb_private::Stream *strm, lldb_private::Args &command);
84
85protected:
86    /// Runtime linker rendezvous structure.
87    DYLDRendezvous m_rendezvous;
88
89    /// Virtual load address of the inferior process.
90    lldb::addr_t m_load_offset;
91
92    /// Virtual entry address of the inferior process.
93    lldb::addr_t m_entry_point;
94
95    /// Auxiliary vector of the inferior process.
96    std::unique_ptr<AuxVector> m_auxv;
97
98    /// Rendezvous breakpoint.
99    lldb::break_id_t m_dyld_bid;
100
101    /// Loaded module list. (link map for each module)
102    std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>> m_loaded_modules;
103
104    /// Enables a breakpoint on a function called by the runtime
105    /// linker each time a module is loaded or unloaded.
106    void
107    SetRendezvousBreakpoint();
108
109    /// Callback routine which updates the current list of loaded modules based
110    /// on the information supplied by the runtime linker.
111    static bool
112    RendezvousBreakpointHit(void *baton,
113                            lldb_private::StoppointCallbackContext *context,
114                            lldb::user_id_t break_id,
115                            lldb::user_id_t break_loc_id);
116
117    /// Helper method for RendezvousBreakpointHit.  Updates LLDB's current set
118    /// of loaded modules.
119    void
120    RefreshModules();
121
122    /// Updates the load address of every allocatable section in @p module.
123    ///
124    /// @param module The module to traverse.
125    ///
126    /// @param link_map_addr The virtual address of the link map for the @p module.
127    ///
128    /// @param base_addr The virtual base address @p module is loaded at.
129    virtual void
130    UpdateLoadedSections(lldb::ModuleSP module,
131                         lldb::addr_t link_map_addr,
132                         lldb::addr_t base_addr);
133
134    /// Removes the loaded sections from the target in @p module.
135    ///
136    /// @param module The module to traverse.
137    virtual void
138    UnloadSections(const lldb::ModuleSP module);
139
140    /// Resolves the entry point for the current inferior process and sets a
141    /// breakpoint at that address.
142    void
143    ProbeEntry();
144
145    /// Callback routine invoked when we hit the breakpoint on process entry.
146    ///
147    /// This routine is responsible for resolving the load addresses of all
148    /// dependent modules required by the inferior and setting up the rendezvous
149    /// breakpoint.
150    static bool
151    EntryBreakpointHit(void *baton,
152                       lldb_private::StoppointCallbackContext *context,
153                       lldb::user_id_t break_id,
154                       lldb::user_id_t break_loc_id);
155
156    /// Helper for the entry breakpoint callback.  Resolves the load addresses
157    /// of all dependent modules.
158    void
159    LoadAllCurrentModules();
160
161    /// Computes a value for m_load_offset returning the computed address on
162    /// success and LLDB_INVALID_ADDRESS on failure.
163    lldb::addr_t
164    ComputeLoadOffset();
165
166    /// Computes a value for m_entry_point returning the computed address on
167    /// success and LLDB_INVALID_ADDRESS on failure.
168    lldb::addr_t
169    GetEntryPoint();
170
171private:
172    DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD);
173};
174
175#endif  // liblldb_DynamicLoaderPOSIXDYLD_H_
176