Browse Source

Debugger visualizers - progress towards getting the project to compile.

newNRvisualizers
Martin Konicek 13 years ago
parent
commit
70b7fef325
  1. 3
      src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj
  2. 6
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/TreeModel/ContentPropertyNode.cs
  3. 16
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraph/ObjectGraphBuilder.cs
  4. 7
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/GridVisualizer/GridVisualizerWindow.xaml.cs
  5. 9
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/DebuggerHelpers.cs
  6. 18
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/IEnumerableExtensions.cs
  7. 46
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/Lookup.cs
  8. 15
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/LookupValueCollection.cs
  9. 41
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/Multimap.cs
  10. 13
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/TypeResolver.cs

3
src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj

@ -222,8 +222,7 @@ @@ -222,8 +222,7 @@
<Compile Include="Visualizers\Utils\ITreeNode.cs" />
<Compile Include="Visualizers\Utils\LinqUtils.cs" />
<Compile Include="Visualizers\Utils\ListHelper.cs" />
<Compile Include="Visualizers\Utils\Lookup.cs" />
<Compile Include="Visualizers\Utils\LookupValueCollection.cs" />
<Compile Include="Visualizers\Utils\Multimap.cs" />
<Compile Include="Visualizers\Utils\StringHelper.cs" />
<Compile Include="Visualizers\Utils\TreeFlattener.cs" />
<Compile Include="Visualizers\Utils\TypeResolver.cs" />

6
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/TreeModel/ContentPropertyNode.cs

@ -74,14 +74,14 @@ namespace Debugger.AddIn.Visualizers.Graph.Layout @@ -74,14 +74,14 @@ namespace Debugger.AddIn.Visualizers.Graph.Layout
void EvalMemberIcon()
{
// should never be null, just to be sure
if ((this.Property != null) && (this.Property.ObjectGraphProperty != null)) {
// TODO reimplement
/*if ((this.Property != null) && (this.Property.ObjectGraphProperty != null)) {
var memberInfo = (IDebugMemberInfo)this.Property.ObjectGraphProperty.MemberInfo;
if (memberInfo != null) {
var image = new ResourceServiceImage(ValueNode.GetImageForMember(memberInfo));
this.MemberIcon = image.ImageSource;
}
}
}*/
}
}
}

16
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraph/ObjectGraphBuilder.cs

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Debugger.AddIn.TreeModel;
using Debugger.AddIn.Visualizers.Graph.Layout;
@ -54,7 +55,7 @@ namespace Debugger.AddIn.Visualizers.Graph @@ -54,7 +55,7 @@ namespace Debugger.AddIn.Visualizers.Graph
/// <summary>
/// Given hash code, lookup already existing node(s) with this hash code.
/// </summary>
private Lookup<int, ObjectGraphNode> objectNodesForHashCode = new Lookup<int, ObjectGraphNode>();
private Multimap<int, ObjectGraphNode> objectNodesForHashCode = new Multimap<int, ObjectGraphNode>();
/// <summary>
/// Binding flags for getting member expressions.
@ -191,10 +192,11 @@ namespace Debugger.AddIn.Visualizers.Graph @@ -191,10 +192,11 @@ namespace Debugger.AddIn.Visualizers.Graph
void LoadNodeObjectContent(AbstractNode node, GraphExpression expression, IType type)
{
// base
if (type.BaseType != null && !type.IsSystemDotObject()) {
var baseClassNode = new BaseClassNode(type.BaseType.FullName, type.BaseType.Name);
var baseType = type.DirectBaseTypes.FirstOrDefault();
if (baseType != null) {
var baseClassNode = new BaseClassNode(baseType.FullName, baseType.Name);
node.AddChild(baseClassNode);
LoadNodeObjectContent(baseClassNode, expression, (DebugType)type.BaseType);
LoadNodeObjectContent(baseClassNode, expression, baseType);
}
// non-public members
@ -312,15 +314,15 @@ namespace Debugger.AddIn.Visualizers.Graph @@ -312,15 +314,15 @@ namespace Debugger.AddIn.Visualizers.Graph
{
int objectHashCode = value.InvokeDefaultGetHashCode();
// are there any nodes with the same hash code?
LookupValueCollection<ObjectGraphNode> nodesWithSameHashCode = objectNodesForHashCode[objectHashCode];
IList<ObjectGraphNode> nodesWithSameHashCode = objectNodesForHashCode[objectHashCode];
if (nodesWithSameHashCode == null) {
return null;
} else {
// if there is a node with same hash code, check if it has also the same address
// (hash codes are not uniqe - http://stackoverflow.com/questions/750947/-net-unique-object-identifier)
ulong objectAddress = value.GetObjectAddress();
ObjectGraphNode nodeWithSameAddress = nodesWithSameHashCode.Find(
node => { return node.PermanentReference.GetObjectAddress() == objectAddress; } );
ObjectGraphNode nodeWithSameAddress =
nodesWithSameHashCode.FirstOrDefault(node => node.PermanentReference.GetObjectAddress() == objectAddress);
return nodeWithSameAddress;
}
}

7
src/AddIns/Debugger/Debugger.AddIn/Visualizers/GridVisualizer/GridVisualizerWindow.xaml.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt)
using System;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
@ -58,8 +59,8 @@ namespace Debugger.AddIn.Visualizers.GridVisualizer @@ -58,8 +59,8 @@ namespace Debugger.AddIn.Visualizers.GridVisualizer
shownValue = shownValue.GetPermanentReference(WindowsDebugger.EvalThread);
MemberInfo[] members = itemType.GetFieldsAndNonIndexedProperties(BindingFlags.Public | BindingFlags.Instance);
PropertyInfo itemGetter = iListType.GetProperty("Item");
int rowCount = (int)shownValue.GetPropertyValue(WindowsDebugger.EvalThread, iListType.GetProperty("Count")).PrimitiveValue;
IProperty indexerProperty = iListType.GetProperties(p => p.Name == "Item").Single();
int rowCount = (int)shownValue.GetPropertyValue(WindowsDebugger.EvalThread, iListType.GetProperties(p => p.Name == "Count").Single()).PrimitiveValue;
int columnCount = members.Length + 1;
var rowCollection = new VirtualizingCollection<VirtualizingCollection<string>>(
@ -70,7 +71,7 @@ namespace Debugger.AddIn.Visualizers.GridVisualizer @@ -70,7 +71,7 @@ namespace Debugger.AddIn.Visualizers.GridVisualizer
if (columnIndex == members.Length)
return "[" + rowIndex + "]";
try {
var rowValue = shownValue.GetPropertyValue(WindowsDebugger.EvalThread, itemGetter, Eval.CreateValue(WindowsDebugger.EvalThread, rowIndex));
var rowValue = shownValue.GetPropertyValue(WindowsDebugger.EvalThread, indexerProperty, Eval.CreateValue(WindowsDebugger.EvalThread, rowIndex));
return rowValue.GetMemberValue(WindowsDebugger.EvalThread, members[columnIndex]).InvokeToString(WindowsDebugger.EvalThread);
} catch (GetValueException e) {
return "Exception: " + e.Message;

9
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/DebuggerHelpers.cs

@ -108,14 +108,9 @@ namespace Debugger.AddIn.Visualizers.Utils @@ -108,14 +108,9 @@ namespace Debugger.AddIn.Visualizers.Utils
/// <summary>
/// Formats System.Type to the C# format, that is generic parameters in angle brackets.
/// </summary>
public static string FormatNameCSharp(this Type type)
public static string FormatNameCSharp(this IType type)
{
string typeName = type.Name.CutoffEnd("`"); // get rid of the `n in generic type names
if (type.IsGenericType) {
return typeName + "<" + string.Join(", ", type.GetGenericArguments().Select(a => FormatNameCSharp(a))) + ">";
} else {
return typeName;
}
return type.ToString(); // TODO use an existing C# IType formatter?
}
// Object graph visualizer: collection support temp disabled (porting to new NRefactory).

18
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/IEnumerableExtensions.cs

@ -18,28 +18,12 @@ namespace Debugger.AddIn.Visualizers.Utils @@ -18,28 +18,12 @@ namespace Debugger.AddIn.Visualizers.Utils
public static Dictionary<K, V> MakeDictionary<K, V>(this IEnumerable<V> collection, Func<V, K> keySelector)
{
Dictionary<K, V> dictionary = new Dictionary<K, V>();
foreach (V item in collection)
{
foreach (V item in collection) {
K key = keySelector(item);
if (dictionary.ContainsKey(key)) throw new InvalidOperationException("MakeDictionary: key " + key + " seen twice");
dictionary[key] = item;
}
return dictionary;
}
/// <summary>
/// Builds Lookup for quickly searching a collection.
/// </summary>
/// <param name="collection">Collection for which to build Dictionary.</param>
/// <param name="keySelector">Function returning key by which to index.</param>
public static Lookup<K, V> MakeLookup<K, V>(this IEnumerable<V> collection, Func<V, K> keySelector)
{
Lookup<K, V> lookup = new Lookup<K, V>();
foreach (V item in collection)
{
lookup.Add(keySelector(item), item);
}
return lookup;
}
}
}

46
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/Lookup.cs

@ -1,46 +0,0 @@ @@ -1,46 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt)
using System;
using System.Collections.Generic;
namespace Debugger.AddIn.Visualizers.Utils
{
/// <summary>
/// Same like Dictionary, but can store multiple values for one key.
/// </summary>
public class Lookup<TKey, TValue>
{
/// <summary>Wrapped dictionary</summary>
private Dictionary<TKey, LookupValueCollection<TValue>> dictionary;
public Lookup()
{
dictionary = new Dictionary<TKey, LookupValueCollection<TValue>>();
}
public LookupValueCollection<TValue> this[TKey key]
{
get
{
LookupValueCollection<TValue> values = null;
if (dictionary.TryGetValue(key, out values))
{
return values;
}
return null;
}
}
public void Add(TKey key, TValue value)
{
LookupValueCollection<TValue> values = null;
if (!dictionary.TryGetValue(key, out values))
{
values = new LookupValueCollection<TValue>();
dictionary.Add(key, values);
}
values.Add(value);
}
}
}

15
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/LookupValueCollection.cs

@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt)
using System;
using System.Collections.Generic;
namespace Debugger.AddIn.Visualizers.Utils
{
/// <summary>
/// A collection of values for one key in the Lookup class.
/// </summary>
public class LookupValueCollection<TValue> : List<TValue>
{
}
}

41
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/Multimap.cs

@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt)
using System;
using System.Collections.Generic;
namespace Debugger.AddIn.Visualizers.Utils
{
/// <summary> Dictionary that can store multiple values for each key.</summary>
public class Multimap<TKey, TValue>
{
/// <summary>Wrapped dictionary</summary>
private Dictionary<TKey, IList<TValue>> dictionary;
public Multimap()
{
dictionary = new Dictionary<TKey, IList<TValue>>();
}
public IList<TValue> this[TKey key]
{
get {
IList<TValue> values = null;
if (dictionary.TryGetValue(key, out values)) {
return values;
}
return null;
}
}
public void Add(TKey key, TValue value)
{
IList<TValue> values = null;
if (!dictionary.TryGetValue(key, out values)) {
values = new List<TValue>();
dictionary.Add(key, values);
}
values.Add(value);
}
}
}

13
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/TypeResolver.cs

@ -21,7 +21,7 @@ namespace Debugger.AddIn.Visualizers.Utils @@ -21,7 +21,7 @@ namespace Debugger.AddIn.Visualizers.Utils
/// <param name="iListType">Result found implementation of System.Collections.Generic.IList.</param>
/// <param name="itemType">The only generic argument of <paramref name="implementation"/></param>
/// <returns>True if found, false otherwise.</returns>
public static bool ResolveIListImplementation(this IType type, out ParameterizedType iListType, out IType itemType)
public static bool ResolveIListImplementation(this IType type, out IType iListType, out IType itemType)
{
return type.ResolveKnownBaseType(KnownTypeCode.IListOfT, out iListType, out itemType);
}
@ -32,7 +32,7 @@ namespace Debugger.AddIn.Visualizers.Utils @@ -32,7 +32,7 @@ namespace Debugger.AddIn.Visualizers.Utils
/// <param name="iEnumerableType">Result found implementation of System.Collections.Generic.IEnumerable.</param>
/// <param name="itemType">The only generic argument of <paramref name="implementation"/></param>
/// <returns>True if found, false otherwise.</returns>
public static bool ResolveIEnumerableImplementation(this IType type, out ParameterizedType iEnumerableType, out IType itemType)
public static bool ResolveIEnumerableImplementation(this IType type, out IType iEnumerableType, out IType itemType)
{
return type.ResolveKnownBaseType(KnownTypeCode.IEnumerableOfT, out iEnumerableType, out itemType);
}
@ -44,17 +44,18 @@ namespace Debugger.AddIn.Visualizers.Utils @@ -44,17 +44,18 @@ namespace Debugger.AddIn.Visualizers.Utils
/// <param name="implementation">Found implementation.</param>
/// <param name="itemType">The only generic argument of <paramref name="implementation"/></param>
/// <returns>True if found, false otherwise.</returns>
private static bool ResolveKnownBaseType(this IType type, KnownTypeCode knownTypeCode, out ParameterizedType implementation, out IType itemType)
private static bool ResolveKnownBaseType(this IType type, KnownTypeCode knownTypeCode, out IType implementation, out IType itemType)
{
if (type == null) throw new ArgumentNullException("type");
implementation = null;
itemType = null;
implementation =
ParameterizedType impl =
type.GetAllBaseTypes().OfType<ParameterizedType>().
Where(t => t.IsKnownType(knownTypeCode) && t.TypeParameterCount == 1)
.FirstOrDefault();
if (implementation != null) {
itemType = implementation.GetTypeArgument(0);
if (impl != null) {
implementation = impl;
itemType = impl.GetTypeArgument(0);
return true;
}
return false;

Loading…
Cancel
Save