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. 18
      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
Value local = context.GetLocalVariableValue(identifier); Value local = context.GetLocalVariableValue(identifier);
if (local != null) return local; if (local != null) return local;
if (!context.MethodInfo.IsStatic) { // Instance class members
Value member = context.GetThisValue().GetMemberValue(identifier); Value thisValue = GetThisValue();
if (thisValue != null) {
Value member = thisValue.GetMemberValue(identifier);
if (member != null) return member; if (member != null) return member;
} else { }
IDebugMemberInfo memberInfo =
(IDebugMemberInfo)context.MethodInfo.DeclaringType.GetField(identifier) ?? // Static class members
(IDebugMemberInfo)context.MethodInfo.DeclaringType.GetProperty(identifier); IDebugMemberInfo memberInfo =
if (memberInfo != null && memberInfo.IsStatic) { (IDebugMemberInfo)context.MethodInfo.DeclaringType.GetField(identifier) ??
return Value.GetMemberValue(null, (MemberInfo)memberInfo, null); (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"); throw new GetValueException("Identifier \"" + identifier + "\" not found in this context");
@ -452,14 +455,22 @@ namespace Debugger
return Eval.CreateValue(context.AppDomain, primitiveExpression.Value); 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 // This is needed so that captured 'this' is supported
foreach(DebugLocalVariableInfo locVar in context.MethodInfo.GetLocalVariables()) { foreach(DebugLocalVariableInfo locVar in context.MethodInfo.GetLocalVariables()) {
if (locVar.IsThis) if (locVar.IsThis)
return locVar.GetValue(context); 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) 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
new List<object>(new DebugType_CompilerGeneratedClasses().MyEnum()); new List<object>(new DebugType_CompilerGeneratedClasses().MyEnum());
} }
string instanceField = "instance field value";
static string staticField = "static field value";
IEnumerable<object> MyEnum() IEnumerable<object> MyEnum()
{ {
int stateFullVar = 101; int stateFullVar = 101;
@ -75,6 +78,9 @@ namespace Debugger.Tests {
PrintLocalVariables("OutterDelegateLocalVariables"); PrintLocalVariables("OutterDelegateLocalVariables");
process.Continue(); process.Continue();
PrintLocalVariables("InnterDelegateLocalVariables"); PrintLocalVariables("InnterDelegateLocalVariables");
Eval("nestedDelegArg");
Eval("instanceField");
Eval("staticField");
EndTest(); EndTest();
} }
} }
@ -89,7 +95,7 @@ namespace Debugger.Tests {
<ProcessStarted /> <ProcessStarted />
<ModuleLoaded>mscorlib.dll (No symbols)</ModuleLoaded> <ModuleLoaded>mscorlib.dll (No symbols)</ModuleLoaded>
<ModuleLoaded>DebugType_CompilerGeneratedClasses.exe (Has 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> <YieldLocalVariables>
<Item> <Item>
<LocalVariable <LocalVariable
@ -140,7 +146,7 @@ namespace Debugger.Tests {
Value="103" /> Value="103" />
</Item> </Item>
</YieldLocalVariables> </YieldLocalVariables>
<DebuggingPaused>Break DebugType_CompilerGeneratedClasses.cs:54,6-54,42</DebuggingPaused> <DebuggingPaused>Break DebugType_CompilerGeneratedClasses.cs:57,6-57,42</DebuggingPaused>
<OutterDelegateLocalVariables> <OutterDelegateLocalVariables>
<Item> <Item>
<LocalVariable <LocalVariable
@ -197,7 +203,7 @@ namespace Debugger.Tests {
Value="{Debugger.Tests.TestPrograms.DebugType_CompilerGeneratedClasses}" /> Value="{Debugger.Tests.TestPrograms.DebugType_CompilerGeneratedClasses}" />
</Item> </Item>
</OutterDelegateLocalVariables> </OutterDelegateLocalVariables>
<DebuggingPaused>Break DebugType_CompilerGeneratedClasses.cs:51,7-51,43</DebuggingPaused> <DebuggingPaused>Break DebugType_CompilerGeneratedClasses.cs:54,7-54,43</DebuggingPaused>
<InnterDelegateLocalVariables> <InnterDelegateLocalVariables>
<Item> <Item>
<LocalVariable <LocalVariable
@ -248,6 +254,9 @@ namespace Debugger.Tests {
Value="{Debugger.Tests.TestPrograms.DebugType_CompilerGeneratedClasses}" /> Value="{Debugger.Tests.TestPrograms.DebugType_CompilerGeneratedClasses}" />
</Item> </Item>
</InnterDelegateLocalVariables> </InnterDelegateLocalVariables>
<Eval> nestedDelegArg = 402 </Eval>
<Eval> instanceField = "instance field value" </Eval>
<Eval> staticField = "static field value" </Eval>
<ProcessExited /> <ProcessExited />
</Test> </Test>
</DebuggerTests> </DebuggerTests>

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

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

Loading…
Cancel
Save