@@ -598,6 +598,126 @@ bool lldb_private::formatters::swift::ObjC_Selector_SummaryProvider(
598
598
StringPrinter::StringElementType::ASCII>(read_options);
599
599
}
600
600
601
+ template <int Key> struct TypePreservingNSNumber ;
602
+
603
+ template <> struct TypePreservingNSNumber <0 > {
604
+ typedef int64_t SixtyFourValueType;
605
+ typedef int32_t ThirtyTwoValueType;
606
+
607
+ static constexpr const char *FormatString = " Int(%" PRId64 " )" ;
608
+ };
609
+
610
+ template <> struct TypePreservingNSNumber <1 > {
611
+ typedef int64_t ValueType;
612
+ static constexpr const char *FormatString = " Int64(%" PRId64 " )" ;
613
+ };
614
+
615
+ template <> struct TypePreservingNSNumber <2 > {
616
+ typedef int32_t ValueType;
617
+ static constexpr const char *FormatString = " Int32(%" PRId32 " )" ;
618
+ };
619
+
620
+ template <> struct TypePreservingNSNumber <3 > {
621
+ typedef int16_t ValueType;
622
+ static constexpr const char *FormatString = " Int16(%" PRId16 " )" ;
623
+ };
624
+
625
+ template <> struct TypePreservingNSNumber <4 > {
626
+ typedef int8_t ValueType;
627
+ static constexpr const char *FormatString = " Int8(%" PRId8 " )" ;
628
+ };
629
+
630
+ template <> struct TypePreservingNSNumber <5 > {
631
+ typedef uint64_t SixtyFourValueType;
632
+ typedef uint32_t ThirtyTwoValueType;
633
+
634
+ static constexpr const char *FormatString = " UInt(%" PRIu64 " )" ;
635
+ };
636
+
637
+ template <> struct TypePreservingNSNumber <6 > {
638
+ typedef uint64_t ValueType;
639
+ static constexpr const char *FormatString = " UInt64(%" PRIu64 " )" ;
640
+ };
641
+
642
+ template <> struct TypePreservingNSNumber <7 > {
643
+ typedef uint32_t ValueType;
644
+ static constexpr const char *FormatString = " UInt32(%" PRIu32 " )" ;
645
+ };
646
+
647
+ template <> struct TypePreservingNSNumber <8 > {
648
+ typedef uint16_t ValueType;
649
+ static constexpr const char *FormatString = " UInt16(%" PRIu16 " )" ;
650
+ };
651
+
652
+ template <> struct TypePreservingNSNumber <9 > {
653
+ typedef uint8_t ValueType;
654
+ static constexpr const char *FormatString = " UInt8(%" PRIu8 " )" ;
655
+ };
656
+
657
+ template <> struct TypePreservingNSNumber <10 > {
658
+ typedef float ValueType;
659
+ static constexpr const char *FormatString = " Float(%f)" ;
660
+ };
661
+
662
+ template <> struct TypePreservingNSNumber <11 > {
663
+ typedef double ValueType;
664
+ static constexpr const char *FormatString = " Double(%f)" ;
665
+ };
666
+
667
+ template <> struct TypePreservingNSNumber <12 > {
668
+ typedef double SixtyFourValueType;
669
+ typedef float ThirtyTwoValueType;
670
+
671
+ static constexpr const char *FormatString = " CGFloat(%f)" ;
672
+ };
673
+
674
+ template <> struct TypePreservingNSNumber <13 > {
675
+ typedef bool ValueType;
676
+ static constexpr const char *FormatString = " Bool(%d)" ;
677
+ };
678
+
679
+ template <int Key,
680
+ typename Value = typename TypePreservingNSNumber<Key>::ValueType>
681
+ bool PrintTypePreservingNSNumber (DataBufferSP buffer_sp, Stream &stream) {
682
+ Value value;
683
+ memcpy (&value, buffer_sp->GetBytes (), sizeof (value));
684
+ stream.Printf (TypePreservingNSNumber<Key>::FormatString, value);
685
+ return true ;
686
+ }
687
+
688
+ template <>
689
+ bool PrintTypePreservingNSNumber<13 , void >(DataBufferSP buffer_sp,
690
+ Stream &stream) {
691
+ typename TypePreservingNSNumber<13 >::ValueType value;
692
+ memcpy (&value, buffer_sp->GetBytes (), sizeof (value));
693
+ stream.PutCString (value ? " true" : " false" );
694
+ return true ;
695
+ }
696
+
697
+ template <int Key, typename SixtyFour =
698
+ typename TypePreservingNSNumber<Key>::SixtyFourValueType,
699
+ typename ThirtyTwo =
700
+ typename TypePreservingNSNumber<Key>::ThirtyTwoValueType>
701
+ bool PrintTypePreservingNSNumber (DataBufferSP buffer_sp, ProcessSP process_sp,
702
+ Stream &stream) {
703
+ switch (process_sp->GetAddressByteSize ()) {
704
+ case 4 : {
705
+ ThirtyTwo value;
706
+ memcpy (&value, buffer_sp->GetBytes (), sizeof (value));
707
+ stream.Printf (TypePreservingNSNumber<Key>::FormatString, (SixtyFour)value);
708
+ return true ;
709
+ }
710
+ case 8 : {
711
+ SixtyFour value;
712
+ memcpy (&value, buffer_sp->GetBytes (), sizeof (value));
713
+ stream.Printf (TypePreservingNSNumber<Key>::FormatString, value);
714
+ return true ;
715
+ }
716
+ }
717
+
718
+ llvm_unreachable (" unknown address byte size" );
719
+ }
720
+
601
721
bool lldb_private::formatters::swift::TypePreservingNSNumber_SummaryProvider (
602
722
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
603
723
lldb::addr_t ptr_value (valobj.GetValueAsUnsigned (LLDB_INVALID_ADDRESS));
@@ -609,16 +729,16 @@ bool lldb_private::formatters::swift::TypePreservingNSNumber_SummaryProvider(
609
729
return false ;
610
730
611
731
uint32_t ptr_size = process_sp->GetAddressByteSize ();
612
- const uint32_t size_of_tag = 4 ;
732
+ const uint32_t size_of_tag = 1 ;
613
733
const uint32_t size_of_payload = 8 ;
614
734
615
- lldb::addr_t addr_of_tag = ptr_value + ptr_size;
616
- lldb::addr_t addr_of_payload = addr_of_tag + size_of_tag ;
735
+ lldb::addr_t addr_of_payload = ptr_value + ptr_size;
736
+ lldb::addr_t addr_of_tag = addr_of_payload + size_of_payload ;
617
737
618
738
Error read_error;
619
739
uint64_t tag = process_sp->ReadUnsignedIntegerFromMemory (
620
740
addr_of_tag, size_of_tag, 0 , read_error);
621
- if (read_error.Fail () || tag == 0 || tag > 6 )
741
+ if (read_error.Fail ())
622
742
return false ;
623
743
624
744
DataBufferSP buffer_sp (new DataBufferHeap (size_of_payload, 0 ));
@@ -627,53 +747,34 @@ bool lldb_private::formatters::swift::TypePreservingNSNumber_SummaryProvider(
627
747
if (read_error.Fail ())
628
748
return false ;
629
749
750
+ #define PROCESS_DEPENDENT_TAG (Key ) \
751
+ case Key: \
752
+ return PrintTypePreservingNSNumber<Key>(buffer_sp, process_sp, stream);
753
+ #define PROCESS_INDEPENDENT_TAG (Key ) \
754
+ case Key: \
755
+ return PrintTypePreservingNSNumber<Key>(buffer_sp, stream);
756
+
630
757
switch (tag) {
631
- case 1 : // Int
632
- {
633
- uint64_t payload = 0 ;
634
- memcpy (&payload, buffer_sp->GetBytes (), sizeof (payload));
635
- stream.Printf (" Int(%" PRId64 " )" , payload);
636
- return true ;
637
- }
638
- case 2 : // UInt
639
- {
640
- uint64_t payload = 0 ;
641
- memcpy (&payload, buffer_sp->GetBytes (), sizeof (payload));
642
- stream.Printf (" UInt(%" PRIu64 " )" , payload);
643
- return true ;
644
- }
645
- case 3 : // Float
646
- {
647
- float payload = 0 ;
648
- memcpy (&payload, buffer_sp->GetBytes (), sizeof (payload));
649
- stream.Printf (" Float(%f)" , payload);
650
- return true ;
651
- }
652
- case 4 : // Double
653
- {
654
- double payload = 0 ;
655
- memcpy (&payload, buffer_sp->GetBytes (), sizeof (payload));
656
- stream.Printf (" Double(%f)" , payload);
657
- return true ;
658
- }
659
- case 5 : // CGFloat
660
- {
661
- if (ptr_size == 4 ) {
662
- float payload = 0 ;
663
- memcpy (&payload, buffer_sp->GetBytes (), sizeof (payload));
664
- stream.Printf (" CGFloat(%f)" , payload);
665
- return true ;
666
- } else if (ptr_size == 8 ) {
667
- double payload = 0 ;
668
- memcpy (&payload, buffer_sp->GetBytes (), sizeof (payload));
669
- stream.Printf (" CGFloat(%f)" , payload);
670
- return true ;
671
- }
672
- break ;
673
- }
758
+ PROCESS_DEPENDENT_TAG (0 );
759
+ PROCESS_INDEPENDENT_TAG (1 );
760
+ PROCESS_INDEPENDENT_TAG (2 );
761
+ PROCESS_INDEPENDENT_TAG (3 );
762
+ PROCESS_INDEPENDENT_TAG (4 );
763
+ PROCESS_DEPENDENT_TAG (5 );
764
+ PROCESS_INDEPENDENT_TAG (6 );
765
+ PROCESS_INDEPENDENT_TAG (7 );
766
+ PROCESS_INDEPENDENT_TAG (8 );
767
+ PROCESS_INDEPENDENT_TAG (9 );
768
+ PROCESS_INDEPENDENT_TAG (10 );
769
+ PROCESS_INDEPENDENT_TAG (11 );
770
+ PROCESS_DEPENDENT_TAG (12 );
771
+ PROCESS_INDEPENDENT_TAG (13 );
674
772
default :
675
773
break ;
676
774
}
677
775
776
+ #undef PROCESS_DEPENDENT_TAG
777
+ #undef PROCESS_INDEPENDENT_TAG
778
+
678
779
return false ;
679
780
}
0 commit comments