Browse Source

Evaluate instance fields.

pull/191/merge
Eusebiu Marcu 16 years ago
parent
commit
a1a8243e26
  1. 6
      Debugger/Debugger.Core/NRefactory/Ast/ExpressionExtensionMethods.cs
  2. 8
      Debugger/Debugger.Core/NRefactory/Visitors/ExpressionEvaluator.cs
  3. 21
      Debugger/ILSpy.Debugger/Models/TreeModel/ChildNodesOfObject.cs
  4. 14
      Debugger/ILSpy.Debugger/Models/TreeModel/ExpressionNode.cs

6
Debugger/Debugger.Core/NRefactory/Ast/ExpressionExtensionMethods.cs

@ -305,7 +305,11 @@ namespace ICSharpCode.NRefactory.Ast @@ -305,7 +305,11 @@ namespace ICSharpCode.NRefactory.Ast
//
public static DebugType ResolveType(this AstNode expr, Debugger.AppDomain appDomain)
{
return expr.GetStaticType();
var result = expr.GetStaticType();
if (result != null)
return result;
return DebugType.CreateFromType(appDomain, expr.Annotation<Type>());
// if (expr is AstType && expr.GetStaticType() != null)
// return expr.GetStaticType();

8
Debugger/Debugger.Core/NRefactory/Visitors/ExpressionEvaluator.cs

@ -351,6 +351,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -351,6 +351,7 @@ namespace ICSharpCode.NRefactory.Visitors
{
TypedValue val = Evaluate(castExpression.Expression);
DebugType castTo = castExpression.Type.ResolveType(context.AppDomain);
if (castTo.IsPrimitive && val.Type.IsPrimitive && castTo != val.Type) {
object oldVal = val.PrimitiveValue;
object newVal;
@ -403,7 +404,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -403,7 +404,7 @@ namespace ICSharpCode.NRefactory.Visitors
// Instance class members
// Note that the method might be generated instance method that represents anonymous method
TypedValue thisValue = GetThisValue();
TypedValue thisValue = this.GetThisValue();
if (thisValue != null) {
IDebugMemberInfo instMember = (IDebugMemberInfo)thisValue.Type.GetMember<MemberInfo>(identifier, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, DebugType.IsFieldOrNonIndexedProperty);
if (instMember != null)
@ -572,10 +573,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -572,10 +573,7 @@ namespace ICSharpCode.NRefactory.Visitors
TypedValue GetThisValue()
{
// This is needed so that captured 'this' is supported
DebugLocalVariableInfo thisVar = context.MethodInfo.GetLocalVariableThis();
if (thisVar != null)
return new TypedValue(thisVar.GetValue(context), (DebugType)thisVar.LocalType);
return null;
return new TypedValue(context.GetThisValue(), (DebugType)context.MethodInfo.DeclaringType);
}
public override object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data)

21
Debugger/ILSpy.Debugger/Models/TreeModel/ChildNodesOfObject.cs

@ -100,7 +100,7 @@ namespace ILSpy.Debugger.Models.TreeModel @@ -100,7 +100,7 @@ namespace ILSpy.Debugger.Models.TreeModel
// This is needed for expanding IEnumerable<T>
var type = new SimpleType() { Identifier = typeof(IList).FullName };
type.AddAnnotation(DebugType.CreateFromType(Mscorlib, typeof(IList)));
type.AddAnnotation(typeof(IList));
targetObject = new CastExpression() { Expression = targetObject.Clone(), Type = type };
@ -151,24 +151,5 @@ namespace ILSpy.Debugger.Models.TreeModel @@ -151,24 +151,5 @@ namespace ILSpy.Debugger.Models.TreeModel
}
}
}
static Module mscorlib;
public static Module Mscorlib {
get {
if (mscorlib != null) return mscorlib;
foreach (var appDomain in WindowsDebugger.CurrentProcess.AppDomains) {
foreach(Module m in appDomain.Process.Modules) {
if (m.Name == "mscorlib.dll" &&
m.AppDomain == appDomain) {
mscorlib = m;
return mscorlib;
}
}
}
throw new DebuggerException("Mscorlib not loaded");
}
}
}
}

14
Debugger/ILSpy.Debugger/Models/TreeModel/ExpressionNode.cs

@ -149,13 +149,23 @@ namespace ILSpy.Debugger.Models.TreeModel @@ -149,13 +149,23 @@ namespace ILSpy.Debugger.Models.TreeModel
Value val;
try {
if (expression is IdentifierExpression) {
var frame = WindowsDebugger.DebuggedProcess.SelectedThread.MostRecentStackFrame;
int token = frame.MethodInfo.MetadataToken;
// get the target name
int index = Name.IndexOf('.');
string targetName = Name;
if (index != -1) {
targetName = Name.Substring(0, index);
}
List<ILVariable> list;
if (ILAstBuilder.MemberLocalVariables.TryGetValue(token, out list)) {
var variable = list.Find(v => v.Name == Name);
var variable = list.Find(v => v.Name == targetName);
if (variable != null) {
if (expression is MemberReferenceExpression) {
var memberExpression = (MemberReferenceExpression)expression;
memberExpression.Target.AddAnnotation(new int[] { variable.OriginalVariable.Index });
} else {
expression.AddAnnotation(new int[] { variable.OriginalVariable.Index });
}
}

Loading…
Cancel
Save