Target.h revision 24943d2ee8bfaa7cf5893e4709143924157a5c1e
1//===-- Target.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_Target_h_
11#define liblldb_Target_h_
12
13// C Includes
14// C++ Includes
15
16// Other libraries and framework includes
17// Project includes
18#include "lldb/lldb-private.h"
19#include "lldb/Breakpoint/BreakpointList.h"
20#include "lldb/Breakpoint/BreakpointLocationCollection.h"
21#include "lldb/Core/Broadcaster.h"
22#include "lldb/Core/Event.h"
23#include "lldb/Core/ModuleList.h"
24#include "lldb/Symbol/SymbolContext.h"
25#include "lldb/Target/ABI.h"
26#include "lldb/Target/ExecutionContextScope.h"
27#include "lldb/Target/PathMappingList.h"
28
29#include "lldb/API/SBTarget.h"
30
31namespace lldb_private {
32
33class Target :
34    public Broadcaster,
35    public ExecutionContextScope
36{
37public:
38    friend class TargetList;
39
40    //------------------------------------------------------------------
41    /// Broadcaster event bits definitions.
42    //------------------------------------------------------------------
43    enum
44    {
45        eBroadcastBitBreakpointChanged  = (1 << 0),
46        eBroadcastBitModulesLoaded      = (1 << 1),
47        eBroadcastBitModulesUnloaded    = (1 << 2)
48    };
49
50    lldb::ModuleSP
51    GetSharedModule (const FileSpec& file_spec,
52                     const ArchSpec& arch,
53                     const UUID *uuid = NULL,
54                     const ConstString *object_name = NULL,
55                     off_t object_offset = 0,
56                     Error *error_ptr = NULL);
57private:
58    //------------------------------------------------------------------
59    /// Construct with optional file and arch.
60    ///
61    /// This member is private. Clients must use
62    /// TargetList::CreateTarget(const FileSpec*, const ArchSpec*)
63    /// so all targets can be tracked from the central target list.
64    ///
65    /// @see TargetList::CreateTarget(const FileSpec*, const ArchSpec*)
66    //------------------------------------------------------------------
67    Target();
68
69public:
70    ~Target();
71
72    void
73    DeleteCurrentProcess ();
74
75    //------------------------------------------------------------------
76    /// Dump a description of this object to a Stream.
77    ///
78    /// Dump a description of the contents of this object to the
79    /// supplied stream \a s. The dumped content will be only what has
80    /// been loaded or parsed up to this point at which this function
81    /// is called, so this is a good way to see what has been parsed
82    /// in a target.
83    ///
84    /// @param[in] s
85    ///     The stream to which to dump the object descripton.
86    //------------------------------------------------------------------
87    void
88    Dump (Stream *s);
89
90    const lldb::ProcessSP &
91    CreateProcess (Listener &listener, const char *plugin_name = NULL);
92
93    const lldb::ProcessSP &
94    GetProcessSP () const;
95
96    lldb::TargetSP
97    GetSP();
98
99
100    //------------------------------------------------------------------
101    // This part handles the breakpoints.
102    //------------------------------------------------------------------
103
104    BreakpointList &
105    GetBreakpointList(bool internal = false);
106
107    const BreakpointList &
108    GetBreakpointList(bool internal = false) const;
109
110    lldb::BreakpointSP
111    GetBreakpointByID (lldb::break_id_t break_id);
112
113    // Use this to create a file and line breakpoint to a given module or all module it is NULL
114    lldb::BreakpointSP
115    CreateBreakpoint (const FileSpec *containingModule,
116                      const FileSpec &file,
117                      uint32_t line_no,
118                      bool check_inlines,
119                      bool internal = false);
120
121    // Use this to create a breakpoint from a load address
122    lldb::BreakpointSP
123    CreateBreakpoint (lldb::addr_t load_addr,
124                      bool internal = false);
125
126    // Use this to create Address breakpoints:
127    lldb::BreakpointSP
128    CreateBreakpoint (Address &addr,
129                      bool internal = false);
130
131    // Use this to create a function breakpoint by regexp in containingModule, or all modules if it is NULL
132    lldb::BreakpointSP
133    CreateBreakpoint (FileSpec *containingModule,
134                      RegularExpression &func_regexp,
135                      bool internal = false);
136
137    // Use this to create a function breakpoint by name in containingModule, or all modules if it is NULL
138    lldb::BreakpointSP
139    CreateBreakpoint (FileSpec *containingModule,
140                      const char *func_name,
141                      bool internal = false);
142
143    // Use this to create a general breakpoint:
144    lldb::BreakpointSP
145    CreateBreakpoint (lldb::SearchFilterSP &filter_sp,
146                      lldb::BreakpointResolverSP &resolver_sp,
147                      bool internal = false);
148
149    void
150    RemoveAllBreakpoints (bool internal_also = false);
151
152    void
153    DisableAllBreakpoints (bool internal_also = false);
154
155    void
156    EnableAllBreakpoints (bool internal_also = false);
157
158    bool
159    DisableBreakpointByID (lldb::break_id_t break_id);
160
161    bool
162    EnableBreakpointByID (lldb::break_id_t break_id);
163
164    bool
165    RemoveBreakpointByID (lldb::break_id_t break_id);
166
167    void
168    ModulesDidLoad (ModuleList &module_list);
169
170    void
171    ModulesDidUnload (ModuleList &module_list);
172
173protected:
174    void
175    ModuleAdded (lldb::ModuleSP &module_sp);
176
177    void
178    ModuleUpdated (lldb::ModuleSP &old_module_sp, lldb::ModuleSP &new_module_sp);
179
180public:
181    //------------------------------------------------------------------
182    /// Gets the module for the main executable.
183    ///
184    /// Each process has a notion of a main executable that is the file
185    /// that will be executed or attached to. Executable files can have
186    /// dependent modules that are discovered from the object files, or
187    /// discovered at runtime as things are dynamically loaded.
188    ///
189    /// @return
190    ///     The shared pointer to the executable module which can
191    ///     contains a NULL Module object if no executable has been
192    ///     set.
193    ///
194    /// @see DynamicLoader
195    /// @see ObjectFile::GetDependentModules (FileSpecList&)
196    /// @see Process::SetExecutableModule(lldb::ModuleSP&)
197    //------------------------------------------------------------------
198    lldb::ModuleSP
199    GetExecutableModule ();
200
201    //------------------------------------------------------------------
202    /// Set the main executable module.
203    ///
204    /// Each process has a notion of a main executable that is the file
205    /// that will be executed or attached to. Executable files can have
206    /// dependent modules that are discovered from the object files, or
207    /// discovered at runtime as things are dynamically loaded.
208    ///
209    /// Setting the executable causes any of the current dependant
210    /// image information to be cleared and replaced with the static
211    /// dependent image information found by calling
212    /// ObjectFile::GetDependentModules (FileSpecList&) on the main
213    /// executable and any modules on which it depends. Calling
214    /// Process::GetImages() will return the newly found images that
215    /// were obtained from all of the object files.
216    ///
217    /// @param[in] module_sp
218    ///     A shared pointer reference to the module that will become
219    ///     the main executable for this process.
220    ///
221    /// @param[in] get_dependent_files
222    ///     If \b true then ask the object files to track down any
223    ///     known dependent files.
224    ///
225    /// @see ObjectFile::GetDependentModules (FileSpecList&)
226    /// @see Process::GetImages()
227    //------------------------------------------------------------------
228    void
229    SetExecutableModule (lldb::ModuleSP& module_sp, bool get_dependent_files);
230
231    //------------------------------------------------------------------
232    /// Get accessor for the images for this process.
233    ///
234    /// Each process has a notion of a main executable that is the file
235    /// that will be executed or attached to. Executable files can have
236    /// dependent modules that are discovered from the object files, or
237    /// discovered at runtime as things are dynamically loaded. After
238    /// a main executable has been set, the images will contain a list
239    /// of all the files that the executable depends upon as far as the
240    /// object files know. These images will usually contain valid file
241    /// virtual addresses only. When the process is launched or attached
242    /// to, the DynamicLoader plug-in will discover where these images
243    /// were loaded in memory and will resolve the load virtual
244    /// addresses is each image, and also in images that are loaded by
245    /// code.
246    ///
247    /// @return
248    ///     A list of Module objects in a module list.
249    //------------------------------------------------------------------
250    ModuleList&
251    GetImages ();
252
253    ArchSpec
254    GetArchitecture () const;
255
256    bool
257    GetTargetTriple (ConstString &target_triple);
258
259    size_t
260    ReadMemory (lldb::AddressType addr_type,
261                lldb::addr_t addr,
262                void *buf,
263                size_t size,
264                Error &error,
265                ObjectFile* objfile = NULL);
266
267    //------------------------------------------------------------------
268    // lldb::ExecutionContextScope pure virtual functions
269    //------------------------------------------------------------------
270    virtual Target *
271    CalculateTarget ();
272
273    virtual Process *
274    CalculateProcess ();
275
276    virtual Thread *
277    CalculateThread ();
278
279    virtual StackFrame *
280    CalculateStackFrame ();
281
282    virtual void
283    Calculate (ExecutionContext &exe_ctx);
284
285    PathMappingList &
286    GetImageSearchPathList ();
287
288    ClangASTContext *
289    GetScratchClangASTContext();
290
291protected:
292    friend class lldb::SBTarget;
293
294    //------------------------------------------------------------------
295    // Member variables.
296    //------------------------------------------------------------------
297    ModuleList      m_images;           ///< The list of images for this process (shared libraries and anything dynamically loaded).
298    BreakpointList  m_breakpoint_list;
299    BreakpointList  m_internal_breakpoint_list;
300    // We want to tightly control the process destruction process so
301    // we can correctly tear down everything that we need to, so the only
302    // class that knows about the process lifespan is this target class.
303    lldb::ProcessSP m_process_sp;
304    ConstString     m_triple;       ///< The target triple ("x86_64-apple-darwin10")
305    lldb::SearchFilterSP  m_search_filter_sp;
306    PathMappingList m_image_search_paths;
307    std::auto_ptr<ClangASTContext> m_scratch_ast_context_ap;
308    //------------------------------------------------------------------
309    // Methods.
310    //------------------------------------------------------------------
311    lldb::SearchFilterSP
312    GetSearchFilterForModule (const FileSpec *containingModule);
313
314    static void
315    ImageSearchPathsChanged (const PathMappingList &path_list,
316                             void *baton);
317
318private:
319    DISALLOW_COPY_AND_ASSIGN (Target);
320};
321
322} // namespace lldb_private
323
324#endif  // liblldb_Target_h_
325