diff --git a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/DebuggerHelpers.cs b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/DebuggerHelpers.cs index 31114e777c..10cbf2d79f 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/DebuggerHelpers.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/DebuggerHelpers.cs @@ -39,6 +39,7 @@ namespace Debugger.AddIn.Visualizers.Utils /// public static ulong GetObjectAddress(this Value val) { + if (val.IsNull) return 0; ICorDebugReferenceValue refVal = val.CorReferenceValue; return refVal.GetValue(); } diff --git a/src/AddIns/Debugger/Debugger.Core/Value.cs b/src/AddIns/Debugger/Debugger.Core/Value.cs index 23b56c108d..0e45de64b6 100644 --- a/src/AddIns/Debugger/Debugger.Core/Value.cs +++ b/src/AddIns/Debugger/Debugger.Core/Value.cs @@ -30,6 +30,9 @@ namespace Debugger PauseSession corValue_pauseSession; DebugType type; + // Permanently stored as convinience so that it survives Continue + bool isNull; + /// The appdomain that owns the value public AppDomain AppDomain { get { return appDomain; } @@ -51,8 +54,11 @@ namespace Debugger [Debugger.Tests.Ignore] public ICorDebugReferenceValue CorReferenceValue { get { + if (IsNull) throw new GetValueException("Value is null"); + if (!(this.CorValue is ICorDebugReferenceValue)) throw new DebuggerException("Reference value expected"); + return (ICorDebugReferenceValue)this.CorValue; } } @@ -78,6 +84,7 @@ namespace Debugger public ICorDebugArrayValue CorArrayValue { get { if (IsNull) throw new GetValueException("Value is null"); + if (!this.Type.IsArray) throw new DebuggerException("Value is not an array"); return (ICorDebugArrayValue)this.CorReferenceValue.Dereference(); @@ -125,10 +132,7 @@ namespace Debugger /// Returns true if the value is null public bool IsNull { - get { - return this.CorValue is ICorDebugReferenceValue && - ((ICorDebugReferenceValue)this.CorValue).IsNull() != 0; - } + get { return isNull; } } /// @@ -166,6 +170,8 @@ namespace Debugger this.corValue = corValue; this.corValue_pauseSession = this.Process.PauseSession; + this.isNull = corValue is ICorDebugReferenceValue && ((ICorDebugReferenceValue)corValue).IsNull() != 0; + if (corValue is ICorDebugReferenceValue && ((ICorDebugReferenceValue)corValue).GetValue() == 0 && ((ICorDebugValue2)corValue).GetExactType() == null) @@ -200,8 +206,8 @@ namespace Debugger if (this.CorValue is ICorDebugHandleValue) { return this; } else if (this.CorValue is ICorDebugReferenceValue) { - if (this.CorReferenceValue.IsNull() > 0) - return this; // ("null" expression) TODO: It isn't permanent + if (this.IsNull) + return this; // ("null" expression) It isn't permanent ICorDebugValue deRef = this.CorReferenceValue.Dereference(); if (deRef is ICorDebugHeapValue2) { return new Value(appDomain, ((ICorDebugHeapValue2)deRef).CreateHandle(CorDebugHandleType.HANDLE_STRONG)); @@ -236,7 +242,7 @@ namespace Debugger if (this.CorValue is ICorDebugReferenceValue) { if (!(newCorValue is ICorDebugReferenceValue)) newCorValue = newValue.Box().CorValue; - this.CorReferenceValue.SetValue(((ICorDebugReferenceValue)newCorValue).GetValue()); + ((ICorDebugReferenceValue)this.CorValue).SetValue(((ICorDebugReferenceValue)newCorValue).GetValue()); } else { this.CorGenericValue.SetRawValue(newValue.CorGenericValue.GetRawValue()); } diff --git a/src/AddIns/Debugger/Debugger.Tests/Tests/StackFrame_VariablesLifetime.cs b/src/AddIns/Debugger/Debugger.Tests/Tests/StackFrame_VariablesLifetime.cs index 150566a732..f46e5b7a10 100644 --- a/src/AddIns/Debugger/Debugger.Tests/Tests/StackFrame_VariablesLifetime.cs +++ b/src/AddIns/Debugger/Debugger.Tests/Tests/StackFrame_VariablesLifetime.cs @@ -122,7 +122,6 @@ namespace Debugger.Tests { @@ -131,7 +130,6 @@ namespace Debugger.Tests { @@ -140,7 +138,6 @@ namespace Debugger.Tests { @@ -156,7 +153,6 @@ namespace Debugger.Tests { @@ -165,7 +161,6 @@ namespace Debugger.Tests { @@ -174,7 +169,6 @@ namespace Debugger.Tests { @@ -183,7 +177,6 @@ namespace Debugger.Tests { @@ -193,7 +186,6 @@ namespace Debugger.Tests { @@ -202,7 +194,6 @@ namespace Debugger.Tests { @@ -211,7 +202,6 @@ namespace Debugger.Tests { @@ -220,7 +210,6 @@ namespace Debugger.Tests { @@ -236,7 +225,6 @@ namespace Debugger.Tests { @@ -245,7 +233,6 @@ namespace Debugger.Tests { @@ -254,7 +241,6 @@ namespace Debugger.Tests { @@ -263,7 +249,6 @@ namespace Debugger.Tests {