diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs index 7e977edb33..97bd9e1c3a 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs @@ -234,24 +234,32 @@ namespace Debugger internal static ICorDebugValue DereferenceUnbox(ICorDebugValue corValue) { - if (corValue.Is()) { - int isNull = corValue.CastTo().IsNull; - if (isNull == 0) { - ICorDebugValue dereferencedValue; + // Method arguments can be passed 'by ref' + if (corValue.Type == (uint)CorElementType.BYREF) { + corValue = corValue.CastTo().Dereference(); + } + + // Pointers may be used in 'unsafe' code - CorElementType.PTR + // Classes need to be dereferenced + while (corValue.Is()) { + ICorDebugReferenceValue refValue = corValue.CastTo(); + if (refValue.IsNull != 0) { + return null; // Reference is null + } else { try { - dereferencedValue = (corValue.CastTo()).Dereference(); + corValue = refValue.Dereference(); + // TODO: Investigate: Must not acutally be null + // eg. Assembly.AssemblyHandle See SD2-1117 + if (corValue == null) return null; // Dereference() returned null } catch { - // Error during dereferencing - return null; + return null; // Error during dereferencing } - return DereferenceUnbox(dereferencedValue); // Try again - } else { - return null; } } + // Unbox value types if (corValue.Is()) { - return DereferenceUnbox(corValue.CastTo().Object.CastTo()); // Try again + corValue = corValue.CastTo().Object.CastTo(); } return corValue; @@ -360,8 +368,13 @@ namespace Debugger more.Add(new VariableCollection("isNull", isNull.ToString())); if (!isNull) { more.Add(new VariableCollection("address", refValue.Value.ToString("X"))); - VariableCollection deRef = GetDebugInfo(refValue.Dereference()); - more.Add(new VariableCollection("dereferenced", deRef.Value, deRef.SubCollections, deRef.Items)); + if (refValue.Dereference() != null) { + VariableCollection deRef = GetDebugInfo(refValue.Dereference()); + more.Add(new VariableCollection("dereferenced", deRef.Value, deRef.SubCollections, deRef.Items)); + } else { + more.Add(new VariableCollection("dereferenced", "N/A", null, null)); + } + } items.Add(new VariableCollection("ICorDebugReferenceValue", "", more, null)); }