-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lldb][Formatters] Use container summary helper for libstdc++ formatters #147140
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
[lldb][Formatters] Use container summary helper for libstdc++ formatters #147140
Conversation
This re-uses the `LibCxxContainerSummaryProvider` for the libstdc++ formatters. There's a couple of containers that aren't making use of it for libstdc++. This patch will make it easier to review when adding those in the future.
|
@llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) ChangesThis re-uses the Full diff: https://github.com/llvm/llvm-project/pull/147140.diff 5 Files Affected:
diff --git a/lldb/include/lldb/DataFormatters/FormattersHelpers.h b/lldb/include/lldb/DataFormatters/FormattersHelpers.h
index 97d367afc65d7..de603eda8af50 100644
--- a/lldb/include/lldb/DataFormatters/FormattersHelpers.h
+++ b/lldb/include/lldb/DataFormatters/FormattersHelpers.h
@@ -60,6 +60,9 @@ std::optional<size_t> ExtractIndexFromString(const char *item_name);
void DumpCxxSmartPtrPointerSummary(Stream &stream, ValueObject &ptr,
const TypeSummaryOptions &options);
+bool CxxContainerSummaryProvider(ValueObject &valobj, Stream &stream,
+ const TypeSummaryOptions &options);
+
Address GetArrayAddressOrPointerValue(ValueObject &valobj);
time_t GetOSXEpoch();
diff --git a/lldb/source/DataFormatters/FormattersHelpers.cpp b/lldb/source/DataFormatters/FormattersHelpers.cpp
index 81c76b06fc47a..db735f050e3cb 100644
--- a/lldb/source/DataFormatters/FormattersHelpers.cpp
+++ b/lldb/source/DataFormatters/FormattersHelpers.cpp
@@ -145,3 +145,9 @@ void lldb_private::formatters::DumpCxxSmartPtrPointerSummary(
ValueObject::PrintableRepresentationSpecialCases::eDisable, false))
stream.Printf("ptr = 0x%" PRIx64, ptr.GetValueAsUnsigned(0));
}
+
+bool lldb_private::formatters::CxxContainerSummaryProvider(
+ ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+ return FormatEntity::FormatStringRef("size=${svar%#}", stream, nullptr,
+ nullptr, nullptr, &valobj, false, false);
+}
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 77047c077c678..38898ccb6e55e 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -1016,15 +1016,15 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
stl_summary_flags.SetDontShowChildren(false);
stl_summary_flags.SetSkipPointers(false);
AddCXXSummary(cpp_category_sp,
- lldb_private::formatters::LibcxxContainerSummaryProvider,
+ lldb_private::formatters::CxxContainerSummaryProvider,
"libc++ std::bitset summary provider",
"^std::__[[:alnum:]]+::bitset<.+>$", stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
- lldb_private::formatters::LibcxxContainerSummaryProvider,
+ lldb_private::formatters::CxxContainerSummaryProvider,
"libc++ std::vector summary provider",
"^std::__[[:alnum:]]+::vector<.+>$", stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
- lldb_private::formatters::LibcxxContainerSummaryProvider,
+ lldb_private::formatters::CxxContainerSummaryProvider,
"libc++ std::valarray summary provider",
"^std::__[[:alnum:]]+::valarray<.+>$", stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
@@ -1033,16 +1033,16 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
"^std::__[[:alnum:]]+::slice_array<.+>$", stl_summary_flags,
true);
AddCXXSummary(cpp_category_sp,
- lldb_private::formatters::LibcxxContainerSummaryProvider,
+ lldb_private::formatters::CxxContainerSummaryProvider,
"libc++ summary provider for the valarray proxy arrays",
"^std::__[[:alnum:]]+::(gslice|mask|indirect)_array<.+>$",
stl_summary_flags, true);
AddCXXSummary(
- cpp_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider,
+ cpp_category_sp, lldb_private::formatters::CxxContainerSummaryProvider,
"libc++ std::list summary provider",
"^std::__[[:alnum:]]+::forward_list<.+>$", stl_summary_flags, true);
AddCXXSummary(
- cpp_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider,
+ cpp_category_sp, lldb_private::formatters::CxxContainerSummaryProvider,
"libc++ std::list summary provider",
// A POSIX variant of: "^std::__(?!cxx11:)[[:alnum:]]+::list<.+>$"
// so that it does not clash with: "^std::(__cxx11::)?list<.+>$"
@@ -1050,35 +1050,35 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
"cxx11[[:alnum:]])[[:alnum:]]*::list<.+>$",
stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
- lldb_private::formatters::LibcxxContainerSummaryProvider,
+ lldb_private::formatters::CxxContainerSummaryProvider,
"libc++ std::map summary provider",
"^std::__[[:alnum:]]+::map<.+>$", stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
- lldb_private::formatters::LibcxxContainerSummaryProvider,
+ lldb_private::formatters::CxxContainerSummaryProvider,
"libc++ std::deque summary provider",
"^std::__[[:alnum:]]+::deque<.+>$", stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
- lldb_private::formatters::LibcxxContainerSummaryProvider,
+ lldb_private::formatters::CxxContainerSummaryProvider,
"libc++ std::queue summary provider",
"^std::__[[:alnum:]]+::queue<.+>$", stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
- lldb_private::formatters::LibcxxContainerSummaryProvider,
+ lldb_private::formatters::CxxContainerSummaryProvider,
"libc++ std::set summary provider",
"^std::__[[:alnum:]]+::set<.+>$", stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
- lldb_private::formatters::LibcxxContainerSummaryProvider,
+ lldb_private::formatters::CxxContainerSummaryProvider,
"libc++ std::multiset summary provider",
"^std::__[[:alnum:]]+::multiset<.+>$", stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
- lldb_private::formatters::LibcxxContainerSummaryProvider,
+ lldb_private::formatters::CxxContainerSummaryProvider,
"libc++ std::multimap summary provider",
"^std::__[[:alnum:]]+::multimap<.+>$", stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
- lldb_private::formatters::LibcxxContainerSummaryProvider,
+ lldb_private::formatters::CxxContainerSummaryProvider,
"libc++ std::unordered containers summary provider",
"^std::__[[:alnum:]]+::unordered_(multi)?(map|set)<.+> >$",
stl_summary_flags, true);
- AddCXXSummary(cpp_category_sp, LibcxxContainerSummaryProvider,
+ AddCXXSummary(cpp_category_sp, CxxContainerSummaryProvider,
"libc++ std::tuple summary provider",
"^std::__[[:alnum:]]+::tuple<.*>$", stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
@@ -1094,7 +1094,7 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
"libc++ std::variant summary provider",
"^std::__[[:alnum:]]+::variant<.+>$", stl_summary_flags, true);
AddCXXSummary(cpp_category_sp,
- lldb_private::formatters::LibcxxContainerSummaryProvider,
+ lldb_private::formatters::CxxContainerSummaryProvider,
"libc++ std::span summary provider",
"^std::__[[:alnum:]]+::span<.+>$", stl_summary_flags, true);
@@ -1456,44 +1456,54 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
stl_summary_flags.SetDontShowChildren(false);
stl_summary_flags.SetSkipPointers(false);
- cpp_category_sp->AddTypeSummary("^std::(__debug::)?bitset<.+>(( )?&)?$",
- eFormatterMatchRegex,
- TypeSummaryImplSP(new StringSummaryFormat(
- stl_summary_flags, "size=${svar%#}")));
- cpp_category_sp->AddTypeSummary("^std::(__debug::)?vector<.+>(( )?&)?$",
- eFormatterMatchRegex,
- TypeSummaryImplSP(new StringSummaryFormat(
- stl_summary_flags, "size=${svar%#}")));
- cpp_category_sp->AddTypeSummary("^std::(__debug::)?map<.+> >(( )?&)?$",
- eFormatterMatchRegex,
- TypeSummaryImplSP(new StringSummaryFormat(
- stl_summary_flags, "size=${svar%#}")));
- cpp_category_sp->AddTypeSummary("^std::(__debug::)?set<.+> >(( )?&)?$",
- eFormatterMatchRegex,
- TypeSummaryImplSP(new StringSummaryFormat(
- stl_summary_flags, "size=${svar%#}")));
- cpp_category_sp->AddTypeSummary("^std::(__debug::)?deque<.+>(( )?&)?$",
- eFormatterMatchRegex,
- TypeSummaryImplSP(new StringSummaryFormat(
- stl_summary_flags, "size=${svar%#}")));
- cpp_category_sp->AddTypeSummary("^std::(__debug::)?multimap<.+> >(( )?&)?$",
- eFormatterMatchRegex,
- TypeSummaryImplSP(new StringSummaryFormat(
- stl_summary_flags, "size=${svar%#}")));
- cpp_category_sp->AddTypeSummary("^std::(__debug::)?multiset<.+> >(( )?&)?$",
- eFormatterMatchRegex,
- TypeSummaryImplSP(new StringSummaryFormat(
- stl_summary_flags, "size=${svar%#}")));
- cpp_category_sp->AddTypeSummary(
- "^std::(__debug::)?unordered_(multi)?(map|set)<.+> >$",
- eFormatterMatchRegex,
- TypeSummaryImplSP(
- new StringSummaryFormat(stl_summary_flags, "size=${svar%#}")));
- cpp_category_sp->AddTypeSummary(
- "^std::((__debug::)?|(__cxx11::)?)list<.+>(( )?&)?$",
- eFormatterMatchRegex,
- TypeSummaryImplSP(
- new StringSummaryFormat(stl_summary_flags, "size=${svar%#}")));
+
+ AddCXXSummary(
+ cpp_category_sp, lldb_private::formatters::CxxContainerSummaryProvider,
+ "libstdc++ std::bitset summary provider",
+ "^std::(__debug::)?bitset<.+>(( )?&)?$", stl_summary_flags, true);
+
+ AddCXXSummary(
+ cpp_category_sp, lldb_private::formatters::CxxContainerSummaryProvider,
+ "libstdc++ std::vector summary provider",
+ "^std::(__debug::)?vector<.+>(( )?&)?$", stl_summary_flags, true);
+
+ AddCXXSummary(
+ cpp_category_sp, lldb_private::formatters::CxxContainerSummaryProvider,
+ "libstdc++ std::map summary provider",
+ "^std::(__debug::)?map<.+> >(( )?&)?$", stl_summary_flags, true);
+
+ AddCXXSummary(
+ cpp_category_sp, lldb_private::formatters::CxxContainerSummaryProvider,
+ "libstdc++ std::set summary provider",
+ "^std::(__debug::)?set<.+> >(( )?&)?$", stl_summary_flags, true);
+
+ AddCXXSummary(
+ cpp_category_sp, lldb_private::formatters::CxxContainerSummaryProvider,
+ "libstdc++ std::deque summary provider",
+ "^std::(__debug::)?deque<.+>(( )?&)?$", stl_summary_flags, true);
+
+ AddCXXSummary(
+ cpp_category_sp, lldb_private::formatters::CxxContainerSummaryProvider,
+ "libstdc++ std::multimap summary provider",
+ "^std::(__debug::)?multimap<.+> >(( )?&)?$", stl_summary_flags, true);
+
+ AddCXXSummary(
+ cpp_category_sp, lldb_private::formatters::CxxContainerSummaryProvider,
+ "libstdc++ std::multiset summary provider",
+ "^std::(__debug::)?multiset<.+> >(( )?&)?$", stl_summary_flags, true);
+
+ AddCXXSummary(cpp_category_sp,
+ lldb_private::formatters::CxxContainerSummaryProvider,
+ "libstdc++ std unordered container summary provider",
+ "^std::(__debug::)?unordered_(multi)?(map|set)<.+> >$",
+ stl_summary_flags, true);
+
+ AddCXXSummary(cpp_category_sp,
+ lldb_private::formatters::CxxContainerSummaryProvider,
+ "libstdc++ std::list summary provider",
+ "^std::((__debug::)?|(__cxx11::)?)list<.+>(( )?&)?$",
+ stl_summary_flags, true);
+
cpp_category_sp->AddTypeSummary(
"^std::((__debug::)?|(__cxx11::)?)forward_list<.+>(( )?&)?$",
eFormatterMatchRegex,
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index 104521b8c3e71..9ee4e2ab0490e 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -410,12 +410,6 @@ lldb_private::formatters::LibcxxUniquePtrSyntheticFrontEnd::
name.AsCString());
}
-bool lldb_private::formatters::LibcxxContainerSummaryProvider(
- ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
- return FormatEntity::FormatStringRef("size=${svar%#}", stream, nullptr,
- nullptr, nullptr, &valobj, false, false);
-}
-
/// The field layout in a libc++ string (cap, side, data or data, size, cap).
namespace {
enum class StringLayout { CSD, DSC };
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
index 56501302d116f..0c1f120ea708a 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
@@ -81,9 +81,6 @@ SyntheticChildrenFrontEnd *
LibcxxVectorBoolSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
-bool LibcxxContainerSummaryProvider(ValueObject &valobj, Stream &stream,
- const TypeSummaryOptions &options);
-
/// Formatter for libc++ std::span<>.
bool LibcxxSpanSummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options);
|
labath
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see we already have some C++ stuff in this file, but given that there really isn't anything specific in this function, maybe we could also drop the Cxx part from the name (maybe call it ContainerSizeSummaryProvider )?
This re-uses the
LibcxxContainerSummaryProviderfor the libstdc++ formatters. There's a couple of containers that aren't making use of it for libstdc++. This patch will make it easier to review when adding those in the future.