Skip to content

Commit c4000d8

Browse files
authored
Merge pull request swiftlang#8190 from Michael137/lldb/libcxx-formatters-to-20230725
[cherry-pick][stable/20230725] [lldb] Add std::chrono and std::valarray libc++ formatters This patch cherry-picks various libc++ formatters for std::chrono and std::valarray. It also cherry-picks some pre-requisite NFC commits to reduce merge conflicts.
2 parents 70d7fe4 + 7ad9b8a commit c4000d8

Some content is hidden

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

55 files changed

+1493
-401
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
@@ -1332,6 +1332,15 @@ enum CompletionType {
13321332
eCustomCompletion = (1u << 25)
13331333
};
13341334

1335+
/// Specifies if children need to be re-computed
1336+
/// after a call to \ref SyntheticChildrenFrontEnd::Update.
1337+
enum class ChildCacheState {
1338+
eRefetch = 0, ///< Children need to be recomputed dynamically.
1339+
1340+
eReuse = 1, ///< Children did not change and don't need to be recomputed;
1341+
///< re-use what we computed the last time we called Update.
1342+
};
1343+
13351344
} // namespace lldb
13361345

13371346
#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 true; }
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
@@ -169,11 +169,13 @@ size_t ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren(uint32_t max) {
169169
return m_interpreter->CalculateNumChildren(m_wrapper_sp, max);
170170
}
171171

172-
bool ScriptedSyntheticChildren::FrontEnd::Update() {
172+
lldb::ChildCacheState ScriptedSyntheticChildren::FrontEnd::Update() {
173173
if (!m_wrapper_sp || m_interpreter == nullptr)
174-
return false;
174+
return lldb::ChildCacheState::eRefetch;
175175

176-
return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp);
176+
return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp)
177+
? lldb::ChildCacheState::eReuse
178+
: lldb::ChildCacheState::eRefetch;
177179
}
178180

179181
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/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_lldb_library(lldbPluginCPlusPlusLanguage PLUGIN
1717
LibCxxTuple.cpp
1818
LibCxxUnorderedMap.cpp
1919
LibCxxVariant.cpp
20+
LibCxxValarray.cpp
2021
LibCxxVector.cpp
2122
LibStdcpp.cpp
2223
LibStdcppTuple.cpp

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

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,11 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
756756
lldb_private::formatters::LibcxxStdVectorSyntheticFrontEndCreator,
757757
"libc++ std::vector synthetic children",
758758
"^std::__[[:alnum:]]+::vector<.+>(( )?&)?$", stl_deref_flags, true);
759+
AddCXXSynthetic(
760+
cpp_category_sp,
761+
lldb_private::formatters::LibcxxStdValarraySyntheticFrontEndCreator,
762+
"libc++ std::valarray synthetic children",
763+
"^std::__[[:alnum:]]+::valarray<.+>$", stl_deref_flags, true);
759764
AddCXXSynthetic(
760765
cpp_category_sp,
761766
lldb_private::formatters::LibcxxStdForwardListSyntheticFrontEndCreator,
@@ -887,6 +892,10 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
887892
"libc++ std::list summary provider",
888893
"^std::__[[:alnum:]]+::forward_list<.+>(( )?&)?$",
889894
stl_summary_flags, true);
895+
AddCXXSummary(cpp_category_sp,
896+
lldb_private::formatters::LibcxxContainerSummaryProvider,
897+
"libc++ std::valarray summary provider",
898+
"^std::__[[:alnum:]]+::valarray<.+>$", stl_summary_flags, true);
890899
AddCXXSummary(
891900
cpp_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider,
892901
"libc++ std::list summary provider",
@@ -986,6 +995,174 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
986995
"std::unordered_map iterator synthetic children",
987996
"^std::__[[:alnum:]]+::__hash_map_(const_)?iterator<.+>$",
988997
stl_synth_flags, true);
998+
// Chrono duration typedefs
999+
cpp_category_sp->AddTypeSummary(
1000+
"^std::__[[:alnum:]]+::chrono::nanoseconds", eFormatterMatchRegex,
1001+
TypeSummaryImplSP(new StringSummaryFormat(
1002+
eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} ns")));
1003+
cpp_category_sp->AddTypeSummary(
1004+
"^std::__[[:alnum:]]+::chrono::microseconds", eFormatterMatchRegex,
1005+
TypeSummaryImplSP(new StringSummaryFormat(
1006+
eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} µs")));
1007+
cpp_category_sp->AddTypeSummary(
1008+
"^std::__[[:alnum:]]+::chrono::milliseconds", eFormatterMatchRegex,
1009+
TypeSummaryImplSP(new StringSummaryFormat(
1010+
eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} ms")));
1011+
cpp_category_sp->AddTypeSummary(
1012+
"^std::__[[:alnum:]]+::chrono::seconds", eFormatterMatchRegex,
1013+
TypeSummaryImplSP(new StringSummaryFormat(
1014+
eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} s")));
1015+
cpp_category_sp->AddTypeSummary(
1016+
"^std::__[[:alnum:]]+::chrono::minutes", eFormatterMatchRegex,
1017+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1018+
eTypeOptionHideValue,
1019+
"${var.__rep_} min")));
1020+
cpp_category_sp->AddTypeSummary(
1021+
"^std::__[[:alnum:]]+::chrono::hours", eFormatterMatchRegex,
1022+
TypeSummaryImplSP(new StringSummaryFormat(
1023+
eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} h")));
1024+
1025+
cpp_category_sp->AddTypeSummary(
1026+
"^std::__[[:alnum:]]+::chrono::days", eFormatterMatchRegex,
1027+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1028+
eTypeOptionHideValue,
1029+
"${var.__rep_} days")));
1030+
cpp_category_sp->AddTypeSummary(
1031+
"^std::__[[:alnum:]]+::chrono::weeks", eFormatterMatchRegex,
1032+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1033+
eTypeOptionHideValue,
1034+
"${var.__rep_} weeks")));
1035+
cpp_category_sp->AddTypeSummary(
1036+
"^std::__[[:alnum:]]+::chrono::months", eFormatterMatchRegex,
1037+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1038+
eTypeOptionHideValue,
1039+
"${var.__rep_} months")));
1040+
cpp_category_sp->AddTypeSummary(
1041+
"^std::__[[:alnum:]]+::chrono::years", eFormatterMatchRegex,
1042+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1043+
eTypeOptionHideValue,
1044+
"${var.__rep_} years")));
1045+
cpp_category_sp->AddTypeSummary(
1046+
"^std::__[[:alnum:]]+::chrono::seconds", eFormatterMatchRegex,
1047+
TypeSummaryImplSP(new StringSummaryFormat(
1048+
eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} s")));
1049+
1050+
// Chrono time point types
1051+
1052+
AddCXXSummary(cpp_category_sp,
1053+
lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider,
1054+
"libc++ std::chrono::sys_seconds summary provider",
1055+
"^std::__[[:alnum:]]+::chrono::time_point<"
1056+
"std::__[[:alnum:]]+::chrono::system_clock, "
1057+
"std::__[[:alnum:]]+::chrono::duration<long long, "
1058+
"std::__[[:alnum:]]+::ratio<1, 1> "
1059+
"> >$",
1060+
eTypeOptionHideChildren | eTypeOptionHideValue |
1061+
eTypeOptionCascade,
1062+
true);
1063+
AddCXXSummary(cpp_category_sp,
1064+
lldb_private::formatters::LibcxxChronoSysDaysSummaryProvider,
1065+
"libc++ std::chrono::sys_seconds summary provider",
1066+
"^std::__[[:alnum:]]+::chrono::time_point<"
1067+
"std::__[[:alnum:]]+::chrono::system_clock, "
1068+
"std::__[[:alnum:]]+::chrono::duration<int, "
1069+
"std::__[[:alnum:]]+::ratio<86400, 1> "
1070+
"> >$",
1071+
eTypeOptionHideChildren | eTypeOptionHideValue |
1072+
eTypeOptionCascade,
1073+
true);
1074+
1075+
// Chrono calendar types
1076+
1077+
cpp_category_sp->AddTypeSummary(
1078+
"^std::__[[:alnum:]]+::chrono::day$", eFormatterMatchRegex,
1079+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1080+
eTypeOptionHideValue,
1081+
"day=${var.__d_%u}")));
1082+
1083+
AddCXXSummary(cpp_category_sp,
1084+
lldb_private::formatters::LibcxxChronoMonthSummaryProvider,
1085+
"libc++ std::chrono::month summary provider",
1086+
"^std::__[[:alnum:]]+::chrono::month$",
1087+
eTypeOptionHideChildren | eTypeOptionHideValue, true);
1088+
1089+
cpp_category_sp->AddTypeSummary(
1090+
"^std::__[[:alnum:]]+::chrono::year$", eFormatterMatchRegex,
1091+
TypeSummaryImplSP(new StringSummaryFormat(
1092+
eTypeOptionHideChildren | eTypeOptionHideValue, "year=${var.__y_}")));
1093+
1094+
AddCXXSummary(cpp_category_sp,
1095+
lldb_private::formatters::LibcxxChronoWeekdaySummaryProvider,
1096+
"libc++ std::chrono::weekday summary provider",
1097+
"^std::__[[:alnum:]]+::chrono::weekday$",
1098+
eTypeOptionHideChildren | eTypeOptionHideValue, true);
1099+
1100+
cpp_category_sp->AddTypeSummary(
1101+
"^std::__[[:alnum:]]+::chrono::weekday_indexed$", eFormatterMatchRegex,
1102+
TypeSummaryImplSP(new StringSummaryFormat(
1103+
eTypeOptionHideChildren | eTypeOptionHideValue,
1104+
"${var.__wd_} index=${var.__idx_%u}")));
1105+
1106+
cpp_category_sp->AddTypeSummary(
1107+
"^std::__[[:alnum:]]+::chrono::weekday_last$", eFormatterMatchRegex,
1108+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1109+
eTypeOptionHideValue,
1110+
"${var.__wd_} index=last")));
1111+
cpp_category_sp->AddTypeSummary(
1112+
"^std::__[[:alnum:]]+::chrono::month_day$", eFormatterMatchRegex,
1113+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1114+
eTypeOptionHideValue,
1115+
"${var.__m_} ${var.__d_}")));
1116+
cpp_category_sp->AddTypeSummary(
1117+
"^std::__[[:alnum:]]+::chrono::month_day_last$", eFormatterMatchRegex,
1118+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1119+
eTypeOptionHideValue,
1120+
"${var.__m_} day=last")));
1121+
1122+
cpp_category_sp->AddTypeSummary(
1123+
"^std::__[[:alnum:]]+::chrono::month_weekday$", eFormatterMatchRegex,
1124+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1125+
eTypeOptionHideValue,
1126+
"${var.__m_} ${var.__wdi_}")));
1127+
1128+
cpp_category_sp->AddTypeSummary(
1129+
"^std::__[[:alnum:]]+::chrono::month_weekday_last$", eFormatterMatchRegex,
1130+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1131+
eTypeOptionHideValue,
1132+
"${var.__m_} ${var.__wdl_}")));
1133+
1134+
cpp_category_sp->AddTypeSummary(
1135+
"^std::__[[:alnum:]]+::chrono::year_month$", eFormatterMatchRegex,
1136+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1137+
eTypeOptionHideValue,
1138+
"${var.__y_} ${var.__m_}")));
1139+
1140+
AddCXXSummary(
1141+
cpp_category_sp,
1142+
lldb_private::formatters::LibcxxChronoYearMonthDaySummaryProvider,
1143+
"libc++ std::chrono::year_month_day summary provider",
1144+
"^std::__[[:alnum:]]+::chrono::year_month_day$",
1145+
eTypeOptionHideChildren | eTypeOptionHideValue, true);
1146+
1147+
cpp_category_sp->AddTypeSummary(
1148+
"^std::__[[:alnum:]]+::chrono::year_month_day_last$",
1149+
eFormatterMatchRegex,
1150+
TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1151+
eTypeOptionHideValue,
1152+
"${var.__y_} ${var.__mdl_}")));
1153+
1154+
cpp_category_sp->AddTypeSummary(
1155+
"^std::__[[:alnum:]]+::chrono::year_month_weekday$", eFormatterMatchRegex,
1156+
TypeSummaryImplSP(new StringSummaryFormat(
1157+
eTypeOptionHideChildren | eTypeOptionHideValue,
1158+
"${var.__y_} ${var.__m_} ${var.__wdi_}")));
1159+
1160+
cpp_category_sp->AddTypeSummary(
1161+
"^std::__[[:alnum:]]+::chrono::year_month_weekday_last$",
1162+
eFormatterMatchRegex,
1163+
TypeSummaryImplSP(new StringSummaryFormat(
1164+
eTypeOptionHideChildren | eTypeOptionHideValue,
1165+
"${var.__y_} ${var.__m_} ${var.__wdl_}")));
9891166
}
9901167

9911168
static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {

0 commit comments

Comments
 (0)