Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | lldb.swig |
| 3 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4 | This is the input file for SWIG, to create the appropriate C++ wrappers and |
| 5 | functions for various scripting languages, to enable them to call the |
| 6 | liblldb Script Bridge functions. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Johnny Chen | ee48178 | 2011-06-30 21:29:50 +0000 | [diff] [blame] | 9 | /* Define our module docstring. */ |
| 10 | %define DOCSTRING |
| 11 | "The lldb module contains the public APIs for Python binding. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | |
Johnny Chen | ee48178 | 2011-06-30 21:29:50 +0000 | [diff] [blame] | 13 | Some of the important classes are describe here: |
| 14 | |
| 15 | o SBTarget: Represents the target program running under the debugger. |
| 16 | o SBProcess: Represents the process associated with the target program. |
| 17 | o SBThread: Represents a thread of execution. SBProcess contains SBThread(s). |
| 18 | o SBFrame: Represents one of the stack frames associated with a thread. SBThread |
| 19 | contains SBFrame(s). |
| 20 | o SBSymbolContext: A container that stores various debugger related info. |
| 21 | o SBValue: Represents the value of a variable, a register, or an expression. |
| 22 | o SBModule: Represents an executable image and its associated object and symbol |
Johnny Chen | 4036b58 | 2011-07-14 21:32:11 +0000 | [diff] [blame] | 23 | files. SBTarget conatins SBModule(s). |
| 24 | o SBBreakpoint: Represents a logical breakpoint and its associated settings. |
| 25 | SBTarget conatins SBBreakpoint(s). |
Johnny Chen | 993f2b6 | 2011-07-14 21:23:24 +0000 | [diff] [blame] | 26 | o SBSymbol: Represents the symbol possibly associated with a stack frame. |
Johnny Chen | ee48178 | 2011-06-30 21:29:50 +0000 | [diff] [blame] | 27 | o SBCompileUnit: Represents a compilation unit, or compiled source file. |
| 28 | o SBFunction: Represents a generic function, which can be inlined or not. |
| 29 | o SBBlock: Represents a lexical block. SBFunction contains SBBlock(s). |
| 30 | o SBLineEntry: Specifies an association with a contiguous range of instructions |
Johnny Chen | 61abb2a | 2011-07-01 18:39:47 +0000 | [diff] [blame] | 31 | and a source file location. SBCompileUnit contains SBLineEntry(s)." |
Johnny Chen | ee48178 | 2011-06-30 21:29:50 +0000 | [diff] [blame] | 32 | %enddef |
| 33 | |
Johnny Chen | 9ffc9f7 | 2011-07-16 21:27:36 +0000 | [diff] [blame] | 34 | // The name of the module to be created. |
Johnny Chen | ee48178 | 2011-06-30 21:29:50 +0000 | [diff] [blame] | 35 | %module(docstring=DOCSTRING) lldb |
| 36 | |
Johnny Chen | 9ffc9f7 | 2011-07-16 21:27:36 +0000 | [diff] [blame] | 37 | // Parameter types will be used in the autodoc string. |
| 38 | %feature("autodoc", "1"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | /* Typemap definitions, to allow SWIG to properly handle 'char**' data types. */ |
| 41 | |
| 42 | %typemap(in) char ** { |
| 43 | /* Check if is a list */ |
| 44 | if (PyList_Check($input)) { |
| 45 | int size = PyList_Size($input); |
| 46 | int i = 0; |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 47 | $1 = (char **) malloc((size+1) * sizeof(char*)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | for (i = 0; i < size; i++) { |
| 49 | PyObject *o = PyList_GetItem($input,i); |
| 50 | if (PyString_Check(o)) |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 51 | $1[i] = PyString_AsString(o); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | else { |
| 53 | PyErr_SetString(PyExc_TypeError,"list must contain strings"); |
| 54 | free($1); |
| 55 | return NULL; |
| 56 | } |
| 57 | } |
| 58 | $1[i] = 0; |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 59 | } else if ($input == Py_None) { |
| 60 | $1 = NULL; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | } else { |
| 62 | PyErr_SetString(PyExc_TypeError,"not a list"); |
| 63 | return NULL; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | %typemap(freearg) char** { |
| 68 | free((char *) $1); |
| 69 | } |
| 70 | |
| 71 | %typemap(out) char** { |
| 72 | int len; |
| 73 | int i; |
| 74 | len = 0; |
| 75 | while ($1[len]) len++; |
| 76 | $result = PyList_New(len); |
| 77 | for (i = 0; i < len; i++) { |
| 78 | PyList_SetItem($result, i, PyString_FromString($1[i])); |
| 79 | } |
| 80 | } |
| 81 | |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 82 | /* Typemap definitions to allow SWIG to properly handle char buffer. */ |
| 83 | |
| 84 | // typemap for a char buffer |
| 85 | // See also SBThread::GetStopDescription. |
| 86 | %typemap(in) (char *dst, size_t dst_len) { |
| 87 | if (!PyInt_Check($input)) { |
| 88 | PyErr_SetString(PyExc_ValueError, "Expecting an integer"); |
| 89 | return NULL; |
| 90 | } |
| 91 | $2 = PyInt_AsLong($input); |
Johnny Chen | de8241c | 2011-03-23 00:26:08 +0000 | [diff] [blame] | 92 | if ($2 <= 0) { |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 93 | PyErr_SetString(PyExc_ValueError, "Positive integer expected"); |
| 94 | return NULL; |
| 95 | } |
| 96 | $1 = (char *) malloc($2); |
| 97 | } |
| 98 | |
| 99 | // Return the char buffer. Discarding any previous return result |
| 100 | // See also SBThread::GetStopDescription. |
| 101 | %typemap(argout) (char *dst, size_t dst_len) { |
| 102 | Py_XDECREF($result); /* Blow away any previous result */ |
| 103 | $result = PyString_FromStringAndSize(($1),result); |
| 104 | free($1); |
| 105 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 106 | |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 107 | |
| 108 | // typemap for an outgoing buffer |
Johnny Chen | 3a709ac | 2011-07-08 23:02:33 +0000 | [diff] [blame] | 109 | // See also SBEvent::SBEvent(uint32_t event, const char *cstr, uint32_t cstr_len). |
| 110 | %typemap(in) (const char *cstr, uint32_t cstr_len) { |
| 111 | if (!PyString_Check($input)) { |
| 112 | PyErr_SetString(PyExc_ValueError, "Expecting a string"); |
| 113 | return NULL; |
| 114 | } |
| 115 | $1 = (char *) PyString_AsString($input); |
| 116 | $2 = PyString_Size($input); |
| 117 | } |
| 118 | // And SBProcess::WriteMemory. |
Johnny Chen | 37f99fd | 2011-03-01 02:20:14 +0000 | [diff] [blame] | 119 | %typemap(in) (const void *buf, size_t size) { |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 120 | if (!PyString_Check($input)) { |
| 121 | PyErr_SetString(PyExc_ValueError, "Expecting a string"); |
| 122 | return NULL; |
| 123 | } |
| 124 | $1 = (void *) PyString_AsString($input); |
| 125 | $2 = PyString_Size($input); |
| 126 | } |
| 127 | |
| 128 | // typemap for an incoming buffer |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 129 | // See also SBProcess::ReadMemory. |
Johnny Chen | 37f99fd | 2011-03-01 02:20:14 +0000 | [diff] [blame] | 130 | %typemap(in) (void *buf, size_t size) { |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 131 | if (!PyInt_Check($input)) { |
| 132 | PyErr_SetString(PyExc_ValueError, "Expecting an integer"); |
| 133 | return NULL; |
| 134 | } |
| 135 | $2 = PyInt_AsLong($input); |
Johnny Chen | de8241c | 2011-03-23 00:26:08 +0000 | [diff] [blame] | 136 | if ($2 <= 0) { |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 137 | PyErr_SetString(PyExc_ValueError, "Positive integer expected"); |
| 138 | return NULL; |
| 139 | } |
| 140 | $1 = (void *) malloc($2); |
| 141 | } |
| 142 | |
| 143 | // Return the buffer. Discarding any previous return result |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 144 | // See also SBProcess::ReadMemory. |
Johnny Chen | 37f99fd | 2011-03-01 02:20:14 +0000 | [diff] [blame] | 145 | %typemap(argout) (void *buf, size_t size) { |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 146 | Py_XDECREF($result); /* Blow away any previous result */ |
Johnny Chen | 37f99fd | 2011-03-01 02:20:14 +0000 | [diff] [blame] | 147 | $result = PyString_FromStringAndSize(static_cast<const char*>($1),result); |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 148 | free($1); |
| 149 | } |
| 150 | |
Greg Clayton | c0cc73e | 2010-06-12 15:34:20 +0000 | [diff] [blame] | 151 | /* The liblldb header files to be included. */ |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 152 | |
| 153 | %{ |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 154 | #include "lldb/lldb-public.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 155 | #include "lldb/API/SBAddress.h" |
| 156 | #include "lldb/API/SBBlock.h" |
| 157 | #include "lldb/API/SBBreakpoint.h" |
| 158 | #include "lldb/API/SBBreakpointLocation.h" |
| 159 | #include "lldb/API/SBBroadcaster.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 160 | #include "lldb/API/SBCommandInterpreter.h" |
| 161 | #include "lldb/API/SBCommandReturnObject.h" |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 162 | #include "lldb/API/SBCommunication.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 163 | #include "lldb/API/SBCompileUnit.h" |
| 164 | #include "lldb/API/SBDebugger.h" |
| 165 | #include "lldb/API/SBError.h" |
| 166 | #include "lldb/API/SBEvent.h" |
Johnny Chen | 23fd10c | 2010-08-27 22:35:26 +0000 | [diff] [blame] | 167 | #include "lldb/API/SBFileSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 168 | #include "lldb/API/SBFrame.h" |
| 169 | #include "lldb/API/SBFunction.h" |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 170 | #include "lldb/API/SBHostOS.h" |
| 171 | #include "lldb/API/SBInputReader.h" |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 172 | #include "lldb/API/SBInstruction.h" |
| 173 | #include "lldb/API/SBInstructionList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 174 | #include "lldb/API/SBLineEntry.h" |
| 175 | #include "lldb/API/SBListener.h" |
| 176 | #include "lldb/API/SBModule.h" |
| 177 | #include "lldb/API/SBProcess.h" |
| 178 | #include "lldb/API/SBSourceManager.h" |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 179 | #include "lldb/API/SBStream.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 180 | #include "lldb/API/SBStringList.h" |
| 181 | #include "lldb/API/SBSymbol.h" |
| 182 | #include "lldb/API/SBSymbolContext.h" |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 183 | #include "lldb/API/SBSymbolContextList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 184 | #include "lldb/API/SBTarget.h" |
| 185 | #include "lldb/API/SBThread.h" |
| 186 | #include "lldb/API/SBType.h" |
| 187 | #include "lldb/API/SBValue.h" |
Caroline Tice | 7740412 | 2010-09-22 16:41:52 +0000 | [diff] [blame] | 188 | #include "lldb/API/SBValueList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 189 | %} |
| 190 | |
| 191 | /* Various liblldb typedefs that SWIG needs to know about. */ |
Johnny Chen | 4b33209 | 2010-12-16 00:01:06 +0000 | [diff] [blame] | 192 | #define __extension__ /* Undefine GCC keyword to make Swig happy when processing glibc's stdint.h. */ |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 193 | %include <stdint.h> |
| 194 | %include "lldb/lldb-defines.h" |
| 195 | %include "lldb/lldb-enumerations.h" |
| 196 | %include "lldb/lldb-forward.h" |
| 197 | %include "lldb/lldb-forward-rtti.h" |
| 198 | %include "lldb/lldb-types.h" |
Johnny Chen | 349f076 | 2011-07-19 01:07:06 +0000 | [diff] [blame] | 199 | |
Johnny Chen | 0f51968 | 2011-07-19 21:49:34 +0000 | [diff] [blame] | 200 | /* Headers that are swigged directly. */ |
| 201 | %include "lldb/API/SBDefines.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 202 | %include "lldb/API/SBBroadcaster.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 203 | %include "lldb/API/SBCommandInterpreter.h" |
| 204 | %include "lldb/API/SBCommandReturnObject.h" |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 205 | %include "lldb/API/SBCommunication.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 206 | %include "lldb/API/SBError.h" |
Johnny Chen | 23fd10c | 2010-08-27 22:35:26 +0000 | [diff] [blame] | 207 | %include "lldb/API/SBFileSpec.h" |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 208 | %include "lldb/API/SBHostOS.h" |
| 209 | %include "lldb/API/SBInputReader.h" |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 210 | %include "lldb/API/SBInstruction.h" |
| 211 | %include "lldb/API/SBInstructionList.h" |
Johnny Chen | 0f51968 | 2011-07-19 21:49:34 +0000 | [diff] [blame] | 212 | %include "lldb/API/SBSourceManager.h" |
| 213 | %include "lldb/API/SBStream.h" |
| 214 | %include "lldb/API/SBStringList.h" |
| 215 | %include "lldb/API/SBType.h" |
| 216 | |
| 217 | /* Python interface files with docstrings. */ |
| 218 | %include "./Python/interface/SBAddress.i" |
| 219 | %include "./Python/interface/SBBlock.i" |
| 220 | %include "./Python/interface/SBBreakpoint.i" |
| 221 | %include "./Python/interface/SBBreakpointLocation.i" |
| 222 | %include "./Python/interface/SBCompileUnit.i" |
| 223 | %include "./Python/interface/SBDebugger.i" |
| 224 | %include "./Python/interface/SBEvent.i" |
| 225 | %include "./Python/interface/SBFrame.i" |
| 226 | %include "./Python/interface/SBFunction.i" |
Johnny Chen | f74cb50 | 2011-07-18 23:11:07 +0000 | [diff] [blame] | 227 | %include "./Python/interface/SBLineEntry.i" |
| 228 | %include "./Python/interface/SBListener.i" |
| 229 | %include "./Python/interface/SBModule.i" |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 230 | %include "./Python/interface/SBProcess.i" |
Johnny Chen | 349f076 | 2011-07-19 01:07:06 +0000 | [diff] [blame] | 231 | %include "./Python/interface/SBSymbol.i" |
| 232 | %include "./Python/interface/SBSymbolContext.i" |
| 233 | %include "./Python/interface/SBSymbolContextList.i" |
Johnny Chen | dc7d3c1 | 2011-07-16 21:15:39 +0000 | [diff] [blame] | 234 | %include "./Python/interface/SBTarget.i" |
Johnny Chen | 357033b | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 235 | %include "./Python/interface/SBThread.i" |
Johnny Chen | 67ae7bd | 2011-07-18 19:08:30 +0000 | [diff] [blame] | 236 | %include "./Python/interface/SBValue.i" |
| 237 | %include "./Python/interface/SBValueList.i" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 238 | |
Caroline Tice | dac97f3 | 2010-09-22 23:01:29 +0000 | [diff] [blame] | 239 | %include "./Python/python-extensions.swig" |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 240 | |
| 241 | |
| 242 | %wrapper %{ |
| 243 | |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 244 | // This function is called by lldb_private::ScriptInterpreterPython::BreakpointCallbackFunction(...) |
| 245 | // 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] | 246 | |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 247 | SWIGEXPORT bool |
Greg Clayton | fc36f791 | 2011-03-22 01:14:58 +0000 | [diff] [blame] | 248 | LLDBSwigPythonBreakpointCallbackFunction |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 249 | ( |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 250 | const char *python_function_name, |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 251 | const char *session_dictionary_name, |
Greg Clayton | fc36f791 | 2011-03-22 01:14:58 +0000 | [diff] [blame] | 252 | const lldb::StackFrameSP& frame_sp, |
| 253 | const lldb::BreakpointLocationSP& bp_loc_sp |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 254 | ) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 255 | { |
Greg Clayton | fc36f791 | 2011-03-22 01:14:58 +0000 | [diff] [blame] | 256 | lldb::SBFrame sb_frame (frame_sp); |
| 257 | lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp); |
| 258 | |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 259 | bool stop_at_breakpoint = true; |
| 260 | PyObject *Frame_PyObj = SWIG_NewPointerObj((void *) &sb_frame, SWIGTYPE_p_lldb__SBFrame, 0); |
| 261 | 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] | 262 | |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 263 | if (Frame_PyObj == NULL || Bp_Loc_PyObj == NULL) |
| 264 | return stop_at_breakpoint; |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 265 | |
| 266 | if (!python_function_name || !session_dictionary_name) |
| 267 | return stop_at_breakpoint; |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 268 | |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 269 | PyObject *pmodule, *main_dict, *session_dict, *pfunc; |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 270 | PyObject *pargs, *pvalue; |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 271 | |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 272 | pmodule = PyImport_AddModule ("__main__"); |
| 273 | if (pmodule != NULL) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 274 | { |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 275 | main_dict = PyModule_GetDict (pmodule); |
| 276 | if (main_dict != NULL) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 277 | { |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 278 | PyObject *key, *value; |
| 279 | Py_ssize_t pos = 0; |
| 280 | |
| 281 | // Find the current session's dictionary in the main module's dictionary. |
| 282 | |
| 283 | if (PyDict_Check (main_dict)) |
| 284 | |
| 285 | { |
| 286 | session_dict = NULL; |
| 287 | while (PyDict_Next (main_dict, &pos, &key, &value)) |
| 288 | { |
| 289 | // We have stolen references to the key and value objects in the dictionary; we need to increment |
| 290 | // them now so that Python's garbage collector doesn't collect them out from under us. |
| 291 | Py_INCREF (key); |
| 292 | Py_INCREF (value); |
| 293 | if (strcmp (PyString_AsString (key), session_dictionary_name) == 0) |
| 294 | { |
| 295 | session_dict = value; |
| 296 | break; |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | if (!session_dict || !PyDict_Check (session_dict)) |
| 302 | return stop_at_breakpoint; |
| 303 | |
| 304 | // Find the function we need to call in the current session's dictionary. |
| 305 | |
| 306 | pos = 0; |
| 307 | pfunc = NULL; |
| 308 | while (PyDict_Next (session_dict, &pos, &key, &value)) |
| 309 | { |
| 310 | if (PyString_Check (key)) |
| 311 | { |
| 312 | // We have stolen references to the key and value objects in the dictionary; we need to increment |
| 313 | // them now so that Python's garbage collector doesn't collect them out from under us. |
| 314 | Py_INCREF (key); |
| 315 | Py_INCREF (value); |
| 316 | if (strcmp (PyString_AsString (key), python_function_name) == 0) |
| 317 | { |
| 318 | pfunc = value; |
| 319 | break; |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | // Set up the arguments and call the function. |
| 325 | |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 326 | if (pfunc && PyCallable_Check (pfunc)) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 327 | { |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 328 | pargs = PyTuple_New (3); |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 329 | if (pargs == NULL) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 330 | { |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 331 | if (PyErr_Occurred()) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 332 | PyErr_Clear(); |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 333 | return stop_at_breakpoint; |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 334 | } |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 335 | |
| 336 | PyTuple_SetItem (pargs, 0, Frame_PyObj); // This "steals" a reference to Frame_PyObj |
| 337 | PyTuple_SetItem (pargs, 1, Bp_Loc_PyObj); // This "steals" a reference to Bp_Loc_PyObj |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 338 | PyTuple_SetItem (pargs, 2, session_dict); // This "steals" a reference to session_dict |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 339 | pvalue = PyObject_CallObject (pfunc, pargs); |
| 340 | Py_DECREF (pargs); |
| 341 | |
| 342 | if (pvalue != NULL) |
| 343 | { |
| 344 | Py_DECREF (pvalue); |
| 345 | } |
| 346 | else if (PyErr_Occurred ()) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 347 | { |
| 348 | PyErr_Clear(); |
| 349 | } |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 350 | Py_INCREF (session_dict); |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 351 | } |
| 352 | else if (PyErr_Occurred()) |
| 353 | { |
| 354 | PyErr_Clear(); |
| 355 | } |
| 356 | } |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 357 | else if (PyErr_Occurred()) |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 358 | { |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 359 | PyErr_Clear(); |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 360 | } |
| 361 | } |
Greg Clayton | c6ed542 | 2010-10-07 17:14:24 +0000 | [diff] [blame] | 362 | else if (PyErr_Occurred ()) |
| 363 | { |
| 364 | PyErr_Clear (); |
| 365 | } |
| 366 | return stop_at_breakpoint; |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 369 | SWIGEXPORT std::string |
| 370 | LLDBSwigPythonCallTypeScript |
| 371 | ( |
| 372 | const char *python_function_name, |
| 373 | const char *session_dictionary_name, |
| 374 | const lldb::ValueObjectSP& valobj_sp |
| 375 | ) |
| 376 | { |
| 377 | lldb::SBValue sb_value (valobj_sp); |
| 378 | |
| 379 | std::string retval = ""; |
| 380 | |
| 381 | PyObject *ValObj_PyObj = SWIG_NewPointerObj((void *) &valobj_sp, SWIGTYPE_p_lldb__SBValue, 0); |
| 382 | |
| 383 | if (ValObj_PyObj == NULL) |
| 384 | return retval; |
| 385 | |
| 386 | if (!python_function_name || !session_dictionary_name) |
| 387 | return retval; |
| 388 | |
| 389 | PyObject *pmodule, *main_dict, *session_dict, *pfunc; |
| 390 | PyObject *pargs, *pvalue; |
| 391 | |
| 392 | pmodule = PyImport_AddModule ("__main__"); |
| 393 | if (pmodule != NULL) |
| 394 | { |
| 395 | main_dict = PyModule_GetDict (pmodule); |
| 396 | if (main_dict != NULL) |
| 397 | { |
| 398 | PyObject *key, *value; |
| 399 | Py_ssize_t pos = 0; |
| 400 | |
| 401 | // Find the current session's dictionary in the main module's dictionary. |
| 402 | |
| 403 | if (PyDict_Check (main_dict)) |
| 404 | |
| 405 | { |
| 406 | session_dict = NULL; |
| 407 | while (PyDict_Next (main_dict, &pos, &key, &value)) |
| 408 | { |
| 409 | // We have stolen references to the key and value objects in the dictionary; we need to increment |
| 410 | // them now so that Python's garbage collector doesn't collect them out from under us. |
| 411 | Py_INCREF (key); |
| 412 | Py_INCREF (value); |
| 413 | if (strcmp (PyString_AsString (key), session_dictionary_name) == 0) |
| 414 | { |
| 415 | session_dict = value; |
| 416 | break; |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | if (!session_dict || !PyDict_Check (session_dict)) |
| 422 | return retval; |
| 423 | |
| 424 | // Find the function we need to call in the current session's dictionary. |
| 425 | |
| 426 | pos = 0; |
| 427 | pfunc = NULL; |
| 428 | while (PyDict_Next (session_dict, &pos, &key, &value)) |
| 429 | { |
| 430 | if (PyString_Check (key)) |
| 431 | { |
| 432 | // We have stolen references to the key and value objects in the dictionary; we need to increment |
| 433 | // them now so that Python's garbage collector doesn't collect them out from under us. |
| 434 | Py_INCREF (key); |
| 435 | Py_INCREF (value); |
| 436 | if (strcmp (PyString_AsString (key), python_function_name) == 0) |
| 437 | { |
| 438 | pfunc = value; |
| 439 | break; |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | // Set up the arguments and call the function. |
| 445 | |
| 446 | if (pfunc && PyCallable_Check (pfunc)) |
| 447 | { |
| 448 | pargs = PyTuple_New (2); |
| 449 | if (pargs == NULL) |
| 450 | { |
| 451 | if (PyErr_Occurred()) |
| 452 | PyErr_Clear(); |
| 453 | return retval; |
| 454 | } |
| 455 | |
| 456 | PyTuple_SetItem (pargs, 0, ValObj_PyObj); // This "steals" a reference to ValObj_PyObj |
| 457 | PyTuple_SetItem (pargs, 1, session_dict); // This "steals" a reference to session_dict |
| 458 | pvalue = PyObject_CallObject (pfunc, pargs); |
| 459 | Py_DECREF (pargs); |
| 460 | |
| 461 | if (pvalue != NULL) |
| 462 | { |
| 463 | if (pvalue != Py_None) |
| 464 | retval = std::string(PyString_AsString(pvalue)); |
| 465 | else |
| 466 | retval = "None"; |
| 467 | Py_DECREF (pvalue); |
| 468 | } |
| 469 | else if (PyErr_Occurred ()) |
| 470 | { |
Enrico Granata | 03f16a0 | 2011-07-18 16:24:10 +0000 | [diff] [blame] | 471 | PyErr_Print(); |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 472 | PyErr_Clear(); |
| 473 | } |
| 474 | Py_INCREF (session_dict); |
| 475 | } |
| 476 | else if (PyErr_Occurred()) |
| 477 | { |
Enrico Granata | 03f16a0 | 2011-07-18 16:24:10 +0000 | [diff] [blame] | 478 | PyErr_Print(); |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 479 | PyErr_Clear(); |
| 480 | } |
| 481 | } |
| 482 | else if (PyErr_Occurred()) |
| 483 | { |
Enrico Granata | 03f16a0 | 2011-07-18 16:24:10 +0000 | [diff] [blame] | 484 | PyErr_Print(); |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 485 | PyErr_Clear(); |
| 486 | } |
| 487 | } |
| 488 | else if (PyErr_Occurred ()) |
| 489 | { |
Enrico Granata | 03f16a0 | 2011-07-18 16:24:10 +0000 | [diff] [blame] | 490 | PyErr_Print(); |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 491 | PyErr_Clear (); |
| 492 | } |
| 493 | return retval; |
| 494 | } |
| 495 | |
| 496 | |
Caroline Tice | 18474c9 | 2010-09-27 18:00:20 +0000 | [diff] [blame] | 497 | %} |