Example #1
0
        internal StackFrame(Thread thread, ICorDebugILFrame corILFrame, uint chainIndex, uint frameIndex)
        {
            this.process                = thread.Process;
            this.thread                 = thread;
            this.appDomain              = process.AppDomains[corILFrame.GetFunction().GetClass().GetModule().GetAssembly().GetAppDomain()];
            this.corILFrame             = corILFrame;
            this.corILFramePauseSession = process.PauseSession;
            this.corFunction            = corILFrame.GetFunction();
            this.chainIndex             = chainIndex;
            this.frameIndex             = frameIndex;

            MetaDataImport metaData      = thread.Process.Modules[corFunction.GetClass().GetModule()].MetaData;
            int            methodGenArgs = metaData.EnumGenericParams(corFunction.GetToken()).Length;
            // Class parameters are first, then the method ones
            List <ICorDebugType> corGenArgs = ((ICorDebugILFrame2)corILFrame).EnumerateTypeParameters().ToList();

            // Remove method parametrs at the end
            corGenArgs.RemoveRange(corGenArgs.Count - methodGenArgs, methodGenArgs);
            List <DebugType> genArgs = new List <DebugType>(corGenArgs.Count);

            foreach (ICorDebugType corGenArg in corGenArgs)
            {
                genArgs.Add(DebugType.CreateFromCorType(this.AppDomain, corGenArg));
            }

            DebugType debugType = DebugType.CreateFromCorClass(
                this.AppDomain,
                null,
                corFunction.GetClass(),
                genArgs.ToArray()
                );

            this.methodInfo = (DebugMethodInfo)debugType.GetMember(corFunction.GetToken());
        }
Example #2
0
        internal StackFrame(Thread thread, ICorDebugILFrame corILFrame, uint chainIndex, uint frameIndex)
        {
            this.process = thread.Process;
            this.thread = thread;
            this.appDomain = process.AppDomains[corILFrame.GetFunction().GetClass().GetModule().GetAssembly().GetAppDomain()];
            this.corILFrame = corILFrame;
            this.corILFramePauseSession = process.PauseSession;
            this.corFunction = corILFrame.GetFunction();
            this.chainIndex = chainIndex;
            this.frameIndex = frameIndex;

            MetaDataImport metaData = thread.Process.Modules[corFunction.GetClass().GetModule()].MetaData;
            int methodGenArgs = metaData.EnumGenericParams(corFunction.GetToken()).Length;
            // Class parameters are first, then the method ones
            List<ICorDebugType> corGenArgs = ((ICorDebugILFrame2)corILFrame).EnumerateTypeParameters().ToList();
            // Remove method parametrs at the end
            corGenArgs.RemoveRange(corGenArgs.Count - methodGenArgs, methodGenArgs);
            List<DebugType> genArgs = new List<DebugType>(corGenArgs.Count);
            foreach(ICorDebugType corGenArg in corGenArgs) {
                genArgs.Add(DebugType.CreateFromCorType(this.AppDomain, corGenArg));
            }

            DebugType debugType = DebugType.CreateFromCorClass(
                this.AppDomain,
                null,
                corFunction.GetClass(),
                genArgs.ToArray()
            );
            this.methodInfo = (DebugMethodInfo)debugType.GetMember(corFunction.GetToken());
        }
        public static IMethod Import(this ICompilation compilation, ICorDebugFunction corFunction)
        {
            Module module = compilation.GetAppDomain().Process.GetModule(corFunction.GetModule());

            if (module.IsDynamic || module.IsInMemory)
            {
                return(module.Assembly.GetTypeDefinition("", "UnknownDynamicType").Methods.First());
            }
            var  info             = GetInfo(module.Assembly);
            uint functionToken    = corFunction.GetToken();
            var  unresolvedMethod = info.GetMethodFromToken(functionToken);

            if (unresolvedMethod == null)
            {
                // The type containing this function wasn't loaded yet
                uint classToken = corFunction.GetClass().GetToken();
                var  definition = ToTypeDefinitionReference(module, classToken).Resolve(new SimpleTypeResolveContext(module.Assembly)).GetDefinition();
                if (definition == null)
                {
                    throw new InvalidOperationException("Could not find class for token " + classToken);
                }
                definition.Methods.ToList();                 // enforce loading the methods so that they get added to the dictionary
                unresolvedMethod = info.GetMethodFromToken(functionToken);
                if (unresolvedMethod == null)
                {
                    throw new InvalidOperationException("Could not find function with token " + functionToken);
                }
            }
            return(unresolvedMethod.Resolve(new SimpleTypeResolveContext(module.Assembly)));
        }
		public static IMethod Import(this ICompilation compilation, ICorDebugFunction corFunction)
		{
			Module module = compilation.GetAppDomain().Process.GetModule(corFunction.GetModule());
			if (module.IsDynamic || module.IsInMemory) {
				return module.Assembly.GetTypeDefinition("", "UnknownDynamicType").Methods.First();
			}
			var info = GetInfo(module.Assembly);
			uint functionToken = corFunction.GetToken();
			var unresolvedMethod = info.GetMethodFromToken(functionToken);
			if (unresolvedMethod == null) {
				// The type containing this function wasn't loaded yet
				uint classToken = corFunction.GetClass().GetToken();
				var definition = ToTypeDefinitionReference(module, classToken).Resolve(new SimpleTypeResolveContext(module.Assembly)).GetDefinition();
				if (definition == null)
					throw new InvalidOperationException("Could not find class for token " + classToken);
				definition.Methods.ToList(); // enforce loading the methods so that they get added to the dictionary
				unresolvedMethod = info.GetMethodFromToken(functionToken);
				if (unresolvedMethod == null)
					throw new InvalidOperationException("Could not find function with token " + functionToken);
			}
			return unresolvedMethod.Resolve(new SimpleTypeResolveContext(module.Assembly));
		}