From af581658904985568b406a97f266da93e2f4e829 Mon Sep 17 00:00:00 2001 From: janwas Date: Mon, 12 Jul 2004 16:38:48 +0000 Subject: [PATCH] hooked up exception handler; a bit of cleanup This was SVN commit r727. --- source/lib/sysdep/win/wdbg.cpp | 30 ++++++++++++++++++++++-------- source/lib/sysdep/win/wdbg.h | 34 +++++++++++++++------------------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/source/lib/sysdep/win/wdbg.cpp b/source/lib/sysdep/win/wdbg.cpp index e274ef68d9..52a6194c1f 100755 --- a/source/lib/sysdep/win/wdbg.cpp +++ b/source/lib/sysdep/win/wdbg.cpp @@ -533,13 +533,6 @@ static int dialog(DLG_TYPE type) static PTOP_LEVEL_EXCEPTION_FILTER prev_except_filter; -static long CALLBACK except_filter(EXCEPTION_POINTERS* except); - - -void dbg_init_except_handler() -{ - prev_except_filter = SetUnhandledExceptionFilter(except_filter); -} static long CALLBACK except_filter(EXCEPTION_POINTERS* except) @@ -602,7 +595,14 @@ static long CALLBACK except_filter(EXCEPTION_POINTERS* except) } -int show_assert_dlg(char* file, int line, char* expr) +static void set_exception_handler() +{ + prev_except_filter = SetUnhandledExceptionFilter(except_filter); +} + + + +int wdbg_show_assert_dlg(char* file, int line, char* expr) { ONCE(dbg_init()); @@ -611,3 +611,17 @@ int show_assert_dlg(char* file, int line, char* expr) return dialog(ASSERT); } + + +// main.cpp will have an exception handler, but this covers low-level init +// (before main is called) +static int wdbg_init() +{ + set_exception_handler(); + return 0; +} + + +#pragma data_seg(".LIB$WIB") // first +WIN_REGISTER_FUNC(wdbg_init); +#pragma data_seg() diff --git a/source/lib/sysdep/win/wdbg.h b/source/lib/sysdep/win/wdbg.h index ac0027f0aa..b07744fa20 100755 --- a/source/lib/sysdep/win/wdbg.h +++ b/source/lib/sysdep/win/wdbg.h @@ -1,43 +1,39 @@ -#ifndef __DEBUG_H__ -#define __DEBUG_H__ +#ifndef WDBG_H__ +#define WDBG_H__ + +#include "win.h" #ifdef __cplusplus extern "C" { #endif -/* - * exception handler and assert with stack trace - * (including variable / parameter types and values) - * shown in a dialog, which offers - * continue, break, suppress (ignore this assert), and exit - */ +// assert with stack trace (including variable / parameter types and values) +// shown in a dialog, which offers +// continue, break, suppress (ignore this assert), and exit -/* register exception handler */ -extern void dbg_init_except_handler(); - -/* recommended use: assert2(expr && "descriptive string") */ +// recommended use: assert2(expr && "descriptive string") #define assert2(expr)\ {\ - static int suppress;\ - if(!suppress && !expr)\ - switch(show_assert_dlg(__FILE__, __LINE__, #expr))\ + static int suppress__;\ + if(!suppress__ && !expr)\ + switch(wdbg_show_assert_dlg(__FILE__, __LINE__, #expr))\ {\ case 1:\ - suppress = 1;\ + suppress__ = 1;\ break;\ \ case 2:\ - __asm { int 3 } /* x86 specific; Win alternative: DebugBreak */\ + win_debug_break();\ break;\ }\ } -extern int show_assert_dlg(char* file, int line, char* expr); +extern int wdbg_show_assert_dlg(char* file, int line, char* expr); #ifdef __cplusplus } #endif -#endif // #ifndef __DEBUG_H__ +#endif // #ifndef WDBG_H__