Sign in to follow this  
Dovyman

Custom Debugging

Recommended Posts

Dovyman    277
Does anybody know how to set interrupts within C code under the Microsoft compiler? i.e., being able to hard code breakpoints in, but when the code hit them, I could have my own interrupt handler instead of control going to the MS debugger. ?

Share this post


Link to post
Share on other sites
mattnewport    1038
To hard code a breakpoint in C code on x86 with MSVC use
__asm int 3
As for catching exceptions, you'll want to look into Win32 Structured Exception Handling but I'm not sure how you can catch a breakpoint exception before the debugger gets a hold of it. This test program:


#include <iostream>
#include <windows.h>

int main(int argc, char* argv[])
{
__try
{
__asm int 3
}
__except(GetExceptionCode() == EXCEPTION_BREAKPOINT ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
std::cout << "Hit a breakpoint!\n";
}
return 0;
}

Will catch the breakpoint when run outside the debugger but when run inside the debugger it seems the debugger catches it first. I don't know how to get around that, maybe a bit of Googling will help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this