CVS Repository/ src/ gnu/ llvm/ lldb/ bindings/ python/ python.swig

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