Target.h revision 12bec71b323dc520f0e985a86e09c4712559e115
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(Debugger &debugger);
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                      uint32_t func_name_type_mask,
142                      bool internal = false);
143
144    // Use this to create a general breakpoint:
145    lldb::BreakpointSP
146    CreateBreakpoint (lldb::SearchFilterSP &filter_sp,
147                      lldb::BreakpointResolverSP &resolver_sp,
148                      bool internal = false);
149
150    void
151    RemoveAllBreakpoints (bool internal_also = false);
152
153    void
154    DisableAllBreakpoints (bool internal_also = false);
155
156    void
157    EnableAllBreakpoints (bool internal_also = false);
158
159    bool
160    DisableBreakpointByID (lldb::break_id_t break_id);
161
162    bool
163    EnableBreakpointByID (lldb::break_id_t break_id);
164
165    bool
166    RemoveBreakpointByID (lldb::break_id_t break_id);
167
168    void
169    ModulesDidLoad (ModuleList &module_list);
170
171    void
172    ModulesDidUnload (ModuleList &module_list);
173
174protected:
175    void
176    ModuleAdded (lldb::ModuleSP &module_sp);
177
178    void
179    ModuleUpdated (lldb::ModuleSP &old_module_sp, lldb::ModuleSP &new_module_sp);
180
181public:
182    //------------------------------------------------------------------
183    /// Gets the module for the main executable.
184    ///
185    /// Each process has a notion of a main executable that is the file
186    /// that will be executed or attached to. Executable files can have
187    /// dependent modules that are discovered from the object files, or
188    /// discovered at runtime as things are dynamically loaded.
189    ///
190    /// @return
191    ///     The shared pointer to the executable module which can
192    ///     contains a NULL Module object if no executable has been
193    ///     set.
194    ///
195    /// @see DynamicLoader
196    /// @see ObjectFile::GetDependentModules (FileSpecList&)
197    /// @see Process::SetExecutableModule(lldb::ModuleSP&)
198    //------------------------------------------------------------------
199    lldb::ModuleSP
200    GetExecutableModule ();
201
202    //------------------------------------------------------------------
203    /// Set the main executable module.
204    ///
205    /// Each process has a notion of a main executable that is the file
206    /// that will be executed or attached to. Executable files can have
207    /// dependent modules that are discovered from the object files, or
208    /// discovered at runtime as things are dynamically loaded.
209    ///
210    /// Setting the executable causes any of the current dependant
211    /// image information to be cleared and replaced with the static
212    /// dependent image information found by calling
213    /// ObjectFile::GetDependentModules (FileSpecList&) on the main
214    /// executable and any modules on which it depends. Calling
215    /// Process::GetImages() will return the newly found images that
216    /// were obtained from all of the object files.
217    ///
218    /// @param[in] module_sp
219    ///     A shared pointer reference to the module that will become
220    ///     the main executable for this process.
221    ///
222    /// @param[in] get_dependent_files
223    ///     If \b true then ask the object files to track down any
224    ///     known dependent files.
225    ///
226    /// @see ObjectFile::GetDependentModules (FileSpecList&)
227    /// @see Process::GetImages()
228    //------------------------------------------------------------------
229    void
230    SetExecutableModule (lldb::ModuleSP& module_sp, bool get_dependent_files);
231
232    //------------------------------------------------------------------
233    /// Get accessor for the images for this process.
234    ///
235    /// Each process has a notion of a main executable that is the file
236    /// that will be executed or attached to. Executable files can have
237    /// dependent modules that are discovered from the object files, or
238    /// discovered at runtime as things are dynamically loaded. After
239    /// a main executable has been set, the images will contain a list
240    /// of all the files that the executable depends upon as far as the
241    /// object files know. These images will usually contain valid file
242    /// virtual addresses only. When the process is launched or attached
243    /// to, the DynamicLoader plug-in will discover where these images
244    /// were loaded in memory and will resolve the load virtual
245    /// addresses is each image, and also in images that are loaded by
246    /// code.
247    ///
248    /// @return
249    ///     A list of Module objects in a module list.
250    //------------------------------------------------------------------
251    ModuleList&
252    GetImages ();
253
254    ArchSpec
255    GetArchitecture () const;
256
257    Debugger &
258    GetDebugger ()
259    {
260        return m_debugger;
261    }
262
263    bool
264    GetTargetTriple (ConstString &target_triple);
265
266    size_t
267    ReadMemory (lldb::AddressType addr_type,
268                lldb::addr_t addr,
269                void *buf,
270                size_t size,
271                Error &error,
272                ObjectFile* objfile = NULL);
273
274    //------------------------------------------------------------------
275    // lldb::ExecutionContextScope pure virtual functions
276    //------------------------------------------------------------------
277    virtual Target *
278    CalculateTarget ();
279
280    virtual Process *
281    CalculateProcess ();
282
283    virtual Thread *
284    CalculateThread ();
285
286    virtual StackFrame *
287    CalculateStackFrame ();
288
289    virtual void
290    Calculate (ExecutionContext &exe_ctx);
291
292    PathMappingList &
293    GetImageSearchPathList ();
294
295    ClangASTContext *
296    GetScratchClangASTContext();
297
298protected:
299    friend class lldb::SBTarget;
300
301    //------------------------------------------------------------------
302    // Member variables.
303    //------------------------------------------------------------------
304    Debugger &      m_debugger;
305    ModuleList      m_images;           ///< The list of images for this process (shared libraries and anything dynamically loaded).
306    BreakpointList  m_breakpoint_list;
307    BreakpointList  m_internal_breakpoint_list;
308    // We want to tightly control the process destruction process so
309    // we can correctly tear down everything that we need to, so the only
310    // class that knows about the process lifespan is this target class.
311    lldb::ProcessSP m_process_sp;
312    ConstString     m_triple;       ///< The target triple ("x86_64-apple-darwin10")
313    lldb::SearchFilterSP  m_search_filter_sp;
314    PathMappingList m_image_search_paths;
315    std::auto_ptr<ClangASTContext> m_scratch_ast_context_ap;
316    //------------------------------------------------------------------
317    // Methods.
318    //------------------------------------------------------------------
319    lldb::SearchFilterSP
320    GetSearchFilterForModule (const FileSpec *containingModule);
321
322    static void
323    ImageSearchPathsChanged (const PathMappingList &path_list,
324                             void *baton);
325
326private:
327    DISALLOW_COPY_AND_ASSIGN (Target);
328};
329
330} // namespace lldb_private
331
332#endif  // liblldb_Target_h_
333