// name is a field name, local variable name, etc. // parent is a LiveStackFrame, ObjectMirror, ArrayMirror, etc. Parents are always non-null except for the LiveStackFrame parent. // key is an integral index, a FieldInfoMirror, LocalVariable, etc. // value is the object associated with the parent/key. It will be a Value or a primitive type (like char or int). public VariableItem(ThreadMirror thread, string name, VariableItem parent, object key, object value, int index) : base(NSObject.AllocAndInitInstance("VariableItem")) { Contract.Requires(thread != null); Contract.Requires(!string.IsNullOrEmpty(name)); Contract.Requires(parent != null || value is LiveStackFrame); Contract.Requires(key != null || value is LiveStackFrame); Contract.Requires(value != null); // null debugger values are PrimitiveValues with a null Value Contract.Requires(index >= 0); Parent = parent; Key = key; Value = value; m_index = index; m_actualName = name; m_actualValue = value; Details details = DoGetDetails(thread, name, parent, key, value); Value = details.Value; AttributedName = NSMutableAttributedString.Create(details.DisplayName).Retain(); AttributedType = NSAttributedString.Create(details.DisplayType).Retain(); AttributedValue = NSAttributedString.Create(details.DisplayValue).Retain(); NumberOfChildren = details.NumberOfChildren; }
public static void Set(ThreadMirror thread, VariableItem item, InstanceValue parent, FieldInfoMirror key, Value newValue) { if (key.IsStatic) { key.DeclaringType.SetValue(key, newValue); } else { var o = (ObjectMirror) parent.Instance; o.SetValue(key, newValue); } }
public static void Set(ThreadMirror thread, VariableItem item, InstanceValue parent, int key, Value newValue) { FieldInfoMirror field = parent.Type.GetFields()[key]; Contract.Assert(!field.IsStatic); ObjectMirror o = parent.Instance as ObjectMirror; if (o != null) { o.SetValue(field, newValue); } else { var s = (StructMirror) parent.Instance; s.Fields[key] = newValue; SetValue.Invoke(thread, item.Parent, item.Parent.Parent.Value, item.Parent.Key, s); } }
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 static VariableItem GetChild(ThreadMirror thread, VariableItem parentItem, ObjectMirror parent, int index) { if (parent.Type.IsType("System.MulticastDelegate")) { return DoGetMulticastDelegateChild(thread, parentItem, parent, index); } // else if (parent.Type.FullName.StartsWith("System.Collections") && parent.Type.FindMethod("GetEnumerator", 0) != null) // TODO: better to use Is(ICollection) but TypeMirror does not expose interfaces // { // var child = new EnumerableValue(parentItem, parent); // return new VariableItem(thread, "Enumerable", parentItem, index, child, index); // } else { PropertyInfoMirror[] props = (from p in parent.Type.GetAllProperties() where p.ShouldDisplay() select p).ToArray(); if (index < props.Length) { PropertyInfoMirror prop = props[index]; Value child = EvalMember.Evaluate(thread, parent, prop.Name); return new VariableItem(thread, prop.Name, parentItem, prop, child, index); } else { FieldInfoMirror[] fields = (from f in parent.Type.GetAllFields() where f.ShouldDisplay() select f).ToArray(); FieldInfoMirror field = fields[index - props.Length]; Value child = EvalMember.Evaluate(thread, parent, field.Name); return new VariableItem(thread, field.Name, parentItem, field, child, index); } } }
public VariableItem GetChild(ThreadMirror thread, VariableItem parent, int index) { return Debug::GetChild.Invoke(thread, parent, Instance, index); }
public static void Set(ThreadMirror thread, VariableItem item, ObjectMirror parent, FieldInfoMirror key, Value newValue) { if (key.IsStatic) key.DeclaringType.SetValue(key, newValue); else parent.SetValue(key, newValue); }
public bool outlineView_isItemExpandable(NSOutlineView table, VariableItem item) { bool expandable = false; try { expandable = item == null ? true : item.NumberOfChildren > 0; } catch (Exception e) { if (!Debugger.IsShuttingDown(e)) throw; } return expandable; }
public void outlineView_setObjectValue_forTableColumn_byItem(NSTableView table, NSObject value, NSTableColumn col, VariableItem item) { try { string text = value.description(); Value newValue = ParseValue.Invoke(m_frame.Thread, item, item.Value, text); SetValue.Invoke(m_frame.Thread, item, item.Parent.Value, item.Key, newValue); item.RefreshValue(m_frame.Thread, newValue); // if we're setting a (non-auto) property we might also want to refresh all fields for that type } catch (Exception e) { Boss boss = ObjectModel.Create("Application"); var transcript = boss.Get<ITranscript>(); // transcript.Show(); // transcript.WriteLine(Output.Error, "{0}", e); transcript.WriteLine(Output.Error, "{0}", e.Message); if (e.InnerException != null) transcript.WriteLine(Output.Error, " {0}", e.InnerException.Message); } }
private static VariableItem DoGetMulticastDelegateChild(ThreadMirror thread, VariableItem parentItem, ObjectMirror target, int index) { Value result; FieldInfoMirror field; switch (index) { case 0: result = EvalMember.Evaluate(thread, target, "Target"); field = target.Type.GetAllFields().Single(f => f.Name == "m_target"); return new VariableItem(thread, "Target", parentItem, field, result, index); case 1: result = EvalMember.Evaluate(thread, target, "Method"); field = target.Type.GetAllFields().Single(f => f.Name == "method"); return new VariableItem(thread, "Method", parentItem, field, result, index); case 2: result = EvalMember.Evaluate(thread, target, "kpm_next"); field = target.Type.GetAllFields().Single(f => f.Name == "kpm_next"); return new VariableItem(thread, "Next", parentItem, field, result, index); case 3: result = EvalMember.Evaluate(thread, target, "prev"); field = target.Type.GetAllFields().Single(f => f.Name == "prev"); return new VariableItem(thread, "Previous", parentItem, field, result, index); default: Contract.Assert(false); return null; } }
public static VariableItem GetChild(ThreadMirror thread, VariableItem parentItem, TypeMirror parent, int index) { var props = (from p in parent.GetAllProperties() where p.HasSimpleGetter() && (p.GetGetMethod(true) != null && p.GetGetMethod(true).IsStatic) || (p.GetSetMethod(true) != null && p.GetSetMethod(true).IsStatic) select p).ToArray(); if (index < props.Length) { PropertyInfoMirror prop = props[index]; MethodMirror method = parent.ResolveProperty(prop.Name); Value child = parent.InvokeMethod(thread, method, new Value[0], InvokeOptions.DisableBreakpoints | InvokeOptions.SingleThreaded); return new VariableItem(thread, prop.Name, parentItem, prop, child, index); } else { var fields = from f in parent.GetAllFields() where f.IsStatic select f; FieldInfoMirror field = fields.ElementAt(index - props.Length); Value child; if (field.HasCustomAttribute("System.ThreadStaticAttribute")) child = field.DeclaringType.GetValue(field, thread); else child = field.DeclaringType.GetValue(field); return new VariableItem(thread, field.Name, parentItem, index, child, index); } }
public static void Set(ThreadMirror thread, VariableItem item, ArrayMirror parent, int key, Value newValue) { parent.SetValues(key, new Value[]{newValue}); }
public static void Set(ThreadMirror thread, VariableItem item, TypeValue parent, int key, Value newValue) { FieldInfoMirror field = parent.Type.GetFields()[key]; Contract.Assert(field.IsStatic); parent.Type.SetValue(field, newValue); }
public static void Set(ThreadMirror thread, VariableItem item, StructMirror parent, int key, Value newValue) { FieldInfoMirror[] fields = parent.Type.GetFields(); if (fields[key].IsStatic) { parent.Type.SetValue(fields[key], newValue); } else { parent.Fields[key] = newValue; SetValue.Invoke(thread, item.Parent, item.Parent.Parent.Value, item.Parent.Key, parent); } }
public static void Set(ThreadMirror thread, VariableItem item, ObjectMirror parent, PropertyInfoMirror key, Value newValue) { Contract.Assert(key.HasSimpleGetter()); // indexors aren't shown... MethodMirror method = key.GetSetMethod(true); if (method != null) { Unused.Value = parent.InvokeMethod(thread, method, new Value[]{newValue}, InvokeOptions.DisableBreakpoints | InvokeOptions.SingleThreaded); } else { throw new Exception("Property does not have a setter."); } }
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(); }
private void DoLoadNameTable(ThreadMirror thread, VariableItem parent) { for (int i = 0; i < parent.NumberOfChildren; ++i) { VariableItem child = parent.GetChild(thread, i); string value = child.AttributedValue.ToString(); if (value.Length > 0) m_nameTable[child.AttributedName.ToString()] = value; var iv = child.Value as InstanceValue; if (iv != null) { for (int j = 0; j < iv.Length; ++j) { VariableItem gchild = iv.GetChild(thread, child, j); gchild.autorelease(); value = gchild.AttributedValue.ToString(); if (value.Length > 0) m_nameTable[gchild.AttributedName.ToString()] = value; } } var tv = child.Value as TypeValue; if (tv != null) { for (int j = 0; j < tv.Length; ++j) { VariableItem gchild = tv.GetChild(thread, child, j); gchild.autorelease(); value = gchild.AttributedValue.ToString(); if (value.Length > 0) m_nameTable[gchild.AttributedName.ToString()] = value; } } } }
public static VariableItem GetChild(ThreadMirror thread, VariableItem parentItem, StringMirror parent, int index) { string name = string.Format("[{0}]", index); char child = parent.Value[index]; return new VariableItem(thread, name, parentItem, index, child, index); }
public static VariableItem GetChild(ThreadMirror thread, VariableItem parentItem, StructMirror parent, int index) { PropertyInfoMirror[] props = (from p in parent.Type.GetAllProperties() where p.ShouldDisplay() select p).ToArray(); if (index < props.Length) { PropertyInfoMirror prop = props[index]; Value child = EvalMember.Evaluate(thread, parent, prop.Name); return new VariableItem(thread, prop.Name, parentItem, prop, child, index); } else { FieldInfoMirror[] fields = (from f in parent.Type.GetAllFields() where f.ShouldDisplay() select f).ToArray(); FieldInfoMirror field = fields[index - props.Length]; Value child; if (field.IsStatic) if (field.HasCustomAttribute("System.ThreadStaticAttribute")) child = parent.Type.GetValue(field, thread); else child = parent.Type.GetValue(field); else child = parent.Fields[index - props.Length]; return new VariableItem(thread, field.Name, parentItem, index, child, index); } }
public int outlineView_numberOfChildrenOfItem(NSOutlineView table, VariableItem item) { int count = 0; try { if (m_item != null) count = item == null ? m_item.NumberOfChildren : item.NumberOfChildren; } catch (Exception e) { if (!Debugger.IsShuttingDown(e)) throw; } return count; }
public static VariableItem GetChild(ThreadMirror thread, VariableItem parentItem, TypeValue parent, int index) { return parent.GetChild(thread, parentItem, index); }
private Details DoGetDetails(ThreadMirror thread, string name, VariableItem parent, object key, object value) { Item item = GetItem.Invoke(thread, parent != null ? parent.Value : null, key, value); var details = new Details(); details.Value = value; details.NumberOfChildren = item.Count; details.DisplayName = name; details.DisplayValue = item.Text; details.DisplayType = item.Type; DoAdjustDetails(details, thread, parent, key, value); return details; }
public static VariableItem GetChild(ThreadMirror thread, VariableItem parentItem, ArrayMirror parent, int index) { string name = GetArrayName(parent, index); Value child = parent[index]; return new VariableItem(thread, name, parentItem, index, child, index); }
public NSObject outlineView_objectValueForTableColumn_byItem(NSOutlineView table, NSTableColumn col, VariableItem item) { NSObject value = null; try { if (m_item != null) { if (col.identifier().ToString() == "0") value = item == null ? m_item.AttributedName : item.AttributedName; else if (col.identifier().ToString() == "1") value = item == null ? m_item.AttributedValue : item.AttributedValue; else value = item == null ? m_item.AttributedType : item.AttributedType; } } catch (Exception e) { if (!Debugger.IsShuttingDown(e)) throw; } return value; }
private void DoAdjustDetails(Details details, ThreadMirror thread, VariableItem parent, object key, object value) { // If the value is decorated with DebuggerTypeProxyAttribute then we need to // use a proxy value instead of the original value. object replacement = DoGetProxyValue(value, thread); // If a property or field of the value is decorated with DebuggerBrowsableAttribute // and RootHidden then we need to display just the value of that property or field. replacement = DoGetRootValue(replacement ?? value, thread); // If we found a replacement for the original value then, if (replacement != null) { // we need to use that value, details.Value = replacement; // the children will be those of the replacement, Item item = GetItem.Invoke(thread, parent != null ? parent.Value : null, key, replacement); details.NumberOfChildren = item.Count; // and if the replacement has a ToString or value attribute then use that. if (!string.IsNullOrEmpty(item.Text)) details.DisplayValue = item.Text; } // Special case for types or fields or properties that use DebuggerDisplayAttribute. // TODO: We don't support DebuggerDisplayAttribute used at the assembly level. string displayName, displayValue, displayType; DoGetDisplayDetails(key, details.Value, thread, out displayName, out displayValue, out displayType); if (displayName != null) { details.DisplayName = displayName; NumberOfChildren = 0; } if (displayValue != null) details.DisplayValue = displayValue; if (displayType != null) details.DisplayType = displayType; if (details.DisplayValue.Length == 0 && value is ArrayMirror) { var aa = (ArrayMirror) value; details.DisplayValue = string.Format("Length = {0}", aa.Length); } }
public static void Set(ThreadMirror thread, VariableItem item, LiveStackFrame parent, int key, Value newValue) { LocalVariable local = parent.GetVisibleVariables()[key]; parent.SetValue(local, newValue); }
public static void Set(ThreadMirror thread, VariableItem item, LiveStackFrame parent, LocalVariable key, Value newValue) { parent.SetValue(key, newValue); }
public NSObject outlineView_child_ofItem(NSOutlineView table, int index, VariableItem item) { NSObject child = null; try { if (m_item != null) child = item == null ? m_item.GetChild(m_frame.Thread, index) : item.GetChild(m_frame.Thread, index); } catch (Exception e) { if (!Debugger.IsShuttingDown(e)) throw; } return child; }