internal Value(Process process, Expression expression, ICorDebugValue corValue) { if (corValue == null) { throw new ArgumentNullException("corValue"); } this.process = process; this.expression = expression; this.corValue = corValue; this.corValue_pauseSession = process.PauseSession; if (corValue.Is <ICorDebugReferenceValue>() && corValue.CastTo <ICorDebugReferenceValue>().Value == 0 && corValue.CastTo <ICorDebugValue2>().ExactType == null) { // We were passed null reference and no metadata description // (happens during CreateThread callback for the thread object) this.type = DebugType.Create(this.Process, null, "System.Object"); } else { ICorDebugType exactType = this.CorValue.CastTo <ICorDebugValue2>().ExactType; this.type = DebugType.Create(this.Process, exactType); } }
internal static ICorDebugValue DereferenceUnbox(ICorDebugValue corValue) { // Method arguments can be passed 'by ref' if (corValue.Type == (uint)CorElementType.BYREF) { corValue = corValue.CastTo<ICorDebugReferenceValue>().Dereference(); } // Pointers may be used in 'unsafe' code - CorElementType.PTR // Classes need to be dereferenced while (corValue.Is<ICorDebugReferenceValue>()) { ICorDebugReferenceValue refValue = corValue.CastTo<ICorDebugReferenceValue>(); if (refValue.IsNull != 0) { return null; // Reference is null } else { try { 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 { return null; // Error during dereferencing } } } // if (corValue.Is<ICorDebugHeapValue2>()) // corValue = corValue.CastTo<ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo<ICorDebugValue>(); // Unbox value types if (corValue.Is<ICorDebugBoxValue>()) { corValue = corValue.CastTo<ICorDebugBoxValue>().Object.CastTo<ICorDebugValue>(); } return corValue; }
public Value GetPermanentReference() { ICorDebugValue corValue = this.CorValue; if (this.Type.IsClass) { corValue = this.CorObjectValue.CastTo <ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo <ICorDebugValue>(); } if (this.Type.IsValueType || this.Type.IsPrimitive) { if (!corValue.Is <ICorDebugReferenceValue>()) { // Box the value type if (this.Type.IsPrimitive) { // Get value type for the primive type object o = this.PrimitiveValue; corValue = Eval.NewObjectNoConstructor(DebugType.Create(process, null, this.Type.FullName)).RawCorValue; this.SetPrimitiveValue(o); } else { corValue = Eval.NewObjectNoConstructor(this.Type).RawCorValue; } // Make the reference to box permanent corValue = corValue.CastTo <ICorDebugReferenceValue>().Dereference().CastTo <ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo <ICorDebugValue>(); // Create new value Value newValue = new Value(process, new IExpirable[] {}, new IMutable[] {}, delegate { return(corValue); }); // Copy the data inside the box newValue.CorGenericValue.RawValue = this.CorGenericValue.RawValue; return(newValue); } else { // Make the reference to box permanent corValue = corValue.CastTo <ICorDebugReferenceValue>().Dereference().CastTo <ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo <ICorDebugValue>(); } } return(new Value(process, new IExpirable[] {}, new IMutable[] {}, delegate { return corValue; })); }
public void SetValue(Value newValue) { ICorDebugValue corValue = this.CorValue; ICorDebugValue newCorValue = newValue.CorValue; if (corValue.Is <ICorDebugReferenceValue>()) { if (newCorValue.Is <ICorDebugObjectValue>()) { ICorDebugValue box = Eval.NewObjectNoConstructor(newValue.Type).CorValue; newCorValue = box; } corValue.CastTo <ICorDebugReferenceValue>().SetValue(newCorValue.CastTo <ICorDebugReferenceValue>().Value); } else { corValue.CastTo <ICorDebugGenericValue>().RawValue = newCorValue.CastTo <ICorDebugGenericValue>().RawValue; } }
internal static ICorDebugValue DereferenceUnbox(ICorDebugValue corValue) { // Method arguments can be passed 'by ref' if (corValue.Type == (uint)CorElementType.BYREF) { corValue = corValue.CastTo <ICorDebugReferenceValue>().Dereference(); } // Pointers may be used in 'unsafe' code - CorElementType.PTR // Classes need to be dereferenced while (corValue.Is <ICorDebugReferenceValue>()) { ICorDebugReferenceValue refValue = corValue.CastTo <ICorDebugReferenceValue>(); if (refValue.IsNull != 0) { return(null); // Reference is null } else { try { 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 { return(null); // Error during dereferencing } } } // if (corValue.Is<ICorDebugHeapValue2>()) // corValue = corValue.CastTo<ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo<ICorDebugValue>(); // Unbox value types if (corValue.Is <ICorDebugBoxValue>()) { corValue = corValue.CastTo <ICorDebugBoxValue>().Object.CastTo <ICorDebugValue>(); } return(corValue); }
Value Box() { byte[] rawValue = this.CorGenericValue.RawValue; // Box the value type ICorDebugValue corValue; if (this.Type.IsPrimitive) { // Get value type for the primive type corValue = Eval.NewObjectNoConstructor(DebugType.Create(process, null, this.Type.FullName)).CorValue; } else { corValue = Eval.NewObjectNoConstructor(this.Type).CorValue; } // Make the reference to box permanent corValue = corValue.CastTo <ICorDebugReferenceValue>().Dereference().CastTo <ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo <ICorDebugValue>(); // Create new value Value newValue = new Value(process, expression, corValue); // Copy the data inside the box newValue.CorGenericValue.RawValue = rawValue; return(newValue); }
/// <summary> Copy the acutal value from some other Value object </summary> public void SetValue(Value newValue) { ICorDebugValue newCorValue = newValue.CorValue; if (this.IsReference) { if (!newCorValue.Is <ICorDebugReferenceValue>()) { newCorValue = newValue.Box().CorValue; } corValue.CastTo <ICorDebugReferenceValue>().SetValue(newCorValue.CastTo <ICorDebugReferenceValue>().Value); } else { corValue.CastTo <ICorDebugGenericValue>().RawValue = newValue.CorGenericValue.RawValue; } }
public static List<AbstractNode> GetDebugInfo(Process process, ICorDebugValue corValue) { List<AbstractNode> items = new List<AbstractNode>(); if (corValue.Is<ICorDebugValue>()) { InfoNode info = new InfoNode("ICorDebugValue", ""); info.AddChild("Address", corValue.Address.ToString("X8")); info.AddChild("Type", ((CorElementType)corValue.Type).ToString()); info.AddChild("Size", corValue.Size.ToString()); items.Add(info); } if (corValue.Is<ICorDebugValue2>()) { InfoNode info = new InfoNode("ICorDebugValue2", ""); ICorDebugValue2 corValue2 = corValue.CastTo<ICorDebugValue2>(); string fullname; try { fullname = DebugType.Create(process, corValue2.ExactType).FullName; } catch (DebuggerException e) { fullname = e.Message; } info.AddChild("ExactType", fullname); items.Add(info); } if (corValue.Is<ICorDebugGenericValue>()) { InfoNode info = new InfoNode("ICorDebugGenericValue", ""); try { byte[] bytes = corValue.CastTo<ICorDebugGenericValue>().RawValue; for(int i = 0; i < bytes.Length; i += 8) { string val = ""; for(int j = i; j < bytes.Length && j < i + 8; j++) { val += bytes[j].ToString("X2") + " "; } info.AddChild("Value" + i.ToString("X2"), val); } } catch (ArgumentException) { info.AddChild("Value", "N/A"); } items.Add(info); } if (corValue.Is<ICorDebugReferenceValue>()) { InfoNode info = new InfoNode("ICorDebugReferenceValue", ""); ICorDebugReferenceValue refValue = corValue.CastTo<ICorDebugReferenceValue>(); info.AddChild("IsNull", (refValue.IsNull != 0).ToString()); if (refValue.IsNull == 0) { info.AddChild("Value", refValue.Value.ToString("X8")); if (refValue.Dereference() != null) { info.AddChild("Dereference", "", GetDebugInfo(process, refValue.Dereference())); } else { info.AddChild("Dereference", "N/A"); } } items.Add(info); } if (corValue.Is<ICorDebugHeapValue>()) { InfoNode info = new InfoNode("ICorDebugHeapValue", ""); items.Add(info); } if (corValue.Is<ICorDebugHeapValue2>()) { InfoNode info = new InfoNode("ICorDebugHeapValue2", ""); items.Add(info); } if (corValue.Is<ICorDebugObjectValue>()) { InfoNode info = new InfoNode("ICorDebugObjectValue", ""); ICorDebugObjectValue objValue = corValue.CastTo<ICorDebugObjectValue>(); info.AddChild("Class", objValue.Class.Token.ToString("X8")); info.AddChild("IsValueClass", (objValue.IsValueClass != 0).ToString()); items.Add(info); } if (corValue.Is<ICorDebugObjectValue2>()) { InfoNode info = new InfoNode("ICorDebugObjectValue2", ""); items.Add(info); } if (corValue.Is<ICorDebugBoxValue>()) { InfoNode info = new InfoNode("ICorDebugBoxValue", ""); ICorDebugBoxValue boxValue = corValue.CastTo<ICorDebugBoxValue>(); info.AddChild("Object", "", GetDebugInfo(process, boxValue.Object.CastTo<ICorDebugValue>())); items.Add(info); } if (corValue.Is<ICorDebugStringValue>()) { InfoNode info = new InfoNode("ICorDebugStringValue", ""); ICorDebugStringValue stringValue = corValue.CastTo<ICorDebugStringValue>(); info.AddChild("Length", stringValue.Length.ToString()); info.AddChild("String", stringValue.String); items.Add(info); } if (corValue.Is<ICorDebugArrayValue>()) { InfoNode info = new InfoNode("ICorDebugArrayValue", ""); info.AddChild("...", "..."); items.Add(info); } if (corValue.Is<ICorDebugHandleValue>()) { InfoNode info = new InfoNode("ICorDebugHandleValue", ""); ICorDebugHandleValue handleValue = corValue.CastTo<ICorDebugHandleValue>(); info.AddChild("HandleType", handleValue.HandleType.ToString()); items.Add(info); } return items; }
public static List <AbstractNode> GetDebugInfo(Process process, ICorDebugValue corValue) { List <AbstractNode> items = new List <AbstractNode>(); if (corValue.Is <ICorDebugValue>()) { InfoNode info = new InfoNode("ICorDebugValue", ""); info.AddChild("Address", corValue.Address.ToString("X8")); info.AddChild("Type", ((CorElementType)corValue.Type).ToString()); info.AddChild("Size", corValue.Size.ToString()); items.Add(info); } if (corValue.Is <ICorDebugValue2>()) { InfoNode info = new InfoNode("ICorDebugValue2", ""); ICorDebugValue2 corValue2 = corValue.CastTo <ICorDebugValue2>(); string fullname; try { fullname = DebugType.Create(process, corValue2.ExactType).FullName; } catch (DebuggerException e) { fullname = e.Message; } info.AddChild("ExactType", fullname); items.Add(info); } if (corValue.Is <ICorDebugGenericValue>()) { InfoNode info = new InfoNode("ICorDebugGenericValue", ""); try { byte[] bytes = corValue.CastTo <ICorDebugGenericValue>().RawValue; for (int i = 0; i < bytes.Length; i += 8) { string val = ""; for (int j = i; j < bytes.Length && j < i + 8; j++) { val += bytes[j].ToString("X2") + " "; } info.AddChild("Value" + i.ToString("X2"), val); } } catch (ArgumentException) { info.AddChild("Value", "N/A"); } items.Add(info); } if (corValue.Is <ICorDebugReferenceValue>()) { InfoNode info = new InfoNode("ICorDebugReferenceValue", ""); ICorDebugReferenceValue refValue = corValue.CastTo <ICorDebugReferenceValue>(); info.AddChild("IsNull", (refValue.IsNull != 0).ToString()); if (refValue.IsNull == 0) { info.AddChild("Value", refValue.Value.ToString("X8")); if (refValue.Dereference() != null) { info.AddChild("Dereference", "", GetDebugInfo(process, refValue.Dereference())); } else { info.AddChild("Dereference", "N/A"); } } items.Add(info); } if (corValue.Is <ICorDebugHeapValue>()) { InfoNode info = new InfoNode("ICorDebugHeapValue", ""); items.Add(info); } if (corValue.Is <ICorDebugHeapValue2>()) { InfoNode info = new InfoNode("ICorDebugHeapValue2", ""); items.Add(info); } if (corValue.Is <ICorDebugObjectValue>()) { InfoNode info = new InfoNode("ICorDebugObjectValue", ""); ICorDebugObjectValue objValue = corValue.CastTo <ICorDebugObjectValue>(); info.AddChild("Class", objValue.Class.Token.ToString("X8")); info.AddChild("IsValueClass", (objValue.IsValueClass != 0).ToString()); items.Add(info); } if (corValue.Is <ICorDebugObjectValue2>()) { InfoNode info = new InfoNode("ICorDebugObjectValue2", ""); items.Add(info); } if (corValue.Is <ICorDebugBoxValue>()) { InfoNode info = new InfoNode("ICorDebugBoxValue", ""); ICorDebugBoxValue boxValue = corValue.CastTo <ICorDebugBoxValue>(); info.AddChild("Object", "", GetDebugInfo(process, boxValue.Object.CastTo <ICorDebugValue>())); items.Add(info); } if (corValue.Is <ICorDebugStringValue>()) { InfoNode info = new InfoNode("ICorDebugStringValue", ""); ICorDebugStringValue stringValue = corValue.CastTo <ICorDebugStringValue>(); info.AddChild("Length", stringValue.Length.ToString()); info.AddChild("String", stringValue.String); items.Add(info); } if (corValue.Is <ICorDebugArrayValue>()) { InfoNode info = new InfoNode("ICorDebugArrayValue", ""); info.AddChild("...", "..."); items.Add(info); } if (corValue.Is <ICorDebugHandleValue>()) { InfoNode info = new InfoNode("ICorDebugHandleValue", ""); ICorDebugHandleValue handleValue = corValue.CastTo <ICorDebugHandleValue>(); info.AddChild("HandleType", handleValue.HandleType.ToString()); items.Add(info); } return(items); }
internal Value(Process process, Expression expression, ICorDebugValue corValue) { if (corValue == null) { throw new ArgumentNullException("corValue"); } this.process = process; this.expression = expression; this.corValue = corValue; this.corValue_pauseSession = process.PauseSession; if (corValue.Is<ICorDebugReferenceValue>() && corValue.CastTo<ICorDebugReferenceValue>().Value == 0 && corValue.CastTo<ICorDebugValue2>().ExactType == null) { // We were passed null reference and no metadata description // (happens during CreateThread callback for the thread object) this.type = DebugType.Create(this.Process, null, "System.Object"); } else { ICorDebugType exactType = this.CorValue.CastTo<ICorDebugValue2>().ExactType; this.type = DebugType.Create(this.Process, exactType); } }