diff options
author | Charles Zablit <c_zablit@apple.com> | 2025-04-30 12:44:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-30 11:44:19 +0100 |
commit | b3d130279f5c59a82d48d4647bef626ac4e202cf (patch) | |
tree | 0da0af37fec618f40d3b0b5a7a593d554308fdd8 /lldb/source/Plugins/ScriptInterpreter/Python | |
parent | 92195f6fc873cd27a5aa0852252dfe44ccdc6ea0 (diff) | |
download | llvm-b3d130279f5c59a82d48d4647bef626ac4e202cf.zip llvm-b3d130279f5c59a82d48d4647bef626ac4e202cf.tar.gz llvm-b3d130279f5c59a82d48d4647bef626ac4e202cf.tar.bz2 |
[lldb] Upgrade `GetIndexOfChildWithName` to use `llvm::Expected` (#136693)
This patch replaces the use of `UINT32_MAX` as the error return value of
`GetIndexOfChildWithName` with `llvm::Expected`.
# Tasks to do in another PR
1. Replace `CalculateNumChildrenIgnoringErrors` with
`CalculateNumChildren`. See [this
comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2056319358).
2. Update `lldb_private::formatters::ExtractIndexFromString` to use
`llvm::Expected`. See [this
comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2054217536).
3. Create a new class which carries both user and internal errors. See
[this
comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2056439608).
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp | 12 | ||||
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h | 5 |
2 files changed, 10 insertions, 7 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 553ee7e..16c3226 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -2037,19 +2037,19 @@ lldb::ValueObjectSP ScriptInterpreterPythonImpl::GetChildAtIndex( return ret_val; } -int ScriptInterpreterPythonImpl::GetIndexOfChildWithName( +llvm::Expected<int> ScriptInterpreterPythonImpl::GetIndexOfChildWithName( const StructuredData::ObjectSP &implementor_sp, const char *child_name) { if (!implementor_sp) - return UINT32_MAX; + return llvm::createStringError("Type has no child named '%s'", child_name); StructuredData::Generic *generic = implementor_sp->GetAsGeneric(); if (!generic) - return UINT32_MAX; + return llvm::createStringError("Type has no child named '%s'", child_name); auto *implementor = static_cast<PyObject *>(generic->GetValue()); if (!implementor) - return UINT32_MAX; + return llvm::createStringError("Type has no child named '%s'", child_name); - int ret_val = UINT32_MAX; + int ret_val = INT32_MAX; { Locker py_lock(this, @@ -2058,6 +2058,8 @@ int ScriptInterpreterPythonImpl::GetIndexOfChildWithName( child_name); } + if (ret_val == INT32_MAX) + return llvm::createStringError("Type has no child named '%s'", child_name); return ret_val; } diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h index 0f290281..5d77608 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h @@ -128,8 +128,9 @@ public: GetChildAtIndex(const StructuredData::ObjectSP &implementor, uint32_t idx) override; - int GetIndexOfChildWithName(const StructuredData::ObjectSP &implementor, - const char *child_name) override; + llvm::Expected<int> + GetIndexOfChildWithName(const StructuredData::ObjectSP &implementor, + const char *child_name) override; bool UpdateSynthProviderInstance( const StructuredData::ObjectSP &implementor) override; |