Browse Source

Lazy getting of array values

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@831 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 20 years ago
parent
commit
dbe4cb08bd
  1. 2
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs
  2. 22
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/MetaData/MetaData.cs
  3. 12
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Exception.cs
  4. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs
  5. 87
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayValue.cs
  6. 61
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValue.cs
  7. 21
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Value.cs
  8. 14
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs

2
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs

@ -251,7 +251,7 @@ namespace ICSharpCode.SharpDevelop.Services @@ -251,7 +251,7 @@ namespace ICSharpCode.SharpDevelop.Services
{
DynamicTreeDebuggerRow row = (DynamicTreeDebuggerRow) sender;
row.ChildRows.Clear();
foreach(Variable variable in row.Variable.Value.SubVariables) {
foreach(Variable variable in row.Variable.SubVariables) {
DynamicTreeDebuggerRow newRow = new DynamicTreeDebuggerRow(variable);
DebuggerGridControl.AddColumns(newRow.ChildColumns);
newRow.Expanding += TooltipControlRowExpanding;

22
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/MetaData/MetaData.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// <file>
// <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"/>
@ -85,11 +85,9 @@ namespace Debugger @@ -85,11 +85,9 @@ namespace Debugger
return typeRefProps;
}
public IList<FieldProps> EnumFields(uint typeToken)
public IEnumerable<FieldProps> EnumFields(uint typeToken)
{
List<FieldProps> fields = new List<FieldProps>();
IntPtr enumerator = IntPtr.Zero;
while (true) {
uint fieldToken;
@ -99,10 +97,8 @@ namespace Debugger @@ -99,10 +97,8 @@ namespace Debugger
metaData.CloseEnum(enumerator);
break;
}
fields.Add(GetFieldProps(fieldToken));
yield return GetFieldProps(fieldToken);
}
return fields;
}
public FieldProps GetFieldProps(uint fieldToken)
@ -147,11 +143,9 @@ namespace Debugger @@ -147,11 +143,9 @@ namespace Debugger
return fieldProps;
}
public IList<MethodProps> EnumMethods(uint typeToken)
public IEnumerable<MethodProps> EnumMethods(uint typeToken)
{
IList<MethodProps> methods = new List<MethodProps>();
IntPtr enumerator = IntPtr.Zero;
while(true) {
uint methodToken;
@ -161,10 +155,8 @@ namespace Debugger @@ -161,10 +155,8 @@ namespace Debugger
metaData.CloseEnum(enumerator);
break;
}
methods.Add(GetMethodProps(methodToken));
yield return GetMethodProps(methodToken);
}
return methods;
}
public unsafe MethodProps GetMethodProps(uint methodToken)

12
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Exception.cs

@ -78,19 +78,13 @@ namespace Debugger @@ -78,19 +78,13 @@ namespace Debugger
type = runtimeValue.Type;
}
public override string ToString() {
return "Exception data:\n" + runtimeValue.ToString() + "\n" +
"---------------\n" +
runtimeValueException.SubVariables.ToString();
}
public string Type {
public string Type {
get {
return type;
}
}
public string Message {
get {
return message;

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

@ -416,7 +416,7 @@ namespace Debugger @@ -416,7 +416,7 @@ namespace Debugger
public IEnumerable<Variable> ContaingClassVariables {
get {
if (!IsStatic) {
foreach(Variable var in ThisValue.SubVariables) {
foreach(Variable var in ThisValue.GetSubVariables(delegate{return ThisValue;})) {
yield return var;
}
}

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

@ -88,49 +88,72 @@ namespace Debugger @@ -88,49 +88,72 @@ namespace Debugger
return this[new uint[] {index1, index2, index3}];
}
}
public unsafe Variable this[uint[] indices] {
public Variable this[uint[] indices] {
get {
if (indices.Length != rank) throw new DebuggerException("Given indicies does not match array size.");
string elementName = "[";
for (int i = 0; i < indices.Length; i++)
elementName += indices[i].ToString() + ",";
elementName = elementName.TrimEnd(new char[] {','}) + "]";
ICorDebugValue element;
fixed (void* pIndices = indices)
corArrayValue.GetElement(rank, new IntPtr(pIndices), out element);
return new Variable(debugger, element, elementName);
return GetItem(indices, delegate {return this;});
}
}
Variable GetItem(uint[] indices, ValueGetter getter)
{
if (indices.Length != rank) throw new DebuggerException("Given indicies does not match array size.");
string elementName = "[";
for (int i = 0; i < indices.Length; i++)
elementName += indices[i].ToString() + ",";
elementName = elementName.TrimEnd(new char[] {','}) + "]";
return new Variable(debugger,
elementName,
delegate {
ArrayValue updatedVal = getter() as ArrayValue;
if (this.IsEquivalentValue(updatedVal)) {
ICorDebugValue element;
unsafe {
fixed (void* pIndices = indices) {
updatedVal.corArrayValue.GetElement(rank, new IntPtr(pIndices), out element);
}
}
return Value.CreateValue(debugger, element);
} else {
return new UnavailableValue(debugger, "Value is not array");
}
});
}
public override bool MayHaveSubVariables {
get {
return true;
}
}
public override IEnumerable<Variable> SubVariables {
get {
uint[] indices = new uint[rank];
public override IEnumerable<Variable> GetSubVariables(ValueGetter getter)
{
uint[] indices = new uint[rank];
while(true) { // Go thought all combinations
for (uint i = rank - 1; i >= 1; i--)
if (indices[i] >= dimensions[i])
{
indices[i] = 0;
indices[i-1]++;
}
if (indices[0] >= dimensions[0]) break; // We are done
for(;;) // Go thought all combinations
{
for (uint i = rank - 1; i >= 1; i--)
if (indices[i] >= dimensions[i])
{
indices[i] = 0;
indices[i-1]++;
}
if (indices[0] >= dimensions[0]) break; // We are done
yield return this[indices];
indices[rank - 1]++;
}
yield return GetItem(indices, getter);
indices[rank - 1]++;
}
}
public override bool IsEquivalentValue(Value val)
{
ArrayValue arrayVal = val as ArrayValue;
return arrayVal != null &&
arrayVal.ElementsType == this.ElementsType &&
arrayVal.Lenght == this.Lenght &&
arrayVal.Rank == this.Rank;
}
}
}

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

@ -120,40 +120,39 @@ namespace Debugger @@ -120,40 +120,39 @@ namespace Debugger
}
}
public override IEnumerable<Variable> SubVariables {
get {
if (HasBaseClass) {
yield return BaseClassVariable;
}
// Current frame is necessary to resolve context specific static values (eg. ThreadStatic)
ICorDebugFrame curFrame;
if (debugger.CurrentThread == null || debugger.CurrentThread.LastFunction == null || debugger.CurrentThread.LastFunction.CorILFrame == null) {
curFrame = null;
} else {
curFrame = debugger.CurrentThread.LastFunction.CorILFrame;
}
foreach(FieldProps field in metaData.EnumFields(classProps.Token)) {
Variable var;
try {
ICorDebugValue fieldValue;
if (field.IsStatic) {
if (field.IsLiteral) continue; // Try next field
corClass.GetStaticFieldValue(field.Token, curFrame, out fieldValue);
} else {
if (corValue == null) continue; // Try next field
((ICorDebugObjectValue)corValue).GetFieldValue(corClass, field.Token, out fieldValue);
}
public override IEnumerable<Variable> GetSubVariables(ValueGetter getter)
{
if (HasBaseClass) {
yield return BaseClassVariable;
}
// Current frame is necessary to resolve context specific static values (eg. ThreadStatic)
ICorDebugFrame curFrame;
if (debugger.CurrentThread == null || debugger.CurrentThread.LastFunction == null || debugger.CurrentThread.LastFunction.CorILFrame == null) {
curFrame = null;
} else {
curFrame = debugger.CurrentThread.LastFunction.CorILFrame;
}
foreach(FieldProps field in metaData.EnumFields(classProps.Token)) {
Variable var;
try {
ICorDebugValue fieldValue;
if (field.IsStatic) {
if (field.IsLiteral) continue; // Try next field
var = new Variable(debugger, fieldValue, field.Name);
} catch {
var = new Variable(new UnavailableValue(debugger), field.Name);
corClass.GetStaticFieldValue(field.Token, curFrame, out fieldValue);
} else {
if (corValue == null) continue; // Try next field
((ICorDebugObjectValue)corValue).GetFieldValue(corClass, field.Token, out fieldValue);
}
yield return var;
var = new Variable(debugger, fieldValue, field.Name);
} catch {
var = new Variable(new UnavailableValue(debugger), field.Name);
}
yield return var;
}
}

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

@ -74,15 +74,26 @@ namespace Debugger @@ -74,15 +74,26 @@ namespace Debugger
get;
}
public virtual IEnumerable<Variable> SubVariables {
get {
yield break;
}
/// <summary>
/// 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)
{
yield break;
}
/// <summary>
/// Gets whether the given value is equivalent to this one. (ie it is may be just its other instance)
/// </summary>
public virtual bool IsEquivalentValue(Value val)
{
return val.GetType() == this.GetType();
}
public Variable this[string variableName] {
get {
foreach(Variable v in SubVariables) {
foreach(Variable v in GetSubVariables(delegate{return this;})) {
if (v.Name == variableName) return v;
}
throw new DebuggerException("Subvariable " + variableName + " does not exist");

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

@ -11,7 +11,7 @@ using Debugger.Interop.CorDebug; @@ -11,7 +11,7 @@ using Debugger.Interop.CorDebug;
namespace Debugger
{
public delegate Value ValueUpdatingEventHandler();
public delegate Value ValueGetter();
public class Variable: RemotingObjectBase
{
@ -21,7 +21,7 @@ namespace Debugger @@ -21,7 +21,7 @@ namespace Debugger
Value val;
VariableCollection subVariables;
event ValueUpdatingEventHandler updating;
event ValueGetter updating;
public event EventHandler<VariableEventArgs> ValueChanged;
public event EventHandler<VariableCollectionEventArgs> ValueRemovedFromCollection;
@ -94,11 +94,7 @@ namespace Debugger @@ -94,11 +94,7 @@ namespace Debugger
void OnSubVariablesUpdating(object sender, VariableCollectionEventArgs e)
{
VariableCollection newVariables = new VariableCollection(debugger);
foreach(Variable v in Value.SubVariables) {
newVariables.Add(v);
}
subVariables.UpdateTo(newVariables);
subVariables.UpdateTo(Value.GetSubVariables(delegate{return this.Value;}));
}
protected internal virtual void OnValueRemovedFromCollection(VariableCollectionEventArgs e) {
@ -112,7 +108,7 @@ namespace Debugger @@ -112,7 +108,7 @@ namespace Debugger
}
public Variable(NDebugger debugger, string name, ValueUpdatingEventHandler updating):this(debugger, null, name, updating)
public Variable(NDebugger debugger, string name, ValueGetter updating):this(debugger, null, name, updating)
{
}
@ -122,7 +118,7 @@ namespace Debugger @@ -122,7 +118,7 @@ namespace Debugger
}
Variable(NDebugger debugger, Value val, string name, ValueUpdatingEventHandler updating)
Variable(NDebugger debugger, Value val, string name, ValueGetter updating)
{
this.debugger = debugger;
if (val != null) {

Loading…
Cancel
Save