Browse Source

Support for member fields from yield/delegate

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5122 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 17 years ago
parent
commit
3cd7721e82
  1. 33
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs
  2. 15
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/DebugType_CompilerGeneratedClasses.cs
  3. 20
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/ExpressionEvaluator.cs

33
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs

@ -275,16 +275,19 @@ namespace Debugger @@ -275,16 +275,19 @@ namespace Debugger
Value local = context.GetLocalVariableValue(identifier);
if (local != null) return local;
if (!context.MethodInfo.IsStatic) {
Value member = context.GetThisValue().GetMemberValue(identifier);
// Instance class members
Value thisValue = GetThisValue();
if (thisValue != null) {
Value member = thisValue.GetMemberValue(identifier);
if (member != null) return member;
} else {
IDebugMemberInfo memberInfo =
(IDebugMemberInfo)context.MethodInfo.DeclaringType.GetField(identifier) ??
(IDebugMemberInfo)context.MethodInfo.DeclaringType.GetProperty(identifier);
if (memberInfo != null && memberInfo.IsStatic) {
return Value.GetMemberValue(null, (MemberInfo)memberInfo, null);
}
}
// Static class members
IDebugMemberInfo memberInfo =
(IDebugMemberInfo)context.MethodInfo.DeclaringType.GetField(identifier) ??
(IDebugMemberInfo)context.MethodInfo.DeclaringType.GetProperty(identifier);
if (memberInfo != null && memberInfo.IsStatic) {
return Value.GetMemberValue(null, (MemberInfo)memberInfo, null);
}
throw new GetValueException("Identifier \"" + identifier + "\" not found in this context");
@ -452,14 +455,22 @@ namespace Debugger @@ -452,14 +455,22 @@ namespace Debugger
return Eval.CreateValue(context.AppDomain, primitiveExpression.Value);
}
public override object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data)
Value GetThisValue()
{
// This is needed so that captured 'this' is supported
foreach(DebugLocalVariableInfo locVar in context.MethodInfo.GetLocalVariables()) {
if (locVar.IsThis)
return locVar.GetValue(context);
}
throw new GetValueException(context.MethodInfo.FullName + " does not have \"this\"");
return null;
}
public override object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data)
{
Value thisValue = GetThisValue();
if (thisValue == null)
throw new GetValueException(context.MethodInfo.FullName + " does not have \"this\"");
return thisValue;
}
public override object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)

15
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/DebugType_CompilerGeneratedClasses.cs

@ -19,6 +19,9 @@ namespace Debugger.Tests.TestPrograms @@ -19,6 +19,9 @@ namespace Debugger.Tests.TestPrograms
new List<object>(new DebugType_CompilerGeneratedClasses().MyEnum());
}
string instanceField = "instance field value";
static string staticField = "static field value";
IEnumerable<object> MyEnum()
{
int stateFullVar = 101;
@ -75,6 +78,9 @@ namespace Debugger.Tests { @@ -75,6 +78,9 @@ namespace Debugger.Tests {
PrintLocalVariables("OutterDelegateLocalVariables");
process.Continue();
PrintLocalVariables("InnterDelegateLocalVariables");
Eval("nestedDelegArg");
Eval("instanceField");
Eval("staticField");
EndTest();
}
}
@ -89,7 +95,7 @@ namespace Debugger.Tests { @@ -89,7 +95,7 @@ namespace Debugger.Tests {
<ProcessStarted />
<ModuleLoaded>mscorlib.dll (No symbols)</ModuleLoaded>
<ModuleLoaded>DebugType_CompilerGeneratedClasses.exe (Has symbols)</ModuleLoaded>
<DebuggingPaused>Break DebugType_CompilerGeneratedClasses.cs:35,5-35,41</DebuggingPaused>
<DebuggingPaused>Break DebugType_CompilerGeneratedClasses.cs:38,5-38,41</DebuggingPaused>
<YieldLocalVariables>
<Item>
<LocalVariable
@ -140,7 +146,7 @@ namespace Debugger.Tests { @@ -140,7 +146,7 @@ namespace Debugger.Tests {
Value="103" />
</Item>
</YieldLocalVariables>
<DebuggingPaused>Break DebugType_CompilerGeneratedClasses.cs:54,6-54,42</DebuggingPaused>
<DebuggingPaused>Break DebugType_CompilerGeneratedClasses.cs:57,6-57,42</DebuggingPaused>
<OutterDelegateLocalVariables>
<Item>
<LocalVariable
@ -197,7 +203,7 @@ namespace Debugger.Tests { @@ -197,7 +203,7 @@ namespace Debugger.Tests {
Value="{Debugger.Tests.TestPrograms.DebugType_CompilerGeneratedClasses}" />
</Item>
</OutterDelegateLocalVariables>
<DebuggingPaused>Break DebugType_CompilerGeneratedClasses.cs:51,7-51,43</DebuggingPaused>
<DebuggingPaused>Break DebugType_CompilerGeneratedClasses.cs:54,7-54,43</DebuggingPaused>
<InnterDelegateLocalVariables>
<Item>
<LocalVariable
@ -248,6 +254,9 @@ namespace Debugger.Tests { @@ -248,6 +254,9 @@ namespace Debugger.Tests {
Value="{Debugger.Tests.TestPrograms.DebugType_CompilerGeneratedClasses}" />
</Item>
</InnterDelegateLocalVariables>
<Eval> nestedDelegArg = 402 </Eval>
<Eval> instanceField = "instance field value" </Eval>
<Eval> staticField = "static field value" </Eval>
<ProcessExited />
</Test>
</DebuggerTests>

20
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/ExpressionEvaluator.cs

@ -61,8 +61,16 @@ namespace Debugger.Tests.TestPrograms @@ -61,8 +61,16 @@ namespace Debugger.Tests.TestPrograms
return "derived Foo - string";
}
}
string instanceField = "instance field value";
static string staticField = "static field value";
public static void Main()
{
new ExpressionEvaluator().Fun("function argument");
}
public void Fun(string arg)
{
bool flag = true;
byte b = 1;
@ -109,6 +117,10 @@ namespace Debugger.Tests { @@ -109,6 +117,10 @@ namespace Debugger.Tests {
pi + hi
pi + ' ' + hi
arg
instanceField
staticField
(5 + 6) % (1 + 2)
3 % 2 == 1
15 & 255
@ -203,7 +215,7 @@ namespace Debugger.Tests { @@ -203,7 +215,7 @@ namespace Debugger.Tests {
<ProcessStarted />
<ModuleLoaded>mscorlib.dll (No symbols)</ModuleLoaded>
<ModuleLoaded>ExpressionEvaluator.exe (Has symbols)</ModuleLoaded>
<DebuggingPaused>Break ExpressionEvaluator.cs:80,4-80,40</DebuggingPaused>
<DebuggingPaused>Break ExpressionEvaluator.cs:88,4-88,40</DebuggingPaused>
<Eval> </Eval>
<Eval> b = 1 </Eval>
<Eval> i = 4 </Eval>
@ -217,6 +229,10 @@ namespace Debugger.Tests { @@ -217,6 +229,10 @@ namespace Debugger.Tests {
<Eval> pi + hi = "3.14hi" </Eval>
<Eval> pi + " " + hi = "3.14 hi" </Eval>
<Eval> </Eval>
<Eval> arg = "function argument" </Eval>
<Eval> instanceField = "instance field value" </Eval>
<Eval> staticField = "static field value" </Eval>
<Eval> </Eval>
<Eval> (5 + 6) % (1 + 2) = 2 </Eval>
<Eval> 3 % 2 == 1 = True </Eval>
<Eval> 15 &amp; 255 = 15 </Eval>

Loading…
Cancel
Save