diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs index 48eee78817..f3d5e9b2a3 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs @@ -215,7 +215,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads string argValue = null; if (showArgumentNames) { try { - parameterName = frame.MethodInfo.GetParameterName(i); + parameterName = frame.MethodInfo.GetParameters()[i].Name; } catch { } if (parameterName == "") parameterName = null; } diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/StackFrameNode.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/StackFrameNode.cs index 30a1d656a7..ef9917cb14 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/StackFrameNode.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/StackFrameNode.cs @@ -4,6 +4,7 @@ // $Revision$ // +using Debugger.MetaData; using System.Collections.Generic; using ICSharpCode.NRefactory.Ast; @@ -27,8 +28,8 @@ namespace Debugger.AddIn.TreeModel IEnumerable LazyGetChildNodes() { - foreach(string arg in stackFrame.MethodInfo.ParameterNames) { - yield return new ExpressionNode(ExpressionNode.GetImageForParameter(), arg, new IdentifierExpression(arg)); + foreach(DebugParameterInfo par in stackFrame.MethodInfo.GetParameters()) { + yield return new ExpressionNode(ExpressionNode.GetImageForParameter(), par.Name, new IdentifierExpression(par.Name)); } foreach(string loc in stackFrame.MethodInfo.LocalVariableNames) { yield return new ExpressionNode(ExpressionNode.GetImageForLocalVariable(), loc, new IdentifierExpression(loc)); diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Eval.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Eval.cs index 99695becbb..a775a3e992 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Eval.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Eval.cs @@ -191,16 +191,6 @@ namespace Debugger } } - #region Convenience methods - - /// Synchronously calls a function and returns its return value - public static Value InvokeMethod(AppDomain appDomain, System.Type type, string name, Value thisValue, Value[] args) - { - return InvokeMethod(DebugMethodInfo.GetFromName(appDomain, type, name, args.Length), thisValue, args); - } - - #endregion - /// Synchronously calls a function and returns its return value public static Value InvokeMethod(DebugMethodInfo method, Value thisValue, Value[] args) { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/StackFrame.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/StackFrame.cs index b9b5e6fd1f..a5a4fd4acb 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/StackFrame.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/StackFrame.cs @@ -357,7 +357,7 @@ namespace Debugger public Value GetArgumentValue(string name) { for(int i = 0; i < this.ArgumentCount; i++) { - if (this.MethodInfo.GetParameterName(i) == name) { + if (this.MethodInfo.GetParameters()[i].Name == name) { return GetArgumentValue(i); } } @@ -382,7 +382,7 @@ namespace Debugger /// Null if not found public Value GetLocalVariableValue(string name) { - foreach(DebugLocalVariableInfo locVar in this.MethodInfo.LocalVariables) { + foreach(DebugLocalVariableInfo locVar in this.MethodInfo.GetLocalVariables()) { if (locVar.Name == name) { return locVar.GetValue(this); } @@ -394,7 +394,7 @@ namespace Debugger public List GetLocalVariableValues() { List values = new List(); - foreach(DebugLocalVariableInfo locVar in this.MethodInfo.LocalVariables) { + foreach(DebugLocalVariableInfo locVar in this.MethodInfo.GetLocalVariables()) { values.Add(locVar.GetValue(this)); } return values; diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs index 92ebd88d86..a2679ac2fb 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs @@ -407,7 +407,7 @@ namespace Debugger public override object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data) { // This is needed so that captured 'this' is supported - foreach(DebugLocalVariableInfo locVar in context.MethodInfo.LocalVariables) { + foreach(DebugLocalVariableInfo locVar in context.MethodInfo.GetLocalVariables()) { if (locVar.IsThis) return locVar.GetValue(context); } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugFieldInfo.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugFieldInfo.cs index 2b64e6a2d1..7985fec75e 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugFieldInfo.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugFieldInfo.cs @@ -28,51 +28,42 @@ namespace Debugger.MetaData } public override Type DeclaringType { - get { - return declaringType; - } + get { return declaringType; } } - /// The AppDomain in which this member is loaded + /// The AppDomain in which this member is declared + [Debugger.Tests.Ignore] public AppDomain AppDomain { - get { - return declaringType.AppDomain; - } + get { return declaringType.AppDomain; } } - /// The Process in which this member is loaded + /// The Process in which this member is declared + [Debugger.Tests.Ignore] public Process Process { - get { - return declaringType.Process; - } + get { return declaringType.Process; } } - /// The Module in which this member is loaded + /// The Module in which this member is declared + [Debugger.Tests.Ignore] public Debugger.Module DebugModule { - get { - return declaringType.DebugModule; - } + get { return declaringType.DebugModule; } } [Debugger.Tests.Ignore] public override int MetadataToken { - get { - return (int)fieldProps.Token; - } + get { return (int)fieldProps.Token; } } - // public virtual Module Module { get; } + public override System.Reflection.Module Module { + get { throw new NotSupportedException(); } + } public override string Name { - get { - return fieldProps.Name; - } + get { return fieldProps.Name; } } public override Type ReflectedType { - get { - throw new NotSupportedException(); - } + get { throw new NotSupportedException(); } } public override object[] GetCustomAttributes(bool inherit) @@ -87,19 +78,15 @@ namespace Debugger.MetaData public override bool IsDefined(Type attributeType, bool inherit) { - throw new NotSupportedException(); + return DebugType.IsDefined(this, inherit, attributeType); } public override FieldAttributes Attributes { - get { - return (FieldAttributes)fieldProps.Flags; - } + get { return (FieldAttributes)fieldProps.Flags; } } public override RuntimeFieldHandle FieldHandle { - get { - throw new NotSupportedException(); - } + get { throw new NotSupportedException(); } } public override Type FieldType { @@ -116,12 +103,17 @@ namespace Debugger.MetaData public override object GetValue(object obj) { - throw new NotSupportedException(); + return Value.GetFieldValue((Value)obj, this); } public override void SetValue(object obj, object value, System.Reflection.BindingFlags invokeAttr, Binder binder, CultureInfo culture) { - throw new NotSupportedException(); + Value.SetFieldValue((Value)obj, this, (Value)value); + } + + public override string ToString() + { + return this.FieldType + " " + this.Name; } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugLocalVariableInfo.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugLocalVariableInfo.cs index ecd313a4e4..0effbabf5b 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugLocalVariableInfo.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugLocalVariableInfo.cs @@ -19,19 +19,33 @@ using Mono.Cecil.Signatures; namespace Debugger.MetaData { - public class DebugLocalVariableInfo + public class DebugLocalVariableInfo: System.Reflection.LocalVariableInfo { ValueGetter getter; + int localIndex; + DebugType localType; + + public override int LocalIndex { + get { return localIndex; } + } + + public override Type LocalType { + get { return localType; } + } + + public override bool IsPinned { + get { throw new NotSupportedException(); } + } public string Name { get; internal set; } - public DebugType Type { get; private set; } public bool IsThis { get; internal set; } public bool IsCaptured { get; internal set; } - public DebugLocalVariableInfo(string name, DebugType type, ValueGetter getter) + public DebugLocalVariableInfo(string name, int localIndex, DebugType localType, ValueGetter getter) { this.Name = name; - this.Type = type; + this.localIndex = localIndex; + this.localType = localType; this.getter = getter; } @@ -42,7 +56,10 @@ namespace Debugger.MetaData public override string ToString() { - return this.Type.ToString() + " " + this.Name; + string msg = this.LocalType + " " + this.Name; + if (IsCaptured) + msg += " (captured)"; + return msg; } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugMethodInfo.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugMethodInfo.cs index 05932b36a3..9fc576c626 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugMethodInfo.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugMethodInfo.cs @@ -16,6 +16,7 @@ using Debugger.Wrappers.CorSym; using Debugger.Wrappers.MetaData; using ICSharpCode.NRefactory.Ast; using Mono.Cecil.Signatures; +using System.Text; namespace Debugger.MetaData { @@ -31,55 +32,64 @@ namespace Debugger.MetaData } public override Type DeclaringType { - get { - return declaringType; - } + get { return declaringType; } } - /// The AppDomain in which this member is loaded + /// The AppDomain in which this member is declared + [Debugger.Tests.Ignore] public AppDomain AppDomain { - get { - return declaringType.AppDomain; - } + get { return declaringType.AppDomain; } } - /// The Process in which this member is loaded + /// The Process in which this member is declared + [Debugger.Tests.Ignore] public Process Process { - get { - return declaringType.Process; - } + get { return declaringType.Process; } } - /// The Module in which this member is loaded + /// The Module in which this member is declared + [Debugger.Tests.Ignore] public Debugger.Module DebugModule { - get { - return declaringType.DebugModule; - } + get { return declaringType.DebugModule; } } + [Debugger.Tests.Ignore] public override int MetadataToken { - get { - return (int)methodProps.Token; - } + get { return (int)methodProps.Token; } + } + + public override System.Reflection.Module Module { + get { throw new NotSupportedException(); } } - // public virtual Module Module { get; } + /// Name including the declaring type and parameters public string FullName { get { - return this.DeclaringType.FullName + "." + this.Name; + StringBuilder sb = new StringBuilder(); + sb.Append(this.DeclaringType.FullName); + sb.Append("."); + sb.Append(this.Name); + sb.Append("("); + bool first = true; + foreach(DebugParameterInfo p in GetParameters()) { + if (!first) + sb.Append(", "); + first = false; + sb.Append(p.ParameterType.Name); + sb.Append(" "); + sb.Append(p.Name); + } + sb.Append(")"); + return sb.ToString(); } } public override string Name { - get { - return methodProps.Name; - } + get { return methodProps.Name; } } public override Type ReflectedType { - get { - throw new NotSupportedException(); - } + get { throw new NotSupportedException(); } } public override object[] GetCustomAttributes(bool inherit) @@ -94,42 +104,46 @@ namespace Debugger.MetaData public override bool IsDefined(Type attributeType, bool inherit) { - throw new NotSupportedException(); + return DebugType.IsDefined(this, inherit, attributeType); } // public virtual Type[] GetGenericArguments(); // public virtual MethodBody GetMethodBody(); - // internal virtual RuntimeMethodHandle GetMethodHandle(); public override MethodImplAttributes GetMethodImplementationFlags() { return (MethodImplAttributes)methodProps.ImplFlags; } - // internal virtual uint GetOneTimeFlags(); - // internal virtual uint GetOneTimeSpecificFlags(); - public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) { - throw new NotSupportedException(); + List args = new List(); + foreach(object arg in parameters) { + args.Add((Value)arg); + } + return Eval.InvokeMethod(this, (Value)obj, args.ToArray()); } public override MethodAttributes Attributes { - get { - return (MethodAttributes)methodProps.Flags; - } + get { return (MethodAttributes)methodProps.Flags; } } // public virtual CallingConventions CallingConvention { get; } - // public virtual bool ContainsGenericParameters { get; } - // public virtual bool IsGenericMethod { get; } - // public virtual bool IsGenericMethodDefinition { get; } - // internal virtual bool IsOverloaded { get; } + + public override bool ContainsGenericParameters { + get { throw new NotSupportedException(); } + } + + public override bool IsGenericMethod { + get { throw new NotSupportedException(); } + } + + public override bool IsGenericMethodDefinition { + get { throw new NotSupportedException(); } + } public override RuntimeMethodHandle MethodHandle { - get { - throw new NotSupportedException(); - } + get { throw new NotSupportedException(); } } public override MethodInfo GetBaseDefinition() @@ -139,27 +153,24 @@ namespace Debugger.MetaData // public override Type[] GetGenericArguments(); // public virtual MethodInfo GetGenericMethodDefinition(); - // internal virtual MethodInfo GetParentDefinition(); - // internal override Type GetReturnType(); // public virtual MethodInfo MakeGenericMethod(params Type[] typeArguments); // public override bool ContainsGenericParameters { get; } - // public override bool IsGenericMethod { get; } - // public override bool IsGenericMethodDefinition { get; } - // public virtual ParameterInfo ReturnParameter { get; } - public Type GetReturnType() - { - if (this.MethodDefSig.RetType.Void) return null; - if (returnType == null) { - returnType = DebugType.CreateFromSignature(this.DebugModule, this.MethodDefSig.RetType.Type, declaringType); + public override ParameterInfo ReturnParameter { + get { + return new DebugParameterInfo( + this, + string.Empty, + this.MethodDefSig.RetType.Void ? + null : + DebugType.CreateFromSignature(this.DebugModule, this.MethodDefSig.RetType.Type, declaringType), + -1 + ); } - return returnType; } public override ICustomAttributeProvider ReturnTypeCustomAttributes { - get { - throw new NotSupportedException(); - } + get { throw new NotSupportedException(); } } MethodDefSig methodDefSig; @@ -174,7 +185,10 @@ namespace Debugger.MetaData } } - DebugType returnType; + /// Gets the number of paramters of this method + public int ParameterCount { + get { return this.MethodDefSig.ParamCount; } + } ParameterInfo[] parameters; @@ -183,10 +197,17 @@ namespace Debugger.MetaData if (parameters == null) { parameters = new ParameterInfo[this.MethodDefSig.ParamCount]; for(int i = 0; i < parameters.Length; i++) { + string name; + try { + // index = 0 is return parameter + name = this.DebugModule.MetaData.GetParamPropsForMethodIndex((uint)this.MetadataToken, (uint)i + 1).Name; + } catch { + name = String.Empty; + } parameters[i] = new DebugParameterInfo( this, - this.GetParameterName(i), + name, DebugType.CreateFromSignature(this.DebugModule, this.MethodDefSig.Parameters[i].Type, declaringType), i ); @@ -195,9 +216,6 @@ namespace Debugger.MetaData return parameters; } - // internal virtual Type[] GetParameterTypes(); - // internal virtual ParameterInfo[] GetParametersNoCopy(); - internal ICorDebugFunction CorFunction { get { return this.DebugModule.CorModule.GetFunctionFromToken((uint)this.MetadataToken); @@ -241,7 +259,7 @@ namespace Debugger.MetaData /// /// Backing field that can be used to obtain the same value as by calling this method. /// - internal DebugFieldInfo BackingField { + public DebugFieldInfo BackingField { get { if (!getBackingFieldCalled) { backingFieldCache = GetBackingField(); @@ -294,7 +312,7 @@ namespace Debugger.MetaData code[10] == 0x06 && // ldloc.0 code[11] == 0x2A) // ret { - token = getTokenFromIL(code, 06); + token = GetTokenFromIL(code, 06); } // code generated for getter 'public int Prop { get; [set;] }' @@ -309,7 +327,7 @@ namespace Debugger.MetaData code[09] == 0x06 && // ldloc.0 code[10] == 0x2A) // ret { - token = getTokenFromIL(code, 05); + token = GetTokenFromIL(code, 05); } if (code.Length == 7 && @@ -318,7 +336,7 @@ namespace Debugger.MetaData code[05] == 0x04 && // code[06] == 0x2A) // ret { - token = getTokenFromIL(code, 05); + token = GetTokenFromIL(code, 05); } if (token != 0) { @@ -344,7 +362,7 @@ namespace Debugger.MetaData /// Bytes representing the code. /// Index of last byte of the token. /// IL token. - uint getTokenFromIL(byte[] ilCode, uint tokenEndIndex) + uint GetTokenFromIL(byte[] ilCode, uint tokenEndIndex) { return ((uint)ilCode[tokenEndIndex] << 24) + ((uint)ilCode[tokenEndIndex - 1] << 16) + @@ -352,7 +370,7 @@ namespace Debugger.MetaData ((uint)ilCode[tokenEndIndex - 3]); } - bool? isSingleLineCache; + bool? isSingleLine; bool IsSingleLine { get { @@ -360,7 +378,7 @@ namespace Debugger.MetaData ISymUnmanagedMethod symMethod = this.SymMethod; if (symMethod == null) return false; // No symbols - can not determine - if (isSingleLineCache.HasValue) return isSingleLineCache.Value; + if (isSingleLine.HasValue) return isSingleLine.Value; List seqPoints = new List(symMethod.SequencePoints); seqPoints.Sort(); @@ -381,53 +399,36 @@ namespace Debugger.MetaData } // Is single line - isSingleLineCache = seqPoints.Count == 0 || seqPoints[0].Line == seqPoints[seqPoints.Count - 1].EndLine; - return isSingleLineCache.Value; + isSingleLine = seqPoints.Count == 0 || seqPoints[0].Line == seqPoints[seqPoints.Count - 1].EndLine; + return isSingleLine.Value; } } - bool? hasDebuggerAttributeCache; + bool? hasDebuggerAttribute; bool HasDebuggerAttribute { get { - if (hasDebuggerAttributeCache.HasValue) return hasDebuggerAttributeCache.Value; + if (hasDebuggerAttribute.HasValue) return hasDebuggerAttribute.Value; - hasDebuggerAttributeCache = + hasDebuggerAttribute = // Look on the method - HasAnyAttribute(this.DebugModule.MetaData, methodProps.Token, - typeof(System.Diagnostics.DebuggerStepThroughAttribute), - typeof(System.Diagnostics.DebuggerNonUserCodeAttribute), - typeof(System.Diagnostics.DebuggerHiddenAttribute)) + DebugType.IsDefined( + this, + false, + typeof(System.Diagnostics.DebuggerStepThroughAttribute), + typeof(System.Diagnostics.DebuggerNonUserCodeAttribute), + typeof(System.Diagnostics.DebuggerHiddenAttribute)) || // Look on the type - HasAnyAttribute(this.DebugModule.MetaData, (uint)this.DeclaringType.MetadataToken, - typeof(System.Diagnostics.DebuggerStepThroughAttribute), - typeof(System.Diagnostics.DebuggerNonUserCodeAttribute), - typeof(System.Diagnostics.DebuggerHiddenAttribute)); - return hasDebuggerAttributeCache.Value; - } - } - - internal static bool HasAnyAttribute(MetaDataImport metaData, uint token, params Type[] wantedAttrTypes) - { - foreach(CustomAttributeProps ca in metaData.EnumCustomAttributeProps(token, 0)) { - CorTokenType tkType = (CorTokenType)(ca.Type & 0xFF000000); - string attributeName; - if (tkType == CorTokenType.MemberRef) { - MemberRefProps constructorMethod = metaData.GetMemberRefProps(ca.Type); - attributeName = metaData.GetTypeRefProps(constructorMethod.DeclaringType).Name; - } else if (tkType == CorTokenType.MethodDef) { - MethodProps constructorMethod = metaData.GetMethodProps(ca.Type); - attributeName = metaData.GetTypeDefProps(constructorMethod.ClassToken).Name; - } else { - throw new DebuggerException("Not expected: " + tkType); - } - foreach(Type wantedAttrType in wantedAttrTypes) { - if (attributeName == wantedAttrType.FullName) - return true; - } + DebugType.IsDefined( + declaringType, + false, + typeof(System.Diagnostics.DebuggerStepThroughAttribute), + typeof(System.Diagnostics.DebuggerNonUserCodeAttribute), + typeof(System.Diagnostics.DebuggerHiddenAttribute)); + + return hasDebuggerAttribute.Value; } - return false; } internal void MarkAsNonUserCode() @@ -439,28 +440,6 @@ namespace Debugger.MetaData } } - /// - /// Get a method from a managed type, method name and argument count - /// - public static DebugMethodInfo GetFromName(AppDomain appDomain, System.Type type, string methodName, int paramCount) - { - if (type.IsNested) throw new DebuggerException("Not implemented for nested types"); - if (type.IsGenericType) throw new DebuggerException("Not implemented for generic types"); - if (type.IsGenericParameter) throw new DebuggerException("Type can not be generic parameter"); - - DebugType debugType = DebugType.CreateFromType(appDomain, type); - if (debugType == null) { - throw new DebuggerException("Type " + type.FullName + " not found"); - } - - foreach(DebugMethodInfo methodInfo in debugType.GetMethods(methodName, DebugType.BindingFlagsAll)) { - if (methodInfo.ParameterCount == paramCount) { - return methodInfo; - } - } - throw new DebuggerException("Method " + methodName + " not found"); - } - internal ISymUnmanagedMethod SymMethod { get { if (this.DebugModule.SymReader == null) return null; @@ -472,62 +451,14 @@ namespace Debugger.MetaData } } - /// Gets the number of paramters of this method - public int ParameterCount { - get { - return this.MethodDefSig.ParamCount; - } - } + List localVariables; - /// Gets the name of given parameter - /// Zero-based index - public string GetParameterName(int index) - { - // index = 0 is return parameter - try { - return this.DebugModule.MetaData.GetParamPropsForMethodIndex((uint)this.MetadataToken, (uint)index + 1).Name; - } catch { - return String.Empty; - } - } - - /// Get names of all parameters in order - public string[] ParameterNames { - get { - List names = new List(); - for(int i = 0; i < ParameterCount; i++) { - names.Add(GetParameterName(i)); - } - return names.ToArray(); - } - } - - public List LocalVariables { - get { - if (this.SymMethod != null) { // TODO: Is this needed? - return GetLocalVariables(); - } else { - return new List(); - } - } - } - - public string[] LocalVariableNames { - get { - List vars = this.LocalVariables; - List names = new List(); - for(int i = 0; i < vars.Count; i++) { - names.Add(vars[i].Name); - } - names.Sort(); - return names.ToArray(); - } - } - - List localVariables; // Cache - - List GetLocalVariables() + public List GetLocalVariables() { + // TODO: Is this needed? + if (this.SymMethod == null) + return new List(); + if (localVariables != null) return localVariables; localVariables = GetLocalVariablesInScope(this.SymMethod.RootScope); @@ -558,6 +489,7 @@ namespace Debugger.MetaData if (!this.IsStatic) { DebugLocalVariableInfo thisVar = new DebugLocalVariableInfo( "this", + -1, declaringType, delegate(StackFrame context) { return context.GetThisValue(); @@ -578,6 +510,7 @@ namespace Debugger.MetaData if (fieldInfo.Name.StartsWith("CS$")) continue; // Ignore DebugLocalVariableInfo locVar = new DebugLocalVariableInfo( fieldInfo.Name, + -1, (DebugType)fieldInfo.FieldType, delegate(StackFrame context) { return getCaptureClass(context).GetFieldValue(fieldInfoCopy); @@ -634,6 +567,7 @@ namespace Debugger.MetaData } else { DebugLocalVariableInfo locVar = new DebugLocalVariableInfo( symVar.Name, + (int)symVar.AddressField1, locVarType, delegate(StackFrame context) { return GetLocalVariableValue(context, symVarCopy); @@ -659,5 +593,10 @@ namespace Debugger.MetaData } return new Value(context.AppDomain, corVal); } + + public override string ToString() + { + return this.FullName; + } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugParameterInfo.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugParameterInfo.cs index 38ec5b839a..1f392a5414 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugParameterInfo.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugParameterInfo.cs @@ -18,10 +18,10 @@ namespace Debugger.MetaData { public class DebugParameterInfo : System.Reflection.ParameterInfo { - public MemberInfo member; - public string name; - public Type parameterType; - public int position; + MemberInfo member; + string name; + Type parameterType; + int position; public override MemberInfo Member { get { return member; } @@ -56,5 +56,10 @@ namespace Debugger.MetaData // public virtual Type[] GetOptionalCustomModifiers(); // public virtual Type[] GetRequiredCustomModifiers(); // public virtual bool IsDefined(Type attributeType, bool inherit); + + public override string ToString() + { + return this.ParameterType + " " + this.Name; + } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugPropertyInfo.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugPropertyInfo.cs index 55d59287c9..fc8cf2336f 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugPropertyInfo.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugPropertyInfo.cs @@ -31,39 +31,35 @@ namespace Debugger.MetaData } public override Type DeclaringType { - get { - return declaringType; - } + get { return declaringType; } } - /// The AppDomain in which this member is loaded + /// The AppDomain in which this member is declared + [Debugger.Tests.Ignore] public AppDomain AppDomain { - get { - return declaringType.AppDomain; - } + get { return declaringType.AppDomain; } } - /// The Process in which this member is loaded + /// The Process in which this member is declared + [Debugger.Tests.Ignore] public Process Process { - get { - return declaringType.Process; - } + get { return declaringType.Process; } } - /// The Module in which this member is loaded + /// The Module in which this member is declared + [Debugger.Tests.Ignore] public Debugger.Module DebugModule { - get { - return declaringType.DebugModule; - } + get { return declaringType.DebugModule; } } + [Debugger.Tests.Ignore] public override int MetadataToken { - get { - return (getMethod ?? setMethod).MetadataToken; - } + get { return (getMethod ?? setMethod).MetadataToken; } } - // public virtual Module Module { get; } + public override System.Reflection.Module Module { + get { throw new NotSupportedException(); } + } public override string Name { get { @@ -72,9 +68,7 @@ namespace Debugger.MetaData } public override Type ReflectedType { - get { - throw new NotSupportedException(); - } + get { throw new NotSupportedException(); } } public override object[] GetCustomAttributes(bool inherit) @@ -89,31 +83,23 @@ namespace Debugger.MetaData public override bool IsDefined(Type attributeType, bool inherit) { - throw new NotSupportedException(); + return DebugType.IsDefined(this, inherit, attributeType); } public override PropertyAttributes Attributes { - get { - throw new NotSupportedException(); - } + get { throw new NotSupportedException(); } } public override bool CanRead { - get { - return getMethod != null; - } + get { return getMethod != null; } } public override bool CanWrite { - get { - return setMethod != null; - } + get { return setMethod != null; } } public override Type PropertyType { - get { - return getMethod.ReturnType; - } + get { return getMethod.ReturnType; } } public override MethodInfo[] GetAccessors(bool nonPublic) @@ -130,7 +116,11 @@ namespace Debugger.MetaData public override ParameterInfo[] GetIndexParameters() { - throw new NotSupportedException(); + if (GetGetMethod() != null) { + return GetGetMethod().GetParameters(); + } else { + return null; + } } // public virtual Type[] GetOptionalCustomModifiers(); @@ -142,18 +132,22 @@ namespace Debugger.MetaData return setMethod; } - // public virtual object GetValue(object obj, object[] index); - public override object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture) { - throw new NotSupportedException(); + List args = new List(); + foreach(object arg in index) { + args.Add((Value)arg); + } + return Value.GetPropertyValue((Value)obj, this, args.ToArray()); } - // public virtual void SetValue(object obj, object value, object[] index); - public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture) { - throw new NotSupportedException(); + List args = new List(); + foreach(object arg in index) { + args.Add((Value)arg); + } + Value.SetPropertyValue((Value)obj, this, args.ToArray(), (Value)value); } public bool IsPublic { @@ -169,5 +163,10 @@ namespace Debugger.MetaData return (getMethod ?? setMethod).IsStatic; } } + + public override string ToString() + { + return this.PropertyType + " " + this.Name; + } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugType.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugType.cs index ef874488fc..2fe97a3afb 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugType.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugType.cs @@ -27,7 +27,7 @@ namespace Debugger.MetaData /// If two types are identical, the references to DebugType will also be identical /// Type will be loaded once per each appdomain. /// - public class DebugType: System.Type + public class DebugType: System.Type, IDebugMemberInfo { public const BindingFlags BindingFlagsAll = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance; public const BindingFlags BindingFlagsAllDeclared = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance; @@ -55,34 +55,28 @@ namespace Debugger.MetaData static Dictionary loadedTypes = new Dictionary(); public override Type DeclaringType { - get { - throw new NotSupportedException(); - } + get { throw new NotSupportedException(); } } /// The AppDomain in which this type is loaded [Debugger.Tests.Ignore] public AppDomain AppDomain { - get { - return appDomain; - } + get { return appDomain; } } - /// The Process in which this member is loaded + /// The Process in which this type is loaded [Debugger.Tests.Ignore] public Process Process { - get { - return process; - } + get { return process; } } - /// The Module in which this member is loaded + /// The Module in which this type is loaded + [Debugger.Tests.Ignore] public Debugger.Module DebugModule { - get { - return module; - } + get { return module; } } + [Debugger.Tests.Ignore] public override int MetadataToken { get { AssertClassOrValueType(); @@ -90,18 +84,16 @@ namespace Debugger.MetaData } } - // public virtual Module Module { get; } + public override System.Reflection.Module Module { + get { throw new NotSupportedException(); } + } public override string Name { - get { - return name; - } + get { return name; } } public override Type ReflectedType { - get { - throw new NotSupportedException(); - } + get { throw new NotSupportedException(); } } public override object[] GetCustomAttributes(bool inherit) @@ -116,20 +108,40 @@ namespace Debugger.MetaData public override bool IsDefined(Type attributeType, bool inherit) { - throw new NotSupportedException(); + return IsDefined(this, inherit, attributeType); } + public static bool IsDefined(IDebugMemberInfo member, bool inherit, params Type[] attributeTypes) + { + // TODO: Support inherit + MetaDataImport metaData = member.DebugModule.MetaData; + uint token = (uint)member.MetadataToken; + foreach(CustomAttributeProps ca in metaData.EnumCustomAttributeProps(token, 0)) { + CorTokenType tkType = (CorTokenType)(ca.Type & 0xFF000000); + string attributeName; + if (tkType == CorTokenType.MemberRef) { + MemberRefProps constructorMethod = metaData.GetMemberRefProps(ca.Type); + attributeName = metaData.GetTypeRefProps(constructorMethod.DeclaringType).Name; + } else if (tkType == CorTokenType.MethodDef) { + MethodProps constructorMethod = metaData.GetMethodProps(ca.Type); + attributeName = metaData.GetTypeDefProps(constructorMethod.ClassToken).Name; + } else { + throw new DebuggerException("Not expected: " + tkType); + } + foreach(Type attributeType in attributeTypes) { + if (attributeName == attributeType.FullName) + return true; + } + } + return false; + } public override Assembly Assembly { - get { - throw new NotSupportedException(); - } + get { throw new NotSupportedException(); } } public override string AssemblyQualifiedName { - get { - throw new NotSupportedException(); - } + get { throw new NotSupportedException(); } } public override Type BaseType { @@ -162,50 +174,38 @@ namespace Debugger.MetaData // public virtual MethodBase DeclaringMethod { get; } public override string FullName { - get { - return fullName; - } + get { return fullName; } } - // public virtual GenericParameterAttributes GenericParameterAttributes { get; } - // public virtual int GenericParameterPosition { get; } - public override Guid GUID { - get { - throw new NotSupportedException(); - } + get { throw new NotSupportedException(); } } + // public virtual GenericParameterAttributes GenericParameterAttributes { get; } + // public virtual int GenericParameterPosition { get; } // public virtual bool IsGenericParameter { get; } - // public virtual bool IsGenericType { get; } // public virtual bool IsGenericTypeDefinition { get; } - // internal virtual bool IsSzArray { get; } - // public override MemberTypes MemberType { get; } - public override System.Reflection.Module Module { + public override bool IsGenericType { get { - throw new NotSupportedException(); + return this.GetGenericArguments().Length > 0; } } + // TODO public override string Namespace { - get { - throw new NotSupportedException(); - } + get { throw new NotSupportedException(); } } - // public override Type ReflectedType { get; } // public virtual StructLayoutAttribute StructLayoutAttribute { get; } - // public virtual RuntimeTypeHandle TypeHandle { get; } - public override Type UnderlyingSystemType { - get { - throw new NotSupportedException(); - } + public override RuntimeTypeHandle TypeHandle { + get { throw new NotSupportedException(); } } - // public virtual Type[] FindInterfaces(TypeFilter filter, object filterCriteria); - // public virtual MemberInfo[] FindMembers(MemberTypes memberType, BindingFlags bindingAttr, MemberFilter filter, object filterCriteria); + public override Type UnderlyingSystemType { + get { throw new NotSupportedException(); } + } public override int GetArrayRank() { @@ -221,6 +221,7 @@ namespace Debugger.MetaData protected override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) { + // TODO throw new NotSupportedException(); } @@ -229,7 +230,6 @@ namespace Debugger.MetaData throw new NotSupportedException(); } - // internal virtual string GetDefaultMemberName(); // public virtual MemberInfo[] GetDefaultMembers(); public override Type GetElementType() @@ -362,7 +362,7 @@ namespace Debugger.MetaData public override Type GetInterface(string name, bool ignoreCase) { - foreach(DebugType inter in this.Interfaces) { + foreach(DebugType inter in this.GetInterfaces()) { if (string.Equals(inter.FullName, fullName, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal)) { return inter; } @@ -399,7 +399,7 @@ namespace Debugger.MetaData if (candidate.ParameterCount == paramNames.Length) { bool match = true; for(int i = 0; i < paramNames.Length; i++) { - if (paramNames[i] != candidate.ParameterNames[i]) + if (paramNames[i] != candidate.GetParameters()[i].Name) match = false; } if (match) @@ -472,13 +472,9 @@ namespace Debugger.MetaData return GetMember(name, bindingAttr, null); } - // internal virtual Type GetRootElementType(); - // internal virtual TypeCode GetTypeCodeInternal(); - // internal virtual RuntimeTypeHandle GetTypeHandleInternal(); - protected override bool HasElementTypeImpl() { - throw new NotSupportedException(); + return this.IsArray || this.IsPointer; } // internal virtual bool HasProxyAttributeImpl(); @@ -540,11 +536,6 @@ namespace Debugger.MetaData get { return corType; } } - /// Gets a list of all interfaces that this type implements - public List Interfaces { - get { return interfaces; } - } - /// Returns what kind of type this is. (eg. value type) public DebugTypeKind Kind { get { @@ -964,7 +955,7 @@ namespace Debugger.MetaData if (appDomain.Process.Options.Verbose) { string prefix = this.IsInterface ? "interface" : "type"; appDomain.Process.TraceMessage("Loaded {0} {1} ({2} ms)", prefix, this.FullName, totalTime2.TotalMilliseconds); - foreach(DebugType inter in this.Interfaces) { + foreach(DebugType inter in GetInterfaces()) { appDomain.Process.TraceMessage(" - Implements {0}", inter.FullName); } } @@ -1081,7 +1072,7 @@ namespace Debugger.MetaData public bool IsCompilerGenerated { get { if (this.IsClass || this.IsValueType) { - return DebugMethodInfo.HasAnyAttribute(this.DebugModule.MetaData, (uint)this.MetadataToken, typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)); + return IsDefined(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), false); } else { return false; } @@ -1097,18 +1088,19 @@ namespace Debugger.MetaData public bool IsYieldEnumerator { get { if (this.IsCompilerGenerated) { - foreach(DebugType intf in this.Interfaces) { - if (intf.FullName == typeof(System.Collections.IEnumerator).FullName) - return true; - } + return GetInterface(typeof(System.Collections.IEnumerator).FullName) != null; } return false; } } + bool IDebugMemberInfo.IsStatic { + get { return false; } + } + public override string ToString() { - return string.Format("{0}", this.FullName); + return this.FullName; } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/IDebugMemberInfo.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/IDebugMemberInfo.cs index 01f4f6d592..763b23f20d 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/IDebugMemberInfo.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/IDebugMemberInfo.cs @@ -11,7 +11,9 @@ namespace Debugger.MetaData public interface IDebugMemberInfo { Type DeclaringType { get; } + Module DebugModule { get; } string Name { get; } + int MetadataToken { get; } bool IsStatic { get; } bool IsPublic { get; } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Values/Value.Object.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Values/Value.Object.cs index 3f3c71bf09..6dc5b07b78 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Values/Value.Object.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Values/Value.Object.cs @@ -98,6 +98,12 @@ namespace Debugger ); } + public static Value SetFieldValue(Value objectInstance, DebugFieldInfo fieldInfo, Value newValue) + { + // TODO + throw new NotImplementedException(); + } + static ICorDebugValue GetFieldCorValue(Value objectInstance, DebugFieldInfo fieldInfo) { CheckObject(objectInstance, fieldInfo); @@ -211,7 +217,8 @@ namespace Debugger if (this.Type.IsPrimitive) return AsString; if (this.Type.IsPointer) return "0x" + this.PointerAddress.ToString("X"); // if (!IsObject) // Can invoke on primitives - return Eval.InvokeMethod(this.AppDomain, typeof(object), "ToString", this, new Value[] {}).AsString; + DebugMethodInfo methodInfo = (DebugMethodInfo)DebugType.CreateFromType(this.AppDomain, typeof(object)).GetMethod("ToString", new DebugType[] {}); + return Eval.InvokeMethod(methodInfo, this, new Value[] {}).AsString; } #region Convenience overload methods