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