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