debugger support under linux

This commit is contained in:
Vadim Lopatin 2015-12-11 18:07:51 +03:00
parent b92f297dc0
commit 3b94eda9c1
2 changed files with 44 additions and 21 deletions

View File

@ -146,8 +146,8 @@ class DebuggerProxy : Debugger, DebuggerCallback {
} }
abstract class DebuggerBase : Thread, Debugger { abstract class DebuggerBase : Thread, Debugger {
private bool _runRequested; protected bool _runRequested;
private bool _stopRequested; protected bool _stopRequested;
private bool _finished; private bool _finished;
protected BlockingQueue!Runnable _queue; protected BlockingQueue!Runnable _queue;

View File

@ -92,7 +92,7 @@ class GDBInterface : ConsoleDebuggerInterface {
string terminalTty; string terminalTty;
string startTerminal() { string startTerminal() {
Log.d("Starting terminal"); Log.d("Starting terminal ", _terminalExecutable);
import std.random; import std.random;
import std.file; import std.file;
import std.path; import std.path;
@ -103,20 +103,22 @@ class GDBInterface : ConsoleDebuggerInterface {
string termfile = buildPath(tempDir, format("dlangide-term-name-%07x.tmp", n)); string termfile = buildPath(tempDir, format("dlangide-term-name-%07x.tmp", n));
Log.d("temp file for tty name: ", termfile); Log.d("temp file for tty name: ", termfile);
try { try {
terminalPid = spawnProcess([ string[] args = [
_terminalExecutable, _terminalExecutable,
"-title", "-title",
"DLangIDE External Console", "DLangIDE External Console",
"-e", "-e",
"echo 'DlangIDE External Console' && tty > " ~ termfile ~ " && sleep 1000000" "echo 'DlangIDE External Console' && tty > " ~ termfile ~ " && sleep 1000000"
]); ];
for (int i = 0; i < 20; i++) { Log.d("Terminal command line: ", args);
terminalPid = spawnProcess(args);
for (int i = 0; i < 40; i++) {
Thread.sleep(dur!"msecs"(100)); Thread.sleep(dur!"msecs"(100));
if (!isTerminalActive) { if (!isTerminalActive) {
Log.e("Failed to get terminal TTY"); Log.e("Failed to get terminal TTY");
return null; return null;
} }
if (!exists(termfile)) { if (exists(termfile)) {
Thread.sleep(dur!"msecs"(20)); Thread.sleep(dur!"msecs"(20));
break; break;
} }
@ -128,6 +130,7 @@ class GDBInterface : ConsoleDebuggerInterface {
terminalTty = terminalTty[0 .. $-1]; terminalTty = terminalTty[0 .. $-1];
// delete file // delete file
remove(termfile); remove(termfile);
Log.d("Terminal tty: ", terminalTty);
} }
} catch (Exception e) { } catch (Exception e) {
Log.e("Failed to start terminal ", e); Log.e("Failed to start terminal ", e);
@ -182,10 +185,10 @@ class GDBInterface : ConsoleDebuggerInterface {
if (!_terminalExecutable.empty) { if (!_terminalExecutable.empty) {
terminalTty = startTerminal(); terminalTty = startTerminal();
if (terminalTty.length == 0) { if (terminalTty.length == 0) {
_callback.onResponse(ResponseCode.CannotRunDebugger, "Cannot start terminal"); //_callback.onResponse(ResponseCode.CannotRunDebugger, "Cannot start terminal");
_status = ExecutionStatus.Error; _status = ExecutionStatus.Error;
_callback.onProgramExecutionStatus(this, _status, _exitCode); _stopRequested = true;
return; return;
} }
debuggerArgs ~= "-tty"; debuggerArgs ~= "-tty";
debuggerArgs ~= terminalTty; debuggerArgs ~= terminalTty;
@ -203,17 +206,37 @@ class GDBInterface : ConsoleDebuggerInterface {
//sendCommand("-break-insert main"); //sendCommand("-break-insert main");
} else { } else {
_status = ExecutionStatus.Error; _status = ExecutionStatus.Error;
_callback.onProgramExecutionStatus(this, _status, _exitCode); _stopRequested = true;
return; return;
} }
} }
override protected void onDebuggerThreadFinished() {
Log.d("Debugger thread finished");
if (_debuggerProcess !is null) {
Log.d("Killing debugger process");
_debuggerProcess.kill();
Log.d("Waiting for debugger process finishing");
//_debuggerProcess.wait();
}
killTerminal();
Log.d("Sending execution status");
_callback.onProgramExecutionStatus(this, _status, _exitCode);
}
bool _threadJoined = false;
override void stop() { override void stop() {
Log.d("GDBInterface.run()"); if (_stopRequested)
if (_debuggerProcess !is null) return;
_debuggerProcess.kill(); Log.d("GDBInterface.stop()");
killTerminal(); _stopRequested = true;
super.stop(); postRequest(delegate() {
});
_queue.close();
if (!_threadJoined) {
_threadJoined = true;
join();
}
} }
/// start program execution, can be called after program is loaded /// start program execution, can be called after program is loaded