mirror of https://github.com/mgba-emu/mgba.git
Fix signal handling for debugger
This commit is contained in:
parent
4e98546cd6
commit
1f8c1bcdfa
|
@ -11,6 +11,10 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#ifdef USE_PTHREADS
|
||||||
|
#include <pthread.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
struct DebugVector {
|
struct DebugVector {
|
||||||
struct DebugVector* next;
|
struct DebugVector* next;
|
||||||
enum DVType {
|
enum DVType {
|
||||||
|
@ -92,9 +96,18 @@ static void _handleDeath(int sig) {
|
||||||
static void _breakInto(struct ARMDebugger* debugger, struct DebugVector* dv) {
|
static void _breakInto(struct ARMDebugger* debugger, struct DebugVector* dv) {
|
||||||
(void)(debugger);
|
(void)(debugger);
|
||||||
(void)(dv);
|
(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);
|
kill(getpid(), SIGTRAP);
|
||||||
signal(SIGTRAP, oldSignal);
|
#endif
|
||||||
|
sigaction(SIGTRAP, &osa, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _continue(struct ARMDebugger* debugger, struct DebugVector* dv) {
|
static void _continue(struct ARMDebugger* debugger, struct DebugVector* dv) {
|
||||||
|
|
|
@ -53,7 +53,8 @@ static THREAD_ENTRY _GBAThreadRun(void* context) {
|
||||||
#if !defined(_WIN32) && defined(USE_PTHREADS)
|
#if !defined(_WIN32) && defined(USE_PTHREADS)
|
||||||
sigset_t signals;
|
sigset_t signals;
|
||||||
sigfillset(&signals);
|
sigfillset(&signals);
|
||||||
pthread_sigmask(SIG_UNBLOCK, &signals, 0);
|
sigdelset(&signals, SIGTRAP);
|
||||||
|
pthread_sigmask(SIG_SETMASK, &signals, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GBAInit(&gba);
|
GBAInit(&gba);
|
||||||
|
@ -166,6 +167,14 @@ int GBAThreadStart(struct GBAThread* threadContext) {
|
||||||
MutexInit(&threadContext->sync.audioBufferMutex);
|
MutexInit(&threadContext->sync.audioBufferMutex);
|
||||||
ConditionInit(&threadContext->sync.audioRequiredCond);
|
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);
|
MutexLock(&threadContext->stateMutex);
|
||||||
ThreadCreate(&threadContext->thread, _GBAThreadRun, threadContext);
|
ThreadCreate(&threadContext->thread, _GBAThreadRun, threadContext);
|
||||||
while (threadContext->state < THREAD_RUNNING) {
|
while (threadContext->state < THREAD_RUNNING) {
|
||||||
|
|
|
@ -56,14 +56,6 @@ int main(int argc, char** argv) {
|
||||||
return 1;
|
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 GBAThread context;
|
||||||
struct GLSoftwareRenderer renderer;
|
struct GLSoftwareRenderer renderer;
|
||||||
GBAVideoSoftwareRendererCreate(&renderer.d);
|
GBAVideoSoftwareRendererCreate(&renderer.d);
|
||||||
|
|
Loading…
Reference in New Issue