X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=os_win32.cpp;h=587503c41553fa7cd013cf5ad28862fa34f938a7;hb=c592957de1083b4e32ee58c0ea2e5feaa9085b47;hp=6cddc552681db55863e1eaf01f1f1baac070c2ed;hpb=dbaae4936e6b647dd0157e5e6b37e668e1fad983;p=apitrace diff --git a/os_win32.cpp b/os_win32.cpp index 6cddc55..587503c 100644 --- a/os_win32.cpp +++ b/os_win32.cpp @@ -24,6 +24,8 @@ **************************************************************************/ #include +#include +#include #include #include @@ -99,11 +101,18 @@ DebugMessage(const char *format, ...) va_end(ap); OutputDebugStringA(buf); + + /* + * Also write the message to stderr, when a debugger is not present (to + * avoid duplicate messages in command line debuggers). + */ +#if _WIN32_WINNT > 0x0400 if (!IsDebuggerPresent()) { fflush(stdout); fputs(buf, stderr); fflush(stderr); } +#endif } long long GetTime(void) @@ -126,4 +135,41 @@ Abort(void) #endif } + +static LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter = NULL; +static void (*gCallback)(void) = NULL; + +static LONG WINAPI UnhandledExceptionFilter(PEXCEPTION_POINTERS pExceptionInfo) +{ + if (gCallback) { + gCallback(); + } + + if (prevExceptionFilter) { + return prevExceptionFilter(pExceptionInfo); + } else { + return EXCEPTION_CONTINUE_SEARCH; + } +} + +void +SetExceptionCallback(void (*callback)(void)) +{ + assert(!gCallback); + + if (!gCallback) { + gCallback = callback; + + assert(!prevExceptionFilter); + prevExceptionFilter = SetUnhandledExceptionFilter(UnhandledExceptionFilter); + } +} + +void +ResetExceptionCallback(void) +{ + gCallback = NULL; +} + + } /* namespace OS */