@@ -802,42 +802,29 @@ class ReflectionContext
802
802
}
803
803
}
804
804
805
- void dumpConformanceNode (const struct ConformanceNode *Node) {
806
- Demangle::Demangler Dem;
807
-
808
- std::string TypeName = " <unknown>" ;
809
- if (auto TR = readTypeFromMetadata (Node->Type )) {
810
- auto Demangling = TR->getDemangling (Dem);
811
- TypeName = nodeToString (Demangling);
812
- }
813
-
814
- auto ProtocolDemangled = readDemanglingForContextDescriptor (Node->Proto , Dem);
815
- auto ProtocolName = nodeToString (ProtocolDemangled);
816
-
817
- printf (" Conformance: %s: %s\n " , TypeName.c_str (), ProtocolName.c_str ());
818
- }
819
-
820
- void dumpConformanceTree (StoredPointer NodePtr) {
805
+ void iterateConformanceTree (StoredPointer NodePtr,
806
+ std::function<void (StoredPointer Type, StoredPointer Proto)> Call) {
821
807
if (!NodePtr)
822
808
return ;
823
809
auto NodeBytes = getReader ().readBytes (RemoteAddress (NodePtr), sizeof (Node));
824
810
auto NodeData = reinterpret_cast <const ConformanceNode *>(NodeBytes.get ());
825
811
if (!NodeData)
826
812
return ;
827
- dumpConformanceNode (NodeData);
828
- dumpConformanceTree (NodeData->Left );
829
- dumpConformanceTree (NodeData->Right );
813
+ Call (NodeData-> Type , NodeData-> Proto );
814
+ iterateConformanceTree (NodeData->Left , Call );
815
+ iterateConformanceTree (NodeData->Right , Call );
830
816
}
831
817
832
- void dumpConformances () {
818
+ bool iterateConformances (
819
+ std::function<void (StoredPointer Type, StoredPointer Proto)> Call) {
833
820
std::string ConformancesName = " __ZL12Conformances" ;
834
821
auto ConformancesAddr = getReader ().getSymbolAddress (ConformancesName);
835
- printf (" %#llx\n " , ConformancesAddr.getAddressData ());
836
822
if (!ConformancesAddr)
837
- return ;
823
+ return false ;
838
824
839
825
auto Root = getReader ().readPointer (ConformancesAddr, sizeof (StoredPointer));
840
- dumpConformanceTree (Root->getResolvedAddress ().getAddressData ());
826
+ iterateConformanceTree (Root->getResolvedAddress ().getAddressData (), Call);
827
+ return true ;
841
828
}
842
829
843
830
void iterateModules (Demangle::NodePointer Ptr, std::function<void (llvm::StringRef)> Call) {
@@ -847,53 +834,41 @@ class ReflectionContext
847
834
iterateModules (Child, Call);
848
835
}
849
836
850
- void dumpGenericMetadataCacheEntry (const char *Ptr) {
851
- struct GenericMetadataCacheEntry {
852
- StoredPointer Left, Right;
853
- StoredPointer LockedStorage;
854
- uint8_t LockedStorageKind;
855
- uint8_t TrackingInfo;
856
- uint16_t NumKeyParameters;
857
- uint16_t NumWitnessTables;
858
- uint32_t Hash;
859
- StoredPointer Value;
860
- };
861
-
862
- auto EntryPtr = (const GenericMetadataCacheEntry *)Ptr;
863
- printf (" Left: %#llx\n " , EntryPtr->Left );
864
- printf (" Right: %#llx\n " , EntryPtr->Right );
865
- printf (" LockedStorage: %#llx\n " , EntryPtr->LockedStorage );
866
- printf (" LockedStorageKind: %u\n " , EntryPtr->LockedStorageKind );
867
- printf (" TrackingInfo: %u\n " , EntryPtr->TrackingInfo );
868
- printf (" NumKeyParameters: %u\n " , EntryPtr->NumKeyParameters );
869
- printf (" NumWitnessTables: %u\n " , EntryPtr->NumWitnessTables );
870
- printf (" Hash: %#x\n " , EntryPtr->Hash );
871
- printf (" Value: %#llx\n " , EntryPtr->Value );
872
-
873
- if (EntryPtr->Value ) {
874
- if (auto Metadata = readMetadata (EntryPtr->Value )) {
875
- if (auto TR = readTypeFromMetadata (Metadata.getAddressData ())) {
876
- Demangle::Demangler Dem;
877
- auto Demangling = TR->getDemangling (Dem);
878
- auto Name = nodeToString (Demangling);
879
- printf (" Name: %s\n " , Name.c_str ());
880
-
881
- printf (" Modules:" );
882
- iterateModules (Demangling, [](llvm::StringRef Str){
883
- printf (" %s" , Str.str ().c_str ());
884
- });
885
- printf (" \n " );
886
- }
887
- }
837
+ struct MetadataAllocation {
838
+ uint16_t Tag;
839
+ StoredPointer Ptr;
840
+ unsigned Size;
841
+ };
842
+
843
+ StoredPointer allocationMetadataPointer (MetadataAllocation Allocation) {
844
+ if (Allocation.Tag == GenericMetadataCacheTag) {
845
+ struct GenericMetadataCacheEntry {
846
+ StoredPointer Left, Right;
847
+ StoredPointer LockedStorage;
848
+ uint8_t LockedStorageKind;
849
+ uint8_t TrackingInfo;
850
+ uint16_t NumKeyParameters;
851
+ uint16_t NumWitnessTables;
852
+ uint32_t Hash;
853
+ StoredPointer Value;
854
+ };
855
+ auto AllocationBytes =
856
+ getReader ().readBytes (RemoteAddress (Allocation.Ptr ),
857
+ Allocation.Size );
858
+ auto Entry = reinterpret_cast <const GenericMetadataCacheEntry *>(
859
+ AllocationBytes.get ());
860
+ if (!Entry)
861
+ return 0 ;
862
+ return Entry->Value ;
888
863
}
864
+ return 0 ;
889
865
}
890
866
891
- void dumpMetadataAllocations ( ) {
867
+ bool iterateMetadataAllocations (std::function< void (MetadataAllocation)> Call ) {
892
868
std::string AllocationPoolName = " __ZL14AllocationPool" ;
893
869
auto AllocationPoolAddr = getReader ().getSymbolAddress (AllocationPoolName);
894
- printf (" %#llx\n " , AllocationPoolAddr.getAddressData ());
895
-
896
- printf (" Initial pool: %#llx\n " , getReader ().getSymbolAddress (" __ZL21InitialAllocationPool" ).getAddressData ());
870
+ if (!AllocationPoolAddr)
871
+ return false ;
897
872
898
873
struct PoolRange {
899
874
StoredPointer Begin;
@@ -912,8 +887,8 @@ class ReflectionContext
912
887
.readBytes (RemoteAddress (AllocationPoolAddr), sizeof (PoolRange));
913
888
auto Pool = reinterpret_cast <const PoolRange *>(PoolBytes.get ());
914
889
if (!Pool)
915
- return ;
916
-
890
+ return false ;
891
+
917
892
auto TrailerPtr = Pool->Begin + Pool->Remaining ;
918
893
while (TrailerPtr) {
919
894
auto TrailerBytes = getReader ()
@@ -922,38 +897,31 @@ class ReflectionContext
922
897
if (!Trailer)
923
898
break ;
924
899
auto PoolStart = TrailerPtr - Trailer->PoolSize ;
925
- printf (" Found pool at %#llx, allocation size is %llu\n " ,
926
- PoolStart, Trailer->PoolSize + sizeof (PoolTrailer));
927
-
928
900
auto PoolBytes = getReader ()
929
901
.readBytes (RemoteAddress (PoolStart), Trailer->PoolSize );
930
902
auto PoolPtr = (const char *)PoolBytes.get ();
931
903
if (!PoolPtr)
932
904
break ;
905
+
933
906
uintptr_t Offset = 0 ;
934
907
while (Offset < Trailer->PoolSize ) {
935
908
auto AllocationPtr = PoolPtr + Offset;
936
909
auto Header = (const AllocationHeader *)AllocationPtr;
937
910
if (Header->Size == 0 )
938
911
break ;
939
- auto Allocation = AllocationPtr + sizeof (AllocationHeader);
940
912
auto RemoteAddr = PoolStart + Offset + sizeof (AllocationHeader);
941
- printf (" Allocation tag %u size %u offset %#lx, remote address %#llx\n " , Header->Tag , Header->Size , Offset, RemoteAddr);
942
-
943
- switch (Header->Tag ) {
944
- case GenericMetadataCacheTag: {
945
- dumpGenericMetadataCacheEntry (Allocation);
946
- break ;
947
- }
948
- default :
949
- break ;
950
- }
913
+ MetadataAllocation Allocation;
914
+ Allocation.Tag = Header->Tag ;
915
+ Allocation.Ptr = RemoteAddr;
916
+ Allocation.Size = Header->Size ;
917
+ Call (Allocation);
951
918
952
919
Offset += sizeof (AllocationHeader) + Header->Size ;
953
920
}
954
921
955
922
TrailerPtr = Trailer->PrevTrailer ;
956
923
}
924
+ return true ;
957
925
}
958
926
959
927
private:
0 commit comments