4

I have crash in my program, it is a visualizer for VS, so, it is very hard to debug it, i have tried to make dump and use WinDbg to study it, but it unsuccessful.

So, now i try to put my hands on that list programmatically, but i don't know how. Thanks.

Yola
  • 18,496
  • 11
  • 65
  • 106
  • Which finalization list? The list of all objects that are currently live but will (when the GC observes no more references) be finalized, or the list of all objects where this has already happened and are just waiting for the finalizer thread to visit them? – Damien_The_Unbeliever May 20 '15 at 10:37
  • 2
    So you want the f-reachable queue. – Yuval Itzchakov May 20 '15 at 10:47
  • @Damien_The_Unbeliever: Re: _"or the list of all objects where this has already happened and are just waiting for the finalizer thread to visit them"_ This doesn't appear to make sense as far as I understand .NET GC. An object's memory might already have been *reclaimed* (garbage-collected), but the object might not yet have been *finalized*. But it doesn't appear possible that an object has been finalized but the "finalizer thread hasn't yet visited it". If the finalizer thread hasn't "visited" an object, then the object is not finalized. – stakx - no longer contributing May 20 '15 at 10:48
  • @stakx - I meant "where this has already happened" as "when the GC observes no more references" – Damien_The_Unbeliever May 20 '15 at 10:49
  • @Damien_The_Unbeliever: That clears it up, thanks. – stakx - no longer contributing May 20 '15 at 10:51
  • This is a humdinger XY question. A visualizer can never display an object that's in the finalization queue. It can only get in that queue when there are no references left. So the crash cannot have anything to do with it. – Hans Passant May 20 '15 at 11:38

2 Answers2

3

If you want to see if an object is in the finalization queue or the f-reachable queue, when you fire off WinDBG, first locate your object, using dumpheap -stat or any other command. After you find that objects address, you can use the !FinalizeQueue which will output how many objects are finalizable in each generation, and how many objects are ready for finalization. The former is the finalization queue, the latter is the f-reachable queue.

For example:

0:003> !FinalizeQueue

SyncBlocks to be cleaned up: 0 MTA Interfaces to be released: 0 STA Interfaces to be released:0

generation 0 has 370 finalizable objects
(0000000000d29030->0000000000d29bc0)

generation 1 has 4 finalizable objects
(0000000000d29010->0000000000d29030)

generation 2 has 8 finalizable objects
(0000000000d28fd0->0000000000d29010)

Ready for finalization 571 objects
(0000000000d29bc0->0000000000d2ad98)

Now, you can see where your objects address space is in.

A great tutorial is available here

Community
  • 1
  • 1
Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
2

I do not think that there is a way to get at the finalization queue via .NET's managed Framework Class Library (FCL). I suspect that if you want to do this programmatically instead of debugging with WinDbg, you (just like WinDbg and similar tools) will need to use the CLR's unmanaged debugging & profiling APIs towards that end.

Take a look at the ICORDebugGCReferenceEnum COM interface. You can retrieve on object of that type via ICorDebugProcess5::EnumerateGCReferences:

"Provides an enumerator for objects that will be garbage-collected."

"The COR_GC_REFERENCE objects in the collection populated by [the ICorDebugGCReferenceEnum::Next method] represent three kinds of objects:

  • Objects from all managed stacks. This includes live references in managed code as well as objects created by the common language runtime.

  • Objects from the handle table. This includes strong references (HNDTYPE_STRONG and HNDTYPE_REFCOUNT) and static variables in a module.

  • Objects from the finalizer queue. The finalizer queue roots objects until the finalizer has run."

(Hyperlinks and emphasis added by me.)

Each object returned by the enumerator has a field type. You might want to filter for objects where that field matches the value CorGCReferenceType.CorReferenceFinalizer.

Community
  • 1
  • 1
stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
  • Thank you for this direction, i'm not really how to use cordebug.idl and cordebug.tlb files that i have fonund on my PC in WDK dir, maybe you can provvide any link to how use this kind of objects? – Yola May 20 '15 at 12:20
  • 1
    @Yola: That is an altogether different question, and I am sure it has been asked before. I suggest you do some searching on SO or on the web. Not sure if a .NET process can inspect its own runtime, anyway (I've never done it), but here's a hint if you want to do this with .NET: Use the `tlbimp` tool to generate a .NET "primary interop assembly" with COM interop types from a `.tlb`. – stakx - no longer contributing May 21 '15 at 08:01