fix debugger stopping handling

This commit is contained in:
Vadim Lopatin 2015-12-16 16:53:09 +03:00
parent 4fa0173a7e
commit 94ae71b7e8
4 changed files with 27 additions and 9 deletions

View File

@ -298,7 +298,9 @@ abstract class DebuggerBase : Thread, Debugger {
_queue.close(); _queue.close();
} }
bool _threadStarted;
protected void onDebuggerThreadStarted() { protected void onDebuggerThreadStarted() {
_threadStarted = true;
} }
protected void onDebuggerThreadFinished() { protected void onDebuggerThreadFinished() {
@ -317,7 +319,7 @@ abstract class DebuggerBase : Thread, Debugger {
} }
} }
} catch (Exception e) { } catch (Exception e) {
Log.e("Exception in debugger thread"); Log.e("Exception in debugger thread", e);
} }
Log.i("Debugger thread finished"); Log.i("Debugger thread finished");
_finished = true; _finished = true;

View File

@ -82,6 +82,11 @@ class GDBInterface : ConsoleDebuggerInterface {
protected int commandId; protected int commandId;
int sendCommand(string text) { int sendCommand(string text) {
ExternalProcessState state = _debuggerProcess.poll();
if (state != ExternalProcessState.Running) {
_stopRequested = true;
return 0;
}
commandId++; commandId++;
string cmd = to!string(commandId) ~ text; string cmd = to!string(commandId) ~ text;
Log.d("GDB command[", commandId, "]> ", text); Log.d("GDB command[", commandId, "]> ", text);
@ -228,19 +233,29 @@ class GDBInterface : ConsoleDebuggerInterface {
bool _threadJoined = false; bool _threadJoined = false;
override void stop() { override void stop() {
if (_stopRequested) if (_stopRequested) {
Log.w("GDBInterface.stop() - _stopRequested flag already set");
return; return;
}
_stopRequested = true;
Log.d("GDBInterface.stop()"); Log.d("GDBInterface.stop()");
postRequest(delegate() { postRequest(delegate() {
Log.d("GDBInterface.stop() processing in queue");
execStop(); execStop();
}); });
_stopRequested = true; Thread.sleep(dur!"msecs"(200));
postRequest(delegate() { postRequest(delegate() {
}); });
_queue.close(); _queue.close();
if (!_threadJoined) { if (!_threadJoined) {
_threadJoined = true; _threadJoined = true;
join(); if (_threadStarted) {
try {
join();
} catch (Exception e) {
Log.e("Exception while trying to join debugger thread");
}
}
} }
} }

View File

@ -380,6 +380,7 @@ class ExternalProcess {
try { try {
_result = std.process.wait(_pipes.pid); _result = std.process.wait(_pipes.pid);
_state = ExternalProcessState.Stopped; _state = ExternalProcessState.Stopped;
Log.d("ExternalProcess.wait : waitForReadingCompletion");
waitForReadingCompletion(); waitForReadingCompletion();
} catch (Exception e) { } catch (Exception e) {
Log.e("Exception while waiting for process ", _program); Log.e("Exception while waiting for process ", _program);
@ -401,11 +402,10 @@ class ExternalProcess {
} }
bool write(string data) { 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; return false;
} } else {
else { //Log.d("writing ", data.length, " characters to stdin");
Log.d("writing ", data.length, " characters to stdin");
_pipes.stdin.write("", data); _pipes.stdin.write("", data);
_pipes.stdin.flush(); _pipes.stdin.flush();
//_pipes.stdin.close(); //_pipes.stdin.close();

View File

@ -151,7 +151,8 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
} }
void debugFinished(ProgramExecution process, ExecutionStatus status, int exitCode) { void debugFinished(ProgramExecution process, ExecutionStatus status, int exitCode) {
_execution = null; _execution = null;
_debugHandler = null;
switch(status) { switch(status) {
case ExecutionStatus.Error: case ExecutionStatus.Error:
_logPanel.logLine("Cannot run program " ~ process.executableFile); _logPanel.logLine("Cannot run program " ~ process.executableFile);