From 0a49e6981831e581be5c6fbfa044a8ce02842edc Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 19 Oct 2022 02:25:48 +0300 Subject: [PATCH] engine: introduce Sys_DebugBreak function to raise an exception for debugger --- engine/common/system.c | 46 +++++++++++++++++++++----------------- engine/common/system.h | 1 + engine/platform/platform.h | 4 +--- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/engine/common/system.c b/engine/common/system.c index ed7493a4..72ae9197 100644 --- a/engine/common/system.c +++ b/engine/common/system.c @@ -43,7 +43,6 @@ GNU General Public License for more details. #include "whereami.h" qboolean error_on_exit = false; // arg for exit(); -#define DEBUG_BREAK /* ================ @@ -54,23 +53,28 @@ double GAME_EXPORT Sys_DoubleTime( void ) { return Platform_DoubleTime(); } + +/* +================ +Sys_DebugBreak +================ +*/ +void Sys_DebugBreak( void ) +{ #if XASH_LINUX || ( XASH_WIN32 && !XASH_64BIT ) - #undef DEBUG_BREAK - qboolean Sys_DebuggerPresent( void ); // see sys_linux.c - #if XASH_MSVC - #define DEBUG_BREAK \ - if( Sys_DebuggerPresent() ) \ - _asm{ int 3 } - #elif XASH_X86 - #define DEBUG_BREAK \ - if( Sys_DebuggerPresent() ) \ - asm volatile("int $3;") - #else - #define DEBUG_BREAK \ - if( Sys_DebuggerPresent() ) \ - raise( SIGINT ) - #endif +#if XASH_MSVC + if( Sys_DebuggerPresent() ) + _asm { int 3 } +#elif XASH_X86 + if( Sys_DebuggerPresent() ) + asm volatile( "int $3;" ); +#else + if( Sys_DebuggerPresent() ) + raise( SIGINT ); #endif +#endif +} + #if !XASH_DEDICATED /* ================ @@ -377,12 +381,14 @@ void Sys_Warn( const char *format, ... ) va_list argptr; char text[MAX_PRINT_MSG]; - DEBUG_BREAK; - va_start( argptr, format ); Q_vsnprintf( text, MAX_PRINT_MSG, format, argptr ); va_end( argptr ); + + Sys_DebugBreak(); + Msg( "Sys_Warn: %s\n", text ); + if( !Host_IsDedicated() ) // dedicated server should not hang on messagebox MSGBOX(text); } @@ -404,8 +410,6 @@ void Sys_Error( const char *error, ... ) if( !Host_IsDedicated( )) Platform_SetCursorType( dc_arrow ); - DEBUG_BREAK; - if( host.status == HOST_ERR_FATAL ) return; // don't multiple executes @@ -418,6 +422,8 @@ void Sys_Error( const char *error, ... ) Q_vsnprintf( text, MAX_PRINT_MSG, error, argptr ); va_end( argptr ); + Sys_DebugBreak(); + SV_SysError( text ); if( !Host_IsDedicated() ) diff --git a/engine/common/system.h b/engine/common/system.h index c6d8956d..adf34f3d 100644 --- a/engine/common/system.h +++ b/engine/common/system.h @@ -59,6 +59,7 @@ void Sys_ParseCommandLine( int argc, char **argv ); void Sys_MergeCommandLine( void ); void Sys_SetupCrashHandler( void ); void Sys_RestoreCrashHandler( void ); +void Sys_DebugBreak( void ); #define Sys_GetParmFromCmdLine( parm, out ) _Sys_GetParmFromCmdLine( parm, out, sizeof( out )) qboolean _Sys_GetParmFromCmdLine( const char *parm, char *out, size_t size ); qboolean Sys_GetIntFromCmdLine( const char *parm, int *out ); diff --git a/engine/platform/platform.h b/engine/platform/platform.h index ead5bc6f..0aaee2b5 100644 --- a/engine/platform/platform.h +++ b/engine/platform/platform.h @@ -37,9 +37,7 @@ double Platform_DoubleTime( void ); void Platform_Sleep( int msec ); void Platform_ShellExecute( const char *path, const char *parms ); void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow ); -// commented out, as this is an optional feature or maybe implemented in system API directly -// see system.c -// qboolean Sys_DebuggerPresent( void ); +qboolean Sys_DebuggerPresent( void ); // optional, see Sys_DebugBreak #if XASH_ANDROID const char *Android_GetAndroidID( void );