how to write a loop in Windbg like this?

(Sorry this question is in the context of managed code, but I think it deals more with how to write loop batch command in Windbg)

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

On Sat, Feb 28, 2009 at 03:58:21AM -0800, Lin George wrote:

(Sorry this question is in the context of managed code, but I think it
deals more with how to write loop batch command in Windbg)

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?

Nope, that's just impossible. Windbg can dump the data in the structure
if you tell it the address, but it can't go out and FIND the objects.
That kind of information simply doesn't exist.

If you need to track the objects, why not just keep the objects in a
list on your own?

And why, may I ask, are you using windbg to debug managed code, instead
of using the debugger in Visual Studio? In my experience, the Visual
Studio debugger is just a lot more handy for managed code.

Tim Roberts, xxxxx@probo.com
Providenza & Boeklheide, Inc.

Thanks Tim, in these days you see I send very few managed code debug issues, because I want to spam the list as least as possible. :slight_smile:

But I still have (1) some crash dump in managed code (2) performance issues, do you have any advice how to debug them without using the powerful windbg?

regards,
George

----- Original Message ----
From: “xxxxx@probo.com
To: Kernel Debugging Interest List
Cc: Tim Roberts
Sent: Sunday, March 1, 2009 3:22:18 PM
Subject: Re: [windbg] how to write a loop in Windbg like this?

On Sat, Feb 28, 2009 at 03:58:21AM -0800, Lin George wrote:
>
> (Sorry this question is in the context of managed code, but I think it
> deals more with how to write loop batch command in Windbg)
>
> 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?

Nope, that’s just impossible.? Windbg can dump the data in the structure
if you tell it the address, but it can’t go out and FIND the objects.
That kind of information simply? doesn’t exist.

If you need to track the objects, why not just keep the objects in a
list on your own?

And why, may I ask, are you using windbg to debug managed code, instead
of using the debugger in Visual Studio?? In my experience, the Visual
Studio debugger is just a lot more handy for managed code.

Tim Roberts, xxxxx@probo.com
Providenza & Boeklheide, Inc.


WINDBG is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

2009/3/1

> And why, may I ask, are you using windbg to debug managed code, instead
> of using the debugger in Visual Studio? In my experience, the Visual
> Studio debugger is just a lot more handy for managed code.
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boeklheide, Inc.
>
>
>

Hi Tim,

WinDbg is the debugger you should use for managed code also. Visual Studio
does not support all the commands from SOS and although I cannot tell you
exact commands that does not work, WinDbg is still preffered way to debug
managed applications in production environments.

All the best,
Martin Kulov [VSTS MVP]
www.kulov.net

Thanks Martin,

If you suggest me to use Windbg, could you let me know how to write a single loop statement in Windbg which will dump length field of all object instances of type Foo in managed heap? I searched for SOS and Windbg help documents for a couple of days but can not find a solution.

Do you have any other discussion forum or list to recommend for discussion more about using Windbg in managed code? :slight_smile:

regards,
George


From: Martin Kulov
To: Kernel Debugging Interest List
Cc: Tim Roberts
Sent: Monday, March 2, 2009 7:20:42 AM
Subject: Re: [windbg] how to write a loop in Windbg like this?

2009/3/1

And why, may I ask, are you using windbg to debug managed code, instead
of using the debugger in Visual Studio? ?In my experience, the Visual
Studio debugger is just a lot more handy for managed code.

Tim Roberts, xxxxx@probo.com
Providenza & Boeklheide, Inc.

?

Hi Tim,

WinDbg is the debugger you should use for managed code also. Visual Studio does not support all the commands from SOS and although I cannot tell you exact commands that does not work, WinDbg is still preffered way to debug managed applications in production environments.

All the best,
Martin Kulov [VSTS MVP]
www.kulov.net— WINDBG is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Hello George,

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?

You can write a loop do dump *all* fields of all instances of “Foo”, but because !DumpObj (!do) doesn’t define an argument that just prints a single field, it’s up to you to extract the “length” field from the output. But you can use the .shell command with the find commandline utility for this.

To dump all instances of “Foo” you can use the following command:

.foreach (v {!dumpheap -type Foo -short}) {!do v}

Do filter only the field “length” (or all lines that include the string “length”):

.shell -ci “.foreach (v {!dumpheap -type Foo -short}) {!do v}” FIND “length”

PS: It would be good to mention that your question is releated to the SOS (managed code) extension, and not windbg in general. Most members of this group only uses unmanaged (mostly kernel) debugging, and have no idea of SOS! Basically it seems like I’m the only one here doing also SOS debugging :smiley:

You say that my posts for you “stack trace issue” are missing? Pavel has reposted them. Ok?

regards,
GP

powered by Exchange 2007 - hosted by a Microsoft Gold Partner - visit us www.world-direct.at

Hey George,

I cannot help you with that one, but you can check the newsgroup
microsoft.public.windbg which you already did as I can see.
Also these forums may be of help:
http://social.msdn.microsoft.com/Forums/en-US/clr/threads/
http://social.msdn.microsoft.com/Forums/en-US/vsdebug/threads/

Did you try Gunter’s solution?

Martin Kulov [VSTS MVP]
www.kulov.net

2009/3/2 G?nter Prossliner

> Hello George,
>
> > 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?
>
>
> You can write a loop do dump all fields of all instances of “Foo”, but
> because !DumpObj (!do) doesn’t define an argument that just prints a single
> field, it’s up to you to extract the “length” field from the output. But you
> can use the .shell command with the find commandline utility for this.
>
> To dump all instances of “Foo” you can use the following command:
>
> .foreach (v {!dumpheap -type Foo -short}) {!do v}
>
> Do filter only the field “length” (or all lines that include the string
> “length”):
>
> .shell -ci “.foreach (v {!dumpheap -type Foo -short}) {!do v}” FIND
> “length”
>
>
> PS: It would be good to mention that your question is releated to the SOS
> (managed code) extension, and not windbg in general. Most members of this
> group only uses unmanaged (mostly kernel) debugging, and have no idea of
> SOS! Basically it seems like I’m the only one here doing also SOS debugging
> :smiley:
>
>
> You say that my posts for you “stack trace issue” are missing? Pavel has
> reposted them. Ok?
>
> regards,
> GP
>
> powered by Exchange 2007 - hosted by a Microsoft Gold Partner - visit us
> www.world-direct.at
>
> —
> WINDBG is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>