@@ -33,27 +33,29 @@ func dumpConformanceCache(context: SwiftReflectionContextRef) throws {
33
33
}
34
34
}
35
35
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 {
39
38
print ( " Metadata allocation at: \( hex: allocation. ptr) " +
40
39
" size: \( allocation. size) tag: \( allocation. tag) " )
41
40
}
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)
45
46
47
+ print ( " Address " , " Allocation " , " Size " , " Offset " , " Name " , separator: " \t " )
46
48
for metadata in metadatas {
47
- print ( " Metadata \( hex: metadata. ptr) " )
48
- print ( " Name: \( metadata. name) " )
49
+ print ( " \( hex: metadata. ptr) " , terminator: " \t " )
49
50
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 " )
54
54
} else {
55
- print ( " Not in any known metadata allocation. How strange. " )
55
+ print ( " ??? \t ??? \t ??? " , terminator: " \t " )
56
+
56
57
}
58
+ print ( metadata. name)
57
59
}
58
60
}
59
61
@@ -99,7 +101,8 @@ struct SwiftInspect: ParsableCommand {
99
101
abstract: " Swift runtime debug tool " ,
100
102
subcommands: [
101
103
DumpConformanceCache . self,
102
- DumpMetadataAllocations . self,
104
+ DumpRawMetadata . self,
105
+ DumpGenericMetadata . self,
103
106
] )
104
107
}
105
108
@@ -117,7 +120,21 @@ struct DumpConformanceCache: ParsableCommand {
117
120
}
118
121
}
119
122
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 {
121
138
static let configuration = CommandConfiguration (
122
139
abstract: " Print the target's metadata allocations. " )
123
140
@Argument ( help: " The pid or partial name of the target process " )
@@ -126,7 +143,7 @@ struct DumpMetadataAllocations: ParsableCommand {
126
143
127
144
func run( ) throws {
128
145
try withReflectionContext ( nameOrPid: nameOrPid) {
129
- try dumpMetadataAllocations ( context: $0)
146
+ try dumpGenericMetadata ( context: $0)
130
147
}
131
148
}
132
149
}
0 commit comments