From 94ae71b7e854f0d1d231c071871adde38e31859d Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Wed, 16 Dec 2015 16:53:09 +0300 Subject: [PATCH] fix debugger stopping handling --- src/ddebug/common/debugger.d | 4 +++- src/ddebug/gdb/gdbinterface.d | 21 ++++++++++++++++++--- src/dlangide/builders/extprocess.d | 8 ++++---- src/dlangide/ui/frame.d | 3 ++- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/ddebug/common/debugger.d b/src/ddebug/common/debugger.d index 99a7f2f..cf6f96f 100644 --- a/src/ddebug/common/debugger.d +++ b/src/ddebug/common/debugger.d @@ -298,7 +298,9 @@ abstract class DebuggerBase : Thread, Debugger { _queue.close(); } + bool _threadStarted; protected void onDebuggerThreadStarted() { + _threadStarted = true; } protected void onDebuggerThreadFinished() { @@ -317,7 +319,7 @@ abstract class DebuggerBase : Thread, Debugger { } } } catch (Exception e) { - Log.e("Exception in debugger thread"); + Log.e("Exception in debugger thread", e); } Log.i("Debugger thread finished"); _finished = true; diff --git a/src/ddebug/gdb/gdbinterface.d b/src/ddebug/gdb/gdbinterface.d index 5bf125d..e981449 100644 --- a/src/ddebug/gdb/gdbinterface.d +++ b/src/ddebug/gdb/gdbinterface.d @@ -82,6 +82,11 @@ class GDBInterface : ConsoleDebuggerInterface { protected int commandId; int sendCommand(string text) { + ExternalProcessState state = _debuggerProcess.poll(); + if (state != ExternalProcessState.Running) { + _stopRequested = true; + return 0; + } commandId++; string cmd = to!string(commandId) ~ text; Log.d("GDB command[", commandId, "]> ", text); @@ -228,19 +233,29 @@ class GDBInterface : ConsoleDebuggerInterface { bool _threadJoined = false; override void stop() { - if (_stopRequested) + if (_stopRequested) { + Log.w("GDBInterface.stop() - _stopRequested flag already set"); return; + } + _stopRequested = true; Log.d("GDBInterface.stop()"); postRequest(delegate() { + Log.d("GDBInterface.stop() processing in queue"); execStop(); }); - _stopRequested = true; + Thread.sleep(dur!"msecs"(200)); postRequest(delegate() { }); _queue.close(); if (!_threadJoined) { _threadJoined = true; - join(); + if (_threadStarted) { + try { + join(); + } catch (Exception e) { + Log.e("Exception while trying to join debugger thread"); + } + } } } diff --git a/src/dlangide/builders/extprocess.d b/src/dlangide/builders/extprocess.d index 3d4fd46..ad2c5be 100644 --- a/src/dlangide/builders/extprocess.d +++ b/src/dlangide/builders/extprocess.d @@ -380,6 +380,7 @@ class ExternalProcess { try { _result = std.process.wait(_pipes.pid); _state = ExternalProcessState.Stopped; + Log.d("ExternalProcess.wait : waitForReadingCompletion"); waitForReadingCompletion(); } catch (Exception e) { Log.e("Exception while waiting for process ", _program); @@ -401,11 +402,10 @@ class ExternalProcess { } bool write(string data) { - if(_state == ExternalProcessState.Error || _state == ExternalProcessState.None || _state == ExternalProcessState.Stopped) { + if (_state == ExternalProcessState.Error || _state == ExternalProcessState.None || _state == ExternalProcessState.Stopped) { return false; - } - else { - Log.d("writing ", data.length, " characters to stdin"); + } else { + //Log.d("writing ", data.length, " characters to stdin"); _pipes.stdin.write("", data); _pipes.stdin.flush(); //_pipes.stdin.close(); diff --git a/src/dlangide/ui/frame.d b/src/dlangide/ui/frame.d index 3e616dd..7115604 100644 --- a/src/dlangide/ui/frame.d +++ b/src/dlangide/ui/frame.d @@ -151,7 +151,8 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL } void debugFinished(ProgramExecution process, ExecutionStatus status, int exitCode) { - _execution = null; + _execution = null; + _debugHandler = null; switch(status) { case ExecutionStatus.Error: _logPanel.logLine("Cannot run program " ~ process.executableFile);