24
24
#include " lldb/ValueObject/ValueObject.h"
25
25
#include " lldb/ValueObject/ValueObjectConstResult.h"
26
26
27
+ #include " Plugins/Language/CPlusPlus/CxxStringTypes.h"
27
28
#include " Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h"
28
29
#include " Plugins/TypeSystem/Clang/TypeSystemClang.h"
29
30
#include " lldb/lldb-enumerations.h"
@@ -535,70 +536,6 @@ ExtractLibcxxStringInfo(ValueObject &valobj) {
535
536
return std::make_pair (size, location_sp);
536
537
}
537
538
538
- static bool
539
- LibcxxWStringSummaryProvider (ValueObject &valobj, Stream &stream,
540
- const TypeSummaryOptions &summary_options,
541
- ValueObjectSP location_sp, size_t size) {
542
- if (size == 0 ) {
543
- stream.Printf (" L\"\" " );
544
- return true ;
545
- }
546
- if (!location_sp)
547
- return false ;
548
-
549
- StringPrinter::ReadBufferAndDumpToStreamOptions options (valobj);
550
- if (summary_options.GetCapping () == TypeSummaryCapping::eTypeSummaryCapped) {
551
- const auto max_size = valobj.GetTargetSP ()->GetMaximumSizeOfStringSummary ();
552
- if (size > max_size) {
553
- size = max_size;
554
- options.SetIsTruncated (true );
555
- }
556
- }
557
-
558
- DataExtractor extractor;
559
- const size_t bytes_read = location_sp->GetPointeeData (extractor, 0 , size);
560
- if (bytes_read < size)
561
- return false ;
562
-
563
- // std::wstring::size() is measured in 'characters', not bytes
564
- TypeSystemClangSP scratch_ts_sp =
565
- ScratchTypeSystemClang::GetForTarget (*valobj.GetTargetSP ());
566
- if (!scratch_ts_sp)
567
- return false ;
568
-
569
- auto wchar_t_size =
570
- scratch_ts_sp->GetBasicType (lldb::eBasicTypeWChar).GetByteSize (nullptr );
571
- if (!wchar_t_size)
572
- return false ;
573
-
574
- options.SetData (std::move (extractor));
575
- options.SetStream (&stream);
576
- options.SetPrefixToken (" L" );
577
- options.SetQuote (' "' );
578
- options.SetSourceSize (size);
579
- options.SetBinaryZeroIsTerminator (false );
580
-
581
- switch (*wchar_t_size) {
582
- case 1 :
583
- return StringPrinter::ReadBufferAndDumpToStream<
584
- lldb_private::formatters::StringPrinter::StringElementType::UTF8>(
585
- options);
586
- break ;
587
-
588
- case 2 :
589
- return StringPrinter::ReadBufferAndDumpToStream<
590
- lldb_private::formatters::StringPrinter::StringElementType::UTF16>(
591
- options);
592
- break ;
593
-
594
- case 4 :
595
- return StringPrinter::ReadBufferAndDumpToStream<
596
- lldb_private::formatters::StringPrinter::StringElementType::UTF32>(
597
- options);
598
- }
599
- return false ;
600
- }
601
-
602
539
bool lldb_private::formatters::LibcxxWStringSummaryProvider (
603
540
ValueObject &valobj, Stream &stream,
604
541
const TypeSummaryOptions &summary_options) {
@@ -609,52 +546,22 @@ bool lldb_private::formatters::LibcxxWStringSummaryProvider(
609
546
ValueObjectSP location_sp;
610
547
std::tie (size, location_sp) = *string_info;
611
548
612
- return ::LibcxxWStringSummaryProvider (valobj, stream, summary_options,
613
- location_sp, size);
614
- }
615
-
616
- template <StringPrinter::StringElementType element_type>
617
- static bool
618
- LibcxxStringSummaryProvider (ValueObject &valobj, Stream &stream,
619
- const TypeSummaryOptions &summary_options,
620
- std::string prefix_token, ValueObjectSP location_sp,
621
- uint64_t size) {
622
-
623
- if (size == 0 ) {
624
- stream.Printf (" \"\" " );
625
- return true ;
626
- }
627
-
628
- if (!location_sp)
549
+ auto wchar_t_size = GetWCharByteSize (valobj);
550
+ if (!wchar_t_size)
629
551
return false ;
630
552
631
- StringPrinter::ReadBufferAndDumpToStreamOptions options (valobj);
632
-
633
- if (summary_options.GetCapping () == TypeSummaryCapping::eTypeSummaryCapped) {
634
- const auto max_size = valobj.GetTargetSP ()->GetMaximumSizeOfStringSummary ();
635
- if (size > max_size) {
636
- size = max_size;
637
- options.SetIsTruncated (true );
638
- }
639
- }
640
-
641
- {
642
- DataExtractor extractor;
643
- const size_t bytes_read = location_sp->GetPointeeData (extractor, 0 , size);
644
- if (bytes_read < size)
645
- return false ;
646
-
647
- options.SetData (std::move (extractor));
553
+ switch (*wchar_t_size) {
554
+ case 1 :
555
+ return StringBufferSummaryProvider<StringPrinter::StringElementType::UTF8>(
556
+ stream, summary_options, location_sp, size, " L" );
557
+ case 2 :
558
+ return StringBufferSummaryProvider<StringPrinter::StringElementType::UTF16>(
559
+ stream, summary_options, location_sp, size, " L" );
560
+ case 4 :
561
+ return StringBufferSummaryProvider<StringPrinter::StringElementType::UTF32>(
562
+ stream, summary_options, location_sp, size, " L" );
648
563
}
649
- options.SetStream (&stream);
650
- if (prefix_token.empty ())
651
- options.SetPrefixToken (nullptr );
652
- else
653
- options.SetPrefixToken (prefix_token);
654
- options.SetQuote (' "' );
655
- options.SetSourceSize (size);
656
- options.SetBinaryZeroIsTerminator (false );
657
- return StringPrinter::ReadBufferAndDumpToStream<element_type>(options);
564
+ return false ;
658
565
}
659
566
660
567
template <StringPrinter::StringElementType element_type>
@@ -669,8 +576,8 @@ LibcxxStringSummaryProvider(ValueObject &valobj, Stream &stream,
669
576
ValueObjectSP location_sp;
670
577
std::tie (size, location_sp) = *string_info;
671
578
672
- return LibcxxStringSummaryProvider <element_type>(
673
- valobj, stream, summary_options, prefix_token, location_sp, size);
579
+ return StringBufferSummaryProvider <element_type>(
580
+ stream, summary_options, location_sp, size, prefix_token );
674
581
}
675
582
template <StringPrinter::StringElementType element_type>
676
583
static bool formatStringImpl (ValueObject &valobj, Stream &stream,
@@ -742,8 +649,8 @@ static bool formatStringViewImpl(ValueObject &valobj, Stream &stream,
742
649
return true ;
743
650
}
744
651
745
- return LibcxxStringSummaryProvider <element_type>(
746
- valobj, stream, summary_options, prefix_token, dataobj, size);
652
+ return StringBufferSummaryProvider <element_type>(stream, summary_options,
653
+ dataobj, size, prefix_token );
747
654
}
748
655
749
656
bool lldb_private::formatters::LibcxxStringViewSummaryProviderASCII (
@@ -781,8 +688,22 @@ bool lldb_private::formatters::LibcxxWStringViewSummaryProvider(
781
688
return true ;
782
689
}
783
690
784
- return ::LibcxxWStringSummaryProvider (valobj, stream, summary_options,
785
- dataobj, size);
691
+ auto wchar_t_size = GetWCharByteSize (valobj);
692
+ if (!wchar_t_size)
693
+ return false ;
694
+
695
+ switch (*wchar_t_size) {
696
+ case 1 :
697
+ return StringBufferSummaryProvider<StringPrinter::StringElementType::UTF8>(
698
+ stream, summary_options, dataobj, size, " L" );
699
+ case 2 :
700
+ return StringBufferSummaryProvider<StringPrinter::StringElementType::UTF16>(
701
+ stream, summary_options, dataobj, size, " L" );
702
+ case 4 :
703
+ return StringBufferSummaryProvider<StringPrinter::StringElementType::UTF32>(
704
+ stream, summary_options, dataobj, size, " L" );
705
+ }
706
+ return false ;
786
707
}
787
708
788
709
static bool
0 commit comments