Skip to content

Commit cc380f6

Browse files
authored
[LLDB] Add formatters for MSVC STL map-like types (#148385)
This PR adds formatters for `std::map`, `std::set`, `std::multimap`, `std::multiset` as well as their iterators. It's done in one PR because the types are essentially the same (a tree) except for their value type. The iterators are required because of the tests. `MsvcStlTreeIterSyntheticFrontEnd` is based on the libc++ equivalent. As opposed to `std::list`, there aren't that many duplicates, so I didn't create a generic type. For reference, the tree is implemented in https://github.com/microsoft/STL/blob/313964b78a8fd5a52e7965e13781f735bcce13c5/stl/inc/xtree. Towards #24834.
1 parent 3affbce commit cc380f6

File tree

10 files changed

+530
-47
lines changed

10 files changed

+530
-47
lines changed

lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ add_lldb_library(lldbPluginCPlusPlusLanguage PLUGIN
3636
MsvcStl.cpp
3737
MsvcStlAtomic.cpp
3838
MsvcStlSmartPointer.cpp
39+
MsvcStlTree.cpp
3940
MsvcStlTuple.cpp
4041
MsvcStlUnordered.cpp
4142
MsvcStlVariant.cpp

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

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
14091409
stl_synth_flags,
14101410
"lldb.formatters.cpp.gnu_libstdcpp.StdVectorSynthProvider")));
14111411
cpp_category_sp->AddTypeSynthetic(
1412-
"^std::(__debug::)?map<.+> >(( )?&)?$", eFormatterMatchRegex,
1412+
"^std::__debug::map<.+> >(( )?&)?$", eFormatterMatchRegex,
14131413
SyntheticChildrenSP(new ScriptedSyntheticChildren(
14141414
stl_synth_flags,
14151415
"lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
@@ -1419,17 +1419,17 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
14191419
stl_deref_flags,
14201420
"lldb.formatters.cpp.gnu_libstdcpp.StdDequeSynthProvider")));
14211421
cpp_category_sp->AddTypeSynthetic(
1422-
"^std::(__debug::)?set<.+> >(( )?&)?$", eFormatterMatchRegex,
1422+
"^std::__debug::set<.+> >(( )?&)?$", eFormatterMatchRegex,
14231423
SyntheticChildrenSP(new ScriptedSyntheticChildren(
14241424
stl_deref_flags,
14251425
"lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
14261426
cpp_category_sp->AddTypeSynthetic(
1427-
"^std::(__debug::)?multimap<.+> >(( )?&)?$", eFormatterMatchRegex,
1427+
"^std::__debug::multimap<.+> >(( )?&)?$", eFormatterMatchRegex,
14281428
SyntheticChildrenSP(new ScriptedSyntheticChildren(
14291429
stl_deref_flags,
14301430
"lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
14311431
cpp_category_sp->AddTypeSynthetic(
1432-
"^std::(__debug::)?multiset<.+> >(( )?&)?$", eFormatterMatchRegex,
1432+
"^std::__debug::multiset<.+> >(( )?&)?$", eFormatterMatchRegex,
14331433
SyntheticChildrenSP(new ScriptedSyntheticChildren(
14341434
stl_deref_flags,
14351435
"lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
@@ -1462,15 +1462,15 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
14621462
"libstdc++ std::__debug::vector summary provider",
14631463
"^std::__debug::vector<.+>(( )?&)?$", stl_summary_flags, true);
14641464

1465-
AddCXXSummary(
1466-
cpp_category_sp, lldb_private::formatters::ContainerSizeSummaryProvider,
1467-
"libstdc++ std::map summary provider",
1468-
"^std::(__debug::)?map<.+> >(( )?&)?$", stl_summary_flags, true);
1465+
AddCXXSummary(cpp_category_sp,
1466+
lldb_private::formatters::ContainerSizeSummaryProvider,
1467+
"libstdc++ debug std::map summary provider",
1468+
"^std::__debug::map<.+> >(( )?&)?$", stl_summary_flags, true);
14691469

1470-
AddCXXSummary(
1471-
cpp_category_sp, lldb_private::formatters::ContainerSizeSummaryProvider,
1472-
"libstdc++ std::set summary provider",
1473-
"^std::(__debug::)?set<.+> >(( )?&)?$", stl_summary_flags, true);
1470+
AddCXXSummary(cpp_category_sp,
1471+
lldb_private::formatters::ContainerSizeSummaryProvider,
1472+
"libstdc++ debug std::set summary provider",
1473+
"^std::__debug::set<.+> >(( )?&)?$", stl_summary_flags, true);
14741474

14751475
AddCXXSummary(
14761476
cpp_category_sp, lldb_private::formatters::ContainerSizeSummaryProvider,
@@ -1479,13 +1479,13 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
14791479

14801480
AddCXXSummary(
14811481
cpp_category_sp, lldb_private::formatters::ContainerSizeSummaryProvider,
1482-
"libstdc++ std::multimap summary provider",
1483-
"^std::(__debug::)?multimap<.+> >(( )?&)?$", stl_summary_flags, true);
1482+
"libstdc++ debug std::multimap summary provider",
1483+
"^std::__debug::multimap<.+> >(( )?&)?$", stl_summary_flags, true);
14841484

14851485
AddCXXSummary(
14861486
cpp_category_sp, lldb_private::formatters::ContainerSizeSummaryProvider,
1487-
"libstdc++ std::multiset summary provider",
1488-
"^std::(__debug::)?multiset<.+> >(( )?&)?$", stl_summary_flags, true);
1487+
"libstdc++ debug std::multiset summary provider",
1488+
"^std::__debug::multiset<.+> >(( )?&)?$", stl_summary_flags, true);
14891489

14901490
AddCXXSummary(cpp_category_sp,
14911491
lldb_private::formatters::ContainerSizeSummaryProvider,
@@ -1672,6 +1672,18 @@ GenericUnorderedSyntheticFrontEndCreator(CXXSyntheticChildren *children,
16721672
*valobj_sp);
16731673
}
16741674

1675+
static SyntheticChildrenFrontEnd *
1676+
GenericMapLikeSyntheticFrontEndCreator(CXXSyntheticChildren *children,
1677+
ValueObjectSP valobj_sp) {
1678+
if (!valobj_sp)
1679+
return nullptr;
1680+
1681+
if (IsMsvcStlMapLike(*valobj_sp))
1682+
return MsvcStlMapLikeSyntheticFrontEndCreator(valobj_sp);
1683+
return new ScriptedSyntheticChildren::FrontEnd(
1684+
"lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider", *valobj_sp);
1685+
}
1686+
16751687
/// Load formatters that are formatting types from more than one STL
16761688
static void LoadCommonStlFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
16771689
if (!cpp_category_sp)
@@ -1749,6 +1761,10 @@ static void LoadCommonStlFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
17491761
AddCXXSynthetic(cpp_category_sp, GenericOptionalSyntheticFrontEndCreator,
17501762
"std::optional synthetic children",
17511763
"^std::optional<.+>(( )?&)?$", stl_deref_flags, true);
1764+
AddCXXSynthetic(cpp_category_sp, GenericMapLikeSyntheticFrontEndCreator,
1765+
"std::(multi)?map/set synthetic children",
1766+
"^std::(multi)?(map|set)<.+>(( )?&)?$", stl_synth_flags,
1767+
true);
17521768

17531769
AddCXXSummary(cpp_category_sp, GenericSmartPointerSummaryProvider,
17541770
"MSVC STL/libstdc++ std::shared_ptr summary provider",
@@ -1786,6 +1802,10 @@ static void LoadCommonStlFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
17861802
"MSVC STL/libstdc++ std unordered container summary provider",
17871803
"^std::unordered_(multi)?(map|set)<.+> ?>$", stl_summary_flags,
17881804
true);
1805+
AddCXXSummary(cpp_category_sp, ContainerSizeSummaryProvider,
1806+
"MSVC STL/libstdc++ std::(multi)?map/set summary provider",
1807+
"^std::(multi)?(map|set)<.+>(( )?&)?$", stl_summary_flags,
1808+
true);
17891809
}
17901810

17911811
static void LoadMsvcStlFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
@@ -1834,6 +1854,14 @@ static void LoadMsvcStlFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
18341854
AddCXXSummary(cpp_category_sp, MsvcStlAtomicSummaryProvider,
18351855
"MSVC STL std::atomic summary provider", "^std::atomic<.+>$",
18361856
stl_summary_flags, true);
1857+
AddCXXSynthetic(cpp_category_sp, MsvcStlTreeIterSyntheticFrontEndCreator,
1858+
"MSVC STL tree iterator synthetic children",
1859+
"^std::_Tree(_const)?_iterator<.+>(( )?&)?$", stl_synth_flags,
1860+
true);
1861+
AddCXXSummary(cpp_category_sp, MsvcStlTreeIterSummaryProvider,
1862+
"MSVC STL tree iterator summary",
1863+
"^std::_Tree(_const)?_iterator<.+>(( )?&)?$", stl_summary_flags,
1864+
true);
18371865
}
18381866

18391867
static void LoadSystemFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ bool IsMsvcStlUnordered(ValueObject &valobj);
9191
SyntheticChildrenFrontEnd *
9292
MsvcStlUnorderedSyntheticFrontEndCreator(CXXSyntheticChildren *,
9393
lldb::ValueObjectSP valobj_sp);
94+
bool IsMsvcStlTreeIter(ValueObject &valobj);
95+
bool MsvcStlTreeIterSummaryProvider(ValueObject &valobj, Stream &stream,
96+
const TypeSummaryOptions &options);
97+
lldb_private::SyntheticChildrenFrontEnd *
98+
MsvcStlTreeIterSyntheticFrontEndCreator(CXXSyntheticChildren *,
99+
lldb::ValueObjectSP valobj_sp);
100+
101+
// std::map,set,multimap,multiset
102+
bool IsMsvcStlMapLike(ValueObject &valobj);
103+
lldb_private::SyntheticChildrenFrontEnd *
104+
MsvcStlMapLikeSyntheticFrontEndCreator(lldb::ValueObjectSP valobj_sp);
94105

95106
} // namespace formatters
96107
} // namespace lldb_private

0 commit comments

Comments
 (0)