void BreakIf(bool condition)
{
if(condition)
{
__asm
{
int 3
}
}
}
Useful Programming Tip
Well, since I don't have a column here, I thought I might as well share my advice here. I'm currently working on a textmode raytracer. I was just converting my raytracer from a scanline renderer to a tile renderer to better utilize the cache. So I ran into this strange problem that happened during rendering. It would seem that all it rendered was a single offscreen tile. Unfortunately I found out that it was happening deep into the rendering cycle. This would mean that everytime I needed to see if it got fixed, I'd need to press the Step Over (F11) key about 800 times. I realized that there's no conditional breakpoint command in Visual Studio.
Here's the important part. I suddenly remembered something from my Computer Organization (Pentium Assembly) course in University. The key is software interrups. So I hurridly coded up what I think will be very useful to everyone. So here it is.
What this code will do is insert a breakpoint on the line that says "int 3". It will move the processor into single-step mode, and thus Visual Studio will also move into single-step mode allowing you to use all of your F10, F11, etc... keys. To get to your code, just keep stepping until you get there.
So what do you think? Useful? Yes? No? Should I write some more useful tips like this (I've got a few more)?
Quote:Original post by Reaper_Unreal
I realized that there's no conditional breakpoint command in Visual Studio.
Yes there is.
Right click on the line you have the breakpoint set on, go to breakpoint properties and there is a conditional button you can enter in a condition you want it to break on.
Also if you ever have an infinite loop somewhere and you dont know where you can force the program to break with CTRL-ALT-BREAK and that will force the program to break wherever the instruction pointer currently is.
That's exactly the way I implemented my own assert macro :D
#ifdef _DEBUG #define EAssert(x, msg) if(x) { EDebugOutput(msg);__asm int 3;}#else #define EAssert(x, msg)#endif
Visual Studio has many break point options infact. Conditional ones and even "Break on Write" style breakpoints (if not using managed code, beacause of managed memory dancing you can't do it or something)
Quote:Original post by Keem
Visual Studio has many break point options infact. Conditional ones and even "Break on Write" style breakpoints (if not using managed code, beacause of managed memory dancing you can't do it or something)
You can do it in an unmanaged block inside managed code if you want (using the unsafe specifier). But you can't break-on-write in managed code because the GC frequently moves lightweight objects around in blocks when it frees up larger memory chunks. So a breakpoint that's watching a specific location in managed memory would get falsely triggered if the GC moves the object.
I usually just do something of the form
and then binary search on the value of count to find where the bug occurs.
// Inside function or loop:static int count = 0; count++; if(count == 10000){ int q = 0; // Put breakpoint on this line. It needs an actual statement (not just a declaration such as 'int q;'), otherwise it moves your breakpoint down}
and then binary search on the value of count to find where the bug occurs.
The platform sdk has a debug break function (int 3):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/debugbreak.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/debugbreak.asp
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement