blob: a02bd65c56fa336a7d85edecbb2c4cbe05480593 [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"
Greg Clayton1d273162010-10-06 03:09:58 +000088#include "lldb/API/SBInstruction.h"
89#include "lldb/API/SBInstructionList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000090#include "lldb/API/SBLineEntry.h"
91#include "lldb/API/SBListener.h"
92#include "lldb/API/SBModule.h"
93#include "lldb/API/SBProcess.h"
94#include "lldb/API/SBSourceManager.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000095#include "lldb/API/SBStream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096#include "lldb/API/SBStringList.h"
97#include "lldb/API/SBSymbol.h"
98#include "lldb/API/SBSymbolContext.h"
99#include "lldb/API/SBTarget.h"
100#include "lldb/API/SBThread.h"
101#include "lldb/API/SBType.h"
102#include "lldb/API/SBValue.h"
Caroline Tice77404122010-09-22 16:41:52 +0000103#include "lldb/API/SBValueList.h"
Caroline Tice18474c92010-09-27 18:00:20 +0000104#include "lldb/Interpreter/ScriptInterpreterPython.h"
105#include "lldb/Breakpoint/Breakpoint.h"
106#include "lldb/Breakpoint/BreakpointLocation.h"
107#include "lldb/Breakpoint/StoppointCallbackContext.h"
108#include "lldb/Target/ExecutionContext.h"
109#include "lldb/Target/StackFrame.h"
110#include "lldb/Target/Target.h"
111#include "lldb/Target/Thread.h"
112#include "lldb/lldb-forward-rtti.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000113using namespace lldb_private;
114%}
115
116/* Various liblldb typedefs that SWIG needs to know about. */
117
118%{
119typedef unsigned int uint32_t;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000120typedef int int32_t;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000121typedef uint32_t tid_t;
122typedef uint64_t addr_t;
Greg Claytonc0cc73e2010-06-12 15:34:20 +0000123typedef int32_t break_id_t;
124typedef lldb::SBStringList SBStringList;
125typedef lldb::RegisterKind RegisterKind;
126const RegisterKind kNumRegisterKinds = lldb::kNumRegisterKinds ;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000127%}
128
129typedef unsigned int uint32_t;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000130typedef int int32_t;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000131typedef uint32_t tid_t;
132typedef uint64_t addr_t;
Greg Claytonc0cc73e2010-06-12 15:34:20 +0000133typedef int32_t break_id_t;
134typedef lldb::SBStringList SBStringList;
135typedef lldb::RegisterKind RegisterKind;
136const RegisterKind kNumRegisterKinds = lldb::kNumRegisterKinds ;
Johnny Chen5fca8ca2010-08-26 20:04:17 +0000137typedef int StopReason;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000138
139
140%include "lldb/API/SBAddress.h"
141%include "lldb/API/SBBlock.h"
142%include "lldb/API/SBBreakpoint.h"
143%include "lldb/API/SBBreakpointLocation.h"
144%include "lldb/API/SBBroadcaster.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000145%include "lldb/API/SBCommandInterpreter.h"
146%include "lldb/API/SBCommandReturnObject.h"
147%include "lldb/API/SBCompileUnit.h"
148%include "lldb/API/SBDebugger.h"
149%include "lldb/API/SBError.h"
150%include "lldb/API/SBEvent.h"
Johnny Chen23fd10c2010-08-27 22:35:26 +0000151%include "lldb/API/SBFileSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000152%include "lldb/API/SBFrame.h"
153%include "lldb/API/SBFunction.h"
Greg Clayton1d273162010-10-06 03:09:58 +0000154%include "lldb/API/SBInstruction.h"
155%include "lldb/API/SBInstructionList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156%include "lldb/API/SBLineEntry.h"
157%include "lldb/API/SBListener.h"
158%include "lldb/API/SBModule.h"
159%include "lldb/API/SBProcess.h"
160%include "lldb/API/SBSourceManager.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +0000161%include "lldb/API/SBStream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162%include "lldb/API/SBStringList.h"
163%include "lldb/API/SBSymbol.h"
164%include "lldb/API/SBSymbolContext.h"
165%include "lldb/API/SBTarget.h"
166%include "lldb/API/SBThread.h"
167%include "lldb/API/SBType.h"
168%include "lldb/API/SBValue.h"
Caroline Tice77404122010-09-22 16:41:52 +0000169%include "lldb/API/SBValueList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000170%include "lldb/lldb-types.h"
171
Caroline Ticedac97f32010-09-22 23:01:29 +0000172%include "./Python/python-extensions.swig"
Caroline Tice18474c92010-09-27 18:00:20 +0000173
174
175%wrapper %{
176
177
178bool
179ScriptInterpreterPython::BreakpointCallbackFunction (void *baton,
180 StoppointCallbackContext *context,
181 lldb::user_id_t break_id,
182 lldb::user_id_t break_loc_id)
183{
184 bool ret_value = true;
185
186 BreakpointOptions::CommandData *bp_option_data = (BreakpointOptions::CommandData *) baton;
187 const char *python_function_name = bp_option_data->script_source.GetStringAtIndex (0);
188
189 if (python_function_name != NULL
190 && python_function_name[0] != '\0')
191 {
192 Thread *thread = context->exe_ctx.thread;
193 Target *target = context->exe_ctx.target;
194 const lldb::StackFrameSP stop_frame_sp = thread->GetStackFrameSPForStackFramePtr (context->exe_ctx.frame);
195 lldb::BreakpointSP breakpoint_sp = target->GetBreakpointByID (break_id);
196 const lldb::BreakpointLocationSP bp_loc_sp = breakpoint_sp->FindLocationByID (break_loc_id);
197
198 lldb::SBFrame sb_frame (stop_frame_sp);
199 lldb::SBBreakpointLocation sb_bp_loc (bp_loc_sp);
200
201 if (!sb_bp_loc.IsValid() || !sb_frame.IsValid())
202 return ret_value;
203
204
205 PyObject *Frame_PyObj = SWIG_NewPointerObj((void *) &sb_frame, SWIGTYPE_p_lldb__SBFrame, 0);
206 PyObject *Bp_Loc_PyObj = SWIG_NewPointerObj ((void *) &sb_bp_loc, SWIGTYPE_p_lldb__SBBreakpointLocation, 0);
207
208 if (Frame_PyObj == NULL
209 || Bp_Loc_PyObj == NULL)
210 return ret_value;
211
212 PyObject *pmodule, *pdict, *pfunc;
213 PyObject *pargs, *pvalue;
214
215 pmodule = PyImport_AddModule ("__main__");
216 if (pmodule != NULL)
217 {
218 pdict = PyModule_GetDict (pmodule);
219 if (pdict != NULL)
220 {
221 pfunc = PyObject_GetAttrString (pmodule, python_function_name);
222 if (pfunc && PyCallable_Check (pfunc))
223 {
224 pargs = PyTuple_New (2);
225 if (pargs == NULL)
226 {
227 if (PyErr_Occurred())
228 PyErr_Clear();
229 return ret_value;
230 }
231
232 PyTuple_SetItem (pargs, 0, Frame_PyObj); // This "steals" a reference to Frame_PyObj
233 PyTuple_SetItem (pargs, 1, Bp_Loc_PyObj); // This "steals" a reference to Bp_Loc_PyObj
234 pvalue = PyObject_CallObject (pfunc, pargs);
235 Py_DECREF (pargs);
236
237 if (pvalue != NULL)
238 {
239 Py_DECREF (pvalue);
240 }
241 else if (PyErr_Occurred ())
242 {
243 PyErr_Clear();
244 }
245 Py_DECREF (pfunc);
246 }
247 else if (PyErr_Occurred())
248 {
249 PyErr_Clear();
250 }
251 }
252 else if (PyErr_Occurred())
253 {
254 PyErr_Clear();
255 }
256 }
257 else if (PyErr_Occurred ())
258 {
259 PyErr_Clear ();
260 }
261 }
262
263 return ret_value;
264}
265
266%}