From fc9f33acdafa20139854da6af8e9351694c92eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro?= Date: Sun, 18 Jun 2017 02:04:59 +0100 Subject: [PATCH] Improved the NullReferenceException message. --- source/Cosmos.Debug.Symbols/DebugInfo.cs | 5 ++++ .../AD7.Impl/AD7Process.cs | 25 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/source/Cosmos.Debug.Symbols/DebugInfo.cs b/source/Cosmos.Debug.Symbols/DebugInfo.cs index d50db1a1c..8b664201d 100644 --- a/source/Cosmos.Debug.Symbols/DebugInfo.cs +++ b/source/Cosmos.Debug.Symbols/DebugInfo.cs @@ -772,6 +772,11 @@ namespace Cosmos.Debug.Symbols return address; } + public Document GetDocumentById(long aDocumentId) + { + return mConnection.Get(aDocumentId); + } + public MethodIlOp GetFirstMethodIlOpByMethodIdAndILOffset(long aMethodId, long aILOffset) { //Debug("GetFirstMethodIlOpByMethodIdAndILOffset. MethodID = {0}, ILOffset = 0x{1}", aMethodId, aILOffset.ToString("X4")); diff --git a/source/Cosmos.VS.DebugEngine/AD7.Impl/AD7Process.cs b/source/Cosmos.VS.DebugEngine/AD7.Impl/AD7Process.cs index 0d8e74a21..4255c7a59 100644 --- a/source/Cosmos.VS.DebugEngine/AD7.Impl/AD7Process.cs +++ b/source/Cosmos.VS.DebugEngine/AD7.Impl/AD7Process.cs @@ -381,6 +381,27 @@ namespace Cosmos.VS.DebugEngine.AD7.Impl private void DbgCmdNullReferenceOccurred(uint lastEIPAddress) { + if (mDebugInfo.TryGetValue(BuildPropertyNames.DebugModeString, out var xDebugMode)) + { + if (xDebugMode == "Source") + { + try + { + var xMethod = mDebugInfoDb.GetMethod(lastEIPAddress); + var xLabel = mDebugInfoDb.GetLabels(lastEIPAddress)[0]; + var xMethodIlOp = mDebugInfoDb.TryGetFirstMethodIlOpByLabelName(xLabel.Remove(xLabel.LastIndexOf('.'))).IlOffset; + var xSequencePoints = mDebugInfoDb.GetSequencePoints(mDebugInfoDb.GetAssemblyFileById(xMethod.AssemblyFileID).Pathname, xMethod.MethodToken); + var xLine = xSequencePoints.Where(q => q.Offset <= xMethodIlOp).Last().LineStart; + + AD7Util.MessageBox($"NullReferenceException occurred in '{xMethod.LabelCall}'{Environment.NewLine}Document: {mDebugInfoDb.GetDocumentById(xMethod.DocumentID)}{Environment.NewLine}Line: {xLine}{Environment.NewLine}Address: 0x{lastEIPAddress.ToString("X8")}"); + return; + } + catch (InvalidOperationException) + { + } + } + } + AD7Util.MessageBox(String.Format("NullReferenceException occurred at address 0x{0:X8}! Halting now.", lastEIPAddress)); } @@ -427,7 +448,7 @@ namespace Cosmos.VS.DebugEngine.AD7.Impl switch (mLaunch) { case LaunchType.VMware: -#region CheckIfHyperVServiceIsRunning + #region CheckIfHyperVServiceIsRunning using (System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("vmms")) { @@ -447,7 +468,7 @@ namespace Cosmos.VS.DebugEngine.AD7.Impl } } -#endregion CheckIfHyperVServiceIsRunning + #endregion CheckIfHyperVServiceIsRunning mHost = new VMware(mDebugInfo, xUseGDB); break;