lldb.swig revision d8c625380b56759fc3fef8b9cf0389ae1a07f44d
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 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; 35 } else if ($input == Py_None) { 36 $1 = NULL; 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 59/* The liblldb header files to be included. */ 60 61%{ 62#include "lldb/lldb-include.h" 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" 68#include "lldb/API/SBCommandInterpreter.h" 69#include "lldb/API/SBCommandReturnObject.h" 70#include "lldb/API/SBCommunication.h" 71#include "lldb/API/SBCompileUnit.h" 72#include "lldb/API/SBDebugger.h" 73#include "lldb/API/SBError.h" 74#include "lldb/API/SBEvent.h" 75#include "lldb/API/SBFileSpec.h" 76#include "lldb/API/SBFrame.h" 77#include "lldb/API/SBFunction.h" 78#include "lldb/API/SBHostOS.h" 79#include "lldb/API/SBInputReader.h" 80#include "lldb/API/SBInstruction.h" 81#include "lldb/API/SBInstructionList.h" 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" 87#include "lldb/API/SBStream.h" 88#include "lldb/API/SBStringList.h" 89#include "lldb/API/SBSymbol.h" 90#include "lldb/API/SBSymbolContext.h" 91#include "lldb/API/SBSymbolContextList.h" 92#include "lldb/API/SBTarget.h" 93#include "lldb/API/SBThread.h" 94#include "lldb/API/SBType.h" 95#include "lldb/API/SBValue.h" 96#include "lldb/API/SBValueList.h" 97#include "lldb/Interpreter/ScriptInterpreterPython.h" 98#include "lldb/Breakpoint/Breakpoint.h" 99#include "lldb/Breakpoint/BreakpointLocation.h" 100#include "lldb/Breakpoint/StoppointCallbackContext.h" 101#include "lldb/Target/ExecutionContext.h" 102#include "lldb/Target/StackFrame.h" 103#include "lldb/Target/Target.h" 104#include "lldb/Target/Thread.h" 105%} 106 107/* Various liblldb typedefs that SWIG needs to know about. */ 108%include <stdint.h> 109%include "lldb/lldb-defines.h" 110%include "lldb/lldb-enumerations.h" 111%include "lldb/lldb-forward.h" 112%include "lldb/lldb-forward-rtti.h" 113%include "lldb/lldb-types.h" 114%include "lldb/API/SBAddress.h" 115%include "lldb/API/SBBlock.h" 116%include "lldb/API/SBBreakpoint.h" 117%include "lldb/API/SBBreakpointLocation.h" 118%include "lldb/API/SBBroadcaster.h" 119%include "lldb/API/SBCommandInterpreter.h" 120%include "lldb/API/SBCommandReturnObject.h" 121%include "lldb/API/SBCommunication.h" 122%include "lldb/API/SBCompileUnit.h" 123%include "lldb/API/SBDebugger.h" 124%include "lldb/API/SBError.h" 125%include "lldb/API/SBEvent.h" 126%include "lldb/API/SBFileSpec.h" 127%include "lldb/API/SBFrame.h" 128%include "lldb/API/SBFunction.h" 129%include "lldb/API/SBHostOS.h" 130%include "lldb/API/SBInputReader.h" 131%include "lldb/API/SBInstruction.h" 132%include "lldb/API/SBInstructionList.h" 133%include "lldb/API/SBLineEntry.h" 134%include "lldb/API/SBListener.h" 135%include "lldb/API/SBModule.h" 136%include "lldb/API/SBProcess.h" 137%include "lldb/API/SBSourceManager.h" 138%include "lldb/API/SBStream.h" 139%include "lldb/API/SBStringList.h" 140%include "lldb/API/SBSymbol.h" 141%include "lldb/API/SBSymbolContext.h" 142%include "lldb/API/SBSymbolContextList.h" 143%include "lldb/API/SBTarget.h" 144%include "lldb/API/SBThread.h" 145%include "lldb/API/SBType.h" 146%include "lldb/API/SBValue.h" 147%include "lldb/API/SBValueList.h" 148 149%include "./Python/python-extensions.swig" 150 151 152%wrapper %{ 153 154 155bool 156lldb_private::ScriptInterpreterPython::BreakpointCallbackFunction 157( 158 void *baton, 159 lldb_private::StoppointCallbackContext *context, 160 lldb::user_id_t break_id, 161 lldb::user_id_t break_loc_id 162) 163{ 164 bool ret_value = true; 165 166 lldb_private::BreakpointOptions::CommandData *bp_option_data = (lldb_private::BreakpointOptions::CommandData *) baton; 167 const char *python_function_name = bp_option_data->script_source.GetStringAtIndex (0); 168 169 if (python_function_name != NULL 170 && python_function_name[0] != '\0') 171 { 172 lldb_private::Thread *thread = context->exe_ctx.thread; 173 lldb_private::Target *target = context->exe_ctx.target; 174 const lldb::StackFrameSP stop_frame_sp = thread->GetStackFrameSPForStackFramePtr (context->exe_ctx.frame); 175 lldb::BreakpointSP breakpoint_sp = target->GetBreakpointByID (break_id); 176 const lldb::BreakpointLocationSP bp_loc_sp = breakpoint_sp->FindLocationByID (break_loc_id); 177 178 lldb::SBFrame sb_frame (stop_frame_sp); 179 lldb::SBBreakpointLocation sb_bp_loc (bp_loc_sp); 180 181 if (!sb_bp_loc.IsValid() || !sb_frame.IsValid()) 182 return ret_value; 183 184 185 PyObject *Frame_PyObj = SWIG_NewPointerObj((void *) &sb_frame, SWIGTYPE_p_lldb__SBFrame, 0); 186 PyObject *Bp_Loc_PyObj = SWIG_NewPointerObj ((void *) &sb_bp_loc, SWIGTYPE_p_lldb__SBBreakpointLocation, 0); 187 188 if (Frame_PyObj == NULL 189 || Bp_Loc_PyObj == NULL) 190 return ret_value; 191 192 PyObject *pmodule, *pdict, *pfunc; 193 PyObject *pargs, *pvalue; 194 195 pmodule = PyImport_AddModule ("__main__"); 196 if (pmodule != NULL) 197 { 198 pdict = PyModule_GetDict (pmodule); 199 if (pdict != NULL) 200 { 201 pfunc = PyObject_GetAttrString (pmodule, python_function_name); 202 if (pfunc && PyCallable_Check (pfunc)) 203 { 204 pargs = PyTuple_New (2); 205 if (pargs == NULL) 206 { 207 if (PyErr_Occurred()) 208 PyErr_Clear(); 209 return ret_value; 210 } 211 212 PyTuple_SetItem (pargs, 0, Frame_PyObj); // This "steals" a reference to Frame_PyObj 213 PyTuple_SetItem (pargs, 1, Bp_Loc_PyObj); // This "steals" a reference to Bp_Loc_PyObj 214 pvalue = PyObject_CallObject (pfunc, pargs); 215 Py_DECREF (pargs); 216 217 if (pvalue != NULL) 218 { 219 Py_DECREF (pvalue); 220 } 221 else if (PyErr_Occurred ()) 222 { 223 PyErr_Clear(); 224 } 225 Py_DECREF (pfunc); 226 } 227 else if (PyErr_Occurred()) 228 { 229 PyErr_Clear(); 230 } 231 } 232 else if (PyErr_Occurred()) 233 { 234 PyErr_Clear(); 235 } 236 } 237 else if (PyErr_Occurred ()) 238 { 239 PyErr_Clear (); 240 } 241 } 242 243 return ret_value; 244} 245 246%} 247