次の方法で共有


How to setup breakpoint programmatically in source code?

Sometimes, you might be in a situation when you want to break in your code at a certain location. You might be trying to put a message box or getch() kind of method for that. There is a direct code to do that, through assembly language.

int _tmain(int argc, _TCHAR* argv[])
{
    __asm
    {
        int 3;
    }

    return 0;
}

When you will do an F5 ( Start Debugging ) from Visual Studio, then the debugger will break at the point where the instruction int 3; is. Visual Studio gives the message like below-

breakpoint 

You might be thinking that How it is going to help you, you can always do it through setting up a break point on any statement using F9. Below is the scenario where the given code is very helpful.

You might want to attach windbg to the executable and keep it running until a certain point and then break right there. If you have the debug exe which have the code like above, it will break in windbg right there.

 pic2

This was a small but cool tip, so just wanted to share.

I am planning to put some more debugging with windbg stuff here.

Nitin Dhawan

Windows SDK – Microsoft

Comments