16498aff2SJonas Devlieghere%header %{ 26498aff2SJonas Devlieghere 36498aff2SJonas Devliegheretemplate <typename T> 46498aff2SJonas DevliegherePyObject * 56498aff2SJonas DevlieghereSBTypeToSWIGWrapper (T* item); 66498aff2SJonas Devlieghere 76498aff2SJonas Devlieghereclass PyErr_Cleaner 86498aff2SJonas Devlieghere{ 96498aff2SJonas Devliegherepublic: 106498aff2SJonas Devlieghere PyErr_Cleaner(bool print=false) : 116498aff2SJonas Devlieghere m_print(print) 126498aff2SJonas Devlieghere { 136498aff2SJonas Devlieghere } 146498aff2SJonas Devlieghere 156498aff2SJonas Devlieghere ~PyErr_Cleaner() 166498aff2SJonas Devlieghere { 176498aff2SJonas Devlieghere if (PyErr_Occurred()) 186498aff2SJonas Devlieghere { 196498aff2SJonas Devlieghere if(m_print && !PyErr_ExceptionMatches(PyExc_SystemExit)) 206498aff2SJonas Devlieghere PyErr_Print(); 216498aff2SJonas Devlieghere PyErr_Clear(); 226498aff2SJonas Devlieghere } 236498aff2SJonas Devlieghere } 246498aff2SJonas Devlieghere 256498aff2SJonas Devlieghereprivate: 266498aff2SJonas Devlieghere bool m_print; 276498aff2SJonas Devlieghere}; 286498aff2SJonas Devlieghere 296498aff2SJonas Devlieghere%} 306498aff2SJonas Devlieghere 316498aff2SJonas Devlieghere%wrapper %{ 326498aff2SJonas Devlieghere 336498aff2SJonas Devlieghere// resolve a dotted Python name in the form 346498aff2SJonas Devlieghere// foo.bar.baz.Foobar to an actual Python object 356498aff2SJonas Devlieghere// if pmodule is NULL, the __main__ module will be used 366498aff2SJonas Devlieghere// as the starting point for the search 376498aff2SJonas Devlieghere 386498aff2SJonas Devlieghere 396498aff2SJonas Devlieghere// This function is called by lldb_private::ScriptInterpreterPython::BreakpointCallbackFunction(...) 406498aff2SJonas Devlieghere// and is used when a script command is attached to a breakpoint for execution. 416498aff2SJonas Devlieghere 426498aff2SJonas DevlieghereSWIGEXPORT llvm::Expected<bool> 436498aff2SJonas DevlieghereLLDBSwigPythonBreakpointCallbackFunction 446498aff2SJonas Devlieghere( 456498aff2SJonas Devlieghere const char *python_function_name, 466498aff2SJonas Devlieghere const char *session_dictionary_name, 476498aff2SJonas Devlieghere const lldb::StackFrameSP& frame_sp, 486498aff2SJonas Devlieghere const lldb::BreakpointLocationSP& bp_loc_sp, 496498aff2SJonas Devlieghere lldb_private::StructuredDataImpl *args_impl 506498aff2SJonas Devlieghere) 516498aff2SJonas Devlieghere{ 526498aff2SJonas Devlieghere using namespace llvm; 536498aff2SJonas Devlieghere 546498aff2SJonas Devlieghere lldb::SBFrame sb_frame (frame_sp); 556498aff2SJonas Devlieghere lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp); 566498aff2SJonas Devlieghere 576498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 586498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 596498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 606498aff2SJonas Devlieghere 616498aff2SJonas Devlieghere unsigned max_positional_args; 626498aff2SJonas Devlieghere if (auto arg_info = pfunc.GetArgInfo()) 636498aff2SJonas Devlieghere max_positional_args = arg_info.get().max_positional_args; 646498aff2SJonas Devlieghere else 656498aff2SJonas Devlieghere return arg_info.takeError(); 666498aff2SJonas Devlieghere 676498aff2SJonas Devlieghere PythonObject frame_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_frame)); 686498aff2SJonas Devlieghere PythonObject bp_loc_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_bp_loc)); 696498aff2SJonas Devlieghere 706498aff2SJonas Devlieghere auto result = [&] () -> Expected<PythonObject> { 716498aff2SJonas Devlieghere // If the called function doesn't take extra_args, drop them here: 726498aff2SJonas Devlieghere if (max_positional_args < 4) { 736498aff2SJonas Devlieghere return pfunc.Call(frame_arg, bp_loc_arg, dict); 746498aff2SJonas Devlieghere } else { 756498aff2SJonas Devlieghere lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl); 766498aff2SJonas Devlieghere PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value)); 776498aff2SJonas Devlieghere return pfunc.Call(frame_arg, bp_loc_arg, args_arg, dict); 786498aff2SJonas Devlieghere } 796498aff2SJonas Devlieghere } (); 806498aff2SJonas Devlieghere 816498aff2SJonas Devlieghere if (!result) 826498aff2SJonas Devlieghere return result.takeError(); 836498aff2SJonas Devlieghere 846498aff2SJonas Devlieghere // Only False counts as false! 856498aff2SJonas Devlieghere return result.get().get() != Py_False; 866498aff2SJonas Devlieghere} 876498aff2SJonas Devlieghere 886498aff2SJonas Devlieghere// This function is called by lldb_private::ScriptInterpreterPython::WatchpointCallbackFunction(...) 896498aff2SJonas Devlieghere// and is used when a script command is attached to a watchpoint for execution. 906498aff2SJonas Devlieghere 916498aff2SJonas DevlieghereSWIGEXPORT bool 926498aff2SJonas DevlieghereLLDBSwigPythonWatchpointCallbackFunction 936498aff2SJonas Devlieghere( 946498aff2SJonas Devlieghere const char *python_function_name, 956498aff2SJonas Devlieghere const char *session_dictionary_name, 966498aff2SJonas Devlieghere const lldb::StackFrameSP& frame_sp, 976498aff2SJonas Devlieghere const lldb::WatchpointSP& wp_sp 986498aff2SJonas Devlieghere) 996498aff2SJonas Devlieghere{ 1006498aff2SJonas Devlieghere lldb::SBFrame sb_frame (frame_sp); 1016498aff2SJonas Devlieghere lldb::SBWatchpoint sb_wp(wp_sp); 1026498aff2SJonas Devlieghere 1036498aff2SJonas Devlieghere bool stop_at_watchpoint = true; 1046498aff2SJonas Devlieghere 1056498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 1066498aff2SJonas Devlieghere 1076498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 1086498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 1096498aff2SJonas Devlieghere 1106498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 1116498aff2SJonas Devlieghere return stop_at_watchpoint; 1126498aff2SJonas Devlieghere 1136498aff2SJonas Devlieghere PythonObject frame_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_frame)); 1146498aff2SJonas Devlieghere PythonObject wp_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_wp)); 1156498aff2SJonas Devlieghere PythonObject result = pfunc(frame_arg, wp_arg, dict); 1166498aff2SJonas Devlieghere 1176498aff2SJonas Devlieghere if (result.get() == Py_False) 1186498aff2SJonas Devlieghere stop_at_watchpoint = false; 1196498aff2SJonas Devlieghere 1206498aff2SJonas Devlieghere return stop_at_watchpoint; 1216498aff2SJonas Devlieghere} 1226498aff2SJonas Devlieghere 1236498aff2SJonas DevlieghereSWIGEXPORT bool 1246498aff2SJonas DevlieghereLLDBSwigPythonCallTypeScript 1256498aff2SJonas Devlieghere( 1266498aff2SJonas Devlieghere const char *python_function_name, 1276498aff2SJonas Devlieghere const void *session_dictionary, 1286498aff2SJonas Devlieghere const lldb::ValueObjectSP& valobj_sp, 1296498aff2SJonas Devlieghere void** pyfunct_wrapper, 1306498aff2SJonas Devlieghere const lldb::TypeSummaryOptionsSP& options_sp, 1316498aff2SJonas Devlieghere std::string& retval 1326498aff2SJonas Devlieghere) 1336498aff2SJonas Devlieghere{ 1346498aff2SJonas Devlieghere lldb::SBValue sb_value (valobj_sp); 1356498aff2SJonas Devlieghere lldb::SBTypeSummaryOptions sb_options(options_sp.get()); 1366498aff2SJonas Devlieghere 1376498aff2SJonas Devlieghere retval.clear(); 1386498aff2SJonas Devlieghere 1396498aff2SJonas Devlieghere if (!python_function_name || !session_dictionary) 1406498aff2SJonas Devlieghere return false; 1416498aff2SJonas Devlieghere 1426498aff2SJonas Devlieghere PyObject *pfunc_impl = nullptr; 1436498aff2SJonas Devlieghere 1446498aff2SJonas Devlieghere if (pyfunct_wrapper && *pyfunct_wrapper && PyFunction_Check (*pyfunct_wrapper)) 1456498aff2SJonas Devlieghere { 1466498aff2SJonas Devlieghere pfunc_impl = (PyObject*)(*pyfunct_wrapper); 1476498aff2SJonas Devlieghere if (pfunc_impl->ob_refcnt == 1) 1486498aff2SJonas Devlieghere { 1496498aff2SJonas Devlieghere Py_XDECREF(pfunc_impl); 1506498aff2SJonas Devlieghere pfunc_impl = NULL; 1516498aff2SJonas Devlieghere } 1526498aff2SJonas Devlieghere } 1536498aff2SJonas Devlieghere 1546498aff2SJonas Devlieghere PyObject *py_dict = (PyObject*)session_dictionary; 1556498aff2SJonas Devlieghere if (!PythonDictionary::Check(py_dict)) 1566498aff2SJonas Devlieghere return true; 1576498aff2SJonas Devlieghere 1586498aff2SJonas Devlieghere PythonDictionary dict(PyRefType::Borrowed, py_dict); 1596498aff2SJonas Devlieghere 1606498aff2SJonas Devlieghere PyErr_Cleaner pyerr_cleanup(true); // show Python errors 1616498aff2SJonas Devlieghere 1626498aff2SJonas Devlieghere PythonCallable pfunc(PyRefType::Borrowed, pfunc_impl); 1636498aff2SJonas Devlieghere 1646498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 1656498aff2SJonas Devlieghere { 1666498aff2SJonas Devlieghere pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 1676498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 1686498aff2SJonas Devlieghere return false; 1696498aff2SJonas Devlieghere 1706498aff2SJonas Devlieghere if (pyfunct_wrapper) 1716498aff2SJonas Devlieghere { 1726498aff2SJonas Devlieghere *pyfunct_wrapper = pfunc.get(); 1736498aff2SJonas Devlieghere Py_XINCREF(pfunc.get()); 1746498aff2SJonas Devlieghere } 1756498aff2SJonas Devlieghere } 1766498aff2SJonas Devlieghere 1776498aff2SJonas Devlieghere PythonObject result; 1786498aff2SJonas Devlieghere auto argc = pfunc.GetArgInfo(); 1796498aff2SJonas Devlieghere if (!argc) { 1806498aff2SJonas Devlieghere llvm::consumeError(argc.takeError()); 1816498aff2SJonas Devlieghere return false; 1826498aff2SJonas Devlieghere } 1836498aff2SJonas Devlieghere 1846498aff2SJonas Devlieghere PythonObject value_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_value)); 1856498aff2SJonas Devlieghere PythonObject options_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_options)); 1866498aff2SJonas Devlieghere 1876498aff2SJonas Devlieghere if (argc.get().max_positional_args < 3) 1886498aff2SJonas Devlieghere result = pfunc(value_arg,dict); 1896498aff2SJonas Devlieghere else 1906498aff2SJonas Devlieghere result = pfunc(value_arg,dict,options_arg); 1916498aff2SJonas Devlieghere 1926498aff2SJonas Devlieghere retval = result.Str().GetString().str(); 1936498aff2SJonas Devlieghere 1946498aff2SJonas Devlieghere return true; 1956498aff2SJonas Devlieghere} 1966498aff2SJonas Devlieghere 1976498aff2SJonas DevlieghereSWIGEXPORT void* 1986498aff2SJonas DevlieghereLLDBSwigPythonCreateSyntheticProvider 1996498aff2SJonas Devlieghere( 2006498aff2SJonas Devlieghere const char *python_class_name, 2016498aff2SJonas Devlieghere const char *session_dictionary_name, 2026498aff2SJonas Devlieghere const lldb::ValueObjectSP& valobj_sp 2036498aff2SJonas Devlieghere) 2046498aff2SJonas Devlieghere{ 2056498aff2SJonas Devlieghere if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name) 2066498aff2SJonas Devlieghere Py_RETURN_NONE; 2076498aff2SJonas Devlieghere 2086498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 2096498aff2SJonas Devlieghere 2106498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 2116498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name,dict); 2126498aff2SJonas Devlieghere 2136498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 2146498aff2SJonas Devlieghere Py_RETURN_NONE; 2156498aff2SJonas Devlieghere 2166498aff2SJonas Devlieghere // I do not want the SBValue to be deallocated when going out of scope because python 2176498aff2SJonas Devlieghere // has ownership of it and will manage memory for this object by itself 2186498aff2SJonas Devlieghere lldb::SBValue *sb_value = new lldb::SBValue(valobj_sp); 2196498aff2SJonas Devlieghere sb_value->SetPreferSyntheticValue(false); 2206498aff2SJonas Devlieghere 2216498aff2SJonas Devlieghere PythonObject val_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_value)); 2226498aff2SJonas Devlieghere if (!val_arg.IsAllocated()) 2236498aff2SJonas Devlieghere Py_RETURN_NONE; 2246498aff2SJonas Devlieghere 2256498aff2SJonas Devlieghere PythonObject result = pfunc(val_arg, dict); 2266498aff2SJonas Devlieghere 2276498aff2SJonas Devlieghere if (result.IsAllocated()) 2286498aff2SJonas Devlieghere return result.release(); 2296498aff2SJonas Devlieghere 2306498aff2SJonas Devlieghere Py_RETURN_NONE; 2316498aff2SJonas Devlieghere} 2326498aff2SJonas Devlieghere 2336498aff2SJonas DevlieghereSWIGEXPORT void* 2346498aff2SJonas DevlieghereLLDBSwigPythonCreateCommandObject 2356498aff2SJonas Devlieghere( 2366498aff2SJonas Devlieghere const char *python_class_name, 2376498aff2SJonas Devlieghere const char *session_dictionary_name, 2386498aff2SJonas Devlieghere const lldb::DebuggerSP debugger_sp 2396498aff2SJonas Devlieghere) 2406498aff2SJonas Devlieghere{ 2416498aff2SJonas Devlieghere if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name) 2426498aff2SJonas Devlieghere Py_RETURN_NONE; 2436498aff2SJonas Devlieghere 2446498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 2456498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 2466498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict); 2476498aff2SJonas Devlieghere 2486498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 2496498aff2SJonas Devlieghere return nullptr; 2506498aff2SJonas Devlieghere 2516498aff2SJonas Devlieghere lldb::SBDebugger debugger_sb(debugger_sp); 2526498aff2SJonas Devlieghere PythonObject debugger_arg(PyRefType::Owned, SBTypeToSWIGWrapper(debugger_sb)); 2536498aff2SJonas Devlieghere PythonObject result = pfunc(debugger_arg, dict); 2546498aff2SJonas Devlieghere 2556498aff2SJonas Devlieghere if (result.IsAllocated()) 2566498aff2SJonas Devlieghere return result.release(); 2576498aff2SJonas Devlieghere 2586498aff2SJonas Devlieghere Py_RETURN_NONE; 2596498aff2SJonas Devlieghere} 2606498aff2SJonas Devlieghere 2616498aff2SJonas DevlieghereSWIGEXPORT void* 2626498aff2SJonas DevlieghereLLDBSwigPythonCreateScriptedThreadPlan 2636498aff2SJonas Devlieghere( 2646498aff2SJonas Devlieghere const char *python_class_name, 2656498aff2SJonas Devlieghere const char *session_dictionary_name, 2666498aff2SJonas Devlieghere lldb_private::StructuredDataImpl *args_impl, 2676498aff2SJonas Devlieghere std::string &error_string, 2686498aff2SJonas Devlieghere const lldb::ThreadPlanSP& thread_plan_sp 2696498aff2SJonas Devlieghere) 2706498aff2SJonas Devlieghere{ 2716498aff2SJonas Devlieghere if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name) 2726498aff2SJonas Devlieghere Py_RETURN_NONE; 2736498aff2SJonas Devlieghere 2746498aff2SJonas Devlieghere // I do not want the SBThreadPlan to be deallocated when going out of scope because python 2756498aff2SJonas Devlieghere // has ownership of it and will manage memory for this object by itself 2766498aff2SJonas Devlieghere lldb::SBThreadPlan *tp_value = new lldb::SBThreadPlan(thread_plan_sp); 2776498aff2SJonas Devlieghere 2786498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 2796498aff2SJonas Devlieghere 2806498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 2816498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict); 2826498aff2SJonas Devlieghere 2836498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) { 2846498aff2SJonas Devlieghere error_string.append("could not find script class: "); 2856498aff2SJonas Devlieghere error_string.append(python_class_name); 2866498aff2SJonas Devlieghere return nullptr; 2876498aff2SJonas Devlieghere } 2886498aff2SJonas Devlieghere 2896498aff2SJonas Devlieghere PythonObject tp_arg(PyRefType::Owned, SBTypeToSWIGWrapper(tp_value)); 2906498aff2SJonas Devlieghere 2916498aff2SJonas Devlieghere if (!tp_arg.IsAllocated()) 2926498aff2SJonas Devlieghere Py_RETURN_NONE; 2936498aff2SJonas Devlieghere 2946498aff2SJonas Devlieghere llvm::Expected<PythonCallable::ArgInfo> arg_info = pfunc.GetArgInfo(); 2956498aff2SJonas Devlieghere if (!arg_info) { 2966498aff2SJonas Devlieghere llvm::handleAllErrors( 2976498aff2SJonas Devlieghere arg_info.takeError(), 2986498aff2SJonas Devlieghere [&](PythonException &E) { 2996498aff2SJonas Devlieghere error_string.append(E.ReadBacktrace()); 3006498aff2SJonas Devlieghere }, 3016498aff2SJonas Devlieghere [&](const llvm::ErrorInfoBase &E) { 3026498aff2SJonas Devlieghere error_string.append(E.message()); 3036498aff2SJonas Devlieghere }); 3046498aff2SJonas Devlieghere Py_RETURN_NONE; 3056498aff2SJonas Devlieghere } 3066498aff2SJonas Devlieghere 3076498aff2SJonas Devlieghere PythonObject result = {}; 3086498aff2SJonas Devlieghere if (arg_info.get().max_positional_args == 2) { 3096498aff2SJonas Devlieghere if (args_impl != nullptr) { 3106498aff2SJonas Devlieghere error_string.assign("args passed, but __init__ does not take an args dictionary"); 3116498aff2SJonas Devlieghere Py_RETURN_NONE; 3126498aff2SJonas Devlieghere } 3136498aff2SJonas Devlieghere result = pfunc(tp_arg, dict); 3146498aff2SJonas Devlieghere } else if (arg_info.get().max_positional_args >= 3) { 3156498aff2SJonas Devlieghere lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl); 3166498aff2SJonas Devlieghere PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value)); 3176498aff2SJonas Devlieghere result = pfunc(tp_arg, args_arg, dict); 3186498aff2SJonas Devlieghere } else { 3196498aff2SJonas Devlieghere error_string.assign("wrong number of arguments in __init__, should be 2 or 3 (not including self)"); 3206498aff2SJonas Devlieghere Py_RETURN_NONE; 3216498aff2SJonas Devlieghere } 3226498aff2SJonas Devlieghere 3236498aff2SJonas Devlieghere // FIXME: At this point we should check that the class we found supports all the methods 3246498aff2SJonas Devlieghere // that we need. 3256498aff2SJonas Devlieghere 3266498aff2SJonas Devlieghere if (result.IsAllocated()) 3276498aff2SJonas Devlieghere return result.release(); 3286498aff2SJonas Devlieghere Py_RETURN_NONE; 3296498aff2SJonas Devlieghere} 3306498aff2SJonas Devlieghere 3316498aff2SJonas DevlieghereSWIGEXPORT bool 3326498aff2SJonas DevlieghereLLDBSWIGPythonCallThreadPlan 3336498aff2SJonas Devlieghere( 3346498aff2SJonas Devlieghere void *implementor, 3356498aff2SJonas Devlieghere const char *method_name, 3366498aff2SJonas Devlieghere lldb_private::Event *event, 3376498aff2SJonas Devlieghere bool &got_error 3386498aff2SJonas Devlieghere) 3396498aff2SJonas Devlieghere{ 3406498aff2SJonas Devlieghere got_error = false; 3416498aff2SJonas Devlieghere 3426498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(false); 3436498aff2SJonas Devlieghere PythonObject self(PyRefType::Borrowed, static_cast<PyObject*>(implementor)); 3446498aff2SJonas Devlieghere auto pfunc = self.ResolveName<PythonCallable>(method_name); 3456498aff2SJonas Devlieghere 3466498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 3476498aff2SJonas Devlieghere return false; 3486498aff2SJonas Devlieghere 3496498aff2SJonas Devlieghere PythonObject result; 3506498aff2SJonas Devlieghere if (event != nullptr) 3516498aff2SJonas Devlieghere { 3526498aff2SJonas Devlieghere lldb::SBEvent sb_event(event); 3536498aff2SJonas Devlieghere PythonObject event_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_event)); 3546498aff2SJonas Devlieghere result = pfunc(event_arg); 3556498aff2SJonas Devlieghere } 3566498aff2SJonas Devlieghere else 3576498aff2SJonas Devlieghere result = pfunc(); 3586498aff2SJonas Devlieghere 3596498aff2SJonas Devlieghere if (PyErr_Occurred()) 3606498aff2SJonas Devlieghere { 3616498aff2SJonas Devlieghere got_error = true; 3626498aff2SJonas Devlieghere printf ("Return value was neither false nor true for call to %s.\n", method_name); 3636498aff2SJonas Devlieghere PyErr_Print(); 3646498aff2SJonas Devlieghere return false; 3656498aff2SJonas Devlieghere } 3666498aff2SJonas Devlieghere 3676498aff2SJonas Devlieghere if (result.get() == Py_True) 3686498aff2SJonas Devlieghere return true; 3696498aff2SJonas Devlieghere else if (result.get() == Py_False) 3706498aff2SJonas Devlieghere return false; 3716498aff2SJonas Devlieghere 3726498aff2SJonas Devlieghere // Somebody returned the wrong thing... 3736498aff2SJonas Devlieghere got_error = true; 3746498aff2SJonas Devlieghere printf ("Wrong return value type for call to %s.\n", method_name); 3756498aff2SJonas Devlieghere return false; 3766498aff2SJonas Devlieghere} 3776498aff2SJonas Devlieghere 3786498aff2SJonas DevlieghereSWIGEXPORT void * 3796498aff2SJonas DevlieghereLLDBSwigPythonCreateScriptedBreakpointResolver 3806498aff2SJonas Devlieghere( 3816498aff2SJonas Devlieghere const char *python_class_name, 3826498aff2SJonas Devlieghere const char *session_dictionary_name, 3836498aff2SJonas Devlieghere lldb_private::StructuredDataImpl *args_impl, 3846498aff2SJonas Devlieghere lldb::BreakpointSP &breakpoint_sp 3856498aff2SJonas Devlieghere) 3866498aff2SJonas Devlieghere{ 3876498aff2SJonas Devlieghere if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name) 3886498aff2SJonas Devlieghere Py_RETURN_NONE; 3896498aff2SJonas Devlieghere 3906498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 3916498aff2SJonas Devlieghere 3926498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 3936498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict); 3946498aff2SJonas Devlieghere 3956498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 3966498aff2SJonas Devlieghere return nullptr; 3976498aff2SJonas Devlieghere 3986498aff2SJonas Devlieghere lldb::SBBreakpoint *bkpt_value = new lldb::SBBreakpoint(breakpoint_sp); 3996498aff2SJonas Devlieghere 4006498aff2SJonas Devlieghere PythonObject bkpt_arg(PyRefType::Owned, SBTypeToSWIGWrapper(bkpt_value)); 4016498aff2SJonas Devlieghere 4026498aff2SJonas Devlieghere lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl); 4036498aff2SJonas Devlieghere PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value)); 4046498aff2SJonas Devlieghere 4056498aff2SJonas Devlieghere PythonObject result = pfunc(bkpt_arg, args_arg, dict); 4066498aff2SJonas Devlieghere // FIXME: At this point we should check that the class we found supports all the methods 4076498aff2SJonas Devlieghere // that we need. 4086498aff2SJonas Devlieghere 4096498aff2SJonas Devlieghere if (result.IsAllocated()) 4106498aff2SJonas Devlieghere { 4116498aff2SJonas Devlieghere // Check that __callback__ is defined: 4126498aff2SJonas Devlieghere auto callback_func = result.ResolveName<PythonCallable>("__callback__"); 4136498aff2SJonas Devlieghere if (callback_func.IsAllocated()) 4146498aff2SJonas Devlieghere return result.release(); 4156498aff2SJonas Devlieghere else 4166498aff2SJonas Devlieghere result.release(); 4176498aff2SJonas Devlieghere } 4186498aff2SJonas Devlieghere Py_RETURN_NONE; 4196498aff2SJonas Devlieghere} 4206498aff2SJonas Devlieghere 4216498aff2SJonas DevlieghereSWIGEXPORT unsigned int 4226498aff2SJonas DevlieghereLLDBSwigPythonCallBreakpointResolver 4236498aff2SJonas Devlieghere( 4246498aff2SJonas Devlieghere void *implementor, 4256498aff2SJonas Devlieghere const char *method_name, 4266498aff2SJonas Devlieghere lldb_private::SymbolContext *sym_ctx 4276498aff2SJonas Devlieghere) 4286498aff2SJonas Devlieghere{ 4296498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(false); 4306498aff2SJonas Devlieghere PythonObject self(PyRefType::Borrowed, static_cast<PyObject*>(implementor)); 4316498aff2SJonas Devlieghere auto pfunc = self.ResolveName<PythonCallable>(method_name); 4326498aff2SJonas Devlieghere 4336498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 4346498aff2SJonas Devlieghere return 0; 4356498aff2SJonas Devlieghere 4366498aff2SJonas Devlieghere PythonObject result; 4376498aff2SJonas Devlieghere if (sym_ctx != nullptr) { 4386498aff2SJonas Devlieghere lldb::SBSymbolContext sb_sym_ctx(sym_ctx); 4396498aff2SJonas Devlieghere PythonObject sym_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_sym_ctx)); 4406498aff2SJonas Devlieghere result = pfunc(sym_ctx_arg); 4416498aff2SJonas Devlieghere } else 4426498aff2SJonas Devlieghere result = pfunc(); 4436498aff2SJonas Devlieghere 4446498aff2SJonas Devlieghere if (PyErr_Occurred()) 4456498aff2SJonas Devlieghere { 4466498aff2SJonas Devlieghere PyErr_Print(); 4476498aff2SJonas Devlieghere return 0; 4486498aff2SJonas Devlieghere } 4496498aff2SJonas Devlieghere 4506498aff2SJonas Devlieghere // The callback will return a bool, but we're need to also return ints 4516498aff2SJonas Devlieghere // so we're squirrelling the bool through as an int... And if you return 4526498aff2SJonas Devlieghere // nothing, we'll continue. 4536498aff2SJonas Devlieghere if (strcmp(method_name, "__callback__") == 0) { 4546498aff2SJonas Devlieghere if (result.get() == Py_False) 4556498aff2SJonas Devlieghere return 0; 4566498aff2SJonas Devlieghere else 4576498aff2SJonas Devlieghere return 1; 4586498aff2SJonas Devlieghere } 4596498aff2SJonas Devlieghere 460*478619cfSMuhammad Omair Javaid PythonInteger int_result = result.AsType<PythonInteger>(); 461*478619cfSMuhammad Omair Javaid if (!int_result.IsAllocated()) 46273752121SLawrence D'Anna return 0; 463*478619cfSMuhammad Omair Javaid 464*478619cfSMuhammad Omair Javaid unsigned int ret_val = int_result.GetInteger(); 4656498aff2SJonas Devlieghere 4666498aff2SJonas Devlieghere return ret_val; 4676498aff2SJonas Devlieghere} 4686498aff2SJonas Devlieghere 4696498aff2SJonas Devlieghere// wrapper that calls an optional instance member of an object taking no arguments 4706498aff2SJonas Devliegherestatic PyObject* 4716498aff2SJonas DevlieghereLLDBSwigPython_CallOptionalMember 4726498aff2SJonas Devlieghere( 4736498aff2SJonas Devlieghere PyObject* implementor, 4746498aff2SJonas Devlieghere char* callee_name, 4756498aff2SJonas Devlieghere PyObject* ret_if_not_found = Py_None, 4766498aff2SJonas Devlieghere bool* was_found = NULL 4776498aff2SJonas Devlieghere) 4786498aff2SJonas Devlieghere{ 4796498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(false); 4806498aff2SJonas Devlieghere 4816498aff2SJonas Devlieghere PythonObject self(PyRefType::Borrowed, static_cast<PyObject*>(implementor)); 4826498aff2SJonas Devlieghere auto pfunc = self.ResolveName<PythonCallable>(callee_name); 4836498aff2SJonas Devlieghere 4846498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 4856498aff2SJonas Devlieghere { 4866498aff2SJonas Devlieghere if (was_found) 4876498aff2SJonas Devlieghere *was_found = false; 4886498aff2SJonas Devlieghere Py_XINCREF(ret_if_not_found); 4896498aff2SJonas Devlieghere return ret_if_not_found; 4906498aff2SJonas Devlieghere } 4916498aff2SJonas Devlieghere 4926498aff2SJonas Devlieghere if (was_found) 4936498aff2SJonas Devlieghere *was_found = true; 4946498aff2SJonas Devlieghere 4956498aff2SJonas Devlieghere PythonObject result = pfunc(); 4966498aff2SJonas Devlieghere return result.release(); 4976498aff2SJonas Devlieghere} 4986498aff2SJonas Devlieghere 4996498aff2SJonas DevlieghereSWIGEXPORT size_t 5006498aff2SJonas DevlieghereLLDBSwigPython_CalculateNumChildren 5016498aff2SJonas Devlieghere( 5026498aff2SJonas Devlieghere PyObject *implementor, 5036498aff2SJonas Devlieghere uint32_t max 5046498aff2SJonas Devlieghere) 5056498aff2SJonas Devlieghere{ 5066498aff2SJonas Devlieghere PythonObject self(PyRefType::Borrowed, implementor); 5076498aff2SJonas Devlieghere auto pfunc = self.ResolveName<PythonCallable>("num_children"); 5086498aff2SJonas Devlieghere 5096498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 5106498aff2SJonas Devlieghere return 0; 5116498aff2SJonas Devlieghere 5126498aff2SJonas Devlieghere auto arg_info = pfunc.GetArgInfo(); 5136498aff2SJonas Devlieghere if (!arg_info) { 5146498aff2SJonas Devlieghere llvm::consumeError(arg_info.takeError()); 5156498aff2SJonas Devlieghere return 0; 5166498aff2SJonas Devlieghere } 5176498aff2SJonas Devlieghere 518*478619cfSMuhammad Omair Javaid PythonObject result; 5196498aff2SJonas Devlieghere 520*478619cfSMuhammad Omair Javaid if (arg_info.get().max_positional_args < 1) 521*478619cfSMuhammad Omair Javaid result = pfunc(); 522*478619cfSMuhammad Omair Javaid else 523*478619cfSMuhammad Omair Javaid result = pfunc(PythonInteger(max)); 524*478619cfSMuhammad Omair Javaid 525*478619cfSMuhammad Omair Javaid if (!result.IsAllocated()) 526*478619cfSMuhammad Omair Javaid return 0; 527*478619cfSMuhammad Omair Javaid 528*478619cfSMuhammad Omair Javaid PythonInteger int_result = result.AsType<PythonInteger>(); 529*478619cfSMuhammad Omair Javaid if (!int_result.IsAllocated()) 530*478619cfSMuhammad Omair Javaid return 0; 531*478619cfSMuhammad Omair Javaid 532*478619cfSMuhammad Omair Javaid size_t ret_val = int_result.GetInteger(); 533*478619cfSMuhammad Omair Javaid 534*478619cfSMuhammad Omair Javaid if (PyErr_Occurred()) //FIXME use Expected to catch python exceptions 5356498aff2SJonas Devlieghere { 5366498aff2SJonas Devlieghere PyErr_Print(); 5376498aff2SJonas Devlieghere PyErr_Clear(); 5386498aff2SJonas Devlieghere } 5396498aff2SJonas Devlieghere 5406498aff2SJonas Devlieghere if (arg_info.get().max_positional_args < 1) 5416498aff2SJonas Devlieghere ret_val = std::min(ret_val, static_cast<size_t>(max)); 5426498aff2SJonas Devlieghere 5436498aff2SJonas Devlieghere return ret_val; 5446498aff2SJonas Devlieghere} 5456498aff2SJonas Devlieghere 5466498aff2SJonas DevlieghereSWIGEXPORT PyObject* 5476498aff2SJonas DevlieghereLLDBSwigPython_GetChildAtIndex 5486498aff2SJonas Devlieghere( 5496498aff2SJonas Devlieghere PyObject *implementor, 5506498aff2SJonas Devlieghere uint32_t idx 5516498aff2SJonas Devlieghere) 5526498aff2SJonas Devlieghere{ 5536498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 5546498aff2SJonas Devlieghere 5556498aff2SJonas Devlieghere PythonObject self(PyRefType::Borrowed, implementor); 5566498aff2SJonas Devlieghere auto pfunc = self.ResolveName<PythonCallable>("get_child_at_index"); 5576498aff2SJonas Devlieghere 5586498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 5596498aff2SJonas Devlieghere return nullptr; 5606498aff2SJonas Devlieghere 5616498aff2SJonas Devlieghere PythonObject result = pfunc(PythonInteger(idx)); 5626498aff2SJonas Devlieghere 5636498aff2SJonas Devlieghere if (!result.IsAllocated()) 5646498aff2SJonas Devlieghere return nullptr; 5656498aff2SJonas Devlieghere 5666498aff2SJonas Devlieghere lldb::SBValue* sbvalue_ptr = nullptr; 5676498aff2SJonas Devlieghere if (SWIG_ConvertPtr(result.get(), (void**)&sbvalue_ptr, SWIGTYPE_p_lldb__SBValue, 0) == -1) 5686498aff2SJonas Devlieghere return nullptr; 5696498aff2SJonas Devlieghere 5706498aff2SJonas Devlieghere if (sbvalue_ptr == nullptr) 5716498aff2SJonas Devlieghere return nullptr; 5726498aff2SJonas Devlieghere 5736498aff2SJonas Devlieghere return result.release(); 5746498aff2SJonas Devlieghere} 5756498aff2SJonas Devlieghere 5766498aff2SJonas DevlieghereSWIGEXPORT int 5776498aff2SJonas DevlieghereLLDBSwigPython_GetIndexOfChildWithName 5786498aff2SJonas Devlieghere( 5796498aff2SJonas Devlieghere PyObject *implementor, 5806498aff2SJonas Devlieghere const char* child_name 5816498aff2SJonas Devlieghere) 5826498aff2SJonas Devlieghere{ 5836498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 5846498aff2SJonas Devlieghere 5856498aff2SJonas Devlieghere PythonObject self(PyRefType::Borrowed, implementor); 5866498aff2SJonas Devlieghere auto pfunc = self.ResolveName<PythonCallable>("get_child_index"); 5876498aff2SJonas Devlieghere 5886498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 5896498aff2SJonas Devlieghere return UINT32_MAX; 5906498aff2SJonas Devlieghere 591*478619cfSMuhammad Omair Javaid PythonObject result = pfunc(PythonString(child_name)); 5926498aff2SJonas Devlieghere 593*478619cfSMuhammad Omair Javaid if (!result.IsAllocated()) 5946498aff2SJonas Devlieghere return UINT32_MAX; 5956498aff2SJonas Devlieghere 596*478619cfSMuhammad Omair Javaid PythonInteger int_result = result.AsType<PythonInteger>(); 597*478619cfSMuhammad Omair Javaid if (!int_result.IsAllocated()) 598*478619cfSMuhammad Omair Javaid return UINT32_MAX; 599*478619cfSMuhammad Omair Javaid 600*478619cfSMuhammad Omair Javaid int64_t retval = int_result.GetInteger(); 6016498aff2SJonas Devlieghere if (retval >= 0) 6026498aff2SJonas Devlieghere return (uint32_t)retval; 6036498aff2SJonas Devlieghere 6046498aff2SJonas Devlieghere return UINT32_MAX; 6056498aff2SJonas Devlieghere} 6066498aff2SJonas Devlieghere 6076498aff2SJonas DevlieghereSWIGEXPORT bool 6086498aff2SJonas DevlieghereLLDBSwigPython_UpdateSynthProviderInstance 6096498aff2SJonas Devlieghere( 6106498aff2SJonas Devlieghere PyObject *implementor 6116498aff2SJonas Devlieghere) 6126498aff2SJonas Devlieghere{ 6136498aff2SJonas Devlieghere bool ret_val = false; 6146498aff2SJonas Devlieghere 6156498aff2SJonas Devlieghere static char callee_name[] = "update"; 6166498aff2SJonas Devlieghere 6176498aff2SJonas Devlieghere PyObject* py_return = LLDBSwigPython_CallOptionalMember(implementor,callee_name); 6186498aff2SJonas Devlieghere 6196498aff2SJonas Devlieghere if (py_return == Py_True) 6206498aff2SJonas Devlieghere ret_val = true; 6216498aff2SJonas Devlieghere 6226498aff2SJonas Devlieghere Py_XDECREF(py_return); 6236498aff2SJonas Devlieghere 6246498aff2SJonas Devlieghere return ret_val; 6256498aff2SJonas Devlieghere} 6266498aff2SJonas Devlieghere 6276498aff2SJonas DevlieghereSWIGEXPORT bool 6286498aff2SJonas DevlieghereLLDBSwigPython_MightHaveChildrenSynthProviderInstance 6296498aff2SJonas Devlieghere( 6306498aff2SJonas Devlieghere PyObject *implementor 6316498aff2SJonas Devlieghere) 6326498aff2SJonas Devlieghere{ 6336498aff2SJonas Devlieghere bool ret_val = false; 6346498aff2SJonas Devlieghere 6356498aff2SJonas Devlieghere static char callee_name[] = "has_children"; 6366498aff2SJonas Devlieghere 6376498aff2SJonas Devlieghere PyObject* py_return = LLDBSwigPython_CallOptionalMember(implementor,callee_name, Py_True); 6386498aff2SJonas Devlieghere 6396498aff2SJonas Devlieghere if (py_return == Py_True) 6406498aff2SJonas Devlieghere ret_val = true; 6416498aff2SJonas Devlieghere 6426498aff2SJonas Devlieghere Py_XDECREF(py_return); 6436498aff2SJonas Devlieghere 6446498aff2SJonas Devlieghere return ret_val; 6456498aff2SJonas Devlieghere} 6466498aff2SJonas Devlieghere 6476498aff2SJonas DevlieghereSWIGEXPORT PyObject* 6486498aff2SJonas DevlieghereLLDBSwigPython_GetValueSynthProviderInstance 6496498aff2SJonas Devlieghere( 6506498aff2SJonas Devlieghere PyObject *implementor 6516498aff2SJonas Devlieghere) 6526498aff2SJonas Devlieghere{ 6536498aff2SJonas Devlieghere PyObject* ret_val = nullptr; 6546498aff2SJonas Devlieghere 6556498aff2SJonas Devlieghere static char callee_name[] = "get_value"; 6566498aff2SJonas Devlieghere 6576498aff2SJonas Devlieghere PyObject* py_return = LLDBSwigPython_CallOptionalMember(implementor,callee_name, Py_None); 6586498aff2SJonas Devlieghere 6596498aff2SJonas Devlieghere if (py_return == Py_None || py_return == nullptr) 6606498aff2SJonas Devlieghere ret_val = nullptr; 6616498aff2SJonas Devlieghere 6626498aff2SJonas Devlieghere lldb::SBValue* sbvalue_ptr = NULL; 6636498aff2SJonas Devlieghere 6646498aff2SJonas Devlieghere if (SWIG_ConvertPtr(py_return, (void**)&sbvalue_ptr, SWIGTYPE_p_lldb__SBValue, 0) == -1) 6656498aff2SJonas Devlieghere ret_val = nullptr; 6666498aff2SJonas Devlieghere else if (sbvalue_ptr == NULL) 6676498aff2SJonas Devlieghere ret_val = nullptr; 6686498aff2SJonas Devlieghere else 6696498aff2SJonas Devlieghere ret_val = py_return; 6706498aff2SJonas Devlieghere 6716498aff2SJonas Devlieghere Py_XDECREF(py_return); 6726498aff2SJonas Devlieghere return ret_val; 6736498aff2SJonas Devlieghere} 6746498aff2SJonas Devlieghere 6756498aff2SJonas DevlieghereSWIGEXPORT void* 6766498aff2SJonas DevlieghereLLDBSWIGPython_CastPyObjectToSBValue 6776498aff2SJonas Devlieghere( 6786498aff2SJonas Devlieghere PyObject* data 6796498aff2SJonas Devlieghere) 6806498aff2SJonas Devlieghere{ 6816498aff2SJonas Devlieghere lldb::SBValue* sb_ptr = NULL; 6826498aff2SJonas Devlieghere 6836498aff2SJonas Devlieghere int valid_cast = SWIG_ConvertPtr(data, (void**)&sb_ptr, SWIGTYPE_p_lldb__SBValue, 0); 6846498aff2SJonas Devlieghere 6856498aff2SJonas Devlieghere if (valid_cast == -1) 6866498aff2SJonas Devlieghere return NULL; 6876498aff2SJonas Devlieghere 6886498aff2SJonas Devlieghere return sb_ptr; 6896498aff2SJonas Devlieghere} 6906498aff2SJonas Devlieghere 6916498aff2SJonas DevlieghereSWIGEXPORT bool 6926498aff2SJonas DevlieghereLLDBSwigPythonCallCommand 6936498aff2SJonas Devlieghere( 6946498aff2SJonas Devlieghere const char *python_function_name, 6956498aff2SJonas Devlieghere const char *session_dictionary_name, 6966498aff2SJonas Devlieghere lldb::DebuggerSP& debugger, 6976498aff2SJonas Devlieghere const char* args, 6986498aff2SJonas Devlieghere lldb_private::CommandReturnObject& cmd_retobj, 6996498aff2SJonas Devlieghere lldb::ExecutionContextRefSP exe_ctx_ref_sp 7006498aff2SJonas Devlieghere) 7016498aff2SJonas Devlieghere{ 7026498aff2SJonas Devlieghere lldb::SBCommandReturnObject cmd_retobj_sb(cmd_retobj); 7036498aff2SJonas Devlieghere lldb::SBDebugger debugger_sb(debugger); 7046498aff2SJonas Devlieghere lldb::SBExecutionContext exe_ctx_sb(exe_ctx_ref_sp); 7056498aff2SJonas Devlieghere 7066498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 7076498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 7086498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 7096498aff2SJonas Devlieghere 7106498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 7116498aff2SJonas Devlieghere return false; 7126498aff2SJonas Devlieghere 7136498aff2SJonas Devlieghere // pass the pointer-to cmd_retobj_sb or watch the underlying object disappear from under you 7146498aff2SJonas Devlieghere // see comment above for SBCommandReturnObjectReleaser for further details 7156498aff2SJonas Devlieghere auto argc = pfunc.GetArgInfo(); 7166498aff2SJonas Devlieghere if (!argc) { 7176498aff2SJonas Devlieghere llvm::consumeError(argc.takeError()); 7186498aff2SJonas Devlieghere return false; 7196498aff2SJonas Devlieghere } 7206498aff2SJonas Devlieghere PythonObject debugger_arg(PyRefType::Owned, SBTypeToSWIGWrapper(debugger_sb)); 7216498aff2SJonas Devlieghere PythonObject exe_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(exe_ctx_sb)); 7226498aff2SJonas Devlieghere PythonObject cmd_retobj_arg(PyRefType::Owned, SBTypeToSWIGWrapper(&cmd_retobj_sb)); 7236498aff2SJonas Devlieghere 7246498aff2SJonas Devlieghere if (argc.get().max_positional_args < 5u) 7256498aff2SJonas Devlieghere pfunc(debugger_arg, PythonString(args), cmd_retobj_arg, dict); 7266498aff2SJonas Devlieghere else 7276498aff2SJonas Devlieghere pfunc(debugger_arg, PythonString(args), exe_ctx_arg, cmd_retobj_arg, dict); 7286498aff2SJonas Devlieghere 7296498aff2SJonas Devlieghere return true; 7306498aff2SJonas Devlieghere} 7316498aff2SJonas Devlieghere 7326498aff2SJonas DevlieghereSWIGEXPORT bool 7336498aff2SJonas DevlieghereLLDBSwigPythonCallCommandObject 7346498aff2SJonas Devlieghere( 7356498aff2SJonas Devlieghere PyObject *implementor, 7366498aff2SJonas Devlieghere lldb::DebuggerSP& debugger, 7376498aff2SJonas Devlieghere const char* args, 7386498aff2SJonas Devlieghere lldb_private::CommandReturnObject& cmd_retobj, 7396498aff2SJonas Devlieghere lldb::ExecutionContextRefSP exe_ctx_ref_sp 7406498aff2SJonas Devlieghere) 7416498aff2SJonas Devlieghere{ 7426498aff2SJonas Devlieghere lldb::SBCommandReturnObject cmd_retobj_sb(cmd_retobj); 7436498aff2SJonas Devlieghere lldb::SBDebugger debugger_sb(debugger); 7446498aff2SJonas Devlieghere lldb::SBExecutionContext exe_ctx_sb(exe_ctx_ref_sp); 7456498aff2SJonas Devlieghere 7466498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 7476498aff2SJonas Devlieghere 7486498aff2SJonas Devlieghere PythonObject self(PyRefType::Borrowed, implementor); 7496498aff2SJonas Devlieghere auto pfunc = self.ResolveName<PythonCallable>("__call__"); 7506498aff2SJonas Devlieghere 7516498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 7526498aff2SJonas Devlieghere return false; 7536498aff2SJonas Devlieghere 7546498aff2SJonas Devlieghere // pass the pointer-to cmd_retobj_sb or watch the underlying object disappear from under you 7556498aff2SJonas Devlieghere // see comment above for SBCommandReturnObjectReleaser for further details 7566498aff2SJonas Devlieghere PythonObject debugger_arg(PyRefType::Owned, SBTypeToSWIGWrapper(debugger_sb)); 7576498aff2SJonas Devlieghere PythonObject exe_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(exe_ctx_sb)); 7586498aff2SJonas Devlieghere PythonObject cmd_retobj_arg(PyRefType::Owned, SBTypeToSWIGWrapper(&cmd_retobj_sb)); 7596498aff2SJonas Devlieghere 7606498aff2SJonas Devlieghere pfunc(debugger_arg, PythonString(args), exe_ctx_arg, cmd_retobj_arg); 7616498aff2SJonas Devlieghere 7626498aff2SJonas Devlieghere return true; 7636498aff2SJonas Devlieghere} 7646498aff2SJonas Devlieghere 7656498aff2SJonas DevlieghereSWIGEXPORT void* 7666498aff2SJonas DevlieghereLLDBSWIGPythonCreateOSPlugin 7676498aff2SJonas Devlieghere( 7686498aff2SJonas Devlieghere const char *python_class_name, 7696498aff2SJonas Devlieghere const char *session_dictionary_name, 7706498aff2SJonas Devlieghere const lldb::ProcessSP& process_sp 7716498aff2SJonas Devlieghere) 7726498aff2SJonas Devlieghere{ 7736498aff2SJonas Devlieghere if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name) 7746498aff2SJonas Devlieghere Py_RETURN_NONE; 7756498aff2SJonas Devlieghere 7766498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 7776498aff2SJonas Devlieghere 7786498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 7796498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict); 7806498aff2SJonas Devlieghere 7816498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 7826498aff2SJonas Devlieghere Py_RETURN_NONE; 7836498aff2SJonas Devlieghere 7846498aff2SJonas Devlieghere // I do not want the SBProcess to be deallocated when going out of scope because python 7856498aff2SJonas Devlieghere // has ownership of it and will manage memory for this object by itself 7866498aff2SJonas Devlieghere lldb::SBProcess *process_sb = new lldb::SBProcess(process_sp); 7876498aff2SJonas Devlieghere PythonObject process_arg(PyRefType::Owned, SBTypeToSWIGWrapper(process_sb)); 7886498aff2SJonas Devlieghere if (!process_arg.IsAllocated()) 7896498aff2SJonas Devlieghere Py_RETURN_NONE; 7906498aff2SJonas Devlieghere 7916498aff2SJonas Devlieghere auto result = pfunc(process_arg); 7926498aff2SJonas Devlieghere 7936498aff2SJonas Devlieghere if (result.IsAllocated()) 7946498aff2SJonas Devlieghere return result.release(); 7956498aff2SJonas Devlieghere 7966498aff2SJonas Devlieghere Py_RETURN_NONE; 7976498aff2SJonas Devlieghere} 7986498aff2SJonas Devlieghere 7996498aff2SJonas DevlieghereSWIGEXPORT void* 8006498aff2SJonas DevlieghereLLDBSWIGPython_CreateFrameRecognizer 8016498aff2SJonas Devlieghere( 8026498aff2SJonas Devlieghere const char *python_class_name, 8036498aff2SJonas Devlieghere const char *session_dictionary_name 8046498aff2SJonas Devlieghere) 8056498aff2SJonas Devlieghere{ 8066498aff2SJonas Devlieghere if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name) 8076498aff2SJonas Devlieghere Py_RETURN_NONE; 8086498aff2SJonas Devlieghere 8096498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 8106498aff2SJonas Devlieghere 8116498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 8126498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict); 8136498aff2SJonas Devlieghere 8146498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 8156498aff2SJonas Devlieghere Py_RETURN_NONE; 8166498aff2SJonas Devlieghere 8176498aff2SJonas Devlieghere auto result = pfunc(); 8186498aff2SJonas Devlieghere 8196498aff2SJonas Devlieghere if (result.IsAllocated()) 8206498aff2SJonas Devlieghere return result.release(); 8216498aff2SJonas Devlieghere 8226498aff2SJonas Devlieghere Py_RETURN_NONE; 8236498aff2SJonas Devlieghere} 8246498aff2SJonas Devlieghere 8256498aff2SJonas DevlieghereSWIGEXPORT PyObject* 8266498aff2SJonas DevlieghereLLDBSwigPython_GetRecognizedArguments 8276498aff2SJonas Devlieghere( 8286498aff2SJonas Devlieghere PyObject *implementor, 8296498aff2SJonas Devlieghere const lldb::StackFrameSP& frame_sp 8306498aff2SJonas Devlieghere) 8316498aff2SJonas Devlieghere{ 8326498aff2SJonas Devlieghere static char callee_name[] = "get_recognized_arguments"; 8336498aff2SJonas Devlieghere 8346498aff2SJonas Devlieghere lldb::SBFrame frame_sb(frame_sp); 8356498aff2SJonas Devlieghere PyObject *arg = SBTypeToSWIGWrapper(frame_sb); 8366498aff2SJonas Devlieghere 8376498aff2SJonas Devlieghere PythonString str(callee_name); 8386498aff2SJonas Devlieghere PyObject* result = PyObject_CallMethodObjArgs(implementor, str.get(), arg, 8396498aff2SJonas Devlieghere NULL); 8406498aff2SJonas Devlieghere return result; 8416498aff2SJonas Devlieghere} 8426498aff2SJonas Devlieghere 8436498aff2SJonas DevlieghereSWIGEXPORT void* 8446498aff2SJonas DevlieghereLLDBSWIGPython_GetDynamicSetting (void* module, const char* setting, const lldb::TargetSP& target_sp) 8456498aff2SJonas Devlieghere{ 8466498aff2SJonas Devlieghere if (!module || !setting) 8476498aff2SJonas Devlieghere Py_RETURN_NONE; 8486498aff2SJonas Devlieghere 8496498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 8506498aff2SJonas Devlieghere PythonObject py_module(PyRefType::Borrowed, (PyObject *)module); 8516498aff2SJonas Devlieghere auto pfunc = py_module.ResolveName<PythonCallable>("get_dynamic_setting"); 8526498aff2SJonas Devlieghere 8536498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 8546498aff2SJonas Devlieghere Py_RETURN_NONE; 8556498aff2SJonas Devlieghere 8566498aff2SJonas Devlieghere lldb::SBTarget target_sb(target_sp); 8576498aff2SJonas Devlieghere PythonObject target_arg(PyRefType::Owned, SBTypeToSWIGWrapper(target_sb)); 8586498aff2SJonas Devlieghere auto result = pfunc(target_arg, PythonString(setting)); 8596498aff2SJonas Devlieghere 8606498aff2SJonas Devlieghere return result.release(); 8616498aff2SJonas Devlieghere} 8626498aff2SJonas Devlieghere 8636498aff2SJonas DevlieghereSWIGEXPORT bool 8646498aff2SJonas DevlieghereLLDBSWIGPythonRunScriptKeywordProcess 8656498aff2SJonas Devlieghere(const char* python_function_name, 8666498aff2SJonas Devlieghereconst char* session_dictionary_name, 8676498aff2SJonas Devliegherelldb::ProcessSP& process, 8686498aff2SJonas Devliegherestd::string& output) 8696498aff2SJonas Devlieghere 8706498aff2SJonas Devlieghere{ 8716498aff2SJonas Devlieghere if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name) 8726498aff2SJonas Devlieghere return false; 8736498aff2SJonas Devlieghere 8746498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 8756498aff2SJonas Devlieghere 8766498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 8776498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 8786498aff2SJonas Devlieghere 8796498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 8806498aff2SJonas Devlieghere return false; 8816498aff2SJonas Devlieghere 8826498aff2SJonas Devlieghere lldb::SBProcess process_sb(process); 8836498aff2SJonas Devlieghere PythonObject process_arg(PyRefType::Owned, SBTypeToSWIGWrapper(process_sb)); 8846498aff2SJonas Devlieghere auto result = pfunc(process_arg, dict); 8856498aff2SJonas Devlieghere 8866498aff2SJonas Devlieghere output = result.Str().GetString().str(); 8876498aff2SJonas Devlieghere 8886498aff2SJonas Devlieghere return true; 8896498aff2SJonas Devlieghere} 8906498aff2SJonas Devlieghere 8916498aff2SJonas DevlieghereSWIGEXPORT bool 8926498aff2SJonas DevlieghereLLDBSWIGPythonRunScriptKeywordThread 8936498aff2SJonas Devlieghere(const char* python_function_name, 8946498aff2SJonas Devlieghereconst char* session_dictionary_name, 8956498aff2SJonas Devliegherelldb::ThreadSP& thread, 8966498aff2SJonas Devliegherestd::string& output) 8976498aff2SJonas Devlieghere 8986498aff2SJonas Devlieghere{ 8996498aff2SJonas Devlieghere if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name) 9006498aff2SJonas Devlieghere return false; 9016498aff2SJonas Devlieghere 9026498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 9036498aff2SJonas Devlieghere 9046498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 9056498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 9066498aff2SJonas Devlieghere 9076498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 9086498aff2SJonas Devlieghere return false; 9096498aff2SJonas Devlieghere 9106498aff2SJonas Devlieghere lldb::SBThread thread_sb(thread); 9116498aff2SJonas Devlieghere PythonObject thread_arg(PyRefType::Owned, SBTypeToSWIGWrapper(thread_sb)); 9126498aff2SJonas Devlieghere auto result = pfunc(thread_arg, dict); 9136498aff2SJonas Devlieghere 9146498aff2SJonas Devlieghere output = result.Str().GetString().str(); 9156498aff2SJonas Devlieghere 9166498aff2SJonas Devlieghere return true; 9176498aff2SJonas Devlieghere} 9186498aff2SJonas Devlieghere 9196498aff2SJonas DevlieghereSWIGEXPORT bool 9206498aff2SJonas DevlieghereLLDBSWIGPythonRunScriptKeywordTarget 9216498aff2SJonas Devlieghere(const char* python_function_name, 9226498aff2SJonas Devlieghereconst char* session_dictionary_name, 9236498aff2SJonas Devliegherelldb::TargetSP& target, 9246498aff2SJonas Devliegherestd::string& output) 9256498aff2SJonas Devlieghere 9266498aff2SJonas Devlieghere{ 9276498aff2SJonas Devlieghere if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name) 9286498aff2SJonas Devlieghere return false; 9296498aff2SJonas Devlieghere 9306498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 9316498aff2SJonas Devlieghere 9326498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 9336498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name,dict); 9346498aff2SJonas Devlieghere 9356498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 9366498aff2SJonas Devlieghere return false; 9376498aff2SJonas Devlieghere 9386498aff2SJonas Devlieghere lldb::SBTarget target_sb(target); 9396498aff2SJonas Devlieghere PythonObject target_arg(PyRefType::Owned, SBTypeToSWIGWrapper(target_sb)); 9406498aff2SJonas Devlieghere auto result = pfunc(target_arg, dict); 9416498aff2SJonas Devlieghere 9426498aff2SJonas Devlieghere output = result.Str().GetString().str(); 9436498aff2SJonas Devlieghere 9446498aff2SJonas Devlieghere return true; 9456498aff2SJonas Devlieghere} 9466498aff2SJonas Devlieghere 9476498aff2SJonas DevlieghereSWIGEXPORT bool 9486498aff2SJonas DevlieghereLLDBSWIGPythonRunScriptKeywordFrame 9496498aff2SJonas Devlieghere(const char* python_function_name, 9506498aff2SJonas Devlieghereconst char* session_dictionary_name, 9516498aff2SJonas Devliegherelldb::StackFrameSP& frame, 9526498aff2SJonas Devliegherestd::string& output) 9536498aff2SJonas Devlieghere 9546498aff2SJonas Devlieghere{ 9556498aff2SJonas Devlieghere if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name) 9566498aff2SJonas Devlieghere return false; 9576498aff2SJonas Devlieghere 9586498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 9596498aff2SJonas Devlieghere 9606498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 9616498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name,dict); 9626498aff2SJonas Devlieghere 9636498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 9646498aff2SJonas Devlieghere return false; 9656498aff2SJonas Devlieghere 9666498aff2SJonas Devlieghere lldb::SBFrame frame_sb(frame); 9676498aff2SJonas Devlieghere PythonObject frame_arg(PyRefType::Owned, SBTypeToSWIGWrapper(frame_sb)); 9686498aff2SJonas Devlieghere auto result = pfunc(frame_arg, dict); 9696498aff2SJonas Devlieghere 9706498aff2SJonas Devlieghere output = result.Str().GetString().str(); 9716498aff2SJonas Devlieghere 9726498aff2SJonas Devlieghere return true; 9736498aff2SJonas Devlieghere} 9746498aff2SJonas Devlieghere 9756498aff2SJonas DevlieghereSWIGEXPORT bool 9766498aff2SJonas DevlieghereLLDBSWIGPythonRunScriptKeywordValue 9776498aff2SJonas Devlieghere(const char* python_function_name, 9786498aff2SJonas Devlieghereconst char* session_dictionary_name, 9796498aff2SJonas Devliegherelldb::ValueObjectSP& value, 9806498aff2SJonas Devliegherestd::string& output) 9816498aff2SJonas Devlieghere 9826498aff2SJonas Devlieghere{ 9836498aff2SJonas Devlieghere if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name) 9846498aff2SJonas Devlieghere return false; 9856498aff2SJonas Devlieghere 9866498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 9876498aff2SJonas Devlieghere 9886498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 9896498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 9906498aff2SJonas Devlieghere 9916498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 9926498aff2SJonas Devlieghere return false; 9936498aff2SJonas Devlieghere 9946498aff2SJonas Devlieghere lldb::SBValue value_sb(value); 9956498aff2SJonas Devlieghere PythonObject value_arg(PyRefType::Owned, SBTypeToSWIGWrapper(value_sb)); 9966498aff2SJonas Devlieghere auto result = pfunc(value_arg, dict); 9976498aff2SJonas Devlieghere 9986498aff2SJonas Devlieghere output = result.Str().GetString().str(); 9996498aff2SJonas Devlieghere 10006498aff2SJonas Devlieghere return true; 10016498aff2SJonas Devlieghere} 10026498aff2SJonas Devlieghere 10036498aff2SJonas DevlieghereSWIGEXPORT bool 10046498aff2SJonas DevlieghereLLDBSwigPythonCallModuleInit 10056498aff2SJonas Devlieghere( 10066498aff2SJonas Devlieghere const char *python_module_name, 10076498aff2SJonas Devlieghere const char *session_dictionary_name, 10086498aff2SJonas Devlieghere lldb::DebuggerSP& debugger 10096498aff2SJonas Devlieghere) 10106498aff2SJonas Devlieghere{ 10116498aff2SJonas Devlieghere std::string python_function_name_string = python_module_name; 10126498aff2SJonas Devlieghere python_function_name_string += ".__lldb_init_module"; 10136498aff2SJonas Devlieghere const char* python_function_name = python_function_name_string.c_str(); 10146498aff2SJonas Devlieghere 10156498aff2SJonas Devlieghere PyErr_Cleaner py_err_cleaner(true); 10166498aff2SJonas Devlieghere 10176498aff2SJonas Devlieghere auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name); 10186498aff2SJonas Devlieghere auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict); 10196498aff2SJonas Devlieghere 10206498aff2SJonas Devlieghere // This method is optional and need not exist. So if we don't find it, 10216498aff2SJonas Devlieghere // it's actually a success, not a failure. 10226498aff2SJonas Devlieghere if (!pfunc.IsAllocated()) 10236498aff2SJonas Devlieghere return true; 10246498aff2SJonas Devlieghere 10256498aff2SJonas Devlieghere lldb::SBDebugger debugger_sb(debugger); 10266498aff2SJonas Devlieghere PythonObject debugger_arg(PyRefType::Owned, SBTypeToSWIGWrapper(debugger_sb)); 10276498aff2SJonas Devlieghere pfunc(debugger_arg, dict); 10286498aff2SJonas Devlieghere 10296498aff2SJonas Devlieghere return true; 10306498aff2SJonas Devlieghere} 10316498aff2SJonas Devlieghere%} 10326498aff2SJonas Devlieghere 10336498aff2SJonas Devlieghere 10346498aff2SJonas Devlieghere%runtime %{ 10356498aff2SJonas Devlieghere// Forward declaration to be inserted at the start of LLDBWrapPython.h 10366498aff2SJonas Devlieghere#include "lldb/API/SBDebugger.h" 10376498aff2SJonas Devlieghere#include "lldb/API/SBValue.h" 10386498aff2SJonas Devlieghere 10396498aff2SJonas DevlieghereSWIGEXPORT lldb::ValueObjectSP 10406498aff2SJonas DevlieghereLLDBSWIGPython_GetValueObjectSPFromSBValue (void* data) 10416498aff2SJonas Devlieghere{ 10426498aff2SJonas Devlieghere lldb::ValueObjectSP valobj_sp; 10436498aff2SJonas Devlieghere if (data) 10446498aff2SJonas Devlieghere { 10456498aff2SJonas Devlieghere lldb::SBValue* sb_ptr = (lldb::SBValue *)data; 10466498aff2SJonas Devlieghere valobj_sp = sb_ptr->GetSP(); 10476498aff2SJonas Devlieghere } 10486498aff2SJonas Devlieghere return valobj_sp; 10496498aff2SJonas Devlieghere} 10506498aff2SJonas Devlieghere 10516498aff2SJonas Devlieghere#ifdef __cplusplus 10526498aff2SJonas Devlieghereextern "C" { 10536498aff2SJonas Devlieghere#endif 10546498aff2SJonas Devlieghere 10556498aff2SJonas Devliegherevoid LLDBSwigPythonCallPythonLogOutputCallback(const char *str, void *baton); 10566498aff2SJonas Devlieghere 10576498aff2SJonas Devlieghere#ifdef __cplusplus 10586498aff2SJonas Devlieghere} 10596498aff2SJonas Devlieghere#endif 10606498aff2SJonas Devlieghere%} 10616498aff2SJonas Devlieghere 10626498aff2SJonas Devlieghere%wrapper %{ 10636498aff2SJonas Devlieghere 10646498aff2SJonas Devlieghere 10656498aff2SJonas Devlieghere// For the LogOutputCallback functions 10666498aff2SJonas Devliegherevoid LLDBSwigPythonCallPythonLogOutputCallback(const char *str, void *baton) { 10676498aff2SJonas Devlieghere if (baton != Py_None) { 10686498aff2SJonas Devlieghere SWIG_PYTHON_THREAD_BEGIN_BLOCK; 10696498aff2SJonas Devlieghere PyObject *result = PyObject_CallFunction(reinterpret_cast<PyObject*>(baton), const_cast<char*>("s"), str); 10706498aff2SJonas Devlieghere Py_XDECREF(result); 10716498aff2SJonas Devlieghere SWIG_PYTHON_THREAD_END_BLOCK; 10726498aff2SJonas Devlieghere } 10736498aff2SJonas Devlieghere} 10746498aff2SJonas Devlieghere%} 1075