From 15bcad7d39c7f27a6817e73bee1e27ef3963e99b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Sat, 4 Nov 2006 20:42:49 +0000 Subject: [PATCH] Variable spit into Variable and Value; Value is taking most of the control git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2022 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/DebugeeInterpreterContext.cs | 30 +++--- .../Project/Debugger.Core.csproj | 5 + .../Project/Src/Threads/Exception.cs | 10 +- .../Project/Src/Threads/Function.cs | 63 +++++++------ .../Project/Src/Threads/Thread.cs | 18 ++-- .../Project/Src/Variables/ArrayElement.cs | 29 ++++++ .../Project/Src/Variables/ArrayValue.cs | 18 ++-- .../Src/Variables/Evals/CallFunctionEval.cs | 15 ++- .../Project/Src/Variables/Evals/Eval.cs | 69 ++++++++------ .../Src/Variables/Evals/NewObjectEval.cs | 7 +- .../Src/Variables/Evals/NewStringEval.cs | 7 +- .../Project/Src/Variables/LocalVariable.cs | 22 +++++ .../Project/Src/Variables/MethodArgument.cs | 31 +++++++ .../Project/Src/Variables/NullValue.cs | 2 +- .../Project/Src/Variables/ObjectMember.cs | 50 ++++++++++ .../Project/Src/Variables/ObjectValue.cs | 16 ++-- .../Project/Src/Variables/ObjectValueClass.cs | 64 +++++++------ .../Project/Src/Variables/PrimitiveValue.cs | 4 +- .../Project/Src/Variables/UnavailableValue.cs | 2 +- .../Project/Src/Variables/Value.cs | 20 ++-- .../Project/Src/Variables/ValueEventArgs.cs | 6 +- .../Project/Src/Variables/Variable.cs | 71 +++------------ .../Project/Src/Variables/Variable2.cs | 91 +++++++++++++++++++ .../Src/Variables/VariableEventArgs.cs | 2 +- 24 files changed, 440 insertions(+), 212 deletions(-) create mode 100644 src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayElement.cs create mode 100644 src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/LocalVariable.cs create mode 100644 src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/MethodArgument.cs create mode 100644 src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectMember.cs create mode 100644 src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable2.cs diff --git a/src/AddIns/Misc/Debugger/Debugger.BooInterpreter/Project/Src/DebugeeInterpreterContext.cs b/src/AddIns/Misc/Debugger/Debugger.BooInterpreter/Project/Src/DebugeeInterpreterContext.cs index 3dae1b7a39..398df7763b 100644 --- a/src/AddIns/Misc/Debugger/Debugger.BooInterpreter/Project/Src/DebugeeInterpreterContext.cs +++ b/src/AddIns/Misc/Debugger/Debugger.BooInterpreter/Project/Src/DebugeeInterpreterContext.cs @@ -24,8 +24,8 @@ namespace Debugger public class DebugeeInterpreterContext: InterpreterContext { Process process; - Variable interpreter; - Variable interpreter_localVariable; + Value interpreter; + Value interpreter_localVariable; public DebugeeInterpreterContext() { @@ -60,15 +60,15 @@ namespace Debugger process.LogMessage -= OnDebuggerLogMessage; process.LogMessage += OnDebuggerLogMessage; - Variable assembly; + Value assembly; // Boo.Lang.Interpreter.dll string path = Path.Combine(Path.GetDirectoryName(typeof(InterpreterContext).Assembly.Location), "Boo.Lang.Interpreter.dll"); assembly = LoadAssembly(path); // Debugger.BooInterpreter.dll assembly = LoadAssembly(typeof(DebugeeInteractiveInterpreter).Assembly.Location); - Variable interpreterType = Eval.NewString(process, typeof(DebugeeInteractiveInterpreter).FullName); - interpreter = Eval.CallFunction(process, typeof(Assembly), "CreateInstance", assembly, new Variable[] {interpreterType}); - interpreter_localVariable = interpreter.ValueProxy.SubVariables["localVariable"]; + Value interpreterType = Eval.NewString(process, typeof(DebugeeInteractiveInterpreter).FullName); + interpreter = Eval.CallFunction(process, typeof(Assembly), "CreateInstance", assembly, new Value[] {interpreterType}); + interpreter_localVariable = interpreter.ValueProxy.SubVariables["localVariable"].Value; RunCommand( "import System\n" + "import System.IO\n" + @@ -79,18 +79,18 @@ namespace Debugger return true; } - Variable LoadAssembly(string path) + Value LoadAssembly(string path) { - Variable assemblyPath = Eval.NewString(process, path); - Variable assembly = Eval.CallFunction(process, typeof(Assembly), "LoadFrom", null, new Variable[] {assemblyPath}); + Value assemblyPath = Eval.NewString(process, path); + Value assembly = Eval.CallFunction(process, typeof(Assembly), "LoadFrom", null, new Value[] {assemblyPath}); return assembly; } public override void RunCommand(string code) { if (CanLoadInterpreter) { - Variable cmd = Eval.NewString(process, code); - Eval.CallFunction(process, typeof(InteractiveInterpreter), "LoopEval", interpreter, new Variable[] {cmd}); + Value cmd = Eval.NewString(process, code); + Eval.CallFunction(process, typeof(InteractiveInterpreter), "LoopEval", interpreter, new Value[] {cmd}); } } @@ -102,8 +102,8 @@ namespace Debugger public override string[] SuggestCodeCompletion(string code) { if (CanLoadInterpreter) { - Variable cmd = Eval.NewString(process, code); - Eval.CallFunction(process, typeof(AbstractInterpreter), "SuggestCodeCompletion", interpreter, new Variable[] {cmd}); + Value cmd = Eval.NewString(process, code); + Eval.CallFunction(process, typeof(AbstractInterpreter), "SuggestCodeCompletion", interpreter, new Value[] {cmd}); return null; } else { return null; @@ -140,7 +140,7 @@ namespace Debugger Stepper stepOut = new Stepper(process.SelectedThread.LastFunction, "Boo interperter"); stepOut.StepComplete += delegate { process.Debugger.MTA2STA.AsyncCall(delegate { - if (!interpreter_localVariable.SetValue(localVar)) { + if (!interpreter_localVariable.SetValue(localVar.Value)) { PrintLine("Getting of local variable " + name + " failed"); } process.Continue(); @@ -158,7 +158,7 @@ namespace Debugger return; } PrintLine("Setting local variable " + name); - localVar.SetValue(interpreter_localVariable); + localVar.Value.SetValue(interpreter_localVariable); } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj index 87ef542566..03d7103334 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj @@ -384,6 +384,11 @@ + + + + + diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Exception.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Exception.cs index af1ba4b338..304a97bb82 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Exception.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Exception.cs @@ -37,12 +37,10 @@ namespace Debugger this.thread = thread; corValue = thread.CorThread.CurrentException; exceptionType = thread.CurrentExceptionType; - runtimeValue = new Variable(process, - "$exception", - Variable.Flags.Default, - new IExpirable[] {process.PauseSession}, - new IMutable[] {}, - delegate { return corValue; } ).ValueProxy; + runtimeValue = new Value(process, + new IExpirable[] {process.PauseSession}, + new IMutable[] {}, + delegate { return corValue; } ).ValueProxy; runtimeValueException = ((ObjectValue)runtimeValue).GetClass("System.Exception"); message = runtimeValueException.SubVariables["_message"].ValueProxy.AsString; diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs index e637848d39..e59f293838 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs @@ -362,7 +362,7 @@ namespace Debugger IEnumerable GetVariables() { if (!IsStatic) { - yield return ThisVariable; + yield return new Variable("this", ThisValue); } foreach(Variable var in ArgumentVariables) { yield return var; @@ -375,14 +375,14 @@ namespace Debugger } } - public Variable ThisVariable { + public Value ThisValue { get { - return new Variable(process, - "this", - Variable.Flags.Default, - new IExpirable[] {this}, - new IMutable[] {}, - delegate { return ThisCorValue; }); + return new Value( + process, + new IExpirable[] {this}, + new IMutable[] {}, + delegate { return ThisCorValue; } + ); } } @@ -404,7 +404,7 @@ namespace Debugger get { // TODO: Should work for static if (!IsStatic) { - foreach(Variable var in ThisVariable.ValueProxy.SubVariables) { + foreach(Variable var in ThisValue.ValueProxy.SubVariables) { yield return var; } } @@ -432,14 +432,18 @@ namespace Debugger } } - public Variable GetArgumentVariable(int index) + public MethodArgument GetArgumentVariable(int index) { - return new Variable(process, - GetParameterName(index), - Variable.Flags.Default, - new IExpirable[] {this}, - new IMutable[] {process.DebugeeState}, - delegate { return GetArgumentCorValue(index); } ); + return new MethodArgument( + GetParameterName(index), + index, + new Value( + process, + new IExpirable[] {this}, + new IMutable[] {process.DebugeeState}, + delegate { return GetArgumentCorValue(index); } + ) + ); } ICorDebugValue GetArgumentCorValue(int index) @@ -455,7 +459,7 @@ namespace Debugger } } - public IEnumerable ArgumentVariables { + public IEnumerable ArgumentVariables { get { for (int i = 0; i < ArgumentCount; i++) { yield return GetArgumentVariable(i); @@ -463,11 +467,11 @@ namespace Debugger } } - public IEnumerable LocalVariables { + public IEnumerable LocalVariables { get { if (symMethod != null) { // TODO: Is this needed? ISymUnmanagedScope symRootScope = symMethod.RootScope; - foreach(Variable var in GetLocalVariablesInScope(symRootScope)) { + foreach(LocalVariable var in GetLocalVariablesInScope(symRootScope)) { if (!var.Name.StartsWith("CS$")) { // TODO: Generalize yield return var; } @@ -476,26 +480,29 @@ namespace Debugger } } - IEnumerable GetLocalVariablesInScope(ISymUnmanagedScope symScope) + IEnumerable GetLocalVariablesInScope(ISymUnmanagedScope symScope) { foreach (ISymUnmanagedVariable symVar in symScope.Locals) { yield return GetLocalVariable(symVar); } foreach(ISymUnmanagedScope childScope in symScope.Children) { - foreach(Variable var in GetLocalVariablesInScope(childScope)) { + foreach(LocalVariable var in GetLocalVariablesInScope(childScope)) { yield return var; } } } - Variable GetLocalVariable(ISymUnmanagedVariable symVar) + LocalVariable GetLocalVariable(ISymUnmanagedVariable symVar) { - return new Variable(process, - symVar.Name, - Variable.Flags.Default, - new IExpirable[] {this}, - new IMutable[] {process.DebugeeState}, - delegate { return GetCorValueOfLocalVariable(symVar); }); + return new LocalVariable( + symVar.Name, + new Value( + process, + new IExpirable[] {this}, + new IMutable[] {process.DebugeeState}, + delegate { return GetCorValueOfLocalVariable(symVar); } + ) + ); } ICorDebugValue GetCorValueOfLocalVariable(ISymUnmanagedVariable symVar) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs index 4281118d11..f65083117c 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs @@ -149,24 +149,24 @@ namespace Debugger if (!HasBeenLoaded) return lastPriority; if (process.IsRunning) return lastPriority; - ValueProxy runTimeValue = RuntimeValue; + ValueProxy runTimeValue = RuntimeValue.ValueProxy; if (runTimeValue is NullValue) return ThreadPriority.Normal; lastPriority = (ThreadPriority)(int)(runTimeValue["m_Priority"].ValueProxy as PrimitiveValue).Primitive; return lastPriority; } } - public ValueProxy RuntimeValue { + public Value RuntimeValue { get { if (!HasBeenLoaded) throw new DebuggerException("Thread has not started jet"); process.AssertPaused(); - return new Variable(process, - "thread" + id, - Variable.Flags.Default, - new IExpirable[] {process.PauseSession}, - new IMutable[] {}, - delegate { return CorThread.Object;} ).ValueProxy; + return new Value( + process, + new IExpirable[] {process.PauseSession}, + new IMutable[] {}, + delegate { return CorThread.Object;} + ); } } @@ -174,7 +174,7 @@ namespace Debugger get { if (!HasBeenLoaded) return lastName; if (process.IsRunning) return lastName; - ValueProxy runtimeVar = RuntimeValue; + ValueProxy runtimeVar = RuntimeValue.ValueProxy; if (runtimeVar is NullValue) return lastName; ValueProxy runtimeName = runtimeVar["m_Name"].ValueProxy; if (runtimeName is NullValue) return string.Empty; diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayElement.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayElement.cs new file mode 100644 index 0000000000..59f1484e1a --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayElement.cs @@ -0,0 +1,29 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +using Debugger.Wrappers.CorDebug; + +namespace Debugger +{ + public class ArrayElement: Variable + { + uint[] indicies; + + public uint[] Indicies { + get { return indicies; } + } + + public ArrayElement(string name, uint[] indicies, Value @value) + :base (name, @value) + { + this.indicies = indicies; + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayValue.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayValue.cs index c3cfeef512..d2aeaa0120 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayValue.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayValue.cs @@ -57,7 +57,7 @@ namespace Debugger } - internal unsafe ArrayValue(Variable variable):base(variable) + internal unsafe ArrayValue(Value @value):base(@value) { corElementType = (CorElementType)CorArrayValue.ElementType; @@ -115,12 +115,16 @@ namespace Debugger elementName += indices[i].ToString() + ","; elementName = elementName.TrimEnd(new char[] {','}) + "]"; - return new Variable(Process, - elementName, - Variable.Flags.Default, - new IExpirable[] {this.Variable}, - new IMutable[] {this.Variable}, - delegate { return GetCorValueOfItem(indices); }); + return new ArrayElement( + elementName, + indices, + new Value( + Process, + new IExpirable[] {this.Value}, + new IMutable[] {this.Value}, + delegate { return GetCorValueOfItem(indices); } + ) + ); } unsafe ICorDebugValue GetCorValueOfItem(uint[] indices) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/CallFunctionEval.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/CallFunctionEval.cs index 0ce91198f9..76b7211c09 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/CallFunctionEval.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/CallFunctionEval.cs @@ -14,11 +14,16 @@ namespace Debugger class CallFunctionEval: Eval { ICorDebugFunction corFunction; - Variable thisValue; - Variable[] args; + Value thisValue; + Value[] args; - public CallFunctionEval(Process process, string name, Flags flags, IExpirable[] expireDependencies, IMutable[] mutateDependencies, ICorDebugFunction corFunction, Variable thisValue, Variable[] args) - :base(process, name, flags, expireDependencies, mutateDependencies) + public CallFunctionEval(Process process, + IExpirable[] expireDependencies, + IMutable[] mutateDependencies, + ICorDebugFunction corFunction, + Value thisValue, + Value[] args) + :base(process, expireDependencies, mutateDependencies) { this.corFunction = corFunction; this.thisValue = thisValue; @@ -39,7 +44,7 @@ namespace Debugger } corArgs.Add(thisValue.SoftReference); } - foreach(Variable arg in args) { + foreach(Value arg in args) { corArgs.Add(arg.SoftReference); } } catch (CannotGetValueException e) { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/Eval.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/Eval.cs index 0331752bc2..2dfbdcf490 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/Eval.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/Eval.cs @@ -16,7 +16,7 @@ namespace Debugger /// /// This class holds information about function evaluation. /// - public abstract partial class Eval: Variable + public abstract partial class Eval: Value { protected class EvalSetupException: System.Exception { @@ -29,6 +29,8 @@ namespace Debugger EvalState currentState = EvalState.WaitingForRequest; string currentErrorMsg; + string description = String.Empty; + public EvalState State { get { return currentState; @@ -50,8 +52,15 @@ namespace Debugger } } - protected Eval(Process process, string name, Flags flags, IExpirable[] expireDependencies, IMutable[] mutateDependencies) - :base(process, name, flags, expireDependencies, mutateDependencies, null) + public string Description { + get { return description; } + set { description = value; } + } + + protected Eval(Process process, + IExpirable[] expireDependencies, + IMutable[] mutateDependencies) + :base(process, expireDependencies, mutateDependencies, null) { } @@ -75,46 +84,52 @@ namespace Debugger /// /// Synchronously calls a function and returns its return value /// - public static Variable CallFunction(Process process, Type type, string functionName, Variable thisValue, Variable[] args) + public static Value CallFunction(Process process, Type type, string functionName, Value thisValue, Value[] args) { string moduleName = System.IO.Path.GetFileName(type.Assembly.Location); Module module = process.GetModule(moduleName); string containgType = type.FullName; ICorDebugFunction corFunction = module.GetMethod(containgType, functionName, args.Length); - return new CallFunctionEval(process, - "Function call: " + containgType + "." + functionName, - Variable.Flags.Default, - new IExpirable[] {}, - new IMutable[] {}, - corFunction, - thisValue, - args).EvaluateNow(); + Eval eval = new CallFunctionEval( + process, + new IExpirable[] {}, + new IMutable[] {}, + corFunction, + thisValue, + args + ); + eval.Description = "Function call: " + containgType + "." + functionName; + return eval.EvaluateNow(); } /// /// Synchronously creates a new string /// - public static Variable NewString(Process process, string textToCreate) + public static Value NewString(Process process, string textToCreate) { - return new NewStringEval(process, - "New string: " + textToCreate, - Variable.Flags.Default, - new IExpirable[] {}, - new IMutable[] {}, - textToCreate).EvaluateNow(); + Eval eval = new NewStringEval( + process, + new IExpirable[] {}, + new IMutable[] {}, + textToCreate + ); + eval.Description = "New string: " + textToCreate; + return eval.EvaluateNow(); } /// /// Synchronously creates a new object /// - public static Variable NewObject(Process process, ICorDebugClass classToCreate) + public static Value NewObject(Process process, ICorDebugClass classToCreate) { - return new NewObjectEval(process, - "New object: " + classToCreate.Token, - Variable.Flags.Default, - new IExpirable[] {}, - new IMutable[] {}, - classToCreate).EvaluateNow(); + Eval eval = new NewObjectEval( + process, + new IExpirable[] {}, + new IMutable[] {}, + classToCreate + ); + eval.Description = "New object: " + classToCreate.Token; + return eval.EvaluateNow(); } protected override ICorDebugValue RawCorValue { @@ -182,7 +197,7 @@ namespace Debugger protected abstract void StartEvaluation(); - public Variable EvaluateNow() + public Value EvaluateNow() { while (State == EvalState.WaitingForRequest) { ScheduleEvaluation(); diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NewObjectEval.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NewObjectEval.cs index 65b2efcfe1..0944235a1a 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NewObjectEval.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NewObjectEval.cs @@ -14,8 +14,11 @@ namespace Debugger { ICorDebugClass classToCreate; - public NewObjectEval(Process process, string name, Flags flags, IExpirable[] expireDependencies, IMutable[] mutateDependencies, ICorDebugClass classToCreate) - :base(process, name, flags, expireDependencies, mutateDependencies) + public NewObjectEval(Process process, + IExpirable[] expireDependencies, + IMutable[] mutateDependencies, + ICorDebugClass classToCreate) + :base(process, expireDependencies, mutateDependencies) { this.classToCreate = classToCreate; } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NewStringEval.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NewStringEval.cs index b2ba583f9c..02dc278198 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NewStringEval.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NewStringEval.cs @@ -13,8 +13,11 @@ namespace Debugger { string textToCreate; - public NewStringEval(Process process, string name, Flags flags, IExpirable[] expireDependencies, IMutable[] mutateDependencies, string textToCreate) - :base(process, name, flags, expireDependencies, mutateDependencies) + public NewStringEval(Process process, + IExpirable[] expireDependencies, + IMutable[] mutateDependencies, + string textToCreate) + :base(process, expireDependencies, mutateDependencies) { this.textToCreate = textToCreate; } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/LocalVariable.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/LocalVariable.cs new file mode 100644 index 0000000000..76817f62e0 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/LocalVariable.cs @@ -0,0 +1,22 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +using Debugger.Wrappers.CorDebug; + +namespace Debugger +{ + public class LocalVariable: Variable + { + public LocalVariable(string name, Value @value) + :base (name, @value) + { + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/MethodArgument.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/MethodArgument.cs new file mode 100644 index 0000000000..dc558da5cd --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/MethodArgument.cs @@ -0,0 +1,31 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +using Debugger.Wrappers.CorDebug; + +namespace Debugger +{ + public class MethodArgument: Variable + { + int index; + + public int Index { + get { + return index; + } + } + + public MethodArgument(string name, int index, Value @value) + :base (name, @value) + { + this.index = index; + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/NullValue.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/NullValue.cs index d70bfd3833..803cb3a6e8 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/NullValue.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/NullValue.cs @@ -33,7 +33,7 @@ namespace Debugger } } - internal unsafe NullValue(Variable variable):base(variable) + internal unsafe NullValue(Value @value):base(@value) { } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectMember.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectMember.cs new file mode 100644 index 0000000000..21db7cd50c --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectMember.cs @@ -0,0 +1,50 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +using Debugger.Wrappers.CorDebug; + +namespace Debugger +{ + /// + /// Provides information about a member of a given object. + /// In particular, it allows to access the value. + /// + public class ObjectMember: Variable + { + [Flags] + public enum Flags { Default = Public, None = 0, Public = 1, Static = 2, PublicStatic = Public | Static}; + + Flags memberFlags; + + public Flags MemberFlags { + get { + return memberFlags; + } + } + + public bool IsStatic { + get { + return (memberFlags & Flags.Static) != 0; + } + } + + public bool IsPublic { + get { + return (memberFlags & Flags.Public) != 0; + } + } + + public ObjectMember(string name, Flags flags, Value @value) + :base (name, @value) + { + this.memberFlags = flags; + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValue.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValue.cs index 0fbd089813..d81e27595b 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValue.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValue.cs @@ -14,7 +14,7 @@ namespace Debugger public class ObjectValue: ValueProxy { ObjectValueClass topClass; - Variable toStringText; + Value toStringText; public override string AsString { get { @@ -22,7 +22,7 @@ namespace Debugger } } - public Variable ToStringText { + public Value ToStringText { get { return toStringText; } @@ -66,19 +66,17 @@ namespace Debugger return false; } - internal ObjectValue(Variable variable):base(variable) + internal ObjectValue(Value @value):base(@value) { topClass = new ObjectValueClass(this, this.CorValue.As().Class); Module module = GetClass("System.Object").Module; ICorDebugFunction corFunction = module.GetMethod("System.Object", "ToString", 0); toStringText = new CallFunctionEval(this.Process, - "ToString()", - Variable.Flags.Default, - new IExpirable[] {this.Variable}, - new IMutable[] {this.Variable}, + new IExpirable[] {this.Value}, + new IMutable[] {this.Value}, corFunction, - this.Variable, - new Variable[] {}); + this.Value, + new Value[] {}); } internal bool IsCorValueCompatible { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValueClass.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValueClass.cs index 4369d9a566..58bf45c827 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValueClass.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValueClass.cs @@ -72,7 +72,7 @@ namespace Debugger return new VariableCollection("Base class", "{" + Type + "}", SubCollections, - GetSubVariables(Variable.Flags.Public, Variable.Flags.PublicStatic)); + GetSubVariables(ObjectMember.Flags.Public, ObjectMember.Flags.PublicStatic)); } } @@ -82,15 +82,15 @@ namespace Debugger VariableCollection privateStatic = new VariableCollection("Private static members", String.Empty, new VariableCollection[0], - GetSubVariables(Variable.Flags.Static, Variable.Flags.PublicStatic)); + GetSubVariables(ObjectMember.Flags.Static, ObjectMember.Flags.PublicStatic)); VariableCollection privateInstance = new VariableCollection("Private members", String.Empty, privateStatic.IsEmpty? new VariableCollection[0] : new VariableCollection[] {privateStatic}, - GetSubVariables(Variable.Flags.None, Variable.Flags.PublicStatic)); + GetSubVariables(ObjectMember.Flags.None, ObjectMember.Flags.PublicStatic)); VariableCollection publicStatic = new VariableCollection("Static members", String.Empty, new VariableCollection[0], - GetSubVariables(Variable.Flags.PublicStatic, Variable.Flags.PublicStatic)); + GetSubVariables(ObjectMember.Flags.PublicStatic, ObjectMember.Flags.PublicStatic)); if (baseClass != null) { yield return baseClass.SubVariables; } @@ -103,15 +103,15 @@ namespace Debugger } } - IEnumerable GetSubVariables(Variable.Flags requiredFlags, Variable.Flags mask) { - foreach(Variable var in GetFieldVariables()) { - if ((var.VariableFlags & mask) == requiredFlags) { + IEnumerable GetSubVariables(ObjectMember.Flags requiredFlags, ObjectMember.Flags mask) { + foreach(ObjectMember var in GetFieldVariables()) { + if ((var.MemberFlags & mask) == requiredFlags) { yield return var; } } - foreach(Variable var in GetPropertyVariables()) { - if ((var.VariableFlags & mask) == requiredFlags) { + foreach(ObjectMember var in GetPropertyVariables()) { + if ((var.MemberFlags & mask) == requiredFlags) { yield return var; } } @@ -128,18 +128,22 @@ namespace Debugger } } - public IEnumerable GetFieldVariables() + public IEnumerable GetFieldVariables() { foreach(FieldProps f in Module.MetaData.EnumFields(ClassToken)) { FieldProps field = f; // One per scope/delegate if (field.IsStatic && field.IsLiteral) continue; // Skip field - yield return new Variable(process, - field.Name, - (field.IsStatic ? Variable.Flags.Static : Variable.Flags.None) | - (field.IsPublic ? Variable.Flags.Public : Variable.Flags.None), - new IExpirable[] {this.objectValue.Variable}, - new IMutable[] {this.objectValue.Variable}, - delegate { return GetCorValueOfField(field); }); + yield return new ObjectMember( + field.Name, + (field.IsStatic ? ObjectMember.Flags.Static : ObjectMember.Flags.None) | + (field.IsPublic ? ObjectMember.Flags.Public : ObjectMember.Flags.None), + new Value( + process, + new IExpirable[] {this.objectValue.Value}, + new IMutable[] {this.objectValue.Value}, + delegate { return GetCorValueOfField(field); } + ) + ); } } @@ -170,21 +174,25 @@ namespace Debugger } } - public IEnumerable GetPropertyVariables() + public IEnumerable GetPropertyVariables() { foreach(MethodProps m in Methods) { MethodProps method = m; // One per scope/delegate if (method.HasSpecialName && method.Name.StartsWith("get_") && method.Name != "get_Item") { - Variable.Flags flags = (method.IsStatic ? Variable.Flags.Static : Variable.Flags.None) | - (method.IsPublic ? Variable.Flags.Public : Variable.Flags.None); - yield return new CallFunctionEval(process, - method.Name.Remove(0, 4), - flags, - new IExpirable[] {this.objectValue.Variable}, - new IMutable[] {process.DebugeeState}, - Module.CorModule.GetFunctionFromToken(method.Token), - method.IsStatic ? null : this.objectValue.Variable, // this - new Variable[] {}); // args + ObjectMember.Flags flags = (method.IsStatic ? ObjectMember.Flags.Static : ObjectMember.Flags.None) | + (method.IsPublic ? ObjectMember.Flags.Public : ObjectMember.Flags.None); + yield return new ObjectMember( + method.Name.Remove(0, 4), + flags, + new CallFunctionEval( + process, + new IExpirable[] {this.objectValue.Value}, + new IMutable[] {process.DebugeeState}, + Module.CorModule.GetFunctionFromToken(method.Token), + method.IsStatic ? null : this.objectValue.Value, // this + new Value[] {} + ) + ); // args } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PrimitiveValue.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PrimitiveValue.cs index a6f108b719..00bf90dc99 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PrimitiveValue.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PrimitiveValue.cs @@ -45,11 +45,11 @@ namespace Debugger } else { (CorValue.CastTo()).Value = newValue; } - this.Variable.NotifyChange(); + this.Value.NotifyChange(); } } - internal PrimitiveValue(Variable variable):base(variable) + internal PrimitiveValue(Value @value):base(@value) { } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/UnavailableValue.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/UnavailableValue.cs index 59f21e4737..4e84b27ab3 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/UnavailableValue.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/UnavailableValue.cs @@ -25,7 +25,7 @@ namespace Debugger } } - internal UnavailableValue(Variable variable, string message):base(variable) + internal UnavailableValue(Value @value, string message):base(@value) { this.message = message; } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Value.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Value.cs index 68495436d5..257fc9c04f 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Value.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Value.cs @@ -12,29 +12,29 @@ namespace Debugger { public abstract class ValueProxy: RemotingObjectBase { - Variable variable; + Value val; public Process Process { get { - return variable.Process; + return val.Process; } } - public Variable Variable { + public Value Value { get { - return variable; + return val; } } internal ICorDebugValue CorValue { get { - return variable.CorValue; + return val.CorValue; } } protected ValueProxy FreshValue { get { - return variable.ValueProxy; + return val.ValueProxy; } } @@ -78,7 +78,7 @@ namespace Debugger #if DEBUG return new VariableCollection(subVars.Name, subVars.Value, - Util.MergeLists(variable.GetDebugInfo(), subVars.SubCollections).ToArray(), + Util.MergeLists(val.GetDebugInfo(), subVars.SubCollections).ToArray(), subVars.Items); #else return subVars; @@ -100,10 +100,10 @@ namespace Debugger } } - protected ValueProxy(Variable variable) + protected ValueProxy(Value @value) { - if (variable == null) throw new ArgumentNullException("variable"); - this.variable = variable; + if (@value == null) throw new ArgumentNullException("value"); + this.val = @value; } public override string ToString() diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ValueEventArgs.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ValueEventArgs.cs index 5ec4075537..4095ea7c2f 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ValueEventArgs.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ValueEventArgs.cs @@ -12,15 +12,15 @@ namespace Debugger [Serializable] public class ValueEventArgs : ProcessEventArgs { - ValueProxy val; + Value val; - public ValueProxy ValueProxy { + public Value Value { get { return val; } } - public ValueEventArgs(ValueProxy val): base(val.Process) + public ValueEventArgs(Value val): base(val.Process) { this.val = val; } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs index f3b9762e3e..8f848d2fd5 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs @@ -13,7 +13,12 @@ using Debugger.Wrappers.CorDebug; namespace Debugger { /// - /// Variable is a container which holds data necessaty to obtain + /// Delegate that is used to get value. This delegate may be called at any time and should never return null. + /// + delegate ICorDebugValue CorValueGetter(); + + /// + /// Value is a container which holds data necessaty to obtain /// the value of a given object even after continue. This level of /// abstraction is necessary because the type of a value can change /// (eg for local variable of type object) @@ -30,21 +35,10 @@ namespace Debugger /// obteined value is still considered up to date. (If continue is /// called and internal value is neutred new copy will be obatined) /// - public class Variable: IExpirable, IMutable + public class Value: IExpirable, IMutable { - /// - /// Delegate that is used to get value. This delegate may be called at any time and should never return null. - /// - public delegate ICorDebugValue CorValueGetter(); - - [Flags] - public enum Flags { Default = Public, None = 0, Public = 1, Static = 2, PublicStatic = Public | Static}; - - protected Process process; - string name; - Flags flags; CorValueGetter corValueGetter; IMutable[] mutateDependencies; @@ -63,15 +57,6 @@ namespace Debugger } } - public string Name { - get { - return name; - } - set { - name = value; - } - } - public ICorDebugValue CorValue { get { return DereferenceUnbox(RawCorValue); @@ -108,27 +93,6 @@ namespace Debugger } } - public Flags VariableFlags { - get { - return flags; - } - set { - flags = value; - } - } - - public bool IsStatic { - get { - return (flags & Flags.Static) != 0; - } - } - - public bool IsPublic { - get { - return (flags & Flags.Public) != 0; - } - } - public ICorDebugValue SoftReference { get { if (this.HasExpired) throw new DebuggerException("CorValue has expired"); @@ -146,17 +110,12 @@ namespace Debugger } } - public Variable(Process process, string name, Flags flags, IExpirable[] expireDependencies, IMutable[] mutateDependencies, CorValueGetter corValueGetter) + internal Value(Process process, + IExpirable[] expireDependencies, + IMutable[] mutateDependencies, + CorValueGetter corValueGetter) { this.process = process; - this.name = name; - if (name.StartsWith("<") && name.Contains(">") && name != "") { - string middle = name.TrimStart('<').Split('>')[0]; // Get text between '<' and '>' - if (middle != "") { - this.name = middle; - } - } - this.flags = flags; foreach(IExpirable exp in expireDependencies) { AddExpireDependency(exp); @@ -191,7 +150,7 @@ namespace Debugger { if (!isExpired) { isExpired = true; - OnExpired(new VariableEventArgs(this)); + OnExpired(new ValueEventArgs(this)); foreach(IMutable mut in mutateDependencies) { mut.Changed -= DependencyChanged; } @@ -214,7 +173,7 @@ namespace Debugger { ClearCurrentValue(); if (!isExpired) { - OnChanged(new VariableEventArgs(this)); + OnChanged(new ValueEventArgs(this)); } } @@ -307,10 +266,10 @@ namespace Debugger } } - public bool SetValue(Variable newVariable) + public bool SetValue(Value newValue) { ICorDebugValue corValue = this.RawCorValue; - ICorDebugValue newCorValue = newVariable.RawCorValue; + ICorDebugValue newCorValue = newValue.RawCorValue; if (newCorValue.Type == (uint)CorElementType.BYREF) { newCorValue = newCorValue.As().Dereference(); } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable2.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable2.cs new file mode 100644 index 0000000000..0d18c1f3be --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable2.cs @@ -0,0 +1,91 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +using Debugger.Wrappers.CorDebug; + +namespace Debugger +{ + /// + /// + /// + public class Variable: IExpirable, IMutable + { + string name; + Value val; + bool hasExpired; + + public event EventHandler Expired; + public event EventHandler Changed; + + public Process Process { + get { + return val.Process; + } + } + + public string Name { + get { + return name; + } + } + + public Value Value { + get { + return val; + } + } + + public ValueProxy ValueProxy { + get { + return val.ValueProxy; + } + } + + public bool HasExpired { + get { + return hasExpired; + } + } + + internal Variable(string name, Value @value) + { + if (@value == null) throw new ArgumentNullException("value"); + + this.name = name; + this.val = @value; + this.val.Expired += delegate(object sender, EventArgs e) { OnExpired(e); }; + this.val.Changed += delegate(object sender, ProcessEventArgs e) { OnChanged(e); }; + + if (name.StartsWith("<") && name.Contains(">") && name != "") { + string middle = name.TrimStart('<').Split('>')[0]; // Get text between '<' and '>' + if (middle != "") { + this.name = middle; + } + } + } + + protected virtual void OnExpired(EventArgs e) + { + if (!hasExpired) { + hasExpired = true; + if (Expired != null) { + Expired(this, e); + } + } + } + + protected virtual void OnChanged(ProcessEventArgs e) + { + if (Changed != null) { + Changed(this, e); + } + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/VariableEventArgs.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/VariableEventArgs.cs index a3de5db0d7..3a872e70b2 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/VariableEventArgs.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/VariableEventArgs.cs @@ -19,7 +19,7 @@ namespace Debugger } } - public VariableEventArgs(Variable variable): base(variable.Process) + public VariableEventArgs(Variable variable): base(variable.Value.Process) { this.variable = variable; }