This commit is contained in:
kudzu_cp 2010-07-26 05:34:44 +00:00
parent bfa8bdb13e
commit 5f3aae4e4e
7 changed files with 67 additions and 32 deletions

View file

@ -36,7 +36,7 @@ namespace Cosmos.Debug.GDB {
public bool AddBreakpoint(string aLabel) {
string s = aLabel.Trim();
if (s.Length > 0) {
var xResult = GDB.SendCmd("break " + s);
var xResult = GDB.SendCmd("break " + s).Text;
var xSplit = xResult[0].Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (xSplit[0] == "Breakpoint") {
lboxBreakpoints.SelectedIndex = lboxBreakpoints.Items.Add(new Breakpoint(s, int.Parse(xSplit[1])));

View file

@ -36,7 +36,7 @@ namespace Cosmos.Debug.GDB {
lboxCallStack.BeginUpdate();
try {
lboxCallStack.Items.Clear();
foreach (var x in xResult) {
foreach (var x in xResult.Text) {
//#0 0x0056d5df in DebugStub_Start ()
//#1 0x0057572b in System_Void__Cosmos_User_Kernel_Program_Init____DOT__00000001 ()
//#2 0x00550018 in Before_Kernel_Stack ()

View file

@ -74,7 +74,7 @@ namespace Cosmos.Debug.GDB {
lablCurrentFunction.Text = "";
lablCurrentFunction.Visible = true;
var xResult = GDB.SendCmd(("disassemble " + aLabel).Trim());
var xResult = GDB.SendCmd(("disassemble " + aLabel).Trim()).Text;
lboxDisassemble.BeginUpdate();
try {
lboxDisassemble.Items.Clear();

View file

@ -129,9 +129,9 @@
//
this.lboxDebug.Dock = System.Windows.Forms.DockStyle.Fill;
this.lboxDebug.FormattingEnabled = true;
this.lboxDebug.Location = new System.Drawing.Point(118, 0);
this.lboxDebug.Location = new System.Drawing.Point(188, 0);
this.lboxDebug.Name = "lboxDebug";
this.lboxDebug.Size = new System.Drawing.Size(371, 316);
this.lboxDebug.Size = new System.Drawing.Size(301, 316);
this.lboxDebug.TabIndex = 9;
//
// lboxCmd
@ -140,8 +140,9 @@
this.lboxCmd.FormattingEnabled = true;
this.lboxCmd.Location = new System.Drawing.Point(0, 0);
this.lboxCmd.Name = "lboxCmd";
this.lboxCmd.Size = new System.Drawing.Size(118, 316);
this.lboxCmd.Size = new System.Drawing.Size(188, 316);
this.lboxCmd.TabIndex = 7;
this.lboxCmd.SelectedIndexChanged += new System.EventHandler(this.lboxCmd_SelectedIndexChanged);
//
// FormLog
//

View file

@ -13,8 +13,8 @@ namespace Cosmos.Debug.GDB {
InitializeComponent();
}
public void Log(string aMsg) {
lboxDebug.SelectedIndex = lboxDebug.Items.Add(aMsg);
public void Log(GDB.Response aResponse) {
lboxCmd.SelectedIndex = lboxCmd.Items.Add(aResponse);
Application.DoEvents();
}
@ -46,5 +46,20 @@ namespace Cosmos.Debug.GDB {
}
}
private void lboxCmd_SelectedIndexChanged(object sender, EventArgs e) {
var xResponse = (GDB.Response)lboxCmd.SelectedItem;
lboxDebug.Items.Clear();
lboxDebug.Items.Add(xResponse.Command);
if (xResponse.Error) {
lboxDebug.Items.Add("ERROR: " + xResponse.ErrorMsg);
}
lboxDebug.Items.Add("");
foreach (var x in xResponse.Text) {
lboxDebug.Items.Add(x);
}
}
}
}

View file

@ -20,7 +20,7 @@ namespace Cosmos.Debug.GDB {
}
public void Redo() {
var xResult = GDB.SendCmd("info registers");
var xResult = GDB.SendCmd("info registers").Text;
int i = 0;
CPUReg xReg;

View file

@ -7,16 +7,33 @@ using System.Text;
namespace Cosmos.Debug.GDB {
public class GDB {
public class Response {
public string Command = "";
public bool Error = false;
public string ErrorMsg = "";
public List<string> Text = new List<string>();
public override string ToString() {
return Command;
}
}
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());
string xResult = aInput;
if (xResult.StartsWith("\"")) {
xResult = xResult.Substring(1, aInput.Length - 2);
xResult = xResult.Replace('\n', ' ');
xResult = Regex.Unescape(xResult);
}
return xResult.Trim();
}
static public List<string> GetResponse() {
var xResult = new List<string>();
static public Response GetResponse() {
var xResult = new Response();
//TODO: Cant find a better way than peek...
while (!mGDBProcess.HasExited) {
@ -31,24 +48,36 @@ namespace Cosmos.Debug.GDB {
// & 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);
//&target remote :8832
//&:8832: No connection could be made because the target machine actively refused it.
//^error,msg=":8832: No connection could be made because the target machine actively refused it."
//&target remote :8832
//~Remote debugging using :8832
//~[New Thread 1]
//~0x000ffff0 in ?? ()
//^done
xLine = Unescape(xLine.Substring(1));
if (xType == '&') {
} else if (xType == '^') {
xResult.Error = xLine != "done";
} else if (xType == '~') {
xResult.Text.Add(Unescape(xLine));
}
}
}
Windows.mLogForm.Log("-----");
return xResult;
}
static public List<string> SendCmd(string aCmd) {
static public Response SendCmd(string aCmd) {
mGDBProcess.StandardInput.WriteLine(aCmd);
return GetResponse();
var xResult = GetResponse();
xResult.Command = aCmd;
Windows.mLogForm.Log(xResult);
return xResult;
}
//TODO: Make path dynamic
@ -58,7 +87,6 @@ namespace Cosmos.Debug.GDB {
var xStartInfo = new ProcessStartInfo();
xStartInfo.FileName = mCosmosPath+ @"Build\Tools\gdb.exe";
xStartInfo.Arguments = @"--interpreter=mi2";
//TODO: Make path dynamic
xStartInfo.WorkingDirectory = mCosmosPath + @"source2\Users\Kudzu\Breakpoints\bin\debug";
xStartInfo.CreateNoWindow = true;
xStartInfo.UseShellExecute = false;
@ -73,15 +101,6 @@ namespace Cosmos.Debug.GDB {
SendCmd("symbol-file CosmosKernel.obj");
SendCmd("target remote :8832");
//&target remote :8832
//&:8832: No connection could be made because the target machine actively refused it.
//^error,msg=":8832: No connection could be made because the target machine actively refused it."
//&target remote :8832
//~Remote debugging using :8832
//~[New Thread 1]
//~0x000ffff0 in ?? ()
//^done
SendCmd("set architecture i386");
SendCmd("set language asm");