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. 46
      engine/common/system.c
  2. 1
      engine/common/system.h
  3. 4
      engine/platform/platform.h

46
engine/common/system.c

@ -43,7 +43,6 @@ GNU General Public License for more details.
#include "whereami.h" #include "whereami.h"
qboolean error_on_exit = false; // arg for exit(); qboolean error_on_exit = false; // arg for exit();
#define DEBUG_BREAK
/* /*
================ ================
@ -54,23 +53,28 @@ double GAME_EXPORT Sys_DoubleTime( void )
{ {
return Platform_DoubleTime(); return Platform_DoubleTime();
} }
/*
================
Sys_DebugBreak
================
*/
void Sys_DebugBreak( void )
{
#if XASH_LINUX || ( XASH_WIN32 && !XASH_64BIT ) #if XASH_LINUX || ( XASH_WIN32 && !XASH_64BIT )
#undef DEBUG_BREAK #if XASH_MSVC
qboolean Sys_DebuggerPresent( void ); // see sys_linux.c if( Sys_DebuggerPresent() )
#if XASH_MSVC _asm { int 3 }
#define DEBUG_BREAK \ #elif XASH_X86
if( Sys_DebuggerPresent() ) \ if( Sys_DebuggerPresent() )
_asm{ int 3 } asm volatile( "int $3;" );
#elif XASH_X86 #else
#define DEBUG_BREAK \ if( Sys_DebuggerPresent() )
if( Sys_DebuggerPresent() ) \ raise( SIGINT );
asm volatile("int $3;")
#else
#define DEBUG_BREAK \
if( Sys_DebuggerPresent() ) \
raise( SIGINT )
#endif
#endif #endif
#endif
}
#if !XASH_DEDICATED #if !XASH_DEDICATED
/* /*
================ ================
@ -377,12 +381,14 @@ void Sys_Warn( const char *format, ... )
va_list argptr; va_list argptr;
char text[MAX_PRINT_MSG]; char text[MAX_PRINT_MSG];
DEBUG_BREAK;
va_start( argptr, format ); va_start( argptr, format );
Q_vsnprintf( text, MAX_PRINT_MSG, format, argptr ); Q_vsnprintf( text, MAX_PRINT_MSG, format, argptr );
va_end( argptr ); va_end( argptr );
Sys_DebugBreak();
Msg( "Sys_Warn: %s\n", text ); Msg( "Sys_Warn: %s\n", text );
if( !Host_IsDedicated() ) // dedicated server should not hang on messagebox if( !Host_IsDedicated() ) // dedicated server should not hang on messagebox
MSGBOX(text); MSGBOX(text);
} }
@ -404,8 +410,6 @@ void Sys_Error( const char *error, ... )
if( !Host_IsDedicated( )) if( !Host_IsDedicated( ))
Platform_SetCursorType( dc_arrow ); Platform_SetCursorType( dc_arrow );
DEBUG_BREAK;
if( host.status == HOST_ERR_FATAL ) if( host.status == HOST_ERR_FATAL )
return; // don't multiple executes return; // don't multiple executes
@ -418,6 +422,8 @@ void Sys_Error( const char *error, ... )
Q_vsnprintf( text, MAX_PRINT_MSG, error, argptr ); Q_vsnprintf( text, MAX_PRINT_MSG, error, argptr );
va_end( argptr ); va_end( argptr );
Sys_DebugBreak();
SV_SysError( text ); SV_SysError( text );
if( !Host_IsDedicated() ) if( !Host_IsDedicated() )

1
engine/common/system.h

@ -59,6 +59,7 @@ void Sys_ParseCommandLine( int argc, char **argv );
void Sys_MergeCommandLine( void ); void Sys_MergeCommandLine( void );
void Sys_SetupCrashHandler( void ); void Sys_SetupCrashHandler( void );
void Sys_RestoreCrashHandler( void ); void Sys_RestoreCrashHandler( void );
void Sys_DebugBreak( void );
#define Sys_GetParmFromCmdLine( parm, out ) _Sys_GetParmFromCmdLine( parm, out, sizeof( out )) #define Sys_GetParmFromCmdLine( parm, out ) _Sys_GetParmFromCmdLine( parm, out, sizeof( out ))
qboolean _Sys_GetParmFromCmdLine( const char *parm, char *out, size_t size ); qboolean _Sys_GetParmFromCmdLine( const char *parm, char *out, size_t size );
qboolean Sys_GetIntFromCmdLine( const char *parm, int *out ); qboolean Sys_GetIntFromCmdLine( const char *parm, int *out );

4
engine/platform/platform.h

@ -37,9 +37,7 @@ double Platform_DoubleTime( void );
void Platform_Sleep( int msec ); void Platform_Sleep( int msec );
void Platform_ShellExecute( const char *path, const char *parms ); void Platform_ShellExecute( const char *path, const char *parms );
void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow ); 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 qboolean Sys_DebuggerPresent( void ); // optional, see Sys_DebugBreak
// see system.c
// qboolean Sys_DebuggerPresent( void );
#if XASH_ANDROID #if XASH_ANDROID
const char *Android_GetAndroidID( void ); const char *Android_GetAndroidID( void );

Loading…
Cancel
Save