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