From 14bf49761aef6245cc0289d4dda3b8ca0ac610d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Thu, 23 Jul 2009 19:54:15 +0000 Subject: [PATCH] Fixed signature reading for fields; Unit test for signature reading (still partially failing) git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4524 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Metadata/DebugType.cs | 17 +- .../Project/Src/Metadata/FieldInfo.cs | 4 +- .../Mono.Cecil.Signatures/SignatureReader.cs | 6 +- .../Project/Src/TestPrograms/DebugTypes.cs | 180 +++++++++++++++++- .../Project/Src/TestPrograms/Metadata.cs | 10 +- 5 files changed, 192 insertions(+), 25 deletions(-) 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 9afb3cdb35..089762790c 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 @@ -346,23 +346,16 @@ namespace Debugger.MetaData if (tokenType == CorTokenType.TypeDef || tokenType == CorTokenType.TypeRef) { return Create(module.AppDomain, GetCorClass(module, token)); } else if (tokenType == CorTokenType.TypeSpec) { - Blob typeSpecBlob = module.MetaData.GetTypeSpecFromToken(token); - return Create(module, typeSpecBlob.GetData(), declaringType); + byte[] typeSpecBlob = module.MetaData.GetTypeSpecFromToken(token).GetData(); + SignatureReader sigReader = new SignatureReader(typeSpecBlob); + int start; + SigType sigType = sigReader.ReadType(typeSpecBlob, 0, out start); + return Create(module, sigType, declaringType); } else { throw new DebuggerException("Unknown token type"); } } - /// Type definition to use to resolve numbered generic references - public static DebugType Create(Module module, byte[] sig, DebugType declaringType) - { - SignatureReader sigReader = new SignatureReader(sig); - int start; - SigType sigType = sigReader.ReadType(sig, 0, out start); - - return Create(module, sigType, declaringType); - } - internal static DebugType Create(Module module, SigType sigType, DebugType declaringType) { System.Type sysType = CorElementTypeToManagedType((CorElementType)(uint)sigType.ElementType); diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/FieldInfo.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/FieldInfo.cs index d1551e8e18..9fefed16b3 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/FieldInfo.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/FieldInfo.cs @@ -65,7 +65,9 @@ namespace Debugger.MetaData /// The type of the field public DebugType Type { get { - return DebugType.Create(this.Module, fieldProps.SigBlob.GetData(), this.DeclaringType); + SignatureReader sigReader = new SignatureReader(fieldProps.SigBlob.GetData()); + FieldSig fieldSig = sigReader.GetFieldSig(0); + return DebugType.Create(this.Module, fieldSig.Type, this.DeclaringType); } } 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 226f3f0740..709634c534 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 @@ -240,9 +240,9 @@ namespace Mono.Cecil.Signatures { public override void VisitFieldSig (FieldSig field) { - int start; - Utilities.ReadCompressedInteger (m_blobData, (int) field.BlobIndex, out start); - field.CallingConvention = m_blobData [start]; + int start = 0; + //Utilities.ReadCompressedInteger (m_blobData, (int) field.BlobIndex, out start); + //field.CallingConvention = m_blobData [start]; field.Field = (field.CallingConvention & 0x6) != 0; field.CustomMods = ReadCustomMods (m_blobData, start + 1, out start); field.Type = ReadType (m_blobData, start, out start); diff --git a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/DebugTypes.cs b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/DebugTypes.cs index 28ada2516d..91189be288 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/DebugTypes.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/DebugTypes.cs @@ -12,9 +12,24 @@ namespace Debugger.Tests.TestPrograms { public class DebugTypes { - public class MyClass + public unsafe class MyClass { + public delegate int Add(byte b1, byte b2); + public int i; + public bool b; + public char c; + public IntPtr intPtr; + public int* pInt; + public int[] intArray; + public int[,] intMultiArray; + public List intList; + public List[] intListArray; + public Point point; + public MyClass myClass; + public Add fnPtr; + + public T Foo(ref T tRef, T[] tArray) { return tRef; } } public interface MyInterface @@ -40,6 +55,7 @@ namespace Debugger.Tests.TestPrograms object nullObject = null; string nullString = null; object obj = new Object(); + MyClass myClass = new MyClass(); int loc = 42; int locByRef = 43; int* locPtr = &loc; @@ -90,6 +106,7 @@ namespace Debugger.Tests { "DebugType.ElementType" ); StartTest("DebugTypes.cs"); + ObjectDump("MyClassMemberts", process.SelectedStackFrame.GetLocalVariableValue("myClass").Type.GetMembers()); ObjectDump("LocalVariables", process.SelectedStackFrame.GetLocalVariableValues()); process.Continue(); ObjectDump("Arguments", process.SelectedStackFrame.GetArgumentValues()); @@ -107,10 +124,143 @@ namespace Debugger.Tests { mscorlib.dll (No symbols) DebugTypes.exe (Has symbols) - Break DebugTypes.cs:59,4-59,40 + Break DebugTypes.cs:75,4-75,40 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Count="20"> + + + + + null + + + + - Break DebugTypes.cs:76,4-76,40 + Break DebugTypes.cs:92,4-92,40 diff --git a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/Metadata.cs b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/Metadata.cs index 8f6ffa1ea8..beeef01058 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/Metadata.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/Metadata.cs @@ -87,7 +87,7 @@ namespace Debugger.Tests { IsPrivate="True" Module="Metadata.exe" Name="privateField" - Type="System.Int16" /> + Type="System.Int32" /> + Type="System.Int32" /> + Type="System.Int32" /> + Type="System.Int32" /> + Type="System.Int32" />