Cosmos/source2/Debug/Cosmos.Debug.GDB/GDB.cs
kudzu_cp 7951702138
2010-07-12 15:02:13 +00:00

82 lines
3 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;
namespace Cosmos.Debug.GDB {
public class GDB {
static protected System.Diagnostics.Process mGDBProcess;
static protected System.IO.StreamReader mGDB;
static public string Unescape(string aInput) {
// Remove surrounding ", /n, then unescape and trim
return Regex.Unescape(aInput.Substring(1, aInput.Length - 2).Replace('\n', ' ').Trim());
}
static public List<string> GetResponse() {
var xResult = new List<string>();
//TODO: Cant find a better way than peek...
while (!mGDBProcess.HasExited) {
var xLine = mGDB.ReadLine();
// Null occurs after quit
if (xLine == null) {
break;
} else if (xLine.Trim() == "(gdb)") {
break;
} else {
var xType = xLine[0];
// & echo of a command
// ~ text response
// ^ done
xLine = xLine.Remove(0, 1);
if ((xType == '~') || (xType == '&')) {
xLine = Unescape(xLine);
}
Windows.mLogForm.Log(xType + xLine);
if (xType == '~') {
xResult.Add(xLine);
}
}
}
Windows.mLogForm.Log("-----");
return xResult;
}
static public List<string> SendCmd(string aCmd) {
mGDBProcess.StandardInput.WriteLine(aCmd);
return GetResponse();
}
static public void Connect() {
var xStartInfo = new ProcessStartInfo();
//TODO: Make path dynamic
xStartInfo.FileName = @"D:\source\Cosmos\Build\Tools\gdb.exe";
xStartInfo.Arguments = @"--interpreter=mi2";
//TODO: Make path dynamic
xStartInfo.WorkingDirectory = @"D:\source\Cosmos\source2\Users\Kudzu\Breakpoints\bin\debug";
xStartInfo.CreateNoWindow = true;
xStartInfo.UseShellExecute = false;
xStartInfo.RedirectStandardError = true;
xStartInfo.RedirectStandardOutput = true;
xStartInfo.RedirectStandardInput = true;
mGDBProcess = System.Diagnostics.Process.Start(xStartInfo);
mGDB = mGDBProcess.StandardOutput;
mGDBProcess.StandardInput.AutoFlush = true;
GetResponse();
SendCmd("symbol-file CosmosKernel.obj");
SendCmd("target remote :8832");
SendCmd("set architecture i386");
SendCmd("set language asm");
SendCmd("set disassembly-flavor intel");
SendCmd("break Kernel_Start");
SendCmd("continue");
SendCmd("delete 1");
}
}
}