From 3c97029fc0a7b0cb9965684f9fada2b246c3bdc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Mon, 30 Jun 2008 13:58:10 +0000 Subject: [PATCH] Significantly beefing up the MetaData wrapper git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3154 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Debugger.Core.csproj | 6 - .../Project/Src/Control/Module.cs | 4 +- .../Src/Interop/MetaData/IMetaDataImport.cs | 40 +- .../Project/Src/Metadata/DebugType.cs | 16 +- .../Project/Src/Metadata/MethodInfo.cs | 2 +- .../Src/Wrappers/MetaData/FieldProps.cs | 41 - .../Wrappers/MetaData/InterfaceImplProps.cs | 25 - .../Src/Wrappers/MetaData/MetaDataImport.cs | 1112 +++++++++++++++-- .../Src/Wrappers/MetaData/MethodProps.cs | 43 - .../Src/Wrappers/MetaData/ParamProps.cs | 24 - .../Src/Wrappers/MetaData/TypeDefProps.cs | 29 - .../Src/Wrappers/MetaData/TypeRefProps.cs | 21 - .../Project/Debugger.Tests.csproj | 1 + .../Src/TestPrograms/DebuggerAttributes.cs | 77 ++ .../Project/Src/TestPrograms/_Template.cs | 4 +- 15 files changed, 1093 insertions(+), 352 deletions(-) delete mode 100644 src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/FieldProps.cs delete mode 100644 src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/InterfaceImplProps.cs delete mode 100644 src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/MethodProps.cs delete mode 100644 src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/ParamProps.cs delete mode 100644 src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/TypeDefProps.cs delete mode 100644 src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/TypeRefProps.cs create mode 100644 src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/DebuggerAttributes.cs 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 0a1404deab..0ef2c16b5c 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj @@ -361,13 +361,7 @@ - - - - - - diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs index 4ab6b53996..28e697b10f 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs @@ -34,7 +34,7 @@ namespace Debugger } } - internal MetaDataImport MetaData { + public MetaDataImport MetaData { get { return metaData; } @@ -153,7 +153,7 @@ namespace Debugger public List GetNamesOfDefinedTypes() { List names = new List(); - foreach(TypeDefProps typeProps in this.MetaData.EnumTypeDefs()) { + foreach(TypeDefProps typeProps in this.MetaData.EnumTypeDefProps()) { names.Add(typeProps.Name); } return names; diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/MetaData/IMetaDataImport.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/MetaData/IMetaDataImport.cs index 2ec35687a3..7f8d357732 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/MetaData/IMetaDataImport.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/MetaData/IMetaDataImport.cs @@ -27,11 +27,11 @@ namespace Debugger.Interop.MetaData [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void EnumInterfaceImpls([In, Out] ref IntPtr phEnum, uint td, out uint rImpls, uint cMax, out uint pcImpls); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void EnumTypeRefs([In, Out] ref IntPtr phEnum, ref uint rTypeRefs, uint cMax, ref uint pcTypeRefs); + void EnumTypeRefs([In, Out] ref IntPtr phEnum, out uint rTypeRefs, uint cMax, out uint pcTypeRefs); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void FindTypeDefByName([In, MarshalAs(UnmanagedType.LPWStr)] string szTypeDef, [In] uint tkEnclosingClass, out uint ptd); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetScopeProps([Out, MarshalAs(UnmanagedType.LPWStr)] string szName, [In] uint cchName, out uint pchName, out Guid pmvid); + void GetScopeProps([Out] IntPtr szName, [In] uint cchName, out uint pchName, out Guid pmvid); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void GetModuleFromScope(out uint pmd); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] @@ -63,51 +63,51 @@ namespace Debugger.Interop.MetaData [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void EnumPermissionSets([In, Out] ref IntPtr phEnum, [In] uint tk, [In] uint dwActions, out uint rPermission, [In] uint cMax, out uint pcTokens); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void FindMember([In] uint td, [In, MarshalAs(UnmanagedType.LPWStr)] string szName, [In] ref byte pvSigBlob, [In] uint cbSigBlob, out uint pmb); + void FindMember([In] uint td, [In, MarshalAs(UnmanagedType.LPWStr)] string szName, [In] IntPtr pvSigBlob, [In] uint cbSigBlob, out uint pmb); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void FindMethod([In] uint td, [In, MarshalAs(UnmanagedType.LPWStr)] string szName, [In] ref byte pvSigBlob, [In] uint cbSigBlob, out uint pmb); + void FindMethod([In] uint td, [In, MarshalAs(UnmanagedType.LPWStr)] string szName, [In] IntPtr pvSigBlob, [In] uint cbSigBlob, out uint pmb); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void FindField([In] uint td, [In, MarshalAs(UnmanagedType.LPWStr)] string szName, [In] ref byte pvSigBlob, [In] uint cbSigBlob, out uint pmb); + void FindField([In] uint td, [In, MarshalAs(UnmanagedType.LPWStr)] string szName, [In] IntPtr pvSigBlob, [In] uint cbSigBlob, out uint pmb); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void FindMemberRef([In] uint td, [In, MarshalAs(UnmanagedType.LPWStr)] string szName, [In] ref byte pvSigBlob, [In] uint cbSigBlob, out uint pmr); + void FindMemberRef([In] uint td, [In, MarshalAs(UnmanagedType.LPWStr)] string szName, [In] IntPtr pvSigBlob, [In] uint cbSigBlob, out uint pmr); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetMethodProps([In] uint mb, out uint pClass, [Out] IntPtr szMethod, [In] uint cchMethod, out uint pchMethod, out uint pdwAttr, [Out] IntPtr ppvSigBlob, out uint pcbSigBlob, out uint pulCodeRVA, out uint pdwImplFlags); + void GetMethodProps([In] uint mb, out uint pClass, [Out] IntPtr szMethod, [In] uint cchMethod, out uint pchMethod, out uint pdwAttr, out IntPtr ppvSigBlob, out uint pcbSigBlob, out uint pulCodeRVA, out uint pdwImplFlags); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetMemberRefProps([In] uint mr, out uint ptk, [Out, MarshalAs(UnmanagedType.LPWStr)] string szMember, [In] uint cchMember, out uint pchMember, [Out] IntPtr ppvSigBlob, out uint pbSig); + void GetMemberRefProps([In] uint mr, out uint ptk, [Out] IntPtr szMember, [In] uint cchMember, out uint pchMember, out IntPtr ppvSigBlob, out uint pbSig); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void EnumProperties([In, Out] ref IntPtr phEnum, [In] uint td, out uint rProperties, [In] uint cMax, out uint pcProperties); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void EnumEvents([In, Out] ref IntPtr phEnum, [In] uint td, out uint rEvents, [In] uint cMax, out uint pcEvents); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetEventProps([In] uint ev, out uint pClass, [Out, MarshalAs(UnmanagedType.LPWStr)] string szEvent, [In] uint cchEvent, out uint pchEvent, out uint pdwEventFlags, out uint ptkEventType, out uint pmdAddOn, out uint pmdRemoveOn, out uint pmdFire, out uint rmdOtherMethod, [In] uint cMax, out uint pcOtherMethod); + void GetEventProps([In] uint ev, out uint pClass, [Out] IntPtr szEvent, [In] uint cchEvent, out uint pchEvent, out uint pdwEventFlags, out uint ptkEventType, out uint pmdAddOn, out uint pmdRemoveOn, out uint pmdFire, uint[] rmdOtherMethod, [In] uint cMax, out uint pcOtherMethod); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void EnumMethodSemantics([In, Out] ref IntPtr phEnum, [In] uint mb, out uint rEventProp, [In] uint cMax, out uint pcEventProp); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void GetMethodSemantics([In] uint mb, [In] uint tkEventProp, out uint pdwSemanticsFlags); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetClassLayout([In] uint td, out uint pdwPackSize, out COR_FIELD_OFFSET rFieldOffset, [In] uint cMax, out uint pcFieldOffset, out uint pulClassSize); + void GetClassLayout([In] uint td, out uint pdwPackSize, COR_FIELD_OFFSET[] rFieldOffset, [In] uint cMax, out uint pcFieldOffset, out uint pulClassSize); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetFieldMarshal([In] uint tk, [Out] IntPtr ppvNativeType, out uint pcbNativeType); + void GetFieldMarshal([In] uint tk, out IntPtr ppvNativeType, out uint pcbNativeType); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void GetRVA([In] uint tk, out uint pulCodeRVA, out uint pdwImplFlags); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void GetPermissionSetProps([In] uint pm, out uint pdwAction, out IntPtr ppvPermission, out uint pcbPermission); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetSigFromToken([In] uint mdSig, [Out] IntPtr ppvSig, out uint pcbSig); + void GetSigFromToken([In] uint mdSig, out IntPtr ppvSig, out uint pcbSig); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetModuleRefProps([In] uint mur, [Out, MarshalAs(UnmanagedType.LPWStr)] string szName, [In] uint cchName, out uint pchName); + void GetModuleRefProps([In] uint mur, [Out] IntPtr szName, [In] uint cchName, out uint pchName); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void EnumModuleRefs([In, Out] ref IntPtr phEnum, out uint rModuleRefs, [In] uint cMax, out uint pcModuleRefs); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetTypeSpecFromToken([In] uint typespec, [Out] IntPtr ppvSig, out uint pcbSig); + void GetTypeSpecFromToken([In] uint typespec, out IntPtr ppvSig, out uint pcbSig); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void GetNameFromToken([In] uint tk, [Out] IntPtr pszUtf8NamePtr); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void EnumUnresolvedMethods([In, Out] ref IntPtr phEnum, out uint rMethods, [In] uint cMax, out uint pcTokens); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetUserString([In] uint stk, [Out, MarshalAs(UnmanagedType.LPWStr)] string szString, [In] uint cchString, out uint pchString); + void GetUserString([In] uint stk, [Out] IntPtr szString, [In] uint cchString, out uint pchString); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetPinvokeMap([In] uint tk, out uint pdwMappingFlags, [Out, MarshalAs(UnmanagedType.LPWStr)] string szImportName, [In] uint cchImportName, out uint pchImportName, out uint pmrImportDLL); + void GetPinvokeMap([In] uint tk, out uint pdwMappingFlags, [Out] IntPtr szImportName, [In] uint cchImportName, out uint pchImportName, out uint pmrImportDLL); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void EnumSignatures([In, Out] ref IntPtr phEnum, out uint rSignatures, [In] uint cMax, out uint pcSignatures); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] @@ -123,13 +123,13 @@ namespace Debugger.Interop.MetaData [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void FindTypeRef([In] uint tkResolutionScope, [In, MarshalAs(UnmanagedType.LPWStr)] string szName, out uint ptr); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetMemberProps([In] uint mb, out uint pClass, [In, MarshalAs(UnmanagedType.LPWStr)] string szMember, [In] uint cchMember, out uint pchMember, out uint pdwAttr, [Out] IntPtr ppvSigBlob, out uint pcbSigBlob, out uint pulCodeRVA, out uint pdwImplFlags, out uint pdwCPlusTypeFlag, out IntPtr ppValue, out uint pcchValue); + void GetMemberProps([In] uint mb, out uint pClass, IntPtr szMember, [In] uint cchMember, out uint pchMember, out uint pdwAttr, out IntPtr ppvSigBlob, out uint pcbSigBlob, out uint pulCodeRVA, out uint pdwImplFlags, out uint pdwCPlusTypeFlag, out IntPtr ppValue, out uint pcchValue); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetFieldProps([In] uint mb, out uint pClass, [In] IntPtr szField, [In] uint cchField, out uint pchField, out uint pdwAttr, [Out] IntPtr ppvSigBlob, out uint pcbSigBlob, out uint pdwCPlusTypeFlag, out IntPtr ppValue, out uint pcchValue); + void GetFieldProps([In] uint mb, out uint pClass, [In] IntPtr szField, [In] uint cchField, out uint pchField, out uint pdwAttr, out IntPtr ppvSigBlob, out uint pcbSigBlob, out uint pdwCPlusTypeFlag, out IntPtr ppValue, out uint pcchValue); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetPropertyProps([In] uint prop, out uint pClass, [Out, MarshalAs(UnmanagedType.LPWStr)] string szProperty, [In] uint cchProperty, out uint pchProperty, out uint pdwPropFlags, [Out] IntPtr ppvSig, out uint pbSig, out uint pdwCPlusTypeFlag, out IntPtr ppDefaultValue, out uint pcchDefaultValue, out uint pmdSetter, out uint pmdGetter, out uint rmdOtherMethod, [In] uint cMax, out uint pcOtherMethod); + void GetPropertyProps([In] uint prop, out uint pClass, [Out] IntPtr szProperty, [In] uint cchProperty, out uint pchProperty, out uint pdwPropFlags, out IntPtr ppvSig, out uint pbSig, out uint pdwCPlusTypeFlag, out IntPtr ppDefaultValue, out uint pcchDefaultValue, out uint pmdSetter, out uint pmdGetter, uint[] rmdOtherMethod, [In] uint cMax, out uint pcOtherMethod); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetParamProps([In] uint tk, out uint pmd, out uint pulSequence, [Out] IntPtr szName, [In] uint cchName, out uint pchName, out uint pdwAttr, out uint pdwCPlusTypeFlag, [Out] IntPtr ppValue, out uint pcchValue); + void GetParamProps([In] uint tk, out uint pmd, out uint pulSequence, [Out] IntPtr szName, [In] uint cchName, out uint pchName, out uint pdwAttr, out uint pdwCPlusTypeFlag, out IntPtr ppValue, out uint pcchValue); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void GetCustomAttributeByName([In] uint tkObj, [In, MarshalAs(UnmanagedType.LPWStr)] string szName, out IntPtr ppData, out uint pcbData); [PreserveSig, MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] 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 2fd9a26d0b..09db598395 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 @@ -319,7 +319,7 @@ namespace Debugger.MetaData foreach(Module module in process.Modules) { if (!domainID.HasValue || domainID == module.CorModule.Assembly.AppDomain.ID) { try { - uint token = module.MetaData.FindTypeDefByName(fullTypeName, 0 /* enclosing class for nested */).Token; + uint token = module.MetaData.FindTypeDefPropsByName(fullTypeName, 0 /* enclosing class for nested */).Token; return Create(process, module.CorModule.GetClassFromToken(token)); } catch { continue; @@ -403,7 +403,7 @@ namespace Debugger.MetaData { // TODO: Generic types List types = new List(); - foreach(TypeDefProps typeDef in module.MetaData.EnumTypeDefs()) { + foreach(TypeDefProps typeDef in module.MetaData.EnumTypeDefProps()) { if (module.MetaData.GetGenericParamCount(typeDef.Token) == 0) { types.Add(DebugType.Create(module, typeDef.Token)); } @@ -442,22 +442,22 @@ namespace Debugger.MetaData void LoadMemberInfo() { // Load interfaces - foreach(InterfaceImplProps implProps in module.MetaData.EnumInterfaceImpls(this.MetadataToken)) { - if ((implProps.ptkIface & 0xFF000000) == (uint)CorTokenType.TypeDef || - (implProps.ptkIface & 0xFF000000) == (uint)CorTokenType.TypeRef) + foreach(InterfaceImplProps implProps in module.MetaData.EnumInterfaceImplProps(this.MetadataToken)) { + if ((implProps.Interface & 0xFF000000) == (uint)CorTokenType.TypeDef || + (implProps.Interface & 0xFF000000) == (uint)CorTokenType.TypeRef) { - this.interfaces.Add(DebugType.Create(module, implProps.ptkIface)); + this.interfaces.Add(DebugType.Create(module, implProps.Interface)); } } // Load fields - foreach(FieldProps field in module.MetaData.EnumFields(this.MetadataToken)) { + foreach(FieldProps field in module.MetaData.EnumFieldProps(this.MetadataToken)) { if (field.IsStatic && field.IsLiteral) continue; // Skip static literals TODO: Why? members.Add(new FieldInfo(this, field)); }; // Load methods - foreach(MethodProps m in module.MetaData.EnumMethods(this.MetadataToken)) { + foreach(MethodProps m in module.MetaData.EnumMethodProps(this.MetadataToken)) { members.Add(new MethodInfo(this, m)); } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/MethodInfo.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/MethodInfo.cs index 8bfb802732..9650fb9f85 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/MethodInfo.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/MethodInfo.cs @@ -207,7 +207,7 @@ namespace Debugger.MetaData { // index = 0 is return parameter try { - return this.Module.MetaData.GetParamForMethodIndex(this.MetadataToken, (uint)index + 1).Name; + return this.Module.MetaData.GetParamPropsForMethodIndex(this.MetadataToken, (uint)index + 1).Name; } catch { return String.Empty; } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/FieldProps.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/FieldProps.cs deleted file mode 100644 index 1d2f6d4eac..0000000000 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/FieldProps.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// -// -// -// $Revision$ -// - -#pragma warning disable 1591 - -using System; - -namespace Debugger.Wrappers.MetaData -{ - public struct FieldProps - { - public uint Token; - public string Name; - public uint ClassToken; - public uint Flags; - - public bool IsStatic { - get { - return (Flags & (uint)ClassFieldAttribute.fdStatic) != 0; - } - } - - public bool IsPublic { - get { - return (Flags & (uint)ClassFieldAttribute.fdPublic) != 0; - } - } - - public bool IsLiteral { - get { - return (Flags & (uint)ClassFieldAttribute.fdLiteral) != 0; - } - } - } -} - -#pragma warning restore 1591 diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/InterfaceImplProps.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/InterfaceImplProps.cs deleted file mode 100644 index 52e44662f7..0000000000 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/InterfaceImplProps.cs +++ /dev/null @@ -1,25 +0,0 @@ -// -// -// -// -// $Revision$ -// - -#pragma warning disable 1591 - -using System; - -namespace Debugger.Wrappers.MetaData -{ - public struct InterfaceImplProps - { - public uint Token; - public uint classTypeDef; - public uint ptkIface; - - public override string ToString() - { - return string.Format("[InterfaceImplProps Token={0:X} ClassTypeDef={1:X} PtkIface={2:X}]", this.Token, this.classTypeDef, this.ptkIface); - } - } -} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/MetaDataImport.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/MetaDataImport.cs index 90b684a284..ed0f6c44f4 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/MetaDataImport.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/MetaDataImport.cs @@ -5,19 +5,21 @@ // $Revision$ // +// Missing XML comment for publicly visible type or member #pragma warning disable 1591 using System; using System.Collections.Generic; +using System.Runtime.InteropServices; + using Debugger.Interop.MetaData; using Debugger.Wrappers.CorDebug; using Debugger.Wrappers.CorSym; namespace Debugger.Wrappers.MetaData { - /// - /// Wrapper for the unmanaged metadata API - /// + /// Wrapper for the unmanaged metadata API. + /// http://msdn.microsoft.com/en-us/library/ms233124.aspx public class MetaDataImport: IDisposable { IMetaDataImport metaData; @@ -52,204 +54,809 @@ namespace Debugger.Wrappers.MetaData } } - public IEnumerable EnumTypeDefs() + + // CloseEnum, CountEnum and ResetEnum are not wrapped + + + public IEnumerable EnumCustomAttributes(uint token_Scope, uint token_TypeOfAttributes) { - foreach(uint token in EnumerateTokens(metaData.EnumTypeDefs)) { - yield return GetTypeDefProps(token); + return EnumerateTokens(metaData.EnumCustomAttributes, token_Scope, token_TypeOfAttributes); + } + + public IEnumerable EnumCustomAttributeProps(uint token_Scope, uint token_TypeOfAttributes) + { + foreach(uint token in EnumerateTokens(metaData.EnumCustomAttributes, token_Scope, token_TypeOfAttributes)) { + yield return GetCustomAttributeProps(token); } } - public TypeDefProps GetTypeDefProps(uint typeToken) + public IEnumerable EnumEvents(uint typeDef) { - TypeDefProps typeDefProps = new TypeDefProps(); - - typeDefProps.Token = typeToken; - typeDefProps.Name = - Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { - metaData.GetTypeDefProps(typeDefProps.Token, - pString, pStringLenght, out stringLenght, // The string to get - out typeDefProps.Flags, - out typeDefProps.SuperClassToken); - }); - - return typeDefProps; + return EnumerateTokens(metaData.EnumEvents, typeDef); } - public TypeRefProps GetTypeRefProps(uint typeToken) + public IEnumerable EnumEventProps(uint typeDef) { - TypeRefProps typeRefProps = new TypeRefProps(); - - typeRefProps.Token = typeToken; - typeRefProps.Name = - Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { - uint unused; - metaData.GetTypeRefProps(typeRefProps.Token, - out unused, - pString, pStringLenght,out stringLenght // The string to get - ); - }); - - return typeRefProps; + foreach(uint token in EnumerateTokens(metaData.EnumEvents, typeDef)) { + yield return GetEventProps(token); + } } - public IEnumerable EnumFields(uint typeToken) + public IEnumerable EnumFields(uint typeDef) { - foreach(uint token in EnumerateTokens(metaData.EnumFields, typeToken)) { + return EnumerateTokens(metaData.EnumFields, typeDef); + } + + public IEnumerable EnumFieldProps(uint typeDef) + { + foreach(uint token in EnumerateTokens(metaData.EnumFields, typeDef)) { yield return GetFieldProps(token); } } - public FieldProps GetFieldProps(uint fieldToken) + public IEnumerable EnumFieldsWithName(uint typeDef, string name) { - FieldProps fieldProps = new FieldProps(); - - fieldProps.Token = fieldToken; - fieldProps.Name = - Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { - uint unused; - IntPtr unusedPtr = IntPtr.Zero; - metaData.GetFieldProps(fieldProps.Token, - out fieldProps.ClassToken, - pString, pStringLenght, out stringLenght, // The string to get - out fieldProps.Flags, - IntPtr.Zero, - out unused, - out unused, - out unusedPtr, - out unused); - }); - - return fieldProps; + return EnumerateTokens(metaData.EnumFieldsWithName, typeDef, name); } - public IEnumerable EnumMethods(uint typeToken) + public IEnumerable EnumFieldPropsWithName(uint typeDef, string name) { - foreach(uint token in EnumerateTokens(metaData.EnumMethods, typeToken)) { - yield return GetMethodProps(token); + foreach(uint token in EnumerateTokens(metaData.EnumFieldsWithName, typeDef, name)) { + yield return GetFieldProps(token); } } - public IEnumerable EnumMethodsWithName(uint typeToken, string name) + public IEnumerable EnumGenericParams(uint typeDef_methodDef) + { + return EnumerateTokens(metaData.EnumGenericParams, typeDef_methodDef); + } + + /// MethodDef tokens + public IEnumerable EnumInterfaceImpls(uint typeDef) + { + return EnumerateTokens(metaData.EnumInterfaceImpls, typeDef); + } + + public IEnumerable EnumInterfaceImplProps(uint typeDef) + { + foreach(uint token in EnumerateTokens(metaData.EnumInterfaceImpls, typeDef)) { + yield return GetInterfaceImplProps(token); + } + } + + public IEnumerable EnumMemberRefs(uint typeDef_typeRef_methodDef_moduleRef) + { + return EnumerateTokens(metaData.EnumMemberRefs, typeDef_typeRef_methodDef_moduleRef); + } + + public IEnumerable EnumMemberRefProps(uint typeDef_typeRef_methodDef_moduleRef) + { + foreach(uint token in EnumerateTokens(metaData.EnumMemberRefs, typeDef_typeRef_methodDef_moduleRef)) { + yield return GetMemberRefProps(token); + } + } + + public IEnumerable EnumMembers(uint typeDef) + { + return EnumerateTokens(metaData.EnumMembers, typeDef); + } + + public IEnumerable EnumMemberProps(uint typeDef) + { + foreach(uint token in EnumerateTokens(metaData.EnumMembers, typeDef)) { + yield return GetMemberProps(token); + } + } + + public IEnumerable EnumMembersWithName(uint typeDef, string name) + { + return EnumerateTokens(metaData.EnumMembersWithName, typeDef, name); + } + + public IEnumerable EnumMemberPropsWithName(uint typeDef, string name) + { + foreach(uint token in EnumerateTokens(metaData.EnumMembersWithName, typeDef, name)) { + yield return GetMemberProps(token); + } + } + + /// MethodBody and MethodDeclaration tokens + public IEnumerable EnumMethodImpls(uint typeDef) { IntPtr enumerator = IntPtr.Zero; while(true) { - uint methodToken; - uint methodsFetched; - metaData.EnumMethodsWithName(ref enumerator, typeToken, name, out methodToken, 1, out methodsFetched); - if (methodsFetched == 0) { + MethodImpl ret = new MethodImpl(); + uint fetched; + metaData.EnumMethodImpls(ref enumerator, typeDef, out ret.MethodBody, out ret.MethodDecl, 1, out fetched); + if (fetched == 0) { metaData.CloseEnum(enumerator); break; } - yield return GetMethodProps(methodToken); + yield return ret; } } - public unsafe MethodProps GetMethodProps(uint methodToken) + public IEnumerable EnumMethods(uint typeDef) { - MethodProps methodProps = new MethodProps(); - - methodProps.Token = methodToken; - methodProps.Name = - Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { - uint sigBlobSize; - metaData.GetMethodProps(methodProps.Token, - out methodProps.ClassToken, - pString, pStringLenght, out stringLenght, // The string to get - out methodProps.Flags, - IntPtr.Zero,//new IntPtr(&pSigBlob), - out sigBlobSize, - out methodProps.CodeRVA, - out methodProps.ImplFlags); - }); - - return methodProps; + return EnumerateTokens(metaData.EnumMethods, typeDef); + } + + public IEnumerable EnumMethodProps(uint typeDef) + { + foreach(uint token in EnumerateTokens(metaData.EnumMethods, typeDef)) { + yield return GetMethodProps(token); + } } - public IEnumerable EnumParams(uint mb) + /// Events or properties + public IEnumerable EnumMethodSemantics(uint methodDef) { - return EnumerateTokens(metaData.EnumParams, mb); + return EnumerateTokens(metaData.EnumMethodSemantics, methodDef); } - public int GetParamCount(uint methodToken) + public IEnumerable EnumMethodsWithName(uint typeDef, string name) { - int count = 0; - foreach(uint param in EnumParams(methodToken)) { - ParamProps paramProps = GetParamProps(param); - // Zero is special parameter representing the return parameter - if (paramProps.ParameterSequence != 0) { - count++; - } + return EnumerateTokens(metaData.EnumMethodsWithName, typeDef, name); + } + + public IEnumerable EnumMethodPropsWithName(uint typeDef, string name) + { + foreach(uint token in EnumerateTokens(metaData.EnumMethodsWithName, typeDef, name)) { + yield return GetMethodProps(token); } - return count; } - public ParamProps GetParamForMethodIndex(uint methodToken, uint parameterSequence) + public IEnumerable EnumModuleRefs() + { + return EnumerateTokens(metaData.EnumModuleRefs); + } + + public IEnumerable EnumModuleRefProps() + { + foreach(uint token in EnumerateTokens(metaData.EnumModuleRefs)) { + yield return GetModuleRefProps(token); + } + } + + public IEnumerable EnumParams(uint methodDef) + { + return EnumerateTokens(metaData.EnumParams, methodDef); + } + + public IEnumerable EnumParamProps(uint methodDef) + { + foreach(uint token in EnumerateTokens(metaData.EnumParams, methodDef)) { + yield return GetParamProps(token); + } + } + + public IEnumerable EnumPermissionSets(uint token_scope_nullable, uint actions) + { + return EnumerateTokens(metaData.EnumPermissionSets, token_scope_nullable, actions); + } + + public IEnumerable EnumPermissionSetProps(uint token_scope_nullable, uint actions) + { + foreach(uint token in EnumerateTokens(metaData.EnumPermissionSets, token_scope_nullable, actions)) { + yield return GetPermissionSetProps(token); + } + } + + public IEnumerable EnumProperties(uint typeDef) + { + return EnumerateTokens(metaData.EnumProperties, typeDef); + } + + public IEnumerable EnumPropertyProps(uint typeDef) + { + foreach(uint token in EnumerateTokens(metaData.EnumProperties, typeDef)) { + yield return GetPropertyProps(token); + } + } + + public IEnumerable EnumSignatures() + { + return EnumerateTokens(metaData.EnumSignatures); + } + + public IEnumerable EnumTypeDefs() + { + return EnumerateTokens(metaData.EnumTypeDefs); + } + + public IEnumerable EnumTypeDefProps() + { + foreach(uint token in EnumerateTokens(metaData.EnumTypeDefs)) { + yield return GetTypeDefProps(token); + } + } + + public IEnumerable EnumTypeRefs() + { + return EnumerateTokens(metaData.EnumTypeRefs); + } + + public IEnumerable EnumTypeRefProps() + { + foreach(uint token in EnumerateTokens(metaData.EnumTypeRefs)) { + yield return GetTypeRefProps(token); + } + } + + public IEnumerable EnumTypeSpecs() + { + return EnumerateTokens(metaData.EnumTypeSpecs); + } + + public IEnumerable EnumTypeSpecBlobs() + { + foreach(uint token in EnumerateTokens(metaData.EnumTypeSpecs)) { + yield return GetTypeSpecFromToken(token); + } + } + + public IEnumerable EnumUnresolvedMethods() + { + return EnumerateTokens(metaData.EnumUnresolvedMethods); + } + + public IEnumerable EnumUserStrings() + { + return EnumerateTokens(metaData.EnumUserStrings); + } + + public IEnumerable EnumUserStringProps() + { + foreach(uint token in EnumerateTokens(metaData.EnumUserStrings)) { + yield return GetUserString(token); + } + } + + public uint FindField(uint typeDef_nullable, string name, Blob sigBlob) + { + sigBlob = sigBlob ?? Blob.Empty; + uint fieldDef; + metaData.FindField(typeDef_nullable, name, sigBlob.Adress, sigBlob.Size, out fieldDef); + return fieldDef; + } + + public FieldProps FindFieldProps(uint typeDef_nullable, string name, Blob sigBlob) + { + return GetFieldProps(FindField(typeDef_nullable, name, sigBlob)); + } + + public uint FindMember(uint typeDef_nullable, string name, Blob sigBlob) + { + sigBlob = sigBlob ?? Blob.Empty; + uint memberDef; + metaData.FindMember(typeDef_nullable, name, sigBlob.Adress, sigBlob.Size, out memberDef); + return memberDef; + } + + public MemberProps FindMemberProps(uint typeDef_nullable, string name, Blob sigBlob) + { + return GetMemberProps(FindMember(typeDef_nullable, name, sigBlob)); + } + + public uint FindMemberRef(uint typeRef_nullable, string name, Blob sigBlob) + { + sigBlob = sigBlob ?? Blob.Empty; + uint memberRef; + metaData.FindMemberRef(typeRef_nullable, name, sigBlob.Adress, sigBlob.Size, out memberRef); + return memberRef; + } + + public MemberRefProps FindMemberRefProps(uint typeRef_nullable, string name, Blob sigBlob) + { + return GetMemberRefProps(FindMemberRef(typeRef_nullable, name, sigBlob)); + } + + public uint FindMethod(uint typeDef_nullable, string name, Blob sigBlob) + { + sigBlob = sigBlob ?? Blob.Empty; + uint methodDef; + metaData.FindMethod(typeDef_nullable, name, sigBlob.Adress, sigBlob.Size, out methodDef); + return methodDef; + } + + public MethodProps FindMethodProps(uint typeDef_nullable, string name, Blob sigBlob) + { + return GetMethodProps(FindMethod(typeDef_nullable, name, sigBlob)); + } + + public uint FindTypeDefByName(string name, uint typeDef_typeRef_enclosingClass_nullable) + { + uint typeDef; + metaData.FindTypeDefByName(name, typeDef_typeRef_enclosingClass_nullable, out typeDef); + return typeDef; + } + + public TypeDefProps FindTypeDefPropsByName(string name, uint typeDef_typeRef_enclosingClass_nullable) + { + return GetTypeDefProps(FindTypeDefByName(name, typeDef_typeRef_enclosingClass_nullable)); + } + + public uint FindTypeRef(uint moduleRef_assemblyRef_typeRef_scope, string name) + { + uint typeRef; + metaData.FindTypeRef(moduleRef_assemblyRef_typeRef_scope, name, out typeRef); + return typeRef; + } + + public TypeRefProps FindTypeRefProps(uint moduleRef_assemblyRef_typeRef_scope, string name) + { + return GetTypeRefProps(FindTypeRef(moduleRef_assemblyRef_typeRef_scope, name)); + } + + public ClassLayout GetClassLayout(uint typeDef) + { + ClassLayout ret = new ClassLayout(); + ret.TypeDef = typeDef; + uint unused; + metaData.GetClassLayout( + ret.TypeDef, + out ret.PackSize, + null, 0, out unused, // TODO + out ret.ClassSize + ); + return ret; + } + + public Blob GetCustomAttributeByName(uint token_owner, string name) + { + IntPtr blobPtr; + uint blobSize; + metaData.GetCustomAttributeByName( + token_owner, + name, + out blobPtr, + out blobSize + ); + return new Blob(blobPtr, blobSize); + } + + public CustomAttributeProps GetCustomAttributeProps(uint token) + { + IntPtr blobPtr; + uint blobSize; + CustomAttributeProps ret = new CustomAttributeProps(); + ret.Token = token; + metaData.GetCustomAttributeProps( + ret.Token, + out ret.Owner, + out ret.Type, + out blobPtr, + out blobSize + ); + ret.Data = new Blob(blobPtr, blobSize); + return ret; + } + + public EventProps GetEventProps(uint eventToken) + { + EventProps ret = new EventProps(); + ret.Event = eventToken; + ret.Name = Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { + uint unused; + metaData.GetEventProps( + ret.Event, + out ret.DeclaringClass, + pString, pStringLenght, out stringLenght, + out ret.Flags, + out ret.EventType, + out ret.AddMethod, + out ret.RemoveMethod, + out ret.FireMethod, + null, 0, out unused // TODO + ); + }); + return ret; + } + + public Blob GetFieldMarshal(uint token) + { + IntPtr blobPtr; + uint blobSize; + metaData.GetFieldMarshal( + token, + out blobPtr, + out blobSize + ); + return new Blob(blobPtr, blobSize); + } + + public FieldProps GetFieldProps(uint fieldDef) + { + FieldProps ret = new FieldProps(); + IntPtr sigPtr = IntPtr.Zero; + uint sigSize = 0; + IntPtr constPtr = IntPtr.Zero; + uint constSize = 0; + ret.Token = fieldDef; + ret.Name = Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { + metaData.GetFieldProps( + ret.Token, + out ret.DeclaringClass, + pString, pStringLenght, out stringLenght, // The string to get + out ret.Flags, + out sigPtr, + out sigSize, + out ret.CPlusTypeFlag, + out constPtr, // TODO: What is this? + out constSize + ); + }); + ret.SigBlob = new Blob(sigPtr, sigSize); + ret.ConstantValue = new Blob(constPtr, constSize); + return ret; + } + + public InterfaceImplProps GetInterfaceImplProps(uint method) + { + InterfaceImplProps ret = new InterfaceImplProps(); + ret.Method = method; + metaData.GetInterfaceImplProps( + ret.Method, + out ret.Class, + out ret.Interface + ); + return ret; + } + + public MemberProps GetMemberProps(uint token) + { + MemberProps ret = new MemberProps(); + IntPtr sigPtr = IntPtr.Zero; + uint sigSize = 0; + IntPtr constPtr = IntPtr.Zero; + uint constSize = 0; + ret.Token = token; + ret.Name = Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { + metaData.GetMemberProps( + ret.Token, + out ret.Class, + pString, pStringLenght, out stringLenght, + out ret.Flags, + out sigPtr, + out sigSize, + out ret.RVA, + out ret.ImplFlags, + out ret.CPlusTypeFlag, + out constPtr, + out constSize + ); + }); + ret.SigBlob = new Blob(sigPtr, sigSize); + ret.Constant = new Blob(constPtr, constSize); + return ret; + } + + public MemberRefProps GetMemberRefProps(uint token) + { + MemberRefProps ret = new MemberRefProps(); + IntPtr sigPtr = IntPtr.Zero; + uint sigSize = 0; + ret.Token = token; + ret.Name = Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { + metaData.GetMemberRefProps( + token, + out ret.DeclaringType, + pString, pStringLenght, out stringLenght, // The string to get + out sigPtr, + out sigSize + ); + }); + ret.SigBlob = new Blob(sigPtr, sigSize); + return ret; + } + + public MethodProps GetMethodProps(uint methodToken) + { + MethodProps ret = new MethodProps(); + IntPtr sigPtr = IntPtr.Zero; + uint sigSize = 0; + ret.Token = methodToken; + ret.Name = Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { + metaData.GetMethodProps( + ret.Token, + out ret.ClassToken, + pString, pStringLenght, out stringLenght, // The string to get + out ret.Flags, + out sigPtr, + out sigSize, + out ret.CodeRVA, + out ret.ImplFlags + ); + }); + ret.SigBlob = new Blob(sigPtr, sigSize); + return ret; + } + + public uint GetMethodSemantics(uint methodDef, uint event_property) + { + uint semFlags; + metaData.GetMethodSemantics(methodDef, event_property, out semFlags); + return semFlags; + } + + public uint GetModuleFromScope() + { + uint module; + metaData.GetModuleFromScope(out module); + return module; + } + + public ModuleRefProps GetModuleRefProps(uint token) + { + ModuleRefProps ret = new ModuleRefProps(); + ret.Token = token; + ret.Name = Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { + metaData.GetModuleRefProps( + token, + pString, pStringLenght, out stringLenght + ); + }); + return ret; + } + + // GetNameFromToken is obsolete + + public uint GetNativeCallConvFromSig(Blob sigBlob) + { + uint callConv; + metaData.GetNativeCallConvFromSig(sigBlob.Adress, sigBlob.Size, out callConv); + return callConv; + } + + public NestedClassProps GetNestedClassProps(uint nestedClass) + { + NestedClassProps ret = new NestedClassProps(); + ret.NestedClass = nestedClass; + metaData.GetNestedClassProps( + ret.NestedClass, + out ret.EnclosingClass + ); + return ret; + } + + public uint GetParamForMethodIndex(uint methodToken, uint parameterSequence) { uint paramToken = 0; metaData.GetParamForMethodIndex(methodToken, parameterSequence, ref paramToken); - return GetParamProps(paramToken); + return paramToken; + } + + public ParamProps GetParamPropsForMethodIndex(uint methodToken, uint parameterSequence) + { + return GetParamProps(GetParamForMethodIndex(methodToken, parameterSequence)); } public ParamProps GetParamProps(uint paramToken) { - ParamProps paramProps = new ParamProps(); + ParamProps ret = new ParamProps(); + IntPtr constPtr = IntPtr.Zero; + uint constSize = 0; + ret.ParamDef = paramToken; + ret.Name = Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { + metaData.GetParamProps( + ret.ParamDef, + out ret.MethodDef, + out ret.Sequence, + pString, pStringLenght, out stringLenght, // The string to get + out ret.Flags, + out ret.CPlusTypeFlag, + out constPtr, + out constSize + ); + }); + ret.Constant = new Blob(constPtr, constSize); + return ret; + } + + public PermissionSetProps GetPermissionSetProps(uint permToken) + { + PermissionSetProps ret = new PermissionSetProps(); + IntPtr permPtr; + uint permSize; + ret.PermToken = permToken; + metaData.GetPermissionSetProps( + ret.PermToken, + out ret.Action, + out permPtr, + out permSize + ); + ret.SigBlob = new Blob(permPtr, permSize); + return ret; + } + + public PinvokeMap GetPinvokeMap(uint fieldDef_methodDef) + { + PinvokeMap ret = new PinvokeMap(); + ret.Token = fieldDef_methodDef; + ret.ImportName = Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { + metaData.GetPinvokeMap( + ret.Token, + out ret.Flags, + pString, pStringLenght, out stringLenght, + out ret.ModuleRef + ); + }); + return ret; + } + + public PropertyProps GetPropertyProps(uint prop) + { + PropertyProps ret = new PropertyProps(); + IntPtr sigPtr = IntPtr.Zero; + uint sigSize = 0; + IntPtr defValPtr = IntPtr.Zero; + uint defValSize = 0; + ret.Propery = prop; + ret.Name = Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { + uint unused; + metaData.GetPropertyProps( + ret.Propery, + out ret.DeclaringClass, + pString, pStringLenght, out stringLenght, + out ret.Flags, + out sigPtr, + out sigSize, + out ret.CPlusTypeFlag, + out defValPtr, + out defValSize, + out ret.SetterMethod, + out ret.GetterMethod, + null, 0, out unused // TODO + ); + }); + ret.SigBlob = new Blob(sigPtr, sigSize); + ret.DefaultValue = new Blob(defValPtr, defValSize); + return ret; + } + + public RVA GetRVA(uint methodDef_fieldDef) + { + RVA ret = new RVA(); + ret.Token = methodDef_fieldDef; + metaData.GetRVA( + ret.Token, + out ret.CodeRVA, + out ret.ImplFlags + ); + return ret; + } + + public ScopeProps GetScopeProps() + { + ScopeProps ret = new ScopeProps(); + ret.Name = Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { + metaData.GetScopeProps( + pString, pStringLenght, out stringLenght, + out ret.Guid + ); + }); + return ret; + } + + public Blob GetSigFromToken(uint token) + { + IntPtr sigPtr; + uint sigSize; + metaData.GetSigFromToken( + token, + out sigPtr, + out sigSize + ); + return new Blob(sigPtr, sigSize); + } + + public TypeDefProps GetTypeDefProps(uint typeDef) + { + TypeDefProps ret = new TypeDefProps(); + ret.Token = typeDef; + ret.Name = + Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { + metaData.GetTypeDefProps( + ret.Token, + pString, pStringLenght, out stringLenght, // The string to get + out ret.Flags, + out ret.SuperClassToken + ); + }); - paramProps.Token = paramToken; - paramProps.Name = + return ret; + } + + public TypeRefProps GetTypeRefProps(uint typeRef) + { + TypeRefProps ret = new TypeRefProps(); + ret.TypeRef = typeRef; + ret.Name = Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { - uint unused; - metaData.GetParamProps(paramProps.Token, - out paramProps.MethodToken, - out paramProps.ParameterSequence, - pString, pStringLenght, out stringLenght, // The string to get - out paramProps.Flags, - out unused, - IntPtr.Zero, - out unused); + metaData.GetTypeRefProps( + ret.TypeRef, + out ret.ResolutionScope, + pString, pStringLenght, out stringLenght // The string to get + ); }); - return paramProps; + return ret; } - public TypeDefProps FindTypeDefByName(string typeName, uint enclosingClassToken) + public Blob GetTypeSpecFromToken(uint typeSpec) { - uint typeDefToken; - metaData.FindTypeDefByName(typeName, enclosingClassToken, out typeDefToken); - return GetTypeDefProps(typeDefToken); + IntPtr sigPtr; + uint sigSize; + metaData.GetTypeSpecFromToken( + typeSpec, + out sigPtr, + out sigSize + ); + return new Blob(sigPtr, sigSize); } - public int GetGenericParamCount(uint typeDef_methodDef) + public string GetUserString(uint stringToken) { - int count = 0; - foreach(uint genericParam in EnumGenericParams(typeDef_methodDef)) count++; - return count; + return Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) { + metaData.GetUserString( + stringToken, + pString, pStringLenght, out stringLenght + ); + }); } - public IEnumerable EnumGenericParams(uint typeDef_methodDef) + public bool IsGlobal(uint token) { - return EnumerateTokens(metaData.EnumGenericParams, typeDef_methodDef); + int isGlobal; + metaData.IsGlobal(token, out isGlobal); + return isGlobal != 0; } - public IEnumerable EnumInterfaceImpls(uint typeDef) + public bool IsValidToken(uint token) { - foreach(uint token in EnumerateTokens(metaData.EnumInterfaceImpls, typeDef)) { - yield return GetInterfaceImplProps(token); + return metaData.IsValidToken(token) != 0; // TODO: Is it correct value? + } + + public ResolvedTypeRef ResolveTypeRef(uint typeRef, Guid riid) + { + ResolvedTypeRef res = new ResolvedTypeRef(); + metaData.ResolveTypeRef( + typeRef, + ref riid, + ref res.Scope, + ref res.TypeDef + ); + return res; + } + + + // Custom methods + + public int GetParamCount(uint methodToken) + { + int count = 0; + foreach(uint param in EnumParams(methodToken)) { + ParamProps paramProps = GetParamProps(param); + // Zero is special parameter representing the return parameter + if (paramProps.Sequence != 0) { + count++; + } } + return count; } - public InterfaceImplProps GetInterfaceImplProps(uint token) + public int GetGenericParamCount(uint typeDef_methodDef) { - InterfaceImplProps implProps = new InterfaceImplProps(); - implProps.Token = token; - metaData.GetInterfaceImplProps(token, out implProps.classTypeDef, out implProps.ptkIface); - return implProps; + int count = 0; + foreach(uint genericParam in EnumGenericParams(typeDef_methodDef)) count++; + return count; } #region Util - delegate void TokenEnumerator(ref IntPtr phEnum, out uint token, uint maxCount, out uint fetched); + delegate void TokenEnumerator0(ref IntPtr phEnum, out uint token, uint maxCount, out uint fetched); - IEnumerable EnumerateTokens(TokenEnumerator tokenEnumerator) + IEnumerable EnumerateTokens(TokenEnumerator0 tokenEnumerator) { IntPtr enumerator = IntPtr.Zero; while(true) { @@ -264,9 +871,9 @@ namespace Debugger.Wrappers.MetaData } } - delegate void TokenEnumeratorWithParameter(ref IntPtr phEnum, uint parameter, out uint token, uint maxCount, out uint fetched); + delegate void TokenEnumerator1(ref IntPtr phEnum, T parameter, out uint token, uint maxCount, out uint fetched); - IEnumerable EnumerateTokens(TokenEnumeratorWithParameter tokenEnumerator, uint parameter) + IEnumerable EnumerateTokens(TokenEnumerator1 tokenEnumerator, T parameter) { IntPtr enumerator = IntPtr.Zero; while(true) { @@ -281,8 +888,253 @@ namespace Debugger.Wrappers.MetaData } } + delegate void TokenEnumerator2(ref IntPtr phEnum, T parameter1, R parameter2, out uint token, uint maxCount, out uint fetched); + + IEnumerable EnumerateTokens(TokenEnumerator2 tokenEnumerator, T parameter1, R parameter2) + { + IntPtr enumerator = IntPtr.Zero; + while(true) { + uint token; + uint fetched; + tokenEnumerator(ref enumerator, parameter1, parameter2, out token, 1, out fetched); + if (fetched == 0) { + metaData.CloseEnum(enumerator); + break; + } + yield return token; + } + } + #endregion } + + public class Blob + { + public static readonly Blob Empty = new Blob(IntPtr.Zero, 0); + + IntPtr adress; + uint size; + + public IntPtr Adress { + get { return adress; } + } + + public uint Size { + get { return size; } + } + + public Blob(IntPtr adress, uint size) + { + this.adress = adress; + this.size = size; + } + + byte[] GetData() + { + byte[] data = new byte[size]; + Marshal.Copy(adress, data, 0, (int)size); + return data; + } + } + + public class ClassLayout + { + public uint TypeDef; + public uint PackSize; + public COR_FIELD_OFFSET[] FieldOffset; + public uint ClassSize; + } + + public class CustomAttributeProps + { + public uint Token; + public uint Owner; + public uint Type; + public Blob Data; + } + + public class EventProps + { + public uint Event; + public uint DeclaringClass; + public string Name; + public uint Flags; + public uint EventType; + public uint AddMethod; + public uint RemoveMethod; + public uint FireMethod; + public uint[] OtherMethods; + } + + public class FieldProps + { + public uint Token; + public string Name; + public uint DeclaringClass; + public uint Flags; + public Blob SigBlob; + public uint CPlusTypeFlag; + public Blob ConstantValue; + + public bool IsStatic { + get { return (Flags & (uint)ClassFieldAttribute.fdStatic) != 0; } + } + + public bool IsPublic { + get { return (Flags & (uint)ClassFieldAttribute.fdPublic) != 0; } + } + + public bool IsLiteral { + get { return (Flags & (uint)ClassFieldAttribute.fdLiteral) != 0; } + } + } + + public class InterfaceImplProps + { + public uint Method; + public uint Class; + public uint Interface; + } + + public class MemberProps + { + public uint Token; + public uint Class; + public string Name; + public uint Flags; + public Blob SigBlob; + public uint RVA; + public uint ImplFlags; + public uint CPlusTypeFlag; + public Blob Constant; + } + + public class MemberRefProps + { + public uint Token; + public uint DeclaringType; + public string Name; + public Blob SigBlob; + } + + public class MethodImpl + { + public uint MethodBody; + public uint MethodDecl; + } + + public class MethodProps + { + public uint Token; + public string Name; + public uint ClassToken; + public uint Flags; + public Blob SigBlob; + public uint CodeRVA; + public uint ImplFlags; + + public bool IsStatic { + get { return (Flags & (uint)CorMethodAttr.mdStatic) != 0; } + } + + public bool IsPublic { + get { return (Flags & (uint)CorMethodAttr.mdPublic) != 0; } + } + + public bool HasSpecialName { + get { return (Flags & (uint)CorMethodAttr.mdSpecialName) != 0; } + } + } + + public class ModuleRefProps + { + public uint Token; + public string Name; + } + + public class NestedClassProps + { + public uint NestedClass; + public uint EnclosingClass; + } + + public class ParamProps + { + public uint ParamDef; + public uint MethodDef; + public uint Sequence; + public string Name; + public uint Flags; + public uint CPlusTypeFlag; + public Blob Constant; + } + + public class PermissionSetProps + { + public uint PermToken; + public uint Action; + public Blob SigBlob; + } + + public class PinvokeMap + { + public uint Token; + public uint Flags; + public string ImportName; + public uint ModuleRef; + } + + public class PropertyProps + { + public uint Propery; + public uint DeclaringClass; + public string Name; + public uint Flags; + public Blob SigBlob; + public uint CPlusTypeFlag; + public Blob DefaultValue; + public uint SetterMethod; + public uint GetterMethod; + public uint[] OtherMethods; + } + + public class ResolvedTypeRef + { + public object Scope; + public uint TypeDef; + } + + public class RVA + { + public uint Token; + public uint CodeRVA; + public uint ImplFlags; + } + + public class ScopeProps + { + public string Name; + public Guid Guid; + } + + public class TypeDefProps + { + public uint Token; + public string Name; + public uint Flags; + public uint SuperClassToken; + + public bool IsInterface { + get { return (Flags & 0x00000020) != 0; } + } + } + + public class TypeRefProps + { + public uint TypeRef; + public uint ResolutionScope; + public string Name; + } } #pragma warning restore 1591 diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/MethodProps.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/MethodProps.cs deleted file mode 100644 index a1dba4bbe6..0000000000 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/MethodProps.cs +++ /dev/null @@ -1,43 +0,0 @@ -// -// -// -// -// $Revision$ -// - -#pragma warning disable 1591 - -using System; - -namespace Debugger.Wrappers.MetaData -{ - public struct MethodProps - { - public uint Token; - public string Name; - public uint ClassToken; - public uint Flags; - public uint ImplFlags; - public uint CodeRVA; - - public bool IsStatic { - get { - return (Flags & (uint)CorMethodAttr.mdStatic) != 0; - } - } - - public bool IsPublic { - get { - return (Flags & (uint)CorMethodAttr.mdPublic) != 0; - } - } - - public bool HasSpecialName { - get { - return (Flags & (uint)CorMethodAttr.mdSpecialName) != 0; - } - } - } -} - -#pragma warning restore 1591 diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/ParamProps.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/ParamProps.cs deleted file mode 100644 index 0e580636b9..0000000000 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/ParamProps.cs +++ /dev/null @@ -1,24 +0,0 @@ -// -// -// -// -// $Revision$ -// - -#pragma warning disable 1591 - -using System; - -namespace Debugger.Wrappers.MetaData -{ - public struct ParamProps - { - public uint Token; - public string Name; - public uint MethodToken; - public uint ParameterSequence; - public uint Flags; - } -} - -#pragma warning restore 1591 diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/TypeDefProps.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/TypeDefProps.cs deleted file mode 100644 index a1349ac8b9..0000000000 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/TypeDefProps.cs +++ /dev/null @@ -1,29 +0,0 @@ -// -// -// -// -// $Revision$ -// - -#pragma warning disable 1591 - -using System; - -namespace Debugger.Wrappers.MetaData -{ - public struct TypeDefProps - { - public uint Token; - public string Name; - public uint Flags; - public uint SuperClassToken; - - public bool IsInterface { - get { - return (Flags & 0x00000020) != 0; - } - } - } -} - -#pragma warning restore 1591 diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/TypeRefProps.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/TypeRefProps.cs deleted file mode 100644 index 5004543f55..0000000000 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/MetaData/TypeRefProps.cs +++ /dev/null @@ -1,21 +0,0 @@ -// -// -// -// -// $Revision$ -// - -#pragma warning disable 1591 - -using System; - -namespace Debugger.Wrappers.MetaData -{ - public struct TypeRefProps - { - public uint Token; - public string Name; - } -} - -#pragma warning restore 1591 diff --git a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Debugger.Tests.csproj b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Debugger.Tests.csproj index 1c2f8612f5..95740f7c88 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Debugger.Tests.csproj +++ b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Debugger.Tests.csproj @@ -46,6 +46,7 @@ + diff --git a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/DebuggerAttributes.cs b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/DebuggerAttributes.cs new file mode 100644 index 0000000000..7a497e0e6b --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/DebuggerAttributes.cs @@ -0,0 +1,77 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Diagnostics; + +namespace Debugger.Tests.TestPrograms +{ + public class DebuggerAttributes + { + public static void Main() + { + System.Diagnostics.Debug.WriteLine("Start"); + System.Diagnostics.Debugger.Break(); + Internal(); + System.Diagnostics.Debug.WriteLine("End"); + } + + [DebuggerStepThrough] + static void Internal() + { + System.Diagnostics.Debug.WriteLine("Internal"); + } + } +} + +#if TEST_CODE +namespace Debugger.Tests { + using Debugger.Wrappers.MetaData; + + public partial class DebuggerTests + { + [NUnit.Framework.Test] + public void DebuggerAttributes() + { + StartTest("DebuggerAttributes.cs"); + process.SelectedStackFrame.StepOver(); + process.SelectedStackFrame.StepInto(); + Module module = process.SelectedStackFrame.MethodInfo.Module; + foreach(ModuleRefProps mRef in module.MetaData.EnumModuleRefProps()) { + + } + uint typeRef = module.MetaData.FindTypeRef(0, "System.Diagnostics.DebuggerStepThroughAttribute"); + foreach(CustomAttributeProps ca in module.MetaData.EnumCustomAttributeProps(0, 0)) { + MemberRefProps memProps = module.MetaData.GetMemberRefProps(ca.Type); + TypeRefProps typeDefProps = module.MetaData.GetTypeRefProps(memProps.DeclaringType); + } + EndTest(); + } + } +} +#endif + +#if EXPECTED_OUTPUT + + + + + mscorlib.dll + DebuggerAttributes.exe + System.dll + System.Configuration.dll + System.Xml.dll + Start\r\n + Break + StepComplete + StepComplete + Internal\r\n + End\r\n + + + +#endif // EXPECTED_OUTPUT \ No newline at end of file diff --git a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/_Template.cs b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/_Template.cs index 735c9e8300..1e05f67b5a 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/_Template.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/_Template.cs @@ -9,7 +9,7 @@ using System; namespace Debugger.Tests.TestPrograms { - public class Template + public class _Template { public static void Main() { @@ -23,7 +23,7 @@ namespace Debugger.Tests { public partial class DebuggerTests { [NUnit.Framework.Test] - public void Template() + public void _Template() { StartTest("_Template.cs");