Debugger main loop
I'm trying to implement in c++/Windows the "Debugger Main Loop" described in this article: Writing the Debugger's Main Loop
But I want any thrown exception to display an error message to the secreen and be caught by the debugger.
I understood that I can do this by开发者_高级运维 giving ContinueDebugEvent
some value of DBG_??? but I don't know what it is.
I also noticed that console applications notify the debugger of exceptions when something is written to the console. How can I filter actual exception from those things? Does it have anything to do with the "first chance" value?
thanks :)The debugger receives an exception event for every exception that occurs in the debuggee.
If you pass DBG_CONTINUE
to ContinueDebugEvent
, the debugger swallows the exception and execution continues as if no exception happened in the first place. That means that the debuggee is not notified of it either.
If on the other hand you pass DBG_EXCEPTION_NOT_HANDLED
the debuggee is notified and responsible for handling the exception.
Now, if the debuggee does not handle (read: catch) the exception, the debugger gets notified a second time, this time with Event.u.Exception.dwFirstChance
set to 0. At this point the exception would terminate the process if you pass DBG_EXCEPTION_NOT_HANDLED
.
Two things to keep in mind:
- The normal way to communicate a string to the debugger is
OutputDebugString
. No need to use self-defined exceptions unless you need to pass something other than a string. - If you do plan on throwing your own exception to communicate certain events to the debugger, check the
Event.u.Exception.ExceptionRecord.ExceptionCode
and see if it matches your predefined exception type and useDBG_CONTINUE
in that case.
精彩评论