diff options
author | jfrijters <jfrijters> | 2010-06-08 15:30:48 +0400 |
---|---|---|
committer | jfrijters <jfrijters> | 2010-06-08 15:30:48 +0400 |
commit | dd2f1b550db4c46c594f03cce95b4170d5698178 (patch) | |
tree | f31a17b799e188747c92c40104d2d3f2a5fd0ebc /reflect/Impl | |
parent | 972cee12dffef4e6c378bc222de258786fccac6a (diff) |
Fixed .PDB emitter to work with .NET 4.0. Thanks to Jb Evain for the heads up on this.
Diffstat (limited to 'reflect/Impl')
-rw-r--r-- | reflect/Impl/PdbWriter.cs | 795 |
1 files changed, 769 insertions, 26 deletions
diff --git a/reflect/Impl/PdbWriter.cs b/reflect/Impl/PdbWriter.cs index c3ea0e48..aacc6c9d 100644 --- a/reflect/Impl/PdbWriter.cs +++ b/reflect/Impl/PdbWriter.cs @@ -1,5 +1,5 @@ /* - Copyright (C) 2008, 2009 Jeroen Frijters + Copyright (C) 2008-2010 Jeroen Frijters This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -29,32 +29,154 @@ using IKVM.Reflection.Emit; namespace IKVM.Reflection.Impl { - [Guid("809c652e-7396-11d2-9771-00a0c9b4d50c")] + [Guid("7dac8207-d3ae-4c75-9b67-92801a497d44")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - [CoClass(typeof(MetaDataDispenserClass))] [ComImport] - interface IMetaDataDispenser + interface IMetaDataImport { - void DefineScope( - [In] ref Guid rclsid, - [In] int dwCreateFlags, - [In] ref Guid riid, - [Out, MarshalAs(UnmanagedType.IUnknown)] out object punk); - } + void PlaceHolder_CloseEnum(); + void PlaceHolder_CountEnum(); + void PlaceHolder_ResetEnum(); + void PlaceHolder_EnumTypeDefs(); + void PlaceHolder_EnumInterfaceImpls(); + void PlaceHolder_EnumTypeRefs(); + void PlaceHolder_FindTypeDefByName(); + void PlaceHolder_GetScopeProps(); + void PlaceHolder_GetModuleFromScope(); - [Guid("e5cb7a31-7512-11d2-89ce-0080c792e5d8")] - [ComImport] - class MetaDataDispenserClass { } + void GetTypeDefProps( + int td, // [IN] TypeDef token for inquiry. + IntPtr szTypeDef, // [OUT] Put name here. + int cchTypeDef, // [IN] size of name buffer in wide chars. + IntPtr pchTypeDef, // [OUT] put size of name (wide chars) here. + IntPtr pdwTypeDefFlags, // [OUT] Put flags here. + IntPtr ptkExtends); // [OUT] Put base class TypeDef/TypeRef here. - [Guid("7dac8207-d3ae-4c75-9b67-92801a497d44")] - [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - [ComImport] - interface IMetadataImport { } + void PlaceHolder_GetInterfaceImplProps(); + void PlaceHolder_GetTypeRefProps(); + void PlaceHolder_ResolveTypeRef(); + void PlaceHolder_EnumMembers(); + void PlaceHolder_EnumMembersWithName(); + void PlaceHolder_EnumMethods(); + void PlaceHolder_EnumMethodsWithName(); + void PlaceHolder_EnumFields(); + void PlaceHolder_EnumFieldsWithName(); + void PlaceHolder_EnumParams(); + void PlaceHolder_EnumMemberRefs(); + void PlaceHolder_EnumMethodImpls(); + void PlaceHolder_EnumPermissionSets(); + void PlaceHolder_FindMember(); + void PlaceHolder_FindMethod(); + void PlaceHolder_FindField(); + void PlaceHolder_FindMemberRef(); + + void GetMethodProps( + int mb, // The method for which to get props. + IntPtr pClass, // Put method's class here. + IntPtr szMethod, // Put method's name here. + int cchMethod, // Size of szMethod buffer in wide chars. + IntPtr pchMethod, // Put actual size here + IntPtr pdwAttr, // Put flags here. + IntPtr ppvSigBlob, // [OUT] point to the blob value of meta data + IntPtr pcbSigBlob, // [OUT] actual size of signature blob + IntPtr pulCodeRVA, // [OUT] codeRVA + IntPtr pdwImplFlags); // [OUT] Impl. Flags + + void PlaceHolder_GetMemberRefProps(); + void PlaceHolder_EnumProperties(); + void PlaceHolder_EnumEvents(); + void PlaceHolder_GetEventProps(); + void PlaceHolder_EnumMethodSemantics(); + void PlaceHolder_GetMethodSemantics(); + void PlaceHolder_GetClassLayout(); + void PlaceHolder_GetFieldMarshal(); + void PlaceHolder_GetRVA(); + void PlaceHolder_GetPermissionSetProps(); + void PlaceHolder_GetSigFromToken(); + void PlaceHolder_GetModuleRefProps(); + void PlaceHolder_EnumModuleRefs(); + void PlaceHolder_GetTypeSpecFromToken(); + void PlaceHolder_GetNameFromToken(); + void PlaceHolder_EnumUnresolvedMethods(); + void PlaceHolder_GetUserString(); + void PlaceHolder_GetPinvokeMap(); + void PlaceHolder_EnumSignatures(); + void PlaceHolder_EnumTypeSpecs(); + void PlaceHolder_EnumUserStrings(); + void PlaceHolder_GetParamForMethodIndex(); + void PlaceHolder_EnumCustomAttributes(); + void PlaceHolder_GetCustomAttributeProps(); + void PlaceHolder_FindTypeRef(); + void PlaceHolder_GetMemberProps(); + void PlaceHolder_GetFieldProps(); + void PlaceHolder_GetPropertyProps(); + void PlaceHolder_GetParamProps(); + void PlaceHolder_GetCustomAttributeByName(); + void PlaceHolder_IsValidToken(); + + void GetNestedClassProps( + int tdNestedClass, // [IN] NestedClass token. + IntPtr ptdEnclosingClass); // [OUT] EnclosingClass token. + + void PlaceHolder_GetNativeCallConvFromSig(); + void PlaceHolder_IsGlobal(); + } [Guid("ba3fee4c-ecb9-4e41-83b7-183fa41cd859")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [ComImport] - interface IMetaDataEmit { } + interface IMetaDataEmit + { + void PlaceHolder_SetModuleProps(); + void PlaceHolder_Save(); + void PlaceHolder_SaveToStream(); + void PlaceHolder_GetSaveSize(); + void PlaceHolder_DefineTypeDef(); + void PlaceHolder_DefineNestedType(); + void PlaceHolder_SetHandler(); + void PlaceHolder_DefineMethod(); + void PlaceHolder_DefineMethodImpl(); + void PlaceHolder_DefineTypeRefByName(); + void PlaceHolder_DefineImportType(); + void PlaceHolder_DefineMemberRef(); + void PlaceHolder_DefineImportMember(); + void PlaceHolder_DefineEvent(); + void PlaceHolder_SetClassLayout(); + void PlaceHolder_DeleteClassLayout(); + void PlaceHolder_SetFieldMarshal(); + void PlaceHolder_DeleteFieldMarshal(); + void PlaceHolder_DefinePermissionSet(); + void PlaceHolder_SetRVA(); + void PlaceHolder_GetTokenFromSig(); + void PlaceHolder_DefineModuleRef(); + void PlaceHolder_SetParent(); + void PlaceHolder_GetTokenFromTypeSpec(); + void PlaceHolder_SaveToMemory(); + void PlaceHolder_DefineUserString(); + void PlaceHolder_DeleteToken(); + void PlaceHolder_SetMethodProps(); + void PlaceHolder_SetTypeDefProps(); + void PlaceHolder_SetEventProps(); + void PlaceHolder_SetPermissionSetProps(); + void PlaceHolder_DefinePinvokeMap(); + void PlaceHolder_SetPinvokeMap(); + void PlaceHolder_DeletePinvokeMap(); + void PlaceHolder_DefineCustomAttribute(); + void PlaceHolder_SetCustomAttributeValue(); + void PlaceHolder_DefineField(); + void PlaceHolder_DefineProperty(); + void PlaceHolder_DefineParam(); + void PlaceHolder_SetFieldProps(); + void PlaceHolder_SetPropertyProps(); + void PlaceHolder_SetParamProps(); + void PlaceHolder_DefineSecurityAttributeSet(); + void PlaceHolder_ApplyEditAndContinue(); + void PlaceHolder_TranslateSigWithScope(); + void PlaceHolder_SetMethodImplFlags(); + void PlaceHolder_SetFieldRVA(); + void PlaceHolder_Merge(); + void PlaceHolder_MergeEnd(); + } [Guid("B01FAFEB-C450-3A4D-BEEC-B4CEEC01E006")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] @@ -117,13 +239,14 @@ namespace IKVM.Reflection.Impl [ComImport] class CorSymWriterClass { } - sealed class PdbWriter : ISymbolWriterImpl + sealed class PdbWriter : ISymbolWriterImpl, IMetaDataEmit, IMetaDataImport { private readonly ModuleBuilder moduleBuilder; private ISymUnmanagedWriter2 symUnmanagedWriter; private readonly Dictionary<string, Document> documents = new Dictionary<string, Document>(); private readonly List<Method> methods = new List<Method>(); private readonly Dictionary<int, int> remap = new Dictionary<int, int>(); + private readonly Dictionary<int, int> reversemap = new Dictionary<int, int>(); private Method currentMethod; internal PdbWriter(ModuleBuilder moduleBuilder) @@ -309,14 +432,8 @@ namespace IKVM.Reflection.Impl string fileName = System.IO.Path.ChangeExtension(moduleBuilder.FullyQualifiedName, ".pdb"); // pro-actively delete the .pdb to get a meaningful IOException, instead of COMInteropException if the file can't be overwritten (or is corrupt, or who knows what) System.IO.File.Delete(fileName); - IMetaDataDispenser disp = new IMetaDataDispenser(); symUnmanagedWriter = new ISymUnmanagedWriter2(); - object emitter; - Guid CLSID_CorMetaDataRuntime = new Guid("005023ca-72b1-11d3-9fc4-00c04f79a0a3"); - Guid IID_IMetaDataEmit = typeof(IMetaDataEmit).GUID; - disp.DefineScope(ref CLSID_CorMetaDataRuntime, 0, ref IID_IMetaDataEmit, out emitter); - symUnmanagedWriter.Initialize(emitter, fileName, null, true); - Marshal.ReleaseComObject(disp); + symUnmanagedWriter.Initialize(this, fileName, null, true); } } @@ -333,6 +450,7 @@ namespace IKVM.Reflection.Impl public void RemapToken(int oldToken, int newToken) { remap.Add(oldToken, newToken); + reversemap.Add(newToken, oldToken); } public void Close() @@ -367,6 +485,7 @@ namespace IKVM.Reflection.Impl documents.Clear(); methods.Clear(); remap.Clear(); + reversemap.Clear(); } public void DefineLocalVariable(string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset) @@ -433,5 +552,629 @@ namespace IKVM.Reflection.Impl { throw new NotImplementedException(); } + + public void PlaceHolder_CloseEnum() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_CountEnum() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_ResetEnum() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumTypeDefs() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumInterfaceImpls() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumTypeRefs() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_FindTypeDefByName() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetScopeProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetModuleFromScope() + { + throw new NotImplementedException(); + } + + private static void WriteString(IntPtr ptrString, IntPtr ptrLength, string str, int length) + { + if (ptrString != IntPtr.Zero) + { + for (int i = 0; i < Math.Min(length, str.Length); i++) + { + Marshal.WriteInt16(ptrString, i, str[i]); + } + } + if (ptrLength != IntPtr.Zero) + { + Marshal.WriteInt32(ptrLength, str.Length); + } + } + + private static void WriteToken(IntPtr ptr, MemberInfo member) + { + if (ptr != IntPtr.Zero) + { + Marshal.WriteInt32(ptr, member == null ? 0 : member.MetadataToken); + } + } + + private static void WriteInt32(IntPtr ptr, int value) + { + if (ptr != IntPtr.Zero) + { + Marshal.WriteInt32(ptr, value); + } + } + + public void GetTypeDefProps( + int td, // [IN] TypeDef token for inquiry. + IntPtr szTypeDef, // [OUT] Put name here. + int cchTypeDef, // [IN] size of name buffer in wide chars. + IntPtr pchTypeDef, // [OUT] put size of name (wide chars) here. + IntPtr pdwTypeDefFlags, // [OUT] Put flags here. + IntPtr ptkExtends) // [OUT] Put base class TypeDef/TypeRef here. + { + if (td == 0) + { + // why are we being called with an invalid token? + WriteString(szTypeDef, pchTypeDef, "", cchTypeDef); + WriteInt32(pdwTypeDefFlags, 0); + WriteToken(ptkExtends, null); + } + else + { + Type type = moduleBuilder.ResolveType(td); + WriteString(szTypeDef, pchTypeDef, type.FullName, cchTypeDef); + WriteInt32(pdwTypeDefFlags, (int)type.Attributes); + WriteToken(ptkExtends, type.BaseType); + } + } + + public void PlaceHolder_GetInterfaceImplProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetTypeRefProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_ResolveTypeRef() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumMembers() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumMembersWithName() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumMethods() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumMethodsWithName() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumFields() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumFieldsWithName() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumParams() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumMemberRefs() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumMethodImpls() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumPermissionSets() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_FindMember() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_FindMethod() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_FindField() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_FindMemberRef() + { + throw new NotImplementedException(); + } + + public void GetMethodProps( + int mb, // The method for which to get props. + IntPtr pClass, // [OUT] Put method's class here. + IntPtr szMethod, // [OUT] Put method's name here. + int cchMethod, // Size of szMethod buffer in wide chars. + IntPtr pchMethod, // [OUT] Put actual size here + IntPtr pdwAttr, // [OUT] Put flags here. + IntPtr ppvSigBlob, // [OUT] point to the blob value of meta data + IntPtr pcbSigBlob, // [OUT] actual size of signature blob + IntPtr pulCodeRVA, // [OUT] codeRVA + IntPtr pdwImplFlags) // [OUT] Impl. Flags + { + if (pdwAttr != IntPtr.Zero || ppvSigBlob != IntPtr.Zero || pcbSigBlob != IntPtr.Zero || pulCodeRVA != IntPtr.Zero || pdwImplFlags != IntPtr.Zero) + { + throw new NotImplementedException(); + } + MethodBase method = moduleBuilder.ResolveMethod(reversemap[mb]); + WriteToken(pClass, method.DeclaringType); + WriteString(szMethod, pchMethod, method.Name, cchMethod); + } + + public void PlaceHolder_GetMemberRefProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumProperties() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumEvents() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetEventProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumMethodSemantics() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetMethodSemantics() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetClassLayout() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetFieldMarshal() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetRVA() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetPermissionSetProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetSigFromToken() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetModuleRefProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumModuleRefs() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetTypeSpecFromToken() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetNameFromToken() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumUnresolvedMethods() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetUserString() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetPinvokeMap() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumSignatures() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumTypeSpecs() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumUserStrings() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetParamForMethodIndex() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_EnumCustomAttributes() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetCustomAttributeProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_FindTypeRef() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetMemberProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetFieldProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetPropertyProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetParamProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetCustomAttributeByName() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_IsValidToken() + { + throw new NotImplementedException(); + } + + public void GetNestedClassProps( + int tdNestedClass, // [IN] NestedClass token. + IntPtr ptdEnclosingClass) // [OUT] EnclosingClass token. + { + Type type = moduleBuilder.ResolveType(tdNestedClass); + WriteToken(ptdEnclosingClass, type.DeclaringType); + } + + public void PlaceHolder_GetNativeCallConvFromSig() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_IsGlobal() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetModuleProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_Save() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SaveToStream() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetSaveSize() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineTypeDef() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineNestedType() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetHandler() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineMethod() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineMethodImpl() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineTypeRefByName() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineImportType() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineMemberRef() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineImportMember() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineEvent() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetClassLayout() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DeleteClassLayout() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetFieldMarshal() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DeleteFieldMarshal() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefinePermissionSet() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetRVA() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetTokenFromSig() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineModuleRef() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetParent() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_GetTokenFromTypeSpec() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SaveToMemory() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineUserString() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DeleteToken() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetMethodProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetTypeDefProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetEventProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetPermissionSetProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefinePinvokeMap() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetPinvokeMap() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DeletePinvokeMap() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineCustomAttribute() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetCustomAttributeValue() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineField() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineProperty() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineParam() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetFieldProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetPropertyProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetParamProps() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_DefineSecurityAttributeSet() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_ApplyEditAndContinue() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_TranslateSigWithScope() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetMethodImplFlags() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_SetFieldRVA() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_Merge() + { + throw new NotImplementedException(); + } + + public void PlaceHolder_MergeEnd() + { + throw new NotImplementedException(); + } } } |