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