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,52 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1372
1373
" ${var.__y_} ${var.__m_} ${var.__wdl_}" )));
1373
1374
}
1374
1375
1376
+ static bool IsMsvcStdStringType (const FormattersMatchCandidate &candidate) {
1377
+ std::vector<uint32_t > indexes;
1378
+ return candidate.GetType ()
1379
+ .GetCompilerType (true )
1380
+ .GetIndexOfChildMemberWithName (" _Mypair" , true , indexes) > 0 ;
1381
+ }
1382
+
1383
+ static bool
1384
+ IsLibstdcppStdStringType (const FormattersMatchCandidate &candidate) {
1385
+ std::vector<uint32_t > indexes;
1386
+ return candidate.GetType ()
1387
+ .GetCompilerType (true )
1388
+ .GetIndexOfChildMemberWithName (" _M_dataplus" , true , indexes) > 0 ;
1389
+ }
1390
+
1391
+ static void RegisterStdStringSummaryProvider (
1392
+ const lldb::TypeCategoryImplSP &category_sp, llvm::StringRef string_ty,
1393
+ llvm::StringRef char_ty, CxxTypeCandidateMatchFn *match_fn,
1394
+ lldb::TypeSummaryImplSP summary_sp) {
1395
+ auto makeSpecifier = [match_fn](llvm::StringRef name) {
1396
+ return std::make_shared<lldb_private::TypeNameSpecifierImpl>(
1397
+ name, eFormatterMatchExact, match_fn);
1398
+ };
1399
+
1400
+ category_sp->AddTypeSummary (makeSpecifier (string_ty), summary_sp);
1401
+
1402
+ // std::basic_string<char>
1403
+ category_sp->AddTypeSummary (
1404
+ makeSpecifier ((llvm::Twine (" std::basic_string<" ) + char_ty + " >" ).str ()),
1405
+ summary_sp);
1406
+ // std::basic_string<char,std::char_traits<char>,std::allocator<char> >
1407
+ category_sp->AddTypeSummary (
1408
+ makeSpecifier ((llvm::Twine (" std::basic_string<" ) + char_ty +
1409
+ " ,std::char_traits<" + char_ty + " >,std::allocator<" +
1410
+ char_ty + " > >" )
1411
+ .str ()),
1412
+ summary_sp);
1413
+ // std::basic_string<char, std::char_traits<char>, std::allocator<char> >
1414
+ category_sp->AddTypeSummary (
1415
+ makeSpecifier ((llvm::Twine (" std::basic_string<" ) + char_ty +
1416
+ " , std::char_traits<" + char_ty + " >, std::allocator<" +
1417
+ char_ty + " > >" )
1418
+ .str ()),
1419
+ summary_sp);
1420
+ }
1421
+
1375
1422
static void LoadLibStdcppFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1376
1423
if (!cpp_category_sp)
1377
1424
return ;
@@ -1385,26 +1432,17 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1385
1432
.SetShowMembersOneLiner (false )
1386
1433
.SetHideItemNames (false );
1387
1434
1388
- lldb::TypeSummaryImplSP std_string_summary_sp (
1389
- new StringSummaryFormat (stl_summary_flags, " ${var._M_dataplus._M_p}" ));
1390
-
1391
1435
lldb::TypeSummaryImplSP cxx11_string_summary_sp (new CXXFunctionSummaryFormat (
1392
1436
stl_summary_flags, LibStdcppStringSummaryProvider,
1393
1437
" libstdc++ c++11 std::string summary provider" ));
1394
1438
lldb::TypeSummaryImplSP cxx11_wstring_summary_sp (new CXXFunctionSummaryFormat (
1395
1439
stl_summary_flags, LibStdcppWStringSummaryProvider,
1396
1440
" libstdc++ c++11 std::wstring summary provider" ));
1397
1441
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);
1442
+ RegisterStdStringSummaryProvider (
1443
+ cpp_category_sp, " std::string" , " char" , IsLibstdcppStdStringType,
1444
+ std::make_shared<StringSummaryFormat>(stl_summary_flags,
1445
+ " ${var._M_dataplus._M_p}" ));
1408
1446
1409
1447
cpp_category_sp->AddTypeSummary (" std::__cxx11::string" , eFormatterMatchExact,
1410
1448
cxx11_string_summary_sp);
@@ -1420,20 +1458,10 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1420
1458
1421
1459
// making sure we force-pick the summary for printing wstring (_M_p is a
1422
1460
// 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);
1461
+ RegisterStdStringSummaryProvider (
1462
+ cpp_category_sp, " std::wstring" , " wchar_t" , IsLibstdcppStdStringType,
1463
+ std::make_shared<StringSummaryFormat>(stl_summary_flags,
1464
+ " ${var._M_dataplus._M_p%S}" ));
1437
1465
1438
1466
cpp_category_sp->AddTypeSummary (" std::__cxx11::wstring" , eFormatterMatchExact,
1439
1467
cxx11_wstring_summary_sp);
@@ -1629,6 +1657,52 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1629
1657
" ^std::optional<.+>(( )?&)?$" , stl_summary_flags, true );
1630
1658
}
1631
1659
1660
+ static void LoadMsvcStlFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1661
+ if (!cpp_category_sp)
1662
+ return ;
1663
+
1664
+ TypeSummaryImpl::Flags stl_summary_flags;
1665
+ stl_summary_flags.SetCascades (true )
1666
+ .SetSkipPointers (false )
1667
+ .SetSkipReferences (false )
1668
+ .SetDontShowChildren (true )
1669
+ .SetDontShowValue (false )
1670
+ .SetShowMembersOneLiner (false )
1671
+ .SetHideItemNames (false );
1672
+
1673
+ using StringElementType = StringPrinter::StringElementType;
1674
+
1675
+ RegisterStdStringSummaryProvider (
1676
+ cpp_category_sp, " std::string" , " char" , IsMsvcStdStringType,
1677
+ std::make_shared<CXXFunctionSummaryFormat>(
1678
+ stl_summary_flags,
1679
+ MsvcStlStringSummaryProvider<StringElementType::ASCII>,
1680
+ " MSVC STL std::string summary provider" ));
1681
+ RegisterStdStringSummaryProvider (
1682
+ cpp_category_sp, " std::wstring" , " wchar_t" , IsMsvcStdStringType,
1683
+ std::make_shared<CXXFunctionSummaryFormat>(
1684
+ stl_summary_flags, MsvcStlWStringSummaryProvider,
1685
+ " MSVC STL std::wstring summary provider" ));
1686
+ RegisterStdStringSummaryProvider (
1687
+ cpp_category_sp, " std::u8string" , " char8_t" , IsMsvcStdStringType,
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" , IsMsvcStdStringType,
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" , IsMsvcStdStringType,
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,7 @@ 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);
1746
1821
LoadSystemFormatters (g_category);
1747
1822
}
1748
1823
});
0 commit comments