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,36 @@ 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::Twine (" 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::Twine (" std::basic_string<" ) + char_ty +
1393
+ " ,std::char_traits<" + char_ty + " >,std::allocator<" +
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 ((llvm::Twine (" std::basic_string<" ) + char_ty +
1400
+ " , std::char_traits<" + char_ty + " >, std::allocator<" +
1401
+ char_ty + " > >" )
1402
+ .str ()),
1403
+ summary_sp);
1404
+ }
1405
+
1375
1406
static void LoadLibStdcppFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1376
1407
if (!cpp_category_sp)
1377
1408
return ;
@@ -1385,27 +1416,13 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1385
1416
.SetShowMembersOneLiner (false )
1386
1417
.SetHideItemNames (false );
1387
1418
1388
- lldb::TypeSummaryImplSP std_string_summary_sp (
1389
- new StringSummaryFormat (stl_summary_flags, " ${var._M_dataplus._M_p}" ));
1390
-
1391
1419
lldb::TypeSummaryImplSP cxx11_string_summary_sp (new CXXFunctionSummaryFormat (
1392
1420
stl_summary_flags, LibStdcppStringSummaryProvider,
1393
1421
" libstdc++ c++11 std::string summary provider" ));
1394
1422
lldb::TypeSummaryImplSP cxx11_wstring_summary_sp (new CXXFunctionSummaryFormat (
1395
1423
stl_summary_flags, LibStdcppWStringSummaryProvider,
1396
1424
" libstdc++ c++11 std::wstring summary provider" ));
1397
1425
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
1426
cpp_category_sp->AddTypeSummary (" std::__cxx11::string" , eFormatterMatchExact,
1410
1427
cxx11_string_summary_sp);
1411
1428
cpp_category_sp->AddTypeSummary (
@@ -1418,23 +1435,6 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1418
1435
eFormatterMatchExact,
1419
1436
cxx11_string_summary_sp);
1420
1437
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
1438
cpp_category_sp->AddTypeSummary (" std::__cxx11::wstring" , eFormatterMatchExact,
1439
1439
cxx11_wstring_summary_sp);
1440
1440
cpp_category_sp->AddTypeSummary (
@@ -1629,6 +1629,81 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1629
1629
" ^std::optional<.+>(( )?&)?$" , stl_summary_flags, true );
1630
1630
}
1631
1631
1632
+ static void LoadCommonStlFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1633
+ if (!cpp_category_sp)
1634
+ return ;
1635
+
1636
+ TypeSummaryImpl::Flags stl_summary_flags;
1637
+ stl_summary_flags.SetCascades (true )
1638
+ .SetSkipPointers (false )
1639
+ .SetSkipReferences (false )
1640
+ .SetDontShowChildren (true )
1641
+ .SetDontShowValue (false )
1642
+ .SetShowMembersOneLiner (false )
1643
+ .SetHideItemNames (false );
1644
+ using StringElementType = StringPrinter::StringElementType;
1645
+
1646
+ RegisterStdStringSummaryProvider (
1647
+ cpp_category_sp, " std::string" , " char" ,
1648
+ std::make_shared<CXXFunctionSummaryFormat>(
1649
+ stl_summary_flags,
1650
+ [](ValueObject &valobj, Stream &stream,
1651
+ const TypeSummaryOptions &options) {
1652
+ if (IsMsvcStdStringType (valobj))
1653
+ return MsvcStlStringSummaryProvider<StringElementType::ASCII>(
1654
+ valobj, stream, options);
1655
+ return LibStdcppPre11StringSummaryProvider (valobj, stream, options);
1656
+ },
1657
+ " MSVC STL/libstdc++ std::string summary provider" ));
1658
+ RegisterStdStringSummaryProvider (
1659
+ cpp_category_sp, " std::wstring" , " wchar_t" ,
1660
+ std::make_shared<CXXFunctionSummaryFormat>(
1661
+ stl_summary_flags,
1662
+ [](ValueObject &valobj, Stream &stream,
1663
+ const TypeSummaryOptions &options) {
1664
+ if (IsMsvcStdStringType (valobj))
1665
+ return MsvcStlWStringSummaryProvider (valobj, stream, options);
1666
+ return LibStdcppPre11WStringSummaryProvider (valobj, stream,
1667
+ options);
1668
+ },
1669
+ " MSVC STL/libstdc++ std::wstring summary provider" ));
1670
+ }
1671
+
1672
+ static void LoadMsvcStlFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1673
+ if (!cpp_category_sp)
1674
+ return ;
1675
+
1676
+ TypeSummaryImpl::Flags stl_summary_flags;
1677
+ stl_summary_flags.SetCascades (true )
1678
+ .SetSkipPointers (false )
1679
+ .SetSkipReferences (false )
1680
+ .SetDontShowChildren (true )
1681
+ .SetDontShowValue (false )
1682
+ .SetShowMembersOneLiner (false )
1683
+ .SetHideItemNames (false );
1684
+
1685
+ using StringElementType = StringPrinter::StringElementType;
1686
+
1687
+ RegisterStdStringSummaryProvider (
1688
+ cpp_category_sp, " std::u8string" , " char8_t" ,
1689
+ std::make_shared<CXXFunctionSummaryFormat>(
1690
+ stl_summary_flags,
1691
+ MsvcStlStringSummaryProvider<StringElementType::UTF8>,
1692
+ " MSVC STL std::u8string summary provider" ));
1693
+ RegisterStdStringSummaryProvider (
1694
+ cpp_category_sp, " std::u16string" , " char16_t" ,
1695
+ std::make_shared<CXXFunctionSummaryFormat>(
1696
+ stl_summary_flags,
1697
+ MsvcStlStringSummaryProvider<StringElementType::UTF16>,
1698
+ " MSVC STL std::u16string summary provider" ));
1699
+ RegisterStdStringSummaryProvider (
1700
+ cpp_category_sp, " std::u32string" , " char32_t" ,
1701
+ std::make_shared<CXXFunctionSummaryFormat>(
1702
+ stl_summary_flags,
1703
+ MsvcStlStringSummaryProvider<StringElementType::UTF32>,
1704
+ " MSVC STL std::u32string summary provider" ));
1705
+ }
1706
+
1632
1707
static void LoadSystemFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1633
1708
if (!cpp_category_sp)
1634
1709
return ;
@@ -1743,6 +1818,8 @@ lldb::TypeCategoryImplSP CPlusPlusLanguage::GetFormatters() {
1743
1818
// LLDB prioritizes the last loaded matching formatter.
1744
1819
LoadLibCxxFormatters (g_category);
1745
1820
LoadLibStdcppFormatters (g_category);
1821
+ LoadMsvcStlFormatters (g_category);
1822
+ LoadCommonStlFormatters (g_category);
1746
1823
LoadSystemFormatters (g_category);
1747
1824
}
1748
1825
});
0 commit comments