Sometimes we have to run release mode code, either because it is what we’re testing, or it just takes too long to run the program in debug mode (I had one level which took > 15 mins to load up in debug mode, and that’s without the debugger attached!). While solving bugs in this case, I would sometimes like to break the process when some invalid situation occurs. I do this way:
if ( _isnan( someNumber ) { __asm int 3 // semi-colon not necessary }
int 3 is a software interrupt that, in this example, gets triggered when someNumber is invalid, which means most likely the latter is an uninitialised variable. This is quite useful when logging to output is not an option.
Notes:
- This is definitely not cross-platform
- DebugBreak() and __debugbreak() should do the same thing, but its more l337 to use asm when debugging 😛
No Comments.