From b3d130279f5c59a82d48d4647bef626ac4e202cf Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Wed, 30 Apr 2025 12:44:19 +0200 Subject: [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). --- lldb/source/DataFormatters/FormatterBytecode.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lldb/source/DataFormatters/FormatterBytecode.cpp') diff --git a/lldb/source/DataFormatters/FormatterBytecode.cpp b/lldb/source/DataFormatters/FormatterBytecode.cpp index 7f3dbe0dba37..714de74abcb3 100644 --- a/lldb/source/DataFormatters/FormatterBytecode.cpp +++ b/lldb/source/DataFormatters/FormatterBytecode.cpp @@ -9,6 +9,7 @@ #include "FormatterBytecode.h" #include "lldb/Utility/LLDBLog.h" #include "lldb/ValueObject/ValueObject.h" +#include "lldb/ValueObject/ValueObjectConstResult.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/DataExtractor.h" #include "llvm/Support/Format.h" @@ -489,7 +490,10 @@ llvm::Error Interpret(std::vector &control, TYPE_CHECK(Object, String); auto name = data.Pop(); POP_VALOBJ(valobj); - data.Push((uint64_t)valobj->GetIndexOfChildWithName(name)); + if (auto index_or_err = valobj->GetIndexOfChildWithName(name)) + data.Push((uint64_t)*index_or_err); + else + return index_or_err.takeError(); break; } case sel_get_type: { -- cgit v1.2.3