Skip to content

[LLDB] Add formatters for MSVC STL map-like types #148385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ add_lldb_library(lldbPluginCPlusPlusLanguage PLUGIN
LibStdcppTuple.cpp
LibStdcppUniquePointer.cpp
MsvcStl.cpp
MsvcStlTree.cpp
MsvcStlSmartPointer.cpp
MSVCUndecoratedNameParser.cpp

Expand Down
66 changes: 52 additions & 14 deletions lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
stl_synth_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdVectorSynthProvider")));
cpp_category_sp->AddTypeSynthetic(
"^std::(__debug::)?map<.+> >(( )?&)?$", eFormatterMatchRegex,
"^std::__debug::map<.+> >(( )?&)?$", eFormatterMatchRegex,
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_synth_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
Expand All @@ -1419,17 +1419,17 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
stl_deref_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdDequeSynthProvider")));
cpp_category_sp->AddTypeSynthetic(
"^std::(__debug::)?set<.+> >(( )?&)?$", eFormatterMatchRegex,
"^std::__debug::set<.+> >(( )?&)?$", eFormatterMatchRegex,
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_deref_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
cpp_category_sp->AddTypeSynthetic(
"^std::(__debug::)?multimap<.+> >(( )?&)?$", eFormatterMatchRegex,
"^std::__debug::multimap<.+> >(( )?&)?$", eFormatterMatchRegex,
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_deref_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
cpp_category_sp->AddTypeSynthetic(
"^std::(__debug::)?multiset<.+> >(( )?&)?$", eFormatterMatchRegex,
"^std::__debug::multiset<.+> >(( )?&)?$", eFormatterMatchRegex,
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_deref_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
Expand Down Expand Up @@ -1470,15 +1470,15 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
"libstdc++ std::vector summary provider",
"^std::(__debug::)?vector<.+>(( )?&)?$", stl_summary_flags, true);

AddCXXSummary(
cpp_category_sp, lldb_private::formatters::ContainerSizeSummaryProvider,
"libstdc++ std::map summary provider",
"^std::(__debug::)?map<.+> >(( )?&)?$", stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
lldb_private::formatters::ContainerSizeSummaryProvider,
"libstdc++ std::map summary provider",
"^std::__debug::map<.+> >(( )?&)?$", stl_summary_flags, true);

AddCXXSummary(
cpp_category_sp, lldb_private::formatters::ContainerSizeSummaryProvider,
"libstdc++ std::set summary provider",
"^std::(__debug::)?set<.+> >(( )?&)?$", stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
lldb_private::formatters::ContainerSizeSummaryProvider,
"libstdc++ std::set summary provider",
"^std::__debug::set<.+> >(( )?&)?$", stl_summary_flags, true);

AddCXXSummary(
cpp_category_sp, lldb_private::formatters::ContainerSizeSummaryProvider,
Expand All @@ -1488,12 +1488,12 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
AddCXXSummary(
cpp_category_sp, lldb_private::formatters::ContainerSizeSummaryProvider,
"libstdc++ std::multimap summary provider",
"^std::(__debug::)?multimap<.+> >(( )?&)?$", stl_summary_flags, true);
"^std::__debug::multimap<.+> >(( )?&)?$", stl_summary_flags, true);

AddCXXSummary(
cpp_category_sp, lldb_private::formatters::ContainerSizeSummaryProvider,
"libstdc++ std::multiset summary provider",
"^std::(__debug::)?multiset<.+> >(( )?&)?$", stl_summary_flags, true);
"^std::__debug::multiset<.+> >(( )?&)?$", stl_summary_flags, true);

AddCXXSummary(cpp_category_sp,
lldb_private::formatters::ContainerSizeSummaryProvider,
Expand Down Expand Up @@ -1599,6 +1599,18 @@ GenericSmartPointerSummaryProvider(ValueObject &valobj, Stream &stream,
return LibStdcppSmartPointerSummaryProvider(valobj, stream, options);
}

static lldb_private::SyntheticChildrenFrontEnd *
GenericMapLikeSyntheticFrontEndCreator(CXXSyntheticChildren *children,
lldb::ValueObjectSP valobj_sp) {
if (!valobj_sp)
return nullptr;

if (IsMsvcStlMapLike(*valobj_sp))
return MsvcStlMapLikeSyntheticFrontEndCreator(valobj_sp);
return new ScriptedSyntheticChildren::FrontEnd(
"lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider", *valobj_sp);
}

/// Load formatters that are formatting types from more than one STL
static void LoadCommonStlFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
if (!cpp_category_sp)
Expand Down Expand Up @@ -1642,19 +1654,30 @@ static void LoadCommonStlFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
},
"MSVC STL/libstdc++ std::wstring summary provider"));

stl_summary_flags.SetDontShowChildren(false);
stl_summary_flags.SetSkipPointers(false);

AddCXXSynthetic(cpp_category_sp, GenericSmartPointerSyntheticFrontEndCreator,
"std::shared_ptr synthetic children",
"^std::shared_ptr<.+>(( )?&)?$", stl_synth_flags, true);
AddCXXSynthetic(cpp_category_sp, GenericSmartPointerSyntheticFrontEndCreator,
"std::weak_ptr synthetic children",
"^std::weak_ptr<.+>(( )?&)?$", stl_synth_flags, true);
AddCXXSynthetic(cpp_category_sp, GenericMapLikeSyntheticFrontEndCreator,
"std::(multi)?map/set synthetic children",
"^std::(multi)?(map|set)<.+>(( )?&)?$", stl_synth_flags,
true);

AddCXXSummary(cpp_category_sp, GenericSmartPointerSummaryProvider,
"MSVC STL/libstdc++ std::shared_ptr summary provider",
"^std::shared_ptr<.+>(( )?&)?$", stl_summary_flags, true);
AddCXXSummary(cpp_category_sp, GenericSmartPointerSummaryProvider,
"MSVC STL/libstdc++ std::weak_ptr summary provider",
"^std::weak_ptr<.+>(( )?&)?$", stl_summary_flags, true);
AddCXXSummary(cpp_category_sp, ContainerSizeSummaryProvider,
"MSVC STL/libstdc++ std::(multi)?map/set summary provider",
"^std::(multi)?(map|set)<.+>(( )?&)?$", stl_summary_flags,
true);
}

static void LoadMsvcStlFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
Expand All @@ -1669,6 +1692,9 @@ static void LoadMsvcStlFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
.SetDontShowValue(false)
.SetShowMembersOneLiner(false)
.SetHideItemNames(false);
SyntheticChildren::Flags stl_synth_flags;
stl_synth_flags.SetCascades(true).SetSkipPointers(false).SetSkipReferences(
false);

using StringElementType = StringPrinter::StringElementType;

Expand All @@ -1690,6 +1716,18 @@ static void LoadMsvcStlFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
stl_summary_flags,
MsvcStlStringSummaryProvider<StringElementType::UTF32>,
"MSVC STL std::u32string summary provider"));

stl_summary_flags.SetDontShowChildren(false);
stl_summary_flags.SetSkipPointers(false);

AddCXXSynthetic(cpp_category_sp, MsvcStlTreeIterSyntheticFrontEndCreator,
"MSVC STL tree iterator synthetic children",
"^std::_Tree(_const)?_iterator<.+>(( )?&)?$", stl_synth_flags,
true);
AddCXXSummary(cpp_category_sp, MsvcStlTreeIterSummaryProvider,
"MSVC STL tree iterator summary",
"^std::_Tree(_const)?_iterator<.+>(( )?&)?$", stl_summary_flags,
true);
}

static void LoadSystemFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
Expand Down
12 changes: 12 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/MsvcStl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ bool MsvcStlSmartPointerSummaryProvider(ValueObject &valobj, Stream &stream,
lldb_private::SyntheticChildrenFrontEnd *
MsvcStlSmartPointerSyntheticFrontEndCreator(lldb::ValueObjectSP valobj_sp);

bool IsMsvcStlTreeIter(ValueObject &valobj);
bool MsvcStlTreeIterSummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options);
lldb_private::SyntheticChildrenFrontEnd *
MsvcStlTreeIterSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP valobj_sp);

// std::map,set,multimap,multiset
bool IsMsvcStlMapLike(ValueObject &valobj);
lldb_private::SyntheticChildrenFrontEnd *
MsvcStlMapLikeSyntheticFrontEndCreator(lldb::ValueObjectSP valobj_sp);

} // namespace formatters
} // namespace lldb_private

Expand Down
Loading
Loading