void HostShutdown(object sender, EventArgs e) { //AD7ThreadDestroyEvent.Send(mEngine, mThread, (uint)mProcess.ExitCode); //mCallback.OnProgramDestroy((uint)mProcess.ExitCode); // We dont use process info any more, but have to call this to tell // VS to stop debugging. if (Interlocked.CompareExchange(ref mProcessExitEventSent, 1, 0) == 0) { try { mCallback.OnProcessExit(0); } catch { // swallow exceptions here? } } if (mDbgConnector != null) { mDbgConnector.Dispose(); mDbgConnector = null; } if (mDebugInfoDb != null) { // Commented for debugging, so we can look at the DB after //mDebugInfoDb.DeleteDB(); mDebugInfoDb.Dispose(); mDebugInfoDb = null; } }
// this file contains code handling situations when a kernel is running // most of this is debug stub related private void InitializeDebugConnector(DebugConnector debugConnector) { if (debugConnector == null) { throw new ArgumentNullException("debugConnector"); } debugConnector.OnDebugMsg = s => OutputHandler.LogDebugMessage(s); debugConnector.CmdChannel = ChannelPacketReceived; debugConnector.CmdStarted = () => { OutputHandler.LogMessage("DC: Started"); debugConnector.SendCmd(Vs2Ds.BatchEnd); }; debugConnector.Error = e => { OutputHandler.LogMessage("DC Error: " + e.ToString()); OutputHandler.SetKernelTestResult(false, "DC Error"); mKernelResultSet = true; mKernelRunning = false; }; debugConnector.CmdText += s => OutputHandler.LogMessage("Text from kernel: " + s); debugConnector.CmdSimpleNumber += n => OutputHandler.LogMessage("Number from kernel: 0x" + n.ToString("X8").ToUpper()); debugConnector.CmdSimpleLongNumber += n => OutputHandler.LogMessage("Number from kernel: 0x" + n.ToString("X16").ToUpper()); debugConnector.CmdComplexNumber += f => OutputHandler.LogMessage("Number from kernel: 0x" + f.ToString("X8").ToUpper()); debugConnector.CmdComplexLongNumber += d => OutputHandler.LogMessage("Number from kernel: 0x" + d.ToString("X16").ToUpper()); debugConnector.CmdMessageBox = s => OutputHandler.LogMessage("MessageBox from kernel: " + s); debugConnector.CmdTrace = t => { }; debugConnector.CmdBreak = t => { }; debugConnector.CmdStackCorruptionOccurred = a => { OutputHandler.LogMessage("Stackcorruption occurred at: 0x" + a.ToString("X8")); OutputHandler.SetKernelTestResult(false, "Stackcorruption occurred at: 0x" + a.ToString("X8")); mKernelResultSet = true; mKernelRunning = false; }; debugConnector.CmdStackOverflowOccurred = a => { OutputHandler.LogMessage("Stack overflow occurred at: 0x" + a.ToString("X8")); OutputHandler.SetKernelTestResult(false, "Stack overflow occurred at: 0x" + a.ToString("X8")); mKernelResultSet = true; mKernelRunning = false; }; debugConnector.CmdNullReferenceOccurred = a => { OutputHandler.LogMessage("Null Reference Exception occurred at: 0x" + a.ToString("X8")); OutputHandler.SetKernelTestResult( false, "Null Reference Exception occurred at: 0x" + a.ToString("X8")); mKernelResultSet = true; mKernelRunning = false; }; if (RunWithGDB) { debugConnector.CmdInterruptOccurred = a => { OutputHandler.LogMessage($"Interrupt {a} occurred"); }; } }
public override int GetHashCode() { unchecked { var hashCode = (ConfigurationBaseFolder != null ? ConfigurationBaseFolder.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (SpecFlow != null ? SpecFlow.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Traceability != null ? Traceability.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (int)ProcessorArchitecture; hashCode = (hashCode * 397) ^ DebugConnector.GetHashCode(); hashCode = (hashCode * 397) ^ (DefaultFeatureLanguage != null ? DefaultFeatureLanguage.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ConfiguredBindingCulture != null ? ConfiguredBindingCulture.GetHashCode() : 0); return(hashCode); } }
// this file contains code handling situations when a kernel is running // most of this is debug stub related private void InitializeDebugConnector(DebugConnector debugConnector) { if (debugConnector == null) { throw new ArgumentNullException("debugConnector"); } debugConnector.CmdChannel = ChannelPacketReceived; debugConnector.CmdStarted = () => { OutputHandler.LogMessage("DC: Started"); debugConnector.SendCmd(Vs2Ds.BatchEnd); }; debugConnector.Error = e => { OutputHandler.LogMessage("DC Error: " + e.ToString()); OutputHandler.SetKernelTestResult(false, "DC Error"); mKernelResultSet = true; mKernelRunning = false; }; debugConnector.CmdText += s => { if (s == "SYS_TestKernel_Completed") { KernelTestCompleted(); return; } else if (s == "SYS_TestKernel_Failed") { KernelTestFailed(); return; } else if (s == "SYS_TestKernel_AssertionSucceeded") { KernelAssertionSucceeded(); return; } OutputHandler.LogMessage("Text from kernel: " + s); }; debugConnector.CmdMessageBox = s => { //OutputHandler.LogMessage("MessageBox from kernel: " + s) }; debugConnector.CmdTrace = t => { }; debugConnector.CmdBreak = t => { }; }
private void HandleRunning(DebugConnector debugConnector, Base host) { if (debugConnector == null) { throw new ArgumentNullException("debugConnector"); } if (host == null) { throw new ArgumentNullException("host"); } mKernelRunning = true; host.Start(); try { var xStartTime = DateTime.Now; mKernelResultSet = false; Interlocked.Exchange(ref mSucceededAssertions, 0); while (mKernelRunning) { Thread.Sleep(50); if (Math.Abs(DateTime.Now.Subtract(xStartTime).TotalSeconds) > AllowedSecondsInKernel) { OutputHandler.SetKernelTestResult(false, "Timeout exceeded"); mKernelResultSet = true; break; } } if (mKernelResultSet) { //OutputHandler.SetKernelTestResult(true, null); OutputHandler.SetKernelSucceededAssertionsCount(mSucceededAssertions); } else { KernelTestFailed(); } } finally { Console.WriteLine("Stopping now"); host.Stop(); debugConnector.Dispose(); Thread.Sleep(50); } }
/// <summary>Instanciate the <see cref="DebugConnector"/> that will handle communications /// between this debug engine hosted process and the emulation environment used to run the /// debugged Cosmos kernel. Actual connector to be instanciated is discovered from Cosmos /// project properties.</summary> private void CreateDebugConnector() { mDbgConnector = null; string xPort = mDebugInfo[BuildProperties.VisualStudioDebugPortString]; var xParts = (null == xPort) ? null : xPort.Split(' '); if ((null == xParts) || (2 > xParts.Length)) { throw new Exception(string.Format( "The '{0}' Cosmos project file property is either ill-formed or missing.", BuildProperties.VisualStudioDebugPortString)); } string xPortType = xParts[0].ToLower(); string xPortParam = xParts[1].ToLower(); OutputText("Starting debug connector."); if (xPortType == "pipe:") { mDbgConnector = new Cosmos.Debug.Common.DebugConnectorPipeServer(xPortParam); } else if (xPortType == "serial:") { mDbgConnector = new Cosmos.Debug.Common.DebugConnectorSerial(xPortParam); } if (mDbgConnector == null) { throw new Exception("No debug connector found."); } mDbgConnector.SetConnectionHandler(DebugConnectorConnected); mDbgConnector.CmdBreak += new Action <UInt32>(DbgCmdBreak); mDbgConnector.CmdTrace += new Action <UInt32>(DbgCmdTrace); mDbgConnector.CmdText += new Action <string>(DbgCmdText); mDbgConnector.CmdStarted += new Action(DbgCmdStarted); mDbgConnector.OnDebugMsg += new Action <string>(DebugMsg); mDbgConnector.ConnectionLost += new Action <Exception>(DbgConnector_ConnectionLost); mDbgConnector.CmdRegisters += new Action <byte[]>(DbgCmdRegisters); mDbgConnector.CmdFrame += new Action <byte[]>(DbgCmdFrame); mDbgConnector.CmdStack += new Action <byte[]>(DbgCmdStack); mDbgConnector.CmdPong += new Action <byte[]>(DbgCmdPong); mDbgConnector.CmdStackCorruptionOccurred += DbgCmdStackCorruptionOccurred; mDbgConnector.CmdNullReferenceOccurred += DbgCmdNullReferenceOccurred; mDbgConnector.CmdMessageBox += DbgCmdMessageBox; }
private void HandleRunning(DebugConnector debugConnector, Host host) { if (debugConnector == null) { throw new ArgumentNullException("debugConnector"); } if (host == null) { throw new ArgumentNullException("host"); } mKernelRunning = true; host.Start(); try { var xStartTime = DateTime.Now; Interlocked.Exchange(ref mSucceededAssertions, 0); while (mKernelRunning) { Thread.Sleep(50); if (Math.Abs(DateTime.Now.Subtract(xStartTime).TotalSeconds) > AllowedSecondsInKernel) { throw new TimeoutException("Timeout exceeded!"); } } } finally { host.Stop(); debugConnector.Dispose(); Thread.Sleep(50); } }
public void SetDebugConnector(DebugConnector aConnector) { mDbgConnector = aConnector; }
/// <summary>Instanciate the <see cref="DebugConnector"/> that will handle communications /// between this debug engine hosted process and the emulation environment used to run the /// debugged Cosmos kernel. Actual connector to be instanciated is discovered from Cosmos /// project properties.</summary> private void CreateDebugConnector() { mDbgConnector = null; string xPort = mDebugInfo[BuildPropertyNames.VisualStudioDebugPortString]; // using (var xDebug = new StreamWriter(@"e:\debug.info", false)) // { // foreach (var xItem in mDebugInfo.AllKeys) // { // xDebug.WriteLine("{0}: '{1}'", xItem, mDebugInfo[xItem]); // } // xDebug.Flush(); // } if (String.IsNullOrWhiteSpace(xPort)) { xPort = mDebugInfo[BuildPropertyNames.CosmosDebugPortString]; } var xParts = (null == xPort) ? null : xPort.Split(' '); if ((null == xParts) || (2 > xParts.Length)) { throw new Exception(string.Format("Unable to parse VS debug port: '{0}'", xPort)); //throw new Exception(string.Format( // "The '{0}' Cosmos project file property is either ill-formed or missing.", // BuildProperties.VisualStudioDebugPortString)); } string xPortType = xParts[0].ToLower(); string xPortParam = xParts[1].ToLower(); var xLaunch = mDebugInfo[BuildPropertyNames.LaunchString]; OutputText("Starting debug connector."); switch (xPortType) { case "pipe:": mDbgConnector = new Cosmos.Debug.Common.DebugConnectorPipeServer(xPortParam); break; case "serial:": if (xLaunch == "IntelEdison") { mDbgConnector = new Cosmos.Debug.Common.DebugConnectorEdison(xPortParam, Path.ChangeExtension(mDebugInfo["ISOFile"], ".bin")); } else { mDbgConnector = new Cosmos.Debug.Common.DebugConnectorSerial(xPortParam); } break; default: throw new Exception("No debug connector found for port type '" + xPortType + "'"); } mDbgConnector.SetConnectionHandler(DebugConnectorConnected); mDbgConnector.CmdBreak += new Action <UInt32>(DbgCmdBreak); mDbgConnector.CmdTrace += new Action <UInt32>(DbgCmdTrace); mDbgConnector.CmdText += new Action <string>(DbgCmdText); mDbgConnector.CmdSimpleNumber += new Action <uint>(DbgCmdSimpleNumber); mDbgConnector.CmdKernelPanic += new Action <uint>(DbgCmdKernelPanic); mDbgConnector.CmdSimpleLongNumber += new Action <ulong>(DbgCmdSimpleLongNumber); mDbgConnector.CmdComplexNumber += new Action <float>(DbgCmdComplexNumber); mDbgConnector.CmdComplexLongNumber += new Action <double>(DbgCmdComplexLongNumber); mDbgConnector.CmdStarted += new Action(DbgCmdStarted); mDbgConnector.OnDebugMsg += new Action <string>(DebugMsg); mDbgConnector.ConnectionLost += new Action <Exception>(DbgConnector_ConnectionLost); mDbgConnector.CmdRegisters += new Action <byte[]>(DbgCmdRegisters); mDbgConnector.CmdFrame += new Action <byte[]>(DbgCmdFrame); mDbgConnector.CmdStack += new Action <byte[]>(DbgCmdStack); mDbgConnector.CmdPong += new Action <byte[]>(DbgCmdPong); mDbgConnector.CmdStackCorruptionOccurred += DbgCmdStackCorruptionOccurred; mDbgConnector.CmdStackOverflowOccurred += DbgCmdStackOverflowOccurred; mDbgConnector.CmdNullReferenceOccurred += DbgCmdNullReferenceOccurred; mDbgConnector.CmdMessageBox += DbgCmdMessageBox; mDbgConnector.CmdChannel += DbgCmdChannel; }
// this file contains code handling situations when a kernel is running // most of this is debug stub related private void InitializeDebugConnector(DebugConnector debugConnector) { if (debugConnector == null) { throw new ArgumentNullException("debugConnector"); } debugConnector.OnDebugMsg = s => OutputHandler.LogDebugMessage(s); debugConnector.ConnectionLost = ex => { OutputHandler.LogError($"DC: Connection lost. {ex.Message}"); }; debugConnector.CmdChannel = ChannelPacketReceived; debugConnector.CmdStarted = () => { OutputHandler.LogMessage("DC: Started"); debugConnector.SendCmd(Vs2Ds.BatchEnd); }; debugConnector.Error = e => { OutputHandler.LogMessage("DC Error: " + e.ToString()); OutputHandler.SetKernelTestResult(false, "DC Error"); mKernelResultSet = true; mKernelRunning = false; }; debugConnector.CmdText += s => OutputHandler.LogMessage("Text from kernel: " + s); debugConnector.CmdSimpleNumber += n => OutputHandler.LogMessage("Number from kernel: 0x" + n.ToString("X8").ToUpper()); debugConnector.CmdSimpleLongNumber += n => OutputHandler.LogMessage("Number from kernel: 0x" + n.ToString("X16").ToUpper()); debugConnector.CmdComplexNumber += f => OutputHandler.LogMessage("Number from kernel: 0x" + f.ToString("X8").ToUpper()); debugConnector.CmdComplexLongNumber += d => OutputHandler.LogMessage("Number from kernel: 0x" + d.ToString("X16").ToUpper()); debugConnector.CmdMessageBox = s => OutputHandler.LogMessage("MessageBox from kernel: " + s); debugConnector.CmdKernelPanic = n => { OutputHandler.LogMessage("Kernel panic! Nummer = " + n); // todo: add core dump here, call stack. }; debugConnector.CmdTrace = t => { }; debugConnector.CmdBreak = t => { }; debugConnector.CmdStackCorruptionOccurred = a => { OutputHandler.LogMessage("Stackcorruption occurred at: 0x" + a.ToString("X8")); OutputHandler.SetKernelTestResult(false, "Stackcorruption occurred at: 0x" + a.ToString("X8")); mKernelResultSet = true; mKernelRunning = false; }; debugConnector.CmdStackOverflowOccurred = a => { OutputHandler.LogMessage("Stack overflow occurred at: 0x" + a.ToString("X8")); OutputHandler.SetKernelTestResult(false, "Stack overflow occurred at: 0x" + a.ToString("X8")); mKernelResultSet = true; mKernelRunning = false; }; debugConnector.CmdNullReferenceOccurred = a => { OutputHandler.LogMessage("Null Reference Exception occurred at: 0x" + a.ToString("X8")); OutputHandler.SetKernelTestResult(false, "Null Reference Exception occurred at: 0x" + a.ToString("X8")); mKernelResultSet = true; mKernelRunning = false; }; debugConnector.CmdCoreDump = b => { string xCallStack = ""; int i = 0; OutputHandler.LogMessage("Core dump:"); string eax = "EAX = 0x" + b[i + 3].ToString("X2") + b[i + 2].ToString("X2") + b[i + 0].ToString("X2") + b[i + 1].ToString("X2"); i += 4; string ebx = "EBX = 0x" + b[i + 3].ToString("X2") + b[i + 2].ToString("X2") + b[i + 0].ToString("X2") + b[i + 1].ToString("X2"); i += 4; string ecx = "ECX = 0x" + b[i + 3].ToString("X2") + b[i + 2].ToString("X2") + b[i + 0].ToString("X2") + b[i + 1].ToString("X2"); i += 4; string edx = "EDX = 0x" + b[i + 3].ToString("X2") + b[i + 2].ToString("X2") + b[i + 0].ToString("X2") + b[i + 1].ToString("X2"); i += 4; string edi = "EDI = 0x" + b[i + 3].ToString("X2") + b[i + 2].ToString("X2") + b[i + 0].ToString("X2") + b[i + 1].ToString("X2"); i += 4; string esi = "ESI = 0x" + b[i + 3].ToString("X2") + b[i + 2].ToString("X2") + b[i + 0].ToString("X2") + b[i + 1].ToString("X2"); i += 4; string ebp = "EBP = 0x" + b[i + 3].ToString("X2") + b[i + 2].ToString("X2") + b[i + 0].ToString("X2") + b[i + 1].ToString("X2"); i += 4; string eip = "EIP = 0x" + b[i + 3].ToString("X2") + b[i + 2].ToString("X2") + b[i + 0].ToString("X2") + b[i + 1].ToString("X2"); i += 4; string esp = "ESP = 0x" + b[i + 3].ToString("X2") + b[i + 2].ToString("X2") + b[i + 0].ToString("X2") + b[i + 1].ToString("X2"); i += 4; OutputHandler.LogMessage(eax + " " + ebx + " " + ecx + " " + edx); OutputHandler.LogMessage(edi + " " + esi); OutputHandler.LogMessage(ebp + " " + esp + " " + eip); OutputHandler.LogMessage(""); while (i < b.Length) { string xAddress = "0x" + b[i + 3].ToString("X2") + b[i + 2].ToString("X2") + b[i + 0].ToString("X2") + b[i + 1].ToString("X2"); xCallStack += xAddress + " "; if ((i != 0) && (i % 12 == 0)) { OutputHandler.LogMessage(xCallStack.Trim()); xCallStack = ""; } i += 4; } if (xCallStack != "") { OutputHandler.LogMessage(xCallStack.Trim()); xCallStack = ""; } }; if (RunWithGDB) { debugConnector.CmdInterruptOccurred = a => { OutputHandler.LogMessage($"Interrupt {a} occurred"); }; } }
private void InitializeDebugConnector(DebugConnector aDebugConnector) { void LogMessage(string aMessage) => OutputHandler.LogMessage(aMessage); void AbortTestAndLogError(string aMessage) { OutputHandler.LogError(aMessage); mKernelRunning = false; } void AbortTestAndLogException(Exception aException, string aMessage) { OutputHandler.LogError(aMessage); OutputHandler.UnhandledException(aException); mKernelRunning = false; } if (aDebugConnector == null) { throw new ArgumentNullException(nameof(aDebugConnector)); } aDebugConnector.OnDebugMsg = s => OutputHandler.LogDebugMessage(s); aDebugConnector.ConnectionLost = e => AbortTestAndLogException(e, "DC: Connection lost."); aDebugConnector.CmdChannel = (a1, a2, a3) => ChannelPacketReceived(a1, a2, a3); aDebugConnector.CmdStarted = () => { LogMessage("DC: Started"); aDebugConnector.SendCmd(Vs2Ds.BatchEnd); }; aDebugConnector.Error = e => AbortTestAndLogException(e, "DC Error."); aDebugConnector.CmdText += s => LogMessage("Text from kernel: " + s); aDebugConnector.CmdSimpleNumber += n => LogMessage( "Number from kernel: 0x" + n.ToString("X8").ToUpper()); aDebugConnector.CmdSimpleLongNumber += n => LogMessage( "Number from kernel: 0x" + n.ToString("X16").ToUpper()); aDebugConnector.CmdComplexNumber += f => { try { LogMessage( "Number from kernel: 0x" + f.ToString("X8").ToUpper()); } catch (Exception e) { } }; aDebugConnector.CmdComplexLongNumber += d => LogMessage( "Number from kernel: 0x" + d.ToString("X16").ToUpper()); aDebugConnector.CmdMessageBox = s => LogMessage( "MessageBox from kernel: " + s); aDebugConnector.CmdKernelPanic = n => { LogMessage("Kernel panic! Number = " + n); // todo: add core dump here, call stack. }; aDebugConnector.CmdTrace = t => { }; aDebugConnector.CmdBreak = t => { }; aDebugConnector.CmdStackCorruptionOccurred = a => AbortTestAndLogError( "Stackcorruption occurred at: 0x" + a.ToString("X8")); aDebugConnector.CmdStackOverflowOccurred = a => AbortTestAndLogError( "Stack overflow occurred at: 0x" + a.ToString("X8")); aDebugConnector.CmdNullReferenceOccurred = a => AbortTestAndLogError( "Null Reference Exception occurred at: 0x" + a.ToString("X8")); aDebugConnector.CmdCoreDump = dump => { if (dump == null) { OutputHandler.LogMessage("Attempted to dump core but didnt get enough data;"); return; } OutputHandler.LogMessage("Core dump:"); string eax = "EAX = 0x" + dump.EAX.ToString("X8"); string ebx = "EBX = 0x" + dump.EBX.ToString("X8"); string ecx = "ECX = 0x" + dump.ECX.ToString("X8"); string edx = "EDX = 0x" + dump.EDX.ToString("X8"); string edi = "EDI = 0x" + dump.EDI.ToString("X8"); string esi = "ESI = 0x" + dump.ESI.ToString("X8"); string ebp = "EBP = 0x" + dump.EBP.ToString("X8"); string esp = "ESP = 0x" + dump.ESP.ToString("X8"); string eip = "EIP = 0x" + dump.EIP.ToString("X8"); OutputHandler.LogMessage(eax + " " + ebx + " " + ecx + " " + edx); OutputHandler.LogMessage(edi + " " + esi); OutputHandler.LogMessage(ebp + " " + esp + " " + eip); OutputHandler.LogMessage(""); OutputHandler.LogMessage("Call stack:"); OutputHandler.LogMessage(""); while (dump.StackTrace.Count > 0) { var xAddress = "0x" + dump.StackTrace.Pop().ToString("X8"); OutputHandler.LogMessage("at " + xAddress); } OutputHandler.LogMessage(""); }; if (RunWithGDB) { aDebugConnector.CmdInterruptOccurred = a => { OutputHandler.LogMessage($"Interrupt {a} occurred"); }; } }