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 ;
@@ -1331,6 +1332,37 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1331
1332
" ${var.__y_} ${var.__m_} ${var.__wdl_}" )));
1332
1333
}
1333
1334
1335
+ static void RegisterStdStringSummaryProvider (
1336
+ const lldb::TypeCategoryImplSP &category_sp, llvm::StringRef string_ty,
1337
+ llvm::StringRef char_ty, lldb::TypeSummaryImplSP summary_sp) {
1338
+ auto makeSpecifier = [](llvm::StringRef name) {
1339
+ return std::make_shared<lldb_private::TypeNameSpecifierImpl>(
1340
+ name, eFormatterMatchExact);
1341
+ };
1342
+
1343
+ category_sp->AddTypeSummary (makeSpecifier (string_ty), summary_sp);
1344
+
1345
+ // std::basic_string<char>
1346
+ category_sp->AddTypeSummary (
1347
+ makeSpecifier (llvm::formatv (" std::basic_string<{}>" , char_ty).str ()),
1348
+ summary_sp);
1349
+ // std::basic_string<char,std::char_traits<char>,std::allocator<char> >
1350
+ category_sp->AddTypeSummary (
1351
+ makeSpecifier (llvm::formatv (" std::basic_string<{0},std::char_traits<{0}>,"
1352
+ " std::allocator<{0}> >" ,
1353
+ char_ty)
1354
+ .str ()),
1355
+ summary_sp);
1356
+ // std::basic_string<char, std::char_traits<char>, std::allocator<char> >
1357
+ category_sp->AddTypeSummary (
1358
+ makeSpecifier (
1359
+ llvm::formatv (" std::basic_string<{0}, std::char_traits<{0}>, "
1360
+ " std::allocator<{0}> >" ,
1361
+ char_ty)
1362
+ .str ()),
1363
+ summary_sp);
1364
+ }
1365
+
1334
1366
static void LoadLibStdcppFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1335
1367
if (!cpp_category_sp)
1336
1368
return ;
@@ -1347,18 +1379,6 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1347
1379
lldb::TypeSummaryImplSP string_summary_sp (new CXXFunctionSummaryFormat (
1348
1380
stl_summary_flags, LibStdcppStringSummaryProvider,
1349
1381
" libstdc++ std::(w)string summary provider" ));
1350
-
1351
- cpp_category_sp->AddTypeSummary (" std::string" , eFormatterMatchExact,
1352
- string_summary_sp);
1353
- cpp_category_sp->AddTypeSummary (" std::basic_string<char>" ,
1354
- eFormatterMatchExact, string_summary_sp);
1355
- cpp_category_sp->AddTypeSummary (
1356
- " std::basic_string<char,std::char_traits<char>,std::allocator<char> >" ,
1357
- eFormatterMatchExact, string_summary_sp);
1358
- cpp_category_sp->AddTypeSummary (
1359
- " std::basic_string<char, std::char_traits<char>, std::allocator<char> >" ,
1360
- eFormatterMatchExact, string_summary_sp);
1361
-
1362
1382
cpp_category_sp->AddTypeSummary (" std::__cxx11::string" , eFormatterMatchExact,
1363
1383
string_summary_sp);
1364
1384
cpp_category_sp->AddTypeSummary (
@@ -1370,23 +1390,6 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1370
1390
" std::allocator<unsigned char> >" ,
1371
1391
eFormatterMatchExact, string_summary_sp);
1372
1392
1373
- // making sure we force-pick the summary for printing wstring (_M_p is a
1374
- // wchar_t*)
1375
- lldb::TypeSummaryImplSP std_wstring_summary_sp (
1376
- new StringSummaryFormat (stl_summary_flags, " ${var._M_dataplus._M_p%S}" ));
1377
-
1378
- cpp_category_sp->AddTypeSummary (" std::wstring" , eFormatterMatchExact,
1379
- std_wstring_summary_sp);
1380
- cpp_category_sp->AddTypeSummary (" std::basic_string<wchar_t>" ,
1381
- eFormatterMatchExact, std_wstring_summary_sp);
1382
- cpp_category_sp->AddTypeSummary (" std::basic_string<wchar_t,std::char_traits<"
1383
- " wchar_t>,std::allocator<wchar_t> >" ,
1384
- eFormatterMatchExact, std_wstring_summary_sp);
1385
- cpp_category_sp->AddTypeSummary (
1386
- " std::basic_string<wchar_t, std::char_traits<wchar_t>, "
1387
- " std::allocator<wchar_t> >" ,
1388
- eFormatterMatchExact, std_wstring_summary_sp);
1389
-
1390
1393
cpp_category_sp->AddTypeSummary (" std::__cxx11::wstring" , eFormatterMatchExact,
1391
1394
string_summary_sp);
1392
1395
cpp_category_sp->AddTypeSummary (
@@ -1581,6 +1584,81 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1581
1584
" ^std::optional<.+>(( )?&)?$" , stl_summary_flags, true );
1582
1585
}
1583
1586
1587
+ // / Load formatters that are formatting types from more than one STL
1588
+ static void LoadCommonStlFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1589
+ if (!cpp_category_sp)
1590
+ return ;
1591
+
1592
+ TypeSummaryImpl::Flags stl_summary_flags;
1593
+ stl_summary_flags.SetCascades (true )
1594
+ .SetSkipPointers (false )
1595
+ .SetSkipReferences (false )
1596
+ .SetDontShowChildren (true )
1597
+ .SetDontShowValue (false )
1598
+ .SetShowMembersOneLiner (false )
1599
+ .SetHideItemNames (false );
1600
+ using StringElementType = StringPrinter::StringElementType;
1601
+
1602
+ RegisterStdStringSummaryProvider (
1603
+ cpp_category_sp, " std::string" , " char" ,
1604
+ std::make_shared<CXXFunctionSummaryFormat>(
1605
+ stl_summary_flags,
1606
+ [](ValueObject &valobj, Stream &stream,
1607
+ const TypeSummaryOptions &options) {
1608
+ if (IsMsvcStlStringType (valobj))
1609
+ return MsvcStlStringSummaryProvider<StringElementType::ASCII>(
1610
+ valobj, stream, options);
1611
+ return LibStdcppStringSummaryProvider (valobj, stream, options);
1612
+ },
1613
+ " MSVC STL/libstdc++ std::string summary provider" ));
1614
+ RegisterStdStringSummaryProvider (
1615
+ cpp_category_sp, " std::wstring" , " wchar_t" ,
1616
+ std::make_shared<CXXFunctionSummaryFormat>(
1617
+ stl_summary_flags,
1618
+ [](ValueObject &valobj, Stream &stream,
1619
+ const TypeSummaryOptions &options) {
1620
+ if (IsMsvcStlStringType (valobj))
1621
+ return MsvcStlWStringSummaryProvider (valobj, stream, options);
1622
+ return LibStdcppStringSummaryProvider (valobj, stream, options);
1623
+ },
1624
+ " MSVC STL/libstdc++ std::wstring summary provider" ));
1625
+ }
1626
+
1627
+ static void LoadMsvcStlFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1628
+ if (!cpp_category_sp)
1629
+ return ;
1630
+
1631
+ TypeSummaryImpl::Flags stl_summary_flags;
1632
+ stl_summary_flags.SetCascades (true )
1633
+ .SetSkipPointers (false )
1634
+ .SetSkipReferences (false )
1635
+ .SetDontShowChildren (true )
1636
+ .SetDontShowValue (false )
1637
+ .SetShowMembersOneLiner (false )
1638
+ .SetHideItemNames (false );
1639
+
1640
+ using StringElementType = StringPrinter::StringElementType;
1641
+
1642
+ RegisterStdStringSummaryProvider (
1643
+ cpp_category_sp, " std::u8string" , " char8_t" ,
1644
+ std::make_shared<CXXFunctionSummaryFormat>(
1645
+ stl_summary_flags,
1646
+ MsvcStlStringSummaryProvider<StringElementType::UTF8>,
1647
+ " MSVC STL std::u8string summary provider" ));
1648
+ RegisterStdStringSummaryProvider (
1649
+ cpp_category_sp, " std::u16string" , " char16_t" ,
1650
+ std::make_shared<CXXFunctionSummaryFormat>(
1651
+ stl_summary_flags,
1652
+ MsvcStlStringSummaryProvider<StringElementType::UTF16>,
1653
+ " MSVC STL std::u16string summary provider" ));
1654
+ RegisterStdStringSummaryProvider (
1655
+ cpp_category_sp, " std::u32string" , " char32_t" ,
1656
+ std::make_shared<CXXFunctionSummaryFormat>(
1657
+ stl_summary_flags,
1658
+ MsvcStlStringSummaryProvider<StringElementType::UTF32>,
1659
+ " MSVC STL std::u32string summary provider" ));
1660
+ }
1661
+
1584
1662
static void LoadSystemFormatters (lldb::TypeCategoryImplSP cpp_category_sp) {
1585
1663
if (!cpp_category_sp)
1586
1664
return ;
@@ -1695,6 +1773,8 @@ lldb::TypeCategoryImplSP CPlusPlusLanguage::GetFormatters() {
1695
1773
// LLDB prioritizes the last loaded matching formatter.
1696
1774
LoadLibCxxFormatters (g_category);
1697
1775
LoadLibStdcppFormatters (g_category);
1776
+ LoadMsvcStlFormatters (g_category);
1777
+ LoadCommonStlFormatters (g_category);
1698
1778
LoadSystemFormatters (g_category);
1699
1779
}
1700
1780
});
0 commit comments