Browse Source

engine: introduce Sys_DebugBreak function to raise an exception for debugger

pull/2/head
Alibek Omarov 2 years ago
parent
commit
0a49e69818
  1. 36
      engine/common/system.c
  2. 1
      engine/common/system.h
  3. 4
      engine/platform/platform.h

36
engine/common/system.c

@ -43,7 +43,6 @@ GNU General Public License for more details. @@ -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 ) @@ -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() ) \
if( Sys_DebuggerPresent() )
_asm { int 3 }
#elif XASH_X86
#define DEBUG_BREAK \
if( Sys_DebuggerPresent() ) \
asm volatile("int $3;")
if( Sys_DebuggerPresent() )
asm volatile( "int $3;" );
#else
#define DEBUG_BREAK \
if( Sys_DebuggerPresent() ) \
raise( SIGINT )
if( Sys_DebuggerPresent() )
raise( SIGINT );
#endif
#endif
}
#if !XASH_DEDICATED
/*
================
@ -377,12 +381,14 @@ void Sys_Warn( const char *format, ... ) @@ -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, ... ) @@ -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, ... ) @@ -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() )

1
engine/common/system.h

@ -59,6 +59,7 @@ void Sys_ParseCommandLine( int argc, char **argv ); @@ -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 );

4
engine/platform/platform.h

@ -37,9 +37,7 @@ double Platform_DoubleTime( void ); @@ -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 );

Loading…
Cancel
Save