1
0
forked from 0ad/0ad

hooked up exception handler; a bit of cleanup

This was SVN commit r727.
This commit is contained in:
janwas 2004-07-12 16:38:48 +00:00
parent abff8d12c4
commit af58165890
2 changed files with 37 additions and 27 deletions

View File

@ -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()

View File

@ -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__