[Lldb-commits] [lldb] Change GetNumChildren()/CalculateNumChildren() methods return llvm::Expected (PR #84219)
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Fri Mar 8 09:53:44 PST 2024
https://github.com/adrian-prantl updated https://github.com/llvm/llvm-project/pull/84219
>From 97a80ffa93d9fd648f0aa995b51981f0ad949530 Mon Sep 17 00:00:00 2001
From: Adrian Prantl <aprantl at apple.com>
Date: Thu, 7 Mar 2024 13:03:14 -0800
Subject: [PATCH] Let GetNumChildren()/CalculateNumChildren() return
llvm::Expected
This is an NFC change that does not yet add any error handling or
change any code to return any errors. Some select APIs may
legitimately not care about errors, so this patch also adds a
GetNumChildrenIgnoringErrors() variant to the API.
As we convert more APIs to returning llvm::Expected, we expect the
number of calls to GetNumChildrenIgnoringErrors() to dwindle.
---
lldb/include/lldb/Core/ValueObject.h | 11 +++-
lldb/include/lldb/Core/ValueObjectCast.h | 2 +-
lldb/include/lldb/Core/ValueObjectChild.h | 2 +-
.../lldb/Core/ValueObjectConstResult.h | 2 +-
.../lldb/Core/ValueObjectDynamicValue.h | 2 +-
lldb/include/lldb/Core/ValueObjectMemory.h | 2 +-
lldb/include/lldb/Core/ValueObjectRegister.h | 4 +-
.../lldb/Core/ValueObjectSyntheticFilter.h | 2 +-
lldb/include/lldb/Core/ValueObjectVTable.h | 2 +-
lldb/include/lldb/Core/ValueObjectVariable.h | 2 +-
.../lldb/DataFormatters/TypeSynthetic.h | 20 ++++--
.../lldb/DataFormatters/VectorIterator.h | 2 +-
lldb/include/lldb/Symbol/CompilerType.h | 5 +-
lldb/include/lldb/Symbol/Type.h | 2 +-
lldb/include/lldb/Symbol/TypeSystem.h | 7 +-
.../lldb/Target/StackFrameRecognizer.h | 3 +-
lldb/include/lldb/Utility/Log.h | 14 ++++
lldb/source/API/SBValue.cpp | 2 +-
lldb/source/Core/FormatEntity.cpp | 2 +-
lldb/source/Core/IOHandlerCursesGUI.cpp | 2 +-
lldb/source/Core/ValueObject.cpp | 31 ++++++---
lldb/source/Core/ValueObjectCast.cpp | 6 +-
lldb/source/Core/ValueObjectChild.cpp | 6 +-
lldb/source/Core/ValueObjectConstResult.cpp | 7 +-
lldb/source/Core/ValueObjectDynamicValue.cpp | 7 +-
lldb/source/Core/ValueObjectMemory.cpp | 10 ++-
lldb/source/Core/ValueObjectRegister.cpp | 12 ++--
.../Core/ValueObjectSyntheticFilter.cpp | 24 ++++---
lldb/source/Core/ValueObjectVTable.cpp | 6 +-
lldb/source/Core/ValueObjectVariable.cpp | 7 +-
lldb/source/DataFormatters/FormatManager.cpp | 13 ++--
lldb/source/DataFormatters/TypeSynthetic.cpp | 17 ++++-
.../DataFormatters/ValueObjectPrinter.cpp | 2 +-
lldb/source/DataFormatters/VectorType.cpp | 16 +++--
.../Clang/ClangExpressionSourceCode.cpp | 2 +-
.../TSan/InstrumentationRuntimeTSan.cpp | 4 +-
.../Language/CPlusPlus/BlockPointer.cpp | 4 +-
.../Plugins/Language/CPlusPlus/Coroutines.cpp | 8 ++-
.../Plugins/Language/CPlusPlus/Coroutines.h | 2 +-
.../Language/CPlusPlus/GenericBitset.cpp | 4 +-
.../Language/CPlusPlus/GenericOptional.cpp | 6 +-
.../Plugins/Language/CPlusPlus/LibCxx.cpp | 18 +++---
.../Plugins/Language/CPlusPlus/LibCxx.h | 8 +--
.../Language/CPlusPlus/LibCxxAtomic.cpp | 6 +-
.../CPlusPlus/LibCxxInitializerList.cpp | 6 +-
.../Plugins/Language/CPlusPlus/LibCxxList.cpp | 12 ++--
.../Plugins/Language/CPlusPlus/LibCxxMap.cpp | 14 ++--
.../Language/CPlusPlus/LibCxxQueue.cpp | 2 +-
.../CPlusPlus/LibCxxRangesRefView.cpp | 2 +-
.../Plugins/Language/CPlusPlus/LibCxxSpan.cpp | 6 +-
.../Language/CPlusPlus/LibCxxTuple.cpp | 4 +-
.../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 8 +--
.../Language/CPlusPlus/LibCxxValarray.cpp | 6 +-
.../Language/CPlusPlus/LibCxxVariant.cpp | 2 +-
.../Language/CPlusPlus/LibCxxVector.cpp | 14 ++--
.../Plugins/Language/CPlusPlus/LibStdcpp.cpp | 17 +++--
.../Language/CPlusPlus/LibStdcppTuple.cpp | 7 +-
.../CPlusPlus/LibStdcppUniquePointer.cpp | 5 +-
lldb/source/Plugins/Language/ObjC/Cocoa.cpp | 2 +-
lldb/source/Plugins/Language/ObjC/NSArray.cpp | 30 ++++-----
.../Plugins/Language/ObjC/NSDictionary.cpp | 64 +++++++++----------
lldb/source/Plugins/Language/ObjC/NSError.cpp | 2 +-
.../Plugins/Language/ObjC/NSException.cpp | 4 +-
.../Plugins/Language/ObjC/NSIndexPath.cpp | 6 +-
lldb/source/Plugins/Language/ObjC/NSSet.cpp | 32 +++++-----
.../AppleObjCRuntime/AppleObjCRuntime.cpp | 3 +-
.../TypeSystem/Clang/TypeSystemClang.cpp | 40 ++++++++----
.../TypeSystem/Clang/TypeSystemClang.h | 7 +-
lldb/source/Symbol/CompilerType.cpp | 5 +-
lldb/source/Symbol/Type.cpp | 2 +-
lldb/source/Symbol/Variable.cpp | 6 +-
lldb/source/Target/StackFrame.cpp | 19 +++---
72 files changed, 395 insertions(+), 248 deletions(-)
diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h
index b4d2c8098edc71..e7e35e2b2bffc0 100644
--- a/lldb/include/lldb/Core/ValueObject.h
+++ b/lldb/include/lldb/Core/ValueObject.h
@@ -476,7 +476,13 @@ class ValueObject {
virtual size_t GetIndexOfChildWithName(llvm::StringRef name);
- uint32_t GetNumChildren(uint32_t max = UINT32_MAX);
+ llvm::Expected<uint32_t> GetNumChildren(uint32_t max = UINT32_MAX);
+ /// Like \c GetNumChildren but returns 0 on error. You probably
+ /// shouldn't be using this function. It exists primarily to ease the
+ /// transition to more pervasive error handling while not all APIs
+ /// have been updated.
+ uint32_t GetNumChildrenIgnoringErrors(uint32_t max = UINT32_MAX);
+ bool HasChildren() { return GetNumChildrenIgnoringErrors() > 0; }
const Value &GetValue() const { return m_value; }
@@ -958,7 +964,8 @@ class ValueObject {
int32_t synthetic_index);
/// Should only be called by ValueObject::GetNumChildren().
- virtual uint32_t CalculateNumChildren(uint32_t max = UINT32_MAX) = 0;
+ virtual llvm::Expected<uint32_t>
+ CalculateNumChildren(uint32_t max = UINT32_MAX) = 0;
void SetNumChildren(uint32_t num_children);
diff --git a/lldb/include/lldb/Core/ValueObjectCast.h b/lldb/include/lldb/Core/ValueObjectCast.h
index 51c647680d5227..ba25e166f32688 100644
--- a/lldb/include/lldb/Core/ValueObjectCast.h
+++ b/lldb/include/lldb/Core/ValueObjectCast.h
@@ -33,7 +33,7 @@ class ValueObjectCast : public ValueObject {
std::optional<uint64_t> GetByteSize() override;
- uint32_t CalculateNumChildren(uint32_t max) override;
+ llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
lldb::ValueType GetValueType() const override;
diff --git a/lldb/include/lldb/Core/ValueObjectChild.h b/lldb/include/lldb/Core/ValueObjectChild.h
index 47a13be08bb83b..1f88e607cb5737 100644
--- a/lldb/include/lldb/Core/ValueObjectChild.h
+++ b/lldb/include/lldb/Core/ValueObjectChild.h
@@ -39,7 +39,7 @@ class ValueObjectChild : public ValueObject {
lldb::ValueType GetValueType() const override;
- uint32_t CalculateNumChildren(uint32_t max) override;
+ llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
ConstString GetTypeName() override;
diff --git a/lldb/include/lldb/Core/ValueObjectConstResult.h b/lldb/include/lldb/Core/ValueObjectConstResult.h
index 9f1246cf2a7874..37dc0867f26c9e 100644
--- a/lldb/include/lldb/Core/ValueObjectConstResult.h
+++ b/lldb/include/lldb/Core/ValueObjectConstResult.h
@@ -67,7 +67,7 @@ class ValueObjectConstResult : public ValueObject {
lldb::ValueType GetValueType() const override;
- uint32_t CalculateNumChildren(uint32_t max) override;
+ llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
ConstString GetTypeName() override;
diff --git a/lldb/include/lldb/Core/ValueObjectDynamicValue.h b/lldb/include/lldb/Core/ValueObjectDynamicValue.h
index 21a9b409fd5bd7..82c20eee0cd42d 100644
--- a/lldb/include/lldb/Core/ValueObjectDynamicValue.h
+++ b/lldb/include/lldb/Core/ValueObjectDynamicValue.h
@@ -43,7 +43,7 @@ class ValueObjectDynamicValue : public ValueObject {
ConstString GetDisplayTypeName() override;
- uint32_t CalculateNumChildren(uint32_t max) override;
+ llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
lldb::ValueType GetValueType() const override;
diff --git a/lldb/include/lldb/Core/ValueObjectMemory.h b/lldb/include/lldb/Core/ValueObjectMemory.h
index a74b325546b03c..a8fb0353d601b2 100644
--- a/lldb/include/lldb/Core/ValueObjectMemory.h
+++ b/lldb/include/lldb/Core/ValueObjectMemory.h
@@ -47,7 +47,7 @@ class ValueObjectMemory : public ValueObject {
ConstString GetDisplayTypeName() override;
- uint32_t CalculateNumChildren(uint32_t max) override;
+ llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
lldb::ValueType GetValueType() const override;
diff --git a/lldb/include/lldb/Core/ValueObjectRegister.h b/lldb/include/lldb/Core/ValueObjectRegister.h
index 6c470c1a686503..fec8566ba33d90 100644
--- a/lldb/include/lldb/Core/ValueObjectRegister.h
+++ b/lldb/include/lldb/Core/ValueObjectRegister.h
@@ -47,7 +47,7 @@ class ValueObjectRegisterSet : public ValueObject {
ConstString GetQualifiedTypeName() override;
- uint32_t CalculateNumChildren(uint32_t max) override;
+ llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
ValueObject *CreateChildAtIndex(size_t idx, bool synthetic_array_member,
int32_t synthetic_index) override;
@@ -95,7 +95,7 @@ class ValueObjectRegister : public ValueObject {
ConstString GetTypeName() override;
- uint32_t CalculateNumChildren(uint32_t max) override;
+ llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
bool SetValueFromCString(const char *value_str, Status &error) override;
diff --git a/lldb/include/lldb/Core/ValueObjectSyntheticFilter.h b/lldb/include/lldb/Core/ValueObjectSyntheticFilter.h
index 1e54babc94f395..ca6d6c728005db 100644
--- a/lldb/include/lldb/Core/ValueObjectSyntheticFilter.h
+++ b/lldb/include/lldb/Core/ValueObjectSyntheticFilter.h
@@ -47,7 +47,7 @@ class ValueObjectSynthetic : public ValueObject {
bool MightHaveChildren() override;
- uint32_t CalculateNumChildren(uint32_t max) override;
+ llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
lldb::ValueType GetValueType() const override;
diff --git a/lldb/include/lldb/Core/ValueObjectVTable.h b/lldb/include/lldb/Core/ValueObjectVTable.h
index e7e14fc83d7892..4662f395a4dde9 100644
--- a/lldb/include/lldb/Core/ValueObjectVTable.h
+++ b/lldb/include/lldb/Core/ValueObjectVTable.h
@@ -64,7 +64,7 @@ class ValueObjectVTable : public ValueObject {
std::optional<uint64_t> GetByteSize() override;
- uint32_t CalculateNumChildren(uint32_t max) override;
+ llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
ValueObject *CreateChildAtIndex(size_t idx, bool synthetic_array_member,
int32_t synthetic_index) override;
diff --git a/lldb/include/lldb/Core/ValueObjectVariable.h b/lldb/include/lldb/Core/ValueObjectVariable.h
index da270300df0b30..db3847f14a0b5a 100644
--- a/lldb/include/lldb/Core/ValueObjectVariable.h
+++ b/lldb/include/lldb/Core/ValueObjectVariable.h
@@ -46,7 +46,7 @@ class ValueObjectVariable : public ValueObject {
ConstString GetDisplayTypeName() override;
- uint32_t CalculateNumChildren(uint32_t max) override;
+ llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
lldb::ValueType GetValueType() const override;
diff --git a/lldb/include/lldb/DataFormatters/TypeSynthetic.h b/lldb/include/lldb/DataFormatters/TypeSynthetic.h
index 38f3ce0fa5f011..ede7442a02bf6a 100644
--- a/lldb/include/lldb/DataFormatters/TypeSynthetic.h
+++ b/lldb/include/lldb/DataFormatters/TypeSynthetic.h
@@ -38,13 +38,17 @@ class SyntheticChildrenFrontEnd {
virtual ~SyntheticChildrenFrontEnd() = default;
- virtual uint32_t CalculateNumChildren() = 0;
+ virtual llvm::Expected<uint32_t> CalculateNumChildren() = 0;
- virtual uint32_t CalculateNumChildren(uint32_t max) {
+ virtual llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) {
auto count = CalculateNumChildren();
- return count <= max ? count : max;
+ if (!count)
+ return count;
+ return *count <= max ? *count : max;
}
+ uint32_t CalculateNumChildrenIgnoringErrors(uint32_t max = UINT32_MAX);
+
virtual lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) = 0;
virtual size_t GetIndexOfChildWithName(ConstString name) = 0;
@@ -109,7 +113,7 @@ class SyntheticValueProviderFrontEnd : public SyntheticChildrenFrontEnd {
~SyntheticValueProviderFrontEnd() override = default;
- uint32_t CalculateNumChildren() override { return 0; }
+ llvm::Expected<uint32_t> CalculateNumChildren() override { return 0; }
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override { return nullptr; }
@@ -322,7 +326,9 @@ class TypeFilterImpl : public SyntheticChildren {
~FrontEnd() override = default;
- uint32_t CalculateNumChildren() override { return filter->GetCount(); }
+ llvm::Expected<uint32_t> CalculateNumChildren() override {
+ return filter->GetCount();
+ }
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override {
if (idx >= filter->GetCount())
@@ -426,9 +432,9 @@ class ScriptedSyntheticChildren : public SyntheticChildren {
bool IsValid();
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
- uint32_t CalculateNumChildren(uint32_t max) override;
+ llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
diff --git a/lldb/include/lldb/DataFormatters/VectorIterator.h b/lldb/include/lldb/DataFormatters/VectorIterator.h
index 7711b9de95dba8..70bcf50ca1b1d2 100644
--- a/lldb/include/lldb/DataFormatters/VectorIterator.h
+++ b/lldb/include/lldb/DataFormatters/VectorIterator.h
@@ -24,7 +24,7 @@ class VectorIteratorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
VectorIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp,
llvm::ArrayRef<ConstString> item_names);
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
diff --git a/lldb/include/lldb/Symbol/CompilerType.h b/lldb/include/lldb/Symbol/CompilerType.h
index 414c44275aaafc..c1dce4ccbf79c2 100644
--- a/lldb/include/lldb/Symbol/CompilerType.h
+++ b/lldb/include/lldb/Symbol/CompilerType.h
@@ -386,8 +386,9 @@ class CompilerType {
std::optional<size_t> GetTypeBitAlign(ExecutionContextScope *exe_scope) const;
- uint32_t GetNumChildren(bool omit_empty_base_classes,
- const ExecutionContext *exe_ctx) const;
+ llvm::Expected<uint32_t>
+ GetNumChildren(bool omit_empty_base_classes,
+ const ExecutionContext *exe_ctx) const;
lldb::BasicType GetBasicTypeEnumeration() const;
diff --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index acd1a769f13cd6..b5eac5fa732d67 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -440,7 +440,7 @@ class Type : public std::enable_shared_from_this<Type>, public UserID {
std::optional<uint64_t> GetByteSize(ExecutionContextScope *exe_scope);
- uint32_t GetNumChildren(bool omit_empty_base_classes);
+ llvm::Expected<uint32_t> GetNumChildren(bool omit_empty_base_classes);
bool IsAggregateType();
diff --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h
index 63829131556e87..f647fcbf1636ea 100644
--- a/lldb/include/lldb/Symbol/TypeSystem.h
+++ b/lldb/include/lldb/Symbol/TypeSystem.h
@@ -300,9 +300,10 @@ class TypeSystem : public PluginInterface,
virtual lldb::Format GetFormat(lldb::opaque_compiler_type_t type) = 0;
- virtual uint32_t GetNumChildren(lldb::opaque_compiler_type_t type,
- bool omit_empty_base_classes,
- const ExecutionContext *exe_ctx) = 0;
+ virtual llvm::Expected<uint32_t>
+ GetNumChildren(lldb::opaque_compiler_type_t type,
+ bool omit_empty_base_classes,
+ const ExecutionContext *exe_ctx) = 0;
virtual CompilerType GetBuiltinTypeByName(ConstString name);
diff --git a/lldb/include/lldb/Target/StackFrameRecognizer.h b/lldb/include/lldb/Target/StackFrameRecognizer.h
index e111f4a4dc7029..5e8e12b2a4e961 100644
--- a/lldb/include/lldb/Target/StackFrameRecognizer.h
+++ b/lldb/include/lldb/Target/StackFrameRecognizer.h
@@ -164,7 +164,8 @@ class ValueObjectRecognizerSynthesizedValue : public ValueObject {
m_value = m_parent->GetValue();
return true;
}
- uint32_t CalculateNumChildren(uint32_t max = UINT32_MAX) override {
+ llvm::Expected<uint32_t>
+ CalculateNumChildren(uint32_t max = UINT32_MAX) override {
return m_parent->GetNumChildren(max);
}
CompilerType GetCompilerTypeImpl() override {
diff --git a/lldb/include/lldb/Utility/Log.h b/lldb/include/lldb/Utility/Log.h
index 1fe28d61b9dacf..01876ad732d4b5 100644
--- a/lldb/include/lldb/Utility/Log.h
+++ b/lldb/include/lldb/Utility/Log.h
@@ -373,4 +373,18 @@ template <typename Cat> Log *GetLog(Cat mask) {
::llvm::consumeError(::std::move(error_private)); \
} while (0)
+// Write message to the verbose log, if error is set. In the log
+// message refer to the error with {0}. Error is cleared regardless of
+// whether logging is enabled.
+#define LLDB_LOG_ERRORV(log, error, ...) \
+ do { \
+ ::lldb_private::Log *log_private = (log); \
+ ::llvm::Error error_private = (error); \
+ if (log_private && log_private->GetVerbose() && error_private) { \
+ log_private->FormatError(::std::move(error_private), __FILE__, __func__, \
+ __VA_ARGS__); \
+ } else \
+ ::llvm::consumeError(::std::move(error_private)); \
+ } while (0)
+
#endif // LLDB_UTILITY_LOG_H
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 89d26a1fbe2824..94a8f3ea319e89 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -947,7 +947,7 @@ uint32_t SBValue::GetNumChildren(uint32_t max) {
ValueLocker locker;
lldb::ValueObjectSP value_sp(GetSP(locker));
if (value_sp)
- num_children = value_sp->GetNumChildren(max);
+ num_children = value_sp->GetNumChildrenIgnoringErrors(max);
return num_children;
}
diff --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp
index fa5eadc6ff4e9a..cf82676beddabe 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -926,7 +926,7 @@ static bool DumpValue(Stream &s, const SymbolContext *sc,
s.PutChar('[');
if (index_higher < 0)
- index_higher = valobj->GetNumChildren() - 1;
+ index_higher = valobj->GetNumChildrenIgnoringErrors() - 1;
uint32_t max_num_children =
target->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
diff --git a/lldb/source/Core/IOHandlerCursesGUI.cpp b/lldb/source/Core/IOHandlerCursesGUI.cpp
index 620e68a28510ef..f86dce247135f8 100644
--- a/lldb/source/Core/IOHandlerCursesGUI.cpp
+++ b/lldb/source/Core/IOHandlerCursesGUI.cpp
@@ -4519,7 +4519,7 @@ struct Row {
calculated_children = true;
ValueObjectSP valobj = value.GetSP();
if (valobj) {
- const size_t num_children = valobj->GetNumChildren();
+ const uint32_t num_children = valobj->GetNumChildrenIgnoringErrors();
for (size_t i = 0; i < num_children; ++i) {
children.push_back(Row(valobj->GetChildAtIndex(i), this));
}
diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp
index 0ed7f03be25c16..d813044d02ff5f 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -377,7 +377,7 @@ ValueObjectSP ValueObject::GetChildAtIndex(uint32_t idx, bool can_create) {
// We may need to update our value if we are dynamic
if (IsPossibleDynamicType())
UpdateValueIfNeeded(false);
- if (idx < GetNumChildren()) {
+ if (idx < GetNumChildrenIgnoringErrors()) {
// Check if we have already made the child value object?
if (can_create && !m_children.HasChildAtIndex(idx)) {
// No we haven't created the child at this index, so lets have our
@@ -440,7 +440,7 @@ ValueObjectSP ValueObject::GetChildMemberWithName(llvm::StringRef name,
return child_sp;
}
-uint32_t ValueObject::GetNumChildren(uint32_t max) {
+llvm::Expected<uint32_t> ValueObject::GetNumChildren(uint32_t max) {
UpdateValueIfNeeded();
if (max < UINT32_MAX) {
@@ -452,11 +452,24 @@ uint32_t ValueObject::GetNumChildren(uint32_t max) {
}
if (!m_flags.m_children_count_valid) {
- SetNumChildren(CalculateNumChildren());
+ auto num_children_or_err = CalculateNumChildren();
+ if (num_children_or_err)
+ SetNumChildren(*num_children_or_err);
+ else
+ return num_children_or_err;
}
return m_children.GetChildrenCount();
}
+uint32_t ValueObject::GetNumChildrenIgnoringErrors(uint32_t max) {
+ auto value_or_err = GetNumChildren(max);
+ if (value_or_err)
+ return *value_or_err;
+ LLDB_LOG_ERRORV(GetLog(LLDBLog::DataFormatters), value_or_err.takeError(),
+ "{0}");
+ return 0;
+}
+
bool ValueObject::MightHaveChildren() {
bool has_children = false;
const uint32_t type_info = GetTypeInfo();
@@ -464,7 +477,7 @@ bool ValueObject::MightHaveChildren() {
if (type_info & (eTypeHasChildren | eTypeIsPointer | eTypeIsReference))
has_children = true;
} else {
- has_children = GetNumChildren() > 0;
+ has_children = GetNumChildrenIgnoringErrors() > 0;
}
return has_children;
}
@@ -1176,7 +1189,7 @@ bool ValueObject::DumpPrintableRepresentation(
if (flags.Test(eTypeIsArray)) {
if ((custom_format == eFormatBytes) ||
(custom_format == eFormatBytesWithASCII)) {
- const size_t count = GetNumChildren();
+ const size_t count = GetNumChildrenIgnoringErrors();
s << '[';
for (size_t low = 0; low < count; low++) {
@@ -1215,7 +1228,7 @@ bool ValueObject::DumpPrintableRepresentation(
// format should be printed
// directly
{
- const size_t count = GetNumChildren();
+ const size_t count = GetNumChildrenIgnoringErrors();
Format format = FormatManager::GetSingleItemFormat(custom_format);
@@ -1294,7 +1307,7 @@ bool ValueObject::DumpPrintableRepresentation(
break;
case eValueObjectRepresentationStyleChildrenCount:
- strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
+ strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildrenIgnoringErrors());
str = strm.GetString();
break;
@@ -2320,7 +2333,9 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl(
child_valobj_sp = root->GetSyntheticArrayMember(index, true);
if (!child_valobj_sp)
if (root->HasSyntheticValue() &&
- root->GetSyntheticValue()->GetNumChildren() > index)
+ llvm::expectedToStdOptional(
+ root->GetSyntheticValue()->GetNumChildren())
+ .value_or(0) > index)
child_valobj_sp =
root->GetSyntheticValue()->GetChildAtIndex(index);
if (child_valobj_sp) {
diff --git a/lldb/source/Core/ValueObjectCast.cpp b/lldb/source/Core/ValueObjectCast.cpp
index a5c555f86b1372..c8e31641514170 100644
--- a/lldb/source/Core/ValueObjectCast.cpp
+++ b/lldb/source/Core/ValueObjectCast.cpp
@@ -41,11 +41,13 @@ ValueObjectCast::~ValueObjectCast() = default;
CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; }
-uint32_t ValueObjectCast::CalculateNumChildren(uint32_t max) {
+llvm::Expected<uint32_t> ValueObjectCast::CalculateNumChildren(uint32_t max) {
ExecutionContext exe_ctx(GetExecutionContextRef());
auto children_count = GetCompilerType().GetNumChildren(
true, &exe_ctx);
- return children_count <= max ? children_count : max;
+ if (!children_count)
+ return children_count;
+ return *children_count <= max ? *children_count : max;
}
std::optional<uint64_t> ValueObjectCast::GetByteSize() {
diff --git a/lldb/source/Core/ValueObjectChild.cpp b/lldb/source/Core/ValueObjectChild.cpp
index 2e55dd7726bdd9..c6a97dd1a5cd7e 100644
--- a/lldb/source/Core/ValueObjectChild.cpp
+++ b/lldb/source/Core/ValueObjectChild.cpp
@@ -49,10 +49,12 @@ lldb::ValueType ValueObjectChild::GetValueType() const {
return m_parent->GetValueType();
}
-uint32_t ValueObjectChild::CalculateNumChildren(uint32_t max) {
+llvm::Expected<uint32_t> ValueObjectChild::CalculateNumChildren(uint32_t max) {
ExecutionContext exe_ctx(GetExecutionContextRef());
auto children_count = GetCompilerType().GetNumChildren(true, &exe_ctx);
- return children_count <= max ? children_count : max;
+ if (!children_count)
+ return children_count;
+ return *children_count <= max ? *children_count : max;
}
static void AdjustForBitfieldness(ConstString &name,
diff --git a/lldb/source/Core/ValueObjectConstResult.cpp b/lldb/source/Core/ValueObjectConstResult.cpp
index 5c7aa4452b70db..8ac2c1cac2f665 100644
--- a/lldb/source/Core/ValueObjectConstResult.cpp
+++ b/lldb/source/Core/ValueObjectConstResult.cpp
@@ -216,10 +216,13 @@ std::optional<uint64_t> ValueObjectConstResult::GetByteSize() {
void ValueObjectConstResult::SetByteSize(size_t size) { m_byte_size = size; }
-uint32_t ValueObjectConstResult::CalculateNumChildren(uint32_t max) {
+llvm::Expected<uint32_t>
+ValueObjectConstResult::CalculateNumChildren(uint32_t max) {
ExecutionContext exe_ctx(GetExecutionContextRef());
auto children_count = GetCompilerType().GetNumChildren(true, &exe_ctx);
- return children_count <= max ? children_count : max;
+ if (!children_count)
+ return children_count;
+ return *children_count <= max ? *children_count : max;
}
ConstString ValueObjectConstResult::GetTypeName() {
diff --git a/lldb/source/Core/ValueObjectDynamicValue.cpp b/lldb/source/Core/ValueObjectDynamicValue.cpp
index 4e64760371ae52..4695febdf8ca12 100644
--- a/lldb/source/Core/ValueObjectDynamicValue.cpp
+++ b/lldb/source/Core/ValueObjectDynamicValue.cpp
@@ -85,12 +85,15 @@ ConstString ValueObjectDynamicValue::GetDisplayTypeName() {
return m_parent->GetDisplayTypeName();
}
-uint32_t ValueObjectDynamicValue::CalculateNumChildren(uint32_t max) {
+llvm::Expected<uint32_t>
+ValueObjectDynamicValue::CalculateNumChildren(uint32_t max) {
const bool success = UpdateValueIfNeeded(false);
if (success && m_dynamic_type_info.HasType()) {
ExecutionContext exe_ctx(GetExecutionContextRef());
auto children_count = GetCompilerType().GetNumChildren(true, &exe_ctx);
- return children_count <= max ? children_count : max;
+ if (!children_count)
+ return children_count;
+ return *children_count <= max ? *children_count : max;
} else
return m_parent->GetNumChildren(max);
}
diff --git a/lldb/source/Core/ValueObjectMemory.cpp b/lldb/source/Core/ValueObjectMemory.cpp
index 7f68236c7884ec..f555ab82f4418a 100644
--- a/lldb/source/Core/ValueObjectMemory.cpp
+++ b/lldb/source/Core/ValueObjectMemory.cpp
@@ -126,17 +126,21 @@ ConstString ValueObjectMemory::GetDisplayTypeName() {
return m_compiler_type.GetDisplayTypeName();
}
-uint32_t ValueObjectMemory::CalculateNumChildren(uint32_t max) {
+llvm::Expected<uint32_t> ValueObjectMemory::CalculateNumChildren(uint32_t max) {
if (m_type_sp) {
auto child_count = m_type_sp->GetNumChildren(true);
- return child_count <= max ? child_count : max;
+ if (!child_count)
+ return child_count;
+ return *child_count <= max ? *child_count : max;
}
ExecutionContext exe_ctx(GetExecutionContextRef());
const bool omit_empty_base_classes = true;
auto child_count =
m_compiler_type.GetNumChildren(omit_empty_base_classes, &exe_ctx);
- return child_count <= max ? child_count : max;
+ if (!child_count)
+ return child_count;
+ return *child_count <= max ? *child_count : max;
}
std::optional<uint64_t> ValueObjectMemory::GetByteSize() {
diff --git a/lldb/source/Core/ValueObjectRegister.cpp b/lldb/source/Core/ValueObjectRegister.cpp
index d4c144cc7edb9a..9d9da8bb119df2 100644
--- a/lldb/source/Core/ValueObjectRegister.cpp
+++ b/lldb/source/Core/ValueObjectRegister.cpp
@@ -74,7 +74,8 @@ ConstString ValueObjectRegisterSet::GetQualifiedTypeName() {
return ConstString();
}
-uint32_t ValueObjectRegisterSet::CalculateNumChildren(uint32_t max) {
+llvm::Expected<uint32_t>
+ValueObjectRegisterSet::CalculateNumChildren(uint32_t max) {
const RegisterSet *reg_set = m_reg_ctx_sp->GetRegisterSet(m_reg_set_idx);
if (reg_set) {
auto reg_count = reg_set->num_registers;
@@ -118,7 +119,7 @@ ValueObject *ValueObjectRegisterSet::CreateChildAtIndex(
size_t idx, bool synthetic_array_member, int32_t synthetic_index) {
ValueObject *valobj = nullptr;
if (m_reg_ctx_sp && m_reg_set) {
- const size_t num_children = GetNumChildren();
+ uint32_t num_children = GetNumChildrenIgnoringErrors();
if (idx < num_children)
valobj = new ValueObjectRegister(
*this, m_reg_ctx_sp,
@@ -220,10 +221,13 @@ ConstString ValueObjectRegister::GetTypeName() {
return m_type_name;
}
-uint32_t ValueObjectRegister::CalculateNumChildren(uint32_t max) {
+llvm::Expected<uint32_t>
+ValueObjectRegister::CalculateNumChildren(uint32_t max) {
ExecutionContext exe_ctx(GetExecutionContextRef());
auto children_count = GetCompilerType().GetNumChildren(true, &exe_ctx);
- return children_count <= max ? children_count : max;
+ if (!children_count)
+ return children_count;
+ return *children_count <= max ? *children_count : max;
}
std::optional<uint64_t> ValueObjectRegister::GetByteSize() {
diff --git a/lldb/source/Core/ValueObjectSyntheticFilter.cpp b/lldb/source/Core/ValueObjectSyntheticFilter.cpp
index 7f8a9a34cb35df..adac1b400705e2 100644
--- a/lldb/source/Core/ValueObjectSyntheticFilter.cpp
+++ b/lldb/source/Core/ValueObjectSyntheticFilter.cpp
@@ -31,7 +31,9 @@ class DummySyntheticFrontEnd : public SyntheticChildrenFrontEnd {
DummySyntheticFrontEnd(ValueObject &backend)
: SyntheticChildrenFrontEnd(backend) {}
- uint32_t CalculateNumChildren() override { return m_backend.GetNumChildren(); }
+ llvm::Expected<uint32_t> CalculateNumChildren() override {
+ return m_backend.GetNumChildren();
+ }
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override {
return m_backend.GetChildAtIndex(idx);
@@ -84,7 +86,8 @@ ConstString ValueObjectSynthetic::GetDisplayTypeName() {
return m_parent->GetDisplayTypeName();
}
-uint32_t ValueObjectSynthetic::CalculateNumChildren(uint32_t max) {
+llvm::Expected<uint32_t>
+ValueObjectSynthetic::CalculateNumChildren(uint32_t max) {
Log *log = GetLog(LLDBLog::DataFormatters);
UpdateValueIfNeeded();
@@ -92,18 +95,23 @@ uint32_t ValueObjectSynthetic::CalculateNumChildren(uint32_t max) {
return m_synthetic_children_count <= max ? m_synthetic_children_count : max;
if (max < UINT32_MAX) {
- size_t num_children = m_synth_filter_up->CalculateNumChildren(max);
+ auto num_children = m_synth_filter_up->CalculateNumChildren(max);
LLDB_LOGF(log,
"[ValueObjectSynthetic::CalculateNumChildren] for VO of name "
- "%s and type %s, the filter returned %zu child values",
- GetName().AsCString(), GetTypeName().AsCString(), num_children);
+ "%s and type %s, the filter returned %u child values",
+ GetName().AsCString(), GetTypeName().AsCString(),
+ num_children ? *num_children : 0);
return num_children;
} else {
- size_t num_children = (m_synthetic_children_count =
- m_synth_filter_up->CalculateNumChildren(max));
+ auto num_children_or_err = m_synth_filter_up->CalculateNumChildren(max);
+ if (!num_children_or_err) {
+ m_synthetic_children_count = 0;
+ return num_children_or_err;
+ }
+ auto num_children = (m_synthetic_children_count = *num_children_or_err);
LLDB_LOGF(log,
"[ValueObjectSynthetic::CalculateNumChildren] for VO of name "
- "%s and type %s, the filter returned %zu child values",
+ "%s and type %s, the filter returned %u child values",
GetName().AsCString(), GetTypeName().AsCString(), num_children);
return num_children;
}
diff --git a/lldb/source/Core/ValueObjectVTable.cpp b/lldb/source/Core/ValueObjectVTable.cpp
index 4d1cbb8d2f6fc2..9bfe8dc9700d30 100644
--- a/lldb/source/Core/ValueObjectVTable.cpp
+++ b/lldb/source/Core/ValueObjectVTable.cpp
@@ -33,7 +33,9 @@ class ValueObjectVTableChild : public ValueObject {
std::optional<uint64_t> GetByteSize() override { return m_addr_size; };
- uint32_t CalculateNumChildren(uint32_t max) override { return 0; };
+ llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override {
+ return 0;
+ };
ValueType GetValueType() const override { return eValueTypeVTableEntry; };
@@ -159,7 +161,7 @@ std::optional<uint64_t> ValueObjectVTable::GetByteSize() {
return std::nullopt;
}
-uint32_t ValueObjectVTable::CalculateNumChildren(uint32_t max) {
+llvm::Expected<uint32_t> ValueObjectVTable::CalculateNumChildren(uint32_t max) {
if (UpdateValueIfNeeded(false))
return m_num_vtable_entries <= max ? m_num_vtable_entries : max;
return 0;
diff --git a/lldb/source/Core/ValueObjectVariable.cpp b/lldb/source/Core/ValueObjectVariable.cpp
index dc62bb6358dc97..fb29c22c0ab5af 100644
--- a/lldb/source/Core/ValueObjectVariable.cpp
+++ b/lldb/source/Core/ValueObjectVariable.cpp
@@ -94,7 +94,8 @@ ConstString ValueObjectVariable::GetQualifiedTypeName() {
return ConstString();
}
-uint32_t ValueObjectVariable::CalculateNumChildren(uint32_t max) {
+llvm::Expected<uint32_t>
+ValueObjectVariable::CalculateNumChildren(uint32_t max) {
CompilerType type(GetCompilerType());
if (!type.IsValid())
@@ -103,7 +104,9 @@ uint32_t ValueObjectVariable::CalculateNumChildren(uint32_t max) {
ExecutionContext exe_ctx(GetExecutionContextRef());
const bool omit_empty_base_classes = true;
auto child_count = type.GetNumChildren(omit_empty_base_classes, &exe_ctx);
- return child_count <= max ? child_count : max;
+ if (!child_count)
+ return child_count;
+ return *child_count <= max ? *child_count : max;
}
std::optional<uint64_t> ValueObjectVariable::GetByteSize() {
diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp
index 092fa3c8ce496d..e7491a70b9115e 100644
--- a/lldb/source/DataFormatters/FormatManager.cpp
+++ b/lldb/source/DataFormatters/FormatManager.cpp
@@ -451,8 +451,13 @@ bool FormatManager::ShouldPrintAsOneLiner(ValueObject &valobj) {
if (valobj.GetSummaryFormat().get() != nullptr)
return valobj.GetSummaryFormat()->IsOneLiner();
+ auto num_children = valobj.GetNumChildren();
+ if (!num_children) {
+ llvm::consumeError(num_children.takeError());
+ return true;
+ }
// no children, no party
- if (valobj.GetNumChildren() == 0)
+ if (*num_children == 0)
return false;
// ask the type if it has any opinion about this eLazyBoolCalculate == no
@@ -471,7 +476,7 @@ bool FormatManager::ShouldPrintAsOneLiner(ValueObject &valobj) {
size_t total_children_name_len = 0;
- for (size_t idx = 0; idx < valobj.GetNumChildren(); idx++) {
+ for (size_t idx = 0; idx < *num_children; idx++) {
bool is_synth_val = false;
ValueObjectSP child_sp(valobj.GetChildAtIndex(idx));
// something is wrong here - bail out
@@ -523,7 +528,7 @@ bool FormatManager::ShouldPrintAsOneLiner(ValueObject &valobj) {
}
// if this child has children..
- if (child_sp->GetNumChildren()) {
+ if (child_sp->HasChildren()) {
// ...and no summary...
// (if it had a summary and the summary wanted children, we would have
// bailed out anyway
@@ -534,7 +539,7 @@ bool FormatManager::ShouldPrintAsOneLiner(ValueObject &valobj) {
// synthetic valued
// child
return false; // then bail out
- }
+ }
}
return true;
}
diff --git a/lldb/source/DataFormatters/TypeSynthetic.cpp b/lldb/source/DataFormatters/TypeSynthetic.cpp
index 0ae38c4d31f26b..e3f613606aa87e 100644
--- a/lldb/source/DataFormatters/TypeSynthetic.cpp
+++ b/lldb/source/DataFormatters/TypeSynthetic.cpp
@@ -115,6 +115,17 @@ std::string CXXSyntheticChildren::GetDescription() {
return std::string(sstr.GetString());
}
+uint32_t
+SyntheticChildrenFrontEnd::CalculateNumChildrenIgnoringErrors(uint32_t max) {
+ auto value_or_err = CalculateNumChildren(max);
+ if (value_or_err)
+ return *value_or_err;
+ Log *log = GetLog(LLDBLog::DataFormatters);
+ if (log && log->GetVerbose())
+ LLDB_LOG_ERROR(log, value_or_err.takeError(), "{0}");
+ return 0;
+}
+
lldb::ValueObjectSP SyntheticChildrenFrontEnd::CreateValueObjectFromExpression(
llvm::StringRef name, llvm::StringRef expression,
const ExecutionContext &exe_ctx) {
@@ -178,13 +189,15 @@ bool ScriptedSyntheticChildren::FrontEnd::IsValid() {
return (m_wrapper_sp && m_wrapper_sp->IsValid() && m_interpreter);
}
-uint32_t ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren() {
+llvm::Expected<uint32_t>
+ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren() {
if (!m_wrapper_sp || m_interpreter == nullptr)
return 0;
return m_interpreter->CalculateNumChildren(m_wrapper_sp, UINT32_MAX);
}
-uint32_t ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren(uint32_t max) {
+llvm::Expected<uint32_t>
+ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren(uint32_t max) {
if (!m_wrapper_sp || m_interpreter == nullptr)
return 0;
return m_interpreter->CalculateNumChildren(m_wrapper_sp, max);
diff --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
index 46e50a8d421a71..b853199e878c95 100644
--- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp
+++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
@@ -627,7 +627,7 @@ uint32_t ValueObjectPrinter::GetMaxNumChildrenToPrint(bool &print_dotdotdot) {
if (m_options.m_pointer_as_array)
return m_options.m_pointer_as_array.m_element_count;
- size_t num_children = synth_valobj.GetNumChildren();
+ uint32_t num_children = synth_valobj.GetNumChildrenIgnoringErrors();
print_dotdotdot = false;
if (num_children) {
const size_t max_num_children = GetMostSpecializedValue()
diff --git a/lldb/source/DataFormatters/VectorType.cpp b/lldb/source/DataFormatters/VectorType.cpp
index a0626a8cba7788..19de204c24353a 100644
--- a/lldb/source/DataFormatters/VectorType.cpp
+++ b/lldb/source/DataFormatters/VectorType.cpp
@@ -9,6 +9,7 @@
#include "lldb/DataFormatters/VectorType.h"
#include "lldb/Core/ValueObject.h"
+#include "lldb/Core/ValueObjectConstResult.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "lldb/Symbol/CompilerType.h"
#include "lldb/Symbol/TypeSystem.h"
@@ -224,10 +225,16 @@ class VectorTypeSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~VectorTypeSyntheticFrontEnd() override = default;
- uint32_t CalculateNumChildren() override { return m_num_children; }
+ llvm::Expected<uint32_t> CalculateNumChildren() override {
+ return m_num_children;
+ }
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override {
- if (idx >= CalculateNumChildren())
+ auto num_children_or_err = CalculateNumChildren();
+ if (!num_children_or_err)
+ return ValueObjectConstResult::Create(
+ nullptr, Status(num_children_or_err.takeError()));
+ if (idx >= *num_children_or_err)
return {};
std::optional<uint64_t> size = m_child_type.GetByteSize(nullptr);
if (!size)
@@ -266,7 +273,7 @@ class VectorTypeSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
size_t GetIndexOfChildWithName(ConstString name) override {
const char *item_name = name.GetCString();
uint32_t idx = ExtractIndexFromString(item_name);
- if (idx < UINT32_MAX && idx >= CalculateNumChildren())
+ if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
return UINT32_MAX;
return idx;
}
@@ -293,7 +300,8 @@ bool lldb_private::formatters::VectorTypeSummaryProvider(
s.PutChar('(');
bool first = true;
- size_t idx = 0, len = synthetic_children->CalculateNumChildren();
+ size_t idx = 0,
+ len = synthetic_children->CalculateNumChildrenIgnoringErrors();
for (; idx < len; idx++) {
auto child_sp = synthetic_children->GetChildAtIndex(idx);
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
index b48bbbecc0cd52..3d43ed3f99ffba 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
@@ -229,7 +229,7 @@ void AddLambdaCaptureDecls(StreamString &stream, StackFrame *frame,
assert(frame);
if (auto thisValSP = ClangExpressionUtil::GetLambdaValueObject(frame)) {
- uint32_t numChildren = thisValSP->GetNumChildren();
+ uint32_t numChildren = thisValSP->GetNumChildrenIgnoringErrors();
for (uint32_t i = 0; i < numChildren; ++i) {
auto childVal = thisValSP->GetChildAtIndex(i);
ConstString childName(childVal ? childVal->GetName() : ConstString(""));
diff --git a/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
index 72293c5331f40d..b2781aa5e7db15 100644
--- a/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
+++ b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
@@ -27,6 +27,8 @@
#include "lldb/Target/StopInfo.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
#include "lldb/Utility/RegularExpression.h"
#include "lldb/Utility/Stream.h"
@@ -211,7 +213,7 @@ CreateStackTrace(ValueObjectSP o,
auto trace_sp = std::make_shared<StructuredData::Array>();
ValueObjectSP trace_value_object =
o->GetValueForExpressionPath(trace_item_name.c_str());
- size_t count = trace_value_object->GetNumChildren();
+ size_t count = trace_value_object->GetNumChildrenIgnoringErrors();
for (size_t j = 0; j < count; j++) {
addr_t trace_addr =
trace_value_object->GetChildAtIndex(j)->GetValueAsUnsigned(0);
diff --git a/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp b/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
index ef0f67d1e9f9e7..9a6e135e008348 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
@@ -74,7 +74,7 @@ class BlockPointerSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~BlockPointerSyntheticFrontEnd() override = default;
- uint32_t CalculateNumChildren() override {
+ llvm::Expected<uint32_t> CalculateNumChildren() override {
const bool omit_empty_base_classes = false;
return m_block_struct_type.GetNumChildren(omit_empty_base_classes, nullptr);
}
@@ -84,7 +84,7 @@ class BlockPointerSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
return lldb::ValueObjectSP();
}
- if (idx >= CalculateNumChildren()) {
+ if (idx >= CalculateNumChildrenIgnoringErrors()) {
return lldb::ValueObjectSP();
}
diff --git a/lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp b/lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp
index 3827f9c21effab..5e63d1d7b21453 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp
@@ -11,6 +11,8 @@
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/VariableList.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
using namespace lldb;
using namespace lldb_private;
@@ -22,7 +24,7 @@ static lldb::addr_t GetCoroFramePtrFromHandle(ValueObjectSP valobj_sp) {
// We expect a single pointer in the `coroutine_handle` class.
// We don't care about its name.
- if (valobj_sp->GetNumChildren() != 1)
+ if (valobj_sp->GetNumChildrenIgnoringErrors() != 1)
return LLDB_INVALID_ADDRESS;
ValueObjectSP ptr_sp(valobj_sp->GetChildAtIndex(0));
if (!ptr_sp)
@@ -104,8 +106,8 @@ lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEnd::
lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEnd::
~StdlibCoroutineHandleSyntheticFrontEnd() = default;
-uint32_t lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ StdlibCoroutineHandleSyntheticFrontEnd::CalculateNumChildren() {
if (!m_resume_ptr_sp || !m_destroy_ptr_sp)
return 0;
diff --git a/lldb/source/Plugins/Language/CPlusPlus/Coroutines.h b/lldb/source/Plugins/Language/CPlusPlus/Coroutines.h
index 5c6a80b57ff424..1d4bc65e26374f 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/Coroutines.h
+++ b/lldb/source/Plugins/Language/CPlusPlus/Coroutines.h
@@ -34,7 +34,7 @@ class StdlibCoroutineHandleSyntheticFrontEnd
~StdlibCoroutineHandleSyntheticFrontEnd() override;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
diff --git a/lldb/source/Plugins/Language/CPlusPlus/GenericBitset.cpp b/lldb/source/Plugins/Language/CPlusPlus/GenericBitset.cpp
index 6a9da1d17c7620..33955dccb6ccc3 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/GenericBitset.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/GenericBitset.cpp
@@ -34,7 +34,9 @@ class GenericBitsetFrontEnd : public SyntheticChildrenFrontEnd {
bool MightHaveChildren() override { return true; }
lldb::ChildCacheState Update() override;
- uint32_t CalculateNumChildren() override { return m_elements.size(); }
+ llvm::Expected<uint32_t> CalculateNumChildren() override {
+ return m_elements.size();
+ }
ValueObjectSP GetChildAtIndex(uint32_t idx) override;
private:
diff --git a/lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp b/lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp
index c06afb53eb8aad..23756de7f1e66e 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp
@@ -19,7 +19,7 @@ using namespace lldb_private;
bool lldb_private::formatters::GenericOptionalSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
stream.Printf(" Has Value=%s ",
- valobj.GetNumChildren() == 0 ? "false" : "true");
+ valobj.GetNumChildrenIgnoringErrors() == 0 ? "false" : "true");
return true;
}
@@ -41,7 +41,9 @@ class GenericOptionalFrontend : public SyntheticChildrenFrontEnd {
}
bool MightHaveChildren() override { return true; }
- uint32_t CalculateNumChildren() override { return m_has_value ? 1U : 0U; }
+ llvm::Expected<uint32_t> CalculateNumChildren() override {
+ return m_has_value ? 1U : 0U;
+ }
ValueObjectSP GetChildAtIndex(uint32_t idx) override;
lldb::ChildCacheState Update() override;
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index bba887fec3ac3f..10a1fe03918984 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -63,7 +63,7 @@ lldb::ValueObjectSP
lldb_private::formatters::GetSecondValueOfLibCXXCompressedPair(
ValueObject &pair) {
ValueObjectSP value;
- if (pair.GetNumChildren() > 1) {
+ if (pair.GetNumChildrenIgnoringErrors() > 1) {
ValueObjectSP second_child = pair.GetChildAtIndex(1);
if (second_child) {
value = second_child->GetChildMemberWithName("__value_");
@@ -351,8 +351,8 @@ lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::Update() {
return lldb::ChildCacheState::eRefetch;
}
-uint32_t lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ LibCxxMapIteratorSyntheticFrontEnd::CalculateNumChildren() {
return 2;
}
@@ -509,8 +509,8 @@ lldb::ChildCacheState lldb_private::formatters::
return lldb::ChildCacheState::eRefetch;
}
-uint32_t lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ LibCxxUnorderedMapIteratorSyntheticFrontEnd::CalculateNumChildren() {
return 2;
}
@@ -566,8 +566,8 @@ lldb_private::formatters::LibcxxSharedPtrSyntheticFrontEnd::
Update();
}
-uint32_t lldb_private::formatters::LibcxxSharedPtrSyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ LibcxxSharedPtrSyntheticFrontEnd::CalculateNumChildren() {
return (m_cntrl ? 1 : 0);
}
@@ -661,8 +661,8 @@ lldb_private::formatters::LibcxxUniquePtrSyntheticFrontEndCreator(
: nullptr);
}
-uint32_t lldb_private::formatters::LibcxxUniquePtrSyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ LibcxxUniquePtrSyntheticFrontEnd::CalculateNumChildren() {
if (m_value_ptr_sp)
return m_deleter_sp ? 2 : 1;
return 0;
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
index ad2f58508ab7b6..a59f21841ec890 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
@@ -87,7 +87,7 @@ class LibCxxMapIteratorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
LibCxxMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -135,7 +135,7 @@ class LibCxxUnorderedMapIteratorSyntheticFrontEnd
~LibCxxUnorderedMapIteratorSyntheticFrontEnd() override = default;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -166,7 +166,7 @@ class LibcxxSharedPtrSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
LibcxxSharedPtrSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -186,7 +186,7 @@ class LibcxxUniquePtrSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
LibcxxUniquePtrSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxAtomic.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxAtomic.cpp
index 8e4c36103a744d..7f30dc186291e9 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxAtomic.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxAtomic.cpp
@@ -90,7 +90,7 @@ class LibcxxStdAtomicSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~LibcxxStdAtomicSyntheticFrontEnd() override = default;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -124,8 +124,8 @@ bool lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd::
return true;
}
-uint32_t lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ LibcxxStdAtomicSyntheticFrontEnd::CalculateNumChildren() {
return m_real_child ? 1 : 0;
}
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxInitializerList.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxInitializerList.cpp
index 00012dfc056e47..bd9c72497664a0 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxInitializerList.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxInitializerList.cpp
@@ -26,7 +26,7 @@ class LibcxxInitializerListSyntheticFrontEnd
~LibcxxInitializerListSyntheticFrontEnd() override;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -59,8 +59,8 @@ lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
// delete m_start;
}
-uint32_t lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ LibcxxInitializerListSyntheticFrontEnd::CalculateNumChildren() {
m_num_elements = 0;
ValueObjectSP size_sp(m_backend.GetChildMemberWithName("__size_"));
if (size_sp)
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
index 17f6b737d9f628..d7cfeb30557c36 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
@@ -136,7 +136,7 @@ class ForwardListFrontEnd : public AbstractListFrontEnd {
public:
ForwardListFrontEnd(ValueObject &valobj);
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
ValueObjectSP GetChildAtIndex(uint32_t idx) override;
lldb::ChildCacheState Update() override;
};
@@ -147,7 +147,7 @@ class ListFrontEnd : public AbstractListFrontEnd {
~ListFrontEnd() override = default;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -240,7 +240,7 @@ ForwardListFrontEnd::ForwardListFrontEnd(ValueObject &valobj)
Update();
}
-uint32_t ForwardListFrontEnd::CalculateNumChildren() {
+llvm::Expected<uint32_t> ForwardListFrontEnd::CalculateNumChildren() {
if (m_count != UINT32_MAX)
return m_count;
@@ -254,7 +254,7 @@ uint32_t ForwardListFrontEnd::CalculateNumChildren() {
}
ValueObjectSP ForwardListFrontEnd::GetChildAtIndex(uint32_t idx) {
- if (idx >= CalculateNumChildren())
+ if (idx >= CalculateNumChildrenIgnoringErrors())
return nullptr;
if (!m_head)
@@ -308,7 +308,7 @@ ListFrontEnd::ListFrontEnd(lldb::ValueObjectSP valobj_sp)
Update();
}
-uint32_t ListFrontEnd::CalculateNumChildren() {
+llvm::Expected<uint32_t> ListFrontEnd::CalculateNumChildren() {
if (m_count != UINT32_MAX)
return m_count;
if (!m_head || !m_tail || m_node_address == 0)
@@ -347,7 +347,7 @@ lldb::ValueObjectSP ListFrontEnd::GetChildAtIndex(uint32_t idx) {
static ConstString g_value("__value_");
static ConstString g_next("__next_");
- if (idx >= CalculateNumChildren())
+ if (idx >= CalculateNumChildrenIgnoringErrors())
return lldb::ValueObjectSP();
if (!m_head || !m_tail || m_node_address == 0)
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
index 6d24eb03779ca3..ec5b320e2218cf 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
@@ -177,7 +177,7 @@ class LibcxxStdMapSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~LibcxxStdMapSyntheticFrontEnd() override = default;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -209,8 +209,8 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::
Update();
}
-uint32_t lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ LibcxxStdMapSyntheticFrontEnd::CalculateNumChildren() {
if (m_count != UINT32_MAX)
return m_count;
@@ -311,13 +311,13 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex(
uint32_t idx) {
static ConstString g_cc_("__cc_"), g_cc("__cc");
static ConstString g_nc("__nc");
-
- if (idx >= CalculateNumChildren())
+ uint32_t num_children = CalculateNumChildrenIgnoringErrors();
+ if (idx >= num_children)
return lldb::ValueObjectSP();
if (m_tree == nullptr || m_root_node == nullptr)
return lldb::ValueObjectSP();
- MapIterator iterator(m_root_node, CalculateNumChildren());
+ MapIterator iterator(m_root_node, num_children);
const bool need_to_skip = (idx > 0);
size_t actual_advancde = idx;
@@ -382,7 +382,7 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex(
name.Printf("[%" PRIu64 "]", (uint64_t)idx);
auto potential_child_sp = iterated_sp->Clone(ConstString(name.GetString()));
if (potential_child_sp) {
- switch (potential_child_sp->GetNumChildren()) {
+ switch (potential_child_sp->GetNumChildrenIgnoringErrors()) {
case 1: {
auto child0_sp = potential_child_sp->GetChildAtIndex(0);
if (child0_sp &&
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxQueue.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxQueue.cpp
index fbadee89b7b7f2..5b459a17fe29ba 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxQueue.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxQueue.cpp
@@ -28,7 +28,7 @@ class QueueFrontEnd : public SyntheticChildrenFrontEnd {
bool MightHaveChildren() override { return true; }
lldb::ChildCacheState Update() override;
- uint32_t CalculateNumChildren() override {
+ llvm::Expected<uint32_t> CalculateNumChildren() override {
return m_container_sp ? m_container_sp->GetNumChildren() : 0;
}
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxRangesRefView.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxRangesRefView.cpp
index 74f54f76735667..01a7b8f142ecb9 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxRangesRefView.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxRangesRefView.cpp
@@ -27,7 +27,7 @@ class LibcxxStdRangesRefViewSyntheticFrontEnd
~LibcxxStdRangesRefViewSyntheticFrontEnd() override = default;
- uint32_t CalculateNumChildren() override {
+ llvm::Expected<uint32_t> CalculateNumChildren() override {
// __range_ will be the sole child of this type
return 1;
}
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxSpan.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxSpan.cpp
index af2b51d2b54016..9895f336bfd020 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxSpan.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxSpan.cpp
@@ -27,7 +27,7 @@ class LibcxxStdSpanSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~LibcxxStdSpanSyntheticFrontEnd() override = default;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -73,8 +73,8 @@ lldb_private::formatters::LibcxxStdSpanSyntheticFrontEnd::
Update();
}
-uint32_t lldb_private::formatters::LibcxxStdSpanSyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ LibcxxStdSpanSyntheticFrontEnd::CalculateNumChildren() {
return m_num_elements;
}
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxTuple.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxTuple.cpp
index 62bb7d619267a3..3e3259ab428df3 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxTuple.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxTuple.cpp
@@ -26,7 +26,9 @@ class TupleFrontEnd: public SyntheticChildrenFrontEnd {
bool MightHaveChildren() override { return true; }
lldb::ChildCacheState Update() override;
- uint32_t CalculateNumChildren() override { return m_elements.size(); }
+ llvm::Expected<uint32_t> CalculateNumChildren() override {
+ return m_elements.size();
+ }
ValueObjectSP GetChildAtIndex(uint32_t idx) override;
private:
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
index b3c36429433570..af29fdb6d00109 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
@@ -33,7 +33,7 @@ class LibcxxStdUnorderedMapSyntheticFrontEnd
~LibcxxStdUnorderedMapSyntheticFrontEnd() override = default;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -62,8 +62,8 @@ lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::
Update();
}
-uint32_t lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ LibcxxStdUnorderedMapSyntheticFrontEnd::CalculateNumChildren() {
return m_num_elements;
}
@@ -94,7 +94,7 @@ static bool isUnorderedMap(ConstString type_name) {
lldb::ValueObjectSP lldb_private::formatters::
LibcxxStdUnorderedMapSyntheticFrontEnd::GetChildAtIndex(uint32_t idx) {
- if (idx >= CalculateNumChildren())
+ if (idx >= CalculateNumChildrenIgnoringErrors())
return lldb::ValueObjectSP();
if (m_tree == nullptr)
return lldb::ValueObjectSP();
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxValarray.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxValarray.cpp
index 463c7b8d7ce3bb..99f94406e99a6a 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxValarray.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxValarray.cpp
@@ -24,7 +24,7 @@ class LibcxxStdValarraySyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~LibcxxStdValarraySyntheticFrontEnd() override;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -63,8 +63,8 @@ lldb_private::formatters::LibcxxStdValarraySyntheticFrontEnd::
// delete m_finish;
}
-uint32_t lldb_private::formatters::LibcxxStdValarraySyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ LibcxxStdValarraySyntheticFrontEnd::CalculateNumChildren() {
if (!m_start || !m_finish)
return 0;
uint64_t start_val = m_start->GetValueAsUnsigned(0);
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
index 1f62062f09be30..62794318e0777c 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
@@ -205,7 +205,7 @@ class VariantFrontEnd : public SyntheticChildrenFrontEnd {
bool MightHaveChildren() override { return true; }
lldb::ChildCacheState Update() override;
- uint32_t CalculateNumChildren() override { return m_size; }
+ llvm::Expected<uint32_t> CalculateNumChildren() override { return m_size; }
ValueObjectSP GetChildAtIndex(uint32_t idx) override;
private:
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp
index fcf727ad2ea027..461fed35164b4d 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp
@@ -25,7 +25,7 @@ class LibcxxStdVectorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~LibcxxStdVectorSyntheticFrontEnd() override;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -46,7 +46,7 @@ class LibcxxVectorBoolSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
LibcxxVectorBoolSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -82,8 +82,8 @@ lldb_private::formatters::LibcxxStdVectorSyntheticFrontEnd::
// delete m_finish;
}
-uint32_t lldb_private::formatters::LibcxxStdVectorSyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ LibcxxStdVectorSyntheticFrontEnd::CalculateNumChildren() {
if (!m_start || !m_finish)
return 0;
uint64_t start_val = m_start->GetValueAsUnsigned(0);
@@ -165,8 +165,8 @@ lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::
}
}
-uint32_t lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ LibcxxVectorBoolSyntheticFrontEnd::CalculateNumChildren() {
return m_count;
}
@@ -259,7 +259,7 @@ size_t lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::
return UINT32_MAX;
const char *item_name = name.GetCString();
uint32_t idx = ExtractIndexFromString(item_name);
- if (idx < UINT32_MAX && idx >= CalculateNumChildren())
+ if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
return UINT32_MAX;
return idx;
}
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
index 5abb3d50674bc5..86bb575af5ca34 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
@@ -43,7 +43,7 @@ class LibstdcppMapIteratorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
explicit LibstdcppMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -64,7 +64,7 @@ class LibStdcppSharedPtrSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
explicit LibStdcppSharedPtrSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -132,7 +132,8 @@ lldb::ChildCacheState LibstdcppMapIteratorSyntheticFrontEnd::Update() {
return lldb::ChildCacheState::eReuse;
}
-uint32_t LibstdcppMapIteratorSyntheticFrontEnd::CalculateNumChildren() {
+llvm::Expected<uint32_t>
+LibstdcppMapIteratorSyntheticFrontEnd::CalculateNumChildren() {
return 2;
}
@@ -219,7 +220,10 @@ lldb::ChildCacheState VectorIteratorSyntheticFrontEnd::Update() {
return lldb::ChildCacheState::eRefetch;
}
-uint32_t VectorIteratorSyntheticFrontEnd::CalculateNumChildren() { return 1; }
+llvm::Expected<uint32_t>
+VectorIteratorSyntheticFrontEnd::CalculateNumChildren() {
+ return 1;
+}
lldb::ValueObjectSP
VectorIteratorSyntheticFrontEnd::GetChildAtIndex(uint32_t idx) {
@@ -371,7 +375,10 @@ LibStdcppSharedPtrSyntheticFrontEnd::LibStdcppSharedPtrSyntheticFrontEnd(
Update();
}
-uint32_t LibStdcppSharedPtrSyntheticFrontEnd::CalculateNumChildren() { return 1; }
+llvm::Expected<uint32_t>
+LibStdcppSharedPtrSyntheticFrontEnd::CalculateNumChildren() {
+ return 1;
+}
lldb::ValueObjectSP
LibStdcppSharedPtrSyntheticFrontEnd::GetChildAtIndex(uint32_t idx) {
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp
index 64d2ec9d943a2a..05199ba35b9a45 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp
@@ -26,7 +26,7 @@ class LibStdcppTupleSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
explicit LibStdcppTupleSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -65,7 +65,7 @@ lldb::ChildCacheState LibStdcppTupleSyntheticFrontEnd::Update() {
ValueObjectSP current_child = next_child_sp;
next_child_sp = nullptr;
- size_t child_count = current_child->GetNumChildren();
+ size_t child_count = current_child->GetNumChildrenIgnoringErrors();
for (size_t i = 0; i < child_count; ++i) {
ValueObjectSP child_sp = current_child->GetChildAtIndex(i);
llvm::StringRef name_str = child_sp->GetName().GetStringRef();
@@ -95,7 +95,8 @@ LibStdcppTupleSyntheticFrontEnd::GetChildAtIndex(uint32_t idx) {
return lldb::ValueObjectSP();
}
-uint32_t LibStdcppTupleSyntheticFrontEnd::CalculateNumChildren() {
+llvm::Expected<uint32_t>
+LibStdcppTupleSyntheticFrontEnd::CalculateNumChildren() {
return m_members.size();
}
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp
index 3a48fe412e0721..92f540d9ca5233 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp
@@ -26,7 +26,7 @@ class LibStdcppUniquePtrSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
explicit LibStdcppUniquePtrSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -135,7 +135,8 @@ LibStdcppUniquePtrSyntheticFrontEnd::GetChildAtIndex(uint32_t idx) {
return lldb::ValueObjectSP();
}
-uint32_t LibStdcppUniquePtrSyntheticFrontEnd::CalculateNumChildren() {
+llvm::Expected<uint32_t>
+LibStdcppUniquePtrSyntheticFrontEnd::CalculateNumChildren() {
if (m_del_obj)
return 2;
return 1;
diff --git a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
index cb740f8e71e168..96166657ceeb62 100644
--- a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
+++ b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
@@ -1038,7 +1038,7 @@ class ObjCClassSyntheticChildrenFrontEnd : public SyntheticChildrenFrontEnd {
~ObjCClassSyntheticChildrenFrontEnd() override = default;
- uint32_t CalculateNumChildren() override { return 0; }
+ llvm::Expected<uint32_t> CalculateNumChildren() override { return 0; }
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override {
return lldb::ValueObjectSP();
diff --git a/lldb/source/Plugins/Language/ObjC/NSArray.cpp b/lldb/source/Plugins/Language/ObjC/NSArray.cpp
index 7f060b2613d6f3..67d0cd08f51aeb 100644
--- a/lldb/source/Plugins/Language/ObjC/NSArray.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSArray.cpp
@@ -50,7 +50,7 @@ class NSArrayMSyntheticFrontEndBase : public SyntheticChildrenFrontEnd {
~NSArrayMSyntheticFrontEndBase() override = default;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -214,7 +214,7 @@ class GenericNSArrayISyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~GenericNSArrayISyntheticFrontEnd() override;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -302,7 +302,7 @@ class NSArray0SyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~NSArray0SyntheticFrontEnd() override = default;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -319,7 +319,7 @@ class NSArray1SyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~NSArray1SyntheticFrontEnd() override = default;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -477,15 +477,15 @@ lldb_private::formatters::
: NSArrayMSyntheticFrontEndBase(valobj_sp), m_data_32(nullptr),
m_data_64(nullptr) {}
-uint32_t lldb_private::formatters::NSArrayMSyntheticFrontEndBase::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ NSArrayMSyntheticFrontEndBase::CalculateNumChildren() {
return GetUsedCount();
}
lldb::ValueObjectSP
lldb_private::formatters::NSArrayMSyntheticFrontEndBase::GetChildAtIndex(
uint32_t idx) {
- if (idx >= CalculateNumChildren())
+ if (idx >= CalculateNumChildrenIgnoringErrors())
return lldb::ValueObjectSP();
lldb::addr_t object_at_idx = GetDataAddress();
size_t pyhs_idx = idx;
@@ -542,7 +542,7 @@ lldb_private::formatters::NSArrayMSyntheticFrontEndBase::GetIndexOfChildWithName
ConstString name) {
const char *item_name = name.GetCString();
uint32_t idx = ExtractIndexFromString(item_name);
- if (idx < UINT32_MAX && idx >= CalculateNumChildren())
+ if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
return UINT32_MAX;
return idx;
}
@@ -628,15 +628,15 @@ lldb_private::formatters::GenericNSArrayISyntheticFrontEnd<D32, D64, Inline>::
GetIndexOfChildWithName(ConstString name) {
const char *item_name = name.GetCString();
uint32_t idx = ExtractIndexFromString(item_name);
- if (idx < UINT32_MAX && idx >= CalculateNumChildren())
+ if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
return UINT32_MAX;
return idx;
}
template <typename D32, typename D64, bool Inline>
-uint32_t
-lldb_private::formatters::GenericNSArrayISyntheticFrontEnd<D32, D64, Inline>::
- CalculateNumChildren() {
+llvm::Expected<uint32_t>
+lldb_private::formatters::GenericNSArrayISyntheticFrontEnd<
+ D32, D64, Inline>::CalculateNumChildren() {
return m_data_32 ? m_data_32->used : m_data_64->used;
}
@@ -685,7 +685,7 @@ template <typename D32, typename D64, bool Inline>
lldb::ValueObjectSP
lldb_private::formatters::GenericNSArrayISyntheticFrontEnd<D32, D64, Inline>::
GetChildAtIndex(uint32_t idx) {
- if (idx >= CalculateNumChildren())
+ if (idx >= CalculateNumChildrenIgnoringErrors())
return lldb::ValueObjectSP();
lldb::addr_t object_at_idx;
if (Inline) {
@@ -719,7 +719,7 @@ lldb_private::formatters::NSArray0SyntheticFrontEnd::GetIndexOfChildWithName(
return UINT32_MAX;
}
-uint32_t
+llvm::Expected<uint32_t>
lldb_private::formatters::NSArray0SyntheticFrontEnd::CalculateNumChildren() {
return 0;
}
@@ -754,7 +754,7 @@ lldb_private::formatters::NSArray1SyntheticFrontEnd::GetIndexOfChildWithName(
return UINT32_MAX;
}
-uint32_t
+llvm::Expected<uint32_t>
lldb_private::formatters::NSArray1SyntheticFrontEnd::CalculateNumChildren() {
return 1;
}
diff --git a/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp b/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
index da94eda1529ce1..ec6fd756394a2f 100644
--- a/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
@@ -103,7 +103,7 @@ class NSDictionaryISyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~NSDictionaryISyntheticFrontEnd() override;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -144,7 +144,7 @@ class NSConstantDictionarySyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
NSConstantDictionarySyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -176,7 +176,7 @@ class NSCFDictionarySyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
NSCFDictionarySyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -209,7 +209,7 @@ class NSDictionary1SyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~NSDictionary1SyntheticFrontEnd() override = default;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -230,7 +230,7 @@ class GenericNSDictionaryMSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~GenericNSDictionaryMSyntheticFrontEnd() override;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -262,9 +262,9 @@ namespace Foundation1100 {
NSDictionaryMSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
~NSDictionaryMSyntheticFrontEnd() override;
-
- uint32_t CalculateNumChildren() override;
-
+
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
+
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
lldb::ChildCacheState Update() override;
@@ -601,13 +601,13 @@ size_t lldb_private::formatters::NSDictionaryISyntheticFrontEnd::
GetIndexOfChildWithName(ConstString name) {
const char *item_name = name.GetCString();
uint32_t idx = ExtractIndexFromString(item_name);
- if (idx < UINT32_MAX && idx >= CalculateNumChildren())
+ if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
return UINT32_MAX;
return idx;
}
-uint32_t lldb_private::formatters::NSDictionaryISyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ NSDictionaryISyntheticFrontEnd::CalculateNumChildren() {
if (!m_data_32 && !m_data_64)
return 0;
return (m_data_32 ? m_data_32->_used : m_data_64->_used);
@@ -656,7 +656,7 @@ bool lldb_private::formatters::NSDictionaryISyntheticFrontEnd::
lldb::ValueObjectSP
lldb_private::formatters::NSDictionaryISyntheticFrontEnd::GetChildAtIndex(
uint32_t idx) {
- uint32_t num_children = CalculateNumChildren();
+ uint32_t num_children = CalculateNumChildrenIgnoringErrors();
if (idx >= num_children)
return lldb::ValueObjectSP();
@@ -739,13 +739,13 @@ size_t lldb_private::formatters::NSCFDictionarySyntheticFrontEnd::
GetIndexOfChildWithName(ConstString name) {
const char *item_name = name.GetCString();
const uint32_t idx = ExtractIndexFromString(item_name);
- if (idx < UINT32_MAX && idx >= CalculateNumChildren())
+ if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
return UINT32_MAX;
return idx;
}
-uint32_t lldb_private::formatters::NSCFDictionarySyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ NSCFDictionarySyntheticFrontEnd::CalculateNumChildren() {
if (!m_hashtable.IsValid())
return 0;
return m_hashtable.GetCount();
@@ -781,7 +781,7 @@ lldb_private::formatters::NSCFDictionarySyntheticFrontEnd::GetChildAtIndex(
lldb::addr_t m_keys_ptr = m_hashtable.GetKeyPointer();
lldb::addr_t m_values_ptr = m_hashtable.GetValuePointer();
- const uint32_t num_children = CalculateNumChildren();
+ const uint32_t num_children = CalculateNumChildrenIgnoringErrors();
if (idx >= num_children)
return lldb::ValueObjectSP();
@@ -875,13 +875,13 @@ size_t lldb_private::formatters::NSConstantDictionarySyntheticFrontEnd::
GetIndexOfChildWithName(ConstString name) {
const char *item_name = name.GetCString();
uint32_t idx = ExtractIndexFromString(item_name);
- if (idx < UINT32_MAX && idx >= CalculateNumChildren())
+ if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
return UINT32_MAX;
return idx;
}
-uint32_t lldb_private::formatters::NSConstantDictionarySyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ NSConstantDictionarySyntheticFrontEnd::CalculateNumChildren() {
return m_size;
}
@@ -921,7 +921,7 @@ bool lldb_private::formatters::NSConstantDictionarySyntheticFrontEnd::
lldb::ValueObjectSP lldb_private::formatters::
NSConstantDictionarySyntheticFrontEnd::GetChildAtIndex(uint32_t idx) {
- uint32_t num_children = CalculateNumChildren();
+ uint32_t num_children = CalculateNumChildrenIgnoringErrors();
if (idx >= num_children)
return lldb::ValueObjectSP();
@@ -994,8 +994,8 @@ size_t lldb_private::formatters::NSDictionary1SyntheticFrontEnd::
return name == g_zero ? 0 : UINT32_MAX;
}
-uint32_t lldb_private::formatters::NSDictionary1SyntheticFrontEnd::
- CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::
+ NSDictionary1SyntheticFrontEnd::CalculateNumChildren() {
return 1;
}
@@ -1081,17 +1081,18 @@ size_t lldb_private::formatters::GenericNSDictionaryMSyntheticFrontEnd<
D32, D64>::GetIndexOfChildWithName(ConstString name) {
const char *item_name = name.GetCString();
uint32_t idx = ExtractIndexFromString(item_name);
- if (idx < UINT32_MAX && idx >= CalculateNumChildren())
+ if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
return UINT32_MAX;
return idx;
}
template <typename D32, typename D64>
-uint32_t
-lldb_private::formatters::GenericNSDictionaryMSyntheticFrontEnd<D32,D64>::CalculateNumChildren() {
+llvm::Expected<uint32_t>
+lldb_private::formatters::GenericNSDictionaryMSyntheticFrontEnd<
+ D32, D64>::CalculateNumChildren() {
if (!m_data_32 && !m_data_64)
return 0;
- return (m_data_32 ? m_data_32->_used : m_data_64->_used);
+ return (m_data_32 ? (uint32_t)m_data_32->_used : (uint32_t)m_data_64->_used);
}
template <typename D32, typename D64>
@@ -1153,7 +1154,7 @@ lldb_private::formatters::GenericNSDictionaryMSyntheticFrontEnd<
m_values_ptr = m_data_64->_buffer + (m_ptr_size * size);
}
- uint32_t num_children = CalculateNumChildren();
+ uint32_t num_children = CalculateNumChildrenIgnoringErrors();
if (idx >= num_children)
return lldb::ValueObjectSP();
@@ -1245,14 +1246,13 @@ lldb_private::formatters::Foundation1100::
NSDictionaryMSyntheticFrontEnd::GetIndexOfChildWithName(ConstString name) {
const char *item_name = name.GetCString();
uint32_t idx = ExtractIndexFromString(item_name);
- if (idx < UINT32_MAX && idx >= CalculateNumChildren())
+ if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
return UINT32_MAX;
return idx;
}
-uint32_t
-lldb_private::formatters::Foundation1100::
- NSDictionaryMSyntheticFrontEnd::CalculateNumChildren() {
+llvm::Expected<uint32_t> lldb_private::formatters::Foundation1100::
+ NSDictionaryMSyntheticFrontEnd::CalculateNumChildren() {
if (!m_data_32 && !m_data_64)
return 0;
return (m_data_32 ? m_data_32->_used : m_data_64->_used);
@@ -1306,7 +1306,7 @@ lldb_private::formatters::Foundation1100::
lldb::addr_t m_values_ptr =
(m_data_32 ? m_data_32->_objs_addr : m_data_64->_objs_addr);
- uint32_t num_children = CalculateNumChildren();
+ uint32_t num_children = CalculateNumChildrenIgnoringErrors();
if (idx >= num_children)
return lldb::ValueObjectSP();
diff --git a/lldb/source/Plugins/Language/ObjC/NSError.cpp b/lldb/source/Plugins/Language/ObjC/NSError.cpp
index b034e799b716e7..5ef7edc7e80c1a 100644
--- a/lldb/source/Plugins/Language/ObjC/NSError.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSError.cpp
@@ -116,7 +116,7 @@ class NSErrorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
// no need to delete m_child_ptr - it's kept alive by the cluster manager on
// our behalf
- uint32_t CalculateNumChildren() override {
+ llvm::Expected<uint32_t> CalculateNumChildren() override {
if (m_child_ptr)
return 1;
if (m_child_sp)
diff --git a/lldb/source/Plugins/Language/ObjC/NSException.cpp b/lldb/source/Plugins/Language/ObjC/NSException.cpp
index 09d3a1b42b747f..e7ce26ea4c6f50 100644
--- a/lldb/source/Plugins/Language/ObjC/NSException.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSException.cpp
@@ -123,9 +123,7 @@ class NSExceptionSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~NSExceptionSyntheticFrontEnd() override = default;
- uint32_t CalculateNumChildren() override {
- return 4;
- }
+ llvm::Expected<uint32_t> CalculateNumChildren() override { return 4; }
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override {
switch (idx) {
diff --git a/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp b/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp
index 10bb907c58ed42..a434cee09d3822 100644
--- a/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp
@@ -40,7 +40,9 @@ class NSIndexPathSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~NSIndexPathSyntheticFrontEnd() override = default;
- uint32_t CalculateNumChildren() override { return m_impl.GetNumIndexes(); }
+ llvm::Expected<uint32_t> CalculateNumChildren() override {
+ return m_impl.GetNumIndexes();
+ }
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override {
return m_impl.GetIndexAtIndex(idx, m_uint_star_type);
@@ -127,7 +129,7 @@ class NSIndexPathSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
size_t GetIndexOfChildWithName(ConstString name) override {
const char *item_name = name.GetCString();
uint32_t idx = ExtractIndexFromString(item_name);
- if (idx < UINT32_MAX && idx >= CalculateNumChildren())
+ if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
return UINT32_MAX;
return idx;
}
diff --git a/lldb/source/Plugins/Language/ObjC/NSSet.cpp b/lldb/source/Plugins/Language/ObjC/NSSet.cpp
index c965a2a1340030..7d0a6a507211f8 100644
--- a/lldb/source/Plugins/Language/ObjC/NSSet.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSSet.cpp
@@ -46,7 +46,7 @@ class NSSetISyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~NSSetISyntheticFrontEnd() override;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -84,7 +84,7 @@ class NSCFSetSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
NSCFSetSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -117,7 +117,7 @@ class GenericNSSetMSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~GenericNSSetMSyntheticFrontEnd() override;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -233,7 +233,7 @@ class NSSetCodeRunningSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
~NSSetCodeRunningSyntheticFrontEnd() override;
- uint32_t CalculateNumChildren() override;
+ llvm::Expected<uint32_t> CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
@@ -414,12 +414,12 @@ lldb_private::formatters::NSSetISyntheticFrontEnd::GetIndexOfChildWithName(
ConstString name) {
const char *item_name = name.GetCString();
uint32_t idx = ExtractIndexFromString(item_name);
- if (idx < UINT32_MAX && idx >= CalculateNumChildren())
+ if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
return UINT32_MAX;
return idx;
}
-uint32_t
+llvm::Expected<uint32_t>
lldb_private::formatters::NSSetISyntheticFrontEnd::CalculateNumChildren() {
if (!m_data_32 && !m_data_64)
return 0;
@@ -468,7 +468,7 @@ bool lldb_private::formatters::NSSetISyntheticFrontEnd::MightHaveChildren() {
lldb::ValueObjectSP
lldb_private::formatters::NSSetISyntheticFrontEnd::GetChildAtIndex(
uint32_t idx) {
- uint32_t num_children = CalculateNumChildren();
+ uint32_t num_children = CalculateNumChildrenIgnoringErrors();
if (idx >= num_children)
return lldb::ValueObjectSP();
@@ -551,12 +551,12 @@ lldb_private::formatters::NSCFSetSyntheticFrontEnd::GetIndexOfChildWithName(
ConstString name) {
const char *item_name = name.GetCString();
const uint32_t idx = ExtractIndexFromString(item_name);
- if (idx < UINT32_MAX && idx >= CalculateNumChildren())
+ if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
return UINT32_MAX;
return idx;
}
-uint32_t
+llvm::Expected<uint32_t>
lldb_private::formatters::NSCFSetSyntheticFrontEnd::CalculateNumChildren() {
if (!m_hashtable.IsValid())
return 0;
@@ -591,7 +591,7 @@ lldb_private::formatters::NSCFSetSyntheticFrontEnd::GetChildAtIndex(
uint32_t idx) {
lldb::addr_t m_values_ptr = m_hashtable.GetValuePointer();
- const uint32_t num_children = CalculateNumChildren();
+ const uint32_t num_children = CalculateNumChildrenIgnoringErrors();
if (idx >= num_children)
return lldb::ValueObjectSP();
@@ -691,18 +691,18 @@ lldb_private::formatters::
ConstString name) {
const char *item_name = name.GetCString();
uint32_t idx = ExtractIndexFromString(item_name);
- if (idx < UINT32_MAX && idx >= CalculateNumChildren())
+ if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
return UINT32_MAX;
return idx;
}
template <typename D32, typename D64>
-uint32_t
-lldb_private::formatters::
- GenericNSSetMSyntheticFrontEnd<D32, D64>::CalculateNumChildren() {
+llvm::Expected<uint32_t>
+lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<
+ D32, D64>::CalculateNumChildren() {
if (!m_data_32 && !m_data_64)
return 0;
- return (m_data_32 ? m_data_32->_used : m_data_64->_used);
+ return (m_data_32 ? (uint32_t)m_data_32->_used : (uint32_t)m_data_64->_used);
}
template <typename D32, typename D64>
@@ -753,7 +753,7 @@ lldb_private::formatters::
lldb::addr_t m_objs_addr =
(m_data_32 ? m_data_32->_objs_addr : m_data_64->_objs_addr);
- uint32_t num_children = CalculateNumChildren();
+ uint32_t num_children = CalculateNumChildrenIgnoringErrors();
if (idx >= num_children)
return lldb::ValueObjectSP();
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
index f08f9f0f815d0c..9434376f7d9ea0 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
@@ -539,7 +539,8 @@ ThreadSP AppleObjCRuntime::GetBacktraceThreadFromException(
return object;
};
- for (size_t idx = 0; idx < reserved_dict->GetNumChildren(); idx++) {
+ for (size_t idx = 0; idx < reserved_dict->GetNumChildrenIgnoringErrors();
+ idx++) {
ValueObjectSP dict_entry = reserved_dict->GetChildAtIndex(idx);
DataExtractor data;
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 51ab13108feb3a..179f987bd61f11 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -5263,9 +5263,10 @@ GetDynamicArrayInfo(TypeSystemClang &ast, SymbolFile *sym_file,
return std::nullopt;
}
-uint32_t TypeSystemClang::GetNumChildren(lldb::opaque_compiler_type_t type,
- bool omit_empty_base_classes,
- const ExecutionContext *exe_ctx) {
+llvm::Expected<uint32_t>
+TypeSystemClang::GetNumChildren(lldb::opaque_compiler_type_t type,
+ bool omit_empty_base_classes,
+ const ExecutionContext *exe_ctx) {
if (!type)
return 0;
@@ -5361,9 +5362,13 @@ uint32_t TypeSystemClang::GetNumChildren(lldb::opaque_compiler_type_t type,
CompilerType pointee_clang_type(GetPointeeType(type));
uint32_t num_pointee_children = 0;
- if (pointee_clang_type.IsAggregateType())
- num_pointee_children =
+ if (pointee_clang_type.IsAggregateType()) {
+ auto num_children_or_err =
pointee_clang_type.GetNumChildren(omit_empty_base_classes, exe_ctx);
+ if (!num_children_or_err)
+ return num_children_or_err;
+ num_pointee_children = *num_children_or_err;
+ }
// If this type points to a simple type, then it has 1 child
if (num_pointee_children == 0)
num_children = 1;
@@ -5397,9 +5402,13 @@ uint32_t TypeSystemClang::GetNumChildren(lldb::opaque_compiler_type_t type,
clang::QualType pointee_type(pointer_type->getPointeeType());
CompilerType pointee_clang_type(GetType(pointee_type));
uint32_t num_pointee_children = 0;
- if (pointee_clang_type.IsAggregateType())
- num_pointee_children =
+ if (pointee_clang_type.IsAggregateType()) {
+ auto num_children_or_err =
pointee_clang_type.GetNumChildren(omit_empty_base_classes, exe_ctx);
+ if (!num_children_or_err)
+ return num_children_or_err;
+ num_pointee_children = *num_children_or_err;
+ }
if (num_pointee_children == 0) {
// We have a pointer to a pointee type that claims it has no children. We
// will want to look at
@@ -6108,8 +6117,15 @@ CompilerType TypeSystemClang::GetChildCompilerTypeAtIndex(
child_is_base_class = false;
language_flags = 0;
- const bool idx_is_valid =
- idx < GetNumChildren(type, omit_empty_base_classes, exe_ctx);
+ auto num_children_or_err =
+ GetNumChildren(type, omit_empty_base_classes, exe_ctx);
+ if (!num_children_or_err){
+ LLDB_LOG_ERRORV(GetLog(LLDBLog::Types), num_children_or_err.takeError(),
+ "{0}");
+ return {};
+ }
+
+ const bool idx_is_valid = idx < *num_children_or_err;
int32_t bit_offset;
switch (parent_type_class) {
case clang::Type::Builtin:
@@ -6265,8 +6281,10 @@ CompilerType TypeSystemClang::GetChildCompilerTypeAtIndex(
CompilerType base_class_clang_type =
GetType(getASTContext().getObjCInterfaceType(
superclass_interface_decl));
- if (base_class_clang_type.GetNumChildren(omit_empty_base_classes,
- exe_ctx) > 0) {
+ if (llvm::expectedToStdOptional(
+ base_class_clang_type.GetNumChildren(
+ omit_empty_base_classes, exe_ctx))
+ .value_or(0) > 0) {
if (idx == 0) {
clang::QualType ivar_qual_type(
getASTContext().getObjCInterfaceType(
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
index a73164895baa80..05c303baa41640 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -833,9 +833,10 @@ class TypeSystemClang : public TypeSystem {
GetTypeBitAlign(lldb::opaque_compiler_type_t type,
ExecutionContextScope *exe_scope) override;
- uint32_t GetNumChildren(lldb::opaque_compiler_type_t type,
- bool omit_empty_base_classes,
- const ExecutionContext *exe_ctx) override;
+ llvm::Expected<uint32_t>
+ GetNumChildren(lldb::opaque_compiler_type_t type,
+ bool omit_empty_base_classes,
+ const ExecutionContext *exe_ctx) override;
CompilerType GetBuiltinTypeByName(ConstString name) override;
diff --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp
index 76b79daa6ac154..85dd2d841a5a0c 100644
--- a/lldb/source/Symbol/CompilerType.cpp
+++ b/lldb/source/Symbol/CompilerType.cpp
@@ -770,8 +770,9 @@ lldb::Format CompilerType::GetFormat() const {
return lldb::eFormatDefault;
}
-uint32_t CompilerType::GetNumChildren(bool omit_empty_base_classes,
- const ExecutionContext *exe_ctx) const {
+llvm::Expected<uint32_t>
+CompilerType::GetNumChildren(bool omit_empty_base_classes,
+ const ExecutionContext *exe_ctx) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetNumChildren(m_type, omit_empty_base_classes,
diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp
index 6069d066eaf66b..44a24d7178f562 100644
--- a/lldb/source/Symbol/Type.cpp
+++ b/lldb/source/Symbol/Type.cpp
@@ -488,7 +488,7 @@ std::optional<uint64_t> Type::GetByteSize(ExecutionContextScope *exe_scope) {
return {};
}
-uint32_t Type::GetNumChildren(bool omit_empty_base_classes) {
+llvm::Expected<uint32_t> Type::GetNumChildren(bool omit_empty_base_classes) {
return GetForwardCompilerType().GetNumChildren(omit_empty_base_classes, nullptr);
}
diff --git a/lldb/source/Symbol/Variable.cpp b/lldb/source/Symbol/Variable.cpp
index a33c3433d9e245..90edede0f06538 100644
--- a/lldb/source/Symbol/Variable.cpp
+++ b/lldb/source/Symbol/Variable.cpp
@@ -27,6 +27,8 @@
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
#include "lldb/Utility/RegularExpression.h"
#include "lldb/Utility/Stream.h"
@@ -568,7 +570,9 @@ static void PrivateAutoComplete(
case eTypeClassObjCObjectPointer:
case eTypeClassPointer: {
bool omit_empty_base_classes = true;
- if (compiler_type.GetNumChildren(omit_empty_base_classes, nullptr) > 0)
+ if (llvm::expectedToStdOptional(
+ compiler_type.GetNumChildren(omit_empty_base_classes, nullptr))
+ .value_or(0))
request.AddCompletion((prefix_path + "->").str());
else {
request.AddCompletion(prefix_path.str());
diff --git a/lldb/source/Target/StackFrame.cpp b/lldb/source/Target/StackFrame.cpp
index 50cf01e63cd493..c29a71d92572e2 100644
--- a/lldb/source/Target/StackFrame.cpp
+++ b/lldb/source/Target/StackFrame.cpp
@@ -857,10 +857,11 @@ ValueObjectSP StackFrame::GetValueForVariableExpressionPath(
"\"(%s) %s\" is not an array type",
valobj_sp->GetTypeName().AsCString("<invalid type>"),
var_expr_path_strm.GetData());
- } else if (
- static_cast<uint32_t>(child_index) >=
- synthetic
- ->GetNumChildren() /* synthetic does not have that many values */) {
+ } else if (static_cast<uint32_t>(child_index) >=
+ synthetic
+ ->GetNumChildrenIgnoringErrors() /* synthetic does
+ not have that
+ many values */) {
valobj_sp->GetExpressionPath(var_expr_path_strm);
error.SetErrorStringWithFormat(
"array index %ld is not valid for \"(%s) %s\"", child_index,
@@ -929,10 +930,9 @@ ValueObjectSP StackFrame::GetValueForVariableExpressionPath(
"\"(%s) %s\" is not an array type",
valobj_sp->GetTypeName().AsCString("<invalid type>"),
var_expr_path_strm.GetData());
- } else if (
- static_cast<uint32_t>(child_index) >=
- synthetic
- ->GetNumChildren() /* synthetic does not have that many values */) {
+ } else if (static_cast<uint32_t>(child_index) >=
+ synthetic->GetNumChildrenIgnoringErrors() /* synthetic
+ does not have that many values */) {
valobj_sp->GetExpressionPath(var_expr_path_strm);
error.SetErrorStringWithFormat(
"array index %ld is not valid for \"(%s) %s\"", child_index,
@@ -1397,7 +1397,8 @@ ValueObjectSP GetValueForOffset(StackFrame &frame, ValueObjectSP &parent,
return parent;
}
- for (int ci = 0, ce = parent->GetNumChildren(); ci != ce; ++ci) {
+ for (int ci = 0, ce = parent->GetNumChildrenIgnoringErrors(); ci != ce;
+ ++ci) {
ValueObjectSP child_sp = parent->GetChildAtIndex(ci);
if (!child_sp) {
More information about the lldb-commits
mailing list