Browse Source

Initialize the debugger type system asynchronously.

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
3b2fd56d92
  1. 5
      src/AddIns/Debugger/Debugger.Core/Debugger.Core.csproj
  2. 9
      src/AddIns/Debugger/Debugger.Core/Module.cs
  3. 37
      src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs

5
src/AddIns/Debugger/Debugger.Core/Debugger.Core.csproj

@ -36,8 +36,9 @@
<IsWebBootstrapper>true</IsWebBootstrapper> <IsWebBootstrapper>true</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile> <TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>

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

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Debugger.Interop; using Debugger.Interop;
using Debugger.Interop.CorDebug; using Debugger.Interop.CorDebug;
using Debugger.Interop.CorSym; using Debugger.Interop.CorSym;
@ -27,15 +28,15 @@ namespace Debugger
ISymUnmanagedReader symReader; ISymUnmanagedReader symReader;
MetaDataImport metaData; MetaDataImport metaData;
IUnresolvedAssembly unresolvedAssembly; Task<IUnresolvedAssembly> unresolvedAssembly;
internal Dictionary<string, DebugType> LoadedDebugTypes = new Dictionary<string, DebugType>(); internal Dictionary<string, DebugType> LoadedDebugTypes = new Dictionary<string, DebugType>();
public IUnresolvedAssembly UnresolvedAssembly { public IUnresolvedAssembly UnresolvedAssembly {
get { return unresolvedAssembly; } get { return unresolvedAssembly.Result; }
} }
public IAssembly Assembly { public IAssembly Assembly {
get { return unresolvedAssembly.Resolve(appDomain.Compilation.TypeResolveContext); } get { return this.UnresolvedAssembly.Resolve(appDomain.Compilation.TypeResolveContext); }
} }
public AppDomain AppDomain { public AppDomain AppDomain {
@ -194,7 +195,7 @@ namespace Debugger
this.process = appDomain.Process; this.process = appDomain.Process;
this.corModule = corModule; this.corModule = corModule;
unresolvedAssembly = TypeSystemExtensions.LoadModule(this, corModule); unresolvedAssembly = TypeSystemExtensions.LoadModuleAsync(this, corModule);
metaData = new MetaDataImport(corModule); metaData = new MetaDataImport(corModule);
if (IsDynamic || IsInMemory) { if (IsDynamic || IsInMemory) {

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

@ -4,12 +4,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Debugger.Interop.CorDebug; using Debugger.Interop.CorDebug;
using Debugger.MetaData; using Debugger.MetaData;
using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation; using ICSharpCode.NRefactory.TypeSystem.Implementation;
using Mono.Cecil;
using Mono.Cecil.Metadata; using Mono.Cecil.Metadata;
namespace Debugger namespace Debugger
@ -33,11 +35,13 @@ namespace Debugger
} }
} }
internal static IUnresolvedAssembly LoadModule(Module module, ICorDebugModule corModule) internal static Task<IUnresolvedAssembly> LoadModuleAsync(Module module, ICorDebugModule corModule)
{ {
string name = corModule.GetName(); string name = corModule.GetName();
if (corModule.IsDynamic() == 1 || corModule.IsInMemory() == 1) if (corModule.IsDynamic() == 1 || corModule.IsInMemory() == 1)
return new DefaultUnresolvedAssembly(name); return Task.FromResult<IUnresolvedAssembly>(new DefaultUnresolvedAssembly(name));
return Task.Run(
delegate {
CecilLoader loader = new CecilLoader(true); CecilLoader loader = new CecilLoader(true);
loader.IncludeInternalMembers = true; loader.IncludeInternalMembers = true;
var asm = loader.LoadAssemblyFile(name); var asm = loader.LoadAssemblyFile(name);
@ -48,6 +52,7 @@ namespace Debugger
} }
weakTable.Add(asm, moduleMetadataInfo); weakTable.Add(asm, moduleMetadataInfo);
return asm; return asm;
});
} }
static ModuleMetadataInfo GetInfo(IAssembly assembly) static ModuleMetadataInfo GetInfo(IAssembly assembly)
@ -66,6 +71,12 @@ namespace Debugger
#region IType -> ICorDebugType #region IType -> ICorDebugType
public static ICorDebugType ToCorDebug(this IType type) public static ICorDebugType ToCorDebug(this IType type)
{
AppDomain appDomain;
return ToCorDebug(type, out appDomain);
}
static ICorDebugType ToCorDebug(IType type, out AppDomain appDomain)
{ {
switch (type.Kind) { switch (type.Kind) {
case TypeKind.Class: case TypeKind.Class:
@ -75,19 +86,33 @@ namespace Debugger
case TypeKind.Enum: case TypeKind.Enum:
case TypeKind.Module: case TypeKind.Module:
case TypeKind.Void: case TypeKind.Void:
return ConvertTypeDefOrParameterizedType(type); return ConvertTypeDefOrParameterizedType(type, out appDomain);
case TypeKind.Array: case TypeKind.Array:
{
var arrayType = (ArrayType)type;
var elementType = ToCorDebug(arrayType.ElementType, out appDomain);
return appDomain.CorAppDomain2.GetArrayOrPointerType(
(uint)(arrayType.Dimensions == 1 ? CorElementType.SZARRAY : CorElementType.ARRAY),
(uint)arrayType.Dimensions, elementType);
}
case TypeKind.Pointer: case TypeKind.Pointer:
case TypeKind.ByReference: case TypeKind.ByReference:
throw new NotImplementedException(); {
var pointerType = (TypeWithElementType)type;
var elementType = ToCorDebug(pointerType.ElementType, out appDomain);
return appDomain.CorAppDomain2.GetArrayOrPointerType(
(uint)(type.Kind == TypeKind.Pointer ? CorElementType.PTR : CorElementType.BYREF),
0, elementType);
}
default: default:
throw new System.Exception("Invalid value for TypeKind"); throw new System.Exception("Invalid value for TypeKind");
} }
} }
static ICorDebugType ConvertTypeDefOrParameterizedType(IType type) static ICorDebugType ConvertTypeDefOrParameterizedType(IType type, out AppDomain appDomain)
{ {
ITypeDefinition typeDef = type.GetDefinition(); ITypeDefinition typeDef = type.GetDefinition();
appDomain = GetAppDomain(typeDef.Compilation);
var info = GetInfo(typeDef.ParentAssembly); var info = GetInfo(typeDef.ParentAssembly);
uint token = info.MetadataTokens[typeDef.Parts[0]]; uint token = info.MetadataTokens[typeDef.Parts[0]];
ICorDebugClass corClass = info.Module.CorModule.GetClassFromToken(token); ICorDebugClass corClass = info.Module.CorModule.GetClassFromToken(token);

Loading…
Cancel
Save