]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/bindings/python.swig
Import PCG-C into sys/contrib
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / bindings / python.swig
1 /*
2    lldb.swig
3
4    This is the input file for SWIG, to create the appropriate C++ wrappers and
5    functions for various scripting languages, to enable them to call the
6    liblldb Script Bridge functions.
7 */
8
9 /* Define our module docstring. */
10 %define DOCSTRING
11 "The lldb module contains the public APIs for Python binding.
12
13 Some of the important classes are described here:
14
15 o SBTarget: Represents the target program running under the debugger.
16 o SBProcess: Represents the process associated with the target program.
17 o SBThread: Represents a thread of execution. SBProcess contains SBThread(s).
18 o SBFrame: Represents one of the stack frames associated with a thread. SBThread
19       contains SBFrame(s).
20 o SBSymbolContext: A container that stores various debugger related info.
21 o SBValue: Represents the value of a variable, a register, or an expression.
22 o SBModule: Represents an executable image and its associated object and symbol
23       files.  SBTarget contains SBModule(s).
24 o SBBreakpoint: Represents a logical breakpoint and its associated settings.
25       SBTarget contains SBBreakpoint(s).
26 o SBSymbol: Represents the symbol possibly associated with a stack frame.
27 o SBCompileUnit: Represents a compilation unit, or compiled source file.
28 o SBFunction: Represents a generic function, which can be inlined or not.
29 o SBBlock: Represents a lexical block. SBFunction contains SBBlock(s).
30 o SBLineEntry: Specifies an association with a contiguous range of instructions
31       and a source file location. SBCompileUnit contains SBLineEntry(s)."
32 %enddef
33
34 /*
35 Since version 3.0.9, swig's logic for importing the native module has changed in
36 a way that is incompatible with our usage of the python module as __init__.py
37 (See swig bug #769).  Fortunately, since version 3.0.11, swig provides a way for
38 us to override the module import logic to suit our needs. This does that.
39
40 Older swig versions will simply ignore this setting.
41 */
42 %define MODULEIMPORT
43 "try:
44     # Try an absolute import first.  If we're being loaded from lldb,
45     # _lldb should be a built-in module.
46     import $module
47 except ImportError:
48     # Relative import should work if we are being loaded by Python.
49     from . import $module"
50 %enddef
51 // These versions will not generate working python modules, so error out early.
52 #if SWIG_VERSION >= 0x030009 && SWIG_VERSION < 0x030011
53 #error Swig versions 3.0.9 and 3.0.10 are incompatible with lldb.
54 #endif
55
56 // The name of the module to be created.
57 %module(docstring=DOCSTRING, moduleimport=MODULEIMPORT) lldb
58
59 // Parameter types will be used in the autodoc string.
60 %feature("autodoc", "1");
61
62 %define ARRAYHELPER(type,name)
63 %inline %{
64 type *new_ ## name (int nitems) {
65    return (type *) malloc(sizeof(type)*nitems);
66 }
67 void delete_ ## name(type *t) {
68    free(t);
69 }
70 type name ## _get(type *t, int index) {
71    return t[index];
72 }
73 void name ## _set(type *t, int index, type val) {
74    t[index] = val;
75 }
76 %}
77 %enddef
78
79 %pythoncode%{
80 import uuid
81 import re
82 import os
83
84 import six
85 %}
86
87 // Include the version of swig that was used to generate this interface.
88 %define EMBED_VERSION(VERSION)
89 %pythoncode%{
90 # SWIG_VERSION is written as a single hex number, but the components of it are
91 # meant to be interpreted in decimal. So, 0x030012 is swig 3.0.12, and not
92 # 3.0.18.
93 def _to_int(hex):
94     return hex // 0x10 % 0x10 * 10 + hex % 0x10
95 swig_version = (_to_int(VERSION // 0x10000), _to_int(VERSION // 0x100), _to_int(VERSION))
96 del _to_int
97 %}
98 %enddef
99 EMBED_VERSION(SWIG_VERSION)
100
101 %pythoncode%{
102 # ===================================
103 # Iterator for lldb container objects
104 # ===================================
105 def lldb_iter(obj, getsize, getelem):
106     """A generator adaptor to support iteration for lldb container objects."""
107     size = getattr(obj, getsize)
108     elem = getattr(obj, getelem)
109     for i in range(size()):
110         yield elem(i)
111 %}
112
113 %include <std_string.i>
114 %include "./python/python-typemaps.swig"
115 %include "./macros.swig"
116 %include "./headers.swig"
117
118 %{
119 #include "../source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h"
120 #include "../bindings/python/python-swigsafecast.swig"
121 using namespace lldb_private;
122 using namespace lldb_private::python;
123 using namespace lldb;
124 %}
125
126 %include "./interfaces.swig"
127 %include "./python/python-extensions.swig"
128 %include "./python/python-wrapper.swig"
129
130 %pythoncode%{
131 debugger_unique_id = 0
132 SBDebugger.Initialize()
133 debugger = None
134 target = None
135 process = None
136 thread = None
137 frame = None
138 %}