From 1f8c1bcdfa8a8fc8b2094870208d8b445627ea1e Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 19 Jan 2014 23:42:34 -0800 Subject: [PATCH] Fix signal handling for debugger --- src/debugger/debugger.c | 17 +++++++++++++++-- src/gba/gba-thread.c | 11 ++++++++++- src/platform/sdl/gl-main.c | 8 -------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/debugger/debugger.c b/src/debugger/debugger.c index 0821713ae..298d6072d 100644 --- a/src/debugger/debugger.c +++ b/src/debugger/debugger.c @@ -11,6 +11,10 @@ #include #include +#ifdef USE_PTHREADS +#include +#endif + struct DebugVector { struct DebugVector* next; enum DVType { @@ -92,9 +96,18 @@ static void _handleDeath(int sig) { 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) { diff --git a/src/gba/gba-thread.c b/src/gba/gba-thread.c index b15a9d7fc..7937d51b6 100644 --- a/src/gba/gba-thread.c +++ b/src/gba/gba-thread.c @@ -53,7 +53,8 @@ static THREAD_ENTRY _GBAThreadRun(void* context) { #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); @@ -166,6 +167,14 @@ int GBAThreadStart(struct GBAThread* threadContext) { 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); while (threadContext->state < THREAD_RUNNING) { diff --git a/src/platform/sdl/gl-main.c b/src/platform/sdl/gl-main.c index 21d73907c..b397555b6 100644 --- a/src/platform/sdl/gl-main.c +++ b/src/platform/sdl/gl-main.c @@ -56,14 +56,6 @@ int main(int argc, char** argv) { 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);