46
46
#include " LibCxxVariant.h"
47
47
#include " LibStdcpp.h"
48
48
#include " MSVCUndecoratedNameParser.h"
49
+ #include " MsvcStl.h"
49
50
#include " lldb/lldb-enumerations.h"
50
51
51
52
using namespace lldb ;
@@ -1372,6 +1373,37 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1372
1373
" ${var.__y_} ${var.__m_} ${var.__wdl_}" )));
1373
1374
}
1374
1375
1376
+ static void RegisterStdStringSummaryProvider (
1377
+ const lldb::TypeCategoryImplSP &category_sp, llvm::StringRef string_ty,
1378
+ llvm::StringRef char_ty, lldb::TypeSummaryImplSP summary_sp) {
1379
+ auto makeSpecifier = [](llvm::StringRef name) {
1380
+ return std::make_shared<lldb_private::TypeNameSpecifierImpl>(
1381
+ name, eFormatterMatchExact);
1382
+ };
1383
+
1384
+ category_sp->AddTypeSummary (makeSpecifier (string_ty), summary_sp);
1385
+
1386
+ // std::basic_string<char>
1387
+ category_sp->AddTypeSummary (
1388
+ makeSpecifier (llvm::formatv (" std::basic_string<{}>" , char_ty).str ()),
1389
+ summary_sp);
1390
+ // std::basic_string<char,std::char_traits<char>,std::allocator<char> >
1391
+ category_sp->AddTypeSummary (
1392
+ makeSpecifier (llvm::formatv (" std::basic_string<{0},std::char_traits<{0}>,"
1393
+ " std::allocator<{0}> >" ,
1394
+ char_ty)
1395
+ .str ()),
1396
+ summary_sp);
1397
+ // std::basic_string<char, std::char_traits<char>, std::allocator<char> >
1398
+ category_sp->AddTypeSummary (
1399
+ makeSpecifier (
1400
+ llvm::formatv (" std::basic_string<{0}, std::char_traits<{0}>, "
1401
+ " std::allocator<{0}> >" ,
1402
+ char_ty)
1403
+ .str ()),
1404
+ summary_sp);
1405
+ }
1406
+
1375
1407
static void LoadLibStdcppFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1376
1408
if (!cpp_category_sp)
1377
1409
return ;
@@ -1385,27 +1417,13 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1385
1417
.SetShowMembersOneLiner (false )
1386
1418
.SetHideItemNames (false );
1387
1419
1388
- lldb::TypeSummaryImplSP std_string_summary_sp (
1389
- new StringSummaryFormat (stl_summary_flags, " ${var._M_dataplus._M_p}" ));
1390
-
1391
1420
lldb::TypeSummaryImplSP cxx11_string_summary_sp (new CXXFunctionSummaryFormat (
1392
1421
stl_summary_flags, LibStdcppStringSummaryProvider,
1393
1422
" libstdc++ c++11 std::string summary provider" ));
1394
1423
lldb::TypeSummaryImplSP cxx11_wstring_summary_sp (new CXXFunctionSummaryFormat (
1395
- stl_summary_flags, LibStdcppWStringSummaryProvider ,
1424
+ stl_summary_flags, LibStdcppStringSummaryProvider ,
1396
1425
" libstdc++ c++11 std::wstring summary provider" ));
1397
1426
1398
- cpp_category_sp->AddTypeSummary (" std::string" , eFormatterMatchExact,
1399
- std_string_summary_sp);
1400
- cpp_category_sp->AddTypeSummary (" std::basic_string<char>" ,
1401
- eFormatterMatchExact, std_string_summary_sp);
1402
- cpp_category_sp->AddTypeSummary (
1403
- " std::basic_string<char,std::char_traits<char>,std::allocator<char> >" ,
1404
- eFormatterMatchExact, std_string_summary_sp);
1405
- cpp_category_sp->AddTypeSummary (
1406
- " std::basic_string<char, std::char_traits<char>, std::allocator<char> >" ,
1407
- eFormatterMatchExact, std_string_summary_sp);
1408
-
1409
1427
cpp_category_sp->AddTypeSummary (" std::__cxx11::string" , eFormatterMatchExact,
1410
1428
cxx11_string_summary_sp);
1411
1429
cpp_category_sp->AddTypeSummary (
@@ -1418,23 +1436,6 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1418
1436
eFormatterMatchExact,
1419
1437
cxx11_string_summary_sp);
1420
1438
1421
- // making sure we force-pick the summary for printing wstring (_M_p is a
1422
- // wchar_t*)
1423
- lldb::TypeSummaryImplSP std_wstring_summary_sp (
1424
- new StringSummaryFormat (stl_summary_flags, " ${var._M_dataplus._M_p%S}" ));
1425
-
1426
- cpp_category_sp->AddTypeSummary (" std::wstring" , eFormatterMatchExact,
1427
- std_wstring_summary_sp);
1428
- cpp_category_sp->AddTypeSummary (" std::basic_string<wchar_t>" ,
1429
- eFormatterMatchExact, std_wstring_summary_sp);
1430
- cpp_category_sp->AddTypeSummary (" std::basic_string<wchar_t,std::char_traits<"
1431
- " wchar_t>,std::allocator<wchar_t> >" ,
1432
- eFormatterMatchExact, std_wstring_summary_sp);
1433
- cpp_category_sp->AddTypeSummary (
1434
- " std::basic_string<wchar_t, std::char_traits<wchar_t>, "
1435
- " std::allocator<wchar_t> >" ,
1436
- eFormatterMatchExact, std_wstring_summary_sp);
1437
-
1438
1439
cpp_category_sp->AddTypeSummary (" std::__cxx11::wstring" , eFormatterMatchExact,
1439
1440
cxx11_wstring_summary_sp);
1440
1441
cpp_category_sp->AddTypeSummary (
@@ -1629,6 +1630,81 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1629
1630
" ^std::optional<.+>(( )?&)?$" , stl_summary_flags, true );
1630
1631
}
1631
1632
1633
+ // / Load formatters that are formatting types from more than one STL
1634
+ static void LoadCommonStlFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1635
+ if (!cpp_category_sp)
1636
+ return ;
1637
+
1638
+ TypeSummaryImpl::Flags stl_summary_flags;
1639
+ stl_summary_flags.SetCascades (true )
1640
+ .SetSkipPointers (false )
1641
+ .SetSkipReferences (false )
1642
+ .SetDontShowChildren (true )
1643
+ .SetDontShowValue (false )
1644
+ .SetShowMembersOneLiner (false )
1645
+ .SetHideItemNames (false );
1646
+ using StringElementType = StringPrinter::StringElementType;
1647
+
1648
+ RegisterStdStringSummaryProvider (
1649
+ cpp_category_sp, " std::string" , " char" ,
1650
+ std::make_shared<CXXFunctionSummaryFormat>(
1651
+ stl_summary_flags,
1652
+ [](ValueObject &valobj, Stream &stream,
1653
+ const TypeSummaryOptions &options) {
1654
+ if (IsMsvcStlStringType (valobj))
1655
+ return MsvcStlStringSummaryProvider<StringElementType::ASCII>(
1656
+ valobj, stream, options);
1657
+ return LibStdcppStringSummaryProvider (valobj, stream, options);
1658
+ },
1659
+ " MSVC STL/libstdc++ std::string summary provider" ));
1660
+ RegisterStdStringSummaryProvider (
1661
+ cpp_category_sp, " std::wstring" , " wchar_t" ,
1662
+ std::make_shared<CXXFunctionSummaryFormat>(
1663
+ stl_summary_flags,
1664
+ [](ValueObject &valobj, Stream &stream,
1665
+ const TypeSummaryOptions &options) {
1666
+ if (IsMsvcStlStringType (valobj))
1667
+ return MsvcStlWStringSummaryProvider (valobj, stream, options);
1668
+ return LibStdcppStringSummaryProvider (valobj, stream, options);
1669
+ },
1670
+ " MSVC STL/libstdc++ std::wstring summary provider" ));
1671
+ }
1672
+
1673
+ static void LoadMsvcStlFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1674
+ if (!cpp_category_sp)
1675
+ return ;
1676
+
1677
+ TypeSummaryImpl::Flags stl_summary_flags;
1678
+ stl_summary_flags.SetCascades (true )
1679
+ .SetSkipPointers (false )
1680
+ .SetSkipReferences (false )
1681
+ .SetDontShowChildren (true )
1682
+ .SetDontShowValue (false )
1683
+ .SetShowMembersOneLiner (false )
1684
+ .SetHideItemNames (false );
1685
+
1686
+ using StringElementType = StringPrinter::StringElementType;
1687
+
1688
+ RegisterStdStringSummaryProvider (
1689
+ cpp_category_sp, " std::u8string" , " char8_t" ,
1690
+ std::make_shared<CXXFunctionSummaryFormat>(
1691
+ stl_summary_flags,
1692
+ MsvcStlStringSummaryProvider<StringElementType::UTF8>,
1693
+ " MSVC STL std::u8string summary provider" ));
1694
+ RegisterStdStringSummaryProvider (
1695
+ cpp_category_sp, " std::u16string" , " char16_t" ,
1696
+ std::make_shared<CXXFunctionSummaryFormat>(
1697
+ stl_summary_flags,
1698
+ MsvcStlStringSummaryProvider<StringElementType::UTF16>,
1699
+ " MSVC STL std::u16string summary provider" ));
1700
+ RegisterStdStringSummaryProvider (
1701
+ cpp_category_sp, " std::u32string" , " char32_t" ,
1702
+ std::make_shared<CXXFunctionSummaryFormat>(
1703
+ stl_summary_flags,
1704
+ MsvcStlStringSummaryProvider<StringElementType::UTF32>,
1705
+ " MSVC STL std::u32string summary provider" ));
1706
+ }
1707
+
1632
1708
static void LoadSystemFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1633
1709
if (!cpp_category_sp)
1634
1710
return ;
@@ -1743,6 +1819,8 @@ lldb::TypeCategoryImplSP CPlusPlusLanguage::GetFormatters() {
1743
1819
// LLDB prioritizes the last loaded matching formatter.
1744
1820
LoadLibCxxFormatters (g_category);
1745
1821
LoadLibStdcppFormatters (g_category);
1822
+ LoadMsvcStlFormatters (g_category);
1823
+ LoadCommonStlFormatters (g_category);
1746
1824
LoadSystemFormatters (g_category);
1747
1825
}
1748
1826
});
0 commit comments