Has "breakpoint exception" got a "exception"?

Hi

Please look at this code:

#include <afxwin.h>

void Foo()
{
__try
{
int val = 0;
int result = 90 / val;
}
__ except(TRUE)
{
TRACE(“In Foo\n”);
AfxMessageBox(L"In Foo");
}
}
void HandledBP()
{
__try
{
DebugBreak();
}
__except(TRUE)
{
TRACE(“In HandleBP\n”);
AfxMessageBox(L"In HandleBP\n");
}
}

int main(int argc, CHAR* argv)
{
Foo();

HandledBP();

TRACE(“In Main\n”);
AfxMessageBox(L"In Main");
return 0;
}

If you run this code “without debugging”, you will see 3 messageboxes:

In Foo
In HandleBp
In Main

But if we run it under debugger;
For Foo():
“First-chance exception at 0x00411afc in Debug.exe: 0xC0000094: Integer division by zero.
In Foo”
This is what i expect to see.

But for HandleBP():
There is no first chance and output for the program is:

First-chance exception at 0x00411afc in Debug.exe: 0xC0000094: Integer division by zero.
In Foo
////…
Debug.exe has triggered a breakpoint
In Main

I can’t see “In Foo” messagebox.

Why is it so?
I think for only breakpoint exceptions debugger doesn’t give chance to my handler code. Am i right?
Is it only valid for breakpoint exception?</afxwin.h>

xxxxx@gmail.com wrote:

Please look at this code:

If you run this code “without debugging”, you will see 3 messageboxes:

In Foo
In HandleBp
In Main

But if we run it under debugger;
For Foo():
“First-chance exception at 0x00411afc in Debug.exe: 0xC0000094: Integer division by zero.
In Foo”
This is what i expect to see.

But for HandleBP():
There is no first chance and output for the program is:

First-chance exception at 0x00411afc in Debug.exe: 0xC0000094: Integer division by zero.
In Foo
////…
Debug.exe has triggered a breakpoint
In Main

I can’t see “In Foo” messagebox.

Why is it so?
I think for only breakpoint exceptions debugger doesn’t give chance to my handler code. Am i right?
Is it only valid for breakpoint exception?

Hitting a breakpoint without a debugger is an exception condition. It’s
an abnormal situation that needs to be handled specially.

Hitting a breakpoint with a debugger attached is not an exception. It’s
a normal condition. If windbg didn’t work this way, there would be no
way to debug the inside of exception handlers.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

“Hitting a breakpoint with a debugger attached is not an exception”
Understood.
Thank you Mr. Tim Roberts.

Well, it is and exception, and always will be.
But when you have a debugger attached, the debugger “handles” it.
In fact one anti debugging technique is to execute an int 3 (which is what a
debugbreak is) and see if you get passed the exception or not.
If you don’t get it, you are being debugged.
If you really want to understand SEH, please read:
http://www.microsoft.com/msj/0197/exception/exception.aspx
and
http://msdn.microsoft.com/en-us/magazine/cc301714.aspx
Excellent Matt Pietrek articles on the subject.

On Wed, Jul 16, 2008 at 1:21 PM, wrote:

> “Hitting a breakpoint with a debugger attached is not an exception”
> Understood.
> Thank you Mr. Tim Roberts.
>
> —
> You are currently subscribed to windbg as: xxxxx@jimdonelson.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Thanks for links and anti debugging tip-trick, i didn’t know it.