次の方法で共有


Windbg loops around First chance and Second chance exceptions

My program causes an exception and debugger catches it, but the debugger is stuck in loop of first chance and second chance exception. Why isn't it get out of the loop and terminates the program if the exception is not handled?

A snip from debugger output

(2724.2708): Integer divide-by-zero - code c0000094 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
DivideByZero!main+0x15:
013516b5 f7f9            idiv    eax,ecx
0:000:x86> g
(2724.2708): Integer divide-by-zero - code c0000094 (!!! second chance !!!)
DivideByZero!main+0x15:
013516b5 f7f9            idiv    eax,ecx
0:000:x86> g
(2724.2708): Integer divide-by-zero - code c0000094 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
DivideByZero!main+0x15:
013516b5 f7f9            idiv    eax,ecx
0:000:x86> g
(2724.2708): Integer divide-by-zero - code c0000094 (!!! second chance !!!)
DivideByZero!main+0x15:
013516b5 f7f9            idiv    eax,ecx

 

When the exception is raised, windows kernel looks if the debugger is attached to the process. If yes, the process is broken into the debugger with First chance exception message. Continuing with 'g' goes with exception unhandled and the process is again broken into the debugger with Second chance exception message. However after first chance exception if you continue with 'gh' instead of 'g', you will see a loop of First chance exception only and no second chance.

After second chance exception continuing with 'g' goes with exception handled, and the kernel resumes the process again from the instruction where exception happened. Which again leads to the First chance exception and the cycle goes on...

However if after Second chance exception you continue with 'gn' instead of 'g', the debugger goes with exception not handled and program is terminated. You won't see an exception loop.