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