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