@@ -1241,6 +1241,86 @@ class TypeRefBuilder {
1241
1241
return llvm::None;
1242
1242
}
1243
1243
1244
+ llvm::Optional<std::string>
1245
+ readFullyQualifiedTypeName (uintptr_t typeDescriptorTarget) {
1246
+ std::string typeName;
1247
+ auto contextTypeDescriptorBytes = OpaqueByteReader (
1248
+ remote::RemoteAddress (typeDescriptorTarget),
1249
+ sizeof (ExternalContextDescriptor<ObjCInteropKind, PointerSize>));
1250
+ if (!contextTypeDescriptorBytes.get ()) {
1251
+ Error = " Failed to read context descriptor." ;
1252
+ return llvm::None;
1253
+ }
1254
+ const ExternalContextDescriptor<ObjCInteropKind, PointerSize>
1255
+ *contextDescriptor =
1256
+ (const ExternalContextDescriptor<ObjCInteropKind, PointerSize> *)
1257
+ contextTypeDescriptorBytes.get ();
1258
+
1259
+ auto typeDescriptor =
1260
+ dyn_cast<ExternalTypeContextDescriptor<ObjCInteropKind, PointerSize>>(
1261
+ contextDescriptor);
1262
+ if (!typeDescriptor) {
1263
+ Error = " Unexpected type of context descriptor." ;
1264
+ return llvm::None;
1265
+ }
1266
+
1267
+ auto optionalTypeName = readTypeNameFromTypeDescriptor (
1268
+ typeDescriptor, typeDescriptorTarget);
1269
+ if (!optionalTypeName.hasValue ())
1270
+ return llvm::None;
1271
+ else
1272
+ typeName = optionalTypeName.getValue ();
1273
+
1274
+ std::vector<ContextNameInfo> contextNameChain;
1275
+ contextNameChain.push_back (
1276
+ ContextNameInfo{typeName, typeDescriptorTarget, false });
1277
+ getParentContextChain (typeDescriptorTarget, contextDescriptor,
1278
+ contextNameChain);
1279
+ return constructFullyQualifiedNameFromContextChain (contextNameChain);
1280
+ }
1281
+
1282
+ llvm::Optional<std::string>
1283
+ readFullyQualifiedProtocolName (
1284
+ uintptr_t protocolDescriptorTarget) {
1285
+ llvm::Optional<std::string> protocolName;
1286
+ // Set low bit indicates that this is an indirect
1287
+ // reference
1288
+ if (protocolDescriptorTarget & 0x1 ) {
1289
+ auto adjustedProtocolDescriptorTarget = protocolDescriptorTarget & ~0x1 ;
1290
+ if (auto symbol = OpaquePointerReader (
1291
+ remote::RemoteAddress (adjustedProtocolDescriptorTarget),
1292
+ PointerSize)) {
1293
+ if (!symbol->getSymbol ().empty ()) {
1294
+ Demangle::Context Ctx;
1295
+ auto demangledRoot =
1296
+ Ctx.demangleSymbolAsNode (symbol->getSymbol ().str ());
1297
+ assert (demangledRoot->getKind () == Node::Kind::Global);
1298
+ assert (demangledRoot->getChild (0 )->getKind () ==
1299
+ Node::Kind::ProtocolDescriptor);
1300
+ protocolName =
1301
+ nodeToString (demangledRoot->getChild (0 )->getChild (0 ));
1302
+ } else {
1303
+ // This is an absolute address of a protocol descriptor
1304
+ auto protocolDescriptorAddress = (uintptr_t )symbol->getOffset ();
1305
+ protocolName =
1306
+ readFullyQualifiedProtocolNameFromProtocolDescriptor (
1307
+ protocolDescriptorAddress);
1308
+ }
1309
+ } else {
1310
+ Error = " Error reading external protocol address." ;
1311
+ return llvm::None;
1312
+ }
1313
+ } else {
1314
+ // If this is a direct reference, get symbol name from the protocol
1315
+ // descriptor.
1316
+ protocolName =
1317
+ readFullyQualifiedProtocolNameFromProtocolDescriptor (
1318
+ protocolDescriptorTarget);
1319
+ }
1320
+ return protocolName;
1321
+ }
1322
+
1323
+ private:
1244
1324
llvm::Optional<std::string>
1245
1325
readFullyQualifiedProtocolNameFromProtocolDescriptor (
1246
1326
uintptr_t protocolDescriptorAddress) {
@@ -1510,7 +1590,7 @@ class TypeRefBuilder {
1510
1590
OpaqueByteReader, OpaqueStringReader, OpaquePointerReader,
1511
1591
OpaqueDynamicSymbolResolver);
1512
1592
auto conformanceRequirementProtocolName =
1513
- nameReader.readFullyQualifiedProtocolNameFromProtocolDescriptor (
1593
+ nameReader.readFullyQualifiedProtocolName (
1514
1594
protocolDescriptorAddress);
1515
1595
result.push_back (*conformanceRequirementProtocolName);
1516
1596
}
@@ -1608,41 +1688,12 @@ class TypeRefBuilder {
1608
1688
}
1609
1689
}
1610
1690
1611
- auto contextTypeDescriptorBytes = OpaqueByteReader (
1612
- remote::RemoteAddress (contextTypeDescriptorAddress),
1613
- sizeof (ExternalContextDescriptor<ObjCInteropKind, PointerSize>));
1614
- if (!contextTypeDescriptorBytes.get ()) {
1615
- Error = " Failed to read context descriptor." ;
1616
- return llvm::None;
1617
- }
1618
- const ExternalContextDescriptor<ObjCInteropKind, PointerSize>
1619
- *contextDescriptor =
1620
- (const ExternalContextDescriptor<ObjCInteropKind, PointerSize> *)
1621
- contextTypeDescriptorBytes.get ();
1622
-
1623
- auto typeDescriptor =
1624
- dyn_cast<ExternalTypeContextDescriptor<ObjCInteropKind, PointerSize>>(
1625
- contextDescriptor);
1626
- if (!typeDescriptor) {
1627
- Error = " Unexpected type of context descriptor." ;
1628
- return llvm::None;
1629
- }
1630
-
1631
- auto optionalTypeName = NameReader.readTypeNameFromTypeDescriptor (
1632
- typeDescriptor, contextTypeDescriptorAddress);
1633
- if (!optionalTypeName.hasValue ())
1691
+ auto fullyQualifiedName =
1692
+ NameReader.readFullyQualifiedTypeName (contextTypeDescriptorAddress);
1693
+ if (!fullyQualifiedName.hasValue ())
1634
1694
return llvm::None;
1635
1695
else
1636
- typeName = optionalTypeName.getValue ();
1637
-
1638
- std::vector<ContextNameInfo> contextNameChain;
1639
- contextNameChain.push_back (
1640
- ContextNameInfo{typeName, contextTypeDescriptorAddress, false });
1641
- NameReader.getParentContextChain (contextTypeDescriptorAddress, contextDescriptor,
1642
- contextNameChain);
1643
- std::string fullyQualifiedName =
1644
- NameReader.constructFullyQualifiedNameFromContextChain (contextNameChain);
1645
- return std::make_pair (mangledTypeName, fullyQualifiedName);
1696
+ return std::make_pair (mangledTypeName, *fullyQualifiedName);
1646
1697
}
1647
1698
1648
1699
// / Extract protocol name from a Conformance Descriptor
@@ -1670,67 +1721,8 @@ class TypeRefBuilder {
1670
1721
(const char *)protocolDescriptorFieldAddress,
1671
1722
(int32_t )*protocolDescriptorOffset);
1672
1723
1673
- auto constructFullyQualifiedProtocolName =
1674
- [&](uintptr_t protocolDescriptorAddress)
1675
- -> llvm::Optional<std::string> {
1676
- auto protocolName =
1677
- NameReader.readProtocolNameFromProtocolDescriptor (protocolDescriptorAddress);
1678
-
1679
- // Read the protocol conformance descriptor itself
1680
- auto protocolContextDescriptorBytes = OpaqueByteReader (
1681
- remote::RemoteAddress (protocolDescriptorAddress),
1682
- sizeof (ExternalContextDescriptor<ObjCInteropKind, PointerSize>));
1683
- if (!protocolContextDescriptorBytes.get ()) {
1684
- Error = " Failed to read context (protocol) descriptor." ;
1685
- return llvm::None;
1686
- }
1687
- const ExternalContextDescriptor<ObjCInteropKind,
1688
- PointerSize> *protocolDescriptor =
1689
- (const ExternalContextDescriptor<ObjCInteropKind, PointerSize> *)
1690
- protocolContextDescriptorBytes.get ();
1691
-
1692
- std::vector<ContextNameInfo> contextNameChain;
1693
- contextNameChain.push_back (ContextNameInfo{
1694
- protocolName.getValue (), protocolDescriptorAddress, false });
1695
- NameReader.getParentContextChain (protocolDescriptorAddress, protocolDescriptor,
1696
- contextNameChain);
1697
- return NameReader.constructFullyQualifiedNameFromContextChain (contextNameChain);
1698
- };
1699
-
1700
- // Set low bit indicates that this is an indirect
1701
- // reference
1702
- if (protocolDescriptorTarget & 0x1 ) {
1703
- auto adjustedProtocolDescriptorTarget = protocolDescriptorTarget & ~0x1 ;
1704
- if (auto symbol = OpaquePointerReader (
1705
- remote::RemoteAddress (adjustedProtocolDescriptorTarget),
1706
- PointerSize)) {
1707
- if (!symbol->getSymbol ().empty ()) {
1708
- Demangle::Context Ctx;
1709
- auto demangledRoot =
1710
- Ctx.demangleSymbolAsNode (symbol->getSymbol ().str ());
1711
- assert (demangledRoot->getKind () == Node::Kind::Global);
1712
- assert (demangledRoot->getChild (0 )->getKind () ==
1713
- Node::Kind::ProtocolDescriptor);
1714
- protocolName =
1715
- nodeToString (demangledRoot->getChild (0 )->getChild (0 ));
1716
- } else {
1717
- // This is an absolute address of a protocol descriptor
1718
- auto protocolDescriptorAddress = (uintptr_t )symbol->getOffset ();
1719
- protocolName =
1720
- constructFullyQualifiedProtocolName (protocolDescriptorAddress);
1721
- }
1722
- } else {
1723
- Error = " Error reading external protocol address." ;
1724
- return llvm::None;
1725
- }
1726
- } else {
1727
- // If this is a direct reference, get symbol name from the protocol
1728
- // descriptor.
1729
- protocolName =
1730
- constructFullyQualifiedProtocolName (protocolDescriptorTarget);
1731
- }
1732
-
1733
- return protocolName;
1724
+ return NameReader.readFullyQualifiedProtocolName (
1725
+ protocolDescriptorTarget);
1734
1726
}
1735
1727
1736
1728
// / Given the address of a conformance descriptor, attempt to read it.
0 commit comments