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 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | /* 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 Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 35 | } else if ($input == Py_None) { |
| 36 | $1 = NULL; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | } 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 Clayton | c0cc73e | 2010-06-12 15:34:20 +0000 | [diff] [blame] | 59 | /* The liblldb header files to be included. */ |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | |
| 61 | %{ |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 62 | #include "lldb/lldb-include.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | #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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 68 | #include "lldb/API/SBCommandInterpreter.h" |
| 69 | #include "lldb/API/SBCommandReturnObject.h" |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 70 | #include "lldb/API/SBCommunication.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | #include "lldb/API/SBCompileUnit.h" |
| 72 | #include "lldb/API/SBDebugger.h" |
| 73 | #include "lldb/API/SBError.h" |
| 74 | #include "lldb/API/SBEvent.h" |
Johnny Chen | 23fd10c | 2010-08-27 22:35:26 +0000 | [diff] [blame] | 75 | #include "lldb/API/SBFileSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | #include "lldb/API/SBFrame.h" |
| 77 | #include "lldb/API/SBFunction.h" |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 78 | #include "lldb/API/SBHostOS.h" |
| 79 | #include "lldb/API/SBInputReader.h" |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 80 | #include "lldb/API/SBInstruction.h" |
| 81 | #include "lldb/API/SBInstructionList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | #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 Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 87 | #include "lldb/API/SBStream.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 88 | #include "lldb/API/SBStringList.h" |
| 89 | #include "lldb/API/SBSymbol.h" |
| 90 | #include "lldb/API/SBSymbolContext.h" |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 91 | #include "lldb/API/SBSymbolContextList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 92 | #include "lldb/API/SBTarget.h" |
| 93 | #include "lldb/API/SBThread.h" |
| 94 | #include "lldb/API/SBType.h" |
| 95 | #include "lldb/API/SBValue.h" |
Caroline Tice | 7740412 | 2010-09-22 16:41:52 +0000 | [diff] [blame] | 96 | #include "lldb/API/SBValueList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | %} |
| 98 | |
| 99 | /* Various liblldb typedefs that SWIG needs to know about. */ |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 100 | %include <stdint.h> |
| 101 | %include "lldb/lldb-defines.h" |
| 102 | %include "lldb/lldb-enumerations.h" |
| 103 | %include "lldb/lldb-forward.h" |
| 104 | %include "lldb/lldb-forward-rtti.h" |
| 105 | %include "lldb/lldb-types.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 106 | %include "lldb/API/SBAddress.h" |
| 107 | %include "lldb/API/SBBlock.h" |
| 108 | %include "lldb/API/SBBreakpoint.h" |
| 109 | %include "lldb/API/SBBreakpointLocation.h" |
| 110 | %include "lldb/API/SBBroadcaster.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | %include "lldb/API/SBCommandInterpreter.h" |
| 112 | %include "lldb/API/SBCommandReturnObject.h" |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 113 | %include "lldb/API/SBCommunication.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 114 | %include "lldb/API/SBCompileUnit.h" |
| 115 | %include "lldb/API/SBDebugger.h" |
| 116 | %include "lldb/API/SBError.h" |
| 117 | %include "lldb/API/SBEvent.h" |
Johnny Chen | 23fd10c | 2010-08-27 22:35:26 +0000 | [diff] [blame] | 118 | %include "lldb/API/SBFileSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 119 | %include "lldb/API/SBFrame.h" |
| 120 | %include "lldb/API/SBFunction.h" |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 121 | %include "lldb/API/SBHostOS.h" |
| 122 | %include "lldb/API/SBInputReader.h" |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 123 | %include "lldb/API/SBInstruction.h" |
| 124 | %include "lldb/API/SBInstructionList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 125 | %include "lldb/API/SBLineEntry.h" |
| 126 | %include "lldb/API/SBListener.h" |
| 127 | %include "lldb/API/SBModule.h" |
| 128 | %include "lldb/API/SBProcess.h" |
| 129 | %include "lldb/API/SBSourceManager.h" |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 130 | %include "lldb/API/SBStream.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 131 | %include "lldb/API/SBStringList.h" |
| 132 | %include "lldb/API/SBSymbol.h" |
| 133 | %include "lldb/API/SBSymbolContext.h" |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 134 | %include "lldb/API/SBSymbolContextList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 135 | %include "lldb/API/SBTarget.h" |
| 136 | %include "lldb/API/SBThread.h" |
| 137 | %include "lldb/API/SBType.h" |
| 138 | %include "lldb/API/SBValue.h" |
Caroline Tice | 7740412 | 2010-09-22 16:41:52 +0000 | [diff] [blame] | 139 | %include "lldb/API/SBValueList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 140 | |
Caroline Tice | dac97f3 | 2010-09-22 23:01:29 +0000 | [diff] [blame] | 141 | %include "./Python/python-extensions.swig" |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 142 | |
| 143 | |
| 144 | %wrapper %{ |
| 145 | |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 146 | // This function is called by lldb_private::ScriptInterpreterPython::BreakpointCallbackFunction(...) |
| 147 | // and is used when a script command is attached to a breakpoint for execution. |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 148 | |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 149 | SWIGEXPORT bool |
| 150 | LLDBSWIGPythonBreakpointCallbackFunction |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 151 | ( |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 152 | const char *python_function_name, |
| 153 | lldb::SBFrame& sb_frame, |
| 154 | lldb::SBBreakpointLocation& sb_bp_loc |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 155 | ) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 156 | { |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 157 | bool stop_at_breakpoint = true; |
| 158 | PyObject *Frame_PyObj = SWIG_NewPointerObj((void *) &sb_frame, SWIGTYPE_p_lldb__SBFrame, 0); |
| 159 | PyObject *Bp_Loc_PyObj = SWIG_NewPointerObj ((void *) &sb_bp_loc, SWIGTYPE_p_lldb__SBBreakpointLocation, 0); |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 160 | |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 161 | if (Frame_PyObj == NULL || Bp_Loc_PyObj == NULL) |
| 162 | return stop_at_breakpoint; |
| 163 | |
| 164 | PyObject *pmodule, *pdict, *pfunc; |
| 165 | PyObject *pargs, *pvalue; |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 166 | |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 167 | pmodule = PyImport_AddModule ("__main__"); |
| 168 | if (pmodule != NULL) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 169 | { |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 170 | pdict = PyModule_GetDict (pmodule); |
| 171 | if (pdict != NULL) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 172 | { |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 173 | pfunc = PyObject_GetAttrString (pmodule, python_function_name); |
| 174 | if (pfunc && PyCallable_Check (pfunc)) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 175 | { |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 176 | pargs = PyTuple_New (2); |
| 177 | if (pargs == NULL) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 178 | { |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 179 | if (PyErr_Occurred()) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 180 | PyErr_Clear(); |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 181 | return stop_at_breakpoint; |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 182 | } |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 183 | |
| 184 | PyTuple_SetItem (pargs, 0, Frame_PyObj); // This "steals" a reference to Frame_PyObj |
| 185 | PyTuple_SetItem (pargs, 1, Bp_Loc_PyObj); // This "steals" a reference to Bp_Loc_PyObj |
| 186 | pvalue = PyObject_CallObject (pfunc, pargs); |
| 187 | Py_DECREF (pargs); |
| 188 | |
| 189 | if (pvalue != NULL) |
| 190 | { |
| 191 | Py_DECREF (pvalue); |
| 192 | } |
| 193 | else if (PyErr_Occurred ()) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 194 | { |
| 195 | PyErr_Clear(); |
| 196 | } |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 197 | Py_DECREF (pfunc); |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 198 | } |
| 199 | else if (PyErr_Occurred()) |
| 200 | { |
| 201 | PyErr_Clear(); |
| 202 | } |
| 203 | } |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 204 | else if (PyErr_Occurred()) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 205 | { |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 206 | PyErr_Clear(); |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 207 | } |
| 208 | } |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 209 | else if (PyErr_Occurred ()) |
| 210 | { |
| 211 | PyErr_Clear (); |
| 212 | } |
| 213 | return stop_at_breakpoint; |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | %} |