Browse Source

Polishing API and implemented more reflection methods

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5106 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 16 years ago
parent
commit
345570538f
  1. 2
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs
  2. 5
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/StackFrameNode.cs
  3. 10
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Eval.cs
  4. 6
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/StackFrame.cs
  5. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs
  6. 60
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugFieldInfo.cs
  7. 27
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugLocalVariableInfo.cs
  8. 299
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugMethodInfo.cs
  9. 13
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugParameterInfo.cs
  10. 83
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugPropertyInfo.cs
  11. 140
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugType.cs
  12. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/IDebugMemberInfo.cs
  13. 9
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Values/Value.Object.cs

2
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs

@ -215,7 +215,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -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;
}

5
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/StackFrameNode.cs

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
// <version>$Revision$</version>
// </file>
using Debugger.MetaData;
using System.Collections.Generic;
using ICSharpCode.NRefactory.Ast;
@ -27,8 +28,8 @@ namespace Debugger.AddIn.TreeModel @@ -27,8 +28,8 @@ namespace Debugger.AddIn.TreeModel
IEnumerable<TreeNode> 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));

10
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Eval.cs

@ -191,16 +191,6 @@ namespace Debugger @@ -191,16 +191,6 @@ namespace Debugger
}
}
#region Convenience methods
/// <summary> Synchronously calls a function and returns its return value </summary>
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
/// <summary> Synchronously calls a function and returns its return value </summary>
public static Value InvokeMethod(DebugMethodInfo method, Value thisValue, Value[] args)
{

6
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/StackFrame.cs

@ -357,7 +357,7 @@ namespace Debugger @@ -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 @@ -382,7 +382,7 @@ namespace Debugger
/// <returns> Null if not found </returns>
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 @@ -394,7 +394,7 @@ namespace Debugger
public List<Value> GetLocalVariableValues()
{
List<Value> values = new List<Value>();
foreach(DebugLocalVariableInfo locVar in this.MethodInfo.LocalVariables) {
foreach(DebugLocalVariableInfo locVar in this.MethodInfo.GetLocalVariables()) {
values.Add(locVar.GetValue(this));
}
return values;

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs

@ -407,7 +407,7 @@ namespace Debugger @@ -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);
}

60
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugFieldInfo.cs

@ -28,51 +28,42 @@ namespace Debugger.MetaData @@ -28,51 +28,42 @@ namespace Debugger.MetaData
}
public override Type DeclaringType {
get {
return declaringType;
}
get { return declaringType; }
}
/// <summary> The AppDomain in which this member is loaded </summary>
/// <summary> The AppDomain in which this member is declared </summary>
[Debugger.Tests.Ignore]
public AppDomain AppDomain {
get {
return declaringType.AppDomain;
}
get { return declaringType.AppDomain; }
}
/// <summary> The Process in which this member is loaded </summary>
/// <summary> The Process in which this member is declared </summary>
[Debugger.Tests.Ignore]
public Process Process {
get {
return declaringType.Process;
}
get { return declaringType.Process; }
}
/// <summary> The Module in which this member is loaded </summary>
/// <summary> The Module in which this member is declared </summary>
[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 @@ -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 @@ -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;
}
}
}

27
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugLocalVariableInfo.cs

@ -19,19 +19,33 @@ using Mono.Cecil.Signatures; @@ -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 @@ -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;
}
}
}

299
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugMethodInfo.cs

@ -16,6 +16,7 @@ using Debugger.Wrappers.CorSym; @@ -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 @@ -31,55 +32,64 @@ namespace Debugger.MetaData
}
public override Type DeclaringType {
get {
return declaringType;
}
get { return declaringType; }
}
/// <summary> The AppDomain in which this member is loaded </summary>
/// <summary> The AppDomain in which this member is declared </summary>
[Debugger.Tests.Ignore]
public AppDomain AppDomain {
get {
return declaringType.AppDomain;
}
get { return declaringType.AppDomain; }
}
/// <summary> The Process in which this member is loaded </summary>
/// <summary> The Process in which this member is declared </summary>
[Debugger.Tests.Ignore]
public Process Process {
get {
return declaringType.Process;
}
get { return declaringType.Process; }
}
/// <summary> The Module in which this member is loaded </summary>
/// <summary> The Module in which this member is declared </summary>
[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; }
/// <summary> Name including the declaring type and parameters </summary>
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 @@ -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<Value> args = new List<Value>();
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 @@ -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 @@ -174,7 +185,10 @@ namespace Debugger.MetaData
}
}
DebugType returnType;
/// <summary> Gets the number of paramters of this method </summary>
public int ParameterCount {
get { return this.MethodDefSig.ParamCount; }
}
ParameterInfo[] parameters;
@ -183,10 +197,17 @@ namespace Debugger.MetaData @@ -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 @@ -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 @@ -241,7 +259,7 @@ namespace Debugger.MetaData
/// <summary>
/// Backing field that can be used to obtain the same value as by calling this method.
/// </summary>
internal DebugFieldInfo BackingField {
public DebugFieldInfo BackingField {
get {
if (!getBackingFieldCalled) {
backingFieldCache = GetBackingField();
@ -294,7 +312,7 @@ namespace Debugger.MetaData @@ -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 @@ -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 @@ -318,7 +336,7 @@ namespace Debugger.MetaData
code[05] == 0x04 && // <field token>
code[06] == 0x2A) // ret
{
token = getTokenFromIL(code, 05);
token = GetTokenFromIL(code, 05);
}
if (token != 0) {
@ -344,7 +362,7 @@ namespace Debugger.MetaData @@ -344,7 +362,7 @@ namespace Debugger.MetaData
/// <param name="ilCode">Bytes representing the code.</param>
/// <param name="tokenEndIndex">Index of last byte of the token.</param>
/// <returns>IL token.</returns>
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 @@ -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 @@ -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<SequencePoint> seqPoints = new List<SequencePoint>(symMethod.SequencePoints);
seqPoints.Sort();
@ -381,53 +399,36 @@ namespace Debugger.MetaData @@ -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 @@ -439,28 +440,6 @@ namespace Debugger.MetaData
}
}
/// <summary>
/// Get a method from a managed type, method name and argument count
/// </summary>
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 @@ -472,62 +451,14 @@ namespace Debugger.MetaData
}
}
/// <summary> Gets the number of paramters of this method </summary>
public int ParameterCount {
get {
return this.MethodDefSig.ParamCount;
}
}
List<DebugLocalVariableInfo> localVariables;
/// <summary> Gets the name of given parameter </summary>
/// <param name="index"> Zero-based index </param>
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;
}
}
/// <summary> Get names of all parameters in order </summary>
public string[] ParameterNames {
get {
List<string> names = new List<string>();
for(int i = 0; i < ParameterCount; i++) {
names.Add(GetParameterName(i));
}
return names.ToArray();
}
}
public List<DebugLocalVariableInfo> LocalVariables {
get {
if (this.SymMethod != null) { // TODO: Is this needed?
return GetLocalVariables();
} else {
return new List<DebugLocalVariableInfo>();
}
}
}
public string[] LocalVariableNames {
get {
List<DebugLocalVariableInfo> vars = this.LocalVariables;
List<string> names = new List<string>();
for(int i = 0; i < vars.Count; i++) {
names.Add(vars[i].Name);
}
names.Sort();
return names.ToArray();
}
}
List<DebugLocalVariableInfo> localVariables; // Cache
List<DebugLocalVariableInfo> GetLocalVariables()
public List<DebugLocalVariableInfo> GetLocalVariables()
{
// TODO: Is this needed?
if (this.SymMethod == null)
return new List<DebugLocalVariableInfo>();
if (localVariables != null) return localVariables;
localVariables = GetLocalVariablesInScope(this.SymMethod.RootScope);
@ -558,6 +489,7 @@ namespace Debugger.MetaData @@ -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 @@ -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 @@ -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 @@ -659,5 +593,10 @@ namespace Debugger.MetaData
}
return new Value(context.AppDomain, corVal);
}
public override string ToString()
{
return this.FullName;
}
}
}

13
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugParameterInfo.cs

@ -18,10 +18,10 @@ namespace Debugger.MetaData @@ -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 @@ -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;
}
}
}

83
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugPropertyInfo.cs

@ -31,39 +31,35 @@ namespace Debugger.MetaData @@ -31,39 +31,35 @@ namespace Debugger.MetaData
}
public override Type DeclaringType {
get {
return declaringType;
}
get { return declaringType; }
}
/// <summary> The AppDomain in which this member is loaded </summary>
/// <summary> The AppDomain in which this member is declared </summary>
[Debugger.Tests.Ignore]
public AppDomain AppDomain {
get {
return declaringType.AppDomain;
}
get { return declaringType.AppDomain; }
}
/// <summary> The Process in which this member is loaded </summary>
/// <summary> The Process in which this member is declared </summary>
[Debugger.Tests.Ignore]
public Process Process {
get {
return declaringType.Process;
}
get { return declaringType.Process; }
}
/// <summary> The Module in which this member is loaded </summary>
/// <summary> The Module in which this member is declared </summary>
[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 @@ -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 @@ -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 @@ -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 @@ -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<Value> args = new List<Value>();
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<Value> args = new List<Value>();
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 @@ -169,5 +163,10 @@ namespace Debugger.MetaData
return (getMethod ?? setMethod).IsStatic;
}
}
public override string ToString()
{
return this.PropertyType + " " + this.Name;
}
}
}

140
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugType.cs

@ -27,7 +27,7 @@ namespace Debugger.MetaData @@ -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.
/// </remarks>
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 @@ -55,34 +55,28 @@ namespace Debugger.MetaData
static Dictionary<ICorDebugType, DebugType> loadedTypes = new Dictionary<ICorDebugType, DebugType>();
public override Type DeclaringType {
get {
throw new NotSupportedException();
}
get { throw new NotSupportedException(); }
}
/// <summary> The AppDomain in which this type is loaded </summary>
[Debugger.Tests.Ignore]
public AppDomain AppDomain {
get {
return appDomain;
}
get { return appDomain; }
}
/// <summary> The Process in which this member is loaded </summary>
/// <summary> The Process in which this type is loaded </summary>
[Debugger.Tests.Ignore]
public Process Process {
get {
return process;
}
get { return process; }
}
/// <summary> The Module in which this member is loaded </summary>
/// <summary> The Module in which this type is loaded </summary>
[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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -472,13 +472,9 @@ namespace Debugger.MetaData
return GetMember<PropertyInfo>(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 @@ -540,11 +536,6 @@ namespace Debugger.MetaData
get { return corType; }
}
/// <summary> Gets a list of all interfaces that this type implements </summary>
public List<DebugType> Interfaces {
get { return interfaces; }
}
/// <summary> Returns what kind of type this is. (eg. value type) </summary>
public DebugTypeKind Kind {
get {
@ -964,7 +955,7 @@ namespace Debugger.MetaData @@ -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 @@ -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 @@ -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;
}
}
}

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/IDebugMemberInfo.cs

@ -11,7 +11,9 @@ namespace Debugger.MetaData @@ -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; }
}

9
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Values/Value.Object.cs

@ -98,6 +98,12 @@ namespace Debugger @@ -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 @@ -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

Loading…
Cancel
Save