Skip to content

Commit 88a498c

Browse files
authored
[LLDB] Add formatters for MSVC STL std::(forward_)list (#148285)
Adds synthetic providers for MSVC's `std::forward_list` and `std::list`. It refactors `LibCxxList` to be generic over the STL type (currently libc++ or MSVC STL). The libstdc++ synthetic providers use something similar in Python [here](https://github.com/llvm/llvm-project/blob/3092b765ba0b2d20bd716944dda86ea8e4ad12e3/lldb/examples/synthetic/gnu_libstdcpp.py#L134). Eventually, this could be ported to C++ as well. Towards #24834.
1 parent dbb1210 commit 88a498c

File tree

8 files changed

+355
-98
lines changed

8 files changed

+355
-98
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ add_lldb_library(lldbPluginCPlusPlusLanguage PLUGIN
1414
CxxStringTypes.cpp
1515
Generic.cpp
1616
GenericBitset.cpp
17+
GenericList.cpp
1718
GenericOptional.cpp
1819
LibCxx.cpp
1920
LibCxxAtomic.cpp
2021
LibCxxInitializerList.cpp
21-
LibCxxList.cpp
2222
LibCxxMap.cpp
2323
LibCxxQueue.cpp
2424
LibCxxRangesRefView.cpp

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

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,14 +1440,12 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
14401440
stl_deref_flags,
14411441
"lldb.formatters.cpp.gnu_libstdcpp.StdUnorderedMapSynthProvider")));
14421442
cpp_category_sp->AddTypeSynthetic(
1443-
"^std::((__debug::)?|(__cxx11::)?)list<.+>(( )?&)?$",
1444-
eFormatterMatchRegex,
1443+
"^std::__(debug|cxx11)::list<.+>(( )?&)?$", eFormatterMatchRegex,
14451444
SyntheticChildrenSP(new ScriptedSyntheticChildren(
14461445
stl_deref_flags,
14471446
"lldb.formatters.cpp.gnu_libstdcpp.StdListSynthProvider")));
14481447
cpp_category_sp->AddTypeSynthetic(
1449-
"^std::((__debug::)?|(__cxx11::)?)forward_list<.+>(( )?&)?$",
1450-
eFormatterMatchRegex,
1448+
"^std::__(debug|cxx11)::forward_list<.+>(( )?&)?$", eFormatterMatchRegex,
14511449
SyntheticChildrenSP(new ScriptedSyntheticChildren(
14521450
stl_synth_flags,
14531451
"lldb.formatters.cpp.gnu_libstdcpp.StdForwardListSynthProvider")));
@@ -1501,15 +1499,13 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
15011499
"^std::(__debug::)?unordered_(multi)?(map|set)<.+> >$",
15021500
stl_summary_flags, true);
15031501

1504-
AddCXXSummary(cpp_category_sp,
1505-
lldb_private::formatters::ContainerSizeSummaryProvider,
1506-
"libstdc++ std::list summary provider",
1507-
"^std::((__debug::)?|(__cxx11::)?)list<.+>(( )?&)?$",
1508-
stl_summary_flags, true);
1502+
AddCXXSummary(
1503+
cpp_category_sp, lldb_private::formatters::ContainerSizeSummaryProvider,
1504+
"libstdc++ debug std::list summary provider",
1505+
"^std::__(debug|cxx11)::list<.+>(( )?&)?$", stl_summary_flags, true);
15091506

15101507
cpp_category_sp->AddTypeSummary(
1511-
"^std::((__debug::)?|(__cxx11::)?)forward_list<.+>(( )?&)?$",
1512-
eFormatterMatchRegex,
1508+
"^std::__(debug|cxx11)::forward_list<.+>(( )?&)?$", eFormatterMatchRegex,
15131509
TypeSummaryImplSP(new ScriptSummaryFormat(
15141510
stl_summary_flags,
15151511
"lldb.formatters.cpp.gnu_libstdcpp.ForwardListSummaryProvider")));
@@ -1627,6 +1623,31 @@ GenericVectorSyntheticFrontEndCreator(CXXSyntheticChildren *children,
16271623
"lldb.formatters.cpp.gnu_libstdcpp.StdVectorSynthProvider", *valobj_sp);
16281624
}
16291625

1626+
static SyntheticChildrenFrontEnd *
1627+
GenericListSyntheticFrontEndCreator(CXXSyntheticChildren *children,
1628+
lldb::ValueObjectSP valobj_sp) {
1629+
if (!valobj_sp)
1630+
return nullptr;
1631+
1632+
if (IsMsvcStlList(*valobj_sp))
1633+
return MsvcStlListSyntheticFrontEndCreator(children, valobj_sp);
1634+
return new ScriptedSyntheticChildren::FrontEnd(
1635+
"lldb.formatters.cpp.gnu_libstdcpp.StdListSynthProvider", *valobj_sp);
1636+
}
1637+
1638+
static SyntheticChildrenFrontEnd *
1639+
GenericForwardListSyntheticFrontEndCreator(CXXSyntheticChildren *children,
1640+
lldb::ValueObjectSP valobj_sp) {
1641+
if (!valobj_sp)
1642+
return nullptr;
1643+
1644+
if (IsMsvcStlList(*valobj_sp))
1645+
return MsvcStlForwardListSyntheticFrontEndCreator(children, valobj_sp);
1646+
return new ScriptedSyntheticChildren::FrontEnd(
1647+
"lldb.formatters.cpp.gnu_libstdcpp.StdForwardListSynthProvider",
1648+
*valobj_sp);
1649+
}
1650+
16301651
/// Load formatters that are formatting types from more than one STL
16311652
static void LoadCommonStlFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
16321653
if (!cpp_category_sp)
@@ -1685,6 +1706,12 @@ static void LoadCommonStlFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
16851706
AddCXXSynthetic(cpp_category_sp, GenericTupleSyntheticFrontEndCreator,
16861707
"std::tuple synthetic children", "^std::tuple<.*>(( )?&)?$",
16871708
stl_synth_flags, true);
1709+
AddCXXSynthetic(cpp_category_sp, GenericListSyntheticFrontEndCreator,
1710+
"std::list synthetic children", "^std::list<.+>(( )?&)?$",
1711+
stl_synth_flags, true);
1712+
AddCXXSynthetic(cpp_category_sp, GenericForwardListSyntheticFrontEndCreator,
1713+
"std::forward_list synthetic children",
1714+
"^std::forward_list<.+>(( )?&)?$", stl_synth_flags, true);
16881715

16891716
AddCXXSummary(cpp_category_sp, GenericSmartPointerSummaryProvider,
16901717
"MSVC STL/libstdc++ std::shared_ptr summary provider",
@@ -1704,6 +1731,14 @@ static void LoadCommonStlFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
17041731
AddCXXSynthetic(cpp_category_sp, GenericVectorSyntheticFrontEndCreator,
17051732
"MSVC/libstdc++ std::vector synthetic provider",
17061733
"^std::vector<.+>(( )?&)?$", stl_synth_flags, true);
1734+
AddCXXSummary(cpp_category_sp, ContainerSizeSummaryProvider,
1735+
"MSVC STL/libstdc++ std::list summary provider",
1736+
"^std::list<.+>(( )?&)?$", stl_summary_flags, true);
1737+
cpp_category_sp->AddTypeSummary(
1738+
"^std::forward_list<.+>(( )?&)?$", eFormatterMatchRegex,
1739+
TypeSummaryImplSP(new ScriptSummaryFormat(
1740+
stl_summary_flags,
1741+
"lldb.formatters.cpp.gnu_libstdcpp.ForwardListSummaryProvider")));
17071742
}
17081743

17091744
static void LoadMsvcStlFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {

0 commit comments

Comments
 (0)