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,80 @@ 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 LibStdcppStringSummaryProvider (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 LibStdcppWStringSummaryProvider (valobj, stream, options);
1667
+ },
1668
+ " MSVC STL/libstdc++ std::wstring summary provider" ));
1669
+ }
1670
+
1671
+ static void LoadMsvcStlFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1672
+ if (!cpp_category_sp)
1673
+ return ;
1674
+
1675
+ TypeSummaryImpl::Flags stl_summary_flags;
1676
+ stl_summary_flags.SetCascades (true )
1677
+ .SetSkipPointers (false )
1678
+ .SetSkipReferences (false )
1679
+ .SetDontShowChildren (true )
1680
+ .SetDontShowValue (false )
1681
+ .SetShowMembersOneLiner (false )
1682
+ .SetHideItemNames (false );
1683
+
1684
+ using StringElementType = StringPrinter::StringElementType;
1685
+
1686
+ RegisterStdStringSummaryProvider (
1687
+ cpp_category_sp, " std::u8string" , " char8_t" ,
1688
+ std::make_shared<CXXFunctionSummaryFormat>(
1689
+ stl_summary_flags,
1690
+ MsvcStlStringSummaryProvider<StringElementType::UTF8>,
1691
+ " MSVC STL std::u8string summary provider" ));
1692
+ RegisterStdStringSummaryProvider (
1693
+ cpp_category_sp, " std::u16string" , " char16_t" ,
1694
+ std::make_shared<CXXFunctionSummaryFormat>(
1695
+ stl_summary_flags,
1696
+ MsvcStlStringSummaryProvider<StringElementType::UTF16>,
1697
+ " MSVC STL std::u16string summary provider" ));
1698
+ RegisterStdStringSummaryProvider (
1699
+ cpp_category_sp, " std::u32string" , " char32_t" ,
1700
+ std::make_shared<CXXFunctionSummaryFormat>(
1701
+ stl_summary_flags,
1702
+ MsvcStlStringSummaryProvider<StringElementType::UTF32>,
1703
+ " MSVC STL std::u32string summary provider" ));
1704
+ }
1705
+
1632
1706
static void LoadSystemFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1633
1707
if (!cpp_category_sp)
1634
1708
return ;
@@ -1743,6 +1817,8 @@ lldb::TypeCategoryImplSP CPlusPlusLanguage::GetFormatters() {
1743
1817
// LLDB prioritizes the last loaded matching formatter.
1744
1818
LoadLibCxxFormatters (g_category);
1745
1819
LoadLibStdcppFormatters (g_category);
1820
+ LoadMsvcStlFormatters (g_category);
1821
+ LoadCommonStlFormatters (g_category);
1746
1822
LoadSystemFormatters (g_category);
1747
1823
}
1748
1824
});
0 commit comments