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