Skip to content

Commit 90f4b4f

Browse files
committed
[LLDB] Replace more instances of the DEBUG_LOG macro with setError
This allows LLDB to query the last error and produce more helpful diagnostics. This is NFC for the runtime.
1 parent 45547be commit 90f4b4f

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

include/swift/RemoteInspection/TypeLowering.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,9 @@ class TypeConverter {
405405
void enableErrorCache() {
406406
ErrorCache = std::make_unique<llvm::DenseMap<KeyT, TCError>>();
407407
}
408-
void setError(const char *msg, const TypeRef *TR) { LastError = {msg, TR}; }
408+
409+
/// Set the LastError variable.
410+
void setError(const char *msg, const TypeRef *TR = nullptr);
409411

410412
/// Retreive the error and reset it.
411413
std::string takeLastError();

stdlib/public/RemoteInspection/TypeLowering.cpp

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,6 @@ class ExistentialTypeInfoBuilder {
11621162

11631163
void markInvalid(const char *msg, const TypeRef *TR = nullptr) {
11641164
Invalid = true;
1165-
DEBUG_LOG(fprintf(stderr, "%s\n", msg); if (TR) TR->dump());
11661165
TC.setError(msg, TR);
11671166
}
11681167

@@ -1347,7 +1346,7 @@ class ExistentialTypeInfoBuilder {
13471346

13481347
if (ObjC) {
13491348
if (WitnessTableCount > 0) {
1350-
DEBUG_LOG(fprintf(stderr, "@objc existential with witness tables\n"));
1349+
TC.setError("@objc existential with witness tables");
13511350
return nullptr;
13521351
}
13531352

@@ -1384,7 +1383,7 @@ class ExistentialTypeInfoBuilder {
13841383
case ExistentialTypeRepresentation::Opaque: {
13851384
auto *TI = TC.getTypeInfo(TC.getRawPointerTypeRef(), ExternalTypeInfo);
13861385
if (TI == nullptr) {
1387-
DEBUG_LOG(fprintf(stderr, "No TypeInfo for RawPointer\n"));
1386+
TC.setError("no TypeInfo for RawPointer");
13881387
return nullptr;
13891388
}
13901389

@@ -1541,7 +1540,7 @@ const ReferenceTypeInfo *TypeConverter::getReferenceTypeInfo(
15411540

15421541
auto BuiltinTI = Builder.getBuiltinTypeDescriptor(TR);
15431542
if (BuiltinTI == nullptr) {
1544-
DEBUG_LOG(fprintf(stderr, "No TypeInfo for reference type: "); TR->dump());
1543+
setError("no TypeInfo for reference type", TR);
15451544
return nullptr;
15461545
}
15471546

@@ -1573,6 +1572,11 @@ const ReferenceTypeInfo *TypeConverter::getReferenceTypeInfo(
15731572
return TI;
15741573
}
15751574

1575+
void TypeConverter::setError(const char *msg, const TypeRef *TR) {
1576+
DEBUG_LOG(fprintf(stderr, "%s\n", msg); if (TR) TR->dump());
1577+
LastError = {msg, TR};
1578+
}
1579+
15761580
std::string TypeConverter::takeLastError() {
15771581
if (!LastError.first)
15781582
return {};
@@ -1595,7 +1599,7 @@ TypeConverter::getThinFunctionTypeInfo() {
15951599
auto descriptor =
15961600
getBuilder().getBuiltinTypeDescriptor(getThinFunctionTypeRef());
15971601
if (descriptor == nullptr) {
1598-
DEBUG_LOG(fprintf(stderr, "No TypeInfo for function type\n"));
1602+
setError("no TypeInfo for function type");
15991603
return nullptr;
16001604
}
16011605

@@ -1630,7 +1634,7 @@ TypeConverter::getAnyMetatypeTypeInfo() {
16301634
auto descriptor =
16311635
getBuilder().getBuiltinTypeDescriptor(getAnyMetatypeTypeRef());
16321636
if (descriptor == nullptr) {
1633-
DEBUG_LOG(fprintf(stderr, "No TypeInfo for metatype type\n"));
1637+
setError("no TypeInfo for metatype type");
16341638
return nullptr;
16351639
}
16361640

@@ -1649,7 +1653,7 @@ const TypeInfo *TypeConverter::getDefaultActorStorageTypeInfo() {
16491653
auto descriptor =
16501654
getBuilder().getBuiltinTypeDescriptor(getRawPointerTypeRef());
16511655
if (descriptor == nullptr) {
1652-
DEBUG_LOG(fprintf(stderr, "No TypeInfo for default actor storage type\n"));
1656+
setError("no TypeInfo for default actor storage type");
16531657
return nullptr;
16541658
}
16551659

@@ -2030,7 +2034,6 @@ class EnumTypeInfoBuilder {
20302034

20312035
void markInvalid(const char *msg, const TypeRef *TR = nullptr) {
20322036
Invalid = true;
2033-
DEBUG_LOG(fprintf(stderr, "%s\n", msg); if (TR) TR->dump());
20342037
TC.setError(msg, TR);
20352038
}
20362039

@@ -2375,7 +2378,7 @@ class LowerType
23752378
/// metadata.
23762379
auto descriptor = TC.getBuilder().getBuiltinTypeDescriptor(B);
23772380
if (descriptor == nullptr) {
2378-
DEBUG_LOG(fprintf(stderr, "No TypeInfo for builtin type: "); B->dump());
2381+
TC.setError("no TypeInfo for builtin type", B);
23792382
return nullptr;
23802383
}
23812384
return TC.makeTypeInfo<BuiltinTypeInfo>(TC.getBuilder(), *descriptor.get());
@@ -2424,7 +2427,7 @@ class LowerType
24242427

24252428

24262429
// If the external provider also fails we're out of luck.
2427-
DEBUG_LOG(fprintf(stderr, "No TypeInfo for nominal type: "); TR->dump());
2430+
TC.setError("no TypeInfo for nominal type", TR);
24282431
return nullptr;
24292432
}
24302433
}
@@ -2459,7 +2462,7 @@ class LowerType
24592462
case FieldDescriptorKind::ObjCProtocol:
24602463
case FieldDescriptorKind::ClassProtocol:
24612464
case FieldDescriptorKind::Protocol:
2462-
DEBUG_LOG(fprintf(stderr, "Invalid field descriptor: "); TR->dump());
2465+
TC.setError("Invalid field descriptor", TR);
24632466
return nullptr;
24642467
}
24652468

@@ -2483,12 +2486,12 @@ class LowerType
24832486
}
24842487

24852488
const TypeInfo *visitPackTypeRef(const PackTypeRef *P) {
2486-
DEBUG_LOG(fprintf(stderr, "Cannot have pack type here: "); P->dump());
2489+
TC.setError("cannot have pack type here", P);
24872490
return nullptr;
24882491
}
24892492

24902493
const TypeInfo *visitPackExpansionTypeRef(const PackExpansionTypeRef *PE) {
2491-
DEBUG_LOG(fprintf(stderr, "Cannot have pack expansion type here: "); PE->dump());
2494+
TC.setError("cannot have pack expansion type here", PE);
24922495
return nullptr;
24932496
}
24942497

@@ -2523,7 +2526,7 @@ class LowerType
25232526
const TypeInfo *visitMetatypeTypeRef(const MetatypeTypeRef *M) {
25242527
switch (HasSingletonMetatype().visit(M)) {
25252528
case MetatypeRepresentation::Unknown:
2526-
DEBUG_LOG(fprintf(stderr, "Unknown metatype representation: "); M->dump());
2529+
TC.setError("unknown metatype representation", M);
25272530
return nullptr;
25282531
case MetatypeRepresentation::Thin:
25292532
return TC.getEmptyTypeInfo();
@@ -2542,7 +2545,7 @@ class LowerType
25422545
if (auto *PC = dyn_cast<ProtocolCompositionTypeRef>(TR)) {
25432546
builder.addProtocolComposition(PC);
25442547
} else {
2545-
DEBUG_LOG(fprintf(stderr, "Invalid existential metatype: "); EM->dump());
2548+
TC.setError("invalid existential metatype", EM);
25462549
return nullptr;
25472550
}
25482551

@@ -2558,13 +2561,13 @@ class LowerType
25582561

25592562
const TypeInfo *
25602563
visitGenericTypeParameterTypeRef(const GenericTypeParameterTypeRef *GTP) {
2561-
DEBUG_LOG(fprintf(stderr, "Unresolved generic TypeRef: "); GTP->dump());
2564+
TC.setError("unresolved generic TypeRef", GTP);
25622565
return nullptr;
25632566
}
25642567

25652568
const TypeInfo *
25662569
visitDependentMemberTypeRef(const DependentMemberTypeRef *DM) {
2567-
DEBUG_LOG(fprintf(stderr, "Unresolved generic TypeRef: "); DM->dump());
2570+
TC.setError("unresolved generic TypeRef", DM);
25682571
return nullptr;
25692572
}
25702573

@@ -2590,7 +2593,7 @@ class LowerType
25902593
rebuildStorageTypeInfo(const TypeInfo *TI, ReferenceKind Kind) {
25912594
// If we can't lower the original storage type, give up.
25922595
if (TI == nullptr) {
2593-
DEBUG_LOG(fprintf(stderr, "Invalid reference type"));
2596+
TC.setError("invalid reference type");
25942597
return nullptr;
25952598
}
25962599

@@ -2636,7 +2639,7 @@ class LowerType
26362639
}
26372640

26382641
// Anything else -- give up
2639-
DEBUG_LOG(fprintf(stderr, "Invalid reference type"));
2642+
TC.setError("invalid reference type");
26402643
return nullptr;
26412644
}
26422645

@@ -2664,19 +2667,19 @@ class LowerType
26642667
}
26652668

26662669
const TypeInfo *visitOpaqueTypeRef(const OpaqueTypeRef *O) {
2667-
DEBUG_LOG(fprintf(stderr, "Can't lower opaque TypeRef"));
2670+
TC.setError("can't lower opaque TypeRef", O);
26682671
return nullptr;
26692672
}
26702673

26712674
const TypeInfo *visitOpaqueArchetypeTypeRef(const OpaqueArchetypeTypeRef *O) {
26722675
// TODO: Provide a hook for the client to try to resolve the opaque archetype
26732676
// with additional information?
2674-
DEBUG_LOG(fprintf(stderr, "Can't lower unresolved opaque archetype TypeRef"));
2677+
TC.setError("can't lower unresolved opaque archetype TypeRef", O);
26752678
return nullptr;
26762679
}
26772680

26782681
const TypeInfo *visitIntegerTypeRef(const IntegerTypeRef *I) {
2679-
DEBUG_LOG(fprintf(stderr, "Can't lower integer TypeRef"));
2682+
TC.setError("can't lower integer TypeRef", I);
26802683
return nullptr;
26812684
}
26822685

@@ -2692,7 +2695,7 @@ const TypeInfo *
26922695
TypeConverter::getTypeInfo(const TypeRef *TR,
26932696
remote::TypeInfoProvider *ExternalTypeInfo) {
26942697
if (!TR) {
2695-
DEBUG_LOG(fprintf(stderr, "null TypeRef"));
2698+
setError("null TypeRef");
26962699
return nullptr;
26972700
}
26982701

@@ -2709,7 +2712,7 @@ TypeConverter::getTypeInfo(const TypeRef *TR,
27092712
// Detect invalid recursive value types (IRGen should not emit
27102713
// them in the first place, but there might be bugs)
27112714
if (!RecursionCheck.insert(TR).second) {
2712-
DEBUG_LOG(fprintf(stderr, "TypeRef recursion detected"));
2715+
setError("TypeRef recursion detected");
27132716
return nullptr;
27142717
}
27152718

@@ -2732,7 +2735,7 @@ const RecordTypeInfo *TypeConverter::getClassInstanceTypeInfo(
27322735
remote::TypeInfoProvider *ExternalTypeInfo) {
27332736
auto FD = getBuilder().getFieldDescriptor(TR);
27342737
if (FD == nullptr) {
2735-
DEBUG_LOG(fprintf(stderr, "No field descriptor: "); TR->dump());
2738+
setError("no field descriptor", TR);
27362739
return nullptr;
27372740
}
27382741

@@ -2744,8 +2747,11 @@ const RecordTypeInfo *TypeConverter::getClassInstanceTypeInfo(
27442747
RecordTypeInfoBuilder builder(*this, RecordKind::ClassInstance);
27452748

27462749
std::vector<FieldTypeInfo> Fields;
2747-
if (!getBuilder().getFieldTypeRefs(TR, *FD.get(), ExternalTypeInfo, Fields))
2750+
if (!getBuilder().getFieldTypeRefs(TR, *FD.get(), ExternalTypeInfo,
2751+
Fields)) {
2752+
setError("cannot get fields", TR);
27482753
return nullptr;
2754+
}
27492755

27502756
// Start layout from the given instance start offset. This should
27512757
// be the superclass instance size.
@@ -2765,7 +2771,7 @@ const RecordTypeInfo *TypeConverter::getClassInstanceTypeInfo(
27652771
case FieldDescriptorKind::ClassProtocol:
27662772
case FieldDescriptorKind::Protocol:
27672773
// Invalid field descriptor.
2768-
DEBUG_LOG(fprintf(stderr, "Invalid field descriptor: "); TR->dump());
2774+
setError("invalid field descriptor", TR);
27692775
return nullptr;
27702776
}
27712777

0 commit comments

Comments
 (0)