public static TargetClassObject ToClassObject(MdbEvaluationContext ctx, TargetObject obj) { TargetClassObject cobj = obj as TargetClassObject; if (cobj != null) { return(cobj); } TargetObjectObject oobj = obj as TargetObjectObject; if (oobj != null) { return(oobj.GetClassObject(ctx.Thread)); } TargetArrayObject aobj = obj as TargetArrayObject; if ((aobj != null) && aobj.HasClassObject) { return(aobj.GetClassObject(ctx.Thread)); } return(null); }
static TargetObject ImplicitReferenceConversion(MdbEvaluationContext ctx, TargetClassObject obj, TargetClassType type) { if (obj.Type == type) { return(obj); } if (obj.Type.HasParent) { TargetObject pobj = obj.GetParentObject(ctx.Thread); if (pobj != null) { pobj = ImplicitConversion(ctx, pobj, type); if (pobj != null) { return(pobj); } } } if (ImplicitReferenceConversionExists(ctx, obj.Type, type)) { return(obj); } return(null); }
protected void FormatClassObject(Thread target, TargetClassObject obj, TargetClass class_info, ref bool first) { Append("{ "); indent_level += 3; if (obj.Type.HasParent) { TargetClassObject parent = obj.GetParentObject(target); if ((parent != null) && (parent.Type != parent.Type.Language.ObjectType)) { Append("<{0}> = ", parent.Type.Name); CheckLineWrap(); FormatStructObject(target, parent); first = false; } } TargetFieldInfo[] fields = class_info.GetFields(target); for (int i = 0; i < fields.Length; i++) { if (fields [i].IsStatic || fields [i].HasConstValue) { continue; } if (fields [i].IsCompilerGenerated) { continue; } if (fields [i].DebuggerBrowsableState == DebuggerBrowsableState.Never) { continue; } if (!first) { Append(", "); CheckLineWrap(); } first = false; Append(fields [i].Name + " = "); try { TargetObject fobj = class_info.GetField(target, obj, fields [i]); if (fobj == null) { Append("null"); } else { FormatObjectRecursed(target, fobj, true); } } catch { Append("<cannot display object>"); } } Append(first ? "}" : " }"); indent_level -= 3; }
protected void FormatStructObject(Thread target, TargetClassObject obj) { bool first = true; TargetClass class_info = obj.Type.GetClass(target); if (class_info != null) { FormatClassObject(target, obj, class_info, ref first); } }
static TargetStructObject TryCurrentCast(MdbEvaluationContext ctx, TargetClassObject source, TargetClassType target_type) { TargetStructObject current = source.GetCurrentObject(ctx.Thread); if (current == null) { return(null); } return(TryParentCast(ctx, current, current.Type, target_type)); }
public void Main() { Process process = Start(); Assert.IsTrue(process.IsManaged); Assert.IsTrue(process.MainThread.IsStopped); Thread thread = process.MainThread; AssertStopped(thread, "main", "X.Main()"); AssertExecute("continue"); AssertHitBreakpoint(thread, "main2", "X.Main()"); TargetClassObject a = EvaluateExpression(thread, "a") as TargetClassObject; TargetClassObject b = EvaluateExpression(thread, "b") as TargetClassObject; Assert.IsTrue(a != null); Assert.IsTrue(b != null); string text; EE.EvaluationResult result; result = EE.MonoObjectToString(thread, a, EE.EvaluationFlags.None, 500, out text); if (result != ExpressionEvaluator.EvaluationResult.Ok) { Assert.Fail("Failed to print `a': got result {0}", result); } if (text != "Foo (3)") { Assert.Fail("Failed to print `a': got result {0}", text); } result = EE.MonoObjectToString(thread, b, EE.EvaluationFlags.None, 500, out text); if (result != EE.EvaluationResult.Timeout) { Assert.Fail("Failed to print `a': got result {0}", result); } AssertExecute("continue"); AssertTargetOutput("TEST: Foo (3) Foo (8)"); AssertTargetExited(thread.Process); }
internal bool CheckException(MonoLanguageBackend mono, TargetMemoryAccess target, TargetAddress address) { TargetClassObject exc = mono.CreateObject(target, address) as TargetClassObject; if (exc == null) { return(false); // OOOPS } if (exception == null) { exception = mono.LookupType(Name); } if (exception == null) { return(false); } return(IsSubclassOf(target, exc.Type, exception)); }
AbstractVariable[] GetChildNodes() { ArrayList nodes = new ArrayList(); TargetClassObject parent = obj.GetParentObject(stackFrame.Thread); if (parent != null && parent.Type != parent.Type.Language.ObjectType) { nodes.Add(new ClassVariable("<Base class>", stackFrame, parent)); } if (obj.Type.StaticFields.Length > 0) { nodes.Add(new StaticMembers(this)); } nodes.AddRange(FieldsToNodes(obj.Type.Fields)); return((AbstractVariable[])nodes.ToArray(typeof(AbstractVariable))); }
string MonoObjectToString(TargetClassObject obj) { TargetClassType ctype = obj.Type; if ((ctype.Name == "System.Object") || (ctype.Name == "System.ValueType")) { return(null); } string text, dummy; EE.EvaluationResult result; if (ctype.DebuggerDisplayAttribute != null) { result = HandleDebuggerDisplay(Interpreter, CurrentThread, obj, ctype.DebuggerDisplayAttribute, -1, out text, out dummy); if (result == EE.EvaluationResult.Ok) { return(String.Format("{{ {0} }}", text)); } else if (result == EE.EvaluationResult.InvalidExpression) { if (text != null) { return(text); } } } result = EE.MonoObjectToString(CurrentThread, obj, EE.EvaluationFlags.None, -1, out text); if (result == EE.EvaluationResult.Ok) { return(String.Format("{{ \"{0}\" }}", text)); } return(null); }
string DoFormatObject(TargetObject obj, DisplayFormat format) { if (format == DisplayFormat.Object) { TargetClassObject cobj = obj as TargetClassObject; if (cobj != null) { string formatted = MonoObjectToString(cobj); if (formatted != null) { return(formatted); } TargetObject proxy = CheckTypeProxy(cobj); if (proxy != null) { obj = proxy; } } } return(CurrentThread.PrintObject(interpreter.Style, obj, format)); }
public static TargetObject TryCast(MdbEvaluationContext ctx, TargetObject source, TargetClassType target_type) { if (source.Type == target_type) { return(source); } TargetClassObject sobj = ToClassObject(ctx, source); if (sobj == null) { return(null); } TargetStructObject result = TryParentCast(ctx, sobj, sobj.Type, target_type); if (result != null) { return(result); } return(TryCurrentCast(ctx, sobj, target_type)); }
public TargetObject GetVariable(StackFrame frame, TargetMemoryAccess target, string name) { TargetObject obj = GetObject(frame, target); if ((obj == null) || (obj is TargetNullObject)) { return(null); } TargetClassObject sobj = (TargetClassObject)obj; foreach (TargetFieldInfo field in fields) { if (field.Name != name) { continue; } return(klass.GetInstanceField(target, sobj, field)); } return(null); }
public ClassVariable(string name, StackFrame stackFrame, TargetClassObject obj) { this.name = name; this.stackFrame = stackFrame; this.obj = obj; }
public static TargetObject Cast(MdbEvaluationContext ctx, TargetObject obj, TargetType targetType) { obj = ObjectUtil.GetRealObject(ctx, obj); if (obj.Type == targetType) { return(obj); } if (targetType is TargetObjectType || ObjectUtil.FixTypeName(targetType.Name) == "System.Object") { if (obj.Type.IsByRef) { return(obj); } return(BoxValue(ctx, obj)); } if (targetType is TargetPointerType) { throw new NotSupportedException(); } if (targetType is TargetFundamentalType) { TargetFundamentalObject fobj = obj as TargetFundamentalObject; if (fobj == null) { throw new NotSupportedException(); } TargetFundamentalType ftype = targetType as TargetFundamentalType; TargetObject ob = ExplicitFundamentalConversion(ctx, fobj, ftype); if (ob == null) { throw new NotSupportedException(); } return(ob); } if (targetType is TargetNullableType) { TargetNullableType ntype = (TargetNullableType)targetType; if (obj.Kind == TargetObjectKind.Null) { return(obj); } else if (obj.Kind != TargetObjectKind.Nullable) { return(ImplicitConversion(ctx, obj, ntype.ElementType)); } TargetNullableType ntype2 = (TargetNullableType)obj.Type; if (ImplicitConversionExists(ctx, ntype2.ElementType, ntype.ElementType)) { return(obj); } } TargetClassType ctype = ToClassType(targetType); TargetClassObject source = ToClassObject(ctx, obj); if (source == null) { throw new Exception(string.Format("Variable is not a class type.")); } return(TryCast(ctx, source, ctype)); }