diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h @@ -51,7 +51,7 @@ bool IsAlive() override; protected: - size_t GetGenericInteger(llvm::StringRef method_name); + llvm::Optional GetGenericInteger(llvm::StringRef method_name); Status GetStatusFromMethod(llvm::StringRef method_name); private: diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp @@ -63,7 +63,12 @@ } bool ScriptedProcessPythonInterface::ShouldStop() { - return GetGenericInteger("shuold_stop"); + auto should_stop = GetGenericInteger("should_stop"); + + if (!should_stop) + return false; + + return static_cast(*should_stop); } Status ScriptedProcessPythonInterface::Stop() { @@ -134,21 +139,21 @@ return Status("Returned object is null."); } -size_t +llvm::Optional ScriptedProcessPythonInterface::GetGenericInteger(llvm::StringRef method_name) { Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock); if (!m_object_instance_sp) - return LLDB_INVALID_ADDRESS; + return llvm::None; if (!m_object_instance_sp) - return LLDB_INVALID_ADDRESS; + return llvm::None; PythonObject implementor(PyRefType::Borrowed, (PyObject *)m_object_instance_sp->GetValue()); if (!implementor.IsAllocated()) - return LLDB_INVALID_ADDRESS; + return llvm::None; PythonObject pmeth( PyRefType::Owned, @@ -158,12 +163,12 @@ PyErr_Clear(); if (!pmeth.IsAllocated()) - return LLDB_INVALID_ADDRESS; + return llvm::None; if (PyCallable_Check(pmeth.get()) == 0) { if (PyErr_Occurred()) PyErr_Clear(); - return LLDB_INVALID_ADDRESS; + return llvm::None; } if (PyErr_Occurred()) @@ -179,11 +184,22 @@ PyErr_Clear(); } - if (py_return.get()) { - auto size = py_return.AsUnsignedLongLong(); - return (size) ? *size : LLDB_INVALID_ADDRESS; + if (!py_return.get()) + return llvm::None; + + StructuredData::ObjectSP structured_object( + py_return.CreateStructuredObject()); + if (!structured_object || !structured_object->IsValid()) + return llvm::None; + + switch (structured_object->GetType()) { + case lldb::eStructuredDataTypeInteger: + return structured_object->GetIntegerValue(); + case lldb::eStructuredDataTypeBoolean: + return structured_object->GetBooleanValue(); + default: + return llvm::None; } - return LLDB_INVALID_ADDRESS; } lldb::MemoryRegionInfoSP @@ -280,15 +296,17 @@ } lldb::pid_t ScriptedProcessPythonInterface::GetProcessID() { - size_t pid = GetGenericInteger("get_process_id"); - - return (pid >= std::numeric_limits::max()) - ? LLDB_INVALID_PROCESS_ID - : pid; + auto pid = GetGenericInteger("get_process_id"); + return (!pid) ? LLDB_INVALID_PROCESS_ID : *pid; } bool ScriptedProcessPythonInterface::IsAlive() { - return GetGenericInteger("is_alive"); + auto is_alive = GetGenericInteger("is_alive"); + + if (!is_alive) + return false; + + return static_cast(*is_alive); } #endif