1 //===-- SBTarget.h ----------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_API_SBTARGET_H
10 #define LLDB_API_SBTARGET_H
11 
12 #include "lldb/API/SBAddress.h"
13 #include "lldb/API/SBAttachInfo.h"
14 #include "lldb/API/SBBreakpoint.h"
15 #include "lldb/API/SBBroadcaster.h"
16 #include "lldb/API/SBDefines.h"
17 #include "lldb/API/SBFileSpec.h"
18 #include "lldb/API/SBFileSpecList.h"
19 #include "lldb/API/SBLaunchInfo.h"
20 #include "lldb/API/SBSymbolContextList.h"
21 #include "lldb/API/SBType.h"
22 #include "lldb/API/SBValue.h"
23 #include "lldb/API/SBWatchpoint.h"
24 
25 namespace lldb {
26 
27 class SBPlatform;
28 
29 class LLDB_API SBTarget {
30 public:
31   // Broadcaster bits.
32   enum {
33     eBroadcastBitBreakpointChanged = (1 << 0),
34     eBroadcastBitModulesLoaded = (1 << 1),
35     eBroadcastBitModulesUnloaded = (1 << 2),
36     eBroadcastBitWatchpointChanged = (1 << 3),
37     eBroadcastBitSymbolsLoaded = (1 << 4)
38   };
39 
40   // Constructors
41   SBTarget();
42 
43   SBTarget(const lldb::SBTarget &rhs);
44 
45   SBTarget(const lldb::TargetSP &target_sp);
46 
47   // Destructor
48   ~SBTarget();
49 
50   const lldb::SBTarget &operator=(const lldb::SBTarget &rhs);
51 
52   explicit operator bool() const;
53 
54   bool IsValid() const;
55 
56   static bool EventIsTargetEvent(const lldb::SBEvent &event);
57 
58   static lldb::SBTarget GetTargetFromEvent(const lldb::SBEvent &event);
59 
60   static uint32_t GetNumModulesFromEvent(const lldb::SBEvent &event);
61 
62   static lldb::SBModule GetModuleAtIndexFromEvent(const uint32_t idx,
63                                                   const lldb::SBEvent &event);
64 
65   static const char *GetBroadcasterClassName();
66 
67   lldb::SBProcess GetProcess();
68 
69   /// Sets whether we should collect statistics on lldb or not.
70   ///
71   /// \param[in] v
72   ///     A boolean to control the collection.
73   void SetCollectingStats(bool v);
74 
75   /// Returns whether statistics collection are enabled.
76   ///
77   /// \return
78   ///     true if statistics are currently being collected, false
79   ///     otherwise.
80   bool GetCollectingStats();
81 
82   /// Returns a dump of the collected statistics.
83   ///
84   /// \return
85   ///     A SBStructuredData with the statistics collected.
86   lldb::SBStructuredData GetStatistics();
87 
88   /// Return the platform object associated with the target.
89   ///
90   /// After return, the platform object should be checked for
91   /// validity.
92   ///
93   /// \return
94   ///     A platform object.
95   lldb::SBPlatform GetPlatform();
96 
97   /// Return the environment variables that would be used to launch a new
98   /// process.
99   ///
100   /// \return
101   ///     An lldb::SBEnvironment object which is a copy of the target's
102   ///     environment.
103 
104   SBEnvironment GetEnvironment();
105 
106   /// Install any binaries that need to be installed.
107   ///
108   /// This function does nothing when debugging on the host system.
109   /// When connected to remote platforms, the target's main executable
110   /// and any modules that have their remote install path set will be
111   /// installed on the remote platform. If the main executable doesn't
112   /// have an install location set, it will be installed in the remote
113   /// platform's working directory.
114   ///
115   /// \return
116   ///     An error describing anything that went wrong during
117   ///     installation.
118   SBError Install();
119 
120   /// Launch a new process.
121   ///
122   /// Launch a new process by spawning a new process using the
123   /// target object's executable module's file as the file to launch.
124   /// Arguments are given in \a argv, and the environment variables
125   /// are in \a envp. Standard input and output files can be
126   /// optionally re-directed to \a stdin_path, \a stdout_path, and
127   /// \a stderr_path.
128   ///
129   /// \param[in] listener
130   ///     An optional listener that will receive all process events.
131   ///     If \a listener is valid then \a listener will listen to all
132   ///     process events. If not valid, then this target's debugger
133   ///     (SBTarget::GetDebugger()) will listen to all process events.
134   ///
135   /// \param[in] argv
136   ///     The argument array.
137   ///
138   /// \param[in] envp
139   ///     The environment array. If this is null, the default
140   ///     environment values (provided through `settings set
141   ///     target.env-vars`) will be used.
142   ///
143   /// \param[in] stdin_path
144   ///     The path to use when re-directing the STDIN of the new
145   ///     process. If all stdXX_path arguments are nullptr, a pseudo
146   ///     terminal will be used.
147   ///
148   /// \param[in] stdout_path
149   ///     The path to use when re-directing the STDOUT of the new
150   ///     process. If all stdXX_path arguments are nullptr, a pseudo
151   ///     terminal will be used.
152   ///
153   /// \param[in] stderr_path
154   ///     The path to use when re-directing the STDERR of the new
155   ///     process. If all stdXX_path arguments are nullptr, a pseudo
156   ///     terminal will be used.
157   ///
158   /// \param[in] working_directory
159   ///     The working directory to have the child process run in
160   ///
161   /// \param[in] launch_flags
162   ///     Some launch options specified by logical OR'ing
163   ///     lldb::LaunchFlags enumeration values together.
164   ///
165   /// \param[in] stop_at_entry
166   ///     If false do not stop the inferior at the entry point.
167   ///
168   /// \param[out] error
169   ///     An error object. Contains the reason if there is some failure.
170   ///
171   /// \return
172   ///      A process object for the newly created process.
173   lldb::SBProcess Launch(SBListener &listener, char const **argv,
174                          char const **envp, const char *stdin_path,
175                          const char *stdout_path, const char *stderr_path,
176                          const char *working_directory,
177                          uint32_t launch_flags, // See LaunchFlags
178                          bool stop_at_entry, lldb::SBError &error);
179 
180   SBProcess LoadCore(const char *core_file);
181   SBProcess LoadCore(const char *core_file, lldb::SBError &error);
182 
183   /// Launch a new process with sensible defaults.
184   ///
185   /// \param[in] argv
186   ///     The argument array.
187   ///
188   /// \param[in] envp
189   ///     The environment array. If this isn't provided, the default
190   ///     environment values (provided through `settings set
191   ///     target.env-vars`) will be used.
192   ///
193   /// \param[in] working_directory
194   ///     The working directory to have the child process run in
195   ///
196   /// Default: listener
197   ///     Set to the target's debugger (SBTarget::GetDebugger())
198   ///
199   /// Default: launch_flags
200   ///     Empty launch flags
201   ///
202   /// Default: stdin_path
203   /// Default: stdout_path
204   /// Default: stderr_path
205   ///     A pseudo terminal will be used.
206   ///
207   /// \return
208   ///      A process object for the newly created process.
209   SBProcess LaunchSimple(const char **argv, const char **envp,
210                          const char *working_directory);
211 
212   SBProcess Launch(SBLaunchInfo &launch_info, SBError &error);
213 
214   SBProcess Attach(SBAttachInfo &attach_info, SBError &error);
215 
216   /// Attach to process with pid.
217   ///
218   /// \param[in] listener
219   ///     An optional listener that will receive all process events.
220   ///     If \a listener is valid then \a listener will listen to all
221   ///     process events. If not valid, then this target's debugger
222   ///     (SBTarget::GetDebugger()) will listen to all process events.
223   ///
224   /// \param[in] pid
225   ///     The process ID to attach to.
226   ///
227   /// \param[out] error
228   ///     An error explaining what went wrong if attach fails.
229   ///
230   /// \return
231   ///      A process object for the attached process.
232   lldb::SBProcess AttachToProcessWithID(SBListener &listener, lldb::pid_t pid,
233                                         lldb::SBError &error);
234 
235   /// Attach to process with name.
236   ///
237   /// \param[in] listener
238   ///     An optional listener that will receive all process events.
239   ///     If \a listener is valid then \a listener will listen to all
240   ///     process events. If not valid, then this target's debugger
241   ///     (SBTarget::GetDebugger()) will listen to all process events.
242   ///
243   /// \param[in] name
244   ///     Basename of process to attach to.
245   ///
246   /// \param[in] wait_for
247   ///     If true wait for a new instance of 'name' to be launched.
248   ///
249   /// \param[out] error
250   ///     An error explaining what went wrong if attach fails.
251   ///
252   /// \return
253   ///      A process object for the attached process.
254   lldb::SBProcess AttachToProcessWithName(SBListener &listener,
255                                           const char *name, bool wait_for,
256                                           lldb::SBError &error);
257 
258   /// Connect to a remote debug server with url.
259   ///
260   /// \param[in] listener
261   ///     An optional listener that will receive all process events.
262   ///     If \a listener is valid then \a listener will listen to all
263   ///     process events. If not valid, then this target's debugger
264   ///     (SBTarget::GetDebugger()) will listen to all process events.
265   ///
266   /// \param[in] url
267   ///     The url to connect to, e.g., 'connect://localhost:12345'.
268   ///
269   /// \param[in] plugin_name
270   ///     The plugin name to be used; can be nullptr.
271   ///
272   /// \param[out] error
273   ///     An error explaining what went wrong if the connect fails.
274   ///
275   /// \return
276   ///      A process object for the connected process.
277   lldb::SBProcess ConnectRemote(SBListener &listener, const char *url,
278                                 const char *plugin_name, SBError &error);
279 
280   lldb::SBFileSpec GetExecutable();
281 
282   // Append the path mapping (from -> to) to the target's paths mapping list.
283   void AppendImageSearchPath(const char *from, const char *to,
284                              lldb::SBError &error);
285 
286   bool AddModule(lldb::SBModule &module);
287 
288   lldb::SBModule AddModule(const char *path, const char *triple,
289                            const char *uuid);
290 
291   lldb::SBModule AddModule(const char *path, const char *triple,
292                            const char *uuid_cstr, const char *symfile);
293 
294   lldb::SBModule AddModule(const SBModuleSpec &module_spec);
295 
296   uint32_t GetNumModules() const;
297 
298   lldb::SBModule GetModuleAtIndex(uint32_t idx);
299 
300   bool RemoveModule(lldb::SBModule module);
301 
302   lldb::SBDebugger GetDebugger() const;
303 
304   lldb::SBModule FindModule(const lldb::SBFileSpec &file_spec);
305 
306   /// Find compile units related to *this target and passed source
307   /// file.
308   ///
309   /// \param[in] sb_file_spec
310   ///     A lldb::SBFileSpec object that contains source file
311   ///     specification.
312   ///
313   /// \return
314   ///     A lldb::SBSymbolContextList that gets filled in with all of
315   ///     the symbol contexts for all the matches.
316   lldb::SBSymbolContextList
317   FindCompileUnits(const lldb::SBFileSpec &sb_file_spec);
318 
319   lldb::ByteOrder GetByteOrder();
320 
321   uint32_t GetAddressByteSize();
322 
323   const char *GetTriple();
324 
325   /// Architecture data byte width accessor
326   ///
327   /// \return
328   /// The size in 8-bit (host) bytes of a minimum addressable
329   /// unit from the Architecture's data bus
330   uint32_t GetDataByteSize();
331 
332   /// Architecture code byte width accessor
333   ///
334   /// \return
335   /// The size in 8-bit (host) bytes of a minimum addressable
336   /// unit from the Architecture's code bus
337   uint32_t GetCodeByteSize();
338 
339   /// Gets the target.max-children-count value
340   /// It should be used to limit the number of
341   /// children of large data structures to be displayed.
342   uint32_t GetMaximumNumberOfChildrenToDisplay() const;
343 
344   /// Set the base load address for a module section.
345   ///
346   /// \param[in] section
347   ///     The section whose base load address will be set within this
348   ///     target.
349   ///
350   /// \param[in] section_base_addr
351   ///     The base address for the section.
352   ///
353   /// \return
354   ///      An error to indicate success, fail, and any reason for
355   ///     failure.
356   lldb::SBError SetSectionLoadAddress(lldb::SBSection section,
357                                       lldb::addr_t section_base_addr);
358 
359   /// Clear the base load address for a module section.
360   ///
361   /// \param[in] section
362   ///     The section whose base load address will be cleared within
363   ///     this target.
364   ///
365   /// \return
366   ///      An error to indicate success, fail, and any reason for
367   ///     failure.
368   lldb::SBError ClearSectionLoadAddress(lldb::SBSection section);
369 
370   /// Slide all file addresses for all module sections so that \a module
371   /// appears to loaded at these slide addresses.
372   ///
373   /// When you need all sections within a module to be loaded at a
374   /// rigid slide from the addresses found in the module object file,
375   /// this function will allow you to easily and quickly slide all
376   /// module sections.
377   ///
378   /// \param[in] module
379   ///     The module to load.
380   ///
381   /// \param[in] sections_offset
382   ///     An offset that will be applied to all section file addresses
383   ///     (the virtual addresses found in the object file itself).
384   ///
385   /// \return
386   ///     An error to indicate success, fail, and any reason for
387   ///     failure.
388   lldb::SBError SetModuleLoadAddress(lldb::SBModule module,
389                                      int64_t sections_offset);
390 
391   /// Clear the section base load addresses for all sections in a module.
392   ///
393   /// \param[in] module
394   ///     The module to unload.
395   ///
396   /// \return
397   ///     An error to indicate success, fail, and any reason for
398   ///     failure.
399   lldb::SBError ClearModuleLoadAddress(lldb::SBModule module);
400 
401   /// Find functions by name.
402   ///
403   /// \param[in] name
404   ///     The name of the function we are looking for.
405   ///
406   /// \param[in] name_type_mask
407   ///     A logical OR of one or more FunctionNameType enum bits that
408   ///     indicate what kind of names should be used when doing the
409   ///     lookup. Bits include fully qualified names, base names,
410   ///     C++ methods, or ObjC selectors.
411   ///     See FunctionNameType for more details.
412   ///
413   /// \return
414   ///     A lldb::SBSymbolContextList that gets filled in with all of
415   ///     the symbol contexts for all the matches.
416   lldb::SBSymbolContextList
417   FindFunctions(const char *name,
418                 uint32_t name_type_mask = lldb::eFunctionNameTypeAny);
419 
420   /// Find global and static variables by name.
421   ///
422   /// \param[in] name
423   ///     The name of the global or static variable we are looking
424   ///     for.
425   ///
426   /// \param[in] max_matches
427   ///     Allow the number of matches to be limited to \a max_matches.
428   ///
429   /// \return
430   ///     A list of matched variables in an SBValueList.
431   lldb::SBValueList FindGlobalVariables(const char *name, uint32_t max_matches);
432 
433   /// Find the first global (or static) variable by name.
434   ///
435   /// \param[in] name
436   ///     The name of the global or static variable we are looking
437   ///     for.
438   ///
439   /// \return
440   ///     An SBValue that gets filled in with the found variable (if any).
441   lldb::SBValue FindFirstGlobalVariable(const char *name);
442 
443   /// Find global and static variables by pattern.
444   ///
445   /// \param[in] name
446   ///     The pattern to search for global or static variables
447   ///
448   /// \param[in] max_matches
449   ///     Allow the number of matches to be limited to \a max_matches.
450   ///
451   /// \param[in] matchtype
452   ///     The match type to use.
453   ///
454   /// \return
455   ///     A list of matched variables in an SBValueList.
456   lldb::SBValueList FindGlobalVariables(const char *name, uint32_t max_matches,
457                                         MatchType matchtype);
458 
459   /// Find global functions by their name with pattern matching.
460   ///
461   /// \param[in] name
462   ///     The pattern to search for global or static variables
463   ///
464   /// \param[in] max_matches
465   ///     Allow the number of matches to be limited to \a max_matches.
466   ///
467   /// \param[in] matchtype
468   ///     The match type to use.
469   ///
470   /// \return
471   ///     A list of matched variables in an SBValueList.
472   lldb::SBSymbolContextList FindGlobalFunctions(const char *name,
473                                                 uint32_t max_matches,
474                                                 MatchType matchtype);
475 
476   void Clear();
477 
478   /// Resolve a current file address into a section offset address.
479   ///
480   /// \param[in] file_addr
481   ///     The file address to resolve.
482   ///
483   /// \return
484   ///     An SBAddress which will be valid if...
485   lldb::SBAddress ResolveFileAddress(lldb::addr_t file_addr);
486 
487   /// Resolve a current load address into a section offset address.
488   ///
489   /// \param[in] vm_addr
490   ///     A virtual address from the current process state that is to
491   ///     be translated into a section offset address.
492   ///
493   /// \return
494   ///     An SBAddress which will be valid if \a vm_addr was
495   ///     successfully resolved into a section offset address, or an
496   ///     invalid SBAddress if \a vm_addr doesn't resolve to a section
497   ///     in a module.
498   lldb::SBAddress ResolveLoadAddress(lldb::addr_t vm_addr);
499 
500   /// Resolve a current load address into a section offset address
501   /// using the process stop ID to identify a time in the past.
502   ///
503   /// \param[in] stop_id
504   ///     Each time a process stops, the process stop ID integer gets
505   ///     incremented. These stop IDs are used to identify past times
506   ///     and can be used in history objects as a cheap way to store
507   ///     the time at which the sample was taken. Specifying
508   ///     UINT32_MAX will always resolve the address using the
509   ///     currently loaded sections.
510   ///
511   /// \param[in] vm_addr
512   ///     A virtual address from the current process state that is to
513   ///     be translated into a section offset address.
514   ///
515   /// \return
516   ///     An SBAddress which will be valid if \a vm_addr was
517   ///     successfully resolved into a section offset address, or an
518   ///     invalid SBAddress if \a vm_addr doesn't resolve to a section
519   ///     in a module.
520   lldb::SBAddress ResolvePastLoadAddress(uint32_t stop_id,
521                                          lldb::addr_t vm_addr);
522 
523   SBSymbolContext ResolveSymbolContextForAddress(const SBAddress &addr,
524                                                  uint32_t resolve_scope);
525 
526   /// Read target memory. If a target process is running then memory
527   /// is read from here. Otherwise the memory is read from the object
528   /// files. For a target whose bytes are sized as a multiple of host
529   /// bytes, the data read back will preserve the target's byte order.
530   ///
531   /// \param[in] addr
532   ///     A target address to read from.
533   ///
534   /// \param[out] buf
535   ///     The buffer to read memory into.
536   ///
537   /// \param[in] size
538   ///     The maximum number of host bytes to read in the buffer passed
539   ///     into this call
540   ///
541   /// \param[out] error
542   ///     Status information is written here if the memory read fails.
543   ///
544   /// \return
545   ///     The amount of data read in host bytes.
546   size_t ReadMemory(const SBAddress addr, void *buf, size_t size,
547                     lldb::SBError &error);
548 
549   lldb::SBBreakpoint BreakpointCreateByLocation(const char *file,
550                                                 uint32_t line);
551 
552   lldb::SBBreakpoint
553   BreakpointCreateByLocation(const lldb::SBFileSpec &file_spec, uint32_t line);
554 
555   lldb::SBBreakpoint
556   BreakpointCreateByLocation(const lldb::SBFileSpec &file_spec, uint32_t line,
557                              lldb::addr_t offset);
558 
559   lldb::SBBreakpoint
560   BreakpointCreateByLocation(const lldb::SBFileSpec &file_spec, uint32_t line,
561                              lldb::addr_t offset, SBFileSpecList &module_list);
562 
563   lldb::SBBreakpoint
564   BreakpointCreateByLocation(const lldb::SBFileSpec &file_spec, uint32_t line,
565                              uint32_t column, lldb::addr_t offset,
566                              SBFileSpecList &module_list);
567 
568   lldb::SBBreakpoint
569   BreakpointCreateByLocation(const lldb::SBFileSpec &file_spec, uint32_t line,
570                              uint32_t column, lldb::addr_t offset,
571                              SBFileSpecList &module_list,
572                              bool move_to_nearest_code);
573 
574   lldb::SBBreakpoint BreakpointCreateByName(const char *symbol_name,
575                                             const char *module_name = nullptr);
576 
577   // This version uses name_type_mask = eFunctionNameTypeAuto
578   lldb::SBBreakpoint
579   BreakpointCreateByName(const char *symbol_name,
580                          const SBFileSpecList &module_list,
581                          const SBFileSpecList &comp_unit_list);
582 
583   lldb::SBBreakpoint BreakpointCreateByName(
584       const char *symbol_name,
585       uint32_t
586           name_type_mask, // Logical OR one or more FunctionNameType enum bits
587       const SBFileSpecList &module_list,
588       const SBFileSpecList &comp_unit_list);
589 
590   lldb::SBBreakpoint BreakpointCreateByName(
591       const char *symbol_name,
592       uint32_t
593           name_type_mask, // Logical OR one or more FunctionNameType enum bits
594       lldb::LanguageType symbol_language,
595       const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list);
596 
597   lldb::SBBreakpoint BreakpointCreateByNames(
598       const char *symbol_name[], uint32_t num_names,
599       uint32_t
600           name_type_mask, // Logical OR one or more FunctionNameType enum bits
601       const SBFileSpecList &module_list,
602       const SBFileSpecList &comp_unit_list);
603 
604   lldb::SBBreakpoint BreakpointCreateByNames(
605       const char *symbol_name[], uint32_t num_names,
606       uint32_t
607           name_type_mask, // Logical OR one or more FunctionNameType enum bits
608       lldb::LanguageType symbol_language,
609       const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list);
610 
611   lldb::SBBreakpoint BreakpointCreateByNames(
612       const char *symbol_name[], uint32_t num_names,
613       uint32_t
614           name_type_mask, // Logical OR one or more FunctionNameType enum bits
615       lldb::LanguageType symbol_language,
616       lldb::addr_t offset, const SBFileSpecList &module_list,
617       const SBFileSpecList &comp_unit_list);
618 
619   lldb::SBBreakpoint BreakpointCreateByRegex(const char *symbol_name_regex,
620                                              const char *module_name = nullptr);
621 
622   lldb::SBBreakpoint
623   BreakpointCreateByRegex(const char *symbol_name_regex,
624                           const SBFileSpecList &module_list,
625                           const SBFileSpecList &comp_unit_list);
626 
627   lldb::SBBreakpoint BreakpointCreateByRegex(
628       const char *symbol_name_regex, lldb::LanguageType symbol_language,
629       const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list);
630 
631   lldb::SBBreakpoint
632   BreakpointCreateBySourceRegex(const char *source_regex,
633                                 const SBFileSpec &source_file,
634                                 const char *module_name = nullptr);
635 
636   lldb::SBBreakpoint
637   BreakpointCreateBySourceRegex(const char *source_regex,
638                                 const SBFileSpecList &module_list,
639                                 const SBFileSpecList &source_file);
640 
641   lldb::SBBreakpoint BreakpointCreateBySourceRegex(
642       const char *source_regex, const SBFileSpecList &module_list,
643       const SBFileSpecList &source_file, const SBStringList &func_names);
644 
645   lldb::SBBreakpoint BreakpointCreateForException(lldb::LanguageType language,
646                                                   bool catch_bp, bool throw_bp);
647 
648   lldb::SBBreakpoint BreakpointCreateByAddress(addr_t address);
649 
650   lldb::SBBreakpoint BreakpointCreateBySBAddress(SBAddress &address);
651 
652   /// Create a breakpoint using a scripted resolver.
653   ///
654   /// \param[in] class_name
655   ///    This is the name of the class that implements a scripted resolver.
656   ///
657   /// \param[in] extra_args
658   ///    This is an SBStructuredData object that will get passed to the
659   ///    constructor of the class in class_name.  You can use this to
660   ///    reuse the same class, parametrizing with entries from this
661   ///    dictionary.
662   ///
663   /// \param module_list
664   ///    If this is non-empty, this will be used as the module filter in the
665   ///    SearchFilter created for this breakpoint.
666   ///
667   /// \param file_list
668   ///    If this is non-empty, this will be used as the comp unit filter in the
669   ///    SearchFilter created for this breakpoint.
670   ///
671   /// \return
672   ///     An SBBreakpoint that will set locations based on the logic in the
673   ///     resolver's search callback.
674   lldb::SBBreakpoint BreakpointCreateFromScript(
675       const char *class_name,
676       SBStructuredData &extra_args,
677       const SBFileSpecList &module_list,
678       const SBFileSpecList &file_list,
679       bool request_hardware = false);
680 
681   /// Read breakpoints from source_file and return the newly created
682   /// breakpoints in bkpt_list.
683   ///
684   /// \param[in] source_file
685   ///    The file from which to read the breakpoints.
686   ///
687   /// \param[out] new_bps
688   ///    A list of the newly created breakpoints.
689   ///
690   /// \return
691   ///     An SBError detailing any errors in reading in the breakpoints.
692   lldb::SBError BreakpointsCreateFromFile(SBFileSpec &source_file,
693                                           SBBreakpointList &new_bps);
694 
695   /// Read breakpoints from source_file and return the newly created
696   /// breakpoints in bkpt_list.
697   ///
698   /// \param[in] source_file
699   ///    The file from which to read the breakpoints.
700   ///
701   /// \param[in] matching_names
702   ///    Only read in breakpoints whose names match one of the names in this
703   ///    list.
704   ///
705   /// \param[out] new_bps
706   ///    A list of the newly created breakpoints.
707   ///
708   /// \return
709   ///     An SBError detailing any errors in reading in the breakpoints.
710   lldb::SBError BreakpointsCreateFromFile(SBFileSpec &source_file,
711                                           SBStringList &matching_names,
712                                           SBBreakpointList &new_bps);
713 
714   /// Write breakpoints to dest_file.
715   ///
716   /// \param[in] dest_file
717   ///    The file to which to write the breakpoints.
718   ///
719   /// \return
720   ///     An SBError detailing any errors in writing in the breakpoints.
721   lldb::SBError BreakpointsWriteToFile(SBFileSpec &dest_file);
722 
723   /// Write breakpoints listed in bkpt_list to dest_file.
724   ///
725   /// \param[in] dest_file
726   ///    The file to which to write the breakpoints.
727   ///
728   /// \param[in] bkpt_list
729   ///    Only write breakpoints from this list.
730   ///
731   /// \param[in] append
732   ///    If \b true, append the breakpoints in bkpt_list to the others
733   ///    serialized in dest_file.  If dest_file doesn't exist, then a new
734   ///    file will be created and the breakpoints in bkpt_list written to it.
735   ///
736   /// \return
737   ///     An SBError detailing any errors in writing in the breakpoints.
738   lldb::SBError BreakpointsWriteToFile(SBFileSpec &dest_file,
739                                        SBBreakpointList &bkpt_list,
740                                        bool append = false);
741 
742   uint32_t GetNumBreakpoints() const;
743 
744   lldb::SBBreakpoint GetBreakpointAtIndex(uint32_t idx) const;
745 
746   bool BreakpointDelete(break_id_t break_id);
747 
748   lldb::SBBreakpoint FindBreakpointByID(break_id_t break_id);
749 
750   // Finds all breakpoints by name, returning the list in bkpt_list.  Returns
751   // false if the name is not a valid breakpoint name, true otherwise.
752   bool FindBreakpointsByName(const char *name, SBBreakpointList &bkpt_list);
753 
754   void GetBreakpointNames(SBStringList &names);
755 
756   void DeleteBreakpointName(const char *name);
757 
758   bool EnableAllBreakpoints();
759 
760   bool DisableAllBreakpoints();
761 
762   bool DeleteAllBreakpoints();
763 
764   uint32_t GetNumWatchpoints() const;
765 
766   lldb::SBWatchpoint GetWatchpointAtIndex(uint32_t idx) const;
767 
768   bool DeleteWatchpoint(lldb::watch_id_t watch_id);
769 
770   lldb::SBWatchpoint FindWatchpointByID(lldb::watch_id_t watch_id);
771 
772   lldb::SBWatchpoint WatchAddress(lldb::addr_t addr, size_t size, bool read,
773                                   bool write, SBError &error);
774 
775   bool EnableAllWatchpoints();
776 
777   bool DisableAllWatchpoints();
778 
779   bool DeleteAllWatchpoints();
780 
781   lldb::SBBroadcaster GetBroadcaster() const;
782 
783   lldb::SBType FindFirstType(const char *type);
784 
785   lldb::SBTypeList FindTypes(const char *type);
786 
787   lldb::SBType GetBasicType(lldb::BasicType type);
788 
789   lldb::SBValue CreateValueFromAddress(const char *name, lldb::SBAddress addr,
790                                        lldb::SBType type);
791 
792   lldb::SBValue CreateValueFromData(const char *name, lldb::SBData data,
793                                     lldb::SBType type);
794 
795   lldb::SBValue CreateValueFromExpression(const char *name, const char *expr);
796 
797   SBSourceManager GetSourceManager();
798 
799   lldb::SBInstructionList ReadInstructions(lldb::SBAddress base_addr,
800                                            uint32_t count);
801 
802   lldb::SBInstructionList ReadInstructions(lldb::SBAddress base_addr,
803                                            uint32_t count,
804                                            const char *flavor_string);
805 
806   lldb::SBInstructionList GetInstructions(lldb::SBAddress base_addr,
807                                           const void *buf, size_t size);
808 
809   // The "WithFlavor" is necessary to keep SWIG from getting confused about
810   // overloaded arguments when using the buf + size -> Python Object magic.
811 
812   lldb::SBInstructionList GetInstructionsWithFlavor(lldb::SBAddress base_addr,
813                                                     const char *flavor_string,
814                                                     const void *buf,
815                                                     size_t size);
816 
817   lldb::SBInstructionList GetInstructions(lldb::addr_t base_addr,
818                                           const void *buf, size_t size);
819 
820   lldb::SBInstructionList GetInstructionsWithFlavor(lldb::addr_t base_addr,
821                                                     const char *flavor_string,
822                                                     const void *buf,
823                                                     size_t size);
824 
825   lldb::SBSymbolContextList FindSymbols(const char *name,
826                                         lldb::SymbolType type = eSymbolTypeAny);
827 
828   bool operator==(const lldb::SBTarget &rhs) const;
829 
830   bool operator!=(const lldb::SBTarget &rhs) const;
831 
832   bool GetDescription(lldb::SBStream &description,
833                       lldb::DescriptionLevel description_level);
834 
835   lldb::SBValue EvaluateExpression(const char *expr);
836 
837   lldb::SBValue EvaluateExpression(const char *expr,
838                                    const SBExpressionOptions &options);
839 
840   lldb::addr_t GetStackRedZoneSize();
841 
842   bool IsLoaded(const lldb::SBModule &module) const;
843 
844   lldb::SBLaunchInfo GetLaunchInfo() const;
845 
846   void SetLaunchInfo(const lldb::SBLaunchInfo &launch_info);
847 
848   /// Get a \a SBTrace object the can manage the processor trace information of
849   /// this target.
850   ///
851   /// \return
852   ///   The trace object. The returned SBTrace object might not be valid, so it
853   ///   should be checked with a call to "bool SBTrace::IsValid()".
854   lldb::SBTrace GetTrace();
855 
856   /// Create a \a Trace object for the current target using the using the
857   /// default supported tracing technology for this process.
858   ///
859   /// \param[out] error
860   ///     An error if a Trace already exists or the trace couldn't be created.
861   lldb::SBTrace CreateTrace(SBError &error);
862 
863 protected:
864   friend class SBAddress;
865   friend class SBBlock;
866   friend class SBBreakpointList;
867   friend class SBBreakpointNameImpl;
868   friend class SBDebugger;
869   friend class SBExecutionContext;
870   friend class SBFunction;
871   friend class SBInstruction;
872   friend class SBModule;
873   friend class SBPlatform;
874   friend class SBProcess;
875   friend class SBSection;
876   friend class SBSourceManager;
877   friend class SBSymbol;
878   friend class SBValue;
879   friend class SBVariablesOptions;
880 
881   // Constructors are private, use static Target::Create function to create an
882   // instance of this class.
883 
884   lldb::TargetSP GetSP() const;
885 
886   void SetSP(const lldb::TargetSP &target_sp);
887 
888 private:
889   lldb::TargetSP m_opaque_sp;
890 };
891 
892 } // namespace lldb
893 
894 #endif // LLDB_API_SBTARGET_H
895