From e3b557809604d036af6e00c60f012c2025b59a5e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 11 Feb 2023 13:38:04 +0100 Subject: Vendor import of llvm-project main llvmorg-16-init-18548-gb0daacf58f41, the last commit before the upstream release/17.x branch was created. --- .../Python/ScriptedProcessPythonInterface.cpp | 40 +++++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp') diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp index 576bf69c9258..6f087e8390ce 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp @@ -8,6 +8,7 @@ #include "lldb/Host/Config.h" #include "lldb/Utility/Log.h" +#include "lldb/Utility/Status.h" #include "lldb/lldb-enumerations.h" #if LLDB_ENABLE_PYTHON @@ -19,6 +20,7 @@ #include "ScriptInterpreterPythonImpl.h" #include "ScriptedProcessPythonInterface.h" #include "ScriptedThreadPythonInterface.h" +#include using namespace lldb; using namespace lldb_private; @@ -35,16 +37,18 @@ StructuredData::GenericSP ScriptedProcessPythonInterface::CreatePluginObject( if (class_name.empty()) return {}; - TargetSP target_sp = exe_ctx.GetTargetSP(); StructuredDataImpl args_impl(args_sp); std::string error_string; Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock); - PythonObject ret_val = LLDBSwigPythonCreateScriptedProcess( - class_name.str().c_str(), m_interpreter.GetDictionaryName(), target_sp, - args_impl, error_string); + lldb::ExecutionContextRefSP exe_ctx_ref_sp = + std::make_shared(exe_ctx); + + PythonObject ret_val = LLDBSwigPythonCreateScriptedObject( + class_name.str().c_str(), m_interpreter.GetDictionaryName(), + exe_ctx_ref_sp, args_impl, error_string); m_object_instance_sp = StructuredData::GenericSP(new StructuredPythonObject(std::move(ret_val))); @@ -74,10 +78,10 @@ Status ScriptedProcessPythonInterface::Stop() { return GetStatusFromMethod("stop"); } -llvm::Optional +std::optional ScriptedProcessPythonInterface::GetMemoryRegionContainingAddress( lldb::addr_t address, Status &error) { - auto mem_region = Dispatch>( + auto mem_region = Dispatch>( "get_memory_region_containing_address", error, address); if (error.Fail()) { @@ -120,8 +124,15 @@ ScriptedProcessPythonInterface::GetRegistersForThread(lldb::tid_t tid) { lldb::DataExtractorSP ScriptedProcessPythonInterface::ReadMemoryAtAddress( lldb::addr_t address, size_t size, Status &error) { - return Dispatch("read_memory_at_address", error, - address, size); + Status py_error; + lldb::DataExtractorSP data_sp = Dispatch( + "read_memory_at_address", py_error, address, size, error); + + // If there was an error on the python call, surface it to the user. + if (py_error.Fail()) + error = py_error; + + return data_sp; } StructuredData::ArraySP ScriptedProcessPythonInterface::GetLoadedImages() { @@ -161,7 +172,7 @@ bool ScriptedProcessPythonInterface::IsAlive() { return obj->GetBooleanValue(); } -llvm::Optional +std::optional ScriptedProcessPythonInterface::GetScriptedThreadPluginName() { Status error; StructuredData::ObjectSP obj = Dispatch("get_scripted_thread_plugin", error); @@ -177,4 +188,15 @@ ScriptedProcessPythonInterface::CreateScriptedThreadInterface() { return std::make_shared(m_interpreter); } +StructuredData::DictionarySP ScriptedProcessPythonInterface::GetMetadata() { + Status error; + StructuredData::DictionarySP dict = + Dispatch("get_process_metadata", error); + + if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict, error)) + return {}; + + return dict; +} + #endif -- cgit v1.3