1 //===-- SWIG Interface for SBTarget -----------------------------*- 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 namespace lldb {
10 
11 %feature("docstring",
12 "Represents the target program running under the debugger.
13 
14 SBTarget supports module, breakpoint, and watchpoint iterations. For example, ::
15 
16     for m in target.module_iter():
17         print m
18 
19 produces: ::
20 
21     (x86_64) /Volumes/data/lldb/svn/trunk/test/python_api/lldbutil/iter/a.out
22     (x86_64) /usr/lib/dyld
23     (x86_64) /usr/lib/libstdc++.6.dylib
24     (x86_64) /usr/lib/libSystem.B.dylib
25     (x86_64) /usr/lib/system/libmathCommon.A.dylib
26     (x86_64) /usr/lib/libSystem.B.dylib(__commpage)
27 
28 and, ::
29 
30     for b in target.breakpoint_iter():
31         print b
32 
33 produces: ::
34 
35     SBBreakpoint: id = 1, file ='main.cpp', line = 66, locations = 1
36     SBBreakpoint: id = 2, file ='main.cpp', line = 85, locations = 1
37 
38 and, ::
39 
40     for wp_loc in target.watchpoint_iter():
41         print wp_loc
42 
43 produces: ::
44 
45     Watchpoint 1: addr = 0x1034ca048 size = 4 state = enabled type = rw
46         declare @ '/Volumes/data/lldb/svn/trunk/test/python_api/watchpoint/main.c:12'
47         hw_index = 0  hit_count = 2     ignore_count = 0"
48 ) SBTarget;
49 class SBTarget
50 {
51 public:
52     //------------------------------------------------------------------
53     // Broadcaster bits.
54     //------------------------------------------------------------------
55     enum
56     {
57         eBroadcastBitBreakpointChanged  = (1 << 0),
58         eBroadcastBitModulesLoaded      = (1 << 1),
59         eBroadcastBitModulesUnloaded    = (1 << 2),
60         eBroadcastBitWatchpointChanged  = (1 << 3),
61         eBroadcastBitSymbolsLoaded      = (1 << 4)
62     };
63 
64     //------------------------------------------------------------------
65     // Constructors
66     //------------------------------------------------------------------
67     SBTarget ();
68 
69     SBTarget (const lldb::SBTarget& rhs);
70 
71     //------------------------------------------------------------------
72     // Destructor
73     //------------------------------------------------------------------
74     ~SBTarget();
75 
76     static const char *
77     GetBroadcasterClassName ();
78 
79     bool
80     IsValid() const;
81 
82     explicit operator bool() const;
83 
84     static bool
85     EventIsTargetEvent (const lldb::SBEvent &event);
86 
87     static lldb::SBTarget
88     GetTargetFromEvent (const lldb::SBEvent &event);
89 
90     static uint32_t
91     GetNumModulesFromEvent (const lldb::SBEvent &event);
92 
93     static lldb::SBModule
94     GetModuleAtIndexFromEvent (const uint32_t idx, const lldb::SBEvent &event);
95 
96     lldb::SBProcess
97     GetProcess ();
98 
99 
100     %feature("docstring", "
101     Return the platform object associated with the target.
102 
103     After return, the platform object should be checked for
104     validity.
105 
106     @return
107         A platform object.") GetPlatform;
108     lldb::SBPlatform
109     GetPlatform ();
110 
111     %feature("docstring", "
112     Install any binaries that need to be installed.
113 
114     This function does nothing when debugging on the host system.
115     When connected to remote platforms, the target's main executable
116     and any modules that have their install path set will be
117     installed on the remote platform. If the main executable doesn't
118     have an install location set, it will be installed in the remote
119     platform's working directory.
120 
121     @return
122         An error describing anything that went wrong during
123         installation.") Install;
124     lldb::SBError
125     Install();
126 
127     %feature("docstring", "
128     Launch a new process.
129 
130     Launch a new process by spawning a new process using the
131     target object's executable module's file as the file to launch.
132     Arguments are given in argv, and the environment variables
133     are in envp. Standard input and output files can be
134     optionally re-directed to stdin_path, stdout_path, and
135     stderr_path.
136 
137     @param[in] listener
138         An optional listener that will receive all process events.
139         If listener is valid then listener will listen to all
140         process events. If not valid, then this target's debugger
141         (SBTarget::GetDebugger()) will listen to all process events.
142 
143     @param[in] argv
144         The argument array.
145 
146     @param[in] envp
147         The environment array.
148 
149     @param[in] launch_flags
150         Flags to modify the launch (@see lldb::LaunchFlags)
151 
152     @param[in] stdin_path
153         The path to use when re-directing the STDIN of the new
154         process. If all stdXX_path arguments are NULL, a pseudo
155         terminal will be used.
156 
157     @param[in] stdout_path
158         The path to use when re-directing the STDOUT of the new
159         process. If all stdXX_path arguments are NULL, a pseudo
160         terminal will be used.
161 
162     @param[in] stderr_path
163         The path to use when re-directing the STDERR of the new
164         process. If all stdXX_path arguments are NULL, a pseudo
165         terminal will be used.
166 
167     @param[in] working_directory
168         The working directory to have the child process run in
169 
170     @param[in] launch_flags
171         Some launch options specified by logical OR'ing
172         lldb::LaunchFlags enumeration values together.
173 
174     @param[in] stop_at_entry
175         If false do not stop the inferior at the entry point.
176 
177     @param[out]
178         An error object. Contains the reason if there is some failure.
179 
180     @return
181          A process object for the newly created process.
182 
183     For example,
184 
185         process = target.Launch(self.dbg.GetListener(), None, None,
186                                 None, '/tmp/stdout.txt', None,
187                                 None, 0, False, error)
188 
189     launches a new process by passing nothing for both the args and the envs
190     and redirect the standard output of the inferior to the /tmp/stdout.txt
191     file. It does not specify a working directory so that the debug server
192     will use its idea of what the current working directory is for the
193     inferior. Also, we ask the debugger not to stop the inferior at the
194     entry point. If no breakpoint is specified for the inferior, it should
195     run to completion if no user interaction is required.") Launch;
196     lldb::SBProcess
197     Launch (SBListener &listener,
198             char const **argv,
199             char const **envp,
200             const char *stdin_path,
201             const char *stdout_path,
202             const char *stderr_path,
203             const char *working_directory,
204             uint32_t launch_flags,   // See LaunchFlags
205             bool stop_at_entry,
206             lldb::SBError& error);
207 
208     %feature("docstring", "
209     Launch a new process with sensible defaults.
210 
211     :param argv: The argument array.
212     :param envp: The environment array.
213     :param working_directory: The working directory to have the child process run in
214     :return: The newly created process.
215     :rtype: SBProcess
216 
217     A pseudo terminal will be used as stdin/stdout/stderr.
218     No launch flags are passed and the target's debuger is used as a listener.
219 
220     For example, ::
221 
222         process = target.LaunchSimple(['X', 'Y', 'Z'], None, os.getcwd())
223 
224     launches a new process by passing 'X', 'Y', 'Z' as the args to the
225     executable.") LaunchSimple;
226     lldb::SBProcess
227     LaunchSimple (const char **argv,
228                   const char **envp,
229                   const char *working_directory);
230 
231     lldb::SBProcess
232     Launch (lldb::SBLaunchInfo &launch_info, lldb::SBError& error);
233 
234     %feature("docstring", "
235     Load a core file
236 
237     @param[in] core_file
238         File path of the core dump.
239 
240     @param[out] error
241         An error explaining what went wrong if the operation fails.
242         (Optional)
243 
244     @return
245          A process object for the newly created core file.
246 
247     For example,
248 
249         process = target.LoadCore('./a.out.core')
250 
251     loads a new core file and returns the process object.") LoadCore;
252     lldb::SBProcess
253     LoadCore(const char *core_file);
254 
255     lldb::SBProcess
256     LoadCore(const char *core_file, lldb::SBError &error);
257 
258     lldb::SBProcess
259     Attach(lldb::SBAttachInfo &attach_info, lldb::SBError& error);
260 
261     %feature("docstring", "
262     Attach to process with pid.
263 
264     @param[in] listener
265         An optional listener that will receive all process events.
266         If listener is valid then listener will listen to all
267         process events. If not valid, then this target's debugger
268         (SBTarget::GetDebugger()) will listen to all process events.
269 
270     @param[in] pid
271         The process ID to attach to.
272 
273     @param[out]
274         An error explaining what went wrong if attach fails.
275 
276     @return
277          A process object for the attached process.") AttachToProcessWithID;
278     lldb::SBProcess
279     AttachToProcessWithID (SBListener &listener,
280                            lldb::pid_t pid,
281                            lldb::SBError& error);
282 
283     %feature("docstring", "
284     Attach to process with name.
285 
286     @param[in] listener
287         An optional listener that will receive all process events.
288         If listener is valid then listener will listen to all
289         process events. If not valid, then this target's debugger
290         (SBTarget::GetDebugger()) will listen to all process events.
291 
292     @param[in] name
293         Basename of process to attach to.
294 
295     @param[in] wait_for
296         If true wait for a new instance of 'name' to be launched.
297 
298     @param[out]
299         An error explaining what went wrong if attach fails.
300 
301     @return
302          A process object for the attached process.") AttachToProcessWithName;
303     lldb::SBProcess
304     AttachToProcessWithName (SBListener &listener,
305                              const char *name,
306                              bool wait_for,
307                              lldb::SBError& error);
308 
309     %feature("docstring", "
310     Connect to a remote debug server with url.
311 
312     @param[in] listener
313         An optional listener that will receive all process events.
314         If listener is valid then listener will listen to all
315         process events. If not valid, then this target's debugger
316         (SBTarget::GetDebugger()) will listen to all process events.
317 
318     @param[in] url
319         The url to connect to, e.g., 'connect://localhost:12345'.
320 
321     @param[in] plugin_name
322         The plugin name to be used; can be NULL.
323 
324     @param[out]
325         An error explaining what went wrong if the connect fails.
326 
327     @return
328          A process object for the connected process.") ConnectRemote;
329     lldb::SBProcess
330     ConnectRemote (SBListener &listener,
331                    const char *url,
332                    const char *plugin_name,
333                    SBError& error);
334 
335     lldb::SBFileSpec
336     GetExecutable ();
337 
338     %feature("docstring", "
339     Append the path mapping (from -> to) to the target's paths mapping list.") AppendImageSearchPath;
340     void
341     AppendImageSearchPath (const char *from,
342                            const char *to,
343                            SBError &error);
344 
345     bool
346     AddModule (lldb::SBModule &module);
347 
348     lldb::SBModule
349     AddModule (const char *path,
350                const char *triple,
351                const char *uuid);
352 
353     lldb::SBModule
354     AddModule (const char *path,
355                const char *triple,
356                const char *uuid_cstr,
357                const char *symfile);
358 
359     lldb::SBModule
360     AddModule (const SBModuleSpec &module_spec);
361 
362     uint32_t
363     GetNumModules () const;
364 
365     lldb::SBModule
366     GetModuleAtIndex (uint32_t idx);
367 
368     bool
369     RemoveModule (lldb::SBModule module);
370 
371     lldb::SBDebugger
372     GetDebugger() const;
373 
374     lldb::SBModule
375     FindModule (const lldb::SBFileSpec &file_spec);
376 
377     %feature("docstring", "
378     Find compile units related to this target and passed source
379     file.
380 
381     :param sb_file_spec: A :py:class:`lldb::SBFileSpec` object that contains source file
382         specification.
383     :return: The symbol contexts for all the matches.
384     :rtype: SBSymbolContextList") FindCompileUnits;
385     lldb::SBSymbolContextList
386     FindCompileUnits (const lldb::SBFileSpec &sb_file_spec);
387 
388     lldb::ByteOrder
389     GetByteOrder ();
390 
391     uint32_t
392     GetAddressByteSize();
393 
394     const char *
395     GetTriple ();
396 
397     %feature("docstring", "
398     Architecture data byte width accessor
399 
400     :return: The size in 8-bit (host) bytes of a minimum addressable unit from the Architecture's data bus.
401 
402     ") GetDataByteSize;
403     uint32_t
404     GetDataByteSize ();
405 
406     %feature("docstring", "
407     Architecture code byte width accessor.
408 
409     :return: The size in 8-bit (host) bytes of a minimum addressable unit from the Architecture's code bus.
410 
411     ") GetCodeByteSize;
412     uint32_t
413     GetCodeByteSize ();
414 
415     lldb::SBError
416     SetSectionLoadAddress (lldb::SBSection section,
417                            lldb::addr_t section_base_addr);
418 
419     lldb::SBError
420     ClearSectionLoadAddress (lldb::SBSection section);
421 
422     lldb::SBError
423     SetModuleLoadAddress (lldb::SBModule module,
424                           int64_t sections_offset);
425 
426     lldb::SBError
427     ClearModuleLoadAddress (lldb::SBModule module);
428 
429     %feature("docstring", "
430     Find functions by name.
431 
432     :param name: The name of the function we are looking for.
433 
434     :param name_type_mask:
435         A logical OR of one or more FunctionNameType enum bits that
436         indicate what kind of names should be used when doing the
437         lookup. Bits include fully qualified names, base names,
438         C++ methods, or ObjC selectors.
439         See FunctionNameType for more details.
440 
441     :return:
442         A lldb::SBSymbolContextList that gets filled in with all of
443         the symbol contexts for all the matches.") FindFunctions;
444     lldb::SBSymbolContextList
445     FindFunctions (const char *name,
446                    uint32_t name_type_mask = lldb::eFunctionNameTypeAny);
447 
448     lldb::SBType
449     FindFirstType (const char* type);
450 
451     lldb::SBTypeList
452     FindTypes (const char* type);
453 
454     lldb::SBType
455     GetBasicType(lldb::BasicType type);
456 
457     lldb::SBSourceManager
458     GetSourceManager ();
459 
460     %feature("docstring", "
461     Find global and static variables by name.
462 
463     @param[in] name
464         The name of the global or static variable we are looking
465         for.
466 
467     @param[in] max_matches
468         Allow the number of matches to be limited to max_matches.
469 
470     @return
471         A list of matched variables in an SBValueList.") FindGlobalVariables;
472     lldb::SBValueList
473     FindGlobalVariables (const char *name,
474                          uint32_t max_matches);
475 
476      %feature("docstring", "
477     Find the first global (or static) variable by name.
478 
479     @param[in] name
480         The name of the global or static variable we are looking
481         for.
482 
483     @return
484         An SBValue that gets filled in with the found variable (if any).") FindFirstGlobalVariable;
485     lldb::SBValue
486     FindFirstGlobalVariable (const char* name);
487 
488 
489     lldb::SBValueList
490     FindGlobalVariables(const char *name,
491                         uint32_t max_matches,
492                         MatchType matchtype);
493 
494     lldb::SBSymbolContextList
495     FindGlobalFunctions(const char *name,
496                         uint32_t max_matches,
497                         MatchType matchtype);
498 
499     void
500     Clear ();
501 
502      %feature("docstring", "
503     Resolve a current file address into a section offset address.
504 
505     @param[in] file_addr
506 
507     @return
508         An SBAddress which will be valid if...") ResolveFileAddress;
509     lldb::SBAddress
510     ResolveFileAddress (lldb::addr_t file_addr);
511 
512     lldb::SBAddress
513     ResolveLoadAddress (lldb::addr_t vm_addr);
514 
515     lldb::SBAddress
516     ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr);
517 
518     SBSymbolContext
519     ResolveSymbolContextForAddress (const SBAddress& addr,
520                                     uint32_t resolve_scope);
521 
522      %feature("docstring", "
523     Read target memory. If a target process is running then memory
524     is read from here. Otherwise the memory is read from the object
525     files. For a target whose bytes are sized as a multiple of host
526     bytes, the data read back will preserve the target's byte order.
527 
528     @param[in] addr
529         A target address to read from.
530 
531     @param[out] buf
532         The buffer to read memory into.
533 
534     @param[in] size
535         The maximum number of host bytes to read in the buffer passed
536         into this call
537 
538     @param[out] error
539         Error information is written here if the memory read fails.
540 
541     @return
542         The amount of data read in host bytes.") ReadMemory;
543     size_t
544     ReadMemory (const SBAddress addr, void *buf, size_t size, lldb::SBError &error);
545 
546     lldb::SBBreakpoint
547     BreakpointCreateByLocation (const char *file, uint32_t line);
548 
549     lldb::SBBreakpoint
550     BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line);
551 
552     lldb::SBBreakpoint
553     BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line, lldb::addr_t offset);
554 
555     lldb::SBBreakpoint
556     BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line,
557                                 lldb::addr_t offset, SBFileSpecList &module_list);
558 
559     lldb::SBBreakpoint
560     BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line,
561                                 uint32_t column, lldb::addr_t offset,
562                                 SBFileSpecList &module_list);
563 
564     lldb::SBBreakpoint
565     BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line,
566                                 uint32_t column, lldb::addr_t offset,
567                                 SBFileSpecList &module_list,
568                                 bool move_to_nearest_code);
569 
570     lldb::SBBreakpoint
571     BreakpointCreateByName (const char *symbol_name, const char *module_name = NULL);
572 
573     lldb::SBBreakpoint
574     BreakpointCreateByName (const char *symbol_name,
575                             uint32_t func_name_type,           // Logical OR one or more FunctionNameType enum bits
576                             const SBFileSpecList &module_list,
577                             const SBFileSpecList &comp_unit_list);
578 
579     lldb::SBBreakpoint
580     BreakpointCreateByName (const char *symbol_name,
581                             uint32_t func_name_type,           // Logical OR one or more FunctionNameType enum bits
582                             lldb::LanguageType symbol_language,
583                             const SBFileSpecList &module_list,
584                             const SBFileSpecList &comp_unit_list);
585 
586 #ifdef SWIGPYTHON
587 %typemap(in) (const char **symbol_name, uint32_t num_names) {
588   using namespace lldb_private;
589   /* Check if is a list  */
590   if (PythonList::Check($input)) {
591     PythonList list(PyRefType::Borrowed, $input);
592     $2 = list.GetSize();
593     int i = 0;
594     $1 = (char**)malloc(($2+1)*sizeof(char*));
595     for (i = 0; i < $2; i++) {
596       PythonString py_str = list.GetItemAtIndex(i).AsType<PythonString>();
597       if (!py_str.IsAllocated()) {
598         PyErr_SetString(PyExc_TypeError,"list must contain strings and blubby");
599         free($1);
600         return nullptr;
601       }
602 
603       $1[i] = const_cast<char*>(py_str.GetString().data());
604     }
605     $1[i] = 0;
606   } else if ($input == Py_None) {
607     $1 =  NULL;
608   } else {
609     PyErr_SetString(PyExc_TypeError,"not a list");
610     return NULL;
611   }
612 }
613 #endif
614 
615     lldb::SBBreakpoint
616     BreakpointCreateByNames (const char **symbol_name,
617                              uint32_t num_names,
618                              uint32_t name_type_mask,           // Logical OR one or more FunctionNameType enum bits
619                              const SBFileSpecList &module_list,
620                              const SBFileSpecList &comp_unit_list);
621 
622     lldb::SBBreakpoint
623     BreakpointCreateByNames (const char **symbol_name,
624                              uint32_t num_names,
625                              uint32_t name_type_mask,           // Logical OR one or more FunctionNameType enum bits
626                              lldb::LanguageType symbol_language,
627                              const SBFileSpecList &module_list,
628                              const SBFileSpecList &comp_unit_list);
629 
630     lldb::SBBreakpoint
631     BreakpointCreateByNames (const char **symbol_name,
632                              uint32_t num_names,
633                              uint32_t name_type_mask,           // Logical OR one or more FunctionNameType enum bits
634                              lldb::LanguageType symbol_language,
635                              lldb::addr_t offset,
636                              const SBFileSpecList &module_list,
637                              const SBFileSpecList &comp_unit_list);
638 
639     lldb::SBBreakpoint
640     BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name = NULL);
641 
642     lldb::SBBreakpoint
643     BreakpointCreateByRegex (const char *symbol_name_regex,
644                              lldb::LanguageType symbol_language,
645                              const SBFileSpecList &module_list,
646                              const SBFileSpecList &comp_unit_list);
647 
648     lldb::SBBreakpoint
649     BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name = NULL);
650 
651     lldb::SBBreakpoint
652     BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpecList &module_list, const lldb::SBFileSpecList &file_list);
653 
654     lldb::SBBreakpoint
655     BreakpointCreateBySourceRegex (const char *source_regex,
656                                    const SBFileSpecList &module_list,
657                                    const SBFileSpecList &source_file,
658                                    const SBStringList  &func_names);
659 
660     lldb::SBBreakpoint
661     BreakpointCreateForException  (lldb::LanguageType language,
662                                    bool catch_bp,
663                                    bool throw_bp);
664 
665     lldb::SBBreakpoint
666     BreakpointCreateByAddress (addr_t address);
667 
668     lldb::SBEnvironment
669     GetEnvironment();
670 
671     lldb::SBBreakpoint
672     BreakpointCreateBySBAddress (SBAddress &sb_address);
673 
674     %feature("docstring", "
675     Create a breakpoint using a scripted resolver.
676 
677     @param[in] class_name
678        This is the name of the class that implements a scripted resolver.
679        The class should have the following signature: ::
680 
681            class Resolver:
682                def __init__(self, bkpt, extra_args):
683                    # bkpt - the breakpoint for which this is the resolver.  When
684                    # the resolver finds an interesting address, call AddLocation
685                    # on this breakpoint to add it.
686                    #
687                    # extra_args - an SBStructuredData that can be used to
688                    # parametrize this instance.  Same as the extra_args passed
689                    # to BreakpointCreateFromScript.
690 
691                def __get_depth__ (self):
692                    # This is optional, but if defined, you should return the
693                    # depth at which you want the callback to be called.  The
694                    # available options are:
695                    #    lldb.eSearchDepthModule
696                    #    lldb.eSearchDepthCompUnit
697                    # The default if you don't implement this method is
698                    # eSearchDepthModule.
699 
700                def __callback__(self, sym_ctx):
701                    # sym_ctx - an SBSymbolContext that is the cursor in the
702                    # search through the program to resolve breakpoints.
703                    # The sym_ctx will be filled out to the depth requested in
704                    # __get_depth__.
705                    # Look in this sym_ctx for new breakpoint locations,
706                    # and if found use bkpt.AddLocation to add them.
707                    # Note, you will only get called for modules/compile_units that
708                    # pass the SearchFilter provided by the module_list & file_list
709                    # passed into BreakpointCreateFromScript.
710 
711                def get_short_help(self):
712                    # Optional, but if implemented return a short string that will
713                    # be printed at the beginning of the break list output for the
714                    # breakpoint.
715 
716     @param[in] extra_args
717        This is an SBStructuredData object that will get passed to the
718        constructor of the class in class_name.  You can use this to
719        reuse the same class, parametrizing it with entries from this
720        dictionary.
721 
722     @param module_list
723        If this is non-empty, this will be used as the module filter in the
724        SearchFilter created for this breakpoint.
725 
726     @param file_list
727        If this is non-empty, this will be used as the comp unit filter in the
728        SearchFilter created for this breakpoint.
729 
730     @return
731         An SBBreakpoint that will set locations based on the logic in the
732         resolver's search callback.") BreakpointCreateFromScript;
733     lldb::SBBreakpoint BreakpointCreateFromScript(
734       const char *class_name,
735       SBStructuredData &extra_args,
736       const SBFileSpecList &module_list,
737       const SBFileSpecList &file_list,
738       bool request_hardware = false);
739 
740     uint32_t
741     GetNumBreakpoints () const;
742 
743     lldb::SBBreakpoint
744     GetBreakpointAtIndex (uint32_t idx) const;
745 
746     bool
747     BreakpointDelete (break_id_t break_id);
748 
749     lldb::SBBreakpoint
750     FindBreakpointByID (break_id_t break_id);
751 
752 
753     bool FindBreakpointsByName(const char *name, SBBreakpointList &bkpt_list);
754 
755     void DeleteBreakpointName(const char *name);
756 
757     void GetBreakpointNames(SBStringList &names);
758 
759     bool
760     EnableAllBreakpoints ();
761 
762     bool
763     DisableAllBreakpoints ();
764 
765     bool
766     DeleteAllBreakpoints ();
767 
768      %feature("docstring", "
769     Read breakpoints from source_file and return the newly created
770     breakpoints in bkpt_list.
771 
772     @param[in] source_file
773        The file from which to read the breakpoints
774 
775     @param[out] bkpt_list
776        A list of the newly created breakpoints.
777 
778     @return
779         An SBError detailing any errors in reading in the breakpoints.") BreakpointsCreateFromFile;
780     lldb::SBError
781     BreakpointsCreateFromFile(SBFileSpec &source_file,
782                               SBBreakpointList &bkpt_list);
783 
784      %feature("docstring", "
785     Read breakpoints from source_file and return the newly created
786     breakpoints in bkpt_list.
787 
788     @param[in] source_file
789        The file from which to read the breakpoints
790 
791     @param[in] matching_names
792        Only read in breakpoints whose names match one of the names in this
793        list.
794 
795     @param[out] bkpt_list
796        A list of the newly created breakpoints.
797 
798     @return
799         An SBError detailing any errors in reading in the breakpoints.") BreakpointsCreateFromFile;
800     lldb::SBError BreakpointsCreateFromFile(SBFileSpec &source_file,
801                                           SBStringList &matching_names,
802                                           SBBreakpointList &new_bps);
803 
804      %feature("docstring", "
805     Write breakpoints to dest_file.
806 
807     @param[in] dest_file
808        The file to which to write the breakpoints.
809 
810     @return
811         An SBError detailing any errors in writing in the breakpoints.") BreakpointsCreateFromFile;
812     lldb::SBError
813     BreakpointsWriteToFile(SBFileSpec &dest_file);
814 
815      %feature("docstring", "
816     Write breakpoints listed in bkpt_list to dest_file.
817 
818     @param[in] dest_file
819        The file to which to write the breakpoints.
820 
821     @param[in] bkpt_list
822        Only write breakpoints from this list.
823 
824     @param[in] append
825        If true, append the breakpoints in bkpt_list to the others
826        serialized in dest_file.  If dest_file doesn't exist, then a new
827        file will be created and the breakpoints in bkpt_list written to it.
828 
829     @return
830         An SBError detailing any errors in writing in the breakpoints.") BreakpointsCreateFromFile;
831     lldb::SBError
832     BreakpointsWriteToFile(SBFileSpec &dest_file,
833                            SBBreakpointList &bkpt_list,
834                            bool append = false);
835 
836     uint32_t
837     GetNumWatchpoints () const;
838 
839     lldb::SBWatchpoint
840     GetWatchpointAtIndex (uint32_t idx) const;
841 
842     bool
843     DeleteWatchpoint (lldb::watch_id_t watch_id);
844 
845     lldb::SBWatchpoint
846     FindWatchpointByID (lldb::watch_id_t watch_id);
847 
848     bool
849     EnableAllWatchpoints ();
850 
851     bool
852     DisableAllWatchpoints ();
853 
854     bool
855     DeleteAllWatchpoints ();
856 
857     lldb::SBWatchpoint
858     WatchAddress (lldb::addr_t addr,
859                   size_t size,
860                   bool read,
861                   bool write,
862                   SBError &error);
863 
864 
865     lldb::SBBroadcaster
866     GetBroadcaster () const;
867 
868      %feature("docstring", "
869     Create an SBValue with the given name by treating the memory starting at addr as an entity of type.
870 
871     @param[in] name
872         The name of the resultant SBValue
873 
874     @param[in] addr
875         The address of the start of the memory region to be used.
876 
877     @param[in] type
878         The type to use to interpret the memory starting at addr.
879 
880     @return
881         An SBValue of the given type, may be invalid if there was an error reading
882         the underlying memory.") CreateValueFromAddress;
883     lldb::SBValue
884     CreateValueFromAddress (const char *name, lldb::SBAddress addr, lldb::SBType type);
885 
886     lldb::SBValue
887     CreateValueFromData (const char *name, lldb::SBData data, lldb::SBType type);
888 
889     lldb::SBValue
890     CreateValueFromExpression (const char *name, const char* expr);
891 
892     %feature("docstring", "
893     Disassemble a specified number of instructions starting at an address.
894 
895     :param base_addr: the address to start disassembly from.
896     :param count: the number of instructions to disassemble.
897     :param flavor_string: may be 'intel' or 'att' on x86 targets to specify that style of disassembly.
898     :rtype: SBInstructionList
899     ")
900     ReadInstructions;
901     lldb::SBInstructionList
902     ReadInstructions (lldb::SBAddress base_addr, uint32_t count);
903 
904     lldb::SBInstructionList
905     ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string);
906 
907     %feature("docstring", "
908     Disassemble the bytes in a buffer and return them in an SBInstructionList.
909 
910     :param base_addr: used for symbolicating the offsets in the byte stream when disassembling.
911     :param buf: bytes to be disassembled.
912     :param size: (C++) size of the buffer.
913     :rtype: SBInstructionList
914     ")
915     GetInstructions;
916     lldb::SBInstructionList
917     GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size);
918 
919     %feature("docstring", "
920     Disassemble the bytes in a buffer and return them in an SBInstructionList, with a supplied flavor.
921 
922     :param base_addr: used for symbolicating the offsets in the byte stream when disassembling.
923     :param flavor:  may be 'intel' or 'att' on x86 targets to specify that style of disassembly.
924     :param buf: bytes to be disassembled.
925     :param size: (C++) size of the buffer.
926     :rtype: SBInstructionList
927     ")
928     GetInstructionsWithFlavor;
929     lldb::SBInstructionList
930     GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size);
931 
932     lldb::SBSymbolContextList
933     FindSymbols (const char *name, lldb::SymbolType type = eSymbolTypeAny);
934 
935     bool
936     GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level);
937 
938     lldb::addr_t
939     GetStackRedZoneSize();
940 
941     %feature("docstring", "
942     Returns true if the module has been loaded in this `SBTarget`.
943     A module can be loaded either by the dynamic loader or by being manually
944     added to the target (see `SBTarget.AddModule` and the `target module add` command).
945 
946     :rtype: bool
947     ") IsLoaded;
948     bool
949     IsLoaded (const lldb::SBModule &module) const;
950 
951     lldb::SBLaunchInfo
952     GetLaunchInfo () const;
953 
954     void
955     SetLaunchInfo (const lldb::SBLaunchInfo &launch_info);
956 
957     void SetCollectingStats(bool v);
958 
959     bool GetCollectingStats();
960 
961     lldb::SBStructuredData GetStatistics();
962 
963     bool
964     operator == (const lldb::SBTarget &rhs) const;
965 
966     bool
967     operator != (const lldb::SBTarget &rhs) const;
968 
969     lldb::SBValue
970     EvaluateExpression (const char *expr);
971 
972     lldb::SBValue
973     EvaluateExpression (const char *expr, const lldb::SBExpressionOptions &options);
974 
975     STRING_EXTENSION_LEVEL(SBTarget, lldb::eDescriptionLevelBrief)
976 
977     lldb::SBTrace
978     GetTrace ();
979 
980     lldb::SBTrace
981     CreateTrace (lldb::SBError &error);
982 
983 #ifdef SWIGPYTHON
984     %pythoncode %{
985         class modules_access(object):
986             '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.'''
987             def __init__(self, sbtarget):
988                 self.sbtarget = sbtarget
989 
990             def __len__(self):
991                 if self.sbtarget:
992                     return int(self.sbtarget.GetNumModules())
993                 return 0
994 
995             def __getitem__(self, key):
996                 num_modules = self.sbtarget.GetNumModules()
997                 if type(key) is int:
998                     if key < num_modules:
999                         return self.sbtarget.GetModuleAtIndex(key)
1000                 elif type(key) is str:
1001                     if key.find('/') == -1:
1002                         for idx in range(num_modules):
1003                             module = self.sbtarget.GetModuleAtIndex(idx)
1004                             if module.file.basename == key:
1005                                 return module
1006                     else:
1007                         for idx in range(num_modules):
1008                             module = self.sbtarget.GetModuleAtIndex(idx)
1009                             if module.file.fullpath == key:
1010                                 return module
1011                     # See if the string is a UUID
1012                     try:
1013                         the_uuid = uuid.UUID(key)
1014                         if the_uuid:
1015                             for idx in range(num_modules):
1016                                 module = self.sbtarget.GetModuleAtIndex(idx)
1017                                 if module.uuid == the_uuid:
1018                                     return module
1019                     except:
1020                         return None
1021                 elif type(key) is uuid.UUID:
1022                     for idx in range(num_modules):
1023                         module = self.sbtarget.GetModuleAtIndex(idx)
1024                         if module.uuid == key:
1025                             return module
1026                 elif type(key) is re.SRE_Pattern:
1027                     matching_modules = []
1028                     for idx in range(num_modules):
1029                         module = self.sbtarget.GetModuleAtIndex(idx)
1030                         re_match = key.search(module.path.fullpath)
1031                         if re_match:
1032                             matching_modules.append(module)
1033                     return matching_modules
1034                 else:
1035                     print("error: unsupported item type: %s" % type(key))
1036                 return None
1037 
1038         def get_modules_access_object(self):
1039             '''An accessor function that returns a modules_access() object which allows lazy module access from a lldb.SBTarget object.'''
1040             return self.modules_access (self)
1041 
1042         def get_modules_array(self):
1043             '''An accessor function that returns a list() that contains all modules in a lldb.SBTarget object.'''
1044             modules = []
1045             for idx in range(self.GetNumModules()):
1046                 modules.append(self.GetModuleAtIndex(idx))
1047             return modules
1048 
1049         def module_iter(self):
1050             '''Returns an iterator over all modules in a lldb.SBTarget
1051             object.'''
1052             return lldb_iter(self, 'GetNumModules', 'GetModuleAtIndex')
1053 
1054         def breakpoint_iter(self):
1055             '''Returns an iterator over all breakpoints in a lldb.SBTarget
1056             object.'''
1057             return lldb_iter(self, 'GetNumBreakpoints', 'GetBreakpointAtIndex')
1058 
1059         def watchpoint_iter(self):
1060             '''Returns an iterator over all watchpoints in a lldb.SBTarget
1061             object.'''
1062             return lldb_iter(self, 'GetNumWatchpoints', 'GetWatchpointAtIndex')
1063 
1064         modules = property(get_modules_array, None, doc='''A read only property that returns a list() of lldb.SBModule objects contained in this target. This list is a list all modules that the target currently is tracking (the main executable and all dependent shared libraries).''')
1065         module = property(get_modules_access_object, None, doc=r'''A read only property that returns an object that implements python operator overloading with the square brackets().\n    target.module[<int>] allows array access to any modules.\n    target.module[<str>] allows access to modules by basename, full path, or uuid string value.\n    target.module[uuid.UUID()] allows module access by UUID.\n    target.module[re] allows module access using a regular expression that matches the module full path.''')
1066         process = property(GetProcess, None, doc='''A read only property that returns an lldb object that represents the process (lldb.SBProcess) that this target owns.''')
1067         executable = property(GetExecutable, None, doc='''A read only property that returns an lldb object that represents the main executable module (lldb.SBModule) for this target.''')
1068         debugger = property(GetDebugger, None, doc='''A read only property that returns an lldb object that represents the debugger (lldb.SBDebugger) that owns this target.''')
1069         num_breakpoints = property(GetNumBreakpoints, None, doc='''A read only property that returns the number of breakpoints that this target has as an integer.''')
1070         num_watchpoints = property(GetNumWatchpoints, None, doc='''A read only property that returns the number of watchpoints that this target has as an integer.''')
1071         broadcaster = property(GetBroadcaster, None, doc='''A read only property that an lldb object that represents the broadcaster (lldb.SBBroadcaster) for this target.''')
1072         byte_order = property(GetByteOrder, None, doc='''A read only property that returns an lldb enumeration value (lldb.eByteOrderLittle, lldb.eByteOrderBig, lldb.eByteOrderInvalid) that represents the byte order for this target.''')
1073         addr_size = property(GetAddressByteSize, None, doc='''A read only property that returns the size in bytes of an address for this target.''')
1074         triple = property(GetTriple, None, doc='''A read only property that returns the target triple (arch-vendor-os) for this target as a string.''')
1075         data_byte_size = property(GetDataByteSize, None, doc='''A read only property that returns the size in host bytes of a byte in the data address space for this target.''')
1076         code_byte_size = property(GetCodeByteSize, None, doc='''A read only property that returns the size in host bytes of a byte in the code address space for this target.''')
1077         platform = property(GetPlatform, None, doc='''A read only property that returns the platform associated with with this target.''')
1078     %}
1079 #endif
1080 };
1081 } // namespace lldb
1082