Fix signal handling for debugger

This commit is contained in:
Jeffrey Pfau 2014-01-19 23:42:34 -08:00
parent 4e98546cd6
commit 1f8c1bcdfa
3 changed files with 25 additions and 11 deletions

View File

@ -11,6 +11,10 @@
#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 _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) {

View File

@ -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) {

View File

@ -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);