private Value DoGetValue(LiveStackFrame frame) { Value result = null; // First try locals. LocalVariable[] locals = frame.Method.GetLocals(); LocalVariable local = locals.FirstOrDefault(l => l.Name == m_name); if (local != null) { result = frame.GetValue(local); } // Then parameters. ParameterInfoMirror parm = frame.Method.GetParameters().FirstOrDefault(p => p.Name == m_name); if (parm != null) { result = frame.GetValue(parm); } // And finally fields and properties. if (result == null) { Value thisPtr = frame.ThisPtr; result = EvalMember.Evaluate(frame.Thread, thisPtr, m_name); } if (result == null) throw new Exception("Couldn't find a local, argument, field, or property named " + m_name); return result; }
public override ExtendedValue Evaluate(LiveStackFrame frame) { bool lhs = m_lhs.Evaluate(frame).Get<bool>(); bool rhs = m_rhs.Evaluate(frame).Get<bool>(); bool result = DoEvaluate(lhs, rhs); return new ExtendedValue(frame.VirtualMachine.CreateValue(result)); }
public override ExtendedValue Evaluate(LiveStackFrame frame) { ExtendedValue result = m_identifier.Evaluate(frame); foreach (PostfixOperator op in m_suffixes) { op.Target = result; result = op.Evaluate(frame); } return result; }
public static VariableItem GetChild(ThreadMirror thread, VariableItem parentItem, LiveStackFrame parent, int index) { VariableItem child; IList<LocalVariable> locals = parent.GetVisibleVariables(); if (index < locals.Count) { LocalVariable local = locals[index]; string name = local.Name; if (string.IsNullOrEmpty(name)) name = "$" + local.Index; // temporary variable Value v = parent.GetValue(local); child = new VariableItem(thread, name, parentItem, local, v, index); } else { FieldInfoMirror[] fields = parent.Method.DeclaringType.GetAllFields().ToArray(); Contract.Assert(fields.Length > 0); object v = null; string name = "this"; if (parent.ThisPtr is ObjectMirror) { v = new InstanceValue((ObjectMirror) parent.ThisPtr, fields); } else if (parent.ThisPtr is StructMirror) { v = new InstanceValue((StructMirror) parent.ThisPtr, fields); } else if (parent.ThisPtr == null || parent.ThisPtr.IsNull()) { v = new TypeValue(parent.Method.DeclaringType); name = "statics"; } else { Contract.Assert(false, parent.ThisPtr.TypeName() + " is bogus"); } child = new VariableItem(thread, name, parentItem, index, v, index); } return child; }
public override ExtendedValue Evaluate(LiveStackFrame frame) { ExtendedValue result; if (Target.Value is ObjectMirror || Target.Value is StructMirror) { Value value = EvalMember.Evaluate(frame.Thread, Target.Value, m_memberName); if (value != null) result = new ExtendedValue(value); else if (Target.Value is ObjectMirror) throw new Exception(string.Format("Couldn't find a field or property for {0}.{1}", ((ObjectMirror) Target.Value).Type.FullName, m_memberName)); else throw new Exception(string.Format("Couldn't find a field or property for {0}.{1}", ((StructMirror) Target.Value).Type.FullName, m_memberName)); } else { throw new Exception("Member access target should be an object, struct, or type name, not a " + Target.Value.GetType()); } return result; }
public static TypeMirror GetType(LiveStackFrame parent, int key) { return parent.Method.DeclaringType; }
public override ExtendedValue Evaluate(LiveStackFrame frame) { return new ExtendedValue(frame.Thread.Domain.CreateString(m_value)); }
public static void Set(ThreadMirror thread, VariableItem item, LiveStackFrame parent, LocalVariable key, Value newValue) { parent.SetValue(key, newValue); }
public static void Set(ThreadMirror thread, VariableItem item, LiveStackFrame parent, int key, Value newValue) { LocalVariable local = parent.GetVisibleVariables()[key]; parent.SetValue(local, newValue); }
private void DoReset(LiveStackFrame frame) { m_nameTable.Clear(); if (frame != null && m_item != null && ((LiveStackFrame) m_item.Value) == frame) { m_frame = frame; m_item.RefreshValue(m_frame.Thread, frame); } else { if (m_item != null) { m_item.release(); m_item = null; } if (frame != null) { m_frame = frame; m_item = new VariableItem(m_frame.Thread, frame); } else { m_frame = null; } } if (m_frame != null) DoLoadNameTable(m_frame.Thread, m_item); m_table.reloadData(); }
public override ExtendedValue Evaluate(LiveStackFrame frame) { Value value = DoGetValue(frame); return new ExtendedValue(value); }
public override ExtendedValue Evaluate(LiveStackFrame frame) { if (Target.Value is ArrayMirror) { var array = (ArrayMirror) Target.Value; Value value = array[m_index]; return new ExtendedValue(value); } else if (Target.Value is StringMirror) { var str = (StringMirror) Target.Value; Value value = frame.VirtualMachine.CreateValue(str.Value[m_index]); return new ExtendedValue(value); } else { throw new Exception("Expected an ArrayMirror or StringMirror, not " + Target.Value.GetType()); } }
public override ExtendedValue Evaluate(LiveStackFrame frame) { bool value = m_expr.Evaluate(frame).Get<bool>(); return new ExtendedValue(frame.VirtualMachine.CreateValue(!value)); }
// Returns a primitive type or throws an error. public abstract ExtendedValue Evaluate(LiveStackFrame frame);
private int m_index; // cache the index (because we sort by name so the old indices become invalid when reloading) #endregion Fields #region Constructors public VariableItem(ThreadMirror thread, LiveStackFrame frame) : this(thread, frame.Method.DeclaringType.FullName + " Stack Frame", null, null, frame, 0) { }
public override ExtendedValue Evaluate(LiveStackFrame frame) { ExtendedValue left = m_lhs.Evaluate(frame); ExtendedValue right = m_rhs.Evaluate(frame); if (left.IsNull && right.IsNull) { switch (m_op) { case "<=": case ">=": case "==": return new ExtendedValue(frame.VirtualMachine.CreateValue(true)); case "<": case ">": case "!=": return new ExtendedValue(frame.VirtualMachine.CreateValue(false)); default: Contract.Assert(false, "bad op: " + m_op); break; } } else if (left.IsNull) { switch (m_op) { case "<": case "<=": case "!=": return new ExtendedValue(frame.VirtualMachine.CreateValue(true)); case ">": case ">=": case "==": return new ExtendedValue(frame.VirtualMachine.CreateValue(false)); default: Contract.Assert(false, "bad op: " + m_op); break; } } else if (right.IsNull) { switch (m_op) { case ">=": case ">": case "!=": return new ExtendedValue(frame.VirtualMachine.CreateValue(true)); case "<": case "<=": case "==": return new ExtendedValue(frame.VirtualMachine.CreateValue(false)); default: Contract.Assert(false, "bad op: " + m_op); break; } } else { object leftValue = DoGetPrimitive(left); object rightValue = DoGetPrimitive(right); Type type = DoFindCommonType(leftValue, rightValue); IComparable lhs = (IComparable) Convert.ChangeType(leftValue, type); IComparable rhs = (IComparable) Convert.ChangeType(rightValue, type); int x = lhs.CompareTo(rhs); switch (m_op) { case "<": return new ExtendedValue(frame.VirtualMachine.CreateValue(x < 0)); case "<=": return new ExtendedValue(frame.VirtualMachine.CreateValue(x <= 0)); case ">=": return new ExtendedValue(frame.VirtualMachine.CreateValue(x >= 0)); case ">": return new ExtendedValue(frame.VirtualMachine.CreateValue(x > 0)); case "==": return new ExtendedValue(frame.VirtualMachine.CreateValue(x == 0)); case "!=": return new ExtendedValue(frame.VirtualMachine.CreateValue(x != 0)); default: Contract.Assert(false, "bad op: " + m_op); break; } } return null; }
public void OnBroadcast(string name, object value) { switch (name) { case "debugger started": m_debugger = (Debugger) value; break; case "debugger processed breakpoint event": case "debugger thrown exception": case "debugger break all": case "debugger processed step event": var context = (Context) value; var frame = new LiveStackFrame(context.Thread, 0); DoReset(frame); break; case "changed thread": var stack = (LiveStack) value; DoReset(stack[0]); break; case "changed stack frame": var frame2 = (LiveStackFrame) value; DoReset(frame2); break; case "debugger stopped": m_debugger = null; DoReset(null); break; case "exiting event loop": DoReset(null); DoSavePrefs(); break; default: Contract.Assert(false, "bad name: " + name); break; } }