Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DEBUGGER VERBAGE 1

Status
Not open for further replies.

ahoodin7

Programmer
Jun 16, 2004
72
US
Hello all,

How do I set a breakpoint to occur when a byte in a buffer changes from 0x04h to any other value? I am using MSVC 6.0 and Windows XP.

The debugger complains hartily when I try to do this.



unsigned char* pbuf = new unsigned char[256];
for (int i = 0; i < 256; i++)
{//INITIALIZE ALL DATA *(pbuf+i) = 0x04; }
for (i = 0; i < 256; i++)
{
//CHANGE DATA TO SIMULATE RE-INITIALIZE SHARED MEM
*(pbuf+i) = i;
}
delete[] pbuf;



Here is my example breakpoint:

*(pbuf+100) != 0x04

What is the best way to do this?

TIA,

ahoodin
 
You can allocate the buffer with VirtualAlloc() and then use VirtualProtect() with PAGE_READONLY - by every change of the region exception (access violation) will be generated. Debugger will catch this exception like a breakpoint (for example, DebugBreak()). If you wish to use this exception in release version, You should implement exception handling with SetUnhandledExceptionFilter( ).
 
I'm using MSVC 6.0 on XP too and I don't get any errors or memory corruption when I ran that code. Do you have Service Pack 5 for Visual Studio?

When you look at the memory bytes for pbuf, after you finish each for loop, check if you have "FD FD FD FD" at the end of pbuf's memory chunk. If you don't have 4 FD bytes, that means you wrote past the end of the array.
 
1) Got to the line where you wish to set the breakpoint. F9 to set it
2) Alt-F9 to display all the breakpoints
3) Click on the breakpoint you have just set in the dialog
4) Click on Condition...
5) In expression, enter *(pbuf+100) != 0x04

and that's it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top