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