Skip to content

Commit d7fb94b

Browse files
authored
[lldb][TypeSynthetic][NFC] Make SyntheticChildrenFrontend::Update() return an enum (#80167)
This patch changes the return value of `SyntheticChildrenFrontend::Update` to a scoped enum that aims to describe what the return value means.
1 parent 455c396 commit d7fb94b

34 files changed

+321
-271
lines changed

lldb/include/lldb/DataFormatters/TypeSynthetic.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ class SyntheticChildrenFrontEnd {
4949

5050
virtual size_t GetIndexOfChildWithName(ConstString name) = 0;
5151

52-
// this function is assumed to always succeed and it if fails, the front-end
53-
// should know to deal with it in the correct way (most probably, by refusing
54-
// to return any children) the return value of Update() should actually be
55-
// interpreted as "ValueObjectSyntheticFilter cache is good/bad" if =true,
56-
// ValueObjectSyntheticFilter is allowed to use the children it fetched
57-
// previously and cached if =false, ValueObjectSyntheticFilter must throw
58-
// away its cache, and query again for children
59-
virtual bool Update() = 0;
52+
/// This function is assumed to always succeed and if it fails, the front-end
53+
/// should know to deal with it in the correct way (most probably, by refusing
54+
/// to return any children). The return value of \ref Update should actually
55+
/// be interpreted as "ValueObjectSyntheticFilter cache is good/bad". If this
56+
/// function returns \ref lldb::ChildCacheState::eReuse, \ref
57+
/// ValueObjectSyntheticFilter is allowed to use the children it fetched
58+
/// previously and cached. Otherwise, \ref ValueObjectSyntheticFilter must
59+
/// throw away its cache, and query again for children.
60+
virtual lldb::ChildCacheState Update() = 0;
6061

6162
// if this function returns false, then CalculateNumChildren() MUST return 0
6263
// since UI frontends might validly decide not to inquire for children given
@@ -116,7 +117,9 @@ class SyntheticValueProviderFrontEnd : public SyntheticChildrenFrontEnd {
116117
return UINT32_MAX;
117118
}
118119

119-
bool Update() override { return false; }
120+
lldb::ChildCacheState Update() override {
121+
return lldb::ChildCacheState::eRefetch;
122+
}
120123

121124
bool MightHaveChildren() override { return false; }
122125

@@ -328,7 +331,9 @@ class TypeFilterImpl : public SyntheticChildren {
328331
filter->GetExpressionPathAtIndex(idx), true);
329332
}
330333

331-
bool Update() override { return false; }
334+
lldb::ChildCacheState Update() override {
335+
return lldb::ChildCacheState::eRefetch;
336+
}
332337

333338
bool MightHaveChildren() override { return filter->GetCount() > 0; }
334339

@@ -427,7 +432,7 @@ class ScriptedSyntheticChildren : public SyntheticChildren {
427432

428433
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
429434

430-
bool Update() override;
435+
lldb::ChildCacheState Update() override;
431436

432437
bool MightHaveChildren() override;
433438

lldb/include/lldb/DataFormatters/VectorIterator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class VectorIteratorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
2828

2929
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
3030

31-
bool Update() override;
31+
lldb::ChildCacheState Update() override;
3232

3333
bool MightHaveChildren() override;
3434

lldb/include/lldb/lldb-enumerations.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,15 @@ enum CompletionType {
13051305
eTerminatorCompletion = (1ul << 27)
13061306
};
13071307

1308+
/// Specifies if children need to be re-computed
1309+
/// after a call to \ref SyntheticChildrenFrontEnd::Update.
1310+
enum class ChildCacheState {
1311+
eRefetch = 0, ///< Children need to be recomputed dynamically.
1312+
1313+
eReuse = 1, ///< Children did not change and don't need to be recomputed;
1314+
///< re-use what we computed the last time we called Update.
1315+
};
1316+
13081317
} // namespace lldb
13091318

13101319
#endif // LLDB_LLDB_ENUMERATIONS_H

lldb/source/Core/ValueObjectSyntheticFilter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class DummySyntheticFrontEnd : public SyntheticChildrenFrontEnd {
4343

4444
bool MightHaveChildren() override { return m_backend.MightHaveChildren(); }
4545

46-
bool Update() override { return false; }
46+
lldb::ChildCacheState Update() override {
47+
return lldb::ChildCacheState::eRefetch;
48+
}
4749
};
4850

4951
ValueObjectSynthetic::ValueObjectSynthetic(ValueObject &parent,
@@ -177,7 +179,7 @@ bool ValueObjectSynthetic::UpdateValue() {
177179
}
178180

179181
// let our backend do its update
180-
if (!m_synth_filter_up->Update()) {
182+
if (m_synth_filter_up->Update() == lldb::ChildCacheState::eRefetch) {
181183
LLDB_LOGF(log,
182184
"[ValueObjectSynthetic::UpdateValue] name=%s, synthetic "
183185
"filter said caches are stale - clearing",

lldb/source/DataFormatters/TypeSynthetic.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,13 @@ size_t ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren(uint32_t max) {
190190
return m_interpreter->CalculateNumChildren(m_wrapper_sp, max);
191191
}
192192

193-
bool ScriptedSyntheticChildren::FrontEnd::Update() {
193+
lldb::ChildCacheState ScriptedSyntheticChildren::FrontEnd::Update() {
194194
if (!m_wrapper_sp || m_interpreter == nullptr)
195-
return false;
195+
return lldb::ChildCacheState::eRefetch;
196196

197-
return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp);
197+
return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp)
198+
? lldb::ChildCacheState::eReuse
199+
: lldb::ChildCacheState::eRefetch;
198200
}
199201

200202
bool ScriptedSyntheticChildren::FrontEnd::MightHaveChildren() {

lldb/source/DataFormatters/VectorType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class VectorTypeSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
245245
return child_sp;
246246
}
247247

248-
bool Update() override {
248+
lldb::ChildCacheState Update() override {
249249
m_parent_format = m_backend.GetFormat();
250250
CompilerType parent_type(m_backend.GetCompilerType());
251251
CompilerType element_type;
@@ -258,7 +258,7 @@ class VectorTypeSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
258258
::CalculateNumChildren(element_type, num_elements, m_child_type)
259259
.value_or(0);
260260
m_item_format = GetItemFormatForFormat(m_parent_format, m_child_type);
261-
return false;
261+
return lldb::ChildCacheState::eRefetch;
262262
}
263263

264264
bool MightHaveChildren() override { return true; }

lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ class BlockPointerSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
136136

137137
// return true if this object is now safe to use forever without ever
138138
// updating again; the typical (and tested) answer here is 'false'
139-
bool Update() override { return false; }
139+
lldb::ChildCacheState Update() override {
140+
return lldb::ChildCacheState::eRefetch;
141+
}
140142

141143
// maybe return false if the block pointer is, say, null
142144
bool MightHaveChildren() override { return true; }

lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,24 @@ lldb::ValueObjectSP lldb_private::formatters::
125125
return lldb::ValueObjectSP();
126126
}
127127

128-
bool lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEnd::
129-
Update() {
128+
lldb::ChildCacheState
129+
lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEnd::Update() {
130130
m_resume_ptr_sp.reset();
131131
m_destroy_ptr_sp.reset();
132132
m_promise_ptr_sp.reset();
133133

134134
ValueObjectSP valobj_sp = m_backend.GetNonSyntheticValue();
135135
if (!valobj_sp)
136-
return false;
136+
return lldb::ChildCacheState::eRefetch;
137137

138138
lldb::addr_t frame_ptr_addr = GetCoroFramePtrFromHandle(valobj_sp);
139139
if (frame_ptr_addr == 0 || frame_ptr_addr == LLDB_INVALID_ADDRESS)
140-
return false;
140+
return lldb::ChildCacheState::eRefetch;
141141

142142
auto ts = valobj_sp->GetCompilerType().GetTypeSystem();
143143
auto ast_ctx = ts.dyn_cast_or_null<TypeSystemClang>();
144144
if (!ast_ctx)
145-
return false;
145+
return lldb::ChildCacheState::eRefetch;
146146

147147
// Create the `resume` and `destroy` children.
148148
lldb::TargetSP target_sp = m_backend.GetTargetSP();
@@ -165,7 +165,7 @@ bool lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEnd::
165165
CompilerType promise_type(
166166
valobj_sp->GetCompilerType().GetTypeTemplateArgument(0));
167167
if (!promise_type)
168-
return false;
168+
return lldb::ChildCacheState::eRefetch;
169169

170170
// Try to infer the promise_type if it was type-erased
171171
if (promise_type.IsVoidType()) {
@@ -180,7 +180,7 @@ bool lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEnd::
180180
// If we don't know the promise type, we don't display the `promise` member.
181181
// `CreateValueObjectFromAddress` below would fail for `void` types.
182182
if (promise_type.IsVoidType()) {
183-
return false;
183+
return lldb::ChildCacheState::eRefetch;
184184
}
185185

186186
// Add the `promise` member. We intentionally add `promise` as a pointer type
@@ -194,7 +194,7 @@ bool lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEnd::
194194
if (error.Success())
195195
m_promise_ptr_sp = promisePtr->Clone(ConstString("promise"));
196196

197-
return false;
197+
return lldb::ChildCacheState::eRefetch;
198198
}
199199

200200
bool lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEnd::

lldb/source/Plugins/Language/CPlusPlus/Coroutines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class StdlibCoroutineHandleSyntheticFrontEnd
3838

3939
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
4040

41-
bool Update() override;
41+
lldb::ChildCacheState Update() override;
4242

4343
bool MightHaveChildren() override;
4444

lldb/source/Plugins/Language/CPlusPlus/GenericBitset.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class GenericBitsetFrontEnd : public SyntheticChildrenFrontEnd {
3333
}
3434

3535
bool MightHaveChildren() override { return true; }
36-
bool Update() override;
36+
lldb::ChildCacheState Update() override;
3737
size_t CalculateNumChildren() override { return m_elements.size(); }
3838
ValueObjectSP GetChildAtIndex(size_t idx) override;
3939

@@ -78,13 +78,13 @@ llvm::StringRef GenericBitsetFrontEnd::GetDataContainerMemberName() {
7878
llvm_unreachable("Unknown StdLib enum");
7979
}
8080

81-
bool GenericBitsetFrontEnd::Update() {
81+
lldb::ChildCacheState GenericBitsetFrontEnd::Update() {
8282
m_elements.clear();
8383
m_first = nullptr;
8484

8585
TargetSP target_sp = m_backend.GetTargetSP();
8686
if (!target_sp)
87-
return false;
87+
return lldb::ChildCacheState::eRefetch;
8888

8989
size_t size = 0;
9090

@@ -94,7 +94,7 @@ bool GenericBitsetFrontEnd::Update() {
9494
m_elements.assign(size, ValueObjectSP());
9595
m_first =
9696
m_backend.GetChildMemberWithName(GetDataContainerMemberName()).get();
97-
return false;
97+
return lldb::ChildCacheState::eRefetch;
9898
}
9999

100100
ValueObjectSP GenericBitsetFrontEnd::GetChildAtIndex(size_t idx) {

lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class GenericOptionalFrontend : public SyntheticChildrenFrontEnd {
4444
size_t CalculateNumChildren() override { return m_has_value ? 1U : 0U; }
4545

4646
ValueObjectSP GetChildAtIndex(size_t idx) override;
47-
bool Update() override;
47+
lldb::ChildCacheState Update() override;
4848

4949
private:
5050
bool m_has_value = false;
@@ -61,7 +61,7 @@ GenericOptionalFrontend::GenericOptionalFrontend(ValueObject &valobj,
6161
}
6262
}
6363

64-
bool GenericOptionalFrontend::Update() {
64+
lldb::ChildCacheState GenericOptionalFrontend::Update() {
6565
ValueObjectSP engaged_sp;
6666

6767
if (m_stdlib == StdLib::LibCxx)
@@ -71,14 +71,14 @@ bool GenericOptionalFrontend::Update() {
7171
->GetChildMemberWithName("_M_engaged");
7272

7373
if (!engaged_sp)
74-
return false;
74+
return lldb::ChildCacheState::eRefetch;
7575

7676
// _M_engaged/__engaged is a bool flag and is true if the optional contains a
7777
// value. Converting it to unsigned gives us a size of 1 if it contains a
7878
// value and 0 if not.
7979
m_has_value = engaged_sp->GetValueAsUnsigned(0) != 0;
8080

81-
return false;
81+
return lldb::ChildCacheState::eRefetch;
8282
}
8383

8484
ValueObjectSP GenericOptionalFrontend::GetChildAtIndex(size_t _idx) {

0 commit comments

Comments
 (0)