Browse Source

ValueGetter delegate wrapped in PersistentValue class

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1545 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 19 years ago
parent
commit
cf51e9a0b4
  1. 1
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj
  2. 8
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs
  3. 14
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayValue.cs
  4. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ClassVariable.cs
  5. 38
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValue.cs
  6. 38
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PersistentValue.cs
  7. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PropertyVariable.cs
  8. 6
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Value.cs
  9. 17
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs
  10. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/VariableCollection.cs

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

@ -380,6 +380,7 @@ @@ -380,6 +380,7 @@
<Compile Include="Src\Threads\FrameID.cs" />
<Compile Include="Src\Wrappers\CorDebug\ICorDebugChain.cs" />
<Compile Include="Src\Wrappers\CorDebug\ICorDebugFrame.cs" />
<Compile Include="Src\Variables\PersistentValue.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="README.TXT" />

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

@ -383,7 +383,7 @@ namespace Debugger @@ -383,7 +383,7 @@ namespace Debugger
if (!IsStatic) {
yield return new Variable(debugger,
"this",
delegate { return ThisValue; });
new PersistentValue(delegate { return ThisValue; }));
}
foreach(Variable var in ArgumentVariables) {
yield return var;
@ -401,7 +401,7 @@ namespace Debugger @@ -401,7 +401,7 @@ namespace Debugger
get {
// TODO: Should work for static
if (!IsStatic) {
foreach(Variable var in ThisValue.GetSubVariables(delegate{return ThisValue;})) {
foreach(Variable var in ThisValue.GetSubVariables(new PersistentValue(delegate{return ThisValue;}))) {
yield return var;
}
}
@ -433,7 +433,7 @@ namespace Debugger @@ -433,7 +433,7 @@ namespace Debugger
{
return new Variable(debugger,
GetParameterName(index),
delegate { return GetArgumentValue(index); });
new PersistentValue(delegate { return GetArgumentValue(index); }));
}
Value GetArgumentValue(int index)
@ -488,7 +488,7 @@ namespace Debugger @@ -488,7 +488,7 @@ namespace Debugger
{
return new Variable(debugger,
symVar.Name,
delegate { return GetValueOfLocalVariable(symVar); });
new PersistentValue(delegate { return GetValueOfLocalVariable(symVar); }));
}
Value GetValueOfLocalVariable(ISymUnmanagedVariable symVar)

14
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayValue.cs

@ -92,11 +92,11 @@ namespace Debugger @@ -92,11 +92,11 @@ namespace Debugger
public Variable this[uint[] indices] {
get {
return GetItem(indices, delegate {return this;});
return GetItem(indices, new PersistentValue(delegate {return this;}));
}
}
Variable GetItem(uint[] itemIndices, ValueGetter getter)
Variable GetItem(uint[] itemIndices, PersistentValue pValue)
{
uint[] indices = (uint[])itemIndices.Clone();
@ -109,12 +109,12 @@ namespace Debugger @@ -109,12 +109,12 @@ namespace Debugger
return new Variable(debugger,
elementName,
delegate { return GetValueOfItem(indices, getter); });
new PersistentValue(delegate { return GetValueOfItem(indices, pValue); }));
}
Value GetValueOfItem(uint[] indices, ValueGetter getter)
Value GetValueOfItem(uint[] indices, PersistentValue pValue)
{
ArrayValue updatedVal = getter() as ArrayValue;
ArrayValue updatedVal = pValue.Value as ArrayValue;
if (this.IsEquivalentValue(updatedVal)) {
ICorDebugValue element;
unsafe {
@ -134,7 +134,7 @@ namespace Debugger @@ -134,7 +134,7 @@ namespace Debugger
}
}
public override IEnumerable<Variable> GetSubVariables(ValueGetter getter)
public override IEnumerable<Variable> GetSubVariables(PersistentValue pValue)
{
uint[] indices = new uint[rank];
@ -147,7 +147,7 @@ namespace Debugger @@ -147,7 +147,7 @@ namespace Debugger
}
if (indices[0] >= dimensions[0]) break; // We are done
yield return GetItem(indices, getter);
yield return GetItem(indices, pValue);
indices[rank - 1]++;
}

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ClassVariable.cs

@ -26,7 +26,7 @@ namespace Debugger @@ -26,7 +26,7 @@ namespace Debugger
}
}
public ClassVariable(NDebugger debugger, string name, bool isStatic, bool isPublic, ValueGetter valueGetter): base(debugger, name, valueGetter)
public ClassVariable(NDebugger debugger, string name, bool isStatic, bool isPublic, PersistentValue pValue): base(debugger, name, pValue)
{
this.isStatic = isStatic;
this.isPublic = isPublic;

38
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValue.cs

@ -111,22 +111,22 @@ namespace Debugger @@ -111,22 +111,22 @@ namespace Debugger
}
}
public override IEnumerable<Variable> GetSubVariables(ValueGetter getter)
public override IEnumerable<Variable> GetSubVariables(PersistentValue pValue)
{
if (HasBaseClass) {
yield return GetBaseClassVariable(getter);
yield return GetBaseClassVariable(pValue);
}
foreach(Variable var in GetFieldVariables(getter)) {
foreach(Variable var in GetFieldVariables(pValue)) {
yield return var;
}
foreach(Variable var in GetPropertyVariables(getter)) {
foreach(Variable var in GetPropertyVariables(pValue)) {
yield return var;
}
}
public IEnumerable<Variable> GetFieldVariables(ValueGetter getter)
public IEnumerable<Variable> GetFieldVariables(PersistentValue pValue)
{
foreach(FieldProps f in metaData.EnumFields(ClassToken)) {
FieldProps field = f; // One per scope/delegate
@ -136,13 +136,13 @@ namespace Debugger @@ -136,13 +136,13 @@ namespace Debugger
field.Name,
field.IsStatic,
field.IsPublic,
delegate { return GetValueOfField(field, getter); });
new PersistentValue(delegate { return GetValueOfField(field, pValue); }));
}
}
Value GetValueOfField(FieldProps field, ValueGetter getter)
Value GetValueOfField(FieldProps field, PersistentValue pValue)
{
Value updatedVal = getter();
Value updatedVal = pValue.Value;
if (updatedVal is UnavailableValue) return updatedVal;
if (this.IsEquivalentValue(updatedVal)) {
return GetValue(updatedVal, field);
@ -151,7 +151,7 @@ namespace Debugger @@ -151,7 +151,7 @@ namespace Debugger
}
}
public IEnumerable<Variable> GetPropertyVariables(ValueGetter getter)
public IEnumerable<Variable> GetPropertyVariables(PersistentValue pValue)
{
foreach(MethodProps m in Methods) {
MethodProps method = m; // One per scope/delegate
@ -160,29 +160,29 @@ namespace Debugger @@ -160,29 +160,29 @@ namespace Debugger
method.Name.Remove(0, 4),
method.IsStatic,
method.IsPublic,
delegate { return CreatePropertyEval(method, getter); });
delegate { return CreatePropertyEval(method, pValue); });
}
}
}
Eval CreatePropertyEval(MethodProps method, ValueGetter getter)
Eval CreatePropertyEval(MethodProps method, PersistentValue pValue)
{
Value updatedVal = getter();
Value updatedVal = pValue.Value;
if (updatedVal is UnavailableValue) {
return null;
}
if (this.IsEquivalentValue(updatedVal)) {
ICorDebugFunction evalCorFunction = Module.CorModule.GetFunctionFromToken(method.Token);
return new Eval(debugger, evalCorFunction, delegate { return GetArgsForEval(method, getter); });
return new Eval(debugger, evalCorFunction, delegate { return GetArgsForEval(method, pValue); });
} else {
return null;
}
}
ICorDebugValue[] GetArgsForEval(MethodProps method, ValueGetter getter)
ICorDebugValue[] GetArgsForEval(MethodProps method, PersistentValue pValue)
{
ObjectValue updatedVal = getter() as ObjectValue;
ObjectValue updatedVal = pValue.Value as ObjectValue;
if (this.IsEquivalentValue(updatedVal)) {
if (method.IsStatic) {
return new ICorDebugValue[] {};
@ -226,20 +226,20 @@ namespace Debugger @@ -226,20 +226,20 @@ namespace Debugger
}
}
public Variable GetBaseClassVariable(ValueGetter getter)
public Variable GetBaseClassVariable(PersistentValue pValue)
{
if (HasBaseClass) {
return new Variable(debugger,
"<Base class>",
delegate { return GetBaseClassValue(getter); });
new PersistentValue(delegate { return GetBaseClassValue(pValue); }));
} else {
return null;
}
}
Value GetBaseClassValue(ValueGetter getter)
Value GetBaseClassValue(PersistentValue pValue)
{
Value updatedVal = getter();
Value updatedVal = pValue.Value;
if (updatedVal is UnavailableValue) return updatedVal;
if (this.IsEquivalentValue(updatedVal)) {
return ((ObjectValue)updatedVal).BaseClass;

38
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PersistentValue.cs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
// <version>$Revision$</version>
// </file>
using System;
using Debugger.Wrappers.CorDebug;
namespace Debugger
{
/// <summary>
/// PersistentValue is a container used to obtain the value of a given object even after continue.
/// </summary>
public class PersistentValue
{
/// <summary>
/// Delegate that is used to get value. This delegate may be called at any time and should never return null.
/// </summary>
public delegate Value ValueGetter();
ValueGetter getter;
public Value Value {
get {
return getter();
}
}
public PersistentValue(ValueGetter getter)
{
this.getter = getter;
}
}
}

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

@ -24,7 +24,7 @@ namespace Debugger @@ -24,7 +24,7 @@ namespace Debugger
internal PropertyVariable(NDebugger debugger, string name, bool isStatic, bool isPublic, EvalCreator evalCreator):base(debugger, name, isStatic, isPublic, null)
{
this.evalCreator = evalCreator;
this.valueGetter = delegate { return GetValueOfResult(); };
this.pValue = new PersistentValue(delegate { return GetValueOfResult(); });
}
Value GetValueOfResult()

6
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Value.cs

@ -112,7 +112,7 @@ namespace Debugger @@ -112,7 +112,7 @@ namespace Debugger
/// Gets the subvariables of this value
/// </summary>
/// <param name="getter">Delegate that will be called to get the up-to-date value</param>
public virtual IEnumerable<Variable> GetSubVariables(ValueGetter getter)
public virtual IEnumerable<Variable> GetSubVariables(PersistentValue pValue)
{
yield break;
}
@ -127,14 +127,14 @@ namespace Debugger @@ -127,14 +127,14 @@ namespace Debugger
public Variable this[string variableName] {
get {
foreach(Variable v in GetSubVariables(delegate{ return this.IsExpired?new UnavailableValue(debugger, "Value has expired"):this;})) {
foreach(Variable v in GetSubVariables(new PersistentValue(delegate{ return this.IsExpired?new UnavailableValue(debugger, "Value has expired"):this;}))) {
if (v.Name == variableName) return v;
}
throw new DebuggerException("Subvariable " + variableName + " does not exist");
}
}
internal Value(NDebugger debugger, ICorDebugValue corValue)
protected Value(NDebugger debugger, ICorDebugValue corValue)
{
this.debugger = debugger;
if (corValue != null) {

17
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs

@ -11,11 +11,6 @@ using Debugger.Wrappers.CorDebug; @@ -11,11 +11,6 @@ using Debugger.Wrappers.CorDebug;
namespace Debugger
{
/// <summary>
/// Delegate that is used to get value. This delegate may be called at any time and should never return null.
/// </summary>
public delegate Value ValueGetter();
public class Variable: RemotingObjectBase
{
protected NDebugger debugger;
@ -23,7 +18,7 @@ namespace Debugger @@ -23,7 +18,7 @@ namespace Debugger
string name;
VariableCollection subVariables;
internal protected ValueGetter valueGetter;
internal protected PersistentValue pValue;
internal Value cachedValue;
event EventHandler<DebuggerEventArgs> valueChanged;
@ -61,7 +56,7 @@ namespace Debugger @@ -61,7 +56,7 @@ namespace Debugger
public Value Value {
get {
if (cachedValue == null || cachedValue.IsExpired) {
cachedValue = valueGetter();
cachedValue = pValue.Value;
if (cachedValue == null) throw new DebuggerException("ValueGetter returned null");
cachedValue.ValueChanged += delegate { OnValueChanged(); };
}
@ -108,16 +103,16 @@ namespace Debugger @@ -108,16 +103,16 @@ namespace Debugger
}
public Variable(Value val, string name):this(val.Debugger, name, delegate {return val;})
public Variable(Value val, string name):this(val.Debugger, name, new PersistentValue(delegate {return val;}))
{
}
public Variable(NDebugger debugger, string name, ValueGetter valueGetter)
public Variable(NDebugger debugger, string name, PersistentValue pValue)
{
this.debugger = debugger;
this.name = name;
this.valueGetter = valueGetter;
this.pValue = pValue;
this.subVariables = new VariableCollection(debugger);
this.subVariables.Updating += OnSubVariablesUpdating;
@ -131,7 +126,7 @@ namespace Debugger @@ -131,7 +126,7 @@ namespace Debugger
void OnSubVariablesUpdating(object sender, VariableCollectionEventArgs e)
{
subVariables.UpdateTo(Value.GetSubVariables(delegate{return this.Value;}));
subVariables.UpdateTo(Value.GetSubVariables(new PersistentValue(delegate{return this.Value;})));
}
}
}

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/VariableCollection.cs

@ -148,7 +148,7 @@ namespace Debugger @@ -148,7 +148,7 @@ namespace Debugger
// HACK: Realy bad object-oriented design!!!
// Trasfer the new variable into the old one
if (oldVariable != newVariable) {
oldVariable.valueGetter = newVariable.valueGetter;
oldVariable.pValue = newVariable.pValue;
oldVariable.cachedValue = null;
if (newVariable is ClassVariable && oldVariable is ClassVariable) {
((ClassVariable)oldVariable).isPublic = ((ClassVariable)oldVariable).isPublic;

Loading…
Cancel
Save