From b85459eaeca4021b7293a41effcff047a9c5681e Mon Sep 17 00:00:00 2001 From: Yannik Marchand Date: Tue, 25 Sep 2018 09:31:19 +0200 Subject: [PATCH] Fix bug that made debugger thread hang after reconnecting twice --- main.py | 13 ++++++++----- src/debugger.cpp | 7 ++++++- src/debugger.h | 2 ++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 5aeacd1..6407610 100644 --- a/main.py +++ b/main.py @@ -141,7 +141,6 @@ class Debugger: self.s.settimeout(4) self.s.connect((host, 1560)) self.connected = True - self.closeRequest = False events.Connected.emit() def handleClose(self): @@ -272,12 +271,16 @@ class Debugger: self.sendall(bytes([byte])) def sendall(self, data): - try: - self.s.sendall(data) - except socket.error: - self.handleClose() + if self.connected: + try: + self.s.sendall(data) + except socket.error: + self.handleClose() def recvall(self, num): + if not self.connected: + return bytes(num) + try: data = b"" while len(data) < num: diff --git a/src/debugger.cpp b/src/debugger.cpp index 1519aea..d124810 100644 --- a/src/debugger.cpp +++ b/src/debugger.cpp @@ -306,7 +306,9 @@ void ExceptionMgr::cleanup() { for (int i = 0; i < list.size(); i++) { ExceptionState *state = list[i]; - OSSendMessage(&state->queue, &message, OS_MESSAGE_FLAGS_BLOCKING); + if (state->isPaused) { + OSSendMessage(&state->queue, &message, OS_MESSAGE_FLAGS_NONE); + } } unlock(); @@ -331,6 +333,7 @@ ExceptionState *ExceptionMgr::findOrCreate(OSThread *thread) { if (!state) { state = new ExceptionState(); state->thread = thread; + state->isPaused = false; OSInitMessageQueue(&state->queue, &state->message, 1); list.push_back(state); } @@ -512,7 +515,9 @@ Debugger::StepCommand Debugger::notifyBreak(ExceptionState *state) { message.args[2] = (uint32_t)state->thread; OSSendMessage(&eventQueue, &message, OS_MESSAGE_FLAGS_BLOCKING); + state->isPaused = true; OSReceiveMessage(&state->queue, &message, OS_MESSAGE_FLAGS_BLOCKING); + state->isPaused = false; return (StepCommand)message.message; } diff --git a/src/debugger.h b/src/debugger.h index ca0a4a2..7ba629d 100644 --- a/src/debugger.h +++ b/src/debugger.h @@ -48,6 +48,8 @@ public: OSMessageQueue queue; OSMessage message; + + bool isPaused; };