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