Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simple example of setting a conditional breakpoint on the value of a string

270 views
Skip to first unread message

Rob

unread,
Jun 6, 2008, 8:23:11 PM6/6/08
to
I haven't been able to locate a simple example of setting a
conditional breakpoint on the value of a string variable. So I'm
posting this as a help for future newbies, like myself. I'm writing
this presuming you are debugging c or c++ using the default expression
evaulator - MASM.

The most important point is that you need to create an alias for your
variable with the 'as' command. Once you can list the alias ('al') as
showing the correct string value, then you can use it in a breakpoint.

I don't know what the comment marker is so take out the comments
before using.

Some examples.

For ASCII strings use /ma. For Unicode use /mu.

as /ma mychar_alias szMyChar // CHAR [] a simple local variable
as /ma mypointchar_alias poi(pszMyChar) // CHAR * a simple local
variable
as /ma myaddresschar_alias 1234567 // CHAR [] the address of a
variable anywhere
as /ma mypointaddresschar_alias poi(1234567) // CHAR * the
address of a variable anywhere

Then use 'al' to list the alias values:
0:007> al
Alias Value
------- -------
mychar_alias ABCDEF

Hint for getting variable addresses in structures - 'dt mystruct' -
will list the offsets of the members then just use mystruct+offset for
the address. e.g.
as /ma var 01c90000+03bc

Now you have an alias for your variable that shows the value of the
string, you can add it to a breakpoint.

Open your source code and set a breakpoint by pressing F9.

In the command window type bl to list the breakpoint.

copy the address info at the end. e.g. LANSA!CWINI_sCheckSysInit
+0x77f

Type: bu, paste the address in and append the script file name to get
this:.
bu LANSA!CWINI_sCheckSysInit+0x77f "$<c:\\script.txt"

Now put something like this in c:\script.txt

as /ma mychar_alias szMyChar
.echo ${mychar_alias}
.if ($scmp("${mychar_alias }","ABCDEF")==0 ) {} .else {gc}

This script shows the value of the string and then tests if it is
equal to ABCDEF. If it is it stops {}, otherwise execution continues
{gc}.

Similarly for $spat and $sicmp.

N.B. A defect in WinDbg: When re-running a debug session, the
breakpoint is remembered but the filename loses the backslash. You'll
need to re-enter the breakpoint.

0 new messages