@@ -54,20 +54,14 @@ static void errorAndExit(const char *message) {
54
54
abort ();
55
55
}
56
56
57
- RemoteSection makeRemoteSection (uintptr_t StartAddress , uintptr_t Size ) {
58
- RemoteSection RS = {
59
- StartAddress ,
60
- Size ,
61
- StartAddress + Size
62
- };
63
- return RS ;
64
- }
65
-
66
57
swift_reflection_section_t
67
- makeLocalSection (uintptr_t StartAddress , size_t Size ) {
58
+ makeLocalSection (void * Buffer , RemoteSection Section ,
59
+ RemoteReflectionInfo Info ) {
60
+ uintptr_t Base
61
+ = (uintptr_t )Buffer + Section .StartAddress - Info .StartAddress ;
68
62
swift_reflection_section_t LS = {
69
- (void * )StartAddress ,
70
- (void * )(StartAddress + Size )
63
+ (void * )Base ,
64
+ (void * )(Base + Section . Size )
71
65
};
72
66
return LS ;
73
67
}
@@ -157,7 +151,7 @@ uint8_t PipeMemoryReader_getSizeSize(void *Context) {
157
151
}
158
152
159
153
void PipeMemoryReader_collectBytesFromPipe (const PipeMemoryReader * Reader ,
160
- uint8_t * Dest , size_t Size ) {
154
+ void * Dest , size_t Size ) {
161
155
int ReadFD = PipeMemoryReader_getParentReadFD (Reader );
162
156
while (Size ) {
163
157
int bytesRead = read (ReadFD , Dest , Size );
@@ -171,7 +165,7 @@ void PipeMemoryReader_collectBytesFromPipe(const PipeMemoryReader *Reader,
171
165
}
172
166
173
167
int PipeMemoryReader_readBytes (void * Context ,
174
- addr_t Address , uint8_t * Dest , uint64_t Size ) {
168
+ addr_t Address , void * Dest , uint64_t Size ) {
175
169
const PipeMemoryReader * Reader = (const PipeMemoryReader * )Context ;
176
170
uintptr_t TargetAddress = Address ;
177
171
int WriteFD = PipeMemoryReader_getParentWriteFD (Reader );
@@ -228,99 +222,68 @@ PipeMemoryReader createPipeMemoryReader() {
228
222
return Reader ;
229
223
}
230
224
231
- const swift_reflection_info_t *
232
- PipeMemoryReader_receiveReflectionInfo (const PipeMemoryReader * Reader ,
233
- size_t * NumReflectionInfos ) {
225
+ RemoteSection makeRemoteSection (const PipeMemoryReader * Reader ) {
226
+ uintptr_t Start ;
227
+ size_t Size ;
228
+
229
+ PipeMemoryReader_collectBytesFromPipe (Reader , & Start , sizeof (Start ));
230
+ PipeMemoryReader_collectBytesFromPipe (Reader , & Size , sizeof (Size ));
231
+
232
+ RemoteSection RS = {Start , Size , Start + Size };
233
+ return RS ;
234
+ }
235
+
236
+ void
237
+ PipeMemoryReader_receiveReflectionInfo (SwiftReflectionContextRef RC ,
238
+ const PipeMemoryReader * Reader ) {
234
239
int WriteFD = PipeMemoryReader_getParentWriteFD (Reader );
235
240
write (WriteFD , REQUEST_REFLECTION_INFO , 2 );
236
- PipeMemoryReader_collectBytesFromPipe (Reader , (uint8_t * )NumReflectionInfos ,
241
+ size_t NumReflectionInfos ;
242
+ PipeMemoryReader_collectBytesFromPipe (Reader , & NumReflectionInfos ,
237
243
sizeof (NumReflectionInfos ));
238
244
239
- if (* NumReflectionInfos == 0 )
240
- return NULL ;
241
-
242
- size_t Size = sizeof (RemoteReflectionInfo ) * * NumReflectionInfos ;
243
- RemoteReflectionInfo * RemoteInfos = (RemoteReflectionInfo * )malloc (Size );
244
-
245
- for (size_t i = 0 ; i < * NumReflectionInfos ; ++ i ) {
246
- uintptr_t fieldmd_start ;
247
- size_t fieldmd_size ;
248
- uintptr_t assocty_start ;
249
- size_t assocty_size ;
250
- uintptr_t builtin_start ;
251
- size_t builtin_size ;
252
- uintptr_t typeref_start ;
253
- size_t typeref_size ;
254
- uintptr_t reflstr_start ;
255
- size_t reflstr_size ;
256
-
257
- PipeMemoryReader_collectBytesFromPipe (Reader , (uint8_t * )& fieldmd_start ,
258
- sizeof (fieldmd_start ));
259
- PipeMemoryReader_collectBytesFromPipe (Reader , (uint8_t * )& fieldmd_size ,
260
- sizeof (fieldmd_size ));
261
- PipeMemoryReader_collectBytesFromPipe (Reader , (uint8_t * )& assocty_start ,
262
- sizeof (assocty_start ));
263
- PipeMemoryReader_collectBytesFromPipe (Reader , (uint8_t * )& assocty_size ,
264
- sizeof (assocty_size ));
265
- PipeMemoryReader_collectBytesFromPipe (Reader , (uint8_t * )& builtin_start ,
266
- sizeof (builtin_start ));
267
- PipeMemoryReader_collectBytesFromPipe (Reader , (uint8_t * )& builtin_size ,
268
- sizeof (builtin_size ));
269
- PipeMemoryReader_collectBytesFromPipe (Reader , (uint8_t * )& typeref_start ,
270
- sizeof (typeref_start ));
271
- PipeMemoryReader_collectBytesFromPipe (Reader , (uint8_t * )& typeref_size ,
272
- sizeof (typeref_size ));
273
- PipeMemoryReader_collectBytesFromPipe (Reader , (uint8_t * )& reflstr_start ,
274
- sizeof (reflstr_start ));
275
- PipeMemoryReader_collectBytesFromPipe (Reader , (uint8_t * )& reflstr_size ,
276
- sizeof (reflstr_size ));
245
+ if (NumReflectionInfos == 0 )
246
+ return ;
277
247
248
+ RemoteReflectionInfo * RemoteInfos = calloc (NumReflectionInfos ,
249
+ sizeof (RemoteReflectionInfo ));
250
+ if (RemoteInfos == NULL )
251
+ errorAndExit ("malloc failed" );
252
+
253
+ for (size_t i = 0 ; i < NumReflectionInfos ; ++ i ) {
278
254
RemoteInfos [i ] = makeRemoteReflectionInfo (
279
- makeRemoteSection (fieldmd_start , fieldmd_size ),
280
- makeRemoteSection (assocty_start , assocty_size ),
281
- makeRemoteSection (builtin_start , builtin_size ),
282
- makeRemoteSection (typeref_start , typeref_size ),
283
- makeRemoteSection (reflstr_start , reflstr_size ));
255
+ makeRemoteSection (Reader ),
256
+ makeRemoteSection (Reader ),
257
+ makeRemoteSection (Reader ),
258
+ makeRemoteSection (Reader ),
259
+ makeRemoteSection (Reader ));
284
260
}
285
261
286
262
// Now pull in the remote sections into our address space.
287
263
288
- swift_reflection_info_t * Infos
289
- = malloc (sizeof (swift_reflection_info_t ) * * NumReflectionInfos );
290
-
291
- for (size_t i = 0 ; i < * NumReflectionInfos ; ++ i ) {
264
+ for (size_t i = 0 ; i < NumReflectionInfos ; ++ i ) {
292
265
RemoteReflectionInfo RemoteInfo = RemoteInfos [i ];
293
266
294
- uintptr_t buffer = ( uintptr_t ) malloc (RemoteInfo .TotalSize );
267
+ void * Buffer = malloc (RemoteInfo .TotalSize );
295
268
296
- int Success = PipeMemoryReader_readBytes ((void * )Reader ,
269
+ int Success = PipeMemoryReader_readBytes ((void * )Reader ,
297
270
RemoteInfo .StartAddress ,
298
- ( uint8_t * ) buffer ,
271
+ Buffer ,
299
272
RemoteInfo .TotalSize );
300
273
if (!Success )
301
274
errorAndExit ("Couldn't read reflection information" );
302
275
303
- uintptr_t fieldmd_base
304
- = buffer + RemoteInfo .fieldmd .StartAddress - RemoteInfo .StartAddress ;
305
- uintptr_t assocty_base
306
- = buffer + RemoteInfo .assocty .StartAddress - RemoteInfo .StartAddress ;
307
- uintptr_t builtin_base
308
- = buffer + RemoteInfo .builtin .StartAddress - RemoteInfo .StartAddress ;
309
- uintptr_t typeref_base
310
- = buffer + RemoteInfo .typeref .StartAddress - RemoteInfo .StartAddress ;
311
- uintptr_t reflstr_base
312
- = buffer + RemoteInfo .reflstr .StartAddress - RemoteInfo .StartAddress ;
313
-
314
276
swift_reflection_info_t Info = {
315
- makeLocalSection (fieldmd_base , RemoteInfo .fieldmd . Size ),
316
- makeLocalSection (assocty_base , RemoteInfo .assocty . Size ),
317
- makeLocalSection (builtin_base , RemoteInfo .builtin . Size ),
318
- makeLocalSection (typeref_base , RemoteInfo .typeref . Size ),
319
- makeLocalSection (reflstr_base , RemoteInfo .reflstr . Size )
277
+ makeLocalSection (Buffer , RemoteInfo .fieldmd , RemoteInfo ),
278
+ makeLocalSection (Buffer , RemoteInfo .assocty , RemoteInfo ),
279
+ makeLocalSection (Buffer , RemoteInfo .builtin , RemoteInfo ),
280
+ makeLocalSection (Buffer , RemoteInfo .typeref , RemoteInfo ),
281
+ makeLocalSection (Buffer , RemoteInfo .reflstr , RemoteInfo )
320
282
};
321
- Infos [ i ] = Info ;
283
+ swift_reflection_addReflectionInfo ( RC , Info ) ;
322
284
}
323
- return Infos ;
285
+
286
+ free (RemoteInfos );
324
287
}
325
288
326
289
uint64_t PipeMemoryReader_getStringLength (void * Context , addr_t Address ) {
@@ -329,8 +292,7 @@ uint64_t PipeMemoryReader_getStringLength(void *Context, addr_t Address) {
329
292
write (WriteFD , REQUEST_STRING_LENGTH , 2 );
330
293
write (WriteFD , & Address , sizeof (Address ));
331
294
uintptr_t Length = 0 ;
332
- PipeMemoryReader_collectBytesFromPipe (Reader , (uint8_t * )& Length ,
333
- sizeof (Length ));
295
+ PipeMemoryReader_collectBytesFromPipe (Reader , & Length , sizeof (Length ));
334
296
return Length ;
335
297
}
336
298
@@ -371,12 +333,7 @@ int doDumpHeapInstance(const char *BinaryFilename) {
371
333
printf ("Instance pointer in child address space: 0x%lx\n" ,
372
334
instance );
373
335
374
- size_t NumReflectionInfos = 0 ;
375
- const swift_reflection_info_t * Infos
376
- = PipeMemoryReader_receiveReflectionInfo (& Pipe , & NumReflectionInfos );
377
-
378
- for (size_t i = 0 ; i < NumReflectionInfos ; ++ i )
379
- swift_reflection_addReflectionInfo (RC , Infos [i ]);
336
+ PipeMemoryReader_receiveReflectionInfo (RC , & Pipe );
380
337
381
338
printf ("Type reference:\n" );
382
339
0 commit comments