@@ -33,27 +33,29 @@ func dumpConformanceCache(context: SwiftReflectionContextRef) throws {
3333 }
3434}
3535
36- func dumpMetadataAllocations( context: SwiftReflectionContextRef ) throws {
37- var allocations = context. allocations
38- for allocation in allocations {
36+ func dumpRawMetadata( context: SwiftReflectionContextRef ) throws {
37+ for allocation in context. allocations {
3938 print ( " Metadata allocation at: \( hex: allocation. ptr) " +
4039 " size: \( allocation. size) tag: \( allocation. tag) " )
4140 }
42-
43- allocations. sort ( )
44- let metadatas = allocations. compactMap { $0. metadata ( in: context) }
41+ }
42+
43+ func dumpGenericMetadata( context: SwiftReflectionContextRef ) throws {
44+ let allocations = context. allocations. sorted ( )
45+ let metadatas = allocations. findGenericMetadata ( in: context)
4546
47+ print ( " Address " , " Allocation " , " Size " , " Offset " , " Name " , separator: " \t " )
4648 for metadata in metadatas {
47- print ( " Metadata \( hex: metadata. ptr) " )
48- print ( " Name: \( metadata. name) " )
49+ print ( " \( hex: metadata. ptr) " , terminator: " \t " )
4950
50- if let allocation = allocations. last ( where: { metadata. ptr >= $0. ptr } ) {
51- let offset = metadata. ptr - allocation. ptr
52- print ( " In allocation \( hex: allocation. ptr) " +
53- " size \( allocation. size) at offset \( offset) " )
51+ if let allocation = metadata. allocation, let offset = metadata. offset {
52+ print ( " \( hex: allocation. ptr) \t \( allocation. size) \t \( offset) " ,
53+ terminator: " \t " )
5454 } else {
55- print ( " Not in any known metadata allocation. How strange. " )
55+ print ( " ??? \t ??? \t ??? " , terminator: " \t " )
56+
5657 }
58+ print ( metadata. name)
5759 }
5860}
5961
@@ -99,7 +101,8 @@ struct SwiftInspect: ParsableCommand {
99101 abstract: " Swift runtime debug tool " ,
100102 subcommands: [
101103 DumpConformanceCache . self,
102- DumpMetadataAllocations . self,
104+ DumpRawMetadata . self,
105+ DumpGenericMetadata . self,
103106 ] )
104107}
105108
@@ -117,7 +120,21 @@ struct DumpConformanceCache: ParsableCommand {
117120 }
118121}
119122
120- struct DumpMetadataAllocations : ParsableCommand {
123+ struct DumpRawMetadata : ParsableCommand {
124+ static let configuration = CommandConfiguration (
125+ abstract: " Print the target's metadata allocations. " )
126+ @Argument ( help: " The pid or partial name of the target process " )
127+
128+ var nameOrPid : String
129+
130+ func run( ) throws {
131+ try withReflectionContext ( nameOrPid: nameOrPid) {
132+ try dumpRawMetadata ( context: $0)
133+ }
134+ }
135+ }
136+
137+ struct DumpGenericMetadata : ParsableCommand {
121138 static let configuration = CommandConfiguration (
122139 abstract: " Print the target's metadata allocations. " )
123140 @Argument ( help: " The pid or partial name of the target process " )
@@ -126,7 +143,7 @@ struct DumpMetadataAllocations: ParsableCommand {
126143
127144 func run( ) throws {
128145 try withReflectionContext ( nameOrPid: nameOrPid) {
129- try dumpMetadataAllocations ( context: $0)
146+ try dumpGenericMetadata ( context: $0)
130147 }
131148 }
132149}
0 commit comments