windbg/sos - !dumpheap/!dumpobj/!gcroot

Is there any way to find the callstack that lead to allocated object in windbg/sos I can do !gcroot, but I would like to see the call stack that lead to the object allocation. Thanks for any pointers!

Answer this question

windbg/sos - !dumpheap/!dumpobj/!gcroot

  • Iyyengar

    Hi,

    Thanks for the links. You're right it would take more memory, but not huge amount. There is a tool called gflags.exe that comes with Debugging tools. It allows to specify stack backtrace for each heap allocation. Later in windbg I can query each memory block and see complete callstack that allocated that memory. It works fine in unmanaged world. I thought there is something like that in managed world also so i could track object allocations and their stack backtrace. Last time I checked non of the profilers supported attaching to an already running process. In my case that's what I need. My process is started by another unmanaged host.

  • addexm

    There is no way to see callstacks at some time after object is allocated. Since it would require all stacks to be saved and would make your code very slow and take up huge amount of memory.

    Having said that. There are tools that will help you track that information including call stack. Take a look at http://www.scitech.se/memprofiler/ and http://www.microsoft.com/downloads/details.aspx FamilyId=86CE6052-D7F4-4AEB-9B7A-94635BEEBDDA&displaylang=en

  • windbg/sos - !dumpheap/!dumpobj/!gcroot