diff options
Diffstat (limited to 'contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp')
-rw-r--r-- | contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp | 294 |
1 files changed, 184 insertions, 110 deletions
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 7026815e120d..55b7a73712c4 100644 --- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -306,7 +306,7 @@ void ScriptInterpreterPython::SharedLibraryDirectoryHelper( // On windows, we need to manually back out of the python tree, and go into // the bin directory. This is pretty much the inverse of what ComputePythonDir // does. - if (this_file.GetFileNameExtension() == ConstString(".pyd")) { + if (this_file.GetFileNameExtension() == ".pyd") { this_file.RemoveLastPathComponent(); // _lldb.pyd or _lldb_d.pyd this_file.RemoveLastPathComponent(); // lldb llvm::StringRef libdir = LLDB_PYTHON_RELATIVE_LIBDIR; @@ -408,12 +408,10 @@ ScriptInterpreterPythonImpl::ScriptInterpreterPythonImpl(Debugger &debugger) m_session_dict(PyInitialValue::Invalid), m_sys_module_dict(PyInitialValue::Invalid), m_run_one_line_function(), m_run_one_line_str_global(), - m_dictionary_name(m_debugger.GetInstanceName().AsCString()), + m_dictionary_name(m_debugger.GetInstanceName()), m_active_io_handler(eIOHandlerNone), m_session_is_active(false), m_pty_secondary_is_open(false), m_valid_session(true), m_lock_count(0), m_command_thread_state(nullptr) { - m_scripted_process_interface_up = - std::make_unique<ScriptedProcessPythonInterface>(*this); m_scripted_platform_interface_up = std::make_unique<ScriptedPlatformPythonInterface>(*this); @@ -443,7 +441,7 @@ ScriptInterpreterPythonImpl::ScriptInterpreterPythonImpl(Debugger &debugger) // do their task run_string.Clear(); run_string.Printf( - "run_one_line (%s, 'import lldb.formatters, lldb.formatters.cpp, pydoc')", + "run_one_line (%s, 'import lldb.formatters, lldb.formatters.cpp')", m_dictionary_name.c_str()); PyRun_SimpleString(run_string.GetData()); run_string.Clear(); @@ -456,7 +454,7 @@ ScriptInterpreterPythonImpl::ScriptInterpreterPythonImpl(Debugger &debugger) run_string.Clear(); run_string.Printf("run_one_line (%s, 'lldb.debugger_unique_id = %" PRIu64 - "; pydoc.pager = pydoc.plainpager')", + "')", m_dictionary_name.c_str(), m_debugger.GetID()); PyRun_SimpleString(run_string.GetData()); } @@ -523,7 +521,8 @@ void ScriptInterpreterPythonImpl::IOHandlerInputComplete(IOHandler &io_handler, StructuredData::ObjectSP empty_args_sp; if (GenerateBreakpointCommandCallbackData(data_up->user_source, data_up->script_source, - false) + /*has_extra_args=*/false, + /*is_callback=*/false) .Success()) { auto baton_sp = std::make_shared<BreakpointOptions::CommandBaton>( std::move(data_up)); @@ -546,7 +545,8 @@ void ScriptInterpreterPythonImpl::IOHandlerInputComplete(IOHandler &io_handler, data_up->user_source.SplitIntoLines(data); if (GenerateWatchpointCommandCallbackData(data_up->user_source, - data_up->script_source)) { + data_up->script_source, + /*is_callback=*/false)) { auto baton_sp = std::make_shared<WatchpointOptions::CommandBaton>(std::move(data_up)); wp_options->SetCallback( @@ -1160,8 +1160,7 @@ Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallbackFunction( StructuredData::ObjectSP extra_args_sp) { Status error; // For now just cons up a oneliner that calls the provided function. - std::string oneliner("return "); - oneliner += function_name; + std::string function_signature = function_name; llvm::Expected<unsigned> maybe_args = GetMaxPositionalArgumentsForCallable(function_name); @@ -1176,7 +1175,7 @@ Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallbackFunction( bool uses_extra_args = false; if (max_args >= 4) { uses_extra_args = true; - oneliner += "(frame, bp_loc, extra_args, internal_dict)"; + function_signature += "(frame, bp_loc, extra_args, internal_dict)"; } else if (max_args >= 3) { if (extra_args_sp) { error.SetErrorString("cannot pass extra_args to a three argument callback" @@ -1184,7 +1183,7 @@ Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallbackFunction( return error; } uses_extra_args = false; - oneliner += "(frame, bp_loc, internal_dict)"; + function_signature += "(frame, bp_loc, internal_dict)"; } else { error.SetErrorStringWithFormat("expected 3 or 4 argument " "function, %s can only take %zu", @@ -1192,8 +1191,9 @@ Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallbackFunction( return error; } - SetBreakpointCommandCallback(bp_options, oneliner.c_str(), extra_args_sp, - uses_extra_args); + SetBreakpointCommandCallback(bp_options, function_signature.c_str(), + extra_args_sp, uses_extra_args, + /*is_callback=*/true); return error; } @@ -1203,7 +1203,8 @@ Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallback( Status error; error = GenerateBreakpointCommandCallbackData(cmd_data_up->user_source, cmd_data_up->script_source, - false); + /*has_extra_args=*/false, + /*is_callback=*/false); if (error.Fail()) { return error; } @@ -1215,14 +1216,17 @@ Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallback( } Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallback( - BreakpointOptions &bp_options, const char *command_body_text) { - return SetBreakpointCommandCallback(bp_options, command_body_text, {},false); + BreakpointOptions &bp_options, const char *command_body_text, + bool is_callback) { + return SetBreakpointCommandCallback(bp_options, command_body_text, {}, + /*uses_extra_args=*/false, is_callback); } // Set a Python one-liner as the callback for the breakpoint. Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallback( BreakpointOptions &bp_options, const char *command_body_text, - StructuredData::ObjectSP extra_args_sp, bool uses_extra_args) { + StructuredData::ObjectSP extra_args_sp, bool uses_extra_args, + bool is_callback) { auto data_up = std::make_unique<CommandDataPython>(extra_args_sp); // Split the command_body_text into lines, and pass that to // GenerateBreakpointCommandCallbackData. That will wrap the body in an @@ -1230,9 +1234,9 @@ Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallback( // That is what the callback will actually invoke. data_up->user_source.SplitIntoLines(command_body_text); - Status error = GenerateBreakpointCommandCallbackData(data_up->user_source, - data_up->script_source, - uses_extra_args); + Status error = GenerateBreakpointCommandCallbackData( + data_up->user_source, data_up->script_source, uses_extra_args, + is_callback); if (error.Success()) { auto baton_sp = std::make_shared<BreakpointOptions::CommandBaton>(std::move(data_up)); @@ -1245,7 +1249,8 @@ Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallback( // Set a Python one-liner as the callback for the watchpoint. void ScriptInterpreterPythonImpl::SetWatchpointCommandCallback( - WatchpointOptions *wp_options, const char *oneliner) { + WatchpointOptions *wp_options, const char *user_input, + bool is_callback) { auto data_up = std::make_unique<WatchpointOptions::CommandData>(); // It's necessary to set both user_source and script_source to the oneliner. @@ -1253,11 +1258,11 @@ void ScriptInterpreterPythonImpl::SetWatchpointCommandCallback( // command list) while the latter is used for Python to interpret during the // actual callback. - data_up->user_source.AppendString(oneliner); - data_up->script_source.assign(oneliner); + data_up->user_source.AppendString(user_input); + data_up->script_source.assign(user_input); - if (GenerateWatchpointCommandCallbackData(data_up->user_source, - data_up->script_source)) { + if (GenerateWatchpointCommandCallbackData( + data_up->user_source, data_up->script_source, is_callback)) { auto baton_sp = std::make_shared<WatchpointOptions::CommandBaton>(std::move(data_up)); wp_options->SetCallback( @@ -1277,7 +1282,8 @@ Status ScriptInterpreterPythonImpl::ExportFunctionDefinitionToInterpreter( } Status ScriptInterpreterPythonImpl::GenerateFunction(const char *signature, - const StringList &input) { + const StringList &input, + bool is_callback) { Status error; int num_lines = input.GetSize(); if (num_lines == 0) { @@ -1294,40 +1300,61 @@ Status ScriptInterpreterPythonImpl::GenerateFunction(const char *signature, StringList auto_generated_function; auto_generated_function.AppendString(signature); auto_generated_function.AppendString( - " global_dict = globals()"); // Grab the global dictionary + " global_dict = globals()"); // Grab the global dictionary auto_generated_function.AppendString( - " new_keys = internal_dict.keys()"); // Make a list of keys in the - // session dict + " new_keys = internal_dict.keys()"); // Make a list of keys in the + // session dict auto_generated_function.AppendString( - " old_keys = global_dict.keys()"); // Save list of keys in global dict + " old_keys = global_dict.keys()"); // Save list of keys in global dict auto_generated_function.AppendString( - " global_dict.update (internal_dict)"); // Add the session dictionary - // to the - // global dictionary. - - // Wrap everything up inside the function, increasing the indentation. - - auto_generated_function.AppendString(" if True:"); - for (int i = 0; i < num_lines; ++i) { - sstr.Clear(); - sstr.Printf(" %s", input.GetStringAtIndex(i)); - auto_generated_function.AppendString(sstr.GetData()); + " global_dict.update(internal_dict)"); // Add the session dictionary + // to the global dictionary. + + if (is_callback) { + // If the user input is a callback to a python function, make sure the input + // is only 1 line, otherwise appending the user input would break the + // generated wrapped function + if (num_lines == 1) { + sstr.Clear(); + sstr.Printf(" __return_val = %s", input.GetStringAtIndex(0)); + auto_generated_function.AppendString(sstr.GetData()); + } else { + return Status("ScriptInterpreterPythonImpl::GenerateFunction(is_callback=" + "true) = ERROR: python function is multiline."); + } + } else { + auto_generated_function.AppendString( + " __return_val = None"); // Initialize user callback return value. + auto_generated_function.AppendString( + " def __user_code():"); // Create a nested function that will wrap + // the user input. This is necessary to + // capture the return value of the user input + // and prevent early returns. + for (int i = 0; i < num_lines; ++i) { + sstr.Clear(); + sstr.Printf(" %s", input.GetStringAtIndex(i)); + auto_generated_function.AppendString(sstr.GetData()); + } + auto_generated_function.AppendString( + " __return_val = __user_code()"); // Call user code and capture + // return value } auto_generated_function.AppendString( - " for key in new_keys:"); // Iterate over all the keys from session - // dict + " for key in new_keys:"); // Iterate over all the keys from session + // dict + auto_generated_function.AppendString( + " internal_dict[key] = global_dict[key]"); // Update session dict + // values auto_generated_function.AppendString( - " internal_dict[key] = global_dict[key]"); // Update session dict - // values + " if key not in old_keys:"); // If key was not originally in + // global dict auto_generated_function.AppendString( - " if key not in old_keys:"); // If key was not originally in - // global dict + " del global_dict[key]"); // ...then remove key/value from + // global dict auto_generated_function.AppendString( - " del global_dict[key]"); // ...then remove key/value from - // global dict + " return __return_val"); // Return the user callback return value. // Verify that the results are valid Python. - error = ExportFunctionDefinitionToInterpreter(auto_generated_function); return error; @@ -1352,7 +1379,8 @@ bool ScriptInterpreterPythonImpl::GenerateTypeScriptFunction( sstr.Printf("def %s (valobj, internal_dict):", auto_generated_function_name.c_str()); - if (!GenerateFunction(sstr.GetData(), user_input).Success()) + if (!GenerateFunction(sstr.GetData(), user_input, /*is_callback=*/false) + .Success()) return false; // Store the name of the auto-generated function to be called. @@ -1376,7 +1404,8 @@ bool ScriptInterpreterPythonImpl::GenerateScriptAliasFunction( sstr.Printf("def %s (debugger, args, exe_ctx, result, internal_dict):", auto_generated_function_name.c_str()); - if (!GenerateFunction(sstr.GetData(), user_input).Success()) + if (!GenerateFunction(sstr.GetData(), user_input, /*is_callback=*/true) + .Success()) return false; // Store the name of the auto-generated function to be called. @@ -1434,7 +1463,7 @@ ScriptInterpreterPythonImpl::CreateFrameRecognizer(const char *class_name) { return StructuredData::GenericSP(); Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock); - PythonObject ret_val = LLDBSWIGPython_CreateFrameRecognizer( + PythonObject ret_val = SWIGBridge::LLDBSWIGPython_CreateFrameRecognizer( class_name, m_dictionary_name.c_str()); return StructuredData::GenericSP( @@ -1459,9 +1488,9 @@ lldb::ValueObjectListSP ScriptInterpreterPythonImpl::GetRecognizedArguments( if (!implementor.IsAllocated()) return ValueObjectListSP(); - PythonObject py_return( - PyRefType::Owned, - LLDBSwigPython_GetRecognizedArguments(implementor.get(), frame_sp)); + PythonObject py_return(PyRefType::Owned, + SWIGBridge::LLDBSwigPython_GetRecognizedArguments( + implementor.get(), frame_sp)); // if it fails, print the error but otherwise go on if (PyErr_Occurred()) { @@ -1475,7 +1504,8 @@ lldb::ValueObjectListSP ScriptInterpreterPythonImpl::GetRecognizedArguments( PyObject *item = result_list.GetItemAtIndex(i).get(); lldb::SBValue *sb_value_ptr = (lldb::SBValue *)LLDBSWIGPython_CastPyObjectToSBValue(item); - auto valobj_sp = LLDBSWIGPython_GetValueObjectSPFromSBValue(sb_value_ptr); + auto valobj_sp = + SWIGBridge::LLDBSWIGPython_GetValueObjectSPFromSBValue(sb_value_ptr); if (valobj_sp) result->Append(valobj_sp); } @@ -1484,6 +1514,22 @@ lldb::ValueObjectListSP ScriptInterpreterPythonImpl::GetRecognizedArguments( return ValueObjectListSP(); } +ScriptedProcessInterfaceUP +ScriptInterpreterPythonImpl::CreateScriptedProcessInterface() { + return std::make_unique<ScriptedProcessPythonInterface>(*this); +} + +StructuredData::ObjectSP +ScriptInterpreterPythonImpl::CreateStructuredDataFromScriptObject( + ScriptObject obj) { + void *ptr = const_cast<void *>(obj.GetPointer()); + PythonObject py_obj(PyRefType::Borrowed, static_cast<PyObject *>(ptr)); + if (!py_obj.IsValid() || py_obj.IsNone()) + return {}; + Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock); + return py_obj.CreateStructuredObject(); +} + StructuredData::GenericSP ScriptInterpreterPythonImpl::OSPlugin_CreatePluginObject( const char *class_name, lldb::ProcessSP process_sp) { @@ -1494,7 +1540,7 @@ ScriptInterpreterPythonImpl::OSPlugin_CreatePluginObject( return StructuredData::GenericSP(); Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock); - PythonObject ret_val = LLDBSWIGPythonCreateOSPlugin( + PythonObject ret_val = SWIGBridge::LLDBSWIGPythonCreateOSPlugin( class_name, m_dictionary_name.c_str(), process_sp); return StructuredData::GenericSP( @@ -1655,7 +1701,7 @@ StructuredData::ObjectSP ScriptInterpreterPythonImpl::CreateScriptedThreadPlan( Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - PythonObject ret_val = LLDBSwigPythonCreateScriptedThreadPlan( + PythonObject ret_val = SWIGBridge::LLDBSwigPythonCreateScriptedThreadPlan( class_name, python_interpreter->m_dictionary_name.c_str(), args_data, error_str, thread_plan_sp); if (!ret_val) @@ -1674,7 +1720,7 @@ bool ScriptInterpreterPythonImpl::ScriptedThreadPlanExplainsStop( if (generic) { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - explains_stop = LLDBSWIGPythonCallThreadPlan( + explains_stop = SWIGBridge::LLDBSWIGPythonCallThreadPlan( generic->GetValue(), "explains_stop", event, script_error); if (script_error) return true; @@ -1691,7 +1737,7 @@ bool ScriptInterpreterPythonImpl::ScriptedThreadPlanShouldStop( if (generic) { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - should_stop = LLDBSWIGPythonCallThreadPlan( + should_stop = SWIGBridge::LLDBSWIGPythonCallThreadPlan( generic->GetValue(), "should_stop", event, script_error); if (script_error) return true; @@ -1708,8 +1754,8 @@ bool ScriptInterpreterPythonImpl::ScriptedThreadPlanIsStale( if (generic) { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - is_stale = LLDBSWIGPythonCallThreadPlan(generic->GetValue(), "is_stale", - nullptr, script_error); + is_stale = SWIGBridge::LLDBSWIGPythonCallThreadPlan( + generic->GetValue(), "is_stale", (Event *)nullptr, script_error); if (script_error) return true; } @@ -1725,8 +1771,8 @@ lldb::StateType ScriptInterpreterPythonImpl::ScriptedThreadPlanGetRunState( if (generic) { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - should_step = LLDBSWIGPythonCallThreadPlan( - generic->GetValue(), "should_step", nullptr, script_error); + should_step = SWIGBridge::LLDBSWIGPythonCallThreadPlan( + generic->GetValue(), "should_step", (Event *)nullptr, script_error); if (script_error) should_step = true; } @@ -1735,6 +1781,24 @@ lldb::StateType ScriptInterpreterPythonImpl::ScriptedThreadPlanGetRunState( return lldb::eStateRunning; } +bool +ScriptInterpreterPythonImpl::ScriptedThreadPlanGetStopDescription( + StructuredData::ObjectSP implementor_sp, lldb_private::Stream *stream, + bool &script_error) { + StructuredData::Generic *generic = nullptr; + if (implementor_sp) + generic = implementor_sp->GetAsGeneric(); + if (!generic) { + script_error = true; + return false; + } + Locker py_lock(this, + Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); + return SWIGBridge::LLDBSWIGPythonCallThreadPlan( + generic->GetValue(), "stop_description", stream, script_error); +} + + StructuredData::GenericSP ScriptInterpreterPythonImpl::CreateScriptedBreakpointResolver( const char *class_name, const StructuredDataImpl &args_data, @@ -1756,9 +1820,10 @@ ScriptInterpreterPythonImpl::CreateScriptedBreakpointResolver( Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - PythonObject ret_val = LLDBSwigPythonCreateScriptedBreakpointResolver( - class_name, python_interpreter->m_dictionary_name.c_str(), args_data, - bkpt_sp); + PythonObject ret_val = + SWIGBridge::LLDBSwigPythonCreateScriptedBreakpointResolver( + class_name, python_interpreter->m_dictionary_name.c_str(), args_data, + bkpt_sp); return StructuredData::GenericSP( new StructuredPythonObject(std::move(ret_val))); @@ -1771,7 +1836,7 @@ bool ScriptInterpreterPythonImpl::ScriptedBreakpointResolverSearchCallback( if (implementor_sp) { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - should_continue = LLDBSwigPythonCallBreakpointResolver( + should_continue = SWIGBridge::LLDBSwigPythonCallBreakpointResolver( implementor_sp->GetValue(), "__callback__", sym_ctx); if (PyErr_Occurred()) { PyErr_Print(); @@ -1788,7 +1853,7 @@ ScriptInterpreterPythonImpl::ScriptedBreakpointResolverSearchDepth( if (implementor_sp) { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - depth_as_int = LLDBSwigPythonCallBreakpointResolver( + depth_as_int = SWIGBridge::LLDBSwigPythonCallBreakpointResolver( implementor_sp->GetValue(), "__get_depth__", nullptr); if (PyErr_Occurred()) { PyErr_Print(); @@ -1828,7 +1893,7 @@ StructuredData::GenericSP ScriptInterpreterPythonImpl::CreateScriptedStopHook( Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - PythonObject ret_val = LLDBSwigPythonCreateScriptedStopHook( + PythonObject ret_val = SWIGBridge::LLDBSwigPythonCreateScriptedStopHook( target_sp, class_name, python_interpreter->m_dictionary_name.c_str(), args_data, error); @@ -1848,7 +1913,7 @@ bool ScriptInterpreterPythonImpl::ScriptedStopHookHandleStop( lldb::ExecutionContextRefSP exc_ctx_ref_sp(new ExecutionContextRef(exc_ctx)); - bool ret_val = LLDBSwigPythonStopHookCallHandleStop( + bool ret_val = SWIGBridge::LLDBSwigPythonStopHookCallHandleStop( implementor_sp->GetValue(), exc_ctx_ref_sp, stream_sp); return ret_val; } @@ -1885,7 +1950,7 @@ StructuredData::DictionarySP ScriptInterpreterPythonImpl::GetDynamicSettings( Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); TargetSP target_sp(target->shared_from_this()); - auto setting = (PyObject *)LLDBSWIGPython_GetDynamicSetting( + auto setting = (PyObject *)SWIGBridge::LLDBSWIGPython_GetDynamicSetting( generic->GetValue(), setting_name, target_sp); if (!setting) @@ -1924,7 +1989,7 @@ ScriptInterpreterPythonImpl::CreateSyntheticScriptedProvider( Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - PythonObject ret_val = LLDBSwigPythonCreateSyntheticProvider( + PythonObject ret_val = SWIGBridge::LLDBSwigPythonCreateSyntheticProvider( class_name, python_interpreter->m_dictionary_name.c_str(), valobj); return StructuredData::ObjectSP( @@ -1943,11 +2008,14 @@ ScriptInterpreterPythonImpl::CreateScriptCommandObject(const char *class_name) { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - PythonObject ret_val = LLDBSwigPythonCreateCommandObject( + PythonObject ret_val = SWIGBridge::LLDBSwigPythonCreateCommandObject( class_name, m_dictionary_name.c_str(), debugger_sp); - return StructuredData::GenericSP( - new StructuredPythonObject(std::move(ret_val))); + if (ret_val.IsValid()) + return StructuredData::GenericSP( + new StructuredPythonObject(std::move(ret_val))); + else + return {}; } bool ScriptInterpreterPythonImpl::GenerateTypeScriptFunction( @@ -1965,8 +2033,8 @@ bool ScriptInterpreterPythonImpl::GenerateTypeSynthClass( } Status ScriptInterpreterPythonImpl::GenerateBreakpointCommandCallbackData( - StringList &user_input, std::string &output, - bool has_extra_args) { + StringList &user_input, std::string &output, bool has_extra_args, + bool is_callback) { static uint32_t num_created_functions = 0; user_input.RemoveBlankLines(); StreamString sstr; @@ -1985,7 +2053,7 @@ Status ScriptInterpreterPythonImpl::GenerateBreakpointCommandCallbackData( sstr.Printf("def %s (frame, bp_loc, internal_dict):", auto_generated_function_name.c_str()); - error = GenerateFunction(sstr.GetData(), user_input); + error = GenerateFunction(sstr.GetData(), user_input, is_callback); if (!error.Success()) return error; @@ -1995,7 +2063,7 @@ Status ScriptInterpreterPythonImpl::GenerateBreakpointCommandCallbackData( } bool ScriptInterpreterPythonImpl::GenerateWatchpointCommandCallbackData( - StringList &user_input, std::string &output) { + StringList &user_input, std::string &output, bool is_callback) { static uint32_t num_created_functions = 0; user_input.RemoveBlankLines(); StreamString sstr; @@ -2008,7 +2076,7 @@ bool ScriptInterpreterPythonImpl::GenerateWatchpointCommandCallbackData( sstr.Printf("def %s (frame, wp, internal_dict):", auto_generated_function_name.c_str()); - if (!GenerateFunction(sstr.GetData(), user_input).Success()) + if (!GenerateFunction(sstr.GetData(), user_input, is_callback).Success()) return false; // Store the name of the auto-generated function to be called. @@ -2047,7 +2115,7 @@ bool ScriptInterpreterPythonImpl::GetScriptedSummary( static Timer::Category func_cat("LLDBSwigPythonCallTypeScript"); Timer scoped_timer(func_cat, "LLDBSwigPythonCallTypeScript"); - ret_val = LLDBSwigPythonCallTypeScript( + ret_val = SWIGBridge::LLDBSwigPythonCallTypeScript( python_function_name, GetSessionDictionary().get(), valobj, &new_callee, options_sp, retval); } @@ -2071,7 +2139,7 @@ bool ScriptInterpreterPythonImpl::FormatterCallbackFunction( const char *python_function_name, TypeImplSP type_impl_sp) { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - return LLDBSwigPythonFormatterCallbackFunction( + return SWIGBridge::LLDBSwigPythonFormatterCallbackFunction( python_function_name, m_dictionary_name.c_str(), type_impl_sp); } @@ -2111,7 +2179,7 @@ bool ScriptInterpreterPythonImpl::BreakpointCallbackFunction( Locker::InitSession | Locker::NoSTDIN); Expected<bool> maybe_ret_val = - LLDBSwigPythonBreakpointCallbackFunction( + SWIGBridge::LLDBSwigPythonBreakpointCallbackFunction( python_function_name, python_interpreter->m_dictionary_name.c_str(), stop_frame_sp, bp_loc_sp, bp_option_data->m_extra_args); @@ -2172,7 +2240,7 @@ bool ScriptInterpreterPythonImpl::WatchpointCallbackFunction( Locker py_lock(python_interpreter, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = LLDBSwigPythonWatchpointCallbackFunction( + ret_val = SWIGBridge::LLDBSwigPythonWatchpointCallbackFunction( python_function_name, python_interpreter->m_dictionary_name.c_str(), stop_frame_sp, wp_sp); @@ -2202,7 +2270,7 @@ size_t ScriptInterpreterPythonImpl::CalculateNumChildren( { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = LLDBSwigPython_CalculateNumChildren(implementor, max); + ret_val = SWIGBridge::LLDBSwigPython_CalculateNumChildren(implementor, max); } return ret_val; @@ -2224,14 +2292,16 @@ lldb::ValueObjectSP ScriptInterpreterPythonImpl::GetChildAtIndex( { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - PyObject *child_ptr = LLDBSwigPython_GetChildAtIndex(implementor, idx); + PyObject *child_ptr = + SWIGBridge::LLDBSwigPython_GetChildAtIndex(implementor, idx); if (child_ptr != nullptr && child_ptr != Py_None) { lldb::SBValue *sb_value_ptr = (lldb::SBValue *)LLDBSWIGPython_CastPyObjectToSBValue(child_ptr); if (sb_value_ptr == nullptr) Py_XDECREF(child_ptr); else - ret_val = LLDBSWIGPython_GetValueObjectSPFromSBValue(sb_value_ptr); + ret_val = SWIGBridge::LLDBSWIGPython_GetValueObjectSPFromSBValue( + sb_value_ptr); } else { Py_XDECREF(child_ptr); } @@ -2257,7 +2327,7 @@ int ScriptInterpreterPythonImpl::GetIndexOfChildWithName( { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = LLDBSwigPython_GetIndexOfChildWithName(implementor, child_name); + ret_val = SWIGBridge::LLDBSwigPython_GetIndexOfChildWithName(implementor, child_name); } return ret_val; @@ -2280,7 +2350,8 @@ bool ScriptInterpreterPythonImpl::UpdateSynthProviderInstance( { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = LLDBSwigPython_UpdateSynthProviderInstance(implementor); + ret_val = + SWIGBridge::LLDBSwigPython_UpdateSynthProviderInstance(implementor); } return ret_val; @@ -2303,8 +2374,8 @@ bool ScriptInterpreterPythonImpl::MightHaveChildrenSynthProviderInstance( { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = - LLDBSwigPython_MightHaveChildrenSynthProviderInstance(implementor); + ret_val = SWIGBridge::LLDBSwigPython_MightHaveChildrenSynthProviderInstance( + implementor); } return ret_val; @@ -2328,14 +2399,15 @@ lldb::ValueObjectSP ScriptInterpreterPythonImpl::GetSyntheticValue( Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); PyObject *child_ptr = - LLDBSwigPython_GetValueSynthProviderInstance(implementor); + SWIGBridge::LLDBSwigPython_GetValueSynthProviderInstance(implementor); if (child_ptr != nullptr && child_ptr != Py_None) { lldb::SBValue *sb_value_ptr = (lldb::SBValue *)LLDBSWIGPython_CastPyObjectToSBValue(child_ptr); if (sb_value_ptr == nullptr) Py_XDECREF(child_ptr); else - ret_val = LLDBSWIGPython_GetValueObjectSPFromSBValue(sb_value_ptr); + ret_val = SWIGBridge::LLDBSWIGPython_GetValueObjectSPFromSBValue( + sb_value_ptr); } else { Py_XDECREF(child_ptr); } @@ -2406,7 +2478,7 @@ bool ScriptInterpreterPythonImpl::RunScriptFormatKeyword( { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = LLDBSWIGPythonRunScriptKeywordProcess( + ret_val = SWIGBridge::LLDBSWIGPythonRunScriptKeywordProcess( impl_function, m_dictionary_name.c_str(), process->shared_from_this(), output); if (!ret_val) @@ -2429,9 +2501,10 @@ bool ScriptInterpreterPythonImpl::RunScriptFormatKeyword( Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - if (std::optional<std::string> result = LLDBSWIGPythonRunScriptKeywordThread( - impl_function, m_dictionary_name.c_str(), - thread->shared_from_this())) { + if (std::optional<std::string> result = + SWIGBridge::LLDBSWIGPythonRunScriptKeywordThread( + impl_function, m_dictionary_name.c_str(), + thread->shared_from_this())) { output = std::move(*result); return true; } @@ -2456,7 +2529,7 @@ bool ScriptInterpreterPythonImpl::RunScriptFormatKeyword( TargetSP target_sp(target->shared_from_this()); Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = LLDBSWIGPythonRunScriptKeywordTarget( + ret_val = SWIGBridge::LLDBSWIGPythonRunScriptKeywordTarget( impl_function, m_dictionary_name.c_str(), target_sp, output); if (!ret_val) error.SetErrorString("python script evaluation failed"); @@ -2478,9 +2551,10 @@ bool ScriptInterpreterPythonImpl::RunScriptFormatKeyword( Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - if (std::optional<std::string> result = LLDBSWIGPythonRunScriptKeywordFrame( - impl_function, m_dictionary_name.c_str(), - frame->shared_from_this())) { + if (std::optional<std::string> result = + SWIGBridge::LLDBSWIGPythonRunScriptKeywordFrame( + impl_function, m_dictionary_name.c_str(), + frame->shared_from_this())) { output = std::move(*result); return true; } @@ -2504,7 +2578,7 @@ bool ScriptInterpreterPythonImpl::RunScriptFormatKeyword( { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = LLDBSWIGPythonRunScriptKeywordValue( + ret_val = SWIGBridge::LLDBSWIGPythonRunScriptKeywordValue( impl_function, m_dictionary_name.c_str(), value->GetSP(), output); if (!ret_val) error.SetErrorString("python script evaluation failed"); @@ -2684,9 +2758,9 @@ bool ScriptInterpreterPythonImpl::LoadScriptingModule( // if we are here, everything worked // call __lldb_init_module(debugger,dict) - if (!LLDBSwigPythonCallModuleInit(module_name.c_str(), - m_dictionary_name.c_str(), - m_debugger.shared_from_this())) { + if (!SWIGBridge::LLDBSwigPythonCallModuleInit( + module_name.c_str(), m_dictionary_name.c_str(), + m_debugger.shared_from_this())) { error.SetErrorString("calling __lldb_init_module failed"); return false; } @@ -2780,7 +2854,7 @@ bool ScriptInterpreterPythonImpl::RunScriptBasedCommand( SynchronicityHandler synch_handler(debugger_sp, synchronicity); std::string args_str = args.str(); - ret_val = LLDBSwigPythonCallCommand( + ret_val = SWIGBridge::LLDBSwigPythonCallCommand( impl_function, m_dictionary_name.c_str(), debugger_sp, args_str.c_str(), cmd_retobj, exe_ctx_ref_sp); } @@ -2825,7 +2899,7 @@ bool ScriptInterpreterPythonImpl::RunScriptBasedCommand( SynchronicityHandler synch_handler(debugger_sp, synchronicity); std::string args_str = args.str(); - ret_val = LLDBSwigPythonCallCommandObject( + ret_val = SWIGBridge::LLDBSwigPythonCallCommandObject( static_cast<PyObject *>(impl_obj_sp->GetValue()), debugger_sp, args_str.c_str(), cmd_retobj, exe_ctx_ref_sp); } |