1*6498aff2SJonas Devlieghere%header %{ 2*6498aff2SJonas Devlieghere 3*6498aff2SJonas Devliegheretemplate <typename T> 4*6498aff2SJonas DevliegherePyObject * 5*6498aff2SJonas DevlieghereSBTypeToSWIGWrapper (T* item); 6*6498aff2SJonas Devlieghere 7*6498aff2SJonas Devlieghereclass PyErr_Cleaner 8*6498aff2SJonas Devlieghere{ 9*6498aff2SJonas Devliegherepublic: 10*6498aff2SJonas Devlieghere PyErr_Cleaner(bool print=false) : 11*6498aff2SJonas Devlieghere m_print(print) 12*6498aff2SJonas Devlieghere { 13*6498aff2SJonas Devlieghere } 14*6498aff2SJonas Devlieghere 15*6498aff2SJonas Devlieghere ~PyErr_Cleaner() 16*6498aff2SJonas Devlieghere { 17*6498aff2SJonas Devlieghere if (PyErr_Occurred()) 18*6498aff2SJonas Devlieghere { 19*6498aff2SJonas Devlieghere if(m_print && !PyErr_ExceptionMatches(PyExc_SystemExit)) 20*6498aff2SJonas Devlieghere PyErr_Print(); 21*6498aff2SJonas Devlieghere PyErr_Clear(); 22*6498aff2SJonas Devlieghere } 23*6498aff2SJonas Devlieghere } 24*6498aff2SJonas Devlieghere 25*6498aff2SJonas Devlieghereprivate: 26*6498aff2SJonas Devlieghere bool m_print; 27*6498aff2SJonas Devlieghere}; 28*6498aff2SJonas Devlieghere 29*6498aff2SJonas Devlieghere%} 30*6498aff2SJonas Devlieghere 31*6498aff2SJonas Devlieghere%wrapper %{ 32*6498aff2SJonas Devlieghere 33*6498aff2SJonas Devlieghere// resolve a dotted Python name in the form 34*6498aff2SJonas Devlieghere// foo.bar.baz.Foobar to an actual Python object 35*6498aff2SJonas Devlieghere// if pmodule is NULL, the __main__ module will be used 36*6498aff2SJonas Devlieghere// as the starting point for the search 37*6498aff2SJonas Devlieghere 38*6498aff2SJonas Devlieghere 39*6498aff2SJonas Devlieghere// This function is called by lldb_private::ScriptInterpreterPython::BreakpointCallbackFunction(...) 40*6498aff2SJonas Devlieghere// and is used when a script command is attached to a breakpoint for execution. 41*6498aff2SJonas Devlieghere 42*6498aff2SJonas DevlieghereSWIGEXPORT llvm::Expected<bool> 43*6498aff2SJonas DevlieghereLLDBSwigPythonBreakpointCallbackFunction 44*6498aff2SJonas Devlieghere( 45*6498aff2SJonas Devlieghere const char *python_function_name, 46*6498aff2SJonas Devlieghere const char *session_dictionary_name, 47*6498aff2SJonas Devlieghere const lldb::StackFrameSP& frame_sp, 48*6498aff2SJonas Devlieghere const lldb::BreakpointLocationSP& bp_loc_sp, 49*6498aff2SJonas Devlieghere lldb_private::StructuredDataImpl *args_impl 50*6498aff2SJonas Devlieghere) 51*6498aff2SJonas Devlieghere{ 52*6498aff2SJonas Devlieghere using namespace llvm; 53*6498aff2SJonas Devlieghere 54*6498aff2SJonas Devlieghere lldb::SBFrame sb_frame (frame_sp); 55*6498aff2SJonas Devlieghere lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp); 56*6498aff2SJonas Devlieghere 57*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 58*6498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 59*6498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 60*6498aff2SJonas Devlieghere 61*6498aff2SJonas Devlieghere unsigned max_positional_args; 62*6498aff2SJonas Devlieghere if (auto arg_info = pfunc.GetArgInfo()) 63*6498aff2SJonas Devlieghere max_positional_args = arg_info.get().max_positional_args; 64*6498aff2SJonas Devlieghere else 65*6498aff2SJonas Devlieghere return arg_info.takeError(); 66*6498aff2SJonas Devlieghere 67*6498aff2SJonas Devlieghere PythonObject frame_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_frame)); 68*6498aff2SJonas Devlieghere PythonObject bp_loc_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_bp_loc)); 69*6498aff2SJonas Devlieghere 70*6498aff2SJonas Devlieghere auto result = [&] () -> Expected<PythonObject> { 71*6498aff2SJonas Devlieghere // If the called function doesn't take extra_args, drop them here: 72*6498aff2SJonas Devlieghere if (max_positional_args < 4) { 73*6498aff2SJonas Devlieghere return pfunc.Call(frame_arg, bp_loc_arg, dict); 74*6498aff2SJonas Devlieghere } else { 75*6498aff2SJonas Devlieghere lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl); 76*6498aff2SJonas Devlieghere PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value)); 77*6498aff2SJonas Devlieghere return pfunc.Call(frame_arg, bp_loc_arg, args_arg, dict); 78*6498aff2SJonas Devlieghere } 79*6498aff2SJonas Devlieghere } (); 80*6498aff2SJonas Devlieghere 81*6498aff2SJonas Devlieghere if (!result) 82*6498aff2SJonas Devlieghere return result.takeError(); 83*6498aff2SJonas Devlieghere 84*6498aff2SJonas Devlieghere // Only False counts as false! 85*6498aff2SJonas Devlieghere return result.get().get() != Py_False; 86*6498aff2SJonas Devlieghere} 87*6498aff2SJonas Devlieghere 88*6498aff2SJonas Devlieghere// This function is called by lldb_private::ScriptInterpreterPython::WatchpointCallbackFunction(...) 89*6498aff2SJonas Devlieghere// and is used when a script command is attached to a watchpoint for execution. 90*6498aff2SJonas Devlieghere 91*6498aff2SJonas DevlieghereSWIGEXPORT bool 92*6498aff2SJonas DevlieghereLLDBSwigPythonWatchpointCallbackFunction 93*6498aff2SJonas Devlieghere( 94*6498aff2SJonas Devlieghere const char *python_function_name, 95*6498aff2SJonas Devlieghere const char *session_dictionary_name, 96*6498aff2SJonas Devlieghere const lldb::StackFrameSP& frame_sp, 97*6498aff2SJonas Devlieghere const lldb::WatchpointSP& wp_sp 98*6498aff2SJonas Devlieghere) 99*6498aff2SJonas Devlieghere{ 100*6498aff2SJonas Devlieghere lldb::SBFrame sb_frame (frame_sp); 101*6498aff2SJonas Devlieghere lldb::SBWatchpoint sb_wp(wp_sp); 102*6498aff2SJonas Devlieghere 103*6498aff2SJonas Devlieghere bool stop_at_watchpoint = true; 104*6498aff2SJonas Devlieghere 105*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 106*6498aff2SJonas Devlieghere 107*6498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 108*6498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 109*6498aff2SJonas Devlieghere 110*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 111*6498aff2SJonas Devlieghere return stop_at_watchpoint; 112*6498aff2SJonas Devlieghere 113*6498aff2SJonas Devlieghere PythonObject frame_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_frame)); 114*6498aff2SJonas Devlieghere PythonObject wp_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_wp)); 115*6498aff2SJonas Devlieghere PythonObject result = pfunc(frame_arg, wp_arg, dict); 116*6498aff2SJonas Devlieghere 117*6498aff2SJonas Devlieghere if (result.get() == Py_False) 118*6498aff2SJonas Devlieghere stop_at_watchpoint = false; 119*6498aff2SJonas Devlieghere 120*6498aff2SJonas Devlieghere return stop_at_watchpoint; 121*6498aff2SJonas Devlieghere} 122*6498aff2SJonas Devlieghere 123*6498aff2SJonas DevlieghereSWIGEXPORT bool 124*6498aff2SJonas DevlieghereLLDBSwigPythonCallTypeScript 125*6498aff2SJonas Devlieghere( 126*6498aff2SJonas Devlieghere const char *python_function_name, 127*6498aff2SJonas Devlieghere const void *session_dictionary, 128*6498aff2SJonas Devlieghere const lldb::ValueObjectSP& valobj_sp, 129*6498aff2SJonas Devlieghere void** pyfunct_wrapper, 130*6498aff2SJonas Devlieghere const lldb::TypeSummaryOptionsSP& options_sp, 131*6498aff2SJonas Devlieghere std::string& retval 132*6498aff2SJonas Devlieghere) 133*6498aff2SJonas Devlieghere{ 134*6498aff2SJonas Devlieghere lldb::SBValue sb_value (valobj_sp); 135*6498aff2SJonas Devlieghere lldb::SBTypeSummaryOptions sb_options(options_sp.get()); 136*6498aff2SJonas Devlieghere 137*6498aff2SJonas Devlieghere retval.clear(); 138*6498aff2SJonas Devlieghere 139*6498aff2SJonas Devlieghere if (!python_function_name || !session_dictionary) 140*6498aff2SJonas Devlieghere return false; 141*6498aff2SJonas Devlieghere 142*6498aff2SJonas Devlieghere PyObject *pfunc_impl = nullptr; 143*6498aff2SJonas Devlieghere 144*6498aff2SJonas Devlieghere if (pyfunct_wrapper && *pyfunct_wrapper && PyFunction_Check (*pyfunct_wrapper)) 145*6498aff2SJonas Devlieghere { 146*6498aff2SJonas Devlieghere pfunc_impl = (PyObject*)(*pyfunct_wrapper); 147*6498aff2SJonas Devlieghere if (pfunc_impl->ob_refcnt == 1) 148*6498aff2SJonas Devlieghere { 149*6498aff2SJonas Devlieghere Py_XDECREF(pfunc_impl); 150*6498aff2SJonas Devlieghere pfunc_impl = NULL; 151*6498aff2SJonas Devlieghere } 152*6498aff2SJonas Devlieghere } 153*6498aff2SJonas Devlieghere 154*6498aff2SJonas Devlieghere PyObject *py_dict = (PyObject*)session_dictionary; 155*6498aff2SJonas Devlieghere if (!PythonDictionary::Check(py_dict)) 156*6498aff2SJonas Devlieghere return true; 157*6498aff2SJonas Devlieghere 158*6498aff2SJonas Devlieghere PythonDictionary dict(PyRefType::Borrowed, py_dict); 159*6498aff2SJonas Devlieghere 160*6498aff2SJonas Devlieghere PyErr_Cleaner pyerr_cleanup(true); // show Python errors 161*6498aff2SJonas Devlieghere 162*6498aff2SJonas Devlieghere PythonCallable pfunc(PyRefType::Borrowed, pfunc_impl); 163*6498aff2SJonas Devlieghere 164*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 165*6498aff2SJonas Devlieghere { 166*6498aff2SJonas Devlieghere pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 167*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 168*6498aff2SJonas Devlieghere return false; 169*6498aff2SJonas Devlieghere 170*6498aff2SJonas Devlieghere if (pyfunct_wrapper) 171*6498aff2SJonas Devlieghere { 172*6498aff2SJonas Devlieghere *pyfunct_wrapper = pfunc.get(); 173*6498aff2SJonas Devlieghere Py_XINCREF(pfunc.get()); 174*6498aff2SJonas Devlieghere } 175*6498aff2SJonas Devlieghere } 176*6498aff2SJonas Devlieghere 177*6498aff2SJonas Devlieghere PythonObject result; 178*6498aff2SJonas Devlieghere auto argc = pfunc.GetArgInfo(); 179*6498aff2SJonas Devlieghere if (!argc) { 180*6498aff2SJonas Devlieghere llvm::consumeError(argc.takeError()); 181*6498aff2SJonas Devlieghere return false; 182*6498aff2SJonas Devlieghere } 183*6498aff2SJonas Devlieghere 184*6498aff2SJonas Devlieghere PythonObject value_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_value)); 185*6498aff2SJonas Devlieghere PythonObject options_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_options)); 186*6498aff2SJonas Devlieghere 187*6498aff2SJonas Devlieghere if (argc.get().max_positional_args < 3) 188*6498aff2SJonas Devlieghere result = pfunc(value_arg,dict); 189*6498aff2SJonas Devlieghere else 190*6498aff2SJonas Devlieghere result = pfunc(value_arg,dict,options_arg); 191*6498aff2SJonas Devlieghere 192*6498aff2SJonas Devlieghere retval = result.Str().GetString().str(); 193*6498aff2SJonas Devlieghere 194*6498aff2SJonas Devlieghere return true; 195*6498aff2SJonas Devlieghere} 196*6498aff2SJonas Devlieghere 197*6498aff2SJonas DevlieghereSWIGEXPORT void* 198*6498aff2SJonas DevlieghereLLDBSwigPythonCreateSyntheticProvider 199*6498aff2SJonas Devlieghere( 200*6498aff2SJonas Devlieghere const char *python_class_name, 201*6498aff2SJonas Devlieghere const char *session_dictionary_name, 202*6498aff2SJonas Devlieghere const lldb::ValueObjectSP& valobj_sp 203*6498aff2SJonas Devlieghere) 204*6498aff2SJonas Devlieghere{ 205*6498aff2SJonas Devlieghere if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name) 206*6498aff2SJonas Devlieghere Py_RETURN_NONE; 207*6498aff2SJonas Devlieghere 208*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 209*6498aff2SJonas Devlieghere 210*6498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 211*6498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name,dict); 212*6498aff2SJonas Devlieghere 213*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 214*6498aff2SJonas Devlieghere Py_RETURN_NONE; 215*6498aff2SJonas Devlieghere 216*6498aff2SJonas Devlieghere // I do not want the SBValue to be deallocated when going out of scope because python 217*6498aff2SJonas Devlieghere // has ownership of it and will manage memory for this object by itself 218*6498aff2SJonas Devlieghere lldb::SBValue *sb_value = new lldb::SBValue(valobj_sp); 219*6498aff2SJonas Devlieghere sb_value->SetPreferSyntheticValue(false); 220*6498aff2SJonas Devlieghere 221*6498aff2SJonas Devlieghere PythonObject val_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_value)); 222*6498aff2SJonas Devlieghere if (!val_arg.IsAllocated()) 223*6498aff2SJonas Devlieghere Py_RETURN_NONE; 224*6498aff2SJonas Devlieghere 225*6498aff2SJonas Devlieghere PythonObject result = pfunc(val_arg, dict); 226*6498aff2SJonas Devlieghere 227*6498aff2SJonas Devlieghere if (result.IsAllocated()) 228*6498aff2SJonas Devlieghere return result.release(); 229*6498aff2SJonas Devlieghere 230*6498aff2SJonas Devlieghere Py_RETURN_NONE; 231*6498aff2SJonas Devlieghere} 232*6498aff2SJonas Devlieghere 233*6498aff2SJonas DevlieghereSWIGEXPORT void* 234*6498aff2SJonas DevlieghereLLDBSwigPythonCreateCommandObject 235*6498aff2SJonas Devlieghere( 236*6498aff2SJonas Devlieghere const char *python_class_name, 237*6498aff2SJonas Devlieghere const char *session_dictionary_name, 238*6498aff2SJonas Devlieghere const lldb::DebuggerSP debugger_sp 239*6498aff2SJonas Devlieghere) 240*6498aff2SJonas Devlieghere{ 241*6498aff2SJonas Devlieghere if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name) 242*6498aff2SJonas Devlieghere Py_RETURN_NONE; 243*6498aff2SJonas Devlieghere 244*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 245*6498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 246*6498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict); 247*6498aff2SJonas Devlieghere 248*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 249*6498aff2SJonas Devlieghere return nullptr; 250*6498aff2SJonas Devlieghere 251*6498aff2SJonas Devlieghere lldb::SBDebugger debugger_sb(debugger_sp); 252*6498aff2SJonas Devlieghere PythonObject debugger_arg(PyRefType::Owned, SBTypeToSWIGWrapper(debugger_sb)); 253*6498aff2SJonas Devlieghere PythonObject result = pfunc(debugger_arg, dict); 254*6498aff2SJonas Devlieghere 255*6498aff2SJonas Devlieghere if (result.IsAllocated()) 256*6498aff2SJonas Devlieghere return result.release(); 257*6498aff2SJonas Devlieghere 258*6498aff2SJonas Devlieghere Py_RETURN_NONE; 259*6498aff2SJonas Devlieghere} 260*6498aff2SJonas Devlieghere 261*6498aff2SJonas DevlieghereSWIGEXPORT void* 262*6498aff2SJonas DevlieghereLLDBSwigPythonCreateScriptedThreadPlan 263*6498aff2SJonas Devlieghere( 264*6498aff2SJonas Devlieghere const char *python_class_name, 265*6498aff2SJonas Devlieghere const char *session_dictionary_name, 266*6498aff2SJonas Devlieghere lldb_private::StructuredDataImpl *args_impl, 267*6498aff2SJonas Devlieghere std::string &error_string, 268*6498aff2SJonas Devlieghere const lldb::ThreadPlanSP& thread_plan_sp 269*6498aff2SJonas Devlieghere) 270*6498aff2SJonas Devlieghere{ 271*6498aff2SJonas Devlieghere if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name) 272*6498aff2SJonas Devlieghere Py_RETURN_NONE; 273*6498aff2SJonas Devlieghere 274*6498aff2SJonas Devlieghere // I do not want the SBThreadPlan to be deallocated when going out of scope because python 275*6498aff2SJonas Devlieghere // has ownership of it and will manage memory for this object by itself 276*6498aff2SJonas Devlieghere lldb::SBThreadPlan *tp_value = new lldb::SBThreadPlan(thread_plan_sp); 277*6498aff2SJonas Devlieghere 278*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 279*6498aff2SJonas Devlieghere 280*6498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 281*6498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict); 282*6498aff2SJonas Devlieghere 283*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) { 284*6498aff2SJonas Devlieghere error_string.append("could not find script class: "); 285*6498aff2SJonas Devlieghere error_string.append(python_class_name); 286*6498aff2SJonas Devlieghere return nullptr; 287*6498aff2SJonas Devlieghere } 288*6498aff2SJonas Devlieghere 289*6498aff2SJonas Devlieghere PythonObject tp_arg(PyRefType::Owned, SBTypeToSWIGWrapper(tp_value)); 290*6498aff2SJonas Devlieghere 291*6498aff2SJonas Devlieghere if (!tp_arg.IsAllocated()) 292*6498aff2SJonas Devlieghere Py_RETURN_NONE; 293*6498aff2SJonas Devlieghere 294*6498aff2SJonas Devlieghere llvm::Expected<PythonCallable::ArgInfo> arg_info = pfunc.GetArgInfo(); 295*6498aff2SJonas Devlieghere if (!arg_info) { 296*6498aff2SJonas Devlieghere llvm::handleAllErrors( 297*6498aff2SJonas Devlieghere arg_info.takeError(), 298*6498aff2SJonas Devlieghere [&](PythonException &E) { 299*6498aff2SJonas Devlieghere error_string.append(E.ReadBacktrace()); 300*6498aff2SJonas Devlieghere }, 301*6498aff2SJonas Devlieghere [&](const llvm::ErrorInfoBase &E) { 302*6498aff2SJonas Devlieghere error_string.append(E.message()); 303*6498aff2SJonas Devlieghere }); 304*6498aff2SJonas Devlieghere Py_RETURN_NONE; 305*6498aff2SJonas Devlieghere } 306*6498aff2SJonas Devlieghere 307*6498aff2SJonas Devlieghere PythonObject result = {}; 308*6498aff2SJonas Devlieghere if (arg_info.get().max_positional_args == 2) { 309*6498aff2SJonas Devlieghere if (args_impl != nullptr) { 310*6498aff2SJonas Devlieghere error_string.assign("args passed, but __init__ does not take an args dictionary"); 311*6498aff2SJonas Devlieghere Py_RETURN_NONE; 312*6498aff2SJonas Devlieghere } 313*6498aff2SJonas Devlieghere result = pfunc(tp_arg, dict); 314*6498aff2SJonas Devlieghere } else if (arg_info.get().max_positional_args >= 3) { 315*6498aff2SJonas Devlieghere lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl); 316*6498aff2SJonas Devlieghere PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value)); 317*6498aff2SJonas Devlieghere result = pfunc(tp_arg, args_arg, dict); 318*6498aff2SJonas Devlieghere } else { 319*6498aff2SJonas Devlieghere error_string.assign("wrong number of arguments in __init__, should be 2 or 3 (not including self)"); 320*6498aff2SJonas Devlieghere Py_RETURN_NONE; 321*6498aff2SJonas Devlieghere } 322*6498aff2SJonas Devlieghere 323*6498aff2SJonas Devlieghere // FIXME: At this point we should check that the class we found supports all the methods 324*6498aff2SJonas Devlieghere // that we need. 325*6498aff2SJonas Devlieghere 326*6498aff2SJonas Devlieghere if (result.IsAllocated()) 327*6498aff2SJonas Devlieghere return result.release(); 328*6498aff2SJonas Devlieghere Py_RETURN_NONE; 329*6498aff2SJonas Devlieghere} 330*6498aff2SJonas Devlieghere 331*6498aff2SJonas DevlieghereSWIGEXPORT bool 332*6498aff2SJonas DevlieghereLLDBSWIGPythonCallThreadPlan 333*6498aff2SJonas Devlieghere( 334*6498aff2SJonas Devlieghere void *implementor, 335*6498aff2SJonas Devlieghere const char *method_name, 336*6498aff2SJonas Devlieghere lldb_private::Event *event, 337*6498aff2SJonas Devlieghere bool &got_error 338*6498aff2SJonas Devlieghere) 339*6498aff2SJonas Devlieghere{ 340*6498aff2SJonas Devlieghere got_error = false; 341*6498aff2SJonas Devlieghere 342*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(false); 343*6498aff2SJonas Devlieghere PythonObject self(PyRefType::Borrowed, static_cast<PyObject*>(implementor)); 344*6498aff2SJonas Devlieghere auto pfunc = self.ResolveName<PythonCallable>(method_name); 345*6498aff2SJonas Devlieghere 346*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 347*6498aff2SJonas Devlieghere return false; 348*6498aff2SJonas Devlieghere 349*6498aff2SJonas Devlieghere PythonObject result; 350*6498aff2SJonas Devlieghere if (event != nullptr) 351*6498aff2SJonas Devlieghere { 352*6498aff2SJonas Devlieghere lldb::SBEvent sb_event(event); 353*6498aff2SJonas Devlieghere PythonObject event_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_event)); 354*6498aff2SJonas Devlieghere result = pfunc(event_arg); 355*6498aff2SJonas Devlieghere } 356*6498aff2SJonas Devlieghere else 357*6498aff2SJonas Devlieghere result = pfunc(); 358*6498aff2SJonas Devlieghere 359*6498aff2SJonas Devlieghere if (PyErr_Occurred()) 360*6498aff2SJonas Devlieghere { 361*6498aff2SJonas Devlieghere got_error = true; 362*6498aff2SJonas Devlieghere printf ("Return value was neither false nor true for call to %s.\n", method_name); 363*6498aff2SJonas Devlieghere PyErr_Print(); 364*6498aff2SJonas Devlieghere return false; 365*6498aff2SJonas Devlieghere } 366*6498aff2SJonas Devlieghere 367*6498aff2SJonas Devlieghere if (result.get() == Py_True) 368*6498aff2SJonas Devlieghere return true; 369*6498aff2SJonas Devlieghere else if (result.get() == Py_False) 370*6498aff2SJonas Devlieghere return false; 371*6498aff2SJonas Devlieghere 372*6498aff2SJonas Devlieghere // Somebody returned the wrong thing... 373*6498aff2SJonas Devlieghere got_error = true; 374*6498aff2SJonas Devlieghere printf ("Wrong return value type for call to %s.\n", method_name); 375*6498aff2SJonas Devlieghere return false; 376*6498aff2SJonas Devlieghere} 377*6498aff2SJonas Devlieghere 378*6498aff2SJonas DevlieghereSWIGEXPORT void * 379*6498aff2SJonas DevlieghereLLDBSwigPythonCreateScriptedBreakpointResolver 380*6498aff2SJonas Devlieghere( 381*6498aff2SJonas Devlieghere const char *python_class_name, 382*6498aff2SJonas Devlieghere const char *session_dictionary_name, 383*6498aff2SJonas Devlieghere lldb_private::StructuredDataImpl *args_impl, 384*6498aff2SJonas Devlieghere lldb::BreakpointSP &breakpoint_sp 385*6498aff2SJonas Devlieghere) 386*6498aff2SJonas Devlieghere{ 387*6498aff2SJonas Devlieghere if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name) 388*6498aff2SJonas Devlieghere Py_RETURN_NONE; 389*6498aff2SJonas Devlieghere 390*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 391*6498aff2SJonas Devlieghere 392*6498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 393*6498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict); 394*6498aff2SJonas Devlieghere 395*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 396*6498aff2SJonas Devlieghere return nullptr; 397*6498aff2SJonas Devlieghere 398*6498aff2SJonas Devlieghere lldb::SBBreakpoint *bkpt_value = new lldb::SBBreakpoint(breakpoint_sp); 399*6498aff2SJonas Devlieghere 400*6498aff2SJonas Devlieghere PythonObject bkpt_arg(PyRefType::Owned, SBTypeToSWIGWrapper(bkpt_value)); 401*6498aff2SJonas Devlieghere 402*6498aff2SJonas Devlieghere lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl); 403*6498aff2SJonas Devlieghere PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value)); 404*6498aff2SJonas Devlieghere 405*6498aff2SJonas Devlieghere PythonObject result = pfunc(bkpt_arg, args_arg, dict); 406*6498aff2SJonas Devlieghere // FIXME: At this point we should check that the class we found supports all the methods 407*6498aff2SJonas Devlieghere // that we need. 408*6498aff2SJonas Devlieghere 409*6498aff2SJonas Devlieghere if (result.IsAllocated()) 410*6498aff2SJonas Devlieghere { 411*6498aff2SJonas Devlieghere // Check that __callback__ is defined: 412*6498aff2SJonas Devlieghere auto callback_func = result.ResolveName<PythonCallable>("__callback__"); 413*6498aff2SJonas Devlieghere if (callback_func.IsAllocated()) 414*6498aff2SJonas Devlieghere return result.release(); 415*6498aff2SJonas Devlieghere else 416*6498aff2SJonas Devlieghere result.release(); 417*6498aff2SJonas Devlieghere } 418*6498aff2SJonas Devlieghere Py_RETURN_NONE; 419*6498aff2SJonas Devlieghere} 420*6498aff2SJonas Devlieghere 421*6498aff2SJonas DevlieghereSWIGEXPORT unsigned int 422*6498aff2SJonas DevlieghereLLDBSwigPythonCallBreakpointResolver 423*6498aff2SJonas Devlieghere( 424*6498aff2SJonas Devlieghere void *implementor, 425*6498aff2SJonas Devlieghere const char *method_name, 426*6498aff2SJonas Devlieghere lldb_private::SymbolContext *sym_ctx 427*6498aff2SJonas Devlieghere) 428*6498aff2SJonas Devlieghere{ 429*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(false); 430*6498aff2SJonas Devlieghere PythonObject self(PyRefType::Borrowed, static_cast<PyObject*>(implementor)); 431*6498aff2SJonas Devlieghere auto pfunc = self.ResolveName<PythonCallable>(method_name); 432*6498aff2SJonas Devlieghere 433*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 434*6498aff2SJonas Devlieghere return 0; 435*6498aff2SJonas Devlieghere 436*6498aff2SJonas Devlieghere PythonObject result; 437*6498aff2SJonas Devlieghere if (sym_ctx != nullptr) { 438*6498aff2SJonas Devlieghere lldb::SBSymbolContext sb_sym_ctx(sym_ctx); 439*6498aff2SJonas Devlieghere PythonObject sym_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_sym_ctx)); 440*6498aff2SJonas Devlieghere result = pfunc(sym_ctx_arg); 441*6498aff2SJonas Devlieghere } else 442*6498aff2SJonas Devlieghere result = pfunc(); 443*6498aff2SJonas Devlieghere 444*6498aff2SJonas Devlieghere if (PyErr_Occurred()) 445*6498aff2SJonas Devlieghere { 446*6498aff2SJonas Devlieghere PyErr_Print(); 447*6498aff2SJonas Devlieghere return 0; 448*6498aff2SJonas Devlieghere } 449*6498aff2SJonas Devlieghere 450*6498aff2SJonas Devlieghere // The callback will return a bool, but we're need to also return ints 451*6498aff2SJonas Devlieghere // so we're squirrelling the bool through as an int... And if you return 452*6498aff2SJonas Devlieghere // nothing, we'll continue. 453*6498aff2SJonas Devlieghere if (strcmp(method_name, "__callback__") == 0) { 454*6498aff2SJonas Devlieghere if (result.get() == Py_False) 455*6498aff2SJonas Devlieghere return 0; 456*6498aff2SJonas Devlieghere else 457*6498aff2SJonas Devlieghere return 1; 458*6498aff2SJonas Devlieghere } 459*6498aff2SJonas Devlieghere 460*6498aff2SJonas Devlieghere PythonInteger int_result = result.AsType<PythonInteger>(); 461*6498aff2SJonas Devlieghere if (!int_result.IsAllocated()) 462*6498aff2SJonas Devlieghere return 0; 463*6498aff2SJonas Devlieghere 464*6498aff2SJonas Devlieghere unsigned int ret_val = int_result.GetInteger(); 465*6498aff2SJonas Devlieghere 466*6498aff2SJonas Devlieghere return ret_val; 467*6498aff2SJonas Devlieghere} 468*6498aff2SJonas Devlieghere 469*6498aff2SJonas Devlieghere// wrapper that calls an optional instance member of an object taking no arguments 470*6498aff2SJonas Devliegherestatic PyObject* 471*6498aff2SJonas DevlieghereLLDBSwigPython_CallOptionalMember 472*6498aff2SJonas Devlieghere( 473*6498aff2SJonas Devlieghere PyObject* implementor, 474*6498aff2SJonas Devlieghere char* callee_name, 475*6498aff2SJonas Devlieghere PyObject* ret_if_not_found = Py_None, 476*6498aff2SJonas Devlieghere bool* was_found = NULL 477*6498aff2SJonas Devlieghere) 478*6498aff2SJonas Devlieghere{ 479*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(false); 480*6498aff2SJonas Devlieghere 481*6498aff2SJonas Devlieghere PythonObject self(PyRefType::Borrowed, static_cast<PyObject*>(implementor)); 482*6498aff2SJonas Devlieghere auto pfunc = self.ResolveName<PythonCallable>(callee_name); 483*6498aff2SJonas Devlieghere 484*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 485*6498aff2SJonas Devlieghere { 486*6498aff2SJonas Devlieghere if (was_found) 487*6498aff2SJonas Devlieghere *was_found = false; 488*6498aff2SJonas Devlieghere Py_XINCREF(ret_if_not_found); 489*6498aff2SJonas Devlieghere return ret_if_not_found; 490*6498aff2SJonas Devlieghere } 491*6498aff2SJonas Devlieghere 492*6498aff2SJonas Devlieghere if (was_found) 493*6498aff2SJonas Devlieghere *was_found = true; 494*6498aff2SJonas Devlieghere 495*6498aff2SJonas Devlieghere PythonObject result = pfunc(); 496*6498aff2SJonas Devlieghere return result.release(); 497*6498aff2SJonas Devlieghere} 498*6498aff2SJonas Devlieghere 499*6498aff2SJonas DevlieghereSWIGEXPORT size_t 500*6498aff2SJonas DevlieghereLLDBSwigPython_CalculateNumChildren 501*6498aff2SJonas Devlieghere( 502*6498aff2SJonas Devlieghere PyObject *implementor, 503*6498aff2SJonas Devlieghere uint32_t max 504*6498aff2SJonas Devlieghere) 505*6498aff2SJonas Devlieghere{ 506*6498aff2SJonas Devlieghere PythonObject self(PyRefType::Borrowed, implementor); 507*6498aff2SJonas Devlieghere auto pfunc = self.ResolveName<PythonCallable>("num_children"); 508*6498aff2SJonas Devlieghere 509*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 510*6498aff2SJonas Devlieghere return 0; 511*6498aff2SJonas Devlieghere 512*6498aff2SJonas Devlieghere auto arg_info = pfunc.GetArgInfo(); 513*6498aff2SJonas Devlieghere if (!arg_info) { 514*6498aff2SJonas Devlieghere llvm::consumeError(arg_info.takeError()); 515*6498aff2SJonas Devlieghere return 0; 516*6498aff2SJonas Devlieghere } 517*6498aff2SJonas Devlieghere 518*6498aff2SJonas Devlieghere PythonObject result; 519*6498aff2SJonas Devlieghere 520*6498aff2SJonas Devlieghere if (arg_info.get().max_positional_args < 1) 521*6498aff2SJonas Devlieghere result = pfunc(); 522*6498aff2SJonas Devlieghere else 523*6498aff2SJonas Devlieghere result = pfunc(PythonInteger(max)); 524*6498aff2SJonas Devlieghere 525*6498aff2SJonas Devlieghere if (!result.IsAllocated()) 526*6498aff2SJonas Devlieghere return 0; 527*6498aff2SJonas Devlieghere 528*6498aff2SJonas Devlieghere PythonInteger int_result = result.AsType<PythonInteger>(); 529*6498aff2SJonas Devlieghere if (!int_result.IsAllocated()) 530*6498aff2SJonas Devlieghere return 0; 531*6498aff2SJonas Devlieghere 532*6498aff2SJonas Devlieghere size_t ret_val = int_result.GetInteger(); 533*6498aff2SJonas Devlieghere 534*6498aff2SJonas Devlieghere if (PyErr_Occurred()) //FIXME use Expected to catch python exceptions 535*6498aff2SJonas Devlieghere { 536*6498aff2SJonas Devlieghere PyErr_Print(); 537*6498aff2SJonas Devlieghere PyErr_Clear(); 538*6498aff2SJonas Devlieghere } 539*6498aff2SJonas Devlieghere 540*6498aff2SJonas Devlieghere if (arg_info.get().max_positional_args < 1) 541*6498aff2SJonas Devlieghere ret_val = std::min(ret_val, static_cast<size_t>(max)); 542*6498aff2SJonas Devlieghere 543*6498aff2SJonas Devlieghere return ret_val; 544*6498aff2SJonas Devlieghere} 545*6498aff2SJonas Devlieghere 546*6498aff2SJonas DevlieghereSWIGEXPORT PyObject* 547*6498aff2SJonas DevlieghereLLDBSwigPython_GetChildAtIndex 548*6498aff2SJonas Devlieghere( 549*6498aff2SJonas Devlieghere PyObject *implementor, 550*6498aff2SJonas Devlieghere uint32_t idx 551*6498aff2SJonas Devlieghere) 552*6498aff2SJonas Devlieghere{ 553*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 554*6498aff2SJonas Devlieghere 555*6498aff2SJonas Devlieghere PythonObject self(PyRefType::Borrowed, implementor); 556*6498aff2SJonas Devlieghere auto pfunc = self.ResolveName<PythonCallable>("get_child_at_index"); 557*6498aff2SJonas Devlieghere 558*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 559*6498aff2SJonas Devlieghere return nullptr; 560*6498aff2SJonas Devlieghere 561*6498aff2SJonas Devlieghere PythonObject result = pfunc(PythonInteger(idx)); 562*6498aff2SJonas Devlieghere 563*6498aff2SJonas Devlieghere if (!result.IsAllocated()) 564*6498aff2SJonas Devlieghere return nullptr; 565*6498aff2SJonas Devlieghere 566*6498aff2SJonas Devlieghere lldb::SBValue* sbvalue_ptr = nullptr; 567*6498aff2SJonas Devlieghere if (SWIG_ConvertPtr(result.get(), (void**)&sbvalue_ptr, SWIGTYPE_p_lldb__SBValue, 0) == -1) 568*6498aff2SJonas Devlieghere return nullptr; 569*6498aff2SJonas Devlieghere 570*6498aff2SJonas Devlieghere if (sbvalue_ptr == nullptr) 571*6498aff2SJonas Devlieghere return nullptr; 572*6498aff2SJonas Devlieghere 573*6498aff2SJonas Devlieghere return result.release(); 574*6498aff2SJonas Devlieghere} 575*6498aff2SJonas Devlieghere 576*6498aff2SJonas DevlieghereSWIGEXPORT int 577*6498aff2SJonas DevlieghereLLDBSwigPython_GetIndexOfChildWithName 578*6498aff2SJonas Devlieghere( 579*6498aff2SJonas Devlieghere PyObject *implementor, 580*6498aff2SJonas Devlieghere const char* child_name 581*6498aff2SJonas Devlieghere) 582*6498aff2SJonas Devlieghere{ 583*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 584*6498aff2SJonas Devlieghere 585*6498aff2SJonas Devlieghere PythonObject self(PyRefType::Borrowed, implementor); 586*6498aff2SJonas Devlieghere auto pfunc = self.ResolveName<PythonCallable>("get_child_index"); 587*6498aff2SJonas Devlieghere 588*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 589*6498aff2SJonas Devlieghere return UINT32_MAX; 590*6498aff2SJonas Devlieghere 591*6498aff2SJonas Devlieghere PythonObject result = pfunc(PythonString(child_name)); 592*6498aff2SJonas Devlieghere 593*6498aff2SJonas Devlieghere if (!result.IsAllocated()) 594*6498aff2SJonas Devlieghere return UINT32_MAX; 595*6498aff2SJonas Devlieghere 596*6498aff2SJonas Devlieghere PythonInteger int_result = result.AsType<PythonInteger>(); 597*6498aff2SJonas Devlieghere if (!int_result.IsAllocated()) 598*6498aff2SJonas Devlieghere return UINT32_MAX; 599*6498aff2SJonas Devlieghere 600*6498aff2SJonas Devlieghere int64_t retval = int_result.GetInteger(); 601*6498aff2SJonas Devlieghere if (retval >= 0) 602*6498aff2SJonas Devlieghere return (uint32_t)retval; 603*6498aff2SJonas Devlieghere 604*6498aff2SJonas Devlieghere return UINT32_MAX; 605*6498aff2SJonas Devlieghere} 606*6498aff2SJonas Devlieghere 607*6498aff2SJonas DevlieghereSWIGEXPORT bool 608*6498aff2SJonas DevlieghereLLDBSwigPython_UpdateSynthProviderInstance 609*6498aff2SJonas Devlieghere( 610*6498aff2SJonas Devlieghere PyObject *implementor 611*6498aff2SJonas Devlieghere) 612*6498aff2SJonas Devlieghere{ 613*6498aff2SJonas Devlieghere bool ret_val = false; 614*6498aff2SJonas Devlieghere 615*6498aff2SJonas Devlieghere static char callee_name[] = "update"; 616*6498aff2SJonas Devlieghere 617*6498aff2SJonas Devlieghere PyObject* py_return = LLDBSwigPython_CallOptionalMember(implementor,callee_name); 618*6498aff2SJonas Devlieghere 619*6498aff2SJonas Devlieghere if (py_return == Py_True) 620*6498aff2SJonas Devlieghere ret_val = true; 621*6498aff2SJonas Devlieghere 622*6498aff2SJonas Devlieghere Py_XDECREF(py_return); 623*6498aff2SJonas Devlieghere 624*6498aff2SJonas Devlieghere return ret_val; 625*6498aff2SJonas Devlieghere} 626*6498aff2SJonas Devlieghere 627*6498aff2SJonas DevlieghereSWIGEXPORT bool 628*6498aff2SJonas DevlieghereLLDBSwigPython_MightHaveChildrenSynthProviderInstance 629*6498aff2SJonas Devlieghere( 630*6498aff2SJonas Devlieghere PyObject *implementor 631*6498aff2SJonas Devlieghere) 632*6498aff2SJonas Devlieghere{ 633*6498aff2SJonas Devlieghere bool ret_val = false; 634*6498aff2SJonas Devlieghere 635*6498aff2SJonas Devlieghere static char callee_name[] = "has_children"; 636*6498aff2SJonas Devlieghere 637*6498aff2SJonas Devlieghere PyObject* py_return = LLDBSwigPython_CallOptionalMember(implementor,callee_name, Py_True); 638*6498aff2SJonas Devlieghere 639*6498aff2SJonas Devlieghere if (py_return == Py_True) 640*6498aff2SJonas Devlieghere ret_val = true; 641*6498aff2SJonas Devlieghere 642*6498aff2SJonas Devlieghere Py_XDECREF(py_return); 643*6498aff2SJonas Devlieghere 644*6498aff2SJonas Devlieghere return ret_val; 645*6498aff2SJonas Devlieghere} 646*6498aff2SJonas Devlieghere 647*6498aff2SJonas DevlieghereSWIGEXPORT PyObject* 648*6498aff2SJonas DevlieghereLLDBSwigPython_GetValueSynthProviderInstance 649*6498aff2SJonas Devlieghere( 650*6498aff2SJonas Devlieghere PyObject *implementor 651*6498aff2SJonas Devlieghere) 652*6498aff2SJonas Devlieghere{ 653*6498aff2SJonas Devlieghere PyObject* ret_val = nullptr; 654*6498aff2SJonas Devlieghere 655*6498aff2SJonas Devlieghere static char callee_name[] = "get_value"; 656*6498aff2SJonas Devlieghere 657*6498aff2SJonas Devlieghere PyObject* py_return = LLDBSwigPython_CallOptionalMember(implementor,callee_name, Py_None); 658*6498aff2SJonas Devlieghere 659*6498aff2SJonas Devlieghere if (py_return == Py_None || py_return == nullptr) 660*6498aff2SJonas Devlieghere ret_val = nullptr; 661*6498aff2SJonas Devlieghere 662*6498aff2SJonas Devlieghere lldb::SBValue* sbvalue_ptr = NULL; 663*6498aff2SJonas Devlieghere 664*6498aff2SJonas Devlieghere if (SWIG_ConvertPtr(py_return, (void**)&sbvalue_ptr, SWIGTYPE_p_lldb__SBValue, 0) == -1) 665*6498aff2SJonas Devlieghere ret_val = nullptr; 666*6498aff2SJonas Devlieghere else if (sbvalue_ptr == NULL) 667*6498aff2SJonas Devlieghere ret_val = nullptr; 668*6498aff2SJonas Devlieghere else 669*6498aff2SJonas Devlieghere ret_val = py_return; 670*6498aff2SJonas Devlieghere 671*6498aff2SJonas Devlieghere Py_XDECREF(py_return); 672*6498aff2SJonas Devlieghere return ret_val; 673*6498aff2SJonas Devlieghere} 674*6498aff2SJonas Devlieghere 675*6498aff2SJonas DevlieghereSWIGEXPORT void* 676*6498aff2SJonas DevlieghereLLDBSWIGPython_CastPyObjectToSBValue 677*6498aff2SJonas Devlieghere( 678*6498aff2SJonas Devlieghere PyObject* data 679*6498aff2SJonas Devlieghere) 680*6498aff2SJonas Devlieghere{ 681*6498aff2SJonas Devlieghere lldb::SBValue* sb_ptr = NULL; 682*6498aff2SJonas Devlieghere 683*6498aff2SJonas Devlieghere int valid_cast = SWIG_ConvertPtr(data, (void**)&sb_ptr, SWIGTYPE_p_lldb__SBValue, 0); 684*6498aff2SJonas Devlieghere 685*6498aff2SJonas Devlieghere if (valid_cast == -1) 686*6498aff2SJonas Devlieghere return NULL; 687*6498aff2SJonas Devlieghere 688*6498aff2SJonas Devlieghere return sb_ptr; 689*6498aff2SJonas Devlieghere} 690*6498aff2SJonas Devlieghere 691*6498aff2SJonas DevlieghereSWIGEXPORT bool 692*6498aff2SJonas DevlieghereLLDBSwigPythonCallCommand 693*6498aff2SJonas Devlieghere( 694*6498aff2SJonas Devlieghere const char *python_function_name, 695*6498aff2SJonas Devlieghere const char *session_dictionary_name, 696*6498aff2SJonas Devlieghere lldb::DebuggerSP& debugger, 697*6498aff2SJonas Devlieghere const char* args, 698*6498aff2SJonas Devlieghere lldb_private::CommandReturnObject& cmd_retobj, 699*6498aff2SJonas Devlieghere lldb::ExecutionContextRefSP exe_ctx_ref_sp 700*6498aff2SJonas Devlieghere) 701*6498aff2SJonas Devlieghere{ 702*6498aff2SJonas Devlieghere lldb::SBCommandReturnObject cmd_retobj_sb(cmd_retobj); 703*6498aff2SJonas Devlieghere lldb::SBDebugger debugger_sb(debugger); 704*6498aff2SJonas Devlieghere lldb::SBExecutionContext exe_ctx_sb(exe_ctx_ref_sp); 705*6498aff2SJonas Devlieghere 706*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 707*6498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 708*6498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 709*6498aff2SJonas Devlieghere 710*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 711*6498aff2SJonas Devlieghere return false; 712*6498aff2SJonas Devlieghere 713*6498aff2SJonas Devlieghere // pass the pointer-to cmd_retobj_sb or watch the underlying object disappear from under you 714*6498aff2SJonas Devlieghere // see comment above for SBCommandReturnObjectReleaser for further details 715*6498aff2SJonas Devlieghere auto argc = pfunc.GetArgInfo(); 716*6498aff2SJonas Devlieghere if (!argc) { 717*6498aff2SJonas Devlieghere llvm::consumeError(argc.takeError()); 718*6498aff2SJonas Devlieghere return false; 719*6498aff2SJonas Devlieghere } 720*6498aff2SJonas Devlieghere PythonObject debugger_arg(PyRefType::Owned, SBTypeToSWIGWrapper(debugger_sb)); 721*6498aff2SJonas Devlieghere PythonObject exe_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(exe_ctx_sb)); 722*6498aff2SJonas Devlieghere PythonObject cmd_retobj_arg(PyRefType::Owned, SBTypeToSWIGWrapper(&cmd_retobj_sb)); 723*6498aff2SJonas Devlieghere 724*6498aff2SJonas Devlieghere if (argc.get().max_positional_args < 5u) 725*6498aff2SJonas Devlieghere pfunc(debugger_arg, PythonString(args), cmd_retobj_arg, dict); 726*6498aff2SJonas Devlieghere else 727*6498aff2SJonas Devlieghere pfunc(debugger_arg, PythonString(args), exe_ctx_arg, cmd_retobj_arg, dict); 728*6498aff2SJonas Devlieghere 729*6498aff2SJonas Devlieghere return true; 730*6498aff2SJonas Devlieghere} 731*6498aff2SJonas Devlieghere 732*6498aff2SJonas DevlieghereSWIGEXPORT bool 733*6498aff2SJonas DevlieghereLLDBSwigPythonCallCommandObject 734*6498aff2SJonas Devlieghere( 735*6498aff2SJonas Devlieghere PyObject *implementor, 736*6498aff2SJonas Devlieghere lldb::DebuggerSP& debugger, 737*6498aff2SJonas Devlieghere const char* args, 738*6498aff2SJonas Devlieghere lldb_private::CommandReturnObject& cmd_retobj, 739*6498aff2SJonas Devlieghere lldb::ExecutionContextRefSP exe_ctx_ref_sp 740*6498aff2SJonas Devlieghere) 741*6498aff2SJonas Devlieghere{ 742*6498aff2SJonas Devlieghere lldb::SBCommandReturnObject cmd_retobj_sb(cmd_retobj); 743*6498aff2SJonas Devlieghere lldb::SBDebugger debugger_sb(debugger); 744*6498aff2SJonas Devlieghere lldb::SBExecutionContext exe_ctx_sb(exe_ctx_ref_sp); 745*6498aff2SJonas Devlieghere 746*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 747*6498aff2SJonas Devlieghere 748*6498aff2SJonas Devlieghere PythonObject self(PyRefType::Borrowed, implementor); 749*6498aff2SJonas Devlieghere auto pfunc = self.ResolveName<PythonCallable>("__call__"); 750*6498aff2SJonas Devlieghere 751*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 752*6498aff2SJonas Devlieghere return false; 753*6498aff2SJonas Devlieghere 754*6498aff2SJonas Devlieghere // pass the pointer-to cmd_retobj_sb or watch the underlying object disappear from under you 755*6498aff2SJonas Devlieghere // see comment above for SBCommandReturnObjectReleaser for further details 756*6498aff2SJonas Devlieghere PythonObject debugger_arg(PyRefType::Owned, SBTypeToSWIGWrapper(debugger_sb)); 757*6498aff2SJonas Devlieghere PythonObject exe_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(exe_ctx_sb)); 758*6498aff2SJonas Devlieghere PythonObject cmd_retobj_arg(PyRefType::Owned, SBTypeToSWIGWrapper(&cmd_retobj_sb)); 759*6498aff2SJonas Devlieghere 760*6498aff2SJonas Devlieghere pfunc(debugger_arg, PythonString(args), exe_ctx_arg, cmd_retobj_arg); 761*6498aff2SJonas Devlieghere 762*6498aff2SJonas Devlieghere return true; 763*6498aff2SJonas Devlieghere} 764*6498aff2SJonas Devlieghere 765*6498aff2SJonas DevlieghereSWIGEXPORT void* 766*6498aff2SJonas DevlieghereLLDBSWIGPythonCreateOSPlugin 767*6498aff2SJonas Devlieghere( 768*6498aff2SJonas Devlieghere const char *python_class_name, 769*6498aff2SJonas Devlieghere const char *session_dictionary_name, 770*6498aff2SJonas Devlieghere const lldb::ProcessSP& process_sp 771*6498aff2SJonas Devlieghere) 772*6498aff2SJonas Devlieghere{ 773*6498aff2SJonas Devlieghere if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name) 774*6498aff2SJonas Devlieghere Py_RETURN_NONE; 775*6498aff2SJonas Devlieghere 776*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 777*6498aff2SJonas Devlieghere 778*6498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 779*6498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict); 780*6498aff2SJonas Devlieghere 781*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 782*6498aff2SJonas Devlieghere Py_RETURN_NONE; 783*6498aff2SJonas Devlieghere 784*6498aff2SJonas Devlieghere // I do not want the SBProcess to be deallocated when going out of scope because python 785*6498aff2SJonas Devlieghere // has ownership of it and will manage memory for this object by itself 786*6498aff2SJonas Devlieghere lldb::SBProcess *process_sb = new lldb::SBProcess(process_sp); 787*6498aff2SJonas Devlieghere PythonObject process_arg(PyRefType::Owned, SBTypeToSWIGWrapper(process_sb)); 788*6498aff2SJonas Devlieghere if (!process_arg.IsAllocated()) 789*6498aff2SJonas Devlieghere Py_RETURN_NONE; 790*6498aff2SJonas Devlieghere 791*6498aff2SJonas Devlieghere auto result = pfunc(process_arg); 792*6498aff2SJonas Devlieghere 793*6498aff2SJonas Devlieghere if (result.IsAllocated()) 794*6498aff2SJonas Devlieghere return result.release(); 795*6498aff2SJonas Devlieghere 796*6498aff2SJonas Devlieghere Py_RETURN_NONE; 797*6498aff2SJonas Devlieghere} 798*6498aff2SJonas Devlieghere 799*6498aff2SJonas DevlieghereSWIGEXPORT void* 800*6498aff2SJonas DevlieghereLLDBSWIGPython_CreateFrameRecognizer 801*6498aff2SJonas Devlieghere( 802*6498aff2SJonas Devlieghere const char *python_class_name, 803*6498aff2SJonas Devlieghere const char *session_dictionary_name 804*6498aff2SJonas Devlieghere) 805*6498aff2SJonas Devlieghere{ 806*6498aff2SJonas Devlieghere if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name) 807*6498aff2SJonas Devlieghere Py_RETURN_NONE; 808*6498aff2SJonas Devlieghere 809*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 810*6498aff2SJonas Devlieghere 811*6498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 812*6498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict); 813*6498aff2SJonas Devlieghere 814*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 815*6498aff2SJonas Devlieghere Py_RETURN_NONE; 816*6498aff2SJonas Devlieghere 817*6498aff2SJonas Devlieghere auto result = pfunc(); 818*6498aff2SJonas Devlieghere 819*6498aff2SJonas Devlieghere if (result.IsAllocated()) 820*6498aff2SJonas Devlieghere return result.release(); 821*6498aff2SJonas Devlieghere 822*6498aff2SJonas Devlieghere Py_RETURN_NONE; 823*6498aff2SJonas Devlieghere} 824*6498aff2SJonas Devlieghere 825*6498aff2SJonas DevlieghereSWIGEXPORT PyObject* 826*6498aff2SJonas DevlieghereLLDBSwigPython_GetRecognizedArguments 827*6498aff2SJonas Devlieghere( 828*6498aff2SJonas Devlieghere PyObject *implementor, 829*6498aff2SJonas Devlieghere const lldb::StackFrameSP& frame_sp 830*6498aff2SJonas Devlieghere) 831*6498aff2SJonas Devlieghere{ 832*6498aff2SJonas Devlieghere static char callee_name[] = "get_recognized_arguments"; 833*6498aff2SJonas Devlieghere 834*6498aff2SJonas Devlieghere lldb::SBFrame frame_sb(frame_sp); 835*6498aff2SJonas Devlieghere PyObject *arg = SBTypeToSWIGWrapper(frame_sb); 836*6498aff2SJonas Devlieghere 837*6498aff2SJonas Devlieghere PythonString str(callee_name); 838*6498aff2SJonas Devlieghere PyObject* result = PyObject_CallMethodObjArgs(implementor, str.get(), arg, 839*6498aff2SJonas Devlieghere NULL); 840*6498aff2SJonas Devlieghere return result; 841*6498aff2SJonas Devlieghere} 842*6498aff2SJonas Devlieghere 843*6498aff2SJonas DevlieghereSWIGEXPORT void* 844*6498aff2SJonas DevlieghereLLDBSWIGPython_GetDynamicSetting (void* module, const char* setting, const lldb::TargetSP& target_sp) 845*6498aff2SJonas Devlieghere{ 846*6498aff2SJonas Devlieghere if (!module || !setting) 847*6498aff2SJonas Devlieghere Py_RETURN_NONE; 848*6498aff2SJonas Devlieghere 849*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 850*6498aff2SJonas Devlieghere PythonObject py_module(PyRefType::Borrowed, (PyObject *)module); 851*6498aff2SJonas Devlieghere auto pfunc = py_module.ResolveName<PythonCallable>("get_dynamic_setting"); 852*6498aff2SJonas Devlieghere 853*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 854*6498aff2SJonas Devlieghere Py_RETURN_NONE; 855*6498aff2SJonas Devlieghere 856*6498aff2SJonas Devlieghere lldb::SBTarget target_sb(target_sp); 857*6498aff2SJonas Devlieghere PythonObject target_arg(PyRefType::Owned, SBTypeToSWIGWrapper(target_sb)); 858*6498aff2SJonas Devlieghere auto result = pfunc(target_arg, PythonString(setting)); 859*6498aff2SJonas Devlieghere 860*6498aff2SJonas Devlieghere return result.release(); 861*6498aff2SJonas Devlieghere} 862*6498aff2SJonas Devlieghere 863*6498aff2SJonas DevlieghereSWIGEXPORT bool 864*6498aff2SJonas DevlieghereLLDBSWIGPythonRunScriptKeywordProcess 865*6498aff2SJonas Devlieghere(const char* python_function_name, 866*6498aff2SJonas Devlieghereconst char* session_dictionary_name, 867*6498aff2SJonas Devliegherelldb::ProcessSP& process, 868*6498aff2SJonas Devliegherestd::string& output) 869*6498aff2SJonas Devlieghere 870*6498aff2SJonas Devlieghere{ 871*6498aff2SJonas Devlieghere if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name) 872*6498aff2SJonas Devlieghere return false; 873*6498aff2SJonas Devlieghere 874*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 875*6498aff2SJonas Devlieghere 876*6498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 877*6498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 878*6498aff2SJonas Devlieghere 879*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 880*6498aff2SJonas Devlieghere return false; 881*6498aff2SJonas Devlieghere 882*6498aff2SJonas Devlieghere lldb::SBProcess process_sb(process); 883*6498aff2SJonas Devlieghere PythonObject process_arg(PyRefType::Owned, SBTypeToSWIGWrapper(process_sb)); 884*6498aff2SJonas Devlieghere auto result = pfunc(process_arg, dict); 885*6498aff2SJonas Devlieghere 886*6498aff2SJonas Devlieghere output = result.Str().GetString().str(); 887*6498aff2SJonas Devlieghere 888*6498aff2SJonas Devlieghere return true; 889*6498aff2SJonas Devlieghere} 890*6498aff2SJonas Devlieghere 891*6498aff2SJonas DevlieghereSWIGEXPORT bool 892*6498aff2SJonas DevlieghereLLDBSWIGPythonRunScriptKeywordThread 893*6498aff2SJonas Devlieghere(const char* python_function_name, 894*6498aff2SJonas Devlieghereconst char* session_dictionary_name, 895*6498aff2SJonas Devliegherelldb::ThreadSP& thread, 896*6498aff2SJonas Devliegherestd::string& output) 897*6498aff2SJonas Devlieghere 898*6498aff2SJonas Devlieghere{ 899*6498aff2SJonas Devlieghere if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name) 900*6498aff2SJonas Devlieghere return false; 901*6498aff2SJonas Devlieghere 902*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 903*6498aff2SJonas Devlieghere 904*6498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 905*6498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 906*6498aff2SJonas Devlieghere 907*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 908*6498aff2SJonas Devlieghere return false; 909*6498aff2SJonas Devlieghere 910*6498aff2SJonas Devlieghere lldb::SBThread thread_sb(thread); 911*6498aff2SJonas Devlieghere PythonObject thread_arg(PyRefType::Owned, SBTypeToSWIGWrapper(thread_sb)); 912*6498aff2SJonas Devlieghere auto result = pfunc(thread_arg, dict); 913*6498aff2SJonas Devlieghere 914*6498aff2SJonas Devlieghere output = result.Str().GetString().str(); 915*6498aff2SJonas Devlieghere 916*6498aff2SJonas Devlieghere return true; 917*6498aff2SJonas Devlieghere} 918*6498aff2SJonas Devlieghere 919*6498aff2SJonas DevlieghereSWIGEXPORT bool 920*6498aff2SJonas DevlieghereLLDBSWIGPythonRunScriptKeywordTarget 921*6498aff2SJonas Devlieghere(const char* python_function_name, 922*6498aff2SJonas Devlieghereconst char* session_dictionary_name, 923*6498aff2SJonas Devliegherelldb::TargetSP& target, 924*6498aff2SJonas Devliegherestd::string& output) 925*6498aff2SJonas Devlieghere 926*6498aff2SJonas Devlieghere{ 927*6498aff2SJonas Devlieghere if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name) 928*6498aff2SJonas Devlieghere return false; 929*6498aff2SJonas Devlieghere 930*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 931*6498aff2SJonas Devlieghere 932*6498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 933*6498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name,dict); 934*6498aff2SJonas Devlieghere 935*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 936*6498aff2SJonas Devlieghere return false; 937*6498aff2SJonas Devlieghere 938*6498aff2SJonas Devlieghere lldb::SBTarget target_sb(target); 939*6498aff2SJonas Devlieghere PythonObject target_arg(PyRefType::Owned, SBTypeToSWIGWrapper(target_sb)); 940*6498aff2SJonas Devlieghere auto result = pfunc(target_arg, dict); 941*6498aff2SJonas Devlieghere 942*6498aff2SJonas Devlieghere output = result.Str().GetString().str(); 943*6498aff2SJonas Devlieghere 944*6498aff2SJonas Devlieghere return true; 945*6498aff2SJonas Devlieghere} 946*6498aff2SJonas Devlieghere 947*6498aff2SJonas DevlieghereSWIGEXPORT bool 948*6498aff2SJonas DevlieghereLLDBSWIGPythonRunScriptKeywordFrame 949*6498aff2SJonas Devlieghere(const char* python_function_name, 950*6498aff2SJonas Devlieghereconst char* session_dictionary_name, 951*6498aff2SJonas Devliegherelldb::StackFrameSP& frame, 952*6498aff2SJonas Devliegherestd::string& output) 953*6498aff2SJonas Devlieghere 954*6498aff2SJonas Devlieghere{ 955*6498aff2SJonas Devlieghere if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name) 956*6498aff2SJonas Devlieghere return false; 957*6498aff2SJonas Devlieghere 958*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 959*6498aff2SJonas Devlieghere 960*6498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 961*6498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name,dict); 962*6498aff2SJonas Devlieghere 963*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 964*6498aff2SJonas Devlieghere return false; 965*6498aff2SJonas Devlieghere 966*6498aff2SJonas Devlieghere lldb::SBFrame frame_sb(frame); 967*6498aff2SJonas Devlieghere PythonObject frame_arg(PyRefType::Owned, SBTypeToSWIGWrapper(frame_sb)); 968*6498aff2SJonas Devlieghere auto result = pfunc(frame_arg, dict); 969*6498aff2SJonas Devlieghere 970*6498aff2SJonas Devlieghere output = result.Str().GetString().str(); 971*6498aff2SJonas Devlieghere 972*6498aff2SJonas Devlieghere return true; 973*6498aff2SJonas Devlieghere} 974*6498aff2SJonas Devlieghere 975*6498aff2SJonas DevlieghereSWIGEXPORT bool 976*6498aff2SJonas DevlieghereLLDBSWIGPythonRunScriptKeywordValue 977*6498aff2SJonas Devlieghere(const char* python_function_name, 978*6498aff2SJonas Devlieghereconst char* session_dictionary_name, 979*6498aff2SJonas Devliegherelldb::ValueObjectSP& value, 980*6498aff2SJonas Devliegherestd::string& output) 981*6498aff2SJonas Devlieghere 982*6498aff2SJonas Devlieghere{ 983*6498aff2SJonas Devlieghere if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name) 984*6498aff2SJonas Devlieghere return false; 985*6498aff2SJonas Devlieghere 986*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 987*6498aff2SJonas Devlieghere 988*6498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 989*6498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 990*6498aff2SJonas Devlieghere 991*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 992*6498aff2SJonas Devlieghere return false; 993*6498aff2SJonas Devlieghere 994*6498aff2SJonas Devlieghere lldb::SBValue value_sb(value); 995*6498aff2SJonas Devlieghere PythonObject value_arg(PyRefType::Owned, SBTypeToSWIGWrapper(value_sb)); 996*6498aff2SJonas Devlieghere auto result = pfunc(value_arg, dict); 997*6498aff2SJonas Devlieghere 998*6498aff2SJonas Devlieghere output = result.Str().GetString().str(); 999*6498aff2SJonas Devlieghere 1000*6498aff2SJonas Devlieghere return true; 1001*6498aff2SJonas Devlieghere} 1002*6498aff2SJonas Devlieghere 1003*6498aff2SJonas DevlieghereSWIGEXPORT bool 1004*6498aff2SJonas DevlieghereLLDBSwigPythonCallModuleInit 1005*6498aff2SJonas Devlieghere( 1006*6498aff2SJonas Devlieghere const char *python_module_name, 1007*6498aff2SJonas Devlieghere const char *session_dictionary_name, 1008*6498aff2SJonas Devlieghere lldb::DebuggerSP& debugger 1009*6498aff2SJonas Devlieghere) 1010*6498aff2SJonas Devlieghere{ 1011*6498aff2SJonas Devlieghere std::string python_function_name_string = python_module_name; 1012*6498aff2SJonas Devlieghere python_function_name_string += ".__lldb_init_module"; 1013*6498aff2SJonas Devlieghere const char* python_function_name = python_function_name_string.c_str(); 1014*6498aff2SJonas Devlieghere 1015*6498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 1016*6498aff2SJonas Devlieghere 1017*6498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 1018*6498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 1019*6498aff2SJonas Devlieghere 1020*6498aff2SJonas Devlieghere // This method is optional and need not exist. So if we don't find it, 1021*6498aff2SJonas Devlieghere // it's actually a success, not a failure. 1022*6498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 1023*6498aff2SJonas Devlieghere return true; 1024*6498aff2SJonas Devlieghere 1025*6498aff2SJonas Devlieghere lldb::SBDebugger debugger_sb(debugger); 1026*6498aff2SJonas Devlieghere PythonObject debugger_arg(PyRefType::Owned, SBTypeToSWIGWrapper(debugger_sb)); 1027*6498aff2SJonas Devlieghere pfunc(debugger_arg, dict); 1028*6498aff2SJonas Devlieghere 1029*6498aff2SJonas Devlieghere return true; 1030*6498aff2SJonas Devlieghere} 1031*6498aff2SJonas Devlieghere%} 1032*6498aff2SJonas Devlieghere 1033*6498aff2SJonas Devlieghere 1034*6498aff2SJonas Devlieghere%runtime %{ 1035*6498aff2SJonas Devlieghere// Forward declaration to be inserted at the start of LLDBWrapPython.h 1036*6498aff2SJonas Devlieghere#include "lldb/API/SBDebugger.h" 1037*6498aff2SJonas Devlieghere#include "lldb/API/SBValue.h" 1038*6498aff2SJonas Devlieghere 1039*6498aff2SJonas DevlieghereSWIGEXPORT lldb::ValueObjectSP 1040*6498aff2SJonas DevlieghereLLDBSWIGPython_GetValueObjectSPFromSBValue (void* data) 1041*6498aff2SJonas Devlieghere{ 1042*6498aff2SJonas Devlieghere lldb::ValueObjectSP valobj_sp; 1043*6498aff2SJonas Devlieghere if (data) 1044*6498aff2SJonas Devlieghere { 1045*6498aff2SJonas Devlieghere lldb::SBValue* sb_ptr = (lldb::SBValue *)data; 1046*6498aff2SJonas Devlieghere valobj_sp = sb_ptr->GetSP(); 1047*6498aff2SJonas Devlieghere } 1048*6498aff2SJonas Devlieghere return valobj_sp; 1049*6498aff2SJonas Devlieghere} 1050*6498aff2SJonas Devlieghere 1051*6498aff2SJonas Devlieghere#ifdef __cplusplus 1052*6498aff2SJonas Devlieghereextern "C" { 1053*6498aff2SJonas Devlieghere#endif 1054*6498aff2SJonas Devlieghere 1055*6498aff2SJonas Devliegherevoid LLDBSwigPythonCallPythonLogOutputCallback(const char *str, void *baton); 1056*6498aff2SJonas Devlieghere 1057*6498aff2SJonas Devlieghere#ifdef __cplusplus 1058*6498aff2SJonas Devlieghere} 1059*6498aff2SJonas Devlieghere#endif 1060*6498aff2SJonas Devlieghere%} 1061*6498aff2SJonas Devlieghere 1062*6498aff2SJonas Devlieghere%wrapper %{ 1063*6498aff2SJonas Devlieghere 1064*6498aff2SJonas Devlieghere 1065*6498aff2SJonas Devlieghere// For the LogOutputCallback functions 1066*6498aff2SJonas Devliegherevoid LLDBSwigPythonCallPythonLogOutputCallback(const char *str, void *baton) { 1067*6498aff2SJonas Devlieghere if (baton != Py_None) { 1068*6498aff2SJonas Devlieghere SWIG_PYTHON_THREAD_BEGIN_BLOCK; 1069*6498aff2SJonas Devlieghere PyObject *result = PyObject_CallFunction(reinterpret_cast<PyObject*>(baton), const_cast<char*>("s"), str); 1070*6498aff2SJonas Devlieghere Py_XDECREF(result); 1071*6498aff2SJonas Devlieghere SWIG_PYTHON_THREAD_END_BLOCK; 1072*6498aff2SJonas Devlieghere } 1073*6498aff2SJonas Devlieghere} 1074*6498aff2SJonas Devlieghere%} 1075