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 3a437b9ef7..31d3385464 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj @@ -232,6 +232,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -417,5 +457,12 @@ false + + + + + + + \ No newline at end of file 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 6d7f91d658..4b7415531a 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 @@ -10,6 +10,8 @@ using System.Collections.Generic; using Debugger.Wrappers.CorDebug; using Debugger.Wrappers.MetaData; +using Mono.Cecil.Signatures; + namespace Debugger.MetaData { public enum DebugTypeKind { Array, Class, ValueType, Primitive, Pointer, Void }; @@ -357,83 +359,64 @@ namespace Debugger.MetaData return Create(module.Process, GetCorClass(module, token)); } else if (tokenType == CorTokenType.TypeSpec) { Blob typeSpecBlob = module.MetaData.GetTypeSpecFromToken(token); - Queue sig = new Queue(typeSpecBlob.GetData()); - return Create(module, sig, signatureContext); + return Create(module, typeSpecBlob.GetData(), signatureContext); } else { throw new DebuggerException("Unknown token type"); } } - public static DebugType Create(Module module, Queue sig) + public static DebugType Create(Module module, byte[] sig) { return Create(module, sig, null); } /// Type definition to use to resolve numbered generic references - public static DebugType Create(Module module, Queue sig, DebugType signatureContext) + public static DebugType Create(Module module, byte[] sig, DebugType signatureContext) { - CorElementType corType = (CorElementType)sig.Dequeue(); + SignatureReader sigReader = new SignatureReader(sig); + int start; + SigType sigType = sigReader.ReadType(sig, 0, out start); - System.Type sysType = CorElementTypeToManagedType(corType); + return Create(module, sigType, signatureContext); + } + + static DebugType Create(Module module, SigType sigType, DebugType signatureContext) + { + System.Type sysType = CorElementTypeToManagedType((CorElementType)(uint)sigType.ElementType); if (sysType != null) { return Create(module.Process, module.AppDomainID, sysType.FullName); } - if (corType == CorElementType.CLASS || corType == CorElementType.VALUETYPE) { - uint typeDefOrRef = ReadTypeDefOrRefEncoded(sig); - ICorDebugClass corClass = GetCorClass(module, typeDefOrRef); + if (sigType is CLASS) { + ICorDebugClass corClass = GetCorClass(module, ((CLASS)sigType).Type.ToUInt()); + return Create(module.Process, corClass); + } + + if (sigType is VALUETYPE) { + ICorDebugClass corClass = GetCorClass(module, ((VALUETYPE)sigType).Type.ToUInt()); return Create(module.Process, corClass); } // Numbered generic reference - if (corType == CorElementType.VAR) { - uint genArgIndex = ReadCompressedInt(sig); - + if (sigType is VAR) { if (signatureContext == null) throw new DebuggerException("Signature context is needed"); - return signatureContext.GenericArguments[(int)genArgIndex]; + return signatureContext.GenericArguments[((VAR)sigType).Index]; } - if (corType == CorElementType.GENERICINST) { - CorElementType classOrValueType = (CorElementType)sig.Dequeue(); - - uint typeDefOrRef = ReadTypeDefOrRefEncoded(sig); - ICorDebugClass corClass = GetCorClass(module, typeDefOrRef); - - uint genArgsCount = ReadCompressedInt(sig); - - ICorDebugType[] genArgs = new ICorDebugType[genArgsCount]; + if (sigType is GENERICINST) { + GENERICINST genInst = (GENERICINST)sigType; + CorElementType classOrValueType = genInst.ValueType ? CorElementType.VALUETYPE : CorElementType.CLASS; + ICorDebugClass corClass = GetCorClass(module, genInst.Type.ToUInt()); + ICorDebugType[] genArgs = new ICorDebugType[genInst.Signature.Arity]; for(int i = 0; i < genArgs.Length; i++) { - genArgs[i] = Create(module, sig, signatureContext).CorType; + genArgs[i] = Create(module, genInst.Signature.Types[i].Type, signatureContext).CorType; } ICorDebugType genInstance = corClass.CastTo().GetParameterizedType((uint)classOrValueType, genArgs); return Create(module.Process, genInstance); } - throw new NotImplementedException(); - } - - static uint ReadTypeDefOrRefEncoded(Queue sig) - { - uint i = ReadCompressedInt(sig); - uint table = i & 0x3; - uint index = i >> 2; - CorTokenType[] tables = new CorTokenType[] {CorTokenType.TypeDef, CorTokenType.TypeRef, CorTokenType.TypeSpec}; - uint token = (uint)tables[table] | index; - return token; - } - - static uint ReadCompressedInt(Queue sig) - { - if ((sig.Peek() & 0x80) == 0x00) { // 1 bit - return (uint)sig.Dequeue(); - } else if ((sig.Peek() & 0xC0) == 0x80) { // 2 bit - return (((uint)sig.Dequeue() & 0x3F) << 8) + (uint)sig.Dequeue(); - } else if ((sig.Peek() & 0xE0) == 0xC0) { // 4 bit - return (((uint)sig.Dequeue() & 0x1F) << 24) + ((uint)sig.Dequeue() << 16) + ((uint)sig.Dequeue() << 8) + (uint)sig.Dequeue(); - } else { - throw new DebuggerException("Unexpected value in signature"); - } + throw new NotImplementedException(sigType.ElementType.ToString()); } public static DebugType Create(Process process, uint? domainID, string fullTypeName) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Mono.Cecil/Mono.Cecil.Metadata/Utilities.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Mono.Cecil/Mono.Cecil.Metadata/Utilities.cs index cc6353a8b3..1acc1217ac 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Mono.Cecil/Mono.Cecil.Metadata/Utilities.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Mono.Cecil/Mono.Cecil.Metadata/Utilities.cs @@ -465,6 +465,8 @@ namespace Mono.Cecil.Metadata { throw new MetadataFormatException ("Non valid CodedIndex"); } } + + /* internal static Type GetCorrespondingTable (TokenType t) { @@ -641,5 +643,7 @@ namespace Mono.Cecil.Metadata { codedIndexCache [ci] = res; return res; } + + */ } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs index 97f8761865..226f3f0740 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs @@ -38,6 +38,17 @@ namespace Mono.Cecil.Signatures { internal sealed class SignatureReader : BaseSignatureVisitor { + byte [] m_blobData; + IDictionary m_signatures; + + public SignatureReader (byte [] blobData) + { + m_blobData = blobData; + m_signatures = new Hashtable (); + } + + /* + MetadataRoot m_root; ReflectionReader m_reflectReader; byte [] m_blobData; @@ -57,6 +68,8 @@ namespace Mono.Cecil.Signatures { m_signatures = new Hashtable (); } + + */ public FieldSig GetFieldSig (uint index) { @@ -136,6 +149,8 @@ namespace Mono.Cecil.Signatures { } return lv; } + + /* public CustomAttrib GetCustomAttrib (uint index, MethodReference ctor) { @@ -157,6 +172,8 @@ namespace Mono.Cecil.Signatures { BinaryReader br = new BinaryReader (new MemoryStream (data)); return ReadCustomAttrib (br, data, ctor, resolve); } + + */ public Signature GetMemberRefSig (TokenType tt, uint index) { @@ -179,6 +196,8 @@ namespace Mono.Cecil.Signatures { } return null; } + + /* public MarshalSig GetMarshalSig (uint index) { @@ -190,18 +209,19 @@ namespace Mono.Cecil.Signatures { } return ms; } + + */ public MethodSig GetStandAloneMethodSig (uint index) { - byte [] data = m_root.Streams.BlobHeap.Read (index); int start; - if ((data [0] & 0x5) > 0) { + if ((m_blobData [index] & 0x5) > 0) { MethodRefSig mrs = new MethodRefSig (index); - ReadMethodRefSig (mrs, data, 0, out start); + ReadMethodRefSig (mrs, m_blobData, (int)index, out start); return mrs; } else { MethodDefSig mds = new MethodDefSig (index); - ReadMethodDefSig (mds, data, 0, out start); + ReadMethodDefSig (mds, m_blobData, (int)index, out start); return mds; } } @@ -209,13 +229,13 @@ namespace Mono.Cecil.Signatures { public override void VisitMethodDefSig (MethodDefSig methodDef) { int start; - ReadMethodDefSig (methodDef, m_root.Streams.BlobHeap.Read (methodDef.BlobIndex), 0, out start); + ReadMethodDefSig (methodDef, m_blobData, (int)methodDef.BlobIndex, out start); } public override void VisitMethodRefSig (MethodRefSig methodRef) { int start; - ReadMethodRefSig (methodRef, m_root.Streams.BlobHeap.Read (methodRef.BlobIndex), 0, out start); + ReadMethodRefSig (methodRef, m_blobData, (int)methodRef.BlobIndex, out start); } public override void VisitFieldSig (FieldSig field) @@ -445,7 +465,7 @@ namespace Mono.Cecil.Signatures { return p; } - SigType ReadType (byte [] data, int pos, out int start) + public SigType ReadType (byte [] data, int pos, out int start) { start = pos; ElementType element = (ElementType) Utilities.ReadCompressedInteger (data, start, out start); @@ -576,6 +596,8 @@ namespace Mono.Cecil.Signatures { (uint) Utilities.ReadCompressedInteger (data, start, out start)); return cm; } + + /* CustomAttrib ReadCustomAttrib (int pos, MethodReference ctor, bool resolve) { @@ -957,5 +979,7 @@ namespace Mono.Cecil.Signatures { // COMPACT FRAMEWORK NOTE: Encoding.GetString (byte[]) is not supported. return Encoding.UTF8.GetString (data, pos, length); } + + */ } }