@@ -29,7 +29,7 @@ public class ClrDump
29
29
30
30
public List < ClrHandle > Handles => Runtime . EnumerateHandles ( ) . ToList ( ) ;
31
31
public List < ulong > FinalizerQueueObjectAddresses => Runtime . EnumerateFinalizerQueueObjectAddresses ( ) . ToList ( ) ;
32
- public IEnumerable < IGrouping < ClrType , ulong > > FinalizerQueueObjectAddressesByType => Runtime . EnumerateFinalizerQueueObjectAddresses ( ) . GroupBy ( address => GetObjectType ( address ) ) ;
32
+ public IEnumerable < IGrouping < ClrType , ulong > > FinalizerQueueObjectAddressesByType => Runtime . EnumerateFinalizerQueueObjectAddresses ( ) . GroupBy ( address => GetObjectType ( address ) ) ;
33
33
public IEnumerable < ClrRoot > ClrRoots => Runtime . GetHeap ( ) . EnumerateRoots ( ) ;
34
34
public List < BlockingObject > BlockingObjects => Runtime . GetHeap ( ) . EnumerateBlockingObjects ( ) . ToList ( ) ;
35
35
public IList < ClrThread > Threads => Runtime . Threads ;
@@ -52,7 +52,7 @@ public Dictionary<int, ThreadProperty> ThreadProperties
52
52
Dictionary < int , ThreadProperty > threadProperties ;
53
53
private readonly SingleThreadWorker worker ;
54
54
private ClrDumpCache cache ;
55
-
55
+
56
56
public ClrDump ( DataTarget target , string dumpPath , MessageBus msgBus )
57
57
{
58
58
Id = n ++ ;
@@ -85,7 +85,7 @@ private void InitRuntime()
85
85
86
86
public List < ClrType > GetTypes ( )
87
87
{
88
- List < ClrType > t = worker . Eval ( ( ) => t = AllTypes ) ;
88
+ List < ClrType > t = worker . Eval ( ( ) => t = AllTypes ) ;
89
89
return t ;
90
90
}
91
91
@@ -98,7 +98,7 @@ internal void Destroy()
98
98
internal void Dispose ( )
99
99
{
100
100
cache . Dispose ( ) ;
101
- Run ( ( ) => Runtime . DataTarget . Dispose ( ) ) ;
101
+ Run ( ( ) => Runtime . DataTarget . Dispose ( ) ) ;
102
102
}
103
103
104
104
public ClrType GetClrType ( string typeName )
@@ -125,7 +125,7 @@ public IEnumerable<ulong> EnumerateInstances(ClrType type)
125
125
return cache . EnumerateInstances ( typeId ) ;
126
126
}
127
127
128
- public List < ulong > GetInstances ( int typeId , int max = int . MaxValue )
128
+ public List < ulong > GetInstances ( int typeId , int max = int . MaxValue )
129
129
{
130
130
var instances = cache . LoadInstances ( typeId , max ) ;
131
131
return instances ;
@@ -177,7 +177,7 @@ private object GetSimpleValueImpl(ulong address, ClrType type)
177
177
var value = SimpleValueHelper . GetSimpleValue ( address , type , false ) ;
178
178
return value ;
179
179
}
180
-
180
+
181
181
return address ;
182
182
}
183
183
@@ -200,7 +200,7 @@ public object GetFieldValueImpl(ulong address, ClrType type, List<ClrInstanceFie
200
200
{
201
201
var field = fields [ i ] ;
202
202
obj = obj [ field ] ;
203
- if ( obj . IsNull )
203
+ if ( obj . IsNull )
204
204
{
205
205
return null ;
206
206
}
@@ -235,7 +235,7 @@ public bool HasReferences(ulong address)
235
235
236
236
public int CountReferences ( ulong address )
237
237
{
238
- var count = cache . CountReferences ( address ) ;
238
+ var count = cache . CountReferences ( address ) ;
239
239
return count ;
240
240
}
241
241
@@ -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 "???" ;
351
+ }
352
+
353
+
301
354
}
302
355
303
356
public class ThreadProperty
0 commit comments