PageRenderTime 32ms CodeModel.GetById 13ms app.highlight 14ms RepoModel.GetById 2ms app.codeStats 0ms

/Debugger/ILSpy.Debugger/Models/TreeModel/ICorDebug.cs

http://github.com/icsharpcode/ILSpy
C# | 153 lines | 141 code | 10 blank | 2 comment | 26 complexity | 51f95d949adfb9a5cf615a60e56d559f MD5 | raw file
  1// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
  2// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
  3using System.Collections.Generic;
  4using Debugger.Interop.CorDebug;
  5using Debugger.MetaData;
  6using Debugger;
  7
  8namespace ICSharpCode.ILSpy.Debugger.Models.TreeModel
  9{
 10	internal class ICorDebug
 11	{
 12		public class InfoNode: TreeNode
 13		{
 14			List<TreeNode> children;
 15			
 16			public InfoNode(string name, string text): this(name, text, null)
 17			{
 18				
 19			}
 20			
 21			public InfoNode(string name, string text, List<TreeNode> children)
 22			{
 23				this.Name = name;
 24				this.Text = text;
 25				this.ChildNodes = children;
 26				this.children = children;
 27			}
 28			
 29			public void AddChild(string name, string text)
 30			{
 31				if (children == null) {
 32					children = new List<TreeNode>();
 33					this.ChildNodes = children;
 34				}
 35				children.Add(new InfoNode(name, text));
 36			}
 37			
 38			public void AddChild(string name, string text, List<TreeNode> subChildren)
 39			{
 40				if (children == null) {
 41					children = new List<TreeNode>();
 42					this.ChildNodes = children;
 43				}
 44				children.Add(new InfoNode(name, text, subChildren));
 45			}
 46		}
 47		
 48		public static InfoNode GetDebugInfoRoot(AppDomain appDomain, ICorDebugValue corValue)
 49		{
 50			return new InfoNode("ICorDebug", "", GetDebugInfo(appDomain, corValue));
 51		}
 52		
 53		public static List<TreeNode> GetDebugInfo(AppDomain appDomain, ICorDebugValue corValue)
 54		{
 55			List<TreeNode> items = new List<TreeNode>();
 56			
 57			if (corValue is ICorDebugValue) {
 58				InfoNode info = new InfoNode("ICorDebugValue", "");
 59				info.AddChild("Address", corValue.GetAddress().ToString("X8"));
 60				info.AddChild("Type", ((CorElementType)corValue.GetTheType()).ToString());
 61				info.AddChild("Size", corValue.GetSize().ToString());
 62				items.Add(info);
 63			}
 64			if (corValue is ICorDebugValue2) {
 65				InfoNode info = new InfoNode("ICorDebugValue2", "");
 66				ICorDebugValue2 corValue2 = (ICorDebugValue2)corValue;
 67				string fullname;
 68				try {
 69					fullname = DebugType.CreateFromCorType(appDomain, corValue2.GetExactType()).FullName;
 70				} catch (DebuggerException e) {
 71					fullname = e.Message;
 72				}
 73				info.AddChild("ExactType", fullname);
 74				items.Add(info);
 75			}
 76			if (corValue is ICorDebugGenericValue) {
 77				InfoNode info = new InfoNode("ICorDebugGenericValue", "");
 78				try {
 79					byte[] bytes = ((ICorDebugGenericValue)corValue).GetRawValue();
 80					for(int i = 0; i < bytes.Length; i += 8) {
 81						string val = "";
 82						for(int j = i; j < bytes.Length && j < i + 8; j++) {
 83							val += bytes[j].ToString("X2") + " ";
 84						}
 85						info.AddChild("Value" + i.ToString("X2"), val);
 86					}
 87				} catch (System.ArgumentException) {
 88					info.AddChild("Value", "N/A");
 89				}
 90				items.Add(info);
 91			}
 92			if (corValue is ICorDebugReferenceValue) {
 93				InfoNode info = new InfoNode("ICorDebugReferenceValue", "");
 94				ICorDebugReferenceValue refValue = (ICorDebugReferenceValue)corValue;
 95				info.AddChild("IsNull", (refValue.IsNull() != 0).ToString());
 96				if (refValue.IsNull() == 0) {
 97					info.AddChild("Value", refValue.GetValue().ToString("X8"));
 98					if (refValue.Dereference() != null) {
 99						info.AddChild("Dereference", "", GetDebugInfo(appDomain, refValue.Dereference()));
100					} else {
101						info.AddChild("Dereference", "N/A");
102					}
103				}
104				items.Add(info);
105			}
106			if (corValue is ICorDebugHeapValue) {
107				InfoNode info = new InfoNode("ICorDebugHeapValue", "");
108				items.Add(info);
109			}
110			if (corValue is ICorDebugHeapValue2) {
111				InfoNode info = new InfoNode("ICorDebugHeapValue2", "");
112				items.Add(info);
113			}
114			if (corValue is ICorDebugObjectValue) {
115				InfoNode info = new InfoNode("ICorDebugObjectValue", "");
116				ICorDebugObjectValue objValue = (ICorDebugObjectValue)corValue;
117				info.AddChild("Class", objValue.GetClass().GetToken().ToString("X8"));
118				info.AddChild("IsValueClass", (objValue.IsValueClass() != 0).ToString());
119				items.Add(info);
120			}
121			if (corValue is ICorDebugObjectValue2) {
122				InfoNode info = new InfoNode("ICorDebugObjectValue2", "");
123				items.Add(info);
124			}
125			if (corValue is ICorDebugBoxValue) {
126				InfoNode info = new InfoNode("ICorDebugBoxValue", "");
127				ICorDebugBoxValue boxValue = (ICorDebugBoxValue)corValue;
128				info.AddChild("Object", "", GetDebugInfo(appDomain, boxValue.GetObject()));
129				items.Add(info);
130			}
131			if (corValue is ICorDebugStringValue) {
132				InfoNode info = new InfoNode("ICorDebugStringValue", "");
133				ICorDebugStringValue stringValue = (ICorDebugStringValue)corValue;
134				info.AddChild("Length", stringValue.GetLength().ToString());
135				info.AddChild("String", stringValue.GetString());
136				items.Add(info);
137			}
138			if (corValue is ICorDebugArrayValue) {
139				InfoNode info = new InfoNode("ICorDebugArrayValue", "");
140				info.AddChild("...", "...");
141				items.Add(info);
142			}
143			if (corValue is ICorDebugHandleValue) {
144				InfoNode info = new InfoNode("ICorDebugHandleValue", "");
145				ICorDebugHandleValue handleValue = (ICorDebugHandleValue)corValue;
146				info.AddChild("HandleType", handleValue.GetHandleType().ToString());
147				items.Add(info);
148			}
149			
150			return items;
151		}
152	}
153}