SBTarget.h revision 917c000e77fcf657099f59085d6436d179a39ea4
1//===-- SBTarget.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 LLDB_SBTarget_h_
11#define LLDB_SBTarget_h_
12
13#include "lldb/API/SBDefines.h"
14#include "lldb/API/SBBroadcaster.h"
15#include "lldb/API/SBFileSpec.h"
16
17namespace lldb {
18
19class SBBreakpoint;
20
21class SBTarget
22{
23public:
24    //------------------------------------------------------------------
25    // Broadcaster bits.
26    //------------------------------------------------------------------
27    enum
28    {
29        eBroadcastBitBreakpointChanged  = (1 << 0),
30        eBroadcastBitModulesLoaded      = (1 << 1),
31        eBroadcastBitModulesUnloaded    = (1 << 2)
32    };
33
34    //------------------------------------------------------------------
35    // Constructors
36    //------------------------------------------------------------------
37    SBTarget ();
38
39    SBTarget (const lldb::SBTarget& rhs);
40
41#ifndef SWIG
42    const lldb::SBTarget&
43    operator = (const lldb::SBTarget& rhs);
44#endif
45
46    //------------------------------------------------------------------
47    // Destructor
48    //------------------------------------------------------------------
49    ~SBTarget();
50
51    bool
52    IsValid() const;
53
54    lldb::SBProcess
55    GetProcess ();
56
57    //------------------------------------------------------------------
58    /// Launch a new process.
59    ///
60    /// Launch a new process by spawning a new process using the
61    /// target object's executable module's file as the file to launch.
62    /// Arguments are given in \a argv, and the environment variables
63    /// are in \a envp. Standard input and output files can be
64    /// optionally re-directed to \a stdin_path, \a stdout_path, and
65    /// \a stderr_path.
66    ///
67    /// @param[in] listener
68    ///     An optional listener that will receive all process events.
69    ///     If \a listener is valid then \a listener will listen to all
70    ///     process events. If not valid, then this target's debugger
71    ///     (SBTarget::GetDebugger()) will listen to all process events.
72    ///
73    /// @param[in] argv
74    ///     The argument array.
75    ///
76    /// @param[in] envp
77    ///     The environment array.
78    ///
79    /// @param[in] launch_flags
80    ///     Flags to modify the launch (@see lldb::LaunchFlags)
81    ///
82    /// @param[in] stdin_path
83    ///     The path to use when re-directing the STDIN of the new
84    ///     process. If all stdXX_path arguments are NULL, a pseudo
85    ///     terminal will be used.
86    ///
87    /// @param[in] stdout_path
88    ///     The path to use when re-directing the STDOUT of the new
89    ///     process. If all stdXX_path arguments are NULL, a pseudo
90    ///     terminal will be used.
91    ///
92    /// @param[in] stderr_path
93    ///     The path to use when re-directing the STDERR of the new
94    ///     process. If all stdXX_path arguments are NULL, a pseudo
95    ///     terminal will be used.
96    ///
97    /// @param[in] working_directory
98    ///     The working directory to have the child process run in
99    ///
100    /// @param[in] launch_flags
101    ///     Some launch options specified by logical OR'ing
102    ///     lldb::LaunchFlags enumeration values together.
103    ///
104    /// @param[out]
105    ///     An error object. Contains the reason if there is some failure.
106    ///
107    /// @return
108    ///      A process object for the newly created process.
109    //------------------------------------------------------------------
110    lldb::SBProcess
111    Launch (SBListener &listener,
112            char const **argv,
113            char const **envp,
114            const char *stdin_path,
115            const char *stdout_path,
116            const char *stderr_path,
117            const char *working_directory,
118            uint32_t launch_flags,   // See LaunchFlags
119            bool stop_at_entry,
120            lldb::SBError& error);
121
122
123    //------------------------------------------------------------------
124    /// Launch a new process with sensible defaults.
125    ///
126    /// @param[in] argv
127    ///     The argument array.
128    ///
129    /// @param[in] envp
130    ///     The environment array.
131    ///
132    /// @param[in] working_directory
133    ///     The working directory to have the child process run in
134    ///
135    /// Default: listener
136    ///     Set to the target's debugger (SBTarget::GetDebugger())
137    ///
138    /// Default: launch_flags
139    ///     Empty launch flags
140    ///
141    /// Default: stdin_path
142    /// Default: stdout_path
143    /// Default: stderr_path
144    ///     A pseudo terminal will be used.
145    ///
146    /// @return
147    ///      A process object for the newly created process.
148    //------------------------------------------------------------------
149    lldb::SBProcess
150    LaunchSimple (const char **argv,
151                  const char **envp,
152                  const char *working_directory);
153
154    lldb::SBProcess
155    AttachToProcessWithID (SBListener &listener,
156                           lldb::pid_t pid, // The process ID to attach to
157                           lldb::SBError& error); // An error explaining what went wrong if attach fails
158
159    lldb::SBProcess
160    AttachToProcessWithName (SBListener &listener,
161                             const char *name,  // basename of process to attach to
162                             bool wait_for,     // if true wait for a new instance of "name" to be launched
163                             lldb::SBError& error);   // An error explaining what went wrong if attach fails
164
165    lldb::SBProcess
166    ConnectRemote (SBListener &listener,
167                   const char *url,
168                   const char *plugin_name, // Can be NULL
169                   SBError& error);
170
171    lldb::SBFileSpec
172    GetExecutable ();
173
174    uint32_t
175    GetNumModules () const;
176
177    lldb::SBModule
178    GetModuleAtIndex (uint32_t idx);
179
180    lldb::SBDebugger
181    GetDebugger() const;
182
183    lldb::SBModule
184    FindModule (const lldb::SBFileSpec &file_spec);
185
186    uint32_t
187    FindFunctions (const char *name,
188                   uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits
189                   bool append,
190                   lldb::SBSymbolContextList& sc_list);
191
192    lldb::SBValueList
193    FindGlobalVariables (const char *name,
194                         uint32_t max_matches);
195
196    void
197    Clear ();
198
199    bool
200    ResolveLoadAddress (lldb::addr_t vm_addr,
201                        lldb::SBAddress& addr);
202
203    SBSymbolContext
204    ResolveSymbolContextForAddress (const SBAddress& addr,
205                                    uint32_t resolve_scope);
206
207    lldb::SBBreakpoint
208    BreakpointCreateByLocation (const char *file, uint32_t line);
209
210    lldb::SBBreakpoint
211    BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line);
212
213    lldb::SBBreakpoint
214    BreakpointCreateByName (const char *symbol_name, const char *module_name = NULL);
215
216    lldb::SBBreakpoint
217    BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name = NULL);
218
219    lldb::SBBreakpoint
220    BreakpointCreateByAddress (addr_t address);
221
222    uint32_t
223    GetNumBreakpoints () const;
224
225    lldb::SBBreakpoint
226    GetBreakpointAtIndex (uint32_t idx) const;
227
228    bool
229    BreakpointDelete (break_id_t break_id);
230
231    lldb::SBBreakpoint
232    FindBreakpointByID (break_id_t break_id);
233
234    bool
235    EnableAllBreakpoints ();
236
237    bool
238    DisableAllBreakpoints ();
239
240    bool
241    DeleteAllBreakpoints ();
242
243    lldb::SBBroadcaster
244    GetBroadcaster () const;
245
246#ifndef SWIG
247    bool
248    operator == (const lldb::SBTarget &rhs) const;
249
250    bool
251    operator != (const lldb::SBTarget &rhs) const;
252
253#endif
254
255    bool
256    GetDescription (lldb::SBStream &description, lldb::DescriptionLevel);
257
258    bool
259    GetDescription (lldb::SBStream &description, lldb::DescriptionLevel) const;
260
261protected:
262    friend class SBAddress;
263    friend class SBDebugger;
264    friend class SBFunction;
265    friend class SBProcess;
266    friend class SBSymbol;
267    friend class SBModule;
268
269    //------------------------------------------------------------------
270    // Constructors are private, use static Target::Create function to
271    // create an instance of this class.
272    //------------------------------------------------------------------
273
274    SBTarget (const lldb::TargetSP& target_sp);
275
276    void
277    reset (const lldb::TargetSP& target_sp);
278
279    lldb_private::Target *
280    operator ->() const;
281
282    lldb_private::Target *
283    get() const;
284
285private:
286    //------------------------------------------------------------------
287    // For Target only
288    //------------------------------------------------------------------
289
290    lldb::TargetSP m_opaque_sp;
291};
292
293} // namespace lldb
294
295#endif  // LLDB_SBTarget_h_
296