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