Esempio n. 1
0
        public IEnumerable <ILLocalVariable> GetLocalVariables(IMethod method)
        {
            string id   = IdStringProvider.GetIdString(method.MemberDefinition);
            var    file = GetSymbols(method);

            if (file == null || !file.DebugSymbols.ContainsKey(id))
            {
                return(Enumerable.Empty <ILLocalVariable>());
            }

            var symbols = file.DebugSymbols[id];

            var context = new SimpleTypeResolveContext(method);
            var loader  = new CecilLoader();

            return(symbols.LocalVariables.Where(v => v.OriginalVariable != null).Select(
                       v => new Debugger.ILLocalVariable()
            {
                Index = v.OriginalVariable.Index,
                Type = loader.ReadTypeReference(v.Type).Resolve(context),
                Name = v.Name,
                IsCompilerGenerated = false,
                ILRanges = new [] { new ILRange(0, int.MaxValue) }
            }));
        }
Esempio n. 2
0
        public Debugger.SequencePoint GetSequencePoint(IMethod method, int iloffset)
        {
            string id   = IdStringProvider.GetIdString(method.MemberDefinition);
            var    file = GetSymbols(method);

            if (file == null || !file.DebugSymbols.ContainsKey(id))
            {
                return(null);
            }
            var symbols = file.DebugSymbols[id];
            var seqs    = symbols.SequencePoints;
            var seq     = seqs.FirstOrDefault(p => p.ILRanges.Any(r => r.From <= iloffset && iloffset < r.To));

            if (seq == null)
            {
                seq = seqs.FirstOrDefault(p => iloffset <= p.ILOffset);
            }
            if (seq != null)
            {
                // Use the widest sequence point containing the IL offset
                iloffset = seq.ILOffset;
                seq      = seqs.Where(p => p.ILRanges.Any(r => r.From <= iloffset && iloffset < r.To))
                           .OrderByDescending(p => p.ILRanges.Last().To - p.ILRanges.First().From)
                           .FirstOrDefault();
                return(seq.ToDebugger(symbols, file.FileName));
            }
            return(null);
        }
        public bool NavigateToEntity(IEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            // Get the underlying entity for generic instance members
            if (entity is IMember)
            {
                entity = ((IMember)entity).MemberDefinition;
            }

            ITypeDefinition declaringType = (entity as ITypeDefinition) ?? entity.DeclaringTypeDefinition;

            if (declaringType == null)
            {
                return(false);
            }
            // get the top-level type
            while (declaringType.DeclaringTypeDefinition != null)
            {
                declaringType = declaringType.DeclaringTypeDefinition;
            }

            FileName assemblyLocation = declaringType.ParentAssembly.GetRuntimeAssemblyLocation();

            if (assemblyLocation != null && File.Exists(assemblyLocation))
            {
                NavigateTo(assemblyLocation, declaringType.ReflectionName, IdStringProvider.GetIdString(entity));
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
        static void Check(IEntity entity, ITypeResolveContext context, HashSet <string> idStrings)
        {
            string id = IdStringProvider.GetIdString(entity);

            if (!idStrings.Add(id))
            {
                throw new InvalidOperationException("Duplicate ID string " + id);
            }
            IEntity resolvedEntity = IdStringProvider.FindEntity(id, context);

            if (resolvedEntity != entity)
            {
                throw new InvalidOperationException(id);
            }
        }
Esempio n. 5
0
        public IEnumerable <ILRange> GetIgnoredILRanges(IMethod method)
        {
            string id   = IdStringProvider.GetIdString(method.MemberDefinition);
            var    file = GetSymbols(method);

            if (file == null || !file.DebugSymbols.ContainsKey(id))
            {
                return new ILRange[] { }
            }
            ;

            var symbols  = file.DebugSymbols[id];
            int codesize = symbols.CecilMethod.Body.CodeSize;
            var inv      = ICSharpCode.Decompiler.ILAst.ILRange.Invert(symbols.SequencePoints.SelectMany(s => s.ILRanges), codesize);

            return(inv.Select(r => new ILRange(r.From, r.To)));
        }
Esempio n. 6
0
#pragma warning disable 618
        public static XmlNode GetMonodocDocumentation(this IEntity member)
        {
            if (member.SymbolKind == SymbolKind.TypeDefinition)
            {
                var helpXml = HelpService.HelpTree != null?HelpService.HelpTree.GetHelpXml(IdStringProvider.GetIdString(member)) : null;

                if (helpXml == null)
                {
                    return(null);
                }
                return(helpXml.SelectSingleNode("/Type/Docs"));
            }

            var declaringXml = HelpService.HelpTree != null && member.DeclaringTypeDefinition != null?HelpService.HelpTree.GetHelpXml(member.DeclaringTypeDefinition.GetIdString()) : null;

            if (declaringXml == null)
            {
                return(null);
            }

            switch (member.SymbolKind)
            {
            case SymbolKind.Method:
            {
                var     nodes = declaringXml.SelectNodes("/Type/Members/Member[@MemberName='" + member.Name + "']");
                XmlNode node  = nodes.Count == 1 ? nodes [0] : FindMatch((IMethod)member, nodes);
                if (node != null)
                {
                    System.Xml.XmlNode result = node.SelectSingleNode("Docs");
                    return(result);
                }
                return(null);
            }

            case SymbolKind.Constructor:
            {
                var     nodes = declaringXml.SelectNodes("/Type/Members/Member[@MemberName='.ctor']");
                XmlNode node  = nodes.Count == 1 ? nodes [0] : FindMatch((IMethod)member, nodes);
                if (node != null)
                {
                    System.Xml.XmlNode result = node.SelectSingleNode("Docs");
                    return(result);
                }
                return(null);
            }

            default:
                return(declaringXml.SelectSingleNode("/Type/Members/Member[@MemberName='" + member.Name + "']/Docs"));
            }
        }
        public static void OpenInILSpy(IEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            // Get the underlying entity for generic instance members
            if (entity is IMember)
            {
                entity = ((IMember)entity).MemberDefinition;
            }

            // Try to find the assembly which contains the resolved type
            var assemblyLocation = entity.ParentAssembly.GetRuntimeAssemblyLocation();

            if (string.IsNullOrEmpty(assemblyLocation))
            {
                MessageService.ShowWarning("ILSpy AddIn: Could not determine the assembly location for " + entity.ParentAssembly.AssemblyName + ".");
                return;
            }

            string ilspyPath = GetILSpyExeFullPathInteractive();

            if (string.IsNullOrEmpty(ilspyPath))
            {
                return;
            }

            string commandLine = "/singleInstance \"" + assemblyLocation + "\" \"/navigateTo:" + IdStringProvider.GetIdString(entity) + "\"";

            LoggingService.Debug(ilspyPath + " " + commandLine);
            Process.Start(ilspyPath, commandLine);
        }