Browse Source

Added debugger test: FunctionVariablesLifetime;

Fixed function so that expired variables do not throw exceptions

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@870 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 20 years ago
parent
commit
bf0bea81ce
  1. 35
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs
  2. 23
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PropertyVariable.cs
  3. 1
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Debugger.Tests.csproj
  4. 52
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs
  5. 1
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestProgram.cs
  6. 39
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/FunctionVariablesLifetime.cs

35
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs

@ -80,14 +80,18 @@ namespace Debugger @@ -80,14 +80,18 @@ namespace Debugger
}
}
public ObjectValue ThisValue {
public Value ThisValue {
get {
if (IsStatic) {
throw new DebuggerException("Static method does not have 'this'.");
} else {
ICorDebugValue argThis = null;
CorILFrame.GetArgument(0, out argThis);
return new ObjectValue(debugger, argThis, ContaingClass);
if (this.HasExpired) {
return new UnavailableValue(debugger, "Function has expired");
} else {
ICorDebugValue argThis = null;
CorILFrame.GetArgument(0, out argThis);
return new ObjectValue(debugger, argThis, ContaingClass);
}
}
}
}
@ -406,6 +410,7 @@ namespace Debugger @@ -406,6 +410,7 @@ namespace Debugger
public IEnumerable<Variable> ContaingClassVariables {
get {
// TODO: Should work for static
if (!IsStatic) {
foreach(Variable var in ThisValue.GetSubVariables(delegate{return ThisValue;})) {
yield return var;
@ -450,7 +455,11 @@ namespace Debugger @@ -450,7 +455,11 @@ namespace Debugger
return new Variable(debugger,
GetParameterName(index),
delegate {
return Value.CreateValue(debugger, GetArgumentValue(index));
if (this.HasExpired) {
return new UnavailableValue(debugger, "Function has expired");
} else {
return Value.CreateValue(debugger, GetArgumentValue(index));
}
});
}
@ -483,7 +492,11 @@ namespace Debugger @@ -483,7 +492,11 @@ namespace Debugger
yield return new PropertyVariable(debugger,
method.Name.Remove(0, 4),
delegate {
return CreatePropertyEval(method);
if (this.HasExpired && !this.IsStatic) {
return null;
} else {
return CreatePropertyEval(method);
}
});
}
}
@ -522,9 +535,13 @@ namespace Debugger @@ -522,9 +535,13 @@ namespace Debugger
return new Variable(debugger,
symVar.Name,
delegate {
ICorDebugValue corValue;
CorILFrame.GetLocalVariable((uint)symVar.AddressField1, out corValue);
return Value.CreateValue(debugger, corValue);
if (this.HasExpired) {
return new UnavailableValue(debugger, "Function has expired");
} else {
ICorDebugValue corValue;
CorILFrame.GetLocalVariable((uint)symVar.AddressField1, out corValue);
return Value.CreateValue(debugger, corValue);
}
});
}
}

23
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PropertyVariable.cs

@ -12,7 +12,7 @@ using Debugger.Interop.CorDebug; @@ -12,7 +12,7 @@ using Debugger.Interop.CorDebug;
namespace Debugger
{
/// <summary>
/// Delegate that is used to get eval. This delegate may be called at any time and should never return null.
/// Delegate that is used to get eval. This delegate may be called at any time and may return null.
/// </summary>
public delegate Eval EvalCreator();
@ -24,12 +24,22 @@ namespace Debugger @@ -24,12 +24,22 @@ namespace Debugger
internal PropertyVariable(NDebugger debugger, string name, EvalCreator evalCreator):base(debugger, name, null)
{
this.evalCreator = evalCreator;
this.valueGetter = delegate{return Eval.Result;};
this.valueGetter = delegate {
if (Eval != null) {
return Eval.Result;
} else {
return new UnavailableValue(debugger, "Property has expired");
}
};
}
public bool IsEvaluated {
get {
return Eval.Evaluated;
if (Eval != null) {
return Eval.Evaluated;
} else {
return true;
}
}
}
@ -37,9 +47,10 @@ namespace Debugger @@ -37,9 +47,10 @@ namespace Debugger
get {
if (cachedEval == null || cachedEval.HasExpired) {
cachedEval = evalCreator();
if (cachedEval == null) throw new DebuggerException("EvalGetter returned null");
cachedEval.EvalStarted += delegate { OnValueChanged(); };
cachedEval.EvalComplete += delegate { OnValueChanged(); };
if (cachedEval != null) {
cachedEval.EvalStarted += delegate { OnValueChanged(); };
cachedEval.EvalComplete += delegate { OnValueChanged(); };
}
}
return cachedEval;
}

1
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Debugger.Tests.csproj

@ -51,6 +51,7 @@ @@ -51,6 +51,7 @@
<Compile Include="Src\TestPrograms\FunctionArgumentVariables.cs" />
<Compile Include="Src\TestPrograms\FunctionLocalVariables.cs" />
<Compile Include="Src\TestPrograms\FunctionLifetime.cs" />
<Compile Include="Src\TestPrograms\FunctionVariablesLifetime.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Src" />

52
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs

@ -342,5 +342,57 @@ namespace Debugger.Tests @@ -342,5 +342,57 @@ namespace Debugger.Tests
debugger.Continue();
debugger.WaitForPrecessExit();
}
[Test]
public void FunctionVariablesLifetime()
{
Function function = null;
Variable argument = null;
Variable local = null;
Variable @class = null;
StartProgram("FunctionVariablesLifetime");
WaitForPause(PausedReason.Break, null);
function = debugger.CurrentFunction;
Assert.IsNotNull(function);
Assert.AreEqual("Function", function.Name);
argument = function.GetArgumentVariable(0);
foreach(Variable var in function.LocalVariables) {
local = var;
}
foreach(Variable var in function.ContaingClassVariables) {
@class = var;
}
Assert.IsNotNull(argument);
Assert.IsNotNull(local);
Assert.IsNotNull(@class);
Assert.AreEqual("argument", argument.Name);
Assert.AreEqual("local", local.Name);
Assert.AreEqual("class", @class.Name);
Assert.AreEqual("1", argument.Value.AsString);
Assert.AreEqual("2", local.Value.AsString);
Assert.AreEqual("3", @class.Value.AsString);
debugger.Continue(); // Go to the SubFunction
WaitForPause(PausedReason.Break, null);
Assert.AreEqual("1", argument.Value.AsString);
Assert.AreEqual("2", local.Value.AsString);
Assert.AreEqual("3", @class.Value.AsString);
debugger.Continue(); // Go back to Function
WaitForPause(PausedReason.Break, null);
Assert.AreEqual("1", argument.Value.AsString);
Assert.AreEqual("2", local.Value.AsString);
Assert.AreEqual("3", @class.Value.AsString);
debugger.Continue(); // Setp out of function
WaitForPause(PausedReason.Break, null);
Assert.AreEqual(typeof(UnavailableValue), argument.Value.GetType());
Assert.AreEqual(typeof(UnavailableValue), local.Value.GetType());
Assert.AreEqual(typeof(UnavailableValue), @class.Value.GetType());
debugger.Continue();
debugger.WaitForPrecessExit();
}
}
}

1
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestProgram.cs

@ -26,6 +26,7 @@ namespace Debugger.Tests @@ -26,6 +26,7 @@ namespace Debugger.Tests
case "FunctionArgumentVariables": Progs.FunctionArgumentVariables.Main(); break;
case "FunctionLifetime": Progs.FunctionLifetime.Main(); break;
case "FunctionLocalVariables": Progs.FunctionLocalVariables.Main(); break;
case "FunctionVariablesLifetime": Progs.FunctionVariablesLifetime.Main(); break;
case "HelloWorld": Progs.HelloWorld.Main(); break;
case "SimpleProgram": Progs.SimpleProgram.Main(); break;
case "Stepping": Progs.Stepping.Main(); break;

39
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/FunctionVariablesLifetime.cs

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
// <version>$Revision$</version>
// </file>
using System;
#pragma warning disable 0219, 0414
namespace Debugger.Tests.TestPrograms
{
public class FunctionVariablesLifetime
{
public int @class = 3;
public static void Main()
{
new FunctionVariablesLifetime().Function(1);
System.Diagnostics.Debugger.Break(); // 4
}
void Function(int argument)
{
int local = 2;
System.Diagnostics.Debugger.Break(); // 1
SubFunction();
System.Diagnostics.Debugger.Break(); // 3
}
void SubFunction()
{
System.Diagnostics.Debugger.Break(); // 2
}
}
}
#pragma warning restore 0219, 0414
Loading…
Cancel
Save