Add an option to trap device errors in a debugger

This commit is contained in:
Chris Robinson
2011-09-10 01:23:59 -07:00
parent 724ad0d893
commit 23d693cd06
2 changed files with 33 additions and 0 deletions
+25
View File
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <memory.h>
#include <ctype.h>
#include <signal.h>
#include "alMain.h"
#include "alSource.h"
@@ -399,6 +400,9 @@ ALdouble ConeScale = 0.5;
// Localized Z scalar for mono sources
ALdouble ZScale = 1.0;
/* Flag to trap ALC device errors */
static ALCboolean TrapALCError = ALC_FALSE;
/* One-time configuration init control */
static pthread_once_t alc_config_once = PTHREAD_ONCE_INIT;
@@ -503,6 +507,10 @@ static void alc_init(void)
if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
TrapALError = AL_TRUE;
str = getenv("__ALSOFT_TRAP_ALC_ERROR");
if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
TrapALCError = ALC_TRUE;
pthread_key_create(&LocalContext, ReleaseThreadCtx);
InitializeCriticalSection(&ListLock);
ThunkInit();
@@ -574,6 +582,9 @@ static void alc_initconfig(void)
if(DefaultResampler >= RESAMPLER_MAX || DefaultResampler <= RESAMPLER_MIN)
DefaultResampler = RESAMPLER_DEFAULT;
if(!TrapALCError)
TrapALCError = GetConfigValueBool(NULL, "trap-alc-error", ALC_FALSE);
if(!TrapALError)
TrapALError = GetConfigValueBool(NULL, "trap-al-error", AL_FALSE);
@@ -1050,6 +1061,20 @@ static ALCboolean IsContext(ALCcontext *context)
*/
ALCvoid alcSetError(ALCdevice *device, ALenum errorCode)
{
if(TrapALCError)
{
#ifdef _WIN32
/* Safely catch a breakpoint exception that wasn't caught by a debugger */
__try {
DebugBreak();
} __except((GetExceptionCode()==EXCEPTION_BREAKPOINT) ?
EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
}
#elif defined(SIGTRAP)
kill(getpid(), SIGTRAP);
#endif
}
LockLists();
if(IsDevice(device))
device->LastError = errorCode;
+8
View File
@@ -150,6 +150,14 @@
#layout_61CHN = fl=-30, fr=30, fc=0, sl=-90, sr=90, bc=180
#layout_71CHN = fl=-30, fr=30, fc=0, sl=-90, sr=90, bl=-150, br=150
## trap-alc-error:
# Generates a SIGTRAP signal when an ALC device error is generated, on systems
# that support it. This helps when debugging, while trying to find the cause
# of a device error. On Windows, a breakpoint exception is generated.
# Optionally, the __ALSOFT_TRAP_ALC_ERROR env var may be set before running
# the app instead.
#trap-alc-error = false
## trap-al-error:
# Generates a SIGTRAP signal when an AL context error is generated, on systems
# that support it. This helps when debugging, while trying to find the cause