aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
diff options
context:
space:
mode:
authorMed Ismail Bennani <medismail.bennani@gmail.com>2021-07-22 20:47:25 +0000
committerMed Ismail Bennani <medismail.bennani@gmail.com>2021-07-22 22:48:15 +0200
commit3d4cadfb26437bd686ca8177f5454a366fed59eb (patch)
treeaad98338f6430e9d11792f476bbb7b13ad2e3977 /lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
parent9dbc4b09afd4427c2def829f0c8283f732e654a0 (diff)
downloadllvm-3d4cadfb26437bd686ca8177f5454a366fed59eb.zip
llvm-3d4cadfb26437bd686ca8177f5454a366fed59eb.tar.gz
llvm-3d4cadfb26437bd686ca8177f5454a366fed59eb.tar.bz2
[lldb/Interpreter] Conform ScriptedProcessPythonInterface to SWIG python types
This patch should address the compiler warnings due to mismatch type comparaison. Differential Revision: https://reviews.llvm.org/D105788 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp48
1 files changed, 30 insertions, 18 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
index 51168f8..ce262c9 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -63,7 +63,13 @@ Status ScriptedProcessPythonInterface::Resume() {
}
bool ScriptedProcessPythonInterface::ShouldStop() {
- return GetGenericInteger("shuold_stop");
+ llvm::Optional<unsigned long long> should_stop =
+ GetGenericInteger("should_stop");
+
+ if (!should_stop)
+ return false;
+
+ return static_cast<bool>(*should_stop);
}
Status ScriptedProcessPythonInterface::Stop() {
@@ -134,21 +140,21 @@ Status ScriptedProcessPythonInterface::GetStatusFromMethod(
return Status("Returned object is null.");
}
-size_t
+llvm::Optional<unsigned long long>
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 +164,12 @@ ScriptedProcessPythonInterface::GetGenericInteger(llvm::StringRef method_name) {
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 +185,15 @@ ScriptedProcessPythonInterface::GetGenericInteger(llvm::StringRef method_name) {
PyErr_Clear();
}
- if (py_return.get()) {
- auto size = py_return.AsUnsignedLongLong();
- return (size) ? *size : LLDB_INVALID_ADDRESS;
- }
- return LLDB_INVALID_ADDRESS;
+ if (!py_return.get())
+ return llvm::None;
+
+ llvm::Expected<unsigned long long> size = py_return.AsUnsignedLongLong();
+ // FIXME: Handle error.
+ if (!size)
+ return llvm::None;
+
+ return *size;
}
lldb::MemoryRegionInfoSP
@@ -280,15 +290,17 @@ StructuredData::DictionarySP ScriptedProcessPythonInterface::GetLoadedImages() {
}
lldb::pid_t ScriptedProcessPythonInterface::GetProcessID() {
- size_t pid = GetGenericInteger("get_process_id");
-
- return (pid >= std::numeric_limits<lldb::pid_t>::max())
- ? LLDB_INVALID_PROCESS_ID
- : pid;
+ llvm::Optional<unsigned long long> pid = GetGenericInteger("get_process_id");
+ return (!pid) ? LLDB_INVALID_PROCESS_ID : *pid;
}
bool ScriptedProcessPythonInterface::IsAlive() {
- return GetGenericInteger("is_alive");
+ llvm::Optional<unsigned long long> is_alive = GetGenericInteger("is_alive");
+
+ if (!is_alive)
+ return false;
+
+ return static_cast<bool>(*is_alive);
}
#endif