@@ -251,7 +251,13 @@ public string GetObjectTypeName(ulong address)
251
251
252
252
public ClrType GetObjectType ( ulong address )
253
253
{
254
- var clrType = worker . Eval ( ( ) => Heap . GetObjectType ( address ) ) ;
254
+ var clrType = worker . Eval ( ( ) => GetObjectTypeImpl ( address ) ) ;
255
+ return clrType ;
256
+ }
257
+
258
+ public ClrType GetObjectTypeImpl ( ulong address )
259
+ {
260
+ var clrType = Heap . GetObjectType ( address ) ;
255
261
return clrType ;
256
262
}
257
263
@@ -298,6 +304,53 @@ public ClrMethod GetMethodByHandle(ulong methodDescriptorPtr)
298
304
var meth = Runtime . GetMethodByHandle ( methodDescriptorPtr ) ;
299
305
return meth ;
300
306
}
307
+
308
+ // Find the field in instance at address that references refAddress
309
+ public string GetFieldNameReference ( ulong refAddress , ulong address )
310
+ {
311
+ return Eval ( ( ) => GetFieldNameReferenceImpl ( refAddress , address ) ) ;
312
+ }
313
+ public string GetFieldNameReferenceImpl ( ulong refAddress , ulong address )
314
+ {
315
+ ClrType type = GetObjectTypeImpl ( address ) ;
316
+ if ( type == null )
317
+ {
318
+ return "Unknown" ;
319
+ }
320
+ ClrObject obj = new ClrObject ( address , type ) ;
321
+ if ( type . IsArray )
322
+ {
323
+ var length = type . GetArrayLength ( address ) ;
324
+ for ( int i = 0 ; i < length ; i ++ )
325
+ {
326
+ if ( obj [ i ] . Address == refAddress )
327
+ {
328
+ return $ "[ { i } ]";
329
+ }
330
+ }
331
+ return "[ ? ]" ;
332
+ }
333
+ foreach ( var field in type . Fields )
334
+ {
335
+ switch ( field . ElementType )
336
+ {
337
+ case ClrElementType . Struct :
338
+ case ClrElementType . String :
339
+ case ClrElementType . Array :
340
+ case ClrElementType . SZArray :
341
+ case ClrElementType . Object :
342
+ var fieldValue = obj [ field ] ;
343
+ if ( fieldValue . Address == refAddress )
344
+ {
345
+ return field . Name ;
346
+ }
347
+ break ;
348
+ }
349
+ }
350
+ return "Toto" ;
351
+ }
352
+
353
+
301
354
}
302
355
303
356
public class ThreadProperty
0 commit comments