Browse Source

Initialize NR5-based type system in the debugger.

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
88959babf6
  1. 28
      src/AddIns/Debugger/Debugger.Core/AppDomain.cs
  2. 13
      src/AddIns/Debugger/Debugger.Core/Debugger.Core.csproj
  3. 6
      src/AddIns/Debugger/Debugger.Core/MetaData/DebugType.cs
  4. 12
      src/AddIns/Debugger/Debugger.Core/Module.cs
  5. 99
      src/AddIns/Debugger/Debugger.Core/Mono.Cecil/Mono.Cecil.Metadata/MetadataToken.cs
  6. 58
      src/AddIns/Debugger/Debugger.Core/Mono.Cecil/Mono.Cecil.Metadata/TokenType.cs
  7. 80
      src/AddIns/Debugger/Debugger.Core/Mono.Cecil/Mono.Cecil.Signatures/CustomAttrib.cs
  8. 93
      src/AddIns/Debugger/Debugger.Core/Mono.Cecil/Mono.Cecil.Signatures/MarshalSig.cs
  9. 520
      src/AddIns/Debugger/Debugger.Core/Mono.Cecil/Mono.Cecil.Signatures/SignatureWriter.cs
  10. 2
      src/AddIns/Debugger/Debugger.Core/Process.cs
  11. 99
      src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs

28
src/AddIns/Debugger/Debugger.Core/AppDomain.cs

@ -2,9 +2,12 @@ @@ -2,9 +2,12 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Linq;
using Debugger.Interop.CorDebug;
using Debugger.MetaData;
using System.Collections.Generic;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
namespace Debugger
{
@ -16,6 +19,31 @@ namespace Debugger @@ -16,6 +19,31 @@ namespace Debugger
internal Dictionary<ICorDebugType, DebugType> DebugTypeCache = new Dictionary<ICorDebugType, DebugType>();
ICompilation compilation;
internal void InvalidateCompilation()
{
compilation = null;
}
public ICompilation Compilation {
get {
if (compilation == null) {
List<IUnresolvedAssembly> assemblies = new List<IUnresolvedAssembly>();
foreach (var module in process.Modules) {
if (module.AppDomain == this) {
assemblies.Add(module.UnresolvedAssembly);
}
}
if (assemblies.Count == 0)
compilation = new SimpleCompilation(MinimalCorlib.Instance);
else
compilation = new SimpleCompilation(assemblies[0], assemblies.Skip(1));
}
return compilation;
}
}
public Process Process {
get { return process; }
}

13
src/AddIns/Debugger/Debugger.Core/Debugger.Core.csproj

@ -61,6 +61,7 @@ @@ -61,6 +61,7 @@
<Compile Include="ManagedCallback.cs" />
<Compile Include="ManagedCallbackProxy.cs" />
<Compile Include="ManagedCallbackSwitch.cs" />
<Compile Include="TypeSystemExtensions.cs" />
<Compile Include="MetaData\DebugConstructorInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="AppDomain.cs" />
@ -99,8 +100,6 @@ @@ -99,8 +100,6 @@
<Compile Include="Mono.Cecil\Mono.Cecil.Metadata\CodedIndex.cs" />
<Compile Include="Mono.Cecil\Mono.Cecil.Metadata\ElementType.cs" />
<Compile Include="Mono.Cecil\Mono.Cecil.Metadata\MetadataFormatException.cs" />
<Compile Include="Mono.Cecil\Mono.Cecil.Metadata\MetadataToken.cs" />
<Compile Include="Mono.Cecil\Mono.Cecil.Metadata\TokenType.cs" />
<Compile Include="Mono.Cecil\Mono.Cecil.Metadata\Utilities.cs" />
<Compile Include="Mono.Cecil\Mono.Cecil.Signatures\Array.cs" />
<Compile Include="Mono.Cecil\Mono.Cecil.Signatures\ArrayShape.cs" />
@ -184,5 +183,15 @@ @@ -184,5 +183,15 @@
<Folder Include="Mono.Cecil\Mono.Cecil.Signatures" />
<Folder Include="Tests" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Libraries\Mono.Cecil\Mono.Cecil.csproj">
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Libraries\NRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project>

6
src/AddIns/Debugger/Debugger.Core/MetaData/DebugType.cs

@ -984,11 +984,11 @@ namespace Debugger.MetaData @@ -984,11 +984,11 @@ namespace Debugger.MetaData
return CreateFromType(module.AppDomain.Mscorlib, sysType);
if (sigType is CLASS) {
return CreateFromTypeDefOrRef(module, false, ((CLASS)sigType).Type.ToUInt(), null);
return CreateFromTypeDefOrRef(module, false, ((CLASS)sigType).Type.ToUInt32(), null);
}
if (sigType is VALUETYPE) {
return CreateFromTypeDefOrRef(module, true, ((VALUETYPE)sigType).Type.ToUInt(), null);
return CreateFromTypeDefOrRef(module, true, ((VALUETYPE)sigType).Type.ToUInt32(), null);
}
// Numbered generic reference
@ -1010,7 +1010,7 @@ namespace Debugger.MetaData @@ -1010,7 +1010,7 @@ namespace Debugger.MetaData
genArgs.Add(CreateFromSignature(module, genArgSig.Type, declaringType));
}
return CreateFromTypeDefOrRef(module, genInst.ValueType, genInst.Type.ToUInt(), genArgs.ToArray());
return CreateFromTypeDefOrRef(module, genInst.ValueType, genInst.Type.ToUInt32(), genArgs.ToArray());
}
if (sigType is ARRAY) {

12
src/AddIns/Debugger/Debugger.Core/Module.cs

@ -4,12 +4,12 @@ @@ -4,12 +4,12 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Debugger.Interop;
using Debugger.Interop.CorDebug;
using Debugger.Interop.CorSym;
using Debugger.Interop.MetaData;
using Debugger.MetaData;
using ICSharpCode.NRefactory.TypeSystem;
namespace Debugger
{
@ -27,8 +27,17 @@ namespace Debugger @@ -27,8 +27,17 @@ namespace Debugger
ISymUnmanagedReader symReader;
MetaDataImport metaData;
IUnresolvedAssembly unresolvedAssembly;
internal Dictionary<string, DebugType> LoadedDebugTypes = new Dictionary<string, DebugType>();
public IUnresolvedAssembly UnresolvedAssembly {
get { return unresolvedAssembly; }
}
public IAssembly Assembly {
get { return unresolvedAssembly.Resolve(appDomain.Compilation.TypeResolveContext); }
}
public AppDomain AppDomain {
get { return appDomain; }
}
@ -185,6 +194,7 @@ namespace Debugger @@ -185,6 +194,7 @@ namespace Debugger
this.process = appDomain.Process;
this.corModule = corModule;
unresolvedAssembly = TypeSystemExtensions.LoadModule(this, corModule);
metaData = new MetaDataImport(corModule);
if (IsDynamic || IsInMemory) {

99
src/AddIns/Debugger/Debugger.Core/Mono.Cecil/Mono.Cecil.Metadata/MetadataToken.cs

@ -1,99 +0,0 @@ @@ -1,99 +0,0 @@
//
// MetadataToken.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Metadata {
public struct MetadataToken {
uint m_rid;
TokenType m_type;
public uint RID {
get { return m_rid; }
}
public TokenType TokenType {
get { return m_type; }
}
public static readonly MetadataToken Zero = new MetadataToken ((TokenType) 0, 0);
public MetadataToken (int token)
{
m_type = (TokenType) (token & 0xff000000);
m_rid = (uint) token & 0x00ffffff;
}
public MetadataToken (TokenType table, uint rid)
{
m_type = table;
m_rid = rid;
}
internal static MetadataToken FromMetadataRow (TokenType table, int rowIndex)
{
return new MetadataToken (table, (uint) rowIndex + 1);
}
public uint ToUInt ()
{
return (uint) m_type | m_rid;
}
public override int GetHashCode ()
{
return (int) ToUInt ();
}
public override bool Equals (object other)
{
if (other is MetadataToken) {
MetadataToken o = (MetadataToken) other;
return o.m_rid == m_rid && o.m_type == m_type;
}
return false;
}
public static bool operator == (MetadataToken one, MetadataToken other)
{
return one.Equals (other);
}
public static bool operator != (MetadataToken one, MetadataToken other)
{
return !one.Equals (other);
}
public override string ToString ()
{
return string.Format ("{0} [0x{1}]",
m_type, m_rid.ToString ("x4"));
}
}
}

58
src/AddIns/Debugger/Debugger.Core/Mono.Cecil/Mono.Cecil.Metadata/TokenType.cs

@ -1,58 +0,0 @@ @@ -1,58 +0,0 @@
//
// TokenType.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Metadata {
public enum TokenType : uint {
Module = 0x00000000,
TypeRef = 0x01000000,
TypeDef = 0x02000000,
Field = 0x04000000,
Method = 0x06000000,
Param = 0x08000000,
InterfaceImpl = 0x09000000,
MemberRef = 0x0a000000,
CustomAttribute = 0x0c000000,
Permission = 0x0e000000,
Signature = 0x11000000,
Event = 0x14000000,
Property = 0x17000000,
ModuleRef = 0x1a000000,
TypeSpec = 0x1b000000,
Assembly = 0x20000000,
AssemblyRef = 0x23000000,
File = 0x26000000,
ExportedType = 0x27000000,
ManifestResource = 0x28000000,
GenericParam = 0x2a000000,
MethodSpec = 0x2b000000,
String = 0x70000000,
Name = 0x71000000,
BaseType = 0x72000000
}
}

80
src/AddIns/Debugger/Debugger.Core/Mono.Cecil/Mono.Cecil.Signatures/CustomAttrib.cs

@ -1,80 +0,0 @@ @@ -1,80 +0,0 @@
//
// CustomAttrib.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Signatures {
using Mono.Cecil.Metadata;
internal sealed class CustomAttrib {
public const ushort StdProlog = 0x0001;
public MethodReference Constructor;
public ushort Prolog;
public FixedArg [] FixedArgs;
public ushort NumNamed;
public NamedArg [] NamedArgs;
public bool Read;
public CustomAttrib (MethodReference ctor)
{
Constructor = ctor;
}
public struct FixedArg {
public bool SzArray;
public uint NumElem;
public Elem [] Elems;
}
public struct Elem {
public bool Simple;
public bool String;
public bool Type;
public bool BoxedValueType;
public ElementType FieldOrPropType;
public object Value;
public TypeReference ElemType;
}
public struct NamedArg {
public bool Field;
public bool Property;
public ElementType FieldOrPropType;
public string FieldOrPropName;
public FixedArg FixedArg;
}
}
}

93
src/AddIns/Debugger/Debugger.Core/Mono.Cecil/Mono.Cecil.Signatures/MarshalSig.cs

@ -1,93 +0,0 @@ @@ -1,93 +0,0 @@
//
// MarshalSig.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Signatures {
using System;
using Mono.Cecil;
internal sealed class MarshalSig {
public NativeType NativeInstrinsic;
public IMarshalSigSpec Spec;
public MarshalSig (NativeType nt)
{
this.NativeInstrinsic = nt;
}
public interface IMarshalSigSpec {
}
public sealed class Array : IMarshalSigSpec {
public NativeType ArrayElemType;
public int ParamNum;
public int ElemMult;
public int NumElem;
public Array ()
{
this.ParamNum = 0;
this.ElemMult = 0;
this.NumElem = 0;
}
}
public sealed class CustomMarshaler : IMarshalSigSpec {
public string Guid;
public string UnmanagedType;
public string ManagedType;
public string Cookie;
}
public sealed class FixedArray : IMarshalSigSpec {
public int NumElem;
public NativeType ArrayElemType;
public FixedArray ()
{
this.NumElem = 0;
this.ArrayElemType = NativeType.NONE;
}
}
public sealed class SafeArray : IMarshalSigSpec {
public VariantType ArrayElemType;
}
public sealed class FixedSysString : IMarshalSigSpec {
public int Size;
}
}
}

520
src/AddIns/Debugger/Debugger.Core/Mono.Cecil/Mono.Cecil.Signatures/SignatureWriter.cs

@ -1,520 +0,0 @@ @@ -1,520 +0,0 @@
//
// SignatureWriter.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 - 2007 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Signatures {
using System;
using System.Text;
using Mono.Cecil;
using Mono.Cecil.Binary;
using Mono.Cecil.Metadata;
internal sealed class SignatureWriter : BaseSignatureVisitor {
MetadataWriter m_mdWriter;
MemoryBinaryWriter m_sigWriter;
public SignatureWriter (MetadataWriter mdWriter)
{
m_mdWriter = mdWriter;
m_sigWriter = new MemoryBinaryWriter ();
}
uint GetPointer ()
{
return m_mdWriter.AddBlob (m_sigWriter.ToArray ());
}
public uint AddMethodDefSig (MethodDefSig methSig)
{
return AddSignature (methSig);
}
public uint AddMethodRefSig (MethodRefSig methSig)
{
return AddSignature (methSig);
}
public uint AddPropertySig (PropertySig ps)
{
return AddSignature (ps);
}
public uint AddFieldSig (FieldSig fSig)
{
return AddSignature (fSig);
}
public uint AddLocalVarSig (LocalVarSig lvs)
{
return AddSignature (lvs);
}
uint AddSignature (Signature s)
{
m_sigWriter.Empty ();
s.Accept (this);
return GetPointer ();
}
public uint AddTypeSpec (TypeSpec ts)
{
m_sigWriter.Empty ();
Write (ts);
return GetPointer ();
}
public uint AddMethodSpec (MethodSpec ms)
{
m_sigWriter.Empty ();
Write (ms);
return GetPointer ();
}
public uint AddMarshalSig (MarshalSig ms)
{
m_sigWriter.Empty ();
Write (ms);
return GetPointer ();
}
public uint AddCustomAttribute (CustomAttrib ca, MethodReference ctor)
{
CompressCustomAttribute (ca, ctor, m_sigWriter);
return GetPointer ();
}
public byte [] CompressCustomAttribute (CustomAttrib ca, MethodReference ctor)
{
MemoryBinaryWriter writer = new MemoryBinaryWriter ();
CompressCustomAttribute (ca, ctor, writer);
return writer.ToArray ();
}
public byte [] CompressFieldSig (FieldSig field)
{
m_sigWriter.Empty ();
VisitFieldSig (field);
return m_sigWriter.ToArray ();
}
public byte [] CompressLocalVar (LocalVarSig.LocalVariable var)
{
m_sigWriter.Empty ();
Write (var);
return m_sigWriter.ToArray ();
}
void CompressCustomAttribute (CustomAttrib ca, MethodReference ctor, MemoryBinaryWriter writer)
{
m_sigWriter.Empty ();
Write (ca, ctor, writer);
}
public override void VisitMethodDefSig (MethodDefSig methodDef)
{
m_sigWriter.Write (methodDef.CallingConvention);
if (methodDef.GenericParameterCount > 0)
Write (methodDef.GenericParameterCount);
Write (methodDef.ParamCount);
Write (methodDef.RetType);
Write (methodDef.Parameters, methodDef.Sentinel);
}
public override void VisitMethodRefSig (MethodRefSig methodRef)
{
m_sigWriter.Write (methodRef.CallingConvention);
Write (methodRef.ParamCount);
Write (methodRef.RetType);
Write (methodRef.Parameters, methodRef.Sentinel);
}
public override void VisitFieldSig (FieldSig field)
{
m_sigWriter.Write (field.CallingConvention);
Write (field.CustomMods);
Write (field.Type);
}
public override void VisitPropertySig (PropertySig property)
{
m_sigWriter.Write (property.CallingConvention);
Write (property.ParamCount);
Write (property.CustomMods);
Write (property.Type);
Write (property.Parameters);
}
public override void VisitLocalVarSig (LocalVarSig localvar)
{
m_sigWriter.Write (localvar.CallingConvention);
Write (localvar.Count);
Write (localvar.LocalVariables);
}
void Write (LocalVarSig.LocalVariable [] vars)
{
foreach (LocalVarSig.LocalVariable var in vars)
Write (var);
}
void Write (LocalVarSig.LocalVariable var)
{
Write (var.CustomMods);
if ((var.Constraint & Constraint.Pinned) != 0)
Write (ElementType.Pinned);
if (var.ByRef)
Write (ElementType.ByRef);
Write (var.Type);
}
void Write (RetType retType)
{
Write (retType.CustomMods);
if (retType.Void)
Write (ElementType.Void);
else if (retType.TypedByRef)
Write (ElementType.TypedByRef);
else if (retType.ByRef) {
Write (ElementType.ByRef);
Write (retType.Type);
} else
Write (retType.Type);
}
void Write (Param [] parameters, int sentinel)
{
for (int i = 0; i < parameters.Length; i++) {
if (i == sentinel)
Write (ElementType.Sentinel);
Write (parameters [i]);
}
}
void Write (Param [] parameters)
{
foreach (Param p in parameters)
Write (p);
}
void Write (ElementType et)
{
Write ((int) et);
}
void Write (SigType t)
{
Write ((int) t.ElementType);
switch (t.ElementType) {
case ElementType.ValueType :
Write ((int) Utilities.CompressMetadataToken (
CodedIndex.TypeDefOrRef, ((VALUETYPE) t).Type));
break;
case ElementType.Class :
Write ((int) Utilities.CompressMetadataToken (
CodedIndex.TypeDefOrRef, ((CLASS) t).Type));
break;
case ElementType.Ptr :
PTR p = (PTR) t;
if (p.Void)
Write (ElementType.Void);
else {
Write (p.CustomMods);
Write (p.PtrType);
}
break;
case ElementType.FnPtr :
FNPTR fp = (FNPTR) t;
if (fp.Method is MethodRefSig)
(fp.Method as MethodRefSig).Accept (this);
else
(fp.Method as MethodDefSig).Accept (this);
break;
case ElementType.Array :
ARRAY ary = (ARRAY) t;
Write (ary.CustomMods);
ArrayShape shape = ary.Shape;
Write (ary.Type);
Write (shape.Rank);
Write (shape.NumSizes);
foreach (int size in shape.Sizes)
Write (size);
Write (shape.NumLoBounds);
foreach (int loBound in shape.LoBounds)
Write (loBound);
break;
case ElementType.SzArray :
SZARRAY sa = (SZARRAY) t;
Write (sa.CustomMods);
Write (sa.Type);
break;
case ElementType.Var :
Write (((VAR) t).Index);
break;
case ElementType.MVar :
Write (((MVAR) t).Index);
break;
case ElementType.GenericInst :
GENERICINST gi = t as GENERICINST;
Write (gi.ValueType ? ElementType.ValueType : ElementType.Class);
Write ((int) Utilities.CompressMetadataToken (
CodedIndex.TypeDefOrRef, gi.Type));
Write (gi.Signature);
break;
}
}
void Write (TypeSpec ts)
{
Write (ts.CustomMods);
Write (ts.Type);
}
void Write (MethodSpec ms)
{
Write (0x0a);
Write (ms.Signature);
}
void Write (GenericInstSignature gis)
{
Write (gis.Arity);
for (int i = 0; i < gis.Arity; i++)
Write (gis.Types [i]);
}
void Write (GenericArg arg)
{
Write (arg.CustomMods);
Write (arg.Type);
}
void Write (Param p)
{
Write (p.CustomMods);
if (p.TypedByRef)
Write (ElementType.TypedByRef);
else if (p.ByRef) {
Write (ElementType.ByRef);
Write (p.Type);
} else
Write (p.Type);
}
void Write (CustomMod [] customMods)
{
foreach (CustomMod cm in customMods)
Write (cm);
}
void Write (CustomMod cm)
{
switch (cm.CMOD) {
case CustomMod.CMODType.OPT :
Write (ElementType.CModOpt);
break;
case CustomMod.CMODType.REQD :
Write (ElementType.CModReqD);
break;
}
Write ((int) Utilities.CompressMetadataToken (
CodedIndex.TypeDefOrRef, cm.TypeDefOrRef));
}
void Write (MarshalSig ms)
{
Write ((int) ms.NativeInstrinsic);
switch (ms.NativeInstrinsic) {
case NativeType.ARRAY :
MarshalSig.Array ar = (MarshalSig.Array) ms.Spec;
Write ((int) ar.ArrayElemType);
if (ar.ParamNum != -1)
Write (ar.ParamNum);
if (ar.NumElem != -1)
Write (ar.NumElem);
if (ar.ElemMult != -1)
Write (ar.ElemMult);
break;
case NativeType.CUSTOMMARSHALER :
MarshalSig.CustomMarshaler cm = (MarshalSig.CustomMarshaler) ms.Spec;
Write (cm.Guid);
Write (cm.UnmanagedType);
Write (cm.ManagedType);
Write (cm.Cookie);
break;
case NativeType.FIXEDARRAY :
MarshalSig.FixedArray fa = (MarshalSig.FixedArray) ms.Spec;
Write (fa.NumElem);
if (fa.ArrayElemType != NativeType.NONE)
Write ((int) fa.ArrayElemType);
break;
case NativeType.SAFEARRAY :
Write ((int) ((MarshalSig.SafeArray) ms.Spec).ArrayElemType);
break;
case NativeType.FIXEDSYSSTRING :
Write (((MarshalSig.FixedSysString) ms.Spec).Size);
break;
}
}
void Write (CustomAttrib ca, MethodReference ctor, MemoryBinaryWriter writer)
{
if (ca == null)
return;
if (ca.Prolog != CustomAttrib.StdProlog)
return;
writer.Write (ca.Prolog);
for (int i = 0; i < ctor.Parameters.Count; i++)
Write (ca.FixedArgs [i], writer);
writer.Write (ca.NumNamed);
for (int i = 0; i < ca.NumNamed; i++)
Write (ca.NamedArgs [i], writer);
}
void Write (CustomAttrib.FixedArg fa, MemoryBinaryWriter writer)
{
if (fa.SzArray)
writer.Write (fa.NumElem);
foreach (CustomAttrib.Elem elem in fa.Elems)
Write (elem, writer);
}
void Write (CustomAttrib.NamedArg na, MemoryBinaryWriter writer)
{
if (na.Field)
writer.Write ((byte) 0x53);
else if (na.Property)
writer.Write ((byte) 0x54);
else
throw new MetadataFormatException ("Unknown kind of namedarg");
if (na.FixedArg.SzArray)
writer.Write ((byte) ElementType.SzArray);
if (na.FieldOrPropType == ElementType.Object)
writer.Write ((byte) ElementType.Boxed);
else
writer.Write ((byte) na.FieldOrPropType);
if (na.FieldOrPropType == ElementType.Enum)
Write (na.FixedArg.Elems [0].ElemType.FullName);
Write (na.FieldOrPropName);
Write (na.FixedArg, writer);
}
void Write (CustomAttrib.Elem elem, MemoryBinaryWriter writer) // TODO
{
if (elem.String)
elem.FieldOrPropType = ElementType.String;
else if (elem.Type)
elem.FieldOrPropType = ElementType.Type;
else if (elem.BoxedValueType)
Write (elem.FieldOrPropType);
switch (elem.FieldOrPropType) {
case ElementType.Boolean :
writer.Write ((byte) ((bool) elem.Value ? 1 : 0));
break;
case ElementType.Char :
writer.Write ((ushort) (char) elem.Value);
break;
case ElementType.R4 :
writer.Write ((float) elem.Value);
break;
case ElementType.R8 :
writer.Write ((double) elem.Value);
break;
case ElementType.I1 :
writer.Write ((sbyte) elem.Value);
break;
case ElementType.I2 :
writer.Write ((short) elem.Value);
break;
case ElementType.I4 :
writer.Write ((int) elem.Value);
break;
case ElementType.I8 :
writer.Write ((long) elem.Value);
break;
case ElementType.U1 :
writer.Write ((byte) elem.Value);
break;
case ElementType.U2 :
writer.Write ((ushort) elem.Value);
break;
case ElementType.U4 :
writer.Write ((uint) elem.Value);
break;
case ElementType.U8 :
writer.Write ((long) elem.Value);
break;
case ElementType.String :
case ElementType.Type :
string s = elem.Value as string;
if (s == null)
writer.Write ((byte) 0xff);
else if (s.Length == 0)
writer.Write ((byte) 0x00);
else
Write (s);
break;
case ElementType.Object :
if (elem.Value != null)
throw new NotSupportedException ("Unknown state");
writer.Write ((byte) 0xff);
break;
default :
throw new NotImplementedException ("WriteElem " + elem.FieldOrPropType.ToString ());
}
}
void Write (string s)
{
byte [] str = Encoding.UTF8.GetBytes (s);
Write (str.Length);
m_sigWriter.Write (str);
}
void Write (int i)
{
Utilities.WriteCompressedInteger (m_sigWriter, i);
}
}
}

2
src/AddIns/Debugger/Debugger.Core/Process.cs

@ -624,6 +624,8 @@ namespace Debugger @@ -624,6 +624,8 @@ namespace Debugger
b.SetBreakpoint(module);
}
module.AppDomain.InvalidateCompilation();
if (this.BreakInMain) {
if (module.SymReader == null) return; // No symbols

99
src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs

@ -0,0 +1,99 @@ @@ -0,0 +1,99 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Debugger.Interop.CorDebug;
using Debugger.MetaData;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using Mono.Cecil.Metadata;
namespace Debugger
{
/// <summary>
/// Cecil-based metadata loader.
/// </summary>
public static class TypeSystemExtensions
{
static ConditionalWeakTable<IUnresolvedAssembly, ModuleMetadataInfo> weakTable = new ConditionalWeakTable<IUnresolvedAssembly, ModuleMetadataInfo>();
class ModuleMetadataInfo
{
public readonly Module Module;
public Dictionary<IUnresolvedTypeDefinition, uint> MetadataTokens = new Dictionary<IUnresolvedTypeDefinition, uint>();
public ModuleMetadataInfo(Module module)
{
this.Module = module;
}
}
internal static IUnresolvedAssembly LoadModule(Module module, ICorDebugModule corModule)
{
string name = corModule.GetName();
if (corModule.IsDynamic() == 1 || corModule.IsInMemory() == 1)
return new DefaultUnresolvedAssembly(name);
CecilLoader loader = new CecilLoader(true);
loader.IncludeInternalMembers = true;
var asm = loader.LoadAssemblyFile(name);
var moduleMetadataInfo = new ModuleMetadataInfo(module);
foreach (var typeDef in asm.GetAllTypeDefinitions()) {
var cecilTypeDef = loader.GetCecilObject(typeDef);
moduleMetadataInfo.MetadataTokens[typeDef] = cecilTypeDef.MetadataToken.ToUInt32();
}
weakTable.Add(asm, moduleMetadataInfo);
return asm;
}
static ModuleMetadataInfo GetInfo(IAssembly assembly)
{
ModuleMetadataInfo info;
if (!weakTable.TryGetValue(assembly.UnresolvedAssembly, out info))
throw new ArgumentException("The assembly was not from the debugger type system");
return info;
}
public static Module GetModule(this IAssembly assembly)
{
return GetInfo(assembly).Module;
}
public static ICorDebugType ToCorDebug(this IType type)
{
switch (type.Kind) {
case TypeKind.Class:
case TypeKind.Interface:
case TypeKind.Struct:
case TypeKind.Delegate:
case TypeKind.Enum:
case TypeKind.Module:
case TypeKind.Void:
return ConvertTypeDefOrParameterizedType(type);
case TypeKind.Array:
case TypeKind.Pointer:
case TypeKind.ByReference:
throw new NotImplementedException();
default:
throw new System.Exception("Invalid value for TypeKind");
}
}
static ICorDebugType ConvertTypeDefOrParameterizedType(IType type)
{
ITypeDefinition typeDef = type.GetDefinition();
var info = GetInfo(typeDef.ParentAssembly);
uint token = info.MetadataTokens[typeDef.Parts[0]];
ICorDebugClass corClass = info.Module.CorModule.GetClassFromToken(token);
List<ICorDebugType> corGenArgs = new List<ICorDebugType>();
ParameterizedType pt = type as ParameterizedType;
if (pt != null) {
foreach (var typeArg in pt.TypeArguments) {
corGenArgs.Add(typeArg.ToCorDebug());
}
}
return ((ICorDebugClass2)corClass).GetParameterizedType((uint)(type.IsReferenceType == false ? CorElementType.VALUETYPE : CorElementType.CLASS), corGenArgs.ToArray());
}
}
}
Loading…
Cancel
Save