This commit is contained in:
kudzu_cp 2011-07-09 21:55:46 +00:00
parent 792b43516b
commit cfb4e0a35f
8 changed files with 98 additions and 47 deletions

View file

@ -192,12 +192,46 @@ namespace Cosmos.Compiler.DebugStub {
public class WriteALToComPort : CodeBlock { public class WriteALToComPort : CodeBlock {
// Input: AL // Input: AL
// Output: None // Output: None
// Modifies: EAX, EDX, ESI // Modifies: EDX, ESI
public override void Assemble() { public override void Assemble() {
EAX.Push(); EAX.Push();
ESI = ESP; ESI = ESP;
Call("WriteByteToComPort"); 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]; ESI = Memory["DebugESP", 32];
// Send number of bytes // Send number of bytes
ESI = Memory["DebugEBP", 32]; EAX = Memory["DebugEBP", 32];
EAX.Sub(ESI); EAX.Sub(ESI);
Call<DebugStub.WriteALToComPort>(); Call<DebugStub.WriteAXToComPort>();
EAX.RotateRight(8); // Should be ShiftRight, but its no in X# ops yet
Call<DebugStub.WriteALToComPort>();
Label = "DebugStub_SendStack_SendByte"; Label = "DebugStub_SendStack_SendByte";
ESI.Compare(Memory["DebugEBP", 32]); ESI.Compare(Memory["DebugEBP", 32]);

View file

@ -291,8 +291,9 @@ namespace Cosmos.Debug.Common
case DsMsgType.Stack: case DsMsgType.Stack:
DoDebugMsg("DC Recv: Stack"); DoDebugMsg("DC Recv: Stack");
Next(128, PacketStack); Next(-1, PacketStack);
break; break;
default: default:
// Exceptions crash VS. // Exceptions crash VS.
MessageBox.Show("Unknown debug command"); MessageBox.Show("Unknown debug command");
@ -368,7 +369,7 @@ namespace Cosmos.Debug.Common
protected void PacketStack(byte[] aPacket) protected void PacketStack(byte[] aPacket)
{ {
mData = aPacket.ToArray(); mData = aPacket;
if (CmdStack != null) if (CmdStack != null)
{ {
CmdStack(mData); CmdStack(mData);

View file

@ -8,9 +8,7 @@ using System.Threading;
namespace Cosmos.Debug.Common namespace Cosmos.Debug.Common
{ {
/// <summary> /// Used for Vmware. VMWare uses a pipe to expose guest serial ports to the host.
/// Used for Vmware.
/// </summary>
public class DebugConnectorPipeServer : DebugConnectorStream { public class DebugConnectorPipeServer : DebugConnectorStream {
public DebugConnectorPipeServer() { public DebugConnectorPipeServer() {

View file

@ -59,12 +59,24 @@ namespace Cosmos.Debug.Common {
base.Dispose(); base.Dispose();
} }
protected Action<byte[]> 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<byte[]> aCompleted) { protected override void Next(int aPacketSize, Action<byte[]> aCompleted) {
var xIncoming = new Incoming() { var xIncoming = new Incoming();
Packet = new byte[aPacketSize] if (aPacketSize == -1) {
, Stream = mStream // Variable size packet, split into two reads
, Completed = aCompleted 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); mStream.BeginRead(xIncoming.Packet, 0, aPacketSize, new AsyncCallback(DoRead), xIncoming);
} }

View file

@ -16,9 +16,13 @@
<h3> <h3>
Debugging via Hive</h3> Debugging via Hive</h3>
<p> <p>
Program: /RootSuffix Exp &quot;M:\source\Cosmos\source\Cosmos.sln&quot;</p> Program: C:\Program Files (x86)\Microsoft Visual Studio
10.0\Common7\IDE\devenv.exe</p>
<p> <p>
Parameters: /RootSuffix Exp &quot;M:\source\Cosmos\source\Cosmos.sln&quot;</p> Parameters: /RootSuffix Exp &quot;<a
href="file:///M:/source/Cosmos/source/Cosmos.sln">M:\source\Cosmos\source\Cosmos.sln</a>&quot;</p>
<p>
Can also debug non hive, but some exceptions are not masked.</p>
</body> </body>
</html> </html>

View file

@ -56,13 +56,18 @@ namespace Cosmos.Cosmos_VS_Windows
{ {
mCommand = new Queue<byte>(); mCommand = new Queue<byte>();
mMessage = new Queue<byte[]>(); mMessage = new Queue<byte[]>();
// 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); System.Timers.Timer xTimer = new System.Timers.Timer(250);
xTimer.AutoReset = true; xTimer.AutoReset = true;
xTimer.Elapsed += new System.Timers.ElapsedEventHandler(ProcessMessage); xTimer.Elapsed += new System.Timers.ElapsedEventHandler(ProcessMessage);
xTimer.Start(); xTimer.Start();
PipeThread.DataPacketReceived += new Action<byte, byte[]>(PipeThread_DataPacketReceived); PipeThread.DataPacketReceived += new Action<byte, byte[]>(PipeThread_DataPacketReceived);
var xServerThread = new Thread(PipeThread.ThreadStartServer); var xServerThread = new Thread(PipeThread.ThreadStartServer);
xServerThread.Start(); xServerThread.Start();
Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString())); Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));
} }

View file

@ -8,8 +8,8 @@
d:DesignHeight="300" d:DesignWidth="300" d:DesignHeight="300" d:DesignWidth="300"
Name="CosmosStackUserControl" Name="CosmosStackUserControl"
Background="{DynamicResource {x:Static vsfx:VsBrushes.ToolWindowBackgroundKey}}"> Background="{DynamicResource {x:Static vsfx:VsBrushes.ToolWindowBackgroundKey}}">
<WrapPanel Orientation="Horizontal"> <DockPanel>
<TextBox Name="tboxSourceFrame" IsReadOnly="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="300" Width="150" /> <TextBox DockPanel.Dock="Left" Name="tboxSourceFrame" IsReadOnly="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" Width="160" Text="[EBP + 124] 0x12345678" />
<TextBox Name="tboxSourceStack" IsReadOnly="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="150" Height="300" /> <TextBox Name="tboxSourceStack" IsReadOnly="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" Text="0x12345678" />
</WrapPanel> </DockPanel>
</UserControl> </UserControl>

View file

@ -14,14 +14,14 @@ using System.Windows.Shapes;
namespace Cosmos.Cosmos_VS_Windows namespace Cosmos.Cosmos_VS_Windows
{ {
/// <summary>
/// Interaction logic for StackUC.xaml
/// </summary>
public partial class StackUC : UserControl public partial class StackUC : UserControl
{ {
public StackUC() public StackUC()
{ {
InitializeComponent(); InitializeComponent();
tboxSourceFrame.Text = "";
tboxSourceStack.Text = "";
} }
public void UpdateFrame(byte[] aData) public void UpdateFrame(byte[] aData)
@ -30,34 +30,33 @@ namespace Cosmos.Cosmos_VS_Windows
string xData = BitConverter.ToString(aData); string xData = BitConverter.ToString(aData);
xData = xData.Trim(); xData = xData.Trim();
xData = xData.Replace("-", ""); xData = xData.Replace("-", "");
if (xData.Length == 256) if (xData.Length == 256) {
{ for (int i = 0; i < 256; i += 8) {
for (int i = 0; i < 256; i += 8)
{
string xTemp = xData.Substring(i, 8); string xTemp = xData.Substring(i, 8);
tboxSourceFrame.Text += ("EBP + " + xOffset.ToString() + " : " + xTemp + "\n"); tboxSourceFrame.Text += ("[EBP + " + xOffset + "] " + xTemp + "\n");
xOffset += 4; xOffset += 4;
} }
} else {
tboxSourceFrame.Text = "Error loading the frame.";
} }
else tboxSourceFrame.Text = "Error loading the frame.";
} }
public void UpdateStack(byte[] aData) public void UpdateStack(byte[] aData)
{ {
int xOffset = -124;
string xData = BitConverter.ToString(aData); string xData = BitConverter.ToString(aData);
xData = xData.Trim(); xData = xData.Trim();
xData = xData.Replace("-", ""); xData = xData.Replace("-", "");
if (xData.Length == 256)
{ if (xData.Length == 256) {
for (int i = 0; i < 256; i += 8) var xSB = new StringBuilder();
{ xSB.AppendLine("Stack Contents");
string xTemp = xData.Substring(i, 8); for (int i = 0; i < 256; i += 8) {
tboxSourceStack.Text += ("EBP + " + xOffset.ToString() + " : " + xTemp + "\n"); xSB.AppendLine("0x" + xData.Substring(i, 8));
xOffset += 4;
} }
tboxSourceStack.Text = xSB.ToString();
} else {
tboxSourceStack.Text = "Error loading the stack.";
} }
else tboxSourceStack.Text = "Error loading the stack.";
} }
} }
} }