Fix signal handling for debugger
Jeffrey Pfau jeffrey@endrift.com
Sun, 19 Jan 2014 23:42:34 -0800
3 files changed,
25 insertions(+),
11 deletions(-)
M
src/debugger/debugger.c
→
src/debugger/debugger.c
@@ -11,6 +11,10 @@ #include <stdlib.h>
#include <string.h> #include <unistd.h> +#ifdef USE_PTHREADS +#include <pthread.h> +#endif + struct DebugVector { struct DebugVector* next; enum DVType {@@ -92,9 +96,18 @@
static void _breakInto(struct ARMDebugger* debugger, struct DebugVector* dv) { (void)(debugger); (void)(dv); - sig_t oldSignal = signal(SIGTRAP, _handleDeath); + struct sigaction sa, osa; + sa.sa_handler = _handleDeath; + sigemptyset(&sa.sa_mask); + sigaddset(&sa.sa_mask, SIGTRAP); + sa.sa_flags = SA_RESTART; + sigaction(SIGTRAP, &sa, &osa); +#ifdef USE_PTHREADS + pthread_kill(pthread_self(), SIGTRAP); +#else kill(getpid(), SIGTRAP); - signal(SIGTRAP, oldSignal); +#endif + sigaction(SIGTRAP, &osa, 0); } static void _continue(struct ARMDebugger* debugger, struct DebugVector* dv) {
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -53,7 +53,8 @@
#if !defined(_WIN32) && defined(USE_PTHREADS) sigset_t signals; sigfillset(&signals); - pthread_sigmask(SIG_UNBLOCK, &signals, 0); + sigdelset(&signals, SIGTRAP); + pthread_sigmask(SIG_SETMASK, &signals, 0); #endif GBAInit(&gba);@@ -165,6 +166,14 @@ ConditionInit(&threadContext->sync.videoFrameAvailableCond);
ConditionInit(&threadContext->sync.videoFrameRequiredCond); MutexInit(&threadContext->sync.audioBufferMutex); ConditionInit(&threadContext->sync.audioRequiredCond); + +#ifndef _WIN32 + sigset_t signals; + sigemptyset(&signals); + sigaddset(&signals, SIGINT); + sigaddset(&signals, SIGTRAP); + pthread_sigmask(SIG_BLOCK, &signals, 0); +#endif MutexLock(&threadContext->stateMutex); ThreadCreate(&threadContext->thread, _GBAThreadRun, threadContext);
M
src/platform/sdl/gl-main.c
→
src/platform/sdl/gl-main.c
@@ -56,14 +56,6 @@ if (fd < 0) {
return 1; } -#ifndef _WIN32 - sigset_t signals; - sigemptyset(&signals); - sigaddset(&signals, SIGINT); - sigaddset(&signals, SIGTRAP); - pthread_sigmask(SIG_BLOCK, &signals, 0); -#endif - struct GBAThread context; struct GLSoftwareRenderer renderer; GBAVideoSoftwareRendererCreate(&renderer.d);