From 2cd0d32184fc3815ba7cb38c4a3f3356aec0ca71 Mon Sep 17 00:00:00 2001 From: Quajak Date: Thu, 22 Oct 2020 19:38:43 +0200 Subject: [PATCH] Added better handling for incomplete data received when debugging --- Tests/Cosmos.TestRunner.Core/Engine.Running.cs | 5 +++++ .../OutputHandlerFullTextBase.cs | 2 +- .../Cosmos.Debug.DebugConnectors/CoreDump.cs | 18 ++++++++++++------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Tests/Cosmos.TestRunner.Core/Engine.Running.cs b/Tests/Cosmos.TestRunner.Core/Engine.Running.cs index 635ef0a06..5445c1da3 100644 --- a/Tests/Cosmos.TestRunner.Core/Engine.Running.cs +++ b/Tests/Cosmos.TestRunner.Core/Engine.Running.cs @@ -90,6 +90,11 @@ namespace Cosmos.TestRunner.Core aDebugConnector.CmdCoreDump = dump => { + if(dump is 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"); diff --git a/Tests/Cosmos.TestRunner.Core/OutputHandlerFullTextBase.cs b/Tests/Cosmos.TestRunner.Core/OutputHandlerFullTextBase.cs index 8aa9c1ed4..675d44884 100644 --- a/Tests/Cosmos.TestRunner.Core/OutputHandlerFullTextBase.cs +++ b/Tests/Cosmos.TestRunner.Core/OutputHandlerFullTextBase.cs @@ -26,7 +26,7 @@ namespace Cosmos.TestRunner.Core protected override void OnUnhandledException(Exception exception) { - Log("Unhandled exception: " + exception.ToString()); + Log("Unhandled exception: " + exception?.ToString() ?? "Unable to get exception: Exception was null!"); } protected override void OnExecutionEnd() diff --git a/source/Cosmos.Debug.DebugConnectors/CoreDump.cs b/source/Cosmos.Debug.DebugConnectors/CoreDump.cs index 47d78fbf6..5fdf32727 100644 --- a/source/Cosmos.Debug.DebugConnectors/CoreDump.cs +++ b/source/Cosmos.Debug.DebugConnectors/CoreDump.cs @@ -48,12 +48,18 @@ namespace Cosmos.Debug.DebugConnectors { stack.Push(BitConverter.ToUInt32(stackBytes, i)); } - - return new CoreDump( - stack.Pop(), stack.Pop(), stack.Pop(), stack.Pop(), - stack.Pop(), stack.Pop(), - stack.Pop(), stack.Pop(), stack.Pop(), - stack); + if(stack.Count != 9) + { + return null; + } + else + { + return new CoreDump( + stack.Pop(), stack.Pop(), stack.Pop(), stack.Pop(), + stack.Pop(), stack.Pop(), + stack.Pop(), stack.Pop(), stack.Pop(), + stack); + } } } }