From cfb4e0a35f74a57ab29bb9cde2b4b7220c85828d Mon Sep 17 00:00:00 2001 From: kudzu_cp <6d05c8c8ef5431987001abfdb2eadc9593ac9498> Date: Sat, 9 Jul 2011 21:55:46 +0000 Subject: [PATCH] --- .../Cosmos.Compiler.DebugStub/DebugStub.cs | 44 ++++++++++++++++--- .../Cosmos.Debug.Common/DebugConnector.cs | 5 ++- .../DebugConnectorPipeServer.cs | 4 +- .../DebugConnectorStream.cs | 26 ++++++++--- .../Cosmos.Debug.VSDebugEngine/ReadMe.html | 10 +++-- .../Cosmos.VS.WindowsPackage.cs | 5 +++ source2/VSIP/Cosmos.VS.Windows/StackUC.xaml | 8 ++-- .../VSIP/Cosmos.VS.Windows/StackUC.xaml.cs | 43 +++++++++--------- 8 files changed, 98 insertions(+), 47 deletions(-) diff --git a/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs b/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs index a7584024b..22c676e89 100644 --- a/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs +++ b/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs @@ -192,12 +192,46 @@ namespace Cosmos.Compiler.DebugStub { public class WriteALToComPort : CodeBlock { // Input: AL // Output: None - // Modifies: EAX, EDX, ESI + // Modifies: EDX, ESI public override void Assemble() { EAX.Push(); ESI = ESP; Call("WriteByteToComPort"); - EAX.Pop(); // Is a local var, cant use Return(4). X# issues the return. + // Is a local var, cant use Return(4). X# issues the return. + // This also allow the function to preserve EAX. + EAX.Pop(); + } + } + + public class WriteAXToComPort : CodeBlock { + // Input: AX + // Output: None + // Modifies: EDX, ESI + public override void Assemble() { + EAX.Push(); + ESI = ESP; + Call("WriteByteToComPort"); + Call("WriteByteToComPort"); + // Is a local var, cant use Return(4). X# issues the return. + // This also allow the function to preserve EAX. + EAX.Pop(); + } + } + + public class WriteEAXToComPort : CodeBlock { + // Input: EAX + // Output: None + // Modifies: EDX, ESI + public override void Assemble() { + EAX.Push(); + ESI = ESP; + Call("WriteByteToComPort"); + Call("WriteByteToComPort"); + Call("WriteByteToComPort"); + Call("WriteByteToComPort"); + // Is a local var, cant use Return(4). X# issues the return. + // This also allow the function to preserve EAX. + EAX.Pop(); } } @@ -295,11 +329,9 @@ namespace Cosmos.Compiler.DebugStub { ESI = Memory["DebugESP", 32]; // Send number of bytes - ESI = Memory["DebugEBP", 32]; + EAX = Memory["DebugEBP", 32]; EAX.Sub(ESI); - Call(); - EAX.RotateRight(8); // Should be ShiftRight, but its no in X# ops yet - Call(); + Call(); Label = "DebugStub_SendStack_SendByte"; ESI.Compare(Memory["DebugEBP", 32]); diff --git a/source2/Debug/Cosmos.Debug.Common/DebugConnector.cs b/source2/Debug/Cosmos.Debug.Common/DebugConnector.cs index 00810f7c4..538d11974 100644 --- a/source2/Debug/Cosmos.Debug.Common/DebugConnector.cs +++ b/source2/Debug/Cosmos.Debug.Common/DebugConnector.cs @@ -291,8 +291,9 @@ namespace Cosmos.Debug.Common case DsMsgType.Stack: DoDebugMsg("DC Recv: Stack"); - Next(128, PacketStack); + Next(-1, PacketStack); break; + default: // Exceptions crash VS. MessageBox.Show("Unknown debug command"); @@ -368,7 +369,7 @@ namespace Cosmos.Debug.Common protected void PacketStack(byte[] aPacket) { - mData = aPacket.ToArray(); + mData = aPacket; if (CmdStack != null) { CmdStack(mData); diff --git a/source2/Debug/Cosmos.Debug.Common/DebugConnectorPipeServer.cs b/source2/Debug/Cosmos.Debug.Common/DebugConnectorPipeServer.cs index 3a6e1834d..465e2e28d 100644 --- a/source2/Debug/Cosmos.Debug.Common/DebugConnectorPipeServer.cs +++ b/source2/Debug/Cosmos.Debug.Common/DebugConnectorPipeServer.cs @@ -8,9 +8,7 @@ using System.Threading; namespace Cosmos.Debug.Common { - /// - /// Used for Vmware. - /// + /// Used for Vmware. VMWare uses a pipe to expose guest serial ports to the host. public class DebugConnectorPipeServer : DebugConnectorStream { public DebugConnectorPipeServer() { diff --git a/source2/Debug/Cosmos.Debug.Common/DebugConnectorStream.cs b/source2/Debug/Cosmos.Debug.Common/DebugConnectorStream.cs index 0e3b11a21..bbb855dde 100644 --- a/source2/Debug/Cosmos.Debug.Common/DebugConnectorStream.cs +++ b/source2/Debug/Cosmos.Debug.Common/DebugConnectorStream.cs @@ -58,14 +58,26 @@ namespace Cosmos.Debug.Common { } base.Dispose(); } - + + protected Action mCompleted; // Action to call after size received + protected void SizePacket(byte[] aPacket) { + int xSize = aPacket[0] + aPacket[1] << 8; + Next(xSize, mCompleted); + } + protected override void Next(int aPacketSize, Action aCompleted) { - var xIncoming = new Incoming() { - Packet = new byte[aPacketSize] - , Stream = mStream - , Completed = aCompleted - }; - mStream.BeginRead(xIncoming.Packet, 0, aPacketSize, new AsyncCallback(DoRead), xIncoming); + var xIncoming = new Incoming(); + if (aPacketSize == -1) { + // Variable size packet, split into two reads + mCompleted = aCompleted; + aPacketSize = 2; + xIncoming.Completed = SizePacket; + } else { + xIncoming.Completed = aCompleted; + } + xIncoming.Packet = new byte[aPacketSize]; + xIncoming.Stream = mStream; + mStream.BeginRead(xIncoming.Packet, 0, aPacketSize, new AsyncCallback(DoRead), xIncoming); } protected void DoRead(IAsyncResult aResult) { diff --git a/source2/Debug/Cosmos.Debug.VSDebugEngine/ReadMe.html b/source2/Debug/Cosmos.Debug.VSDebugEngine/ReadMe.html index 608708d2f..1fcb7767b 100644 --- a/source2/Debug/Cosmos.Debug.VSDebugEngine/ReadMe.html +++ b/source2/Debug/Cosmos.Debug.VSDebugEngine/ReadMe.html @@ -16,9 +16,13 @@

Debugging via Hive

- Program: /RootSuffix Exp "M:\source\Cosmos\source\Cosmos.sln"

-

- Parameters: /RootSuffix Exp "M:\source\Cosmos\source\Cosmos.sln"

+ Program: C:\Program Files (x86)\Microsoft Visual Studio + 10.0\Common7\IDE\devenv.exe

+

+ Parameters: /RootSuffix Exp "M:\source\Cosmos\source\Cosmos.sln"

+

+ Can also debug non hive, but some exceptions are not masked.

\ No newline at end of file diff --git a/source2/VSIP/Cosmos.VS.Windows/Cosmos.VS.WindowsPackage.cs b/source2/VSIP/Cosmos.VS.Windows/Cosmos.VS.WindowsPackage.cs index 36ce527f2..8bd8254b4 100644 --- a/source2/VSIP/Cosmos.VS.Windows/Cosmos.VS.WindowsPackage.cs +++ b/source2/VSIP/Cosmos.VS.Windows/Cosmos.VS.WindowsPackage.cs @@ -56,13 +56,18 @@ namespace Cosmos.Cosmos_VS_Windows { mCommand = new Queue(); mMessage = new Queue(); + + // There are a lot of threading issues in VSIP, and the WPF dispatchers do not work + // So instead we use a stack and a timer to poll it for data. System.Timers.Timer xTimer = new System.Timers.Timer(250); xTimer.AutoReset = true; xTimer.Elapsed += new System.Timers.ElapsedEventHandler(ProcessMessage); xTimer.Start(); + PipeThread.DataPacketReceived += new Action(PipeThread_DataPacketReceived); var xServerThread = new Thread(PipeThread.ThreadStartServer); xServerThread.Start(); + Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString())); } diff --git a/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml b/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml index 3aadbd26e..ccb2b3a38 100644 --- a/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml +++ b/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml @@ -8,8 +8,8 @@ d:DesignHeight="300" d:DesignWidth="300" Name="CosmosStackUserControl" Background="{DynamicResource {x:Static vsfx:VsBrushes.ToolWindowBackgroundKey}}"> - - - - + + + + diff --git a/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml.cs b/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml.cs index f0af5b33f..1e64b497b 100644 --- a/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml.cs +++ b/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml.cs @@ -14,14 +14,14 @@ using System.Windows.Shapes; namespace Cosmos.Cosmos_VS_Windows { - /// - /// Interaction logic for StackUC.xaml - /// public partial class StackUC : UserControl { public StackUC() { InitializeComponent(); + + tboxSourceFrame.Text = ""; + tboxSourceStack.Text = ""; } public void UpdateFrame(byte[] aData) @@ -30,34 +30,33 @@ namespace Cosmos.Cosmos_VS_Windows string xData = BitConverter.ToString(aData); xData = xData.Trim(); xData = xData.Replace("-", ""); - if (xData.Length == 256) - { - for (int i = 0; i < 256; i += 8) - { - string xTemp = xData.Substring(i, 8); - tboxSourceFrame.Text += ("EBP + " + xOffset.ToString() + " : " + xTemp + "\n"); - xOffset += 4; - } + if (xData.Length == 256) { + for (int i = 0; i < 256; i += 8) { + string xTemp = xData.Substring(i, 8); + tboxSourceFrame.Text += ("[EBP + " + xOffset + "] " + xTemp + "\n"); + xOffset += 4; + } + } else { + tboxSourceFrame.Text = "Error loading the frame."; } - else tboxSourceFrame.Text = "Error loading the frame."; } public void UpdateStack(byte[] aData) { - int xOffset = -124; string xData = BitConverter.ToString(aData); xData = xData.Trim(); xData = xData.Replace("-", ""); - if (xData.Length == 256) - { - for (int i = 0; i < 256; i += 8) - { - string xTemp = xData.Substring(i, 8); - tboxSourceStack.Text += ("EBP + " + xOffset.ToString() + " : " + xTemp + "\n"); - xOffset += 4; - } + + if (xData.Length == 256) { + var xSB = new StringBuilder(); + xSB.AppendLine("Stack Contents"); + for (int i = 0; i < 256; i += 8) { + xSB.AppendLine("0x" + xData.Substring(i, 8)); + } + tboxSourceStack.Text = xSB.ToString(); + } else { + tboxSourceStack.Text = "Error loading the stack."; } - else tboxSourceStack.Text = "Error loading the stack."; } } } \ No newline at end of file