From 26e805fe1d2da7ae70b4ff3435b405593116293e Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Mon, 16 Nov 2015 16:54:32 +0300 Subject: [PATCH] gdb support --- src/ddebug/gdb/gdbinterface.d | 16 ++++++++++++++++ src/dlangide/builders/extprocess.d | 8 +++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/ddebug/gdb/gdbinterface.d b/src/ddebug/gdb/gdbinterface.d index 76ea636..91fb190 100644 --- a/src/ddebug/gdb/gdbinterface.d +++ b/src/ddebug/gdb/gdbinterface.d @@ -5,6 +5,7 @@ import dlangui.core.logger; import ddebug.common.queue; import dlangide.builders.extprocess; import std.utf; +import std.conv : to; class ConsoleDebuggerInterface : DebuggerBase, TextWriter { protected ExternalProcess _debuggerProcess; @@ -51,6 +52,10 @@ class ConsoleDebuggerInterface : DebuggerBase, TextWriter { } } + bool sendLine(string text) { + return _debuggerProcess.write(text ~ "\n"); + } + /// log lines override void writeText(dstring text) { string text8 = toUTF8(text); @@ -63,6 +68,15 @@ class ConsoleDebuggerInterface : DebuggerBase, TextWriter { class GDBInterface : ConsoleDebuggerInterface { + protected int commandId; + + + int sendCommand(string text) { + commandId++; + sendLine(to!string(commandId) ~ text); + return commandId; + } + override void startDebugging(string debuggerExecutable, string executable, string[] args, string workingDir, DebuggerResponse response) { string[] debuggerArgs; debuggerArgs ~= "--interpreter=mi"; @@ -75,6 +89,8 @@ class GDBInterface : ConsoleDebuggerInterface { Log.i("Debugger process state:"); if (state == ExternalProcessState.Running) { response(ResponseCode.Ok, "Started"); + sendCommand("-break-insert main"); + sendCommand("-exec-run"); } else { response(ResponseCode.CannotRunDebugger, "Error while trying to run debugger process"); } diff --git a/src/dlangide/builders/extprocess.d b/src/dlangide/builders/extprocess.d index 9d782e9..3d4fd46 100644 --- a/src/dlangide/builders/extprocess.d +++ b/src/dlangide/builders/extprocess.d @@ -400,14 +400,16 @@ class ExternalProcess { return _state; } - void write(string data) { + bool write(string data) { if(_state == ExternalProcessState.Error || _state == ExternalProcessState.None || _state == ExternalProcessState.Stopped) { - return; + return false; } else { Log.d("writing ", data.length, " characters to stdin"); _pipes.stdin.write("", data); - _pipes.stdin.close(); + _pipes.stdin.flush(); + //_pipes.stdin.close(); + return true; } } }