Skip to content

Commit f6a5830

Browse files
author
Enrico Granata
committed
Adjust LLDB for changes to the layout of _SwiftTypePreservingNSNumber
1 parent 7924534 commit f6a5830

File tree

3 files changed

+151
-50
lines changed

3 files changed

+151
-50
lines changed

Diff for: packages/Python/lldbsuite/test/lang/swift/variables/bridged_array/TestSwiftBridgedArray.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ def do_test(self):
6464

6565
self.expect(
6666
"frame variable -d run -- swarr",
67-
substrs=['123456', '234567', '345678', '1.25'])
67+
substrs=['Int(123456)', 'Int32(234567)', 'UInt16(45678)', 'Double(1.250000)', 'Float(2.500000)'])
6868
self.expect(
6969
"expression -d run -- swarr",
70-
substrs=['123456', '234567', '345678', '1.25'])
70+
substrs=['Int(123456)', 'Int32(234567)', 'UInt16(45678)', 'Double(1.250000)', 'Float(2.500000)'])
7171

7272
if __name__ == '__main__':
7373
import atexit

Diff for: packages/Python/lldbsuite/test/lang/swift/variables/bridged_array/main.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import Foundation
1313

1414
func main() {
15-
var nsarr: NSArray = NSArray(array: [123456,234567,345678,1.25,false])
15+
var nsarr: NSArray = NSArray(array: [Int(123456),Int32(234567),UInt16(45678),Double(1.25),Float(2.5)])
1616
var swarr = unsafeBitCast(unsafeBitCast(nsarr, to: Int.self), to: NSArray.self) as! [AnyObject]
1717
print("break here")
1818
}

Diff for: source/Plugins/Language/Swift/SwiftFormatters.cpp

+148-47
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,126 @@ bool lldb_private::formatters::swift::ObjC_Selector_SummaryProvider(
598598
StringPrinter::StringElementType::ASCII>(read_options);
599599
}
600600

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+
601721
bool lldb_private::formatters::swift::TypePreservingNSNumber_SummaryProvider(
602722
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
603723
lldb::addr_t ptr_value(valobj.GetValueAsUnsigned(LLDB_INVALID_ADDRESS));
@@ -609,16 +729,16 @@ bool lldb_private::formatters::swift::TypePreservingNSNumber_SummaryProvider(
609729
return false;
610730

611731
uint32_t ptr_size = process_sp->GetAddressByteSize();
612-
const uint32_t size_of_tag = 4;
732+
const uint32_t size_of_tag = 1;
613733
const uint32_t size_of_payload = 8;
614734

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;
617737

618738
Error read_error;
619739
uint64_t tag = process_sp->ReadUnsignedIntegerFromMemory(
620740
addr_of_tag, size_of_tag, 0, read_error);
621-
if (read_error.Fail() || tag == 0 || tag > 6)
741+
if (read_error.Fail())
622742
return false;
623743

624744
DataBufferSP buffer_sp(new DataBufferHeap(size_of_payload, 0));
@@ -627,53 +747,34 @@ bool lldb_private::formatters::swift::TypePreservingNSNumber_SummaryProvider(
627747
if (read_error.Fail())
628748
return false;
629749

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+
630757
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);
674772
default:
675773
break;
676774
}
677775

776+
#undef PROCESS_DEPENDENT_TAG
777+
#undef PROCESS_INDEPENDENT_TAG
778+
678779
return false;
679780
}

0 commit comments

Comments
 (0)