1130d950cSDimitry Andric%header %{ 2130d950cSDimitry Andric 30eae32dcSDimitry Andricclass PyErr_Cleaner { 4130d950cSDimitry Andricpublic: 50eae32dcSDimitry Andric PyErr_Cleaner(bool print = false) : m_print(print) {} 6130d950cSDimitry Andric 70eae32dcSDimitry Andric ~PyErr_Cleaner() { 80eae32dcSDimitry Andric if (PyErr_Occurred()) { 9130d950cSDimitry Andric if (m_print && !PyErr_ExceptionMatches(PyExc_SystemExit)) 10130d950cSDimitry Andric PyErr_Print(); 11130d950cSDimitry Andric PyErr_Clear(); 12130d950cSDimitry Andric } 13130d950cSDimitry Andric } 14130d950cSDimitry Andric 15130d950cSDimitry Andricprivate: 16130d950cSDimitry Andric bool m_print; 17130d950cSDimitry Andric}; 18130d950cSDimitry Andric 1906c3fb27SDimitry Andricllvm::Expected<bool> lldb_private::python::SWIGBridge::LLDBSwigPythonBreakpointCallbackFunction( 200eae32dcSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 21130d950cSDimitry Andric const lldb::StackFrameSP &frame_sp, 22130d950cSDimitry Andric const lldb::BreakpointLocationSP &bp_loc_sp, 230eae32dcSDimitry Andric const lldb_private::StructuredDataImpl &args_impl) { 24130d950cSDimitry Andric using namespace llvm; 25130d950cSDimitry Andric 26130d950cSDimitry Andric lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp); 27130d950cSDimitry Andric 28130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 290eae32dcSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 300eae32dcSDimitry Andric session_dictionary_name); 310eae32dcSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 320eae32dcSDimitry Andric python_function_name, dict); 33130d950cSDimitry Andric 34130d950cSDimitry Andric unsigned max_positional_args; 35130d950cSDimitry Andric if (auto arg_info = pfunc.GetArgInfo()) 36130d950cSDimitry Andric max_positional_args = arg_info.get().max_positional_args; 37130d950cSDimitry Andric else 38130d950cSDimitry Andric return arg_info.takeError(); 39130d950cSDimitry Andric 4006c3fb27SDimitry Andric PythonObject frame_arg = SWIGBridge::ToSWIGWrapper(frame_sp); 4106c3fb27SDimitry Andric PythonObject bp_loc_arg = SWIGBridge::ToSWIGWrapper(bp_loc_sp); 42130d950cSDimitry Andric 430eae32dcSDimitry Andric auto result = 440eae32dcSDimitry Andric max_positional_args < 4 450eae32dcSDimitry Andric ? pfunc.Call(frame_arg, bp_loc_arg, dict) 4606c3fb27SDimitry Andric : pfunc.Call(frame_arg, bp_loc_arg, SWIGBridge::ToSWIGWrapper(args_impl), dict); 47130d950cSDimitry Andric 48130d950cSDimitry Andric if (!result) 49130d950cSDimitry Andric return result.takeError(); 50130d950cSDimitry Andric 51130d950cSDimitry Andric // Only False counts as false! 52130d950cSDimitry Andric return result.get().get() != Py_False; 53130d950cSDimitry Andric} 54130d950cSDimitry Andric 554824e7fdSDimitry Andric// resolve a dotted Python name in the form 564824e7fdSDimitry Andric// foo.bar.baz.Foobar to an actual Python object 574824e7fdSDimitry Andric// if pmodule is NULL, the __main__ module will be used 584824e7fdSDimitry Andric// as the starting point for the search 59fe6060f1SDimitry Andric 600eae32dcSDimitry Andric// This function is called by 610eae32dcSDimitry Andric// lldb_private::ScriptInterpreterPython::BreakpointCallbackFunction(...) and is 620eae32dcSDimitry Andric// used when a script command is attached to a breakpoint for execution. 634824e7fdSDimitry Andric 640eae32dcSDimitry Andric// This function is called by 650eae32dcSDimitry Andric// lldb_private::ScriptInterpreterPython::WatchpointCallbackFunction(...) and is 660eae32dcSDimitry Andric// used when a script command is attached to a watchpoint for execution. 67fe6060f1SDimitry Andric 6806c3fb27SDimitry Andricbool lldb_private::python::SWIGBridge::LLDBSwigPythonWatchpointCallbackFunction( 690eae32dcSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 700eae32dcSDimitry Andric const lldb::StackFrameSP &frame_sp, const lldb::WatchpointSP &wp_sp) { 71130d950cSDimitry Andric 72130d950cSDimitry Andric bool stop_at_watchpoint = true; 73130d950cSDimitry Andric 74130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 75130d950cSDimitry Andric 760eae32dcSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 770eae32dcSDimitry Andric session_dictionary_name); 780eae32dcSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 790eae32dcSDimitry Andric python_function_name, dict); 80130d950cSDimitry Andric 81130d950cSDimitry Andric if (!pfunc.IsAllocated()) 82130d950cSDimitry Andric return stop_at_watchpoint; 83130d950cSDimitry Andric 840eae32dcSDimitry Andric PythonObject result = 8506c3fb27SDimitry Andric pfunc(SWIGBridge::ToSWIGWrapper(frame_sp), SWIGBridge::ToSWIGWrapper(wp_sp), dict); 86130d950cSDimitry Andric 87130d950cSDimitry Andric if (result.get() == Py_False) 88130d950cSDimitry Andric stop_at_watchpoint = false; 89130d950cSDimitry Andric 90130d950cSDimitry Andric return stop_at_watchpoint; 91130d950cSDimitry Andric} 92130d950cSDimitry Andric 93bdd1243dSDimitry Andric// This function is called by 94bdd1243dSDimitry Andric// ScriptInterpreterPython::FormatterMatchingCallbackFunction and it's used when 95bdd1243dSDimitry Andric// a data formatter provides the name of a callback to inspect a candidate type 96bdd1243dSDimitry Andric// before considering a match. 9706c3fb27SDimitry Andricbool lldb_private::python::SWIGBridge::LLDBSwigPythonFormatterCallbackFunction( 98bdd1243dSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 99bdd1243dSDimitry Andric lldb::TypeImplSP type_impl_sp) { 100bdd1243dSDimitry Andric 101bdd1243dSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 102bdd1243dSDimitry Andric 103bdd1243dSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 104bdd1243dSDimitry Andric session_dictionary_name); 105bdd1243dSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 106bdd1243dSDimitry Andric python_function_name, dict); 107bdd1243dSDimitry Andric 108bdd1243dSDimitry Andric if (!pfunc.IsAllocated()) 109bdd1243dSDimitry Andric return false; 110bdd1243dSDimitry Andric 111bdd1243dSDimitry Andric PythonObject result = 11206c3fb27SDimitry Andric pfunc(SWIGBridge::ToSWIGWrapper(type_impl_sp), dict); 113bdd1243dSDimitry Andric 114bdd1243dSDimitry Andric // Only if everything goes okay and the function returns True we'll consider 115bdd1243dSDimitry Andric // it a match. 116bdd1243dSDimitry Andric return result.get() == Py_True; 117bdd1243dSDimitry Andric} 118bdd1243dSDimitry Andric 11906c3fb27SDimitry Andricbool lldb_private::python::SWIGBridge::LLDBSwigPythonCallTypeScript( 1200eae32dcSDimitry Andric const char *python_function_name, const void *session_dictionary, 1210eae32dcSDimitry Andric const lldb::ValueObjectSP &valobj_sp, void **pyfunct_wrapper, 1220eae32dcSDimitry Andric const lldb::TypeSummaryOptionsSP &options_sp, std::string &retval) { 123130d950cSDimitry Andric 124130d950cSDimitry Andric retval.clear(); 125130d950cSDimitry Andric 126130d950cSDimitry Andric if (!python_function_name || !session_dictionary) 127130d950cSDimitry Andric return false; 128130d950cSDimitry Andric 129130d950cSDimitry Andric PyObject *pfunc_impl = nullptr; 130130d950cSDimitry Andric 1310eae32dcSDimitry Andric if (pyfunct_wrapper && *pyfunct_wrapper && 1320eae32dcSDimitry Andric PyFunction_Check(*pyfunct_wrapper)) { 133130d950cSDimitry Andric pfunc_impl = (PyObject *)(*pyfunct_wrapper); 1340eae32dcSDimitry Andric if (pfunc_impl->ob_refcnt == 1) { 135130d950cSDimitry Andric Py_XDECREF(pfunc_impl); 136130d950cSDimitry Andric pfunc_impl = NULL; 137130d950cSDimitry Andric } 138130d950cSDimitry Andric } 139130d950cSDimitry Andric 140130d950cSDimitry Andric PyObject *py_dict = (PyObject *)session_dictionary; 141130d950cSDimitry Andric if (!PythonDictionary::Check(py_dict)) 142130d950cSDimitry Andric return true; 143130d950cSDimitry Andric 144130d950cSDimitry Andric PythonDictionary dict(PyRefType::Borrowed, py_dict); 145130d950cSDimitry Andric 146130d950cSDimitry Andric PyErr_Cleaner pyerr_cleanup(true); // show Python errors 147130d950cSDimitry Andric 148130d950cSDimitry Andric PythonCallable pfunc(PyRefType::Borrowed, pfunc_impl); 149130d950cSDimitry Andric 1500eae32dcSDimitry Andric if (!pfunc.IsAllocated()) { 1510eae32dcSDimitry Andric pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 1520eae32dcSDimitry Andric python_function_name, dict); 153130d950cSDimitry Andric if (!pfunc.IsAllocated()) 154130d950cSDimitry Andric return false; 155130d950cSDimitry Andric 1560eae32dcSDimitry Andric if (pyfunct_wrapper) { 157130d950cSDimitry Andric *pyfunct_wrapper = pfunc.get(); 158130d950cSDimitry Andric Py_XINCREF(pfunc.get()); 159130d950cSDimitry Andric } 160130d950cSDimitry Andric } 161130d950cSDimitry Andric 162130d950cSDimitry Andric PythonObject result; 163130d950cSDimitry Andric auto argc = pfunc.GetArgInfo(); 164130d950cSDimitry Andric if (!argc) { 165130d950cSDimitry Andric llvm::consumeError(argc.takeError()); 166130d950cSDimitry Andric return false; 167130d950cSDimitry Andric } 168130d950cSDimitry Andric 16906c3fb27SDimitry Andric PythonObject value_arg = SWIGBridge::ToSWIGWrapper(valobj_sp); 170130d950cSDimitry Andric 171130d950cSDimitry Andric if (argc.get().max_positional_args < 3) 172130d950cSDimitry Andric result = pfunc(value_arg, dict); 173130d950cSDimitry Andric else 17406c3fb27SDimitry Andric result = pfunc(value_arg, dict, SWIGBridge::ToSWIGWrapper(*options_sp)); 175130d950cSDimitry Andric 176130d950cSDimitry Andric retval = result.Str().GetString().str(); 177130d950cSDimitry Andric 178130d950cSDimitry Andric return true; 179130d950cSDimitry Andric} 180130d950cSDimitry Andric 18106c3fb27SDimitry AndricPythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateSyntheticProvider( 1820eae32dcSDimitry Andric const char *python_class_name, const char *session_dictionary_name, 1830eae32dcSDimitry Andric const lldb::ValueObjectSP &valobj_sp) { 1840eae32dcSDimitry Andric if (python_class_name == NULL || python_class_name[0] == '\0' || 1850eae32dcSDimitry Andric !session_dictionary_name) 18604eeddc0SDimitry Andric return PythonObject(); 187130d950cSDimitry Andric 188130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 189130d950cSDimitry Andric 1900eae32dcSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 1910eae32dcSDimitry Andric session_dictionary_name); 1920eae32dcSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 1930eae32dcSDimitry Andric python_class_name, dict); 194130d950cSDimitry Andric 195130d950cSDimitry Andric if (!pfunc.IsAllocated()) 19604eeddc0SDimitry Andric return PythonObject(); 197130d950cSDimitry Andric 19806c3fb27SDimitry Andric auto sb_value = std::unique_ptr<lldb::SBValue>(new lldb::SBValue(valobj_sp)); 199130d950cSDimitry Andric sb_value->SetPreferSyntheticValue(false); 200130d950cSDimitry Andric 20106c3fb27SDimitry Andric PythonObject val_arg = SWIGBridge::ToSWIGWrapper(std::move(sb_value)); 202130d950cSDimitry Andric if (!val_arg.IsAllocated()) 20304eeddc0SDimitry Andric return PythonObject(); 204130d950cSDimitry Andric 205130d950cSDimitry Andric PythonObject result = pfunc(val_arg, dict); 206130d950cSDimitry Andric 207130d950cSDimitry Andric if (result.IsAllocated()) 20804eeddc0SDimitry Andric return result; 209130d950cSDimitry Andric 21004eeddc0SDimitry Andric return PythonObject(); 211130d950cSDimitry Andric} 212130d950cSDimitry Andric 21306c3fb27SDimitry AndricPythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateCommandObject( 2140eae32dcSDimitry Andric const char *python_class_name, const char *session_dictionary_name, 2150eae32dcSDimitry Andric lldb::DebuggerSP debugger_sp) { 2160eae32dcSDimitry Andric if (python_class_name == NULL || python_class_name[0] == '\0' || 2170eae32dcSDimitry Andric !session_dictionary_name) 21804eeddc0SDimitry Andric return PythonObject(); 219130d950cSDimitry Andric 220130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 2210eae32dcSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 2220eae32dcSDimitry Andric session_dictionary_name); 2230eae32dcSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 2240eae32dcSDimitry Andric python_class_name, dict); 225130d950cSDimitry Andric 226130d950cSDimitry Andric if (!pfunc.IsAllocated()) 22704eeddc0SDimitry Andric return PythonObject(); 228130d950cSDimitry Andric 22906c3fb27SDimitry Andric return pfunc(SWIGBridge::ToSWIGWrapper(std::move(debugger_sp)), dict); 230130d950cSDimitry Andric} 231130d950cSDimitry Andric 23206c3fb27SDimitry AndricPythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedBreakpointResolver( 2334824e7fdSDimitry Andric const char *python_class_name, const char *session_dictionary_name, 2340eae32dcSDimitry Andric const StructuredDataImpl &args_impl, 2354824e7fdSDimitry Andric const lldb::BreakpointSP &breakpoint_sp) { 2364824e7fdSDimitry Andric 2370eae32dcSDimitry Andric if (python_class_name == NULL || python_class_name[0] == '\0' || 2380eae32dcSDimitry Andric !session_dictionary_name) 23904eeddc0SDimitry Andric return PythonObject(); 240130d950cSDimitry Andric 241130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 242130d950cSDimitry Andric 2430eae32dcSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 2440eae32dcSDimitry Andric session_dictionary_name); 2450eae32dcSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 2460eae32dcSDimitry Andric python_class_name, dict); 247130d950cSDimitry Andric 248130d950cSDimitry Andric if (!pfunc.IsAllocated()) 24904eeddc0SDimitry Andric return PythonObject(); 250130d950cSDimitry Andric 2510eae32dcSDimitry Andric PythonObject result = 25206c3fb27SDimitry Andric pfunc(SWIGBridge::ToSWIGWrapper(breakpoint_sp), SWIGBridge::ToSWIGWrapper(args_impl), dict); 2530eae32dcSDimitry Andric // FIXME: At this point we should check that the class we found supports all 2540eae32dcSDimitry Andric // the methods that we need. 255130d950cSDimitry Andric 2560eae32dcSDimitry Andric if (result.IsAllocated()) { 257130d950cSDimitry Andric // Check that __callback__ is defined: 258130d950cSDimitry Andric auto callback_func = result.ResolveName<PythonCallable>("__callback__"); 259130d950cSDimitry Andric if (callback_func.IsAllocated()) 26004eeddc0SDimitry Andric return result; 261130d950cSDimitry Andric } 26204eeddc0SDimitry Andric return PythonObject(); 263130d950cSDimitry Andric} 264130d950cSDimitry Andric 26506c3fb27SDimitry Andricunsigned int lldb_private::python::SWIGBridge::LLDBSwigPythonCallBreakpointResolver( 2660eae32dcSDimitry Andric void *implementor, const char *method_name, 2670eae32dcSDimitry Andric lldb_private::SymbolContext *sym_ctx) { 268130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(false); 269130d950cSDimitry Andric PythonObject self(PyRefType::Borrowed, static_cast<PyObject *>(implementor)); 270130d950cSDimitry Andric auto pfunc = self.ResolveName<PythonCallable>(method_name); 271130d950cSDimitry Andric 272130d950cSDimitry Andric if (!pfunc.IsAllocated()) 273130d950cSDimitry Andric return 0; 274130d950cSDimitry Andric 27506c3fb27SDimitry Andric PythonObject result = sym_ctx ? pfunc(SWIGBridge::ToSWIGWrapper(*sym_ctx)) : pfunc(); 276130d950cSDimitry Andric 2770eae32dcSDimitry Andric if (PyErr_Occurred()) { 278130d950cSDimitry Andric PyErr_Print(); 2795ffd83dbSDimitry Andric PyErr_Clear(); 280130d950cSDimitry Andric return 0; 281130d950cSDimitry Andric } 282130d950cSDimitry Andric 283130d950cSDimitry Andric // The callback will return a bool, but we're need to also return ints 284130d950cSDimitry Andric // so we're squirrelling the bool through as an int... And if you return 285130d950cSDimitry Andric // nothing, we'll continue. 286130d950cSDimitry Andric if (strcmp(method_name, "__callback__") == 0) { 287130d950cSDimitry Andric if (result.get() == Py_False) 288130d950cSDimitry Andric return 0; 289130d950cSDimitry Andric else 290130d950cSDimitry Andric return 1; 291130d950cSDimitry Andric } 292130d950cSDimitry Andric 2935ffd83dbSDimitry Andric long long ret_val = unwrapOrSetPythonException(As<long long>(result)); 294130d950cSDimitry Andric 2955ffd83dbSDimitry Andric if (PyErr_Occurred()) { 2965ffd83dbSDimitry Andric PyErr_Print(); 2975ffd83dbSDimitry Andric PyErr_Clear(); 2985ffd83dbSDimitry Andric return 0; 2995ffd83dbSDimitry Andric } 300130d950cSDimitry Andric 301130d950cSDimitry Andric return ret_val; 302130d950cSDimitry Andric} 303130d950cSDimitry Andric 30406c3fb27SDimitry AndricPythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedStopHook( 3050eae32dcSDimitry Andric lldb::TargetSP target_sp, const char *python_class_name, 3060eae32dcSDimitry Andric const char *session_dictionary_name, const StructuredDataImpl &args_impl, 3070eae32dcSDimitry Andric Status &error) { 308e8d8bef9SDimitry Andric if (python_class_name == NULL || python_class_name[0] == '\0') { 309e8d8bef9SDimitry Andric error.SetErrorString("Empty class name."); 31004eeddc0SDimitry Andric return PythonObject(); 311e8d8bef9SDimitry Andric } 312e8d8bef9SDimitry Andric if (!session_dictionary_name) { 313e8d8bef9SDimitry Andric error.SetErrorString("No session dictionary"); 31404eeddc0SDimitry Andric return PythonObject(); 315e8d8bef9SDimitry Andric } 316e8d8bef9SDimitry Andric 317e8d8bef9SDimitry Andric PyErr_Cleaner py_err_cleaner(true); 318e8d8bef9SDimitry Andric 3190eae32dcSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 320e8d8bef9SDimitry Andric session_dictionary_name); 3210eae32dcSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 322e8d8bef9SDimitry Andric python_class_name, dict); 323e8d8bef9SDimitry Andric 324e8d8bef9SDimitry Andric if (!pfunc.IsAllocated()) { 325e8d8bef9SDimitry Andric error.SetErrorStringWithFormat("Could not find class: %s.", 326e8d8bef9SDimitry Andric python_class_name); 32704eeddc0SDimitry Andric return PythonObject(); 328e8d8bef9SDimitry Andric } 329e8d8bef9SDimitry Andric 3300eae32dcSDimitry Andric PythonObject result = 33106c3fb27SDimitry Andric pfunc(SWIGBridge::ToSWIGWrapper(target_sp), SWIGBridge::ToSWIGWrapper(args_impl), dict); 332e8d8bef9SDimitry Andric 3330eae32dcSDimitry Andric if (result.IsAllocated()) { 334e8d8bef9SDimitry Andric // Check that the handle_stop callback is defined: 335e8d8bef9SDimitry Andric auto callback_func = result.ResolveName<PythonCallable>("handle_stop"); 336e8d8bef9SDimitry Andric if (callback_func.IsAllocated()) { 337e8d8bef9SDimitry Andric if (auto args_info = callback_func.GetArgInfo()) { 338e8d8bef9SDimitry Andric size_t num_args = (*args_info).max_positional_args; 339e8d8bef9SDimitry Andric if (num_args != 2) { 3400eae32dcSDimitry Andric error.SetErrorStringWithFormat( 3410eae32dcSDimitry Andric "Wrong number of args for " 342e8d8bef9SDimitry Andric "handle_stop callback, should be 2 (excluding self), got: %zu", 343e8d8bef9SDimitry Andric num_args); 34404eeddc0SDimitry Andric return PythonObject(); 345e8d8bef9SDimitry Andric } else 34604eeddc0SDimitry Andric return result; 347e8d8bef9SDimitry Andric } else { 348e8d8bef9SDimitry Andric error.SetErrorString("Couldn't get num arguments for handle_stop " 349e8d8bef9SDimitry Andric "callback."); 35004eeddc0SDimitry Andric return PythonObject(); 351e8d8bef9SDimitry Andric } 35204eeddc0SDimitry Andric return result; 3530eae32dcSDimitry Andric } else { 354e8d8bef9SDimitry Andric error.SetErrorStringWithFormat("Class \"%s\" is missing the required " 355e8d8bef9SDimitry Andric "handle_stop callback.", 356e8d8bef9SDimitry Andric python_class_name); 357e8d8bef9SDimitry Andric } 358e8d8bef9SDimitry Andric } 35904eeddc0SDimitry Andric return PythonObject(); 360e8d8bef9SDimitry Andric} 361e8d8bef9SDimitry Andric 36206c3fb27SDimitry Andricbool lldb_private::python::SWIGBridge::LLDBSwigPythonStopHookCallHandleStop( 3630eae32dcSDimitry Andric void *implementor, lldb::ExecutionContextRefSP exc_ctx_sp, 3640eae32dcSDimitry Andric lldb::StreamSP stream) { 365e8d8bef9SDimitry Andric // handle_stop will return a bool with the meaning "should_stop"... 366e8d8bef9SDimitry Andric // If you return nothing we'll assume we are going to stop. 367e8d8bef9SDimitry Andric // Also any errors should return true, since we should stop on error. 368e8d8bef9SDimitry Andric 369e8d8bef9SDimitry Andric PyErr_Cleaner py_err_cleaner(false); 370e8d8bef9SDimitry Andric PythonObject self(PyRefType::Borrowed, static_cast<PyObject *>(implementor)); 371e8d8bef9SDimitry Andric auto pfunc = self.ResolveName<PythonCallable>("handle_stop"); 372e8d8bef9SDimitry Andric 373e8d8bef9SDimitry Andric if (!pfunc.IsAllocated()) 374e8d8bef9SDimitry Andric return true; 375e8d8bef9SDimitry Andric 376*0fca6ea1SDimitry Andric std::shared_ptr<lldb::SBStream> sb_stream = std::make_shared<lldb::SBStream>(); 377*0fca6ea1SDimitry Andric PythonObject sb_stream_arg = SWIGBridge::ToSWIGWrapper(sb_stream); 3780eae32dcSDimitry Andric PythonObject result = 37906c3fb27SDimitry Andric pfunc(SWIGBridge::ToSWIGWrapper(std::move(exc_ctx_sp)), sb_stream_arg); 380e8d8bef9SDimitry Andric 3810eae32dcSDimitry Andric if (PyErr_Occurred()) { 382e8d8bef9SDimitry Andric stream->PutCString("Python error occurred handling stop-hook."); 383e8d8bef9SDimitry Andric PyErr_Print(); 384e8d8bef9SDimitry Andric PyErr_Clear(); 385e8d8bef9SDimitry Andric return true; 386e8d8bef9SDimitry Andric } 387e8d8bef9SDimitry Andric 388e8d8bef9SDimitry Andric // Now add the result to the output stream. SBStream only 389e8d8bef9SDimitry Andric // makes an internally help StreamString which I can't interpose, so I 390e8d8bef9SDimitry Andric // have to copy it over here. 3910eae32dcSDimitry Andric stream->PutCString(sb_stream->GetData()); 392*0fca6ea1SDimitry Andric sb_stream_arg.release(); 393e8d8bef9SDimitry Andric 394e8d8bef9SDimitry Andric if (result.get() == Py_False) 395e8d8bef9SDimitry Andric return false; 396e8d8bef9SDimitry Andric else 397e8d8bef9SDimitry Andric return true; 398e8d8bef9SDimitry Andric} 399e8d8bef9SDimitry Andric 4000eae32dcSDimitry Andric// wrapper that calls an optional instance member of an object taking no 4010eae32dcSDimitry Andric// arguments 4020eae32dcSDimitry Andricstatic PyObject *LLDBSwigPython_CallOptionalMember( 4030eae32dcSDimitry Andric PyObject * implementor, char *callee_name, 4040eae32dcSDimitry Andric PyObject *ret_if_not_found = Py_None, bool *was_found = NULL) { 405130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(false); 406130d950cSDimitry Andric 407130d950cSDimitry Andric PythonObject self(PyRefType::Borrowed, static_cast<PyObject *>(implementor)); 408130d950cSDimitry Andric auto pfunc = self.ResolveName<PythonCallable>(callee_name); 409130d950cSDimitry Andric 4100eae32dcSDimitry Andric if (!pfunc.IsAllocated()) { 411130d950cSDimitry Andric if (was_found) 412130d950cSDimitry Andric *was_found = false; 413130d950cSDimitry Andric Py_XINCREF(ret_if_not_found); 414130d950cSDimitry Andric return ret_if_not_found; 415130d950cSDimitry Andric } 416130d950cSDimitry Andric 417130d950cSDimitry Andric if (was_found) 418130d950cSDimitry Andric *was_found = true; 419130d950cSDimitry Andric 420130d950cSDimitry Andric PythonObject result = pfunc(); 421130d950cSDimitry Andric return result.release(); 422130d950cSDimitry Andric} 423130d950cSDimitry Andric 42406c3fb27SDimitry Andricsize_t lldb_private::python::SWIGBridge::LLDBSwigPython_CalculateNumChildren(PyObject * implementor, 4250eae32dcSDimitry Andric uint32_t max) { 426130d950cSDimitry Andric PythonObject self(PyRefType::Borrowed, implementor); 427130d950cSDimitry Andric auto pfunc = self.ResolveName<PythonCallable>("num_children"); 428130d950cSDimitry Andric 429130d950cSDimitry Andric if (!pfunc.IsAllocated()) 430130d950cSDimitry Andric return 0; 431130d950cSDimitry Andric 432130d950cSDimitry Andric auto arg_info = pfunc.GetArgInfo(); 433130d950cSDimitry Andric if (!arg_info) { 434130d950cSDimitry Andric llvm::consumeError(arg_info.takeError()); 435130d950cSDimitry Andric return 0; 436130d950cSDimitry Andric } 437130d950cSDimitry Andric 4385ffd83dbSDimitry Andric size_t ret_val; 439130d950cSDimitry Andric if (arg_info.get().max_positional_args < 1) 4405ffd83dbSDimitry Andric ret_val = unwrapOrSetPythonException(As<long long>(pfunc.Call())); 441130d950cSDimitry Andric else 4420eae32dcSDimitry Andric ret_val = unwrapOrSetPythonException( 4430eae32dcSDimitry Andric As<long long>(pfunc.Call(PythonInteger(max)))); 444130d950cSDimitry Andric 4450eae32dcSDimitry Andric if (PyErr_Occurred()) { 446130d950cSDimitry Andric PyErr_Print(); 447130d950cSDimitry Andric PyErr_Clear(); 4485ffd83dbSDimitry Andric return 0; 449130d950cSDimitry Andric } 450130d950cSDimitry Andric 451130d950cSDimitry Andric if (arg_info.get().max_positional_args < 1) 452130d950cSDimitry Andric ret_val = std::min(ret_val, static_cast<size_t>(max)); 453130d950cSDimitry Andric 454130d950cSDimitry Andric return ret_val; 455130d950cSDimitry Andric} 456130d950cSDimitry Andric 45706c3fb27SDimitry AndricPyObject *lldb_private::python::SWIGBridge::LLDBSwigPython_GetChildAtIndex(PyObject * implementor, 4580eae32dcSDimitry Andric uint32_t idx) { 459130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 460130d950cSDimitry Andric 461130d950cSDimitry Andric PythonObject self(PyRefType::Borrowed, implementor); 462130d950cSDimitry Andric auto pfunc = self.ResolveName<PythonCallable>("get_child_at_index"); 463130d950cSDimitry Andric 464130d950cSDimitry Andric if (!pfunc.IsAllocated()) 465130d950cSDimitry Andric return nullptr; 466130d950cSDimitry Andric 467130d950cSDimitry Andric PythonObject result = pfunc(PythonInteger(idx)); 468130d950cSDimitry Andric 469130d950cSDimitry Andric if (!result.IsAllocated()) 470130d950cSDimitry Andric return nullptr; 471130d950cSDimitry Andric 472130d950cSDimitry Andric lldb::SBValue *sbvalue_ptr = nullptr; 4730eae32dcSDimitry Andric if (SWIG_ConvertPtr(result.get(), (void **)&sbvalue_ptr, 4740eae32dcSDimitry Andric SWIGTYPE_p_lldb__SBValue, 0) == -1) 475130d950cSDimitry Andric return nullptr; 476130d950cSDimitry Andric 477130d950cSDimitry Andric if (sbvalue_ptr == nullptr) 478130d950cSDimitry Andric return nullptr; 479130d950cSDimitry Andric 480130d950cSDimitry Andric return result.release(); 481130d950cSDimitry Andric} 482130d950cSDimitry Andric 48306c3fb27SDimitry Andricint lldb_private::python::SWIGBridge::LLDBSwigPython_GetIndexOfChildWithName( 4840eae32dcSDimitry Andric PyObject * implementor, const char *child_name) { 485130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 486130d950cSDimitry Andric 487130d950cSDimitry Andric PythonObject self(PyRefType::Borrowed, implementor); 488130d950cSDimitry Andric auto pfunc = self.ResolveName<PythonCallable>("get_child_index"); 489130d950cSDimitry Andric 490130d950cSDimitry Andric if (!pfunc.IsAllocated()) 491130d950cSDimitry Andric return UINT32_MAX; 492130d950cSDimitry Andric 4935ffd83dbSDimitry Andric llvm::Expected<PythonObject> result = pfunc.Call(PythonString(child_name)); 494130d950cSDimitry Andric 4950eae32dcSDimitry Andric long long retval = 4960eae32dcSDimitry Andric unwrapOrSetPythonException(As<long long>(std::move(result))); 4975ffd83dbSDimitry Andric 4985ffd83dbSDimitry Andric if (PyErr_Occurred()) { 4995ffd83dbSDimitry Andric PyErr_Clear(); // FIXME print this? do something else 500130d950cSDimitry Andric return UINT32_MAX; 5015ffd83dbSDimitry Andric } 502130d950cSDimitry Andric 503130d950cSDimitry Andric if (retval >= 0) 504130d950cSDimitry Andric return (uint32_t)retval; 505130d950cSDimitry Andric 506130d950cSDimitry Andric return UINT32_MAX; 507130d950cSDimitry Andric} 508130d950cSDimitry Andric 50906c3fb27SDimitry Andricbool lldb_private::python::SWIGBridge::LLDBSwigPython_UpdateSynthProviderInstance(PyObject * 5100eae32dcSDimitry Andric implementor) { 511130d950cSDimitry Andric bool ret_val = false; 512130d950cSDimitry Andric 513130d950cSDimitry Andric static char callee_name[] = "update"; 514130d950cSDimitry Andric 5150eae32dcSDimitry Andric PyObject *py_return = 5160eae32dcSDimitry Andric LLDBSwigPython_CallOptionalMember(implementor, callee_name); 517130d950cSDimitry Andric 518130d950cSDimitry Andric if (py_return == Py_True) 519130d950cSDimitry Andric ret_val = true; 520130d950cSDimitry Andric 521130d950cSDimitry Andric Py_XDECREF(py_return); 522130d950cSDimitry Andric 523130d950cSDimitry Andric return ret_val; 524130d950cSDimitry Andric} 525130d950cSDimitry Andric 52606c3fb27SDimitry Andricbool lldb_private::python::SWIGBridge::LLDBSwigPython_MightHaveChildrenSynthProviderInstance( 5270eae32dcSDimitry Andric PyObject * implementor) { 528130d950cSDimitry Andric bool ret_val = false; 529130d950cSDimitry Andric 530130d950cSDimitry Andric static char callee_name[] = "has_children"; 531130d950cSDimitry Andric 5320eae32dcSDimitry Andric PyObject *py_return = 5330eae32dcSDimitry Andric LLDBSwigPython_CallOptionalMember(implementor, callee_name, Py_True); 534130d950cSDimitry Andric 535130d950cSDimitry Andric if (py_return == Py_True) 536130d950cSDimitry Andric ret_val = true; 537130d950cSDimitry Andric 538130d950cSDimitry Andric Py_XDECREF(py_return); 539130d950cSDimitry Andric 540130d950cSDimitry Andric return ret_val; 541130d950cSDimitry Andric} 542130d950cSDimitry Andric 54306c3fb27SDimitry AndricPyObject *lldb_private::python::SWIGBridge::LLDBSwigPython_GetValueSynthProviderInstance( 5440eae32dcSDimitry Andric PyObject * implementor) { 545130d950cSDimitry Andric PyObject *ret_val = nullptr; 546130d950cSDimitry Andric 547130d950cSDimitry Andric static char callee_name[] = "get_value"; 548130d950cSDimitry Andric 5490eae32dcSDimitry Andric PyObject *py_return = 5500eae32dcSDimitry Andric LLDBSwigPython_CallOptionalMember(implementor, callee_name, Py_None); 551130d950cSDimitry Andric 552130d950cSDimitry Andric if (py_return == Py_None || py_return == nullptr) 553130d950cSDimitry Andric ret_val = nullptr; 554130d950cSDimitry Andric 555130d950cSDimitry Andric lldb::SBValue *sbvalue_ptr = NULL; 556130d950cSDimitry Andric 5570eae32dcSDimitry Andric if (SWIG_ConvertPtr(py_return, (void **)&sbvalue_ptr, 5580eae32dcSDimitry Andric SWIGTYPE_p_lldb__SBValue, 0) == -1) 559130d950cSDimitry Andric ret_val = nullptr; 560130d950cSDimitry Andric else if (sbvalue_ptr == NULL) 561130d950cSDimitry Andric ret_val = nullptr; 562130d950cSDimitry Andric else 563130d950cSDimitry Andric ret_val = py_return; 564130d950cSDimitry Andric 565130d950cSDimitry Andric Py_XDECREF(py_return); 566130d950cSDimitry Andric return ret_val; 567130d950cSDimitry Andric} 568130d950cSDimitry Andric 56906c3fb27SDimitry Andricvoid *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBData(PyObject * data) { 570fe6060f1SDimitry Andric lldb::SBData *sb_ptr = nullptr; 571fe6060f1SDimitry Andric 5720eae32dcSDimitry Andric int valid_cast = 5730eae32dcSDimitry Andric SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBData, 0); 574fe6060f1SDimitry Andric 575fe6060f1SDimitry Andric if (valid_cast == -1) 576fe6060f1SDimitry Andric return NULL; 577fe6060f1SDimitry Andric 578fe6060f1SDimitry Andric return sb_ptr; 579fe6060f1SDimitry Andric} 580fe6060f1SDimitry Andric 58106c3fb27SDimitry Andricvoid *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBBreakpoint(PyObject * data) { 58206c3fb27SDimitry Andric lldb::SBBreakpoint *sb_ptr = nullptr; 58306c3fb27SDimitry Andric 58406c3fb27SDimitry Andric int valid_cast = 58506c3fb27SDimitry Andric SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBBreakpoint, 0); 58606c3fb27SDimitry Andric 58706c3fb27SDimitry Andric if (valid_cast == -1) 58806c3fb27SDimitry Andric return NULL; 58906c3fb27SDimitry Andric 59006c3fb27SDimitry Andric return sb_ptr; 59106c3fb27SDimitry Andric} 59206c3fb27SDimitry Andric 59306c3fb27SDimitry Andricvoid *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBAttachInfo(PyObject * data) { 59406c3fb27SDimitry Andric lldb::SBAttachInfo *sb_ptr = nullptr; 59506c3fb27SDimitry Andric 59606c3fb27SDimitry Andric int valid_cast = 59706c3fb27SDimitry Andric SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBAttachInfo, 0); 59806c3fb27SDimitry Andric 59906c3fb27SDimitry Andric if (valid_cast == -1) 60006c3fb27SDimitry Andric return NULL; 60106c3fb27SDimitry Andric 60206c3fb27SDimitry Andric return sb_ptr; 60306c3fb27SDimitry Andric} 60406c3fb27SDimitry Andric 60506c3fb27SDimitry Andricvoid *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBLaunchInfo(PyObject * data) { 60606c3fb27SDimitry Andric lldb::SBLaunchInfo *sb_ptr = nullptr; 60706c3fb27SDimitry Andric 60806c3fb27SDimitry Andric int valid_cast = 60906c3fb27SDimitry Andric SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBLaunchInfo, 0); 61006c3fb27SDimitry Andric 61106c3fb27SDimitry Andric if (valid_cast == -1) 61206c3fb27SDimitry Andric return NULL; 61306c3fb27SDimitry Andric 61406c3fb27SDimitry Andric return sb_ptr; 61506c3fb27SDimitry Andric} 61606c3fb27SDimitry Andric 61706c3fb27SDimitry Andricvoid *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBError(PyObject * data) { 618fe6060f1SDimitry Andric lldb::SBError *sb_ptr = nullptr; 619fe6060f1SDimitry Andric 6200eae32dcSDimitry Andric int valid_cast = 6210eae32dcSDimitry Andric SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBError, 0); 622fe6060f1SDimitry Andric 623fe6060f1SDimitry Andric if (valid_cast == -1) 624fe6060f1SDimitry Andric return NULL; 625fe6060f1SDimitry Andric 626fe6060f1SDimitry Andric return sb_ptr; 627fe6060f1SDimitry Andric} 628fe6060f1SDimitry Andric 629*0fca6ea1SDimitry Andricvoid *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBEvent(PyObject * data) { 630*0fca6ea1SDimitry Andric lldb::SBEvent *sb_ptr = nullptr; 631*0fca6ea1SDimitry Andric 632*0fca6ea1SDimitry Andric int valid_cast = 633*0fca6ea1SDimitry Andric SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBEvent, 0); 634*0fca6ea1SDimitry Andric 635*0fca6ea1SDimitry Andric if (valid_cast == -1) 636*0fca6ea1SDimitry Andric return NULL; 637*0fca6ea1SDimitry Andric 638*0fca6ea1SDimitry Andric return sb_ptr; 639*0fca6ea1SDimitry Andric} 640*0fca6ea1SDimitry Andric 641*0fca6ea1SDimitry Andricvoid *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBStream(PyObject * data) { 642*0fca6ea1SDimitry Andric lldb::SBStream *sb_ptr = nullptr; 643*0fca6ea1SDimitry Andric 644*0fca6ea1SDimitry Andric int valid_cast = 645*0fca6ea1SDimitry Andric SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBStream, 0); 646*0fca6ea1SDimitry Andric 647*0fca6ea1SDimitry Andric if (valid_cast == -1) 648*0fca6ea1SDimitry Andric return NULL; 649*0fca6ea1SDimitry Andric 650*0fca6ea1SDimitry Andric return sb_ptr; 651*0fca6ea1SDimitry Andric} 652*0fca6ea1SDimitry Andric 65306c3fb27SDimitry Andricvoid *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBValue(PyObject * data) { 654130d950cSDimitry Andric lldb::SBValue *sb_ptr = NULL; 655130d950cSDimitry Andric 6560eae32dcSDimitry Andric int valid_cast = 6570eae32dcSDimitry Andric SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBValue, 0); 658130d950cSDimitry Andric 659130d950cSDimitry Andric if (valid_cast == -1) 660130d950cSDimitry Andric return NULL; 661130d950cSDimitry Andric 662130d950cSDimitry Andric return sb_ptr; 663130d950cSDimitry Andric} 664130d950cSDimitry Andric 66506c3fb27SDimitry Andricvoid *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject * 6660eae32dcSDimitry Andric data) { 667349cc55cSDimitry Andric lldb::SBMemoryRegionInfo *sb_ptr = NULL; 668349cc55cSDimitry Andric 6690eae32dcSDimitry Andric int valid_cast = SWIG_ConvertPtr(data, (void **)&sb_ptr, 6700eae32dcSDimitry Andric SWIGTYPE_p_lldb__SBMemoryRegionInfo, 0); 671349cc55cSDimitry Andric 672349cc55cSDimitry Andric if (valid_cast == -1) 673349cc55cSDimitry Andric return NULL; 674349cc55cSDimitry Andric 675349cc55cSDimitry Andric return sb_ptr; 676349cc55cSDimitry Andric} 677349cc55cSDimitry Andric 67806c3fb27SDimitry Andricbool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommand( 6790eae32dcSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 6800eae32dcSDimitry Andric lldb::DebuggerSP debugger, const char *args, 681130d950cSDimitry Andric lldb_private::CommandReturnObject &cmd_retobj, 6820eae32dcSDimitry Andric lldb::ExecutionContextRefSP exe_ctx_ref_sp) { 683130d950cSDimitry Andric 684130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 6850eae32dcSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 6860eae32dcSDimitry Andric session_dictionary_name); 6870eae32dcSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 6880eae32dcSDimitry Andric python_function_name, dict); 689130d950cSDimitry Andric 690130d950cSDimitry Andric if (!pfunc.IsAllocated()) 691130d950cSDimitry Andric return false; 692130d950cSDimitry Andric 693130d950cSDimitry Andric auto argc = pfunc.GetArgInfo(); 694130d950cSDimitry Andric if (!argc) { 695130d950cSDimitry Andric llvm::consumeError(argc.takeError()); 696130d950cSDimitry Andric return false; 697130d950cSDimitry Andric } 69806c3fb27SDimitry Andric PythonObject debugger_arg = SWIGBridge::ToSWIGWrapper(std::move(debugger)); 69906c3fb27SDimitry Andric auto cmd_retobj_arg = SWIGBridge::ToSWIGWrapper(cmd_retobj); 700130d950cSDimitry Andric 701130d950cSDimitry Andric if (argc.get().max_positional_args < 5u) 70204eeddc0SDimitry Andric pfunc(debugger_arg, PythonString(args), cmd_retobj_arg.obj(), dict); 703130d950cSDimitry Andric else 7040eae32dcSDimitry Andric pfunc(debugger_arg, PythonString(args), 70506c3fb27SDimitry Andric SWIGBridge::ToSWIGWrapper(std::move(exe_ctx_ref_sp)), cmd_retobj_arg.obj(), dict); 706130d950cSDimitry Andric 707130d950cSDimitry Andric return true; 708130d950cSDimitry Andric} 709130d950cSDimitry Andric 71006c3fb27SDimitry Andricbool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommandObject( 7110eae32dcSDimitry Andric PyObject *implementor, lldb::DebuggerSP debugger, const char *args, 712130d950cSDimitry Andric lldb_private::CommandReturnObject &cmd_retobj, 7130eae32dcSDimitry Andric lldb::ExecutionContextRefSP exe_ctx_ref_sp) { 714130d950cSDimitry Andric 715130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 716130d950cSDimitry Andric 717130d950cSDimitry Andric PythonObject self(PyRefType::Borrowed, implementor); 718130d950cSDimitry Andric auto pfunc = self.ResolveName<PythonCallable>("__call__"); 719130d950cSDimitry Andric 720130d950cSDimitry Andric if (!pfunc.IsAllocated()) 721130d950cSDimitry Andric return false; 722130d950cSDimitry Andric 72306c3fb27SDimitry Andric auto cmd_retobj_arg = SWIGBridge::ToSWIGWrapper(cmd_retobj); 724130d950cSDimitry Andric 72506c3fb27SDimitry Andric pfunc(SWIGBridge::ToSWIGWrapper(std::move(debugger)), PythonString(args), 72606c3fb27SDimitry Andric SWIGBridge::ToSWIGWrapper(exe_ctx_ref_sp), cmd_retobj_arg.obj()); 727130d950cSDimitry Andric 728130d950cSDimitry Andric return true; 729130d950cSDimitry Andric} 730130d950cSDimitry Andric 731*0fca6ea1SDimitry Andricstd::optional<std::string> 732*0fca6ea1SDimitry Andriclldb_private::python::SWIGBridge::LLDBSwigPythonGetRepeatCommandForScriptedCommand(PyObject *implementor, 733*0fca6ea1SDimitry Andric std::string &command) { 734*0fca6ea1SDimitry Andric PyErr_Cleaner py_err_cleaner(true); 735*0fca6ea1SDimitry Andric 736*0fca6ea1SDimitry Andric PythonObject self(PyRefType::Borrowed, implementor); 737*0fca6ea1SDimitry Andric auto pfunc = self.ResolveName<PythonCallable>("get_repeat_command"); 738*0fca6ea1SDimitry Andric // If not implemented, repeat the exact command. 739*0fca6ea1SDimitry Andric if (!pfunc.IsAllocated()) 740*0fca6ea1SDimitry Andric return std::nullopt; 741*0fca6ea1SDimitry Andric 742*0fca6ea1SDimitry Andric PythonString command_str(command); 743*0fca6ea1SDimitry Andric PythonObject result = pfunc(command_str); 744*0fca6ea1SDimitry Andric 745*0fca6ea1SDimitry Andric // A return of None is the equivalent of nullopt - means repeat 746*0fca6ea1SDimitry Andric // the command as is: 747*0fca6ea1SDimitry Andric if (result.IsNone()) 748*0fca6ea1SDimitry Andric return std::nullopt; 749*0fca6ea1SDimitry Andric 750*0fca6ea1SDimitry Andric return result.Str().GetString().str(); 751*0fca6ea1SDimitry Andric} 752*0fca6ea1SDimitry Andric 753*0fca6ea1SDimitry Andric#include "lldb/Interpreter/CommandReturnObject.h" 754*0fca6ea1SDimitry Andric 755*0fca6ea1SDimitry Andricbool lldb_private::python::SWIGBridge::LLDBSwigPythonCallParsedCommandObject( 756*0fca6ea1SDimitry Andric PyObject *implementor, lldb::DebuggerSP debugger, lldb_private::StructuredDataImpl &args_impl, 757*0fca6ea1SDimitry Andric lldb_private::CommandReturnObject &cmd_retobj, 758*0fca6ea1SDimitry Andric lldb::ExecutionContextRefSP exe_ctx_ref_sp) { 759*0fca6ea1SDimitry Andric 760*0fca6ea1SDimitry Andric PyErr_Cleaner py_err_cleaner(true); 761*0fca6ea1SDimitry Andric 762*0fca6ea1SDimitry Andric PythonObject self(PyRefType::Borrowed, implementor); 763*0fca6ea1SDimitry Andric auto pfunc = self.ResolveName<PythonCallable>("__call__"); 764*0fca6ea1SDimitry Andric 765*0fca6ea1SDimitry Andric if (!pfunc.IsAllocated()) { 766*0fca6ea1SDimitry Andric cmd_retobj.AppendError("Could not find '__call__' method in implementation class"); 767*0fca6ea1SDimitry Andric return false; 768*0fca6ea1SDimitry Andric } 769*0fca6ea1SDimitry Andric 770*0fca6ea1SDimitry Andric pfunc(SWIGBridge::ToSWIGWrapper(std::move(debugger)), SWIGBridge::ToSWIGWrapper(args_impl), 771*0fca6ea1SDimitry Andric SWIGBridge::ToSWIGWrapper(exe_ctx_ref_sp), SWIGBridge::ToSWIGWrapper(cmd_retobj).obj()); 772*0fca6ea1SDimitry Andric 773*0fca6ea1SDimitry Andric return true; 774*0fca6ea1SDimitry Andric} 775*0fca6ea1SDimitry Andric 77606c3fb27SDimitry AndricPythonObject lldb_private::python::SWIGBridge::LLDBSWIGPythonCreateOSPlugin( 7770eae32dcSDimitry Andric const char *python_class_name, const char *session_dictionary_name, 7780eae32dcSDimitry Andric const lldb::ProcessSP &process_sp) { 7790eae32dcSDimitry Andric if (python_class_name == NULL || python_class_name[0] == '\0' || 7800eae32dcSDimitry Andric !session_dictionary_name) 78104eeddc0SDimitry Andric return PythonObject(); 782130d950cSDimitry Andric 783130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 784130d950cSDimitry Andric 7850eae32dcSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 7860eae32dcSDimitry Andric session_dictionary_name); 7870eae32dcSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 7880eae32dcSDimitry Andric python_class_name, dict); 789130d950cSDimitry Andric 790130d950cSDimitry Andric if (!pfunc.IsAllocated()) 79104eeddc0SDimitry Andric return PythonObject(); 792130d950cSDimitry Andric 79306c3fb27SDimitry Andric return pfunc(SWIGBridge::ToSWIGWrapper(process_sp)); 794130d950cSDimitry Andric} 795130d950cSDimitry Andric 79606c3fb27SDimitry AndricPythonObject lldb_private::python::SWIGBridge::LLDBSWIGPython_CreateFrameRecognizer( 7970eae32dcSDimitry Andric const char *python_class_name, const char *session_dictionary_name) { 7980eae32dcSDimitry Andric if (python_class_name == NULL || python_class_name[0] == '\0' || 7990eae32dcSDimitry Andric !session_dictionary_name) 80004eeddc0SDimitry Andric return PythonObject(); 801130d950cSDimitry Andric 802130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 803130d950cSDimitry Andric 8040eae32dcSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 8050eae32dcSDimitry Andric session_dictionary_name); 8060eae32dcSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 8070eae32dcSDimitry Andric python_class_name, dict); 808130d950cSDimitry Andric 809130d950cSDimitry Andric if (!pfunc.IsAllocated()) 81004eeddc0SDimitry Andric return PythonObject(); 811130d950cSDimitry Andric 81204eeddc0SDimitry Andric return pfunc(); 813130d950cSDimitry Andric} 814130d950cSDimitry Andric 81506c3fb27SDimitry AndricPyObject *lldb_private::python::SWIGBridge::LLDBSwigPython_GetRecognizedArguments( 8160eae32dcSDimitry Andric PyObject * implementor, const lldb::StackFrameSP &frame_sp) { 817130d950cSDimitry Andric static char callee_name[] = "get_recognized_arguments"; 818130d950cSDimitry Andric 81906c3fb27SDimitry Andric PythonObject arg = SWIGBridge::ToSWIGWrapper(frame_sp); 820130d950cSDimitry Andric 821130d950cSDimitry Andric PythonString str(callee_name); 8220eae32dcSDimitry Andric PyObject *result = 8230eae32dcSDimitry Andric PyObject_CallMethodObjArgs(implementor, str.get(), arg.get(), NULL); 824130d950cSDimitry Andric return result; 825130d950cSDimitry Andric} 826130d950cSDimitry Andric 82706c3fb27SDimitry Andricvoid *lldb_private::python::SWIGBridge::LLDBSWIGPython_GetDynamicSetting( 8280eae32dcSDimitry Andric void *module, const char *setting, const lldb::TargetSP &target_sp) { 829130d950cSDimitry Andric if (!module || !setting) 830130d950cSDimitry Andric Py_RETURN_NONE; 831130d950cSDimitry Andric 832130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 833130d950cSDimitry Andric PythonObject py_module(PyRefType::Borrowed, (PyObject *)module); 834130d950cSDimitry Andric auto pfunc = py_module.ResolveName<PythonCallable>("get_dynamic_setting"); 835130d950cSDimitry Andric 836130d950cSDimitry Andric if (!pfunc.IsAllocated()) 837130d950cSDimitry Andric Py_RETURN_NONE; 838130d950cSDimitry Andric 83906c3fb27SDimitry Andric auto result = pfunc(SWIGBridge::ToSWIGWrapper(target_sp), PythonString(setting)); 840130d950cSDimitry Andric 841130d950cSDimitry Andric return result.release(); 842130d950cSDimitry Andric} 843130d950cSDimitry Andric 84406c3fb27SDimitry Andricbool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordProcess( 8454824e7fdSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 8464824e7fdSDimitry Andric const lldb::ProcessSP &process, std::string &output) { 847130d950cSDimitry Andric 8480eae32dcSDimitry Andric if (python_function_name == NULL || python_function_name[0] == '\0' || 8490eae32dcSDimitry Andric !session_dictionary_name) 850130d950cSDimitry Andric return false; 851130d950cSDimitry Andric 852130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 853130d950cSDimitry Andric 8540eae32dcSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 8550eae32dcSDimitry Andric session_dictionary_name); 8560eae32dcSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 8570eae32dcSDimitry Andric python_function_name, dict); 858130d950cSDimitry Andric 859130d950cSDimitry Andric if (!pfunc.IsAllocated()) 860130d950cSDimitry Andric return false; 861130d950cSDimitry Andric 86206c3fb27SDimitry Andric auto result = pfunc(SWIGBridge::ToSWIGWrapper(process), dict); 863130d950cSDimitry Andric 864130d950cSDimitry Andric output = result.Str().GetString().str(); 865130d950cSDimitry Andric 866130d950cSDimitry Andric return true; 867130d950cSDimitry Andric} 868130d950cSDimitry Andric 86906c3fb27SDimitry Andricstd::optional<std::string> lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordThread( 8700eae32dcSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 8710eae32dcSDimitry Andric lldb::ThreadSP thread) { 8720eae32dcSDimitry Andric if (python_function_name == NULL || python_function_name[0] == '\0' || 8730eae32dcSDimitry Andric !session_dictionary_name) 874bdd1243dSDimitry Andric return std::nullopt; 875130d950cSDimitry Andric 876130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 877130d950cSDimitry Andric 8780eae32dcSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 8790eae32dcSDimitry Andric session_dictionary_name); 8800eae32dcSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 8810eae32dcSDimitry Andric python_function_name, dict); 882130d950cSDimitry Andric 883130d950cSDimitry Andric if (!pfunc.IsAllocated()) 884bdd1243dSDimitry Andric return std::nullopt; 885130d950cSDimitry Andric 88606c3fb27SDimitry Andric auto result = pfunc(SWIGBridge::ToSWIGWrapper(std::move(thread)), dict); 887130d950cSDimitry Andric 8880eae32dcSDimitry Andric return result.Str().GetString().str(); 889130d950cSDimitry Andric} 890130d950cSDimitry Andric 89106c3fb27SDimitry Andricbool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordTarget( 8924824e7fdSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 8934824e7fdSDimitry Andric const lldb::TargetSP &target, std::string &output) { 894130d950cSDimitry Andric 8950eae32dcSDimitry Andric if (python_function_name == NULL || python_function_name[0] == '\0' || 8960eae32dcSDimitry Andric !session_dictionary_name) 897130d950cSDimitry Andric return false; 898130d950cSDimitry Andric 899130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 900130d950cSDimitry Andric 9010eae32dcSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 9020eae32dcSDimitry Andric session_dictionary_name); 9030eae32dcSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 9040eae32dcSDimitry Andric python_function_name, dict); 905130d950cSDimitry Andric 906130d950cSDimitry Andric if (!pfunc.IsAllocated()) 907130d950cSDimitry Andric return false; 908130d950cSDimitry Andric 90906c3fb27SDimitry Andric auto result = pfunc(SWIGBridge::ToSWIGWrapper(target), dict); 910130d950cSDimitry Andric 911130d950cSDimitry Andric output = result.Str().GetString().str(); 912130d950cSDimitry Andric 913130d950cSDimitry Andric return true; 914130d950cSDimitry Andric} 915130d950cSDimitry Andric 91606c3fb27SDimitry Andricstd::optional<std::string> lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordFrame( 9170eae32dcSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 9180eae32dcSDimitry Andric lldb::StackFrameSP frame) { 9190eae32dcSDimitry Andric if (python_function_name == NULL || python_function_name[0] == '\0' || 9200eae32dcSDimitry Andric !session_dictionary_name) 921bdd1243dSDimitry Andric return std::nullopt; 922130d950cSDimitry Andric 923130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 924130d950cSDimitry Andric 9250eae32dcSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 9260eae32dcSDimitry Andric session_dictionary_name); 9270eae32dcSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 9280eae32dcSDimitry Andric python_function_name, dict); 929130d950cSDimitry Andric 930130d950cSDimitry Andric if (!pfunc.IsAllocated()) 931bdd1243dSDimitry Andric return std::nullopt; 932130d950cSDimitry Andric 93306c3fb27SDimitry Andric auto result = pfunc(SWIGBridge::ToSWIGWrapper(std::move(frame)), dict); 934130d950cSDimitry Andric 9350eae32dcSDimitry Andric return result.Str().GetString().str(); 936130d950cSDimitry Andric} 937130d950cSDimitry Andric 93806c3fb27SDimitry Andricbool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordValue( 9394824e7fdSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 9404824e7fdSDimitry Andric const lldb::ValueObjectSP &value, std::string &output) { 941130d950cSDimitry Andric 9420eae32dcSDimitry Andric if (python_function_name == NULL || python_function_name[0] == '\0' || 9430eae32dcSDimitry Andric !session_dictionary_name) 944130d950cSDimitry Andric return false; 945130d950cSDimitry Andric 946130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 947130d950cSDimitry Andric 9480eae32dcSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 9490eae32dcSDimitry Andric session_dictionary_name); 9500eae32dcSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 9510eae32dcSDimitry Andric python_function_name, dict); 952130d950cSDimitry Andric 953130d950cSDimitry Andric if (!pfunc.IsAllocated()) 954130d950cSDimitry Andric return false; 955130d950cSDimitry Andric 95606c3fb27SDimitry Andric auto result = pfunc(SWIGBridge::ToSWIGWrapper(value), dict); 957130d950cSDimitry Andric 958130d950cSDimitry Andric output = result.Str().GetString().str(); 959130d950cSDimitry Andric 960130d950cSDimitry Andric return true; 961130d950cSDimitry Andric} 962130d950cSDimitry Andric 96306c3fb27SDimitry Andricbool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleInit( 9640eae32dcSDimitry Andric const char *python_module_name, const char *session_dictionary_name, 9650eae32dcSDimitry Andric lldb::DebuggerSP debugger) { 966130d950cSDimitry Andric std::string python_function_name_string = python_module_name; 967130d950cSDimitry Andric python_function_name_string += ".__lldb_init_module"; 968130d950cSDimitry Andric const char *python_function_name = python_function_name_string.c_str(); 969130d950cSDimitry Andric 970130d950cSDimitry Andric PyErr_Cleaner py_err_cleaner(true); 971130d950cSDimitry Andric 9720eae32dcSDimitry Andric auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>( 9730eae32dcSDimitry Andric session_dictionary_name); 9740eae32dcSDimitry Andric auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>( 9750eae32dcSDimitry Andric python_function_name, dict); 976130d950cSDimitry Andric 977130d950cSDimitry Andric // This method is optional and need not exist. So if we don't find it, 978130d950cSDimitry Andric // it's actually a success, not a failure. 979130d950cSDimitry Andric if (!pfunc.IsAllocated()) 980130d950cSDimitry Andric return true; 981130d950cSDimitry Andric 98206c3fb27SDimitry Andric pfunc(SWIGBridge::ToSWIGWrapper(std::move(debugger)), dict); 983130d950cSDimitry Andric 984130d950cSDimitry Andric return true; 985130d950cSDimitry Andric} 986130d950cSDimitry Andric 98706c3fb27SDimitry Andriclldb::ValueObjectSP lldb_private::python::SWIGBridge::LLDBSWIGPython_GetValueObjectSPFromSBValue( 9880eae32dcSDimitry Andric void *data) { 989130d950cSDimitry Andric lldb::ValueObjectSP valobj_sp; 9900eae32dcSDimitry Andric if (data) { 991130d950cSDimitry Andric lldb::SBValue *sb_ptr = (lldb::SBValue *)data; 992130d950cSDimitry Andric valobj_sp = sb_ptr->GetSP(); 993130d950cSDimitry Andric } 994130d950cSDimitry Andric return valobj_sp; 995130d950cSDimitry Andric} 996130d950cSDimitry Andric 997130d950cSDimitry Andric// For the LogOutputCallback functions 9980eae32dcSDimitry Andricstatic void LLDBSwigPythonCallPythonLogOutputCallback(const char *str, 9990eae32dcSDimitry Andric void *baton) { 1000130d950cSDimitry Andric if (baton != Py_None) { 1001130d950cSDimitry Andric SWIG_PYTHON_THREAD_BEGIN_BLOCK; 10020eae32dcSDimitry Andric PyObject *result = PyObject_CallFunction( 10030eae32dcSDimitry Andric reinterpret_cast<PyObject *>(baton), const_cast<char *>("s"), str); 1004130d950cSDimitry Andric Py_XDECREF(result); 1005130d950cSDimitry Andric SWIG_PYTHON_THREAD_END_BLOCK; 1006130d950cSDimitry Andric } 1007130d950cSDimitry Andric} 100806c3fb27SDimitry Andric 100906c3fb27SDimitry Andric// For DebuggerTerminateCallback functions 101006c3fb27SDimitry Andricstatic void LLDBSwigPythonCallPythonSBDebuggerTerminateCallback(lldb::user_id_t debugger_id, 101106c3fb27SDimitry Andric void *baton) { 101206c3fb27SDimitry Andric if (baton != Py_None) { 101306c3fb27SDimitry Andric SWIG_PYTHON_THREAD_BEGIN_BLOCK; 101406c3fb27SDimitry Andric PyObject *result = PyObject_CallFunction( 101506c3fb27SDimitry Andric reinterpret_cast<PyObject *>(baton), const_cast<char *>("l"), debugger_id); 101606c3fb27SDimitry Andric Py_XDECREF(result); 101706c3fb27SDimitry Andric SWIG_PYTHON_THREAD_END_BLOCK; 101806c3fb27SDimitry Andric } 101906c3fb27SDimitry Andric} 102006c3fb27SDimitry Andric 1021*0fca6ea1SDimitry Andricstatic bool LLDBSwigPythonCallPythonSBCommandInterpreterSetCommandOverrideCallback(void *baton, const char **argv) { 1022*0fca6ea1SDimitry Andric bool ret_val = false; 1023*0fca6ea1SDimitry Andric if (baton != Py_None) { 1024*0fca6ea1SDimitry Andric SWIG_PYTHON_THREAD_BEGIN_BLOCK; 1025*0fca6ea1SDimitry Andric // Create a PyList of items since we're going to pass it to the callback as a tuple 1026*0fca6ea1SDimitry Andric // of arguments. 1027*0fca6ea1SDimitry Andric PyObject *py_argv = PyList_New(0); 1028*0fca6ea1SDimitry Andric for (const char **arg = argv; arg && *arg; arg++) { 1029*0fca6ea1SDimitry Andric std::string arg_string = *arg; 1030*0fca6ea1SDimitry Andric PyObject *py_string = PyUnicode_FromStringAndSize(arg_string.c_str(), arg_string.size()); 1031*0fca6ea1SDimitry Andric PyList_Append(py_argv, py_string); 1032*0fca6ea1SDimitry Andric } 1033*0fca6ea1SDimitry Andric 1034*0fca6ea1SDimitry Andric PyObject *result = PyObject_CallObject( 1035*0fca6ea1SDimitry Andric reinterpret_cast<PyObject *>(baton), PyList_AsTuple(py_argv)); 1036*0fca6ea1SDimitry Andric ret_val = result ? PyObject_IsTrue(result) : false; 1037*0fca6ea1SDimitry Andric Py_XDECREF(result); 1038*0fca6ea1SDimitry Andric SWIG_PYTHON_THREAD_END_BLOCK; 1039*0fca6ea1SDimitry Andric } 1040*0fca6ea1SDimitry Andric return ret_val; 1041*0fca6ea1SDimitry Andric} 1042*0fca6ea1SDimitry Andric 104306c3fb27SDimitry Andricstatic SBError LLDBSwigPythonCallLocateModuleCallback( 104406c3fb27SDimitry Andric void *callback_baton, const SBModuleSpec &module_spec_sb, 104506c3fb27SDimitry Andric SBFileSpec &module_file_spec_sb, SBFileSpec &symbol_file_spec_sb) { 104606c3fb27SDimitry Andric SWIG_Python_Thread_Block swig_thread_block; 104706c3fb27SDimitry Andric 104806c3fb27SDimitry Andric PyErr_Cleaner py_err_cleaner(true); 104906c3fb27SDimitry Andric PythonObject module_spec_arg = SWIGBridge::ToSWIGWrapper( 105006c3fb27SDimitry Andric std::make_unique<SBModuleSpec>(module_spec_sb)); 105106c3fb27SDimitry Andric PythonObject module_file_spec_arg = SWIGBridge::ToSWIGWrapper( 105206c3fb27SDimitry Andric std::make_unique<SBFileSpec>(module_file_spec_sb)); 105306c3fb27SDimitry Andric PythonObject symbol_file_spec_arg = SWIGBridge::ToSWIGWrapper( 105406c3fb27SDimitry Andric std::make_unique<SBFileSpec>(symbol_file_spec_sb)); 105506c3fb27SDimitry Andric 105606c3fb27SDimitry Andric PythonCallable callable = 105706c3fb27SDimitry Andric Retain<PythonCallable>(reinterpret_cast<PyObject *>(callback_baton)); 105806c3fb27SDimitry Andric if (!callable.IsValid()) { 105906c3fb27SDimitry Andric return SBError("The callback callable is not valid."); 106006c3fb27SDimitry Andric } 106106c3fb27SDimitry Andric 106206c3fb27SDimitry Andric PythonObject result = callable(module_spec_arg, module_file_spec_arg, 106306c3fb27SDimitry Andric symbol_file_spec_arg); 106406c3fb27SDimitry Andric 106506c3fb27SDimitry Andric if (!result.IsAllocated()) 106606c3fb27SDimitry Andric return SBError("No result."); 106706c3fb27SDimitry Andric lldb::SBError *sb_error_ptr = nullptr; 106806c3fb27SDimitry Andric if (SWIG_ConvertPtr(result.get(), (void **)&sb_error_ptr, 106906c3fb27SDimitry Andric SWIGTYPE_p_lldb__SBError, 0) == -1) { 107006c3fb27SDimitry Andric return SBError("Result is not SBError."); 107106c3fb27SDimitry Andric } 107206c3fb27SDimitry Andric 107306c3fb27SDimitry Andric if (sb_error_ptr->Success()) { 107406c3fb27SDimitry Andric lldb::SBFileSpec *sb_module_file_spec_ptr = nullptr; 107506c3fb27SDimitry Andric if (SWIG_ConvertPtr(module_file_spec_arg.get(), 107606c3fb27SDimitry Andric (void **)&sb_module_file_spec_ptr, 107706c3fb27SDimitry Andric SWIGTYPE_p_lldb__SBFileSpec, 0) == -1) 107806c3fb27SDimitry Andric return SBError("module_file_spec is not SBFileSpec."); 107906c3fb27SDimitry Andric 108006c3fb27SDimitry Andric lldb::SBFileSpec *sb_symbol_file_spec_ptr = nullptr; 108106c3fb27SDimitry Andric if (SWIG_ConvertPtr(symbol_file_spec_arg.get(), 108206c3fb27SDimitry Andric (void **)&sb_symbol_file_spec_ptr, 108306c3fb27SDimitry Andric SWIGTYPE_p_lldb__SBFileSpec, 0) == -1) 108406c3fb27SDimitry Andric return SBError("symbol_file_spec is not SBFileSpec."); 108506c3fb27SDimitry Andric 108606c3fb27SDimitry Andric module_file_spec_sb = *sb_module_file_spec_ptr; 108706c3fb27SDimitry Andric symbol_file_spec_sb = *sb_symbol_file_spec_ptr; 108806c3fb27SDimitry Andric } 108906c3fb27SDimitry Andric 109006c3fb27SDimitry Andric return *sb_error_ptr; 109106c3fb27SDimitry Andric} 1092130d950cSDimitry Andric%} 1093