private void openTreeFromPtr(ulong ptr) { if (ptr == 0) { return; } ClrTypeHelper clr = comboBoxClrMdTypes.Items.Cast <ClrTypeHelper>().FirstOrDefault(x => x.Ptr == ptr); if (clr != null) { comboBoxClrMdTypes.SelectedItem = clr; return; } ClrType type = runtime.Heap.GetObjectType(ptr); if (type != null) { ClrTypeHelper clrTypeHelper = new ClrTypeHelper() { Ptr = ptr, Name = type.Name, Size = type.GetSize(ptr) }; comboBoxClrMdTypes.Items.Add(clrTypeHelper); comboBoxClrMdTypes.SelectedIndex = comboBoxClrMdTypes.Items.Count - 1; } }
private void AddNodesRecursive(ClrTypeHelper root, TreeNodeCollection nodes) { TreeNode nodeParent = new TreeNode(root.Name); nodes.Add(nodeParent); foreach (ClrTypeHelper p in root.Parents) { AddNodesRecursive(p, nodeParent.Nodes); } }
private void treeViewObjects_AfterSelect(object sender, TreeViewEventArgs e) { ClrTypeHelper c = e.Node.Tag as ClrTypeHelper; if (c.ObjectInfo == null) { c.ObjectInfo = ClrMdHelper.GetInfoOfObject(runtime, c.Ptr, null); } richTextBoxInfo.Text = c.ObjectInfo; }
private void comboBoxClrMdTypes_SelectedIndexChanged(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; ClrTypeHelper clrTypeHelper = comboBoxClrMdTypes.SelectedItem as ClrTypeHelper; if (clrTypeHelper.Parents.Count == 0) { ClrMdHelper.BuildFullRetentionTree(runtime, clrTypeHelper); } this.treeViewRetention.Nodes.Clear(); AddNodesRecursive(clrTypeHelper, this.treeViewRetention.Nodes); Cursor.Current = Cursors.Default; }
public static void BuildFullRetentionTree(ClrRuntime runtime, ClrTypeHelper clrTypeHelper) { Stack <ulong> stack = new Stack <ulong>(); foreach (var root in runtime.Heap.EnumerateRoots()) { stack.Clear(); stack.Push(root.Object); ClrTypeHelper lastCrlTypeHelper = clrTypeHelper; if (GetPathToObject(runtime.Heap, clrTypeHelper.Ptr, stack, new HashSet <ulong>())) { foreach (var address in stack) { var t = runtime.Heap.GetObjectType(address); if (t == null) { continue; } String s = String.Format("{0} - {1} - {2} bytes", address, t.Name, t.GetSize(address)); if (clrTypeHelper.Ptr == address) { continue; } ClrTypeHelper c = new ClrTypeHelper() { Ptr = address, Name = t.Name, Size = t.GetSize(address) }; ClrTypeHelper stringObjectFound; if (lastCrlTypeHelper.Parents.TryGetValue(c, out stringObjectFound)) { lastCrlTypeHelper = stringObjectFound; } else { lastCrlTypeHelper.Parents.Add(c); lastCrlTypeHelper = c; } } } } }
private void treeViewObjects_BeforeExpand(object sender, TreeViewCancelEventArgs e) { if (e.Node.Nodes.Count == 1 && e.Node.Nodes[0].Tag == null) { e.Node.Nodes.Clear(); ClrTypeHelper c = (ClrTypeHelper)e.Node.Tag; ClrType type = runtime.Heap.GetObjectType(c.Ptr); foreach (ClrObject o in type.EnumerateObjectReferences(c.Ptr)) { if (o.Type.Name == "System.String") { continue; } ClrType refType = runtime.Heap.GetObjectType(o.Address); TreeNode refNode = new TreeNode(refType.Name); refNode.Nodes.Add(new TreeNode()); ClrTypeHelper refHelper = new ClrTypeHelper() { Ptr = o.Address, Name = refType.Name, Size = type.GetSize(o.Address), TreeNode = refNode }; System.Diagnostics.Debug.WriteLine("{0:X} {1}", o.Address, refType.Name); refNode.Tag = refHelper; e.Node.Nodes.Add(refNode); globalSearchList.Add(refHelper); } foreach (ClrInstanceField f in type.Fields) { System.Diagnostics.Debug.WriteLine("{0:X} {1}", f.GetAddress(c.Ptr), f.Type); } } }