From 5f3aae4e4e09ede8bde9d2c0a815b16f9c2b6381 Mon Sep 17 00:00:00 2001 From: kudzu_cp <6d05c8c8ef5431987001abfdb2eadc9593ac9498> Date: Mon, 26 Jul 2010 05:34:44 +0000 Subject: [PATCH] --- .../Debug/Cosmos.Debug.GDB/FormBreakpoints.cs | 2 +- .../Debug/Cosmos.Debug.GDB/FormCallStack.cs | 2 +- .../Debug/Cosmos.Debug.GDB/FormDisassembly.cs | 2 +- .../Cosmos.Debug.GDB/FormLog.Designer.cs | 7 +- source2/Debug/Cosmos.Debug.GDB/FormLog.cs | 19 +++++- .../Debug/Cosmos.Debug.GDB/FormRegisters.cs | 2 +- source2/Debug/Cosmos.Debug.GDB/GDB.cs | 65 ++++++++++++------- 7 files changed, 67 insertions(+), 32 deletions(-) diff --git a/source2/Debug/Cosmos.Debug.GDB/FormBreakpoints.cs b/source2/Debug/Cosmos.Debug.GDB/FormBreakpoints.cs index 2d00da799..1ccd90589 100644 --- a/source2/Debug/Cosmos.Debug.GDB/FormBreakpoints.cs +++ b/source2/Debug/Cosmos.Debug.GDB/FormBreakpoints.cs @@ -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]))); diff --git a/source2/Debug/Cosmos.Debug.GDB/FormCallStack.cs b/source2/Debug/Cosmos.Debug.GDB/FormCallStack.cs index 1bd891174..c38958a99 100644 --- a/source2/Debug/Cosmos.Debug.GDB/FormCallStack.cs +++ b/source2/Debug/Cosmos.Debug.GDB/FormCallStack.cs @@ -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 () diff --git a/source2/Debug/Cosmos.Debug.GDB/FormDisassembly.cs b/source2/Debug/Cosmos.Debug.GDB/FormDisassembly.cs index 6e4acc966..407e9d7c1 100644 --- a/source2/Debug/Cosmos.Debug.GDB/FormDisassembly.cs +++ b/source2/Debug/Cosmos.Debug.GDB/FormDisassembly.cs @@ -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(); diff --git a/source2/Debug/Cosmos.Debug.GDB/FormLog.Designer.cs b/source2/Debug/Cosmos.Debug.GDB/FormLog.Designer.cs index 320186002..bd09a0883 100644 --- a/source2/Debug/Cosmos.Debug.GDB/FormLog.Designer.cs +++ b/source2/Debug/Cosmos.Debug.GDB/FormLog.Designer.cs @@ -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 // diff --git a/source2/Debug/Cosmos.Debug.GDB/FormLog.cs b/source2/Debug/Cosmos.Debug.GDB/FormLog.cs index 40089d2ac..e094e4058 100644 --- a/source2/Debug/Cosmos.Debug.GDB/FormLog.cs +++ b/source2/Debug/Cosmos.Debug.GDB/FormLog.cs @@ -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); + } + } + } } diff --git a/source2/Debug/Cosmos.Debug.GDB/FormRegisters.cs b/source2/Debug/Cosmos.Debug.GDB/FormRegisters.cs index caeff3760..caba767e0 100644 --- a/source2/Debug/Cosmos.Debug.GDB/FormRegisters.cs +++ b/source2/Debug/Cosmos.Debug.GDB/FormRegisters.cs @@ -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; diff --git a/source2/Debug/Cosmos.Debug.GDB/GDB.cs b/source2/Debug/Cosmos.Debug.GDB/GDB.cs index 581642b53..41afbc6b3 100644 --- a/source2/Debug/Cosmos.Debug.GDB/GDB.cs +++ b/source2/Debug/Cosmos.Debug.GDB/GDB.cs @@ -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 Text = new List(); + + 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 GetResponse() { - var xResult = new List(); + 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 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");