How to print my allocations > 64Kb using WinDBG?

Hello WinDBG gurus,

I would like to script WinDBG to print the size and the stack of my malloc
allocations while my application is executing.
These would be save to the WinDBG log which I would parse later.

I came all the way to this breakpoint:

bp msvcrt!malloc “j (poi(@esp+4)>=0x10000) ‘kb;printf
‘allocSize=%d’,poi(@esp+4)’ ; ‘gc’”

This means to break on msvcrt!malloc, check if the size argument is > 64K.
If so, print its stack and then print “allocSize=[size_in_decimal]\n”
If smaller, continue the execution.

When I use it and it finally reaches one of these allocations, I get the
following error:
^ Extra character error in 'j (poi(@esp+4)>=0x10000)
'kb;printf ‘allocSize=%d ,poi(@esp+4)’

Appreciate any input, since this is a puzzle I have attempt to resolve many
times…

Also, is there a escape character for WinDBG commands?

Thanks,
Osiris Pedroso

Osiris Pedroso wrote:

Hello WinDBG gurus,

I would like to script WinDBG to print the size and the stack of my
malloc allocations while my application is executing.
These would be save to the WinDBG log which I would parse later.

I came all the way to this breakpoint:

bp msvcrt!malloc “j (poi(@esp+4)>=0x10000) ‘kb;printf
‘allocSize=%d’,poi(@esp+4)’ ; ‘gc’”

That should be .printf (with a leading dot). You nest the inner quotes
by doubling them. So:

bp msvcrt!malloc “j (poi(@esp+4)>=0x10000) ‘kb;.printf
‘‘allocSize=%d’’,poi(@esp+4)’ ; ‘gc’”

That actually seems to work for me. Note that, in order, you see double
quotes, single quotes, doubled single quotes, doubled single quotes,
single quote, single quote, double quote. Sheesh.


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

bp msvcr90d!malloc "j ( poi(@esp+4)>=0x10) ‘.printf
"allocSize=%p\n",poi(@esp+4);kb;g’ ‘gc’ "

printf has a . dot in front and iirc there is no %d you need to escape
the quotes back slashes etc

the above line should work

On 7/30/11, Osiris Pedroso wrote:
> Hello WinDBG gurus,
>
> I would like to script WinDBG to print the size and the stack of my malloc
> allocations while my application is executing.
> These would be save to the WinDBG log which I would parse later.
>
> I came all the way to this breakpoint:
>
> bp msvcrt!malloc “j (poi(@esp+4)>=0x10000) ‘kb;printf
> ‘allocSize=%d’,poi(@esp+4)’ ; ‘gc’”
>
> This means to break on msvcrt!malloc, check if the size argument is > 64K.
> If so, print its stack and then print “allocSize=[size_in_decimal]\n”
> If smaller, continue the execution.
>
> When I use it and it finally reaches one of these allocations, I get the
> following error:
> ^ Extra character error in 'j (poi(@esp+4)>=0x10000)
> 'kb;printf ‘allocSize=%d ,poi(@esp+4)’
>
> Appreciate any input, since this is a puzzle I have attempt to resolve many
> times…
>
> Also, is there a escape character for WinDBG commands?
>
> Thanks,
> Osiris Pedroso
>
> —
> 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


thanks and regards

raj_r