SBTarget.h revision 7dd5c51fbab8384b18f20ecc125f9a1bb3c9bcb2
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/SBAddress.h"
15#include "lldb/API/SBBroadcaster.h"
16#include "lldb/API/SBFileSpec.h"
17#include "lldb/API/SBFileSpecList.h"
18#include "lldb/API/SBType.h"
19#include "lldb/API/SBWatchpoint.h"
20
21namespace lldb {
22
23class SBBreakpoint;
24
25class SBTarget
26{
27public:
28    //------------------------------------------------------------------
29    // Broadcaster bits.
30    //------------------------------------------------------------------
31    enum
32    {
33        eBroadcastBitBreakpointChanged  = (1 << 0),
34        eBroadcastBitModulesLoaded      = (1 << 1),
35        eBroadcastBitModulesUnloaded    = (1 << 2)
36    };
37
38    //------------------------------------------------------------------
39    // Constructors
40    //------------------------------------------------------------------
41    SBTarget ();
42
43    SBTarget (const lldb::SBTarget& rhs);
44
45    const lldb::SBTarget&
46    operator = (const lldb::SBTarget& rhs);
47
48    //------------------------------------------------------------------
49    // Destructor
50    //------------------------------------------------------------------
51    ~SBTarget();
52
53    bool
54    IsValid() const;
55
56    lldb::SBProcess
57    GetProcess ();
58
59    //------------------------------------------------------------------
60    /// Launch a new process.
61    ///
62    /// Launch a new process by spawning a new process using the
63    /// target object's executable module's file as the file to launch.
64    /// Arguments are given in \a argv, and the environment variables
65    /// are in \a envp. Standard input and output files can be
66    /// optionally re-directed to \a stdin_path, \a stdout_path, and
67    /// \a stderr_path.
68    ///
69    /// @param[in] listener
70    ///     An optional listener that will receive all process events.
71    ///     If \a listener is valid then \a listener will listen to all
72    ///     process events. If not valid, then this target's debugger
73    ///     (SBTarget::GetDebugger()) will listen to all process events.
74    ///
75    /// @param[in] argv
76    ///     The argument array.
77    ///
78    /// @param[in] envp
79    ///     The environment array.
80    ///
81    /// @param[in] launch_flags
82    ///     Flags to modify the launch (@see lldb::LaunchFlags)
83    ///
84    /// @param[in] stdin_path
85    ///     The path to use when re-directing the STDIN of the new
86    ///     process. If all stdXX_path arguments are NULL, a pseudo
87    ///     terminal will be used.
88    ///
89    /// @param[in] stdout_path
90    ///     The path to use when re-directing the STDOUT of the new
91    ///     process. If all stdXX_path arguments are NULL, a pseudo
92    ///     terminal will be used.
93    ///
94    /// @param[in] stderr_path
95    ///     The path to use when re-directing the STDERR of the new
96    ///     process. If all stdXX_path arguments are NULL, a pseudo
97    ///     terminal will be used.
98    ///
99    /// @param[in] working_directory
100    ///     The working directory to have the child process run in
101    ///
102    /// @param[in] launch_flags
103    ///     Some launch options specified by logical OR'ing
104    ///     lldb::LaunchFlags enumeration values together.
105    ///
106    /// @param[in] stop_at_endtry
107    ///     If false do not stop the inferior at the entry point.
108    ///
109    /// @param[out]
110    ///     An error object. Contains the reason if there is some failure.
111    ///
112    /// @return
113    ///      A process object for the newly created process.
114    //------------------------------------------------------------------
115    lldb::SBProcess
116    Launch (SBListener &listener,
117            char const **argv,
118            char const **envp,
119            const char *stdin_path,
120            const char *stdout_path,
121            const char *stderr_path,
122            const char *working_directory,
123            uint32_t launch_flags,   // See LaunchFlags
124            bool stop_at_entry,
125            lldb::SBError& error);
126
127
128    //------------------------------------------------------------------
129    /// Launch a new process with sensible defaults.
130    ///
131    /// @param[in] argv
132    ///     The argument array.
133    ///
134    /// @param[in] envp
135    ///     The environment array.
136    ///
137    /// @param[in] working_directory
138    ///     The working directory to have the child process run in
139    ///
140    /// Default: listener
141    ///     Set to the target's debugger (SBTarget::GetDebugger())
142    ///
143    /// Default: launch_flags
144    ///     Empty launch flags
145    ///
146    /// Default: stdin_path
147    /// Default: stdout_path
148    /// Default: stderr_path
149    ///     A pseudo terminal will be used.
150    ///
151    /// @return
152    ///      A process object for the newly created process.
153    //------------------------------------------------------------------
154    lldb::SBProcess
155    LaunchSimple (const char **argv,
156                  const char **envp,
157                  const char *working_directory);
158
159    //------------------------------------------------------------------
160    /// Attach to process with pid.
161    ///
162    /// @param[in] listener
163    ///     An optional listener that will receive all process events.
164    ///     If \a listener is valid then \a listener will listen to all
165    ///     process events. If not valid, then this target's debugger
166    ///     (SBTarget::GetDebugger()) will listen to all process events.
167    ///
168    /// @param[in] pid
169    ///     The process ID to attach to.
170    ///
171    /// @param[out]
172    ///     An error explaining what went wrong if attach fails.
173    ///
174    /// @return
175    ///      A process object for the attached process.
176    //------------------------------------------------------------------
177    lldb::SBProcess
178    AttachToProcessWithID (SBListener &listener,
179                           lldb::pid_t pid,
180                           lldb::SBError& error);
181
182#if defined(__APPLE__)
183    // We need to keep this around for a build or two since Xcode links
184    // to the 32 bit version of this function. We will take it out soon.
185    lldb::SBProcess
186    AttachToProcessWithID (SBListener &listener,
187                           ::pid_t pid,           // 32 bit int process ID
188                           lldb::SBError& error); // DEPRECATED
189#endif
190    //------------------------------------------------------------------
191    /// Attach to process with name.
192    ///
193    /// @param[in] listener
194    ///     An optional listener that will receive all process events.
195    ///     If \a listener is valid then \a listener will listen to all
196    ///     process events. If not valid, then this target's debugger
197    ///     (SBTarget::GetDebugger()) will listen to all process events.
198    ///
199    /// @param[in] name
200    ///     Basename of process to attach to.
201    ///
202    /// @param[in] wait_for
203    ///     If true wait for a new instance of 'name' to be launched.
204    ///
205    /// @param[out]
206    ///     An error explaining what went wrong if attach fails.
207    ///
208    /// @return
209    ///      A process object for the attached process.
210    //------------------------------------------------------------------
211    lldb::SBProcess
212    AttachToProcessWithName (SBListener &listener,
213                             const char *name,
214                             bool wait_for,
215                             lldb::SBError& error);
216
217    //------------------------------------------------------------------
218    /// Connect to a remote debug server with url.
219    ///
220    /// @param[in] listener
221    ///     An optional listener that will receive all process events.
222    ///     If \a listener is valid then \a listener will listen to all
223    ///     process events. If not valid, then this target's debugger
224    ///     (SBTarget::GetDebugger()) will listen to all process events.
225    ///
226    /// @param[in] url
227    ///     The url to connect to, e.g., 'connect://localhost:12345'.
228    ///
229    /// @param[in] plugin_name
230    ///     The plugin name to be used; can be NULL.
231    ///
232    /// @param[out]
233    ///     An error explaining what went wrong if the connect fails.
234    ///
235    /// @return
236    ///      A process object for the connected process.
237    //------------------------------------------------------------------
238    lldb::SBProcess
239    ConnectRemote (SBListener &listener,
240                   const char *url,
241                   const char *plugin_name,
242                   SBError& error);
243
244    lldb::SBFileSpec
245    GetExecutable ();
246
247    bool
248    AddModule (lldb::SBModule &module);
249
250    lldb::SBModule
251    AddModule (const char *path,
252               const char *triple,
253               const char *uuid);
254
255    uint32_t
256    GetNumModules () const;
257
258    lldb::SBModule
259    GetModuleAtIndex (uint32_t idx);
260
261    bool
262    RemoveModule (lldb::SBModule module);
263
264    lldb::SBDebugger
265    GetDebugger() const;
266
267    lldb::SBModule
268    FindModule (const lldb::SBFileSpec &file_spec);
269
270    lldb::ByteOrder
271    GetByteOrder ();
272
273    uint32_t
274    GetAddressByteSize();
275
276    const char *
277    GetTriple ();
278
279    //------------------------------------------------------------------
280    /// Set the base load address for a module section.
281    ///
282    /// @param[in] section
283    ///     The section whose base load address will be set within this
284    ///     target.
285    ///
286    /// @param[in] section_base_addr
287    ///     The base address for the section.
288    ///
289    /// @return
290    ///      An error to indicate success, fail, and any reason for
291    ///     failure.
292    //------------------------------------------------------------------
293    lldb::SBError
294    SetSectionLoadAddress (lldb::SBSection section,
295                           lldb::addr_t section_base_addr);
296
297    //------------------------------------------------------------------
298    /// Clear the base load address for a module section.
299    ///
300    /// @param[in] section
301    ///     The section whose base load address will be cleared within
302    ///     this target.
303    ///
304    /// @return
305    ///      An error to indicate success, fail, and any reason for
306    ///     failure.
307    //------------------------------------------------------------------
308    lldb::SBError
309    ClearSectionLoadAddress (lldb::SBSection section);
310
311    //------------------------------------------------------------------
312    /// Slide all file addresses for all module sections so that \a module
313    /// appears to loaded at these slide addresses.
314    ///
315    /// When you need all sections within a module to be loaded at a
316    /// rigid slide from the addresses found in the module object file,
317    /// this function will allow you to easily and quickly slide all
318    /// module sections.
319    ///
320    /// @param[in] module
321    ///     The module to load.
322    ///
323    /// @param[in] sections_offset
324    ///     An offset that will be applied to all section file addresses
325    ///     (the virtual addresses found in the object file itself).
326    ///
327    /// @return
328    ///     An error to indicate success, fail, and any reason for
329    ///     failure.
330    //------------------------------------------------------------------
331    lldb::SBError
332    SetModuleLoadAddress (lldb::SBModule module,
333                          int64_t sections_offset);
334
335
336    //------------------------------------------------------------------
337    /// The the section base load addresses for all sections in a module.
338    ///
339    /// @param[in] module
340    ///     The module to unload.
341    ///
342    /// @return
343    ///     An error to indicate success, fail, and any reason for
344    ///     failure.
345    //------------------------------------------------------------------
346    lldb::SBError
347    ClearModuleLoadAddress (lldb::SBModule module);
348
349    //------------------------------------------------------------------
350    /// Find functions by name.
351    ///
352    /// @param[in] name
353    ///     The name of the function we are looking for.
354    ///
355    /// @param[in] name_type_mask
356    ///     A logical OR of one or more FunctionNameType enum bits that
357    ///     indicate what kind of names should be used when doing the
358    ///     lookup. Bits include fully qualified names, base names,
359    ///     C++ methods, or ObjC selectors.
360    ///     See FunctionNameType for more details.
361    ///
362    /// @return
363    ///     A lldb::SBSymbolContextList that gets filled in with all of
364    ///     the symbol contexts for all the matches.
365    //------------------------------------------------------------------
366    lldb::SBSymbolContextList
367    FindFunctions (const char *name,
368                   uint32_t name_type_mask = lldb::eFunctionNameTypeAny);
369
370    //------------------------------------------------------------------
371    /// Find global and static variables by name.
372    ///
373    /// @param[in] name
374    ///     The name of the global or static variable we are looking
375    ///     for.
376    ///
377    /// @param[in] max_matches
378    ///     Allow the number of matches to be limited to \a max_matches.
379    ///
380    /// @return
381    ///     A list of matched variables in an SBValueList.
382    //------------------------------------------------------------------
383    lldb::SBValueList
384    FindGlobalVariables (const char *name,
385                         uint32_t max_matches);
386
387    void
388    Clear ();
389
390    lldb::SBAddress
391    ResolveLoadAddress (lldb::addr_t vm_addr);
392
393    SBSymbolContext
394    ResolveSymbolContextForAddress (const SBAddress& addr,
395                                    uint32_t resolve_scope);
396
397    lldb::SBBreakpoint
398    BreakpointCreateByLocation (const char *file, uint32_t line);
399
400    lldb::SBBreakpoint
401    BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line);
402
403    lldb::SBBreakpoint
404    BreakpointCreateByName (const char *symbol_name, const char *module_name = NULL);
405
406    // This version uses name_type_mask = eFunctionNameTypeAuto
407    lldb::SBBreakpoint
408    BreakpointCreateByName (const char *symbol_name,
409                            const SBFileSpecList &module_list,
410                            const SBFileSpecList &comp_unit_list);
411
412    lldb::SBBreakpoint
413    BreakpointCreateByName (const char *symbol_name,
414                            uint32_t name_type_mask,           // Logical OR one or more FunctionNameType enum bits
415                            const SBFileSpecList &module_list,
416                            const SBFileSpecList &comp_unit_list);
417
418    lldb::SBBreakpoint
419    BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name = NULL);
420
421    lldb::SBBreakpoint
422    BreakpointCreateByRegex (const char *symbol_name_regex,
423                             const SBFileSpecList &module_list,
424                             const SBFileSpecList &comp_unit_list);
425
426    lldb::SBBreakpoint
427    BreakpointCreateBySourceRegex (const char *source_regex,
428                                   const lldb::SBFileSpec &source_file,
429                                   const char *module_name = NULL);
430
431    lldb::SBBreakpoint
432    BreakpointCreateBySourceRegex (const char *source_regex,
433                                   const SBFileSpecList &module_list,
434                                   const lldb::SBFileSpecList &source_file);
435
436    lldb::SBBreakpoint
437    BreakpointCreateByAddress (addr_t address);
438
439    uint32_t
440    GetNumBreakpoints () const;
441
442    lldb::SBBreakpoint
443    GetBreakpointAtIndex (uint32_t idx) const;
444
445    bool
446    BreakpointDelete (break_id_t break_id);
447
448    lldb::SBBreakpoint
449    FindBreakpointByID (break_id_t break_id);
450
451    bool
452    EnableAllBreakpoints ();
453
454    bool
455    DisableAllBreakpoints ();
456
457    bool
458    DeleteAllBreakpoints ();
459
460    uint32_t
461    GetNumWatchpoints () const;
462
463    lldb::SBWatchpoint
464    GetWatchpointAtIndex (uint32_t idx) const;
465
466    bool
467    DeleteWatchpoint (lldb::watch_id_t watch_id);
468
469    lldb::SBWatchpoint
470    FindWatchpointByID (lldb::watch_id_t watch_id);
471
472    lldb::SBWatchpoint
473    WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write);
474
475    bool
476    EnableAllWatchpoints ();
477
478    bool
479    DisableAllWatchpoints ();
480
481    bool
482    DeleteAllWatchpoints ();
483
484    lldb::SBBroadcaster
485    GetBroadcaster () const;
486
487    lldb::SBType
488    FindFirstType (const char* type);
489
490    lldb::SBTypeList
491    FindTypes (const char* type);
492
493    SBSourceManager
494    GetSourceManager();
495
496    lldb::SBInstructionList
497    GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size);
498
499    lldb::SBInstructionList
500    GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size);
501
502    bool
503    operator == (const lldb::SBTarget &rhs) const;
504
505    bool
506    operator != (const lldb::SBTarget &rhs) const;
507
508    bool
509    GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level);
510
511protected:
512    friend class SBAddress;
513    friend class SBBlock;
514    friend class SBDebugger;
515    friend class SBFunction;
516    friend class SBInstruction;
517    friend class SBModule;
518    friend class SBProcess;
519    friend class SBSourceManager;
520    friend class SBSymbol;
521    friend class SBValue;
522
523    //------------------------------------------------------------------
524    // Constructors are private, use static Target::Create function to
525    // create an instance of this class.
526    //------------------------------------------------------------------
527
528    SBTarget (const lldb::TargetSP& target_sp);
529
530    lldb::TargetSP
531    GetSP () const;
532
533    void
534    SetSP (const lldb::TargetSP& target_sp);
535
536
537private:
538    //------------------------------------------------------------------
539    // For Target only
540    //------------------------------------------------------------------
541
542    lldb::TargetSP m_opaque_sp;
543};
544
545} // namespace lldb
546
547#endif  // LLDB_SBTarget_h_
548