@@ -859,6 +859,43 @@ class TypeRefBuilder {
859
859
return typeName;
860
860
}
861
861
862
+ std::string readProtocolNameFromProtocolDescriptor (const char *protocolDescriptorAddress) {
863
+ std::string protocolName;
864
+ auto protocolDescriptorBytes =
865
+ OpaqueByteReader (remote::RemoteAddress (protocolDescriptorAddress),
866
+ sizeof (ExternalProtocolDescriptor<PointerSize>));
867
+ if (!protocolDescriptorBytes.get ()) {
868
+ Error = " Error reading protocol descriptor." ;
869
+ return protocolName;
870
+ }
871
+ const ExternalProtocolDescriptor<PointerSize> *protocolDescriptor =
872
+ (const ExternalProtocolDescriptor<PointerSize> *)
873
+ protocolDescriptorBytes.get ();
874
+
875
+ // Compute the address of the protocol descriptor's name field and read
876
+ // the offset
877
+ auto protocolNameOffsetAddress = detail::applyRelativeOffset (
878
+ (const char *)protocolDescriptorAddress,
879
+ (int32_t )protocolDescriptor->getNameOffset ());
880
+ auto protocolNameOfsetBytes = OpaqueByteReader (
881
+ remote::RemoteAddress (protocolNameOffsetAddress), sizeof (uint32_t ));
882
+ if (!protocolNameOfsetBytes.get ()) {
883
+ Error = " Failed to read type name offset in a protocol descriptor." ;
884
+ return protocolName;
885
+ }
886
+ auto protocolNameOffset =
887
+ (const uint32_t *)protocolNameOfsetBytes.get ();
888
+
889
+ // Using the offset above, compute the address of the name field itsel
890
+ // and read it.
891
+ auto protocolNameAddress =
892
+ detail::applyRelativeOffset ((const char *)protocolNameOffsetAddress,
893
+ (int32_t )*protocolNameOffset);
894
+ OpaqueStringReader (remote::RemoteAddress (protocolNameAddress),
895
+ protocolName);
896
+ return protocolName;
897
+ }
898
+
862
899
std::string getConformanceProtocol (
863
900
const char *conformanceDescriptorAddress,
864
901
const ExternalProtocolConformanceDescriptor<PointerSize>
@@ -888,52 +925,26 @@ class TypeRefBuilder {
888
925
(const void *)((uint64_t )protocolDescriptorTarget & ~(0x1 ));
889
926
if (auto symbol = OpaquePointerReader (
890
927
remote::RemoteAddress (adjustedProtocolDescriptorTarget), 8 )) {
891
-
892
- Demangle::Context Ctx;
893
- auto demangledRoot =
894
- Ctx.demangleSymbolAsNode (symbol->getSymbol ().str ());
895
- assert (demangledRoot->getKind () == Node::Kind::Global);
896
- assert (demangledRoot->getChild (0 )->getKind () ==
897
- Node::Kind::ProtocolDescriptor);
898
- protocolName = nodeToString (demangledRoot->getChild (0 )->getChild (0 ));
928
+ if (!symbol->getSymbol ().empty ()) {
929
+ Demangle::Context Ctx;
930
+ auto demangledRoot =
931
+ Ctx.demangleSymbolAsNode (symbol->getSymbol ().str ());
932
+ assert (demangledRoot->getKind () == Node::Kind::Global);
933
+ assert (demangledRoot->getChild (0 )->getKind () ==
934
+ Node::Kind::ProtocolDescriptor);
935
+ protocolName = nodeToString (demangledRoot->getChild (0 )->getChild (0 ));
936
+ } else {
937
+ // This is an absolute address offset.
938
+ auto protocolDescriptorAddress = symbol->getOffset ();
939
+ protocolName = readProtocolNameFromProtocolDescriptor ((const char *)protocolDescriptorAddress);
940
+ }
899
941
} else {
900
942
Error = " Error reading external protocol address." ;
901
943
return protocolName;
902
944
}
903
945
// If direct, read the protocol descriptor and get symbol name
904
946
} else {
905
- auto protocolDescriptorBytes =
906
- OpaqueByteReader (remote::RemoteAddress (protocolDescriptorTarget),
907
- sizeof (ExternalProtocolDescriptor<PointerSize>));
908
- if (!protocolDescriptorBytes.get ()) {
909
- Error = " Error reading protocol descriptor." ;
910
- return protocolName;
911
- }
912
- const ExternalProtocolDescriptor<PointerSize> *protocolDescriptor =
913
- (const ExternalProtocolDescriptor<PointerSize> *)
914
- protocolDescriptorBytes.get ();
915
-
916
- // Compute the address of the protocol descriptor's name field and read
917
- // the offset
918
- auto protocolNameOffsetAddress = detail::applyRelativeOffset (
919
- (const char *)protocolDescriptorTarget,
920
- (int32_t )protocolDescriptor->getNameOffset ());
921
- auto protocolNameOfsetBytes = OpaqueByteReader (
922
- remote::RemoteAddress (protocolNameOffsetAddress), sizeof (uint32_t ));
923
- if (!protocolNameOfsetBytes.get ()) {
924
- Error = " Failed to read type name offset in a protocol descriptor." ;
925
- return protocolName;
926
- }
927
- auto protocolNameOffset =
928
- (const uint32_t *)protocolNameOfsetBytes.get ();
929
-
930
- // Using the offset above, compute the address of the name field itsel
931
- // and read it.
932
- auto protocolNameAddress =
933
- detail::applyRelativeOffset ((const char *)protocolNameOffsetAddress,
934
- (int32_t )*protocolNameOffset);
935
- OpaqueStringReader (remote::RemoteAddress (protocolNameAddress),
936
- protocolName);
947
+ protocolName = readProtocolNameFromProtocolDescriptor ((const char *)protocolDescriptorTarget);
937
948
}
938
949
939
950
return protocolName;
0 commit comments