Browse Source

Improving the metadata interop class

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5147 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 16 years ago
parent
commit
9a5571b59e
  1. 36
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/MetaData.cs
  2. 225
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/MetaDataWrapper.cs
  3. 11
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/MetaData/DebugType.cs
  4. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Module.cs
  5. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/StackFrame.cs

36
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/MetaData.cs

@ -20,7 +20,7 @@ namespace Debugger.Interop.MetaData @@ -20,7 +20,7 @@ namespace Debugger.Interop.MetaData
public uint ulOffset;
}
[System.Flags()]
enum ClassFieldAttribute: uint
public enum ClassFieldAttribute: uint
{
// member access mask - Use this mask to retrieve accessibility information.
fdFieldAccessMask = 0x0007,
@ -51,7 +51,7 @@ namespace Debugger.Interop.MetaData @@ -51,7 +51,7 @@ namespace Debugger.Interop.MetaData
fdHasDefault = 0x8000, // Field has default.
fdHasFieldRVA = 0x0100, // Field has RVA.
}
enum CorCallingConvention: uint
public enum CorCallingConvention: uint
{
IMAGE_CEE_CS_CALLCONV_DEFAULT = 0x0,
@ -68,7 +68,7 @@ namespace Debugger.Interop.MetaData @@ -68,7 +68,7 @@ namespace Debugger.Interop.MetaData
IMAGE_CEE_CS_CALLCONV_HASTHIS = 0x20, // Top bit indicates a 'this' parameter
IMAGE_CEE_CS_CALLCONV_EXPLICITTHIS = 0x40, // This parameter is explicitly in the signature
}
enum CorMethodAttr: uint
public enum CorMethodAttr: uint
{
// member access mask - Use this mask to retrieve accessibility information.
mdMemberAccessMask = 0x0007,
@ -155,17 +155,17 @@ namespace Debugger.Interop.MetaData @@ -155,17 +155,17 @@ namespace Debugger.Interop.MetaData
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void FindTypeDefByName([In, MarshalAs(UnmanagedType.LPWStr)] string szTypeDef, uint tkEnclosingClass, out uint ptd);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetScopeProps([Out] IntPtr szName, uint cchName, out uint pchName, out Guid pmvid);
void GetScopeProps(IntPtr szName, 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)]
void GetTypeDefProps(uint td, [Out] IntPtr szTypeDef, uint cchTypeDef, out uint pchTypeDef, out uint pdwTypeDefFlags, out uint ptkExtends);
void GetTypeDefProps(uint td, IntPtr szTypeDef, uint cchTypeDef, out uint pchTypeDef, out uint pdwTypeDefFlags, out uint ptkExtends);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetInterfaceImplProps(uint iiImpl, out uint pClass, out uint ptkIface);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetTypeRefProps(uint tr, out uint ptkResolutionScope, [Out] IntPtr szName, uint cchName, out uint pchName);
void GetTypeRefProps(uint tr, out uint ptkResolutionScope, IntPtr szName, uint cchName, out uint pchName);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void ResolveTypeRef(uint tr, ref Guid riid, [MarshalAs(UnmanagedType.IUnknown)] ref object ppIScope, ref uint ptd);
void ResolveTypeRef(uint tr, [In] ref Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppIScope, out uint ptd);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void EnumMembers(ref IntPtr phEnum, uint cl, [Out, MarshalAsAttribute(UnmanagedType.LPArray)] uint[] rMembers, uint cMax, out uint pcTokens);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
@ -195,21 +195,21 @@ namespace Debugger.Interop.MetaData @@ -195,21 +195,21 @@ namespace Debugger.Interop.MetaData
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void FindMemberRef(uint td, [In, MarshalAs(UnmanagedType.LPWStr)] string szName, [In] IntPtr pvSigBlob, uint cbSigBlob, out uint pmr);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetMethodProps(uint mb, out uint pClass, [Out] IntPtr szMethod, uint cchMethod, out uint pchMethod, out uint pdwAttr, out IntPtr ppvSigBlob, out uint pcbSigBlob, out uint pulCodeRVA, out uint pdwImplFlags);
void GetMethodProps(uint mb, out uint pClass, IntPtr szMethod, 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(uint mr, out uint ptk, [Out] IntPtr szMember, uint cchMember, out uint pchMember, out IntPtr ppvSigBlob, out uint pbSig);
void GetMemberRefProps(uint mr, out uint ptk, IntPtr szMember, uint cchMember, out uint pchMember, out IntPtr ppvSigBlob, out uint pbSig);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void EnumProperties(ref IntPtr phEnum, uint td, [Out, MarshalAsAttribute(UnmanagedType.LPArray)] uint[] rProperties, uint cMax, out uint pcProperties);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void EnumEvents(ref IntPtr phEnum, uint td, [Out, MarshalAsAttribute(UnmanagedType.LPArray)] uint[] rEvents, uint cMax, out uint pcEvents);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetEventProps(uint ev, out uint pClass, [Out] IntPtr szEvent, uint cchEvent, out uint pchEvent, out uint pdwEventFlags, out uint ptkEventType, out uint pmdAddOn, out uint pmdRemoveOn, out uint pmdFire, uint[] rmdOtherMethod, uint cMax, out uint pcOtherMethod);
void GetEventProps(uint ev, out uint pClass, IntPtr szEvent, uint cchEvent, out uint pchEvent, out uint pdwEventFlags, out uint ptkEventType, out uint pmdAddOn, out uint pmdRemoveOn, out uint pmdFire, [Out, MarshalAsAttribute(UnmanagedType.LPArray)] uint[] rmdOtherMethod, uint cMax, out uint pcOtherMethod);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void EnumMethodSemantics(ref IntPtr phEnum, uint mb, [Out, MarshalAsAttribute(UnmanagedType.LPArray)] uint[] rEventProp, uint cMax, out uint pcEventProp);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetMethodSemantics(uint mb, uint tkEventProp, out uint pdwSemanticsFlags);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetClassLayout(uint td, out uint pdwPackSize, COR_FIELD_OFFSET[] rFieldOffset, uint cMax, out uint pcFieldOffset, out uint pulClassSize);
void GetClassLayout(uint td, out uint pdwPackSize, [Out] COR_FIELD_OFFSET[] rFieldOffset, uint cMax, out uint pcFieldOffset, out uint pulClassSize);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetFieldMarshal(uint tk, out IntPtr ppvNativeType, out uint pcbNativeType);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
@ -219,19 +219,19 @@ namespace Debugger.Interop.MetaData @@ -219,19 +219,19 @@ namespace Debugger.Interop.MetaData
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetSigFromToken(uint mdSig, out IntPtr ppvSig, out uint pcbSig);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetModuleRefProps(uint mur, [Out] IntPtr szName, uint cchName, out uint pchName);
void GetModuleRefProps(uint mur, IntPtr szName, uint cchName, out uint pchName);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void EnumModuleRefs(ref IntPtr phEnum, [Out, MarshalAsAttribute(UnmanagedType.LPArray)] uint[] rModuleRefs, uint cMax, out uint pcModuleRefs);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetTypeSpecFromToken(uint typespec, out IntPtr ppvSig, out uint pcbSig);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetNameFromToken(uint tk, [Out] IntPtr pszUtf8NamePtr);
void GetNameFromToken(uint tk, IntPtr pszUtf8NamePtr);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void EnumUnresolvedMethods(ref IntPtr phEnum, [Out, MarshalAsAttribute(UnmanagedType.LPArray)] uint[] rMethods, uint cMax, out uint pcTokens);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetUserString(uint stk, [Out] IntPtr szString, uint cchString, out uint pchString);
void GetUserString(uint stk, IntPtr szString, uint cchString, out uint pchString);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetPinvokeMap(uint tk, out uint pdwMappingFlags, [Out] IntPtr szImportName, uint cchImportName, out uint pchImportName, out uint pmrImportDLL);
void GetPinvokeMap(uint tk, out uint pdwMappingFlags, IntPtr szImportName, uint cchImportName, out uint pchImportName, out uint pmrImportDLL);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void EnumSignatures(ref IntPtr phEnum, [Out, MarshalAsAttribute(UnmanagedType.LPArray)] uint[] rSignatures, uint cMax, out uint pcSignatures);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
@ -239,7 +239,7 @@ namespace Debugger.Interop.MetaData @@ -239,7 +239,7 @@ namespace Debugger.Interop.MetaData
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void EnumUserStrings(ref IntPtr phEnum, [Out, MarshalAsAttribute(UnmanagedType.LPArray)] uint[] rStrings, uint cMax, out uint pcStrings);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetParamForMethodIndex(uint md, uint ulParamSeq, [In] ref uint ppd);
void GetParamForMethodIndex(uint md, uint ulParamSeq, out uint ppd);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void EnumCustomAttributes(ref IntPtr phEnum, uint tk, uint tkType, [Out, MarshalAsAttribute(UnmanagedType.LPArray)] uint[] rCustomAttributes, uint cMax, out uint pcCustomAttributes);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
@ -251,9 +251,9 @@ namespace Debugger.Interop.MetaData @@ -251,9 +251,9 @@ namespace Debugger.Interop.MetaData
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetFieldProps(uint mb, out uint pClass, [In] IntPtr szField, 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(uint prop, out uint pClass, [Out] IntPtr szProperty, 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, uint cMax, out uint pcOtherMethod);
void GetPropertyProps(uint prop, out uint pClass, IntPtr szProperty, 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, MarshalAsAttribute(UnmanagedType.LPArray)] uint[] rmdOtherMethod, uint cMax, out uint pcOtherMethod);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void GetParamProps(uint tk, out uint pmd, out uint pulSequence, [Out] IntPtr szName, uint cchName, out uint pchName, out uint pdwAttr, out uint pdwCPlusTypeFlag, out IntPtr ppValue, out uint pcchValue);
void GetParamProps(uint tk, out uint pmd, out uint pulSequence, IntPtr szName, 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(uint tkObj, [In, MarshalAs(UnmanagedType.LPWStr)] string szName, out IntPtr ppData, out uint pcbData);
[PreserveSig, MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]

225
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/MetaDataWrapper.cs

@ -22,6 +22,10 @@ namespace Debugger.Interop.MetaData @@ -22,6 +22,10 @@ namespace Debugger.Interop.MetaData
/// <remarks>http://msdn.microsoft.com/en-us/library/ms230172.aspx</remarks>
public class MetaDataImport: IDisposable
{
const int DefaultBufferSize = 8;
// If buffer is too small, enlarge it
const int BufferSizeMultiplier = 4;
IMetaDataImport metaData;
public MetaDataImport(ICorDebugModule pModule)
@ -67,7 +71,8 @@ namespace Debugger.Interop.MetaData @@ -67,7 +71,8 @@ namespace Debugger.Interop.MetaData
}
}
// CloseEnum, CountEnum and ResetEnum are not wrapped
// CloseEnum, CountEnum and ResetEnum are not wrapped, use them directly
// GetNameFromToken is obsolete
public uint[] EnumCustomAttributes(uint token_Scope, uint token_TypeOfAttributes)
{
@ -181,14 +186,13 @@ namespace Debugger.Interop.MetaData @@ -181,14 +186,13 @@ namespace Debugger.Interop.MetaData
uint[] decl = new uint[1];
uint fetched;
metaData.EnumMethodImpls(ref enumerator, typeDef, body, decl, 1, out fetched);
if (fetched == 0) {
metaData.CloseEnum(enumerator);
if (fetched == 0)
break;
}
ret.MethodBody = body[0];
ret.MethodDecl = decl[0];
yield return ret;
}
metaData.CloseEnum(enumerator);
}
public uint[] EnumMethods(uint typeDef)
@ -407,13 +411,19 @@ namespace Debugger.Interop.MetaData @@ -407,13 +411,19 @@ namespace Debugger.Interop.MetaData
{
ClassLayout ret = new ClassLayout();
ret.TypeDef = typeDef;
uint unused;
metaData.GetClassLayout(
ret.TypeDef,
out ret.PackSize,
null, 0, out unused, // TODO
out ret.ClassSize
);
ret.FieldOffsets = new COR_FIELD_OFFSET[DefaultBufferSize];
uint returned;
while (true) {
metaData.GetClassLayout(
ret.TypeDef,
out ret.PackSize,
ret.FieldOffsets, (uint)ret.FieldOffsets.Length, out returned,
out ret.ClassSize
);
if (returned < ret.FieldOffsets.Length) break;
ret.FieldOffsets = new COR_FIELD_OFFSET[ret.FieldOffsets.Length * BufferSizeMultiplier];
}
Array.Resize(ref ret.FieldOffsets, (int)returned);
return ret;
}
@ -452,18 +462,24 @@ namespace Debugger.Interop.MetaData @@ -452,18 +462,24 @@ namespace Debugger.Interop.MetaData
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
);
ret.OtherMethods = new uint[DefaultBufferSize];
uint returned;
while(true) {
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,
ret.OtherMethods, (uint)ret.OtherMethods.Length, out returned
);
if (returned < ret.OtherMethods.Length) break;
ret.OtherMethods = new uint[ret.OtherMethods.Length * BufferSizeMultiplier];
}
Array.Resize(ref ret.OtherMethods, (int)returned);
});
return ret;
}
@ -492,12 +508,12 @@ namespace Debugger.Interop.MetaData @@ -492,12 +508,12 @@ namespace Debugger.Interop.MetaData
metaData.GetFieldProps(
ret.Token,
out ret.DeclaringClass,
pString, pStringLenght, out stringLenght, // The string to get
pString, pStringLenght, out stringLenght,
out ret.Flags,
out sigPtr,
out sigSize,
out ret.CPlusTypeFlag,
out constPtr, // TODO: What is this?
out constPtr,
out constSize
);
});
@ -556,7 +572,7 @@ namespace Debugger.Interop.MetaData @@ -556,7 +572,7 @@ namespace Debugger.Interop.MetaData
metaData.GetMemberRefProps(
token,
out ret.DeclaringType,
pString, pStringLenght, out stringLenght, // The string to get
pString, pStringLenght, out stringLenght,
out sigPtr,
out sigSize
);
@ -575,7 +591,7 @@ namespace Debugger.Interop.MetaData @@ -575,7 +591,7 @@ namespace Debugger.Interop.MetaData
metaData.GetMethodProps(
ret.Token,
out ret.ClassToken,
pString, pStringLenght, out stringLenght, // The string to get
pString, pStringLenght, out stringLenght,
out ret.Flags,
out sigPtr,
out sigSize,
@ -614,8 +630,6 @@ namespace Debugger.Interop.MetaData @@ -614,8 +630,6 @@ namespace Debugger.Interop.MetaData
return ret;
}
// GetNameFromToken is obsolete
public uint GetNativeCallConvFromSig(Blob sigBlob)
{
uint callConv;
@ -636,8 +650,8 @@ namespace Debugger.Interop.MetaData @@ -636,8 +650,8 @@ namespace Debugger.Interop.MetaData
public uint GetParamForMethodIndex(uint methodToken, uint parameterSequence)
{
uint paramToken = 0;
metaData.GetParamForMethodIndex(methodToken, parameterSequence, ref paramToken);
uint paramToken;
metaData.GetParamForMethodIndex(methodToken, parameterSequence, out paramToken);
return paramToken;
}
@ -657,7 +671,7 @@ namespace Debugger.Interop.MetaData @@ -657,7 +671,7 @@ namespace Debugger.Interop.MetaData
ret.ParamDef,
out ret.MethodDef,
out ret.Sequence,
pString, pStringLenght, out stringLenght, // The string to get
pString, pStringLenght, out stringLenght,
out ret.Flags,
out ret.CPlusTypeFlag,
out constPtr,
@ -708,21 +722,27 @@ namespace Debugger.Interop.MetaData @@ -708,21 +722,27 @@ namespace Debugger.Interop.MetaData
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.OtherMethods = new uint[DefaultBufferSize];
uint returned;
while(true) {
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,
ret.OtherMethods, (uint)ret.OtherMethods.Length, out returned
);
if (returned < ret.OtherMethods.Length) break;
ret.OtherMethods = new uint[ret.OtherMethods.Length * BufferSizeMultiplier];
}
Array.Resize(ref ret.OtherMethods, (int)returned);
});
ret.SigBlob = new Blob(sigPtr, sigSize);
ret.DefaultValue = new Blob(defValPtr, defValSize);
@ -773,7 +793,7 @@ namespace Debugger.Interop.MetaData @@ -773,7 +793,7 @@ namespace Debugger.Interop.MetaData
Util.GetString(delegate(uint pStringLenght, out uint stringLenght, System.IntPtr pString) {
metaData.GetTypeDefProps(
ret.Token,
pString, pStringLenght, out stringLenght, // The string to get
pString, pStringLenght, out stringLenght,
out ret.Flags,
out ret.SuperClassToken
);
@ -791,7 +811,7 @@ namespace Debugger.Interop.MetaData @@ -791,7 +811,7 @@ namespace Debugger.Interop.MetaData
metaData.GetTypeRefProps(
ret.TypeRef,
out ret.ResolutionScope,
pString, pStringLenght, out stringLenght // The string to get
pString, pStringLenght, out stringLenght
);
});
@ -829,7 +849,7 @@ namespace Debugger.Interop.MetaData @@ -829,7 +849,7 @@ namespace Debugger.Interop.MetaData
public bool IsValidToken(uint token)
{
return metaData.IsValidToken(token) != 0; // TODO: Is it correct value?
return metaData.IsValidToken(token) != 0;
}
public ResolvedTypeRef ResolveTypeRef(uint typeRef, Guid riid)
@ -838,47 +858,20 @@ namespace Debugger.Interop.MetaData @@ -838,47 +858,20 @@ namespace Debugger.Interop.MetaData
metaData.ResolveTypeRef(
typeRef,
ref riid,
ref res.Scope,
ref res.TypeDef
out res.Scope,
out 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 int GetGenericParamCount(uint typeDef_methodDef)
{
return EnumGenericParams(typeDef_methodDef).Length;
}
#region Util
const int initialBufferSize = 8;
delegate void TokenEnumerator0(ref IntPtr phEnum, uint[] token, uint maxCount, out uint fetched);
uint[] EnumerateTokens(TokenEnumerator0 tokenEnumerator)
{
IntPtr enumerator = IntPtr.Zero;
uint[] buffer = new uint[initialBufferSize];
uint[] buffer = new uint[DefaultBufferSize];
uint fetched;
tokenEnumerator(ref enumerator, buffer, (uint)buffer.Length, out fetched);
if (fetched < buffer.Length) {
@ -903,7 +896,7 @@ namespace Debugger.Interop.MetaData @@ -903,7 +896,7 @@ namespace Debugger.Interop.MetaData
uint[] EnumerateTokens<T>(TokenEnumerator1<T> tokenEnumerator, T parameter)
{
IntPtr enumerator = IntPtr.Zero;
uint[] buffer = new uint[initialBufferSize];
uint[] buffer = new uint[DefaultBufferSize];
uint fetched;
tokenEnumerator(ref enumerator, parameter, buffer, (uint)buffer.Length, out fetched);
if (fetched < buffer.Length) {
@ -928,7 +921,7 @@ namespace Debugger.Interop.MetaData @@ -928,7 +921,7 @@ namespace Debugger.Interop.MetaData
uint[] EnumerateTokens<T,R>(TokenEnumerator2<T,R> tokenEnumerator, T parameter1, R parameter2)
{
IntPtr enumerator = IntPtr.Zero;
uint[] buffer = new uint[initialBufferSize];
uint[] buffer = new uint[DefaultBufferSize];
uint fetched;
tokenEnumerator(ref enumerator, parameter1, parameter2, buffer, (uint)buffer.Length, out fetched);
if (fetched < buffer.Length) {
@ -984,7 +977,7 @@ namespace Debugger.Interop.MetaData @@ -984,7 +977,7 @@ namespace Debugger.Interop.MetaData
{
public uint TypeDef;
public uint PackSize;
public COR_FIELD_OFFSET[] FieldOffset;
public COR_FIELD_OFFSET[] FieldOffsets;
public uint ClassSize;
}
@ -1018,34 +1011,6 @@ namespace Debugger.Interop.MetaData @@ -1018,34 +1011,6 @@ namespace Debugger.Interop.MetaData
public Blob SigBlob;
public uint CPlusTypeFlag;
public Blob ConstantValue;
private ClassFieldAttribute access {
get { return (ClassFieldAttribute)(Flags & (uint)ClassFieldAttribute.fdFieldAccessMask); }
}
public bool IsPrivate {
get { return access == ClassFieldAttribute.fdPrivate; }
}
public bool IsInternal {
get { return access == ClassFieldAttribute.fdAssembly; }
}
public bool IsProtected {
get { return access == ClassFieldAttribute.fdFamily; }
}
public bool IsPublic {
get { return access == ClassFieldAttribute.fdPublic; }
}
public bool IsStatic {
get { return (Flags & (uint)ClassFieldAttribute.fdStatic) != 0; }
}
public bool IsLiteral {
get { return (Flags & (uint)ClassFieldAttribute.fdLiteral) != 0; }
}
}
public class InterfaceImplProps
@ -1091,34 +1056,6 @@ namespace Debugger.Interop.MetaData @@ -1091,34 +1056,6 @@ namespace Debugger.Interop.MetaData
public Blob SigBlob;
public uint CodeRVA;
public uint ImplFlags;
private CorMethodAttr access {
get { return (CorMethodAttr)(Flags & (uint)CorMethodAttr.mdMemberAccessMask); }
}
public bool IsPrivate {
get { return access == CorMethodAttr.mdPrivate; }
}
public bool IsInternal {
get { return access == CorMethodAttr.mdAssem; }
}
public bool IsProtected {
get { return access == CorMethodAttr.mdFamily; }
}
public bool IsPublic {
get { return access == CorMethodAttr.mdPublic; }
}
public bool IsStatic {
get { return (Flags & (uint)CorMethodAttr.mdStatic) != 0; }
}
public bool HasSpecialName {
get { return (Flags & (uint)CorMethodAttr.mdSpecialName) != 0; }
}
}
public class ModuleRefProps
@ -1198,16 +1135,6 @@ namespace Debugger.Interop.MetaData @@ -1198,16 +1135,6 @@ namespace Debugger.Interop.MetaData
public string Name;
public uint Flags;
public uint SuperClassToken;
public bool IsInterface {
get { return (Flags & 0x00000020) != 0; }
}
public bool IsNested {
get {
return (Flags & 0x00000007) >= 2;
}
}
}
public class TypeRefProps

11
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/MetaData/DebugType.cs

@ -937,10 +937,10 @@ namespace Debugger.MetaData @@ -937,10 +937,10 @@ namespace Debugger.MetaData
}
genericArguments = genericArguments ?? new DebugType[] {};
if (genericArguments.Length < metaData.GetGenericParamCount(corClass.GetToken())) {
if (genericArguments.Length < metaData.EnumGenericParams(corClass.GetToken()).Length) {
throw new DebuggerException("Not enough generic arguments");
}
Array.Resize(ref genericArguments, metaData.GetGenericParamCount(corClass.GetToken()));
Array.Resize(ref genericArguments, metaData.EnumGenericParams(corClass.GetToken()).Length);
List<ICorDebugType> corGenArgs = new List<ICorDebugType>(genericArguments.Length);
foreach(DebugType genAgr in genericArguments) {
@ -1014,7 +1014,7 @@ namespace Debugger.MetaData @@ -1014,7 +1014,7 @@ namespace Debugger.MetaData
this.module = appDomain.Process.Modules[corType.GetClass().GetModule()];
this.classProps = module.MetaData.GetTypeDefProps(corType.GetClass().GetToken());
// Get the enclosing class
if (classProps.IsNested) {
if (!this.IsPublic && !this.IsNotPublic) {
uint enclosingTk = module.MetaData.GetNestedClassProps((uint)this.MetadataToken).EnclosingClass;
this.declaringType = DebugType.CreateFromTypeDefOrRef(this.DebugModule, null, enclosingTk, genericArguments.ToArray());
}
@ -1131,8 +1131,9 @@ namespace Debugger.MetaData @@ -1131,8 +1131,9 @@ namespace Debugger.MetaData
// Load fields
foreach(FieldProps field in module.MetaData.EnumFieldProps((uint)this.MetadataToken)) {
if (field.IsStatic && field.IsLiteral) continue; // Skip static literals TODO: Why?
AddMember(new DebugFieldInfo(this, field));
DebugFieldInfo fieldInfo = new DebugFieldInfo(this, field);
if (fieldInfo.IsStatic && fieldInfo.IsLiteral) continue; // Skip static literals TODO: Why?
AddMember(fieldInfo);
};
// Load methods

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Module.cs

@ -159,7 +159,7 @@ namespace Debugger @@ -159,7 +159,7 @@ namespace Debugger
{
List<DebugType> types = new List<DebugType>();
foreach(TypeDefProps typeDef in this.MetaData.EnumTypeDefProps()) {
if (this.MetaData.GetGenericParamCount(typeDef.Token) == 0) {
if (this.MetaData.EnumGenericParams(typeDef.Token).Length == 0) {
types.Add(DebugType.CreateFromTypeDefOrRef(this, null, typeDef.Token, null));
}
}

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/StackFrame.cs

@ -95,7 +95,7 @@ namespace Debugger @@ -95,7 +95,7 @@ namespace Debugger
this.frameIndex = frameIndex;
MetaDataImport metaData = thread.Process.Modules[corFunction.GetClass().GetModule()].MetaData;
int methodGenArgs = metaData.GetGenericParamCount(corFunction.GetToken());
int methodGenArgs = metaData.EnumGenericParams(corFunction.GetToken()).Length;
// Class parameters are first, then the method ones
List<ICorDebugType> corGenArgs = ((ICorDebugILFrame2)corILFrame).EnumerateTypeParameters().ToList();
// Remove method parametrs at the end

Loading…
Cancel
Save