Skip to content

Commit 5839da3

Browse files
Merge pull request #8376 from adrian-prantl/123794838
Surface errors in GetNumChildren.
2 parents 71d0f0e + 1ab3de7 commit 5839da3

File tree

105 files changed

+830
-512
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+830
-512
lines changed

lldb/include/lldb/Core/ValueObject.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ class ValueObject {
470470
/// Returns a unique id for this ValueObject.
471471
lldb::user_id_t GetID() const { return m_id.GetID(); }
472472

473-
virtual lldb::ValueObjectSP GetChildAtIndex(size_t idx,
473+
virtual lldb::ValueObjectSP GetChildAtIndex(uint32_t idx,
474474
bool can_create = true);
475475

476476
// The method always creates missing children in the path, if necessary.
@@ -485,7 +485,13 @@ class ValueObject {
485485

486486
virtual size_t GetIndexOfChildWithName(llvm::StringRef name);
487487

488-
size_t GetNumChildren(uint32_t max = UINT32_MAX);
488+
llvm::Expected<uint32_t> GetNumChildren(uint32_t max = UINT32_MAX);
489+
/// Like \c GetNumChildren but returns 0 on error. You probably
490+
/// shouldn't be using this function. It exists primarily to ease the
491+
/// transition to more pervasive error handling while not all APIs
492+
/// have been updated.
493+
uint32_t GetNumChildrenIgnoringErrors(uint32_t max = UINT32_MAX);
494+
bool HasChildren() { return GetNumChildrenIgnoringErrors() > 0; }
489495

490496
const Value &GetValue() const { return m_value; }
491497

@@ -805,7 +811,7 @@ class ValueObject {
805811
return (m_children.find(idx) != m_children.end());
806812
}
807813

808-
ValueObject *GetChildAtIndex(size_t idx) {
814+
ValueObject *GetChildAtIndex(uint32_t idx) {
809815
std::lock_guard<std::recursive_mutex> guard(m_mutex);
810816
const auto iter = m_children.find(idx);
811817
return ((iter == m_children.end()) ? nullptr : iter->second);
@@ -972,9 +978,10 @@ class ValueObject {
972978
int32_t synthetic_index);
973979

974980
/// Should only be called by ValueObject::GetNumChildren().
975-
virtual size_t CalculateNumChildren(uint32_t max = UINT32_MAX) = 0;
981+
virtual llvm::Expected<uint32_t>
982+
CalculateNumChildren(uint32_t max = UINT32_MAX) = 0;
976983

977-
void SetNumChildren(size_t num_children);
984+
void SetNumChildren(uint32_t num_children);
978985

979986
void SetValueDidChange(bool value_changed) {
980987
m_flags.m_value_did_change = value_changed;

lldb/include/lldb/Core/ValueObjectCast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ValueObjectCast : public ValueObject {
3333

3434
std::optional<uint64_t> GetByteSize() override;
3535

36-
size_t CalculateNumChildren(uint32_t max) override;
36+
llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
3737

3838
lldb::ValueType GetValueType() const override;
3939

lldb/include/lldb/Core/ValueObjectChild.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ValueObjectChild : public ValueObject {
3939

4040
lldb::ValueType GetValueType() const override;
4141

42-
size_t CalculateNumChildren(uint32_t max) override;
42+
llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
4343

4444
ConstString GetTypeName() override;
4545

lldb/include/lldb/Core/ValueObjectConstResult.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ValueObjectConstResult : public ValueObject {
6767

6868
lldb::ValueType GetValueType() const override;
6969

70-
size_t CalculateNumChildren(uint32_t max) override;
70+
llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
7171

7272
ConstString GetTypeName() override;
7373

lldb/include/lldb/Core/ValueObjectDynamicValue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ValueObjectDynamicValue : public ValueObject {
4343

4444
ConstString GetDisplayTypeName() override;
4545

46-
size_t CalculateNumChildren(uint32_t max) override;
46+
llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
4747

4848
lldb::ValueType GetValueType() const override;
4949

lldb/include/lldb/Core/ValueObjectMemory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ValueObjectMemory : public ValueObject {
4747

4848
ConstString GetDisplayTypeName() override;
4949

50-
size_t CalculateNumChildren(uint32_t max) override;
50+
llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
5151

5252
lldb::ValueType GetValueType() const override;
5353

lldb/include/lldb/Core/ValueObjectRegister.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ValueObjectRegisterSet : public ValueObject {
4747

4848
ConstString GetQualifiedTypeName() override;
4949

50-
size_t CalculateNumChildren(uint32_t max) override;
50+
llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
5151

5252
ValueObject *CreateChildAtIndex(size_t idx, bool synthetic_array_member,
5353
int32_t synthetic_index) override;
@@ -95,7 +95,7 @@ class ValueObjectRegister : public ValueObject {
9595

9696
ConstString GetTypeName() override;
9797

98-
size_t CalculateNumChildren(uint32_t max) override;
98+
llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
9999

100100
bool SetValueFromCString(const char *value_str, Status &error) override;
101101

lldb/include/lldb/Core/ValueObjectSyntheticFilter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ class ValueObjectSynthetic : public ValueObject {
4747

4848
bool MightHaveChildren() override;
4949

50-
size_t CalculateNumChildren(uint32_t max) override;
50+
llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
5151

5252
lldb::ValueType GetValueType() const override;
5353

54-
lldb::ValueObjectSP GetChildAtIndex(size_t idx,
54+
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx,
5555
bool can_create = true) override;
5656

5757
lldb::ValueObjectSP GetChildMemberWithName(llvm::StringRef name,

lldb/include/lldb/Core/ValueObjectVTable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ValueObjectVTable : public ValueObject {
6464

6565
std::optional<uint64_t> GetByteSize() override;
6666

67-
size_t CalculateNumChildren(uint32_t max) override;
67+
llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
6868

6969
ValueObject *CreateChildAtIndex(size_t idx, bool synthetic_array_member,
7070
int32_t synthetic_index) override;

lldb/include/lldb/Core/ValueObjectVariable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ValueObjectVariable : public ValueObject {
4646

4747
ConstString GetDisplayTypeName() override;
4848

49-
size_t CalculateNumChildren(uint32_t max) override;
49+
llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
5050

5151
lldb::ValueType GetValueType() const override;
5252

lldb/include/lldb/DataFormatters/TypeSynthetic.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@ class SyntheticChildrenFrontEnd {
3838

3939
virtual ~SyntheticChildrenFrontEnd() = default;
4040

41-
virtual size_t CalculateNumChildren() = 0;
41+
virtual llvm::Expected<uint32_t> CalculateNumChildren() = 0;
4242

43-
virtual size_t CalculateNumChildren(uint32_t max) {
43+
virtual llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) {
4444
auto count = CalculateNumChildren();
45-
return count <= max ? count : max;
45+
if (!count)
46+
return count;
47+
return *count <= max ? *count : max;
4648
}
4749

48-
virtual lldb::ValueObjectSP GetChildAtIndex(size_t idx) = 0;
50+
uint32_t CalculateNumChildrenIgnoringErrors(uint32_t max = UINT32_MAX);
51+
52+
virtual lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) = 0;
4953

5054
virtual size_t GetIndexOfChildWithName(ConstString name) = 0;
5155

@@ -109,9 +113,9 @@ class SyntheticValueProviderFrontEnd : public SyntheticChildrenFrontEnd {
109113

110114
~SyntheticValueProviderFrontEnd() override = default;
111115

112-
size_t CalculateNumChildren() override { return 0; }
116+
llvm::Expected<uint32_t> CalculateNumChildren() override { return 0; }
113117

114-
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override { return nullptr; }
118+
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override { return nullptr; }
115119

116120
size_t GetIndexOfChildWithName(ConstString name) override {
117121
return UINT32_MAX;
@@ -322,9 +326,11 @@ class TypeFilterImpl : public SyntheticChildren {
322326

323327
~FrontEnd() override = default;
324328

325-
size_t CalculateNumChildren() override { return filter->GetCount(); }
329+
llvm::Expected<uint32_t> CalculateNumChildren() override {
330+
return filter->GetCount();
331+
}
326332

327-
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override {
333+
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override {
328334
if (idx >= filter->GetCount())
329335
return lldb::ValueObjectSP();
330336
return m_backend.GetSyntheticExpressionPathChild(
@@ -426,11 +432,11 @@ class ScriptedSyntheticChildren : public SyntheticChildren {
426432

427433
bool IsValid();
428434

429-
size_t CalculateNumChildren() override;
435+
llvm::Expected<uint32_t> CalculateNumChildren() override;
430436

431-
size_t CalculateNumChildren(uint32_t max) override;
437+
llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
432438

433-
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
439+
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
434440

435441
lldb::ChildCacheState Update() override;
436442

lldb/include/lldb/DataFormatters/ValueObjectPrinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class ValueObjectPrinter {
127127
void PrintChild(lldb::ValueObjectSP child_sp,
128128
const DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
129129

130-
uint32_t GetMaxNumChildrenToPrint(bool &print_dotdotdot);
130+
llvm::Expected<uint32_t> GetMaxNumChildrenToPrint(bool &print_dotdotdot);
131131

132132
void
133133
PrintChildren(bool value_printed, bool summary_printed,

lldb/include/lldb/DataFormatters/VectorIterator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class VectorIteratorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
2424
VectorIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp,
2525
llvm::ArrayRef<ConstString> item_names);
2626

27-
size_t CalculateNumChildren() override;
27+
llvm::Expected<uint32_t> CalculateNumChildren() override;
2828

29-
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
29+
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
3030

3131
lldb::ChildCacheState Update() override;
3232

lldb/include/lldb/Symbol/CompilerType.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,9 @@ class CompilerType {
345345

346346
std::optional<size_t> GetTypeBitAlign(ExecutionContextScope *exe_scope) const;
347347

348-
uint32_t GetNumChildren(bool omit_empty_base_classes,
349-
const ExecutionContext *exe_ctx) const;
348+
llvm::Expected<uint32_t>
349+
GetNumChildren(bool omit_empty_base_classes,
350+
const ExecutionContext *exe_ctx) const;
350351

351352
lldb::BasicType GetBasicTypeEnumeration() const;
352353

lldb/include/lldb/Symbol/Type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ class Type : public std::enable_shared_from_this<Type>, public UserID {
440440

441441
std::optional<uint64_t> GetByteSize(ExecutionContextScope *exe_scope);
442442

443-
uint32_t GetNumChildren(bool omit_empty_base_classes);
443+
llvm::Expected<uint32_t> GetNumChildren(bool omit_empty_base_classes);
444444

445445
bool IsAggregateType();
446446

lldb/include/lldb/Symbol/TypeSystem.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,10 @@ class TypeSystem : public PluginInterface,
323323

324324
virtual lldb::Format GetFormat(lldb::opaque_compiler_type_t type) = 0;
325325

326-
virtual uint32_t GetNumChildren(lldb::opaque_compiler_type_t type,
327-
bool omit_empty_base_classes,
328-
const ExecutionContext *exe_ctx) = 0;
326+
virtual llvm::Expected<uint32_t>
327+
GetNumChildren(lldb::opaque_compiler_type_t type,
328+
bool omit_empty_base_classes,
329+
const ExecutionContext *exe_ctx) = 0;
329330

330331
virtual CompilerType GetBuiltinTypeByName(ConstString name);
331332

lldb/include/lldb/Target/StackFrameRecognizer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ class ValueObjectRecognizerSynthesizedValue : public ValueObject {
164164
m_value = m_parent->GetValue();
165165
return true;
166166
}
167-
size_t CalculateNumChildren(uint32_t max = UINT32_MAX) override {
167+
llvm::Expected<uint32_t>
168+
CalculateNumChildren(uint32_t max = UINT32_MAX) override {
168169
return m_parent->GetNumChildren(max);
169170
}
170171
CompilerType GetCompilerTypeImpl() override {

lldb/include/lldb/Utility/Log.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,18 @@ template <typename Cat> Log *GetLog(Cat mask) {
373373
::llvm::consumeError(::std::move(error_private)); \
374374
} while (0)
375375

376+
// Write message to the verbose log, if error is set. In the log
377+
// message refer to the error with {0}. Error is cleared regardless of
378+
// whether logging is enabled.
379+
#define LLDB_LOG_ERRORV(log, error, ...) \
380+
do { \
381+
::lldb_private::Log *log_private = (log); \
382+
::llvm::Error error_private = (error); \
383+
if (log_private && log_private->GetVerbose() && error_private) { \
384+
log_private->FormatError(::std::move(error_private), __FILE__, __func__, \
385+
__VA_ARGS__); \
386+
} else \
387+
::llvm::consumeError(::std::move(error_private)); \
388+
} while (0)
389+
376390
#endif // LLDB_UTILITY_LOG_H

lldb/source/API/SBValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ uint32_t SBValue::GetNumChildren(uint32_t max) {
947947
ValueLocker locker;
948948
lldb::ValueObjectSP value_sp(GetSP(locker));
949949
if (value_sp)
950-
num_children = value_sp->GetNumChildren(max);
950+
num_children = value_sp->GetNumChildrenIgnoringErrors(max);
951951

952952
return num_children;
953953
}

lldb/source/Core/FormatEntity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ static bool DumpValue(Stream &s, const SymbolContext *sc,
926926
s.PutChar('[');
927927

928928
if (index_higher < 0)
929-
index_higher = valobj->GetNumChildren() - 1;
929+
index_higher = valobj->GetNumChildrenIgnoringErrors() - 1;
930930

931931
uint32_t max_num_children =
932932
target->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();

lldb/source/Core/IOHandlerCursesGUI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4520,7 +4520,7 @@ struct Row {
45204520
calculated_children = true;
45214521
ValueObjectSP valobj = value.GetSP();
45224522
if (valobj) {
4523-
const size_t num_children = valobj->GetNumChildren();
4523+
const uint32_t num_children = valobj->GetNumChildrenIgnoringErrors();
45244524
for (size_t i = 0; i < num_children; ++i) {
45254525
children.push_back(Row(valobj->GetChildAtIndex(i), this));
45264526
}

0 commit comments

Comments
 (0)