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ý 20 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 @@
<Compile Include="Src\Threads\FrameID.cs" /> <Compile Include="Src\Threads\FrameID.cs" />
<Compile Include="Src\Wrappers\CorDebug\ICorDebugChain.cs" /> <Compile Include="Src\Wrappers\CorDebug\ICorDebugChain.cs" />
<Compile Include="Src\Wrappers\CorDebug\ICorDebugFrame.cs" /> <Compile Include="Src\Wrappers\CorDebug\ICorDebugFrame.cs" />
<Compile Include="Src\Variables\PersistentValue.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="README.TXT" /> <Content Include="README.TXT" />

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

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

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

@ -92,11 +92,11 @@ namespace Debugger
public Variable this[uint[] indices] { public Variable this[uint[] indices] {
get { 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(); uint[] indices = (uint[])itemIndices.Clone();
@ -109,12 +109,12 @@ namespace Debugger
return new Variable(debugger, return new Variable(debugger,
elementName, 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)) { if (this.IsEquivalentValue(updatedVal)) {
ICorDebugValue element; ICorDebugValue element;
unsafe { unsafe {
@ -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]; uint[] indices = new uint[rank];
@ -147,7 +147,7 @@ namespace Debugger
} }
if (indices[0] >= dimensions[0]) break; // We are done if (indices[0] >= dimensions[0]) break; // We are done
yield return GetItem(indices, getter); yield return GetItem(indices, pValue);
indices[rank - 1]++; indices[rank - 1]++;
} }

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

@ -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.isStatic = isStatic;
this.isPublic = isPublic; this.isPublic = isPublic;

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

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

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

@ -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
internal PropertyVariable(NDebugger debugger, string name, bool isStatic, bool isPublic, EvalCreator evalCreator):base(debugger, name, isStatic, isPublic, null) internal PropertyVariable(NDebugger debugger, string name, bool isStatic, bool isPublic, EvalCreator evalCreator):base(debugger, name, isStatic, isPublic, null)
{ {
this.evalCreator = evalCreator; this.evalCreator = evalCreator;
this.valueGetter = delegate { return GetValueOfResult(); }; this.pValue = new PersistentValue(delegate { return GetValueOfResult(); });
} }
Value GetValueOfResult() Value GetValueOfResult()

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

@ -112,7 +112,7 @@ namespace Debugger
/// Gets the subvariables of this value /// Gets the subvariables of this value
/// </summary> /// </summary>
/// <param name="getter">Delegate that will be called to get the up-to-date value</param> /// <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; yield break;
} }
@ -127,14 +127,14 @@ namespace Debugger
public Variable this[string variableName] { public Variable this[string variableName] {
get { 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; if (v.Name == variableName) return v;
} }
throw new DebuggerException("Subvariable " + variableName + " does not exist"); throw new DebuggerException("Subvariable " + variableName + " does not exist");
} }
} }
internal Value(NDebugger debugger, ICorDebugValue corValue) protected Value(NDebugger debugger, ICorDebugValue corValue)
{ {
this.debugger = debugger; this.debugger = debugger;
if (corValue != null) { if (corValue != null) {

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

@ -11,11 +11,6 @@ using Debugger.Wrappers.CorDebug;
namespace Debugger 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 public class Variable: RemotingObjectBase
{ {
protected NDebugger debugger; protected NDebugger debugger;
@ -23,7 +18,7 @@ namespace Debugger
string name; string name;
VariableCollection subVariables; VariableCollection subVariables;
internal protected ValueGetter valueGetter; internal protected PersistentValue pValue;
internal Value cachedValue; internal Value cachedValue;
event EventHandler<DebuggerEventArgs> valueChanged; event EventHandler<DebuggerEventArgs> valueChanged;
@ -61,7 +56,7 @@ namespace Debugger
public Value Value { public Value Value {
get { get {
if (cachedValue == null || cachedValue.IsExpired) { if (cachedValue == null || cachedValue.IsExpired) {
cachedValue = valueGetter(); cachedValue = pValue.Value;
if (cachedValue == null) throw new DebuggerException("ValueGetter returned null"); if (cachedValue == null) throw new DebuggerException("ValueGetter returned null");
cachedValue.ValueChanged += delegate { OnValueChanged(); }; cachedValue.ValueChanged += delegate { OnValueChanged(); };
} }
@ -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.debugger = debugger;
this.name = name; this.name = name;
this.valueGetter = valueGetter; this.pValue = pValue;
this.subVariables = new VariableCollection(debugger); this.subVariables = new VariableCollection(debugger);
this.subVariables.Updating += OnSubVariablesUpdating; this.subVariables.Updating += OnSubVariablesUpdating;
@ -131,7 +126,7 @@ namespace Debugger
void OnSubVariablesUpdating(object sender, VariableCollectionEventArgs e) 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
// HACK: Realy bad object-oriented design!!! // HACK: Realy bad object-oriented design!!!
// Trasfer the new variable into the old one // Trasfer the new variable into the old one
if (oldVariable != newVariable) { if (oldVariable != newVariable) {
oldVariable.valueGetter = newVariable.valueGetter; oldVariable.pValue = newVariable.pValue;
oldVariable.cachedValue = null; oldVariable.cachedValue = null;
if (newVariable is ClassVariable && oldVariable is ClassVariable) { if (newVariable is ClassVariable && oldVariable is ClassVariable) {
((ClassVariable)oldVariable).isPublic = ((ClassVariable)oldVariable).isPublic; ((ClassVariable)oldVariable).isPublic = ((ClassVariable)oldVariable).isPublic;

Loading…
Cancel
Save