blob: e144944458c19a9209d53aeb1db6bd21258f899a [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
16%typemap(in) lldb::ReturnStatus {
17 $1 = (int) $input;
18}
19
20%typemap(freearg) lldb::ReturnStatus {
21}
22
23%typemap(out) lldb::ReturnStatus {
24 $result = SWIG_From_unsigned_SS_int(static_cast< unsigned int >($1));
25}
26
27/* Typemap definitions, to allow SWIG to properly handle 'char**' data types. */
28
29%typemap(in) char ** {
30 /* Check if is a list */
31 if (PyList_Check($input)) {
32 int size = PyList_Size($input);
33 int i = 0;
34 $1 = (char **) malloc((size+1) * sizeof(char));
35 for (i = 0; i < size; i++) {
36 PyObject *o = PyList_GetItem($input,i);
37 if (PyString_Check(o))
38 $1[i] = PyString_AsString(PyList_GetItem($input,i));
39 else {
40 PyErr_SetString(PyExc_TypeError,"list must contain strings");
41 free($1);
42 return NULL;
43 }
44 }
45 $1[i] = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000046 } else if ($input == Py_None) {
47 $1 = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048 } else {
49 PyErr_SetString(PyExc_TypeError,"not a list");
50 return NULL;
51 }
52}
53
54%typemap(freearg) char** {
55 free((char *) $1);
56}
57
58%typemap(out) char** {
59 int len;
60 int i;
61 len = 0;
62 while ($1[len]) len++;
63 $result = PyList_New(len);
64 for (i = 0; i < len; i++) {
65 PyList_SetItem($result, i, PyString_FromString($1[i]));
66 }
67}
68
69
Greg Claytonc0cc73e2010-06-12 15:34:20 +000070/* The liblldb header files to be included. */
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071
72%{
73#include "lldb/lldb-types.h"
74#include "lldb/API/SBAddress.h"
75#include "lldb/API/SBBlock.h"
76#include "lldb/API/SBBreakpoint.h"
77#include "lldb/API/SBBreakpointLocation.h"
78#include "lldb/API/SBBroadcaster.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079#include "lldb/API/SBCommandInterpreter.h"
80#include "lldb/API/SBCommandReturnObject.h"
81#include "lldb/API/SBCompileUnit.h"
82#include "lldb/API/SBDebugger.h"
83#include "lldb/API/SBError.h"
84#include "lldb/API/SBEvent.h"
Johnny Chen23fd10c2010-08-27 22:35:26 +000085#include "lldb/API/SBFileSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086#include "lldb/API/SBFrame.h"
87#include "lldb/API/SBFunction.h"
88#include "lldb/API/SBLineEntry.h"
89#include "lldb/API/SBListener.h"
90#include "lldb/API/SBModule.h"
91#include "lldb/API/SBProcess.h"
92#include "lldb/API/SBSourceManager.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000093#include "lldb/API/SBStream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094#include "lldb/API/SBStringList.h"
95#include "lldb/API/SBSymbol.h"
96#include "lldb/API/SBSymbolContext.h"
97#include "lldb/API/SBTarget.h"
98#include "lldb/API/SBThread.h"
99#include "lldb/API/SBType.h"
100#include "lldb/API/SBValue.h"
Caroline Tice77404122010-09-22 16:41:52 +0000101#include "lldb/API/SBValueList.h"
Caroline Tice18474c92010-09-27 18:00:20 +0000102#include "lldb/Interpreter/ScriptInterpreterPython.h"
103#include "lldb/Breakpoint/Breakpoint.h"
104#include "lldb/Breakpoint/BreakpointLocation.h"
105#include "lldb/Breakpoint/StoppointCallbackContext.h"
106#include "lldb/Target/ExecutionContext.h"
107#include "lldb/Target/StackFrame.h"
108#include "lldb/Target/Target.h"
109#include "lldb/Target/Thread.h"
110#include "lldb/lldb-forward-rtti.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111using namespace lldb_private;
112%}
113
114/* Various liblldb typedefs that SWIG needs to know about. */
115
116%{
117typedef unsigned int uint32_t;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118typedef int int32_t;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000119typedef uint32_t tid_t;
120typedef uint64_t addr_t;
Greg Claytonc0cc73e2010-06-12 15:34:20 +0000121typedef int32_t break_id_t;
122typedef lldb::SBStringList SBStringList;
123typedef lldb::RegisterKind RegisterKind;
124const RegisterKind kNumRegisterKinds = lldb::kNumRegisterKinds ;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000125%}
126
127typedef unsigned int uint32_t;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000128typedef int int32_t;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000129typedef uint32_t tid_t;
130typedef uint64_t addr_t;
Greg Claytonc0cc73e2010-06-12 15:34:20 +0000131typedef int32_t break_id_t;
132typedef lldb::SBStringList SBStringList;
133typedef lldb::RegisterKind RegisterKind;
134const RegisterKind kNumRegisterKinds = lldb::kNumRegisterKinds ;
Johnny Chen5fca8ca2010-08-26 20:04:17 +0000135typedef int StopReason;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000136
137
138%include "lldb/API/SBAddress.h"
139%include "lldb/API/SBBlock.h"
140%include "lldb/API/SBBreakpoint.h"
141%include "lldb/API/SBBreakpointLocation.h"
142%include "lldb/API/SBBroadcaster.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000143%include "lldb/API/SBCommandInterpreter.h"
144%include "lldb/API/SBCommandReturnObject.h"
145%include "lldb/API/SBCompileUnit.h"
146%include "lldb/API/SBDebugger.h"
147%include "lldb/API/SBError.h"
148%include "lldb/API/SBEvent.h"
Johnny Chen23fd10c2010-08-27 22:35:26 +0000149%include "lldb/API/SBFileSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000150%include "lldb/API/SBFrame.h"
151%include "lldb/API/SBFunction.h"
152%include "lldb/API/SBLineEntry.h"
153%include "lldb/API/SBListener.h"
154%include "lldb/API/SBModule.h"
155%include "lldb/API/SBProcess.h"
156%include "lldb/API/SBSourceManager.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +0000157%include "lldb/API/SBStream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158%include "lldb/API/SBStringList.h"
159%include "lldb/API/SBSymbol.h"
160%include "lldb/API/SBSymbolContext.h"
161%include "lldb/API/SBTarget.h"
162%include "lldb/API/SBThread.h"
163%include "lldb/API/SBType.h"
164%include "lldb/API/SBValue.h"
Caroline Tice77404122010-09-22 16:41:52 +0000165%include "lldb/API/SBValueList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000166%include "lldb/lldb-types.h"
167
Caroline Ticedac97f32010-09-22 23:01:29 +0000168%include "./Python/python-extensions.swig"
Caroline Tice18474c92010-09-27 18:00:20 +0000169
170
171%wrapper %{
172
173
174bool
175ScriptInterpreterPython::BreakpointCallbackFunction (void *baton,
176 StoppointCallbackContext *context,
177 lldb::user_id_t break_id,
178 lldb::user_id_t break_loc_id)
179{
180 bool ret_value = true;
181
182 BreakpointOptions::CommandData *bp_option_data = (BreakpointOptions::CommandData *) baton;
183 const char *python_function_name = bp_option_data->script_source.GetStringAtIndex (0);
184
185 if (python_function_name != NULL
186 && python_function_name[0] != '\0')
187 {
188 Thread *thread = context->exe_ctx.thread;
189 Target *target = context->exe_ctx.target;
190 const lldb::StackFrameSP stop_frame_sp = thread->GetStackFrameSPForStackFramePtr (context->exe_ctx.frame);
191 lldb::BreakpointSP breakpoint_sp = target->GetBreakpointByID (break_id);
192 const lldb::BreakpointLocationSP bp_loc_sp = breakpoint_sp->FindLocationByID (break_loc_id);
193
194 lldb::SBFrame sb_frame (stop_frame_sp);
195 lldb::SBBreakpointLocation sb_bp_loc (bp_loc_sp);
196
197 if (!sb_bp_loc.IsValid() || !sb_frame.IsValid())
198 return ret_value;
199
200
201 PyObject *Frame_PyObj = SWIG_NewPointerObj((void *) &sb_frame, SWIGTYPE_p_lldb__SBFrame, 0);
202 PyObject *Bp_Loc_PyObj = SWIG_NewPointerObj ((void *) &sb_bp_loc, SWIGTYPE_p_lldb__SBBreakpointLocation, 0);
203
204 if (Frame_PyObj == NULL
205 || Bp_Loc_PyObj == NULL)
206 return ret_value;
207
208 PyObject *pmodule, *pdict, *pfunc;
209 PyObject *pargs, *pvalue;
210
211 pmodule = PyImport_AddModule ("__main__");
212 if (pmodule != NULL)
213 {
214 pdict = PyModule_GetDict (pmodule);
215 if (pdict != NULL)
216 {
217 pfunc = PyObject_GetAttrString (pmodule, python_function_name);
218 if (pfunc && PyCallable_Check (pfunc))
219 {
220 pargs = PyTuple_New (2);
221 if (pargs == NULL)
222 {
223 if (PyErr_Occurred())
224 PyErr_Clear();
225 return ret_value;
226 }
227
228 PyTuple_SetItem (pargs, 0, Frame_PyObj); // This "steals" a reference to Frame_PyObj
229 PyTuple_SetItem (pargs, 1, Bp_Loc_PyObj); // This "steals" a reference to Bp_Loc_PyObj
230 pvalue = PyObject_CallObject (pfunc, pargs);
231 Py_DECREF (pargs);
232
233 if (pvalue != NULL)
234 {
235 Py_DECREF (pvalue);
236 }
237 else if (PyErr_Occurred ())
238 {
239 PyErr_Clear();
240 }
241 Py_DECREF (pfunc);
242 }
243 else if (PyErr_Occurred())
244 {
245 PyErr_Clear();
246 }
247 }
248 else if (PyErr_Occurred())
249 {
250 PyErr_Clear();
251 }
252 }
253 else if (PyErr_Occurred ())
254 {
255 PyErr_Clear ();
256 }
257 }
258
259 return ret_value;
260}
261
262%}