Skip to content

Commit

Permalink
Ongoing debug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mterwoord committed Jul 21, 2015
1 parent bbe4638 commit 8e7fc28
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 185 deletions.
2 changes: 1 addition & 1 deletion Build/VMWare/Workstation/Cosmos.vmx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ serial0.present = "TRUE"
serial0.yieldOnMsrRead = "TRUE"
serial0.fileType = "pipe"
serial0.fileName = "\\.\pipe\Cosmos\Serial"
serial0.pipe.endPoint = "client"
serial0.pipe.endPoint = "server"
serial0.tryNoRxLoss = "TRUE"
sound.present = "TRUE"
ethernet0.present = "TRUE"
Expand Down
1 change: 1 addition & 0 deletions Demos/Guess/GuessOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected override void Run()
{
mCount++;

mDebugger.Send("");
mDebugger.SendMessage("Kernel", "New iteration");
Console.WriteLine();
Console.WriteLine("Guess #" + mCount);
Expand Down
1 change: 1 addition & 0 deletions Tests/Cosmos.TestRunner.Core/Engine.Running.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ private void InitializeDebugConnector(DebugConnector debugConnector)
throw new ArgumentNullException("debugConnector");
}

debugConnector.OnDebugMsg = s => OutputHandler.LogDebugMessage(s);
debugConnector.CmdChannel = ChannelPacketReceived;
debugConnector.CmdStarted = () =>
{
Expand Down
6 changes: 3 additions & 3 deletions Tests/Cosmos.TestRunner/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
</startup>
</configuration>
</configuration>
3 changes: 2 additions & 1 deletion Tests/Cosmos.TestRunner/Cosmos.TestRunner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Cosmos.TestRunner.Console</RootNamespace>
<AssemblyName>Cosmos.TestRunner.Console</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x86</PlatformTarget>
Expand Down
6 changes: 6 additions & 0 deletions source/Cosmos.Debug.Common/Cosmos.Debug.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
<Compile Include="CacheHelper.cs" />
<Compile Include="Consts.cs" />
<Compile Include="DebugConnector.cs" />
<Compile Include="DebugConnector.Receiving.cs">
<DependentUpon>DebugConnector.cs</DependentUpon>
</Compile>
<Compile Include="DebugConnectorEdison.cs" />
<Compile Include="DebugConnectorPipeServer.cs" />
<Compile Include="DebugConnectorSerial.cs" />
Expand All @@ -139,6 +142,9 @@
<None Include=".editorconfig" />
<None Include="App.config" />
<None Include="Cosmos.snk" />
<Compile Include="DebugConnector.Sending.cs">
<DependentUpon>DebugConnector.cs</DependentUpon>
</Compile>
<None Include="Entities2.datasource" />
<None Include="packages.config" />
</ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions source/Cosmos.Debug.Common/DebugConnector.Receiving.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Cosmos.Debug.Common
{
partial class DebugConnector
{
protected abstract void Next(int aPacketSize, Action<byte[]> aCompleted);

}
}
177 changes: 177 additions & 0 deletions source/Cosmos.Debug.Common/DebugConnector.Sending.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cosmos.Debug.Common
{
partial class DebugConnector
{
protected void SendCmd(byte aCmd, byte[] aData)
{
SendCmd(aCmd, aData, true);
}

protected virtual void BeforeSendCmd()
{

}

protected void SendCmd(byte aCmd, byte[] aData, bool aWait)
{
//System.Windows.Forms.MessageBox.Show(xSB.ToString());

// If no sig received yet, we dont send anything. Things like BPs etc can be set before connected.
// The debugger must resend these after the start command hits.
// We dont queue them, as it would end up with a lot of overlapping ops, ie set and then remove.
// We also dont check connected at caller, becuase its a lot of extra code.
// So we just ignore any commands sent before ready, and its part of the contract
// that the caller (Debugger) knows when the Start msg is received that it must
// send over initializing information such as breakpoints.
if (SigReceived)
{
// This lock is used for:
// 1) VSDebugEngine is threaded and could send commands concurrently
// 2) Becuase in VSDebugEngine and commands from Debug.Windows can occur concurrently
lock (mSendCmdLock)
{
//var xSB = new StringBuilder();
//foreach(byte x in aBytes) {
// xSB.AppendLine(x.ToString("X2"));
//}
//System.Windows.Forms.MessageBox.Show(xSB.ToString());
DoDebugMsg("DC Send: " + aCmd.ToString() + ", data.Length = " + aData.Length + ", aWait = " + aWait);

DoDebugMsg("Send locked...");

BeforeSendCmd();

if (aCmd == Vs2Ds.Noop)
{
// Noops dont have any data.
// This is becuase Noops are used to clear out the
// channel and are often not received. Sending noop + data
// usually causes the data to be interpreted as a command
// as its often the first byte received.
SendRawData(new byte[1]
{
Vs2Ds.Noop
});
}
else
{
// +2 - Leave room for Cmd and CmdID
var xData = new byte[aData.Length + 2];
// See comments about flow control in the DebugStub class
// to see why we limit to 16.
if (aData.Length > 16)
{
throw new Exception("Command is too large. 16 bytes max.");
}

xData[0] = (byte)aCmd;
aData.CopyTo(xData, 2);

bool resetID = false;
if (mCommandID == 255)
{
mCommandID = 0;
resetID = true;
}
else
{
mCommandID++;
}
xData[1] = mCommandID;
mCurrCmdID = mCommandID;

if (SendRawData(xData))
{
if (aWait)
{
// All commands except NOOP reply back from the DebugStub
// with an ACK. The ACK will set the event and allow us to proceed.
// This wait causes this method to wait on the ACK to be receive back from
// DebugStub.

//Sometimes we get out of sync or recieve something we aren't expecting
//So this forces us to only return when we are back in-sync or after we think we've frozen the system for
//too long
//If we haven't gone past the command already!
if ((!resetID && lastCmdCompletedID < mCommandID)
|| (resetID && lastCmdCompletedID > 5))
{
int attempts = 0;
do
{
mCmdWait.WaitOne(2000 /*60000*/);
} while ((
(!resetID && lastCmdCompletedID < mCommandID) ||
(resetID && lastCmdCompletedID > 5)
)
&&
++attempts < 10);
}
}
}
}
}

DoDebugMsg("Send unlocked.");
}
else
{
DoDebugMsg("Tried to send command " + aCmd + ", but signature was not yet received!");
}
}

protected abstract bool SendRawData(byte[] aBytes);

protected byte mCommandID = 0;
protected byte mCurrCmdID;

protected bool SendRawData(string aData, Encoding aEncoding = null)
{
if (aEncoding == null)
{
aEncoding = Encoding.UTF8;
}

if (aData == null)
{
return true;
}

var xBytes = aEncoding.GetBytes(aData);
return SendRawData(xBytes);
}
// Prevent more than one command from happening at once.
// The debugger is user driven so should not happen, but maybe could
// happen while a previous command is waiting on a reply msg.
protected object mSendCmdLock = new object();
public void SendCmd(byte aCmd)
{
SendCmd(aCmd, new byte[0], true);
}

public void SendRegisters()
{
SendCmd(Vs2Ds.SendRegisters);
}

public void SendFrame()
{
SendCmd(Vs2Ds.SendFrame);
}

public void SendStack()
{
SendCmd(Vs2Ds.SendStack);
}

public void Ping()
{
SendCmd(Vs2Ds.Ping);
}
}
}
Loading

0 comments on commit 8e7fc28

Please sign in to comment.