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