Demystifying first-chance exceptions (Part 1)
DATA (Dump Analysis + Trace Analysis) Facebook group
Please join the community of memory (dump) and trace analysis engineers. This group promotes scientific methods and memory dump-based world view.
Twitter @ DumpAnalysis You can now follow portal and blog news at DumpAnalysis on Twitter.
2009 (0x7D9) - The Year of Debugging 2010 (0x7DA) - The Year of Dump Analysis 2011 (0x7DB) - 2020 (0x7E4) The Debugging Decade
There is a bit of confusion around the division of exceptions between the first- and second-chance. For example, I am often asked whether saving crash dumps on first-chance exceptions should be disabled or enabled. So I decided to clarify this issue.
First, let me say that the concept of first-chance exceptions is purely a debugger-related. There is only one exception that happens when we access an invalid address, for example. However, that exception may be handled or may not be handled by exception handlers. Or it might be handled in peculiar way and terminate the thread that caused the exception, for example. And if it was not handled then an unhandled exception filter might be called. The default one might launch a postmortem debugger (or any process that can read process memory) to save a postmortem memory dump. Any thread can replace the default filter with a custom exception filter that might also do peculiar things and quietly terminate or exit. Even the properly configured postmortem debugger can fail to save a dump file. Therefore we have this question: how can we catch the exception and examine the process state as earlier as possible, before the execution flow goes through the exception handling mechanism?

Here we have the concept of the first chance exception dispatched to the attached user-mode debugger. if it wasn’t handled we have the same exception but called the second chance that is dispatched to the same debugger again. We see that it has nothing to do with the postmortem debugger although the attached live debugger can save crash dump files too, which what ADPlus does, for example.
- Dmitry Vostokov @ DumpAnalysis.org -
_1125.png)
Coming Soon:
Crash Dump Analysis for System Administrators
New Magazines:
Debugged! MZ/PE: MagaZine for/from Practicing Engineers
New Books:
Windows Debugging: Practical Foundations
DLL List Landscape: The Art from Computer Memory Space
Dumps, Bugs and Debugging Forensics: The Adventures of Dr. Debugalov
WinDbg: A Reference Poster and Learning Cards
Memory Dump Analysis Anthology, Volume 2
Also available:
Memory Dump Analysis Anthology, Volume 1
New Children's Book:
May 22nd, 2008 at 8:14 pm
who gets it first, the vectored exception handler or the debugger?
May 23rd, 2008 at 5:41 pm
Keep in mind that when monitoring services such as the Print Spooler, a lot of first chance exceptions (that end up being handled) may be thrown and if a debugger is busy dumping the process for each first chance exception performance will be impacted.
May 23rd, 2008 at 11:56 pm
Debugger gets it first then vectored exception handler. Please refer to:
http://msdn.microsoft.com/en-us/library/ms681420.aspx