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