all repos — mgba @ 1f8c1bcdfa8a8fc8b2094870208d8b445627ea1e

mGBA Game Boy Advance Emulator

Fix signal handling for debugger
Jeffrey Pfau jeffrey@endrift.com
Sun, 19 Jan 2014 23:42:34 -0800
commit

1f8c1bcdfa8a8fc8b2094870208d8b445627ea1e

parent

4e98546cd655405a88fc8670ba0a37d21455b8fc

3 files changed, 25 insertions(+), 11 deletions(-)

jump to
M src/debugger/debugger.csrc/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.csrc/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.csrc/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);