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. 40
      Debugger/Debugger.Core/NRefactory/Visitors/ExpressionEvaluator.cs
  3. 21
      Debugger/ILSpy.Debugger/Models/TreeModel/ChildNodesOfObject.cs
  4. 24
      Debugger/ILSpy.Debugger/Models/TreeModel/ExpressionNode.cs

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

@ -305,7 +305,11 @@ namespace ICSharpCode.NRefactory.Ast
// //
public static DebugType ResolveType(this AstNode expr, Debugger.AppDomain appDomain) 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) // if (expr is AstType && expr.GetStaticType() != null)
// return expr.GetStaticType(); // return expr.GetStaticType();

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

@ -351,6 +351,7 @@ namespace ICSharpCode.NRefactory.Visitors
{ {
TypedValue val = Evaluate(castExpression.Expression); TypedValue val = Evaluate(castExpression.Expression);
DebugType castTo = castExpression.Type.ResolveType(context.AppDomain); DebugType castTo = castExpression.Type.ResolveType(context.AppDomain);
if (castTo.IsPrimitive && val.Type.IsPrimitive && castTo != val.Type) { if (castTo.IsPrimitive && val.Type.IsPrimitive && castTo != val.Type) {
object oldVal = val.PrimitiveValue; object oldVal = val.PrimitiveValue;
object newVal; object newVal;
@ -367,7 +368,7 @@ namespace ICSharpCode.NRefactory.Visitors
throw new GetValueException("Can not cast {0} to {1}", val.Value.Type.FullName, castTo.FullName); throw new GetValueException("Can not cast {0} to {1}", val.Value.Type.FullName, castTo.FullName);
return new TypedValue(val.Value, castTo); return new TypedValue(val.Value, castTo);
} }
public override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) public override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data)
{ {
string identifier = identifierExpression.Identifier; string identifier = identifierExpression.Identifier;
@ -403,7 +404,7 @@ namespace ICSharpCode.NRefactory.Visitors
// Instance class members // Instance class members
// Note that the method might be generated instance method that represents anonymous method // Note that the method might be generated instance method that represents anonymous method
TypedValue thisValue = GetThisValue(); TypedValue thisValue = this.GetThisValue();
if (thisValue != null) { if (thisValue != null) {
IDebugMemberInfo instMember = (IDebugMemberInfo)thisValue.Type.GetMember<MemberInfo>(identifier, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, DebugType.IsFieldOrNonIndexedProperty); IDebugMemberInfo instMember = (IDebugMemberInfo)thisValue.Type.GetMember<MemberInfo>(identifier, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, DebugType.IsFieldOrNonIndexedProperty);
if (instMember != null) if (instMember != null)
@ -419,7 +420,7 @@ namespace ICSharpCode.NRefactory.Visitors
throw new GetValueException("Identifier \"" + identifier + "\" not found in this context"); throw new GetValueException("Identifier \"" + identifier + "\" not found in this context");
} }
public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data) public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
{ {
TypedValue target = Evaluate(indexerExpression.Target); TypedValue target = Evaluate(indexerExpression.Target);
@ -453,7 +454,7 @@ namespace ICSharpCode.NRefactory.Visitors
); );
} }
} }
public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data) public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
{ {
TypedValue target; TypedValue target;
@ -491,7 +492,7 @@ namespace ICSharpCode.NRefactory.Visitors
return null; return null;
return new TypedValue(retVal, (DebugType)method.ReturnType); return new TypedValue(retVal, (DebugType)method.ReturnType);
} }
public override object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data) public override object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data)
{ {
if (!objectCreateExpression.Initializer.IsNull) if (!objectCreateExpression.Initializer.IsNull)
@ -505,7 +506,7 @@ namespace ICSharpCode.NRefactory.Visitors
Value val = (Value)ctor.Invoke(GetValues(ctorArgs)); Value val = (Value)ctor.Invoke(GetValues(ctorArgs));
return new TypedValue(val, type); return new TypedValue(val, type);
} }
public override object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) public override object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data)
{ {
if (arrayCreateExpression.AdditionalArraySpecifiers.Count() != 0) if (arrayCreateExpression.AdditionalArraySpecifiers.Count() != 0)
@ -532,7 +533,7 @@ namespace ICSharpCode.NRefactory.Visitors
} }
return new TypedValue(array, type); return new TypedValue(array, type);
} }
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{ {
TypedValue target; TypedValue target;
@ -558,26 +559,23 @@ namespace ICSharpCode.NRefactory.Visitors
((IDebugMemberInfo)memberInfos[0]).MemberType ((IDebugMemberInfo)memberInfos[0]).MemberType
); );
} }
public override object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data) public override object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
{ {
return Evaluate(parenthesizedExpression.Expression); return Evaluate(parenthesizedExpression.Expression);
} }
public override object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data) public override object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data)
{ {
return CreateValue(primitiveExpression.Value); return CreateValue(primitiveExpression.Value);
} }
TypedValue GetThisValue() TypedValue GetThisValue()
{ {
// This is needed so that captured 'this' is supported // This is needed so that captured 'this' is supported
DebugLocalVariableInfo thisVar = context.MethodInfo.GetLocalVariableThis(); return new TypedValue(context.GetThisValue(), (DebugType)context.MethodInfo.DeclaringType);
if (thisVar != null)
return new TypedValue(thisVar.GetValue(context), (DebugType)thisVar.LocalType);
return null;
} }
public override object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data) public override object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data)
{ {
TypedValue thisValue = GetThisValue(); TypedValue thisValue = GetThisValue();
@ -585,9 +583,9 @@ namespace ICSharpCode.NRefactory.Visitors
throw new GetValueException(context.MethodInfo.FullName + " is static method and does not have \"this\""); throw new GetValueException(context.MethodInfo.FullName + " is static method and does not have \"this\"");
return thisValue; return thisValue;
} }
#region Binary and unary expressions #region Binary and unary expressions
public override object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) public override object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
{ {
TypedValue value = Evaluate(unaryOperatorExpression.Expression); TypedValue value = Evaluate(unaryOperatorExpression.Expression);
@ -664,7 +662,7 @@ namespace ICSharpCode.NRefactory.Visitors
throw new EvaluateException(unaryOperatorExpression, "Can not use the unary operator {0} on type {1}", op.ToString(), value.Type.FullName); throw new EvaluateException(unaryOperatorExpression, "Can not use the unary operator {0} on type {1}", op.ToString(), value.Type.FullName);
} }
/// <summary> /// <summary>
/// Perform given arithmetic operation. /// Perform given arithmetic operation.
/// The arguments must be already converted to the correct types. /// The arguments must be already converted to the correct types.
@ -732,7 +730,7 @@ namespace ICSharpCode.NRefactory.Visitors
return null; return null;
} }
public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
{ {
BinaryOperatorType op = binaryOperatorExpression.Operator; BinaryOperatorType op = binaryOperatorExpression.Operator;
@ -843,7 +841,7 @@ namespace ICSharpCode.NRefactory.Visitors
throw new EvaluateException(binaryOperatorExpression, "Can not use the binary operator {0} on types {1} and {2}", op.ToString(), left.Type.FullName, right.Type.FullName); throw new EvaluateException(binaryOperatorExpression, "Can not use the binary operator {0} on types {1} and {2}", op.ToString(), left.Type.FullName, right.Type.FullName);
} }
/// <summary> /// <summary>
/// Perform given arithmetic operation. /// Perform given arithmetic operation.
/// The arguments must be already converted to the correct types. /// The arguments must be already converted to the correct types.
@ -1024,7 +1022,7 @@ namespace ICSharpCode.NRefactory.Visitors
return null; return null;
} }
} }
#endregion #endregion
} }
} }

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

@ -100,7 +100,7 @@ namespace ILSpy.Debugger.Models.TreeModel
// This is needed for expanding IEnumerable<T> // This is needed for expanding IEnumerable<T>
var type = new SimpleType() { Identifier = typeof(IList).FullName }; 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 }; targetObject = new CastExpression() { Expression = targetObject.Clone(), Type = type };
@ -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");
}
}
} }
} }

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

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

Loading…
Cancel
Save