tags:

views:

493

answers:

2

Hello everyone,

I have a type called Foo and it has a field called length. I want to write a single loop statement in Windbg which will dump length field of all object instances of type Foo in managed heap?

thanks in advance, George

+1  A: 

Hi George,

Here's a script that I haven't tested, but might do the trick for you. I based it off of Tess' scripts for dumping out all session variables on the heap for ASP.net.

r @$t0=0;

$$ Loop to get all foo's
.foreach (CurrentFoo {!dumpheap -type George.George2.Foo -short}){
    $$ Increment # of Foo's
    r @$t0 = @$t0+1

    .printf "Length:\t%d\n", poi(${CurrentFoo}+0xc);
}
.printf "Number of Foo's: %d\n\n\n\n\n\n\n\n\n", @$t0;

The trick to this one will be figuring out the number of bytes that the length property is offset from the main Foo reference, and replacing the "0xc" in the printf line with the correct number of offset bytes.

You should be able to do this by just doing a !dumpobject on one of your Foo's and looking at the structure of it.

Hope that helps.

womp