blob: 16177f83301bca199f8a9bafcadd8148be0b82ab [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001/*
2 lldb.swig
3
4 Created by Caroline Tice 1/18/2010
5
6 This is the input file for SWIG, to create the appropriate C++ wrappers and
7 functions for various scripting languages, to enable them to call the
8 liblldb Script Bridge functions.
9
10*/
11
12/* The name of the module to be created. */
13
14%module lldb
15
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016/* Typemap definitions, to allow SWIG to properly handle 'char**' data types. */
17
18%typemap(in) char ** {
19 /* Check if is a list */
20 if (PyList_Check($input)) {
21 int size = PyList_Size($input);
22 int i = 0;
23 $1 = (char **) malloc((size+1) * sizeof(char));
24 for (i = 0; i < size; i++) {
25 PyObject *o = PyList_GetItem($input,i);
26 if (PyString_Check(o))
27 $1[i] = PyString_AsString(PyList_GetItem($input,i));
28 else {
29 PyErr_SetString(PyExc_TypeError,"list must contain strings");
30 free($1);
31 return NULL;
32 }
33 }
34 $1[i] = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000035 } else if ($input == Py_None) {
36 $1 = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037 } else {
38 PyErr_SetString(PyExc_TypeError,"not a list");
39 return NULL;
40 }
41}
42
43%typemap(freearg) char** {
44 free((char *) $1);
45}
46
47%typemap(out) char** {
48 int len;
49 int i;
50 len = 0;
51 while ($1[len]) len++;
52 $result = PyList_New(len);
53 for (i = 0; i < len; i++) {
54 PyList_SetItem($result, i, PyString_FromString($1[i]));
55 }
56}
57
58
Greg Claytonc0cc73e2010-06-12 15:34:20 +000059/* The liblldb header files to be included. */
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060
61%{
Greg Clayton05faeb72010-10-07 04:19:01 +000062#include "lldb/lldb-include.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063#include "lldb/API/SBAddress.h"
64#include "lldb/API/SBBlock.h"
65#include "lldb/API/SBBreakpoint.h"
66#include "lldb/API/SBBreakpointLocation.h"
67#include "lldb/API/SBBroadcaster.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068#include "lldb/API/SBCommandInterpreter.h"
69#include "lldb/API/SBCommandReturnObject.h"
Greg Clayton05faeb72010-10-07 04:19:01 +000070#include "lldb/API/SBCommunication.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071#include "lldb/API/SBCompileUnit.h"
72#include "lldb/API/SBDebugger.h"
73#include "lldb/API/SBError.h"
74#include "lldb/API/SBEvent.h"
Johnny Chen23fd10c2010-08-27 22:35:26 +000075#include "lldb/API/SBFileSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076#include "lldb/API/SBFrame.h"
77#include "lldb/API/SBFunction.h"
Greg Clayton05faeb72010-10-07 04:19:01 +000078#include "lldb/API/SBHostOS.h"
79#include "lldb/API/SBInputReader.h"
Greg Clayton1d273162010-10-06 03:09:58 +000080#include "lldb/API/SBInstruction.h"
81#include "lldb/API/SBInstructionList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082#include "lldb/API/SBLineEntry.h"
83#include "lldb/API/SBListener.h"
84#include "lldb/API/SBModule.h"
85#include "lldb/API/SBProcess.h"
86#include "lldb/API/SBSourceManager.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000087#include "lldb/API/SBStream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088#include "lldb/API/SBStringList.h"
89#include "lldb/API/SBSymbol.h"
90#include "lldb/API/SBSymbolContext.h"
Greg Clayton05faeb72010-10-07 04:19:01 +000091#include "lldb/API/SBSymbolContextList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000092#include "lldb/API/SBTarget.h"
93#include "lldb/API/SBThread.h"
94#include "lldb/API/SBType.h"
95#include "lldb/API/SBValue.h"
Caroline Tice77404122010-09-22 16:41:52 +000096#include "lldb/API/SBValueList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000097%}
98
99/* Various liblldb typedefs that SWIG needs to know about. */
Johnny Chen4b332092010-12-16 00:01:06 +0000100#define __extension__ /* Undefine GCC keyword to make Swig happy when processing glibc's stdint.h. */
Greg Clayton05faeb72010-10-07 04:19:01 +0000101%include <stdint.h>
102%include "lldb/lldb-defines.h"
103%include "lldb/lldb-enumerations.h"
104%include "lldb/lldb-forward.h"
105%include "lldb/lldb-forward-rtti.h"
106%include "lldb/lldb-types.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000107%include "lldb/API/SBAddress.h"
108%include "lldb/API/SBBlock.h"
109%include "lldb/API/SBBreakpoint.h"
110%include "lldb/API/SBBreakpointLocation.h"
111%include "lldb/API/SBBroadcaster.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112%include "lldb/API/SBCommandInterpreter.h"
113%include "lldb/API/SBCommandReturnObject.h"
Greg Clayton05faeb72010-10-07 04:19:01 +0000114%include "lldb/API/SBCommunication.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115%include "lldb/API/SBCompileUnit.h"
116%include "lldb/API/SBDebugger.h"
117%include "lldb/API/SBError.h"
118%include "lldb/API/SBEvent.h"
Johnny Chen23fd10c2010-08-27 22:35:26 +0000119%include "lldb/API/SBFileSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000120%include "lldb/API/SBFrame.h"
121%include "lldb/API/SBFunction.h"
Greg Clayton05faeb72010-10-07 04:19:01 +0000122%include "lldb/API/SBHostOS.h"
123%include "lldb/API/SBInputReader.h"
Greg Clayton1d273162010-10-06 03:09:58 +0000124%include "lldb/API/SBInstruction.h"
125%include "lldb/API/SBInstructionList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126%include "lldb/API/SBLineEntry.h"
127%include "lldb/API/SBListener.h"
128%include "lldb/API/SBModule.h"
129%include "lldb/API/SBProcess.h"
130%include "lldb/API/SBSourceManager.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +0000131%include "lldb/API/SBStream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000132%include "lldb/API/SBStringList.h"
133%include "lldb/API/SBSymbol.h"
134%include "lldb/API/SBSymbolContext.h"
Greg Clayton05faeb72010-10-07 04:19:01 +0000135%include "lldb/API/SBSymbolContextList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000136%include "lldb/API/SBTarget.h"
137%include "lldb/API/SBThread.h"
138%include "lldb/API/SBType.h"
139%include "lldb/API/SBValue.h"
Caroline Tice77404122010-09-22 16:41:52 +0000140%include "lldb/API/SBValueList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000141
Caroline Ticedac97f32010-09-22 23:01:29 +0000142%include "./Python/python-extensions.swig"
Caroline Tice18474c92010-09-27 18:00:20 +0000143
144
145%wrapper %{
146
Greg Claytonc6ed5422010-10-07 17:14:24 +0000147// This function is called by lldb_private::ScriptInterpreterPython::BreakpointCallbackFunction(...)
148// and is used when a script command is attached to a breakpoint for execution.
Caroline Tice18474c92010-09-27 18:00:20 +0000149
Greg Claytonc6ed5422010-10-07 17:14:24 +0000150SWIGEXPORT bool
151LLDBSWIGPythonBreakpointCallbackFunction
Greg Clayton05faeb72010-10-07 04:19:01 +0000152(
Greg Claytonc6ed5422010-10-07 17:14:24 +0000153 const char *python_function_name,
154 lldb::SBFrame& sb_frame,
155 lldb::SBBreakpointLocation& sb_bp_loc
Greg Clayton05faeb72010-10-07 04:19:01 +0000156)
Caroline Tice18474c92010-09-27 18:00:20 +0000157{
Greg Claytonc6ed5422010-10-07 17:14:24 +0000158 bool stop_at_breakpoint = true;
159 PyObject *Frame_PyObj = SWIG_NewPointerObj((void *) &sb_frame, SWIGTYPE_p_lldb__SBFrame, 0);
160 PyObject *Bp_Loc_PyObj = SWIG_NewPointerObj ((void *) &sb_bp_loc, SWIGTYPE_p_lldb__SBBreakpointLocation, 0);
Caroline Tice18474c92010-09-27 18:00:20 +0000161
Greg Claytonc6ed5422010-10-07 17:14:24 +0000162 if (Frame_PyObj == NULL || Bp_Loc_PyObj == NULL)
163 return stop_at_breakpoint;
164
165 PyObject *pmodule, *pdict, *pfunc;
166 PyObject *pargs, *pvalue;
Caroline Tice18474c92010-09-27 18:00:20 +0000167
Greg Claytonc6ed5422010-10-07 17:14:24 +0000168 pmodule = PyImport_AddModule ("__main__");
169 if (pmodule != NULL)
Caroline Tice18474c92010-09-27 18:00:20 +0000170 {
Greg Claytonc6ed5422010-10-07 17:14:24 +0000171 pdict = PyModule_GetDict (pmodule);
172 if (pdict != NULL)
Caroline Tice18474c92010-09-27 18:00:20 +0000173 {
Greg Claytonc6ed5422010-10-07 17:14:24 +0000174 pfunc = PyObject_GetAttrString (pmodule, python_function_name);
175 if (pfunc && PyCallable_Check (pfunc))
Caroline Tice18474c92010-09-27 18:00:20 +0000176 {
Greg Claytonc6ed5422010-10-07 17:14:24 +0000177 pargs = PyTuple_New (2);
178 if (pargs == NULL)
Caroline Tice18474c92010-09-27 18:00:20 +0000179 {
Greg Claytonc6ed5422010-10-07 17:14:24 +0000180 if (PyErr_Occurred())
Caroline Tice18474c92010-09-27 18:00:20 +0000181 PyErr_Clear();
Greg Claytonc6ed5422010-10-07 17:14:24 +0000182 return stop_at_breakpoint;
Caroline Tice18474c92010-09-27 18:00:20 +0000183 }
Greg Claytonc6ed5422010-10-07 17:14:24 +0000184
185 PyTuple_SetItem (pargs, 0, Frame_PyObj); // This "steals" a reference to Frame_PyObj
186 PyTuple_SetItem (pargs, 1, Bp_Loc_PyObj); // This "steals" a reference to Bp_Loc_PyObj
187 pvalue = PyObject_CallObject (pfunc, pargs);
188 Py_DECREF (pargs);
189
190 if (pvalue != NULL)
191 {
192 Py_DECREF (pvalue);
193 }
194 else if (PyErr_Occurred ())
Caroline Tice18474c92010-09-27 18:00:20 +0000195 {
196 PyErr_Clear();
197 }
Greg Claytonc6ed5422010-10-07 17:14:24 +0000198 Py_DECREF (pfunc);
Caroline Tice18474c92010-09-27 18:00:20 +0000199 }
200 else if (PyErr_Occurred())
201 {
202 PyErr_Clear();
203 }
204 }
Greg Claytonc6ed5422010-10-07 17:14:24 +0000205 else if (PyErr_Occurred())
Caroline Tice18474c92010-09-27 18:00:20 +0000206 {
Greg Claytonc6ed5422010-10-07 17:14:24 +0000207 PyErr_Clear();
Caroline Tice18474c92010-09-27 18:00:20 +0000208 }
209 }
Greg Claytonc6ed5422010-10-07 17:14:24 +0000210 else if (PyErr_Occurred ())
211 {
212 PyErr_Clear ();
213 }
214 return stop_at_breakpoint;
Caroline Tice18474c92010-09-27 18:00:20 +0000215}
216
217%}