Skip to content

Commit a899377

Browse files
committed
[lldb][TypeSynthetic] Make SyntheticChildrenFrontend::Update() return an enum
1 parent 08c0eb1 commit a899377

33 files changed

+303
-271
lines changed

lldb/include/lldb/DataFormatters/TypeSynthetic.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@ 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+
enum class CacheState { Invalid, Valid };
53+
54+
/// This function is assumed to always succeed and if it fails, the front-end
55+
/// should know to deal with it in the correct way (most probably, by refusing
56+
/// to return any children). The return value of \ref Update should actually
57+
/// be interpreted as "ValueObjectSyntheticFilter cache is good/bad". If this
58+
/// function returns \ref CacheState::Valid, \ref ValueObjectSyntheticFilter
59+
/// is allowed to use the children it fetched previously and cached.
60+
/// Otherwise, \ref ValueObjectSyntheticFilter must throw away its cache, and
61+
/// query again for children.
62+
virtual CacheState Update() = 0;
6063

6164
// if this function returns false, then CalculateNumChildren() MUST return 0
6265
// since UI frontends might validly decide not to inquire for children given
@@ -116,7 +119,7 @@ class SyntheticValueProviderFrontEnd : public SyntheticChildrenFrontEnd {
116119
return UINT32_MAX;
117120
}
118121

119-
bool Update() override { return false; }
122+
CacheState Update() override { return CacheState::Invalid; }
120123

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

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

331-
bool Update() override { return false; }
334+
CacheState Update() override { return CacheState::Invalid; }
332335

333336
bool MightHaveChildren() override { return filter->GetCount() > 0; }
334337

@@ -427,7 +430,7 @@ class ScriptedSyntheticChildren : public SyntheticChildren {
427430

428431
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
429432

430-
bool Update() override;
433+
CacheState Update() override;
431434

432435
bool MightHaveChildren() override;
433436

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+
CacheState Update() override;
3232

3333
bool MightHaveChildren() override;
3434

lldb/source/Core/ValueObjectSyntheticFilter.cpp

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

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

46-
bool Update() override { return false; }
46+
CacheState Update() override { return CacheState::Invalid; }
4747
};
4848

4949
ValueObjectSynthetic::ValueObjectSynthetic(ValueObject &parent,
@@ -177,7 +177,8 @@ bool ValueObjectSynthetic::UpdateValue() {
177177
}
178178

179179
// let our backend do its update
180-
if (!m_synth_filter_up->Update()) {
180+
if (m_synth_filter_up->Update() ==
181+
SyntheticChildrenFrontEnd::CacheState::Invalid) {
181182
LLDB_LOGF(log,
182183
"[ValueObjectSynthetic::UpdateValue] name=%s, synthetic "
183184
"filter said caches are stale - clearing",

lldb/source/DataFormatters/TypeSynthetic.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,14 @@ 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+
SyntheticChildrenFrontEnd::CacheState
194+
ScriptedSyntheticChildren::FrontEnd::Update() {
194195
if (!m_wrapper_sp || m_interpreter == nullptr)
195-
return false;
196+
return CacheState::Invalid;
196197

197-
return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp);
198+
return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp)
199+
? CacheState::Valid
200+
: CacheState::Invalid;
198201
}
199202

200203
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+
CacheState 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 CacheState::Invalid;
262262
}
263263

264264
bool MightHaveChildren() override { return true; }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ 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+
CacheState Update() override { return CacheState::Invalid; }
140140

141141
// maybe return false if the block pointer is, say, null
142142
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+
SyntheticChildrenFrontEnd::CacheState
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 CacheState::Invalid;
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 CacheState::Invalid;
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 CacheState::Invalid;
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 CacheState::Invalid;
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 CacheState::Invalid;
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 CacheState::Invalid;
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+
CacheState 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+
CacheState 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+
SyntheticChildrenFrontEnd::CacheState 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 CacheState::Invalid;
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 CacheState::Invalid;
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+
CacheState 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+
SyntheticChildrenFrontEnd::CacheState 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 CacheState::Invalid;
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 CacheState::Invalid;
8282
}
8383

8484
ValueObjectSP GenericOptionalFrontend::GetChildAtIndex(size_t _idx) {

0 commit comments

Comments
 (0)