Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | /* |
| 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 Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 46 | } else if ($input == Py_None) { |
| 47 | $1 = NULL; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | } 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 Clayton | c0cc73e | 2010-06-12 15:34:20 +0000 | [diff] [blame] | 70 | /* The liblldb header files to be included. */ |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | |
| 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 | #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 Chen | 23fd10c | 2010-08-27 22:35:26 +0000 | [diff] [blame] | 85 | #include "lldb/API/SBFileSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 86 | #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 Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 93 | #include "lldb/API/SBStream.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 94 | #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 Tice | 7740412 | 2010-09-22 16:41:52 +0000 | [diff] [blame] | 101 | #include "lldb/API/SBValueList.h" |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 102 | #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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | using namespace lldb_private; |
| 112 | %} |
| 113 | |
| 114 | /* Various liblldb typedefs that SWIG needs to know about. */ |
| 115 | |
| 116 | %{ |
| 117 | typedef unsigned int uint32_t; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 118 | typedef int int32_t; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 119 | typedef uint32_t tid_t; |
| 120 | typedef uint64_t addr_t; |
Greg Clayton | c0cc73e | 2010-06-12 15:34:20 +0000 | [diff] [blame] | 121 | typedef int32_t break_id_t; |
| 122 | typedef lldb::SBStringList SBStringList; |
| 123 | typedef lldb::RegisterKind RegisterKind; |
| 124 | const RegisterKind kNumRegisterKinds = lldb::kNumRegisterKinds ; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 125 | %} |
| 126 | |
| 127 | typedef unsigned int uint32_t; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 128 | typedef int int32_t; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 129 | typedef uint32_t tid_t; |
| 130 | typedef uint64_t addr_t; |
Greg Clayton | c0cc73e | 2010-06-12 15:34:20 +0000 | [diff] [blame] | 131 | typedef int32_t break_id_t; |
| 132 | typedef lldb::SBStringList SBStringList; |
| 133 | typedef lldb::RegisterKind RegisterKind; |
| 134 | const RegisterKind kNumRegisterKinds = lldb::kNumRegisterKinds ; |
Johnny Chen | 5fca8ca | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 135 | typedef int StopReason; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 136 | |
| 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 143 | %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 Chen | 23fd10c | 2010-08-27 22:35:26 +0000 | [diff] [blame] | 149 | %include "lldb/API/SBFileSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 150 | %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 Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 157 | %include "lldb/API/SBStream.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 158 | %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 Tice | 7740412 | 2010-09-22 16:41:52 +0000 | [diff] [blame] | 165 | %include "lldb/API/SBValueList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 166 | %include "lldb/lldb-types.h" |
| 167 | |
Caroline Tice | dac97f3 | 2010-09-22 23:01:29 +0000 | [diff] [blame] | 168 | %include "./Python/python-extensions.swig" |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 169 | |
| 170 | |
| 171 | %wrapper %{ |
| 172 | |
| 173 | |
| 174 | bool |
| 175 | ScriptInterpreterPython::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 | %} |