Esempio n. 1
0
        public MethodInfo(AssemblyInfo assembly, MethodDefinitionHandle methodDefHandle, int token, SourceFile source, TypeInfo type, MetadataReader asmMetadataReader, MetadataReader pdbMetadataReader)
        {
            this.IsAsync           = -1;
            this.Assembly          = assembly;
            this.methodDef         = asmMetadataReader.GetMethodDefinition(methodDefHandle);
            this.DebugInformation  = pdbMetadataReader.GetMethodDebugInformation(methodDefHandle.ToDebugInformationHandle());
            this.source            = source;
            this.Token             = token;
            this.methodDefHandle   = methodDefHandle;
            this.Name              = asmMetadataReader.GetString(methodDef.Name);
            this.pdbMetadataReader = pdbMetadataReader;
            this.IsEnCMethod       = false;
            this.TypeInfo          = type;
            if (!DebugInformation.SequencePointsBlob.IsNil)
            {
                var           sps   = DebugInformation.GetSequencePoints();
                SequencePoint start = sps.First();
                SequencePoint end   = sps.First();

                foreach (SequencePoint sp in sps)
                {
                    if (sp.StartLine < start.StartLine)
                    {
                        start = sp;
                    }
                    else if (sp.StartLine == start.StartLine && sp.StartColumn < start.StartColumn)
                    {
                        start = sp;
                    }

                    if (sp.EndLine > end.EndLine)
                    {
                        end = sp;
                    }
                    else if (sp.EndLine == end.EndLine && sp.EndColumn > end.EndColumn)
                    {
                        end = sp;
                    }
                }

                StartLocation = new SourceLocation(this, start);
                EndLocation   = new SourceLocation(this, end);

                foreach (var cattr in methodDef.GetCustomAttributes())
                {
                    var ctorHandle = asmMetadataReader.GetCustomAttribute(cattr).Constructor;
                    if (ctorHandle.Kind == HandleKind.MemberReference)
                    {
                        var container = asmMetadataReader.GetMemberReference((MemberReferenceHandle)ctorHandle).Parent;
                        var name      = asmMetadataReader.GetString(asmMetadataReader.GetTypeReference((TypeReferenceHandle)container).Name);
                        if (name == "DebuggerHiddenAttribute")
                        {
                            this.IsHiddenFromDebugger = true;
                            break;
                        }
                    }
                }
            }
            localScopes = pdbMetadataReader.GetLocalScopes(methodDefHandle);
        }
Esempio n. 2
0
        private ISymbolScope CreateSymbolScope(MetadataReader pdb, LocalScopeHandleCollection scopes, SymbolMethod owner, int methodEndOffset)
        {
            SymbolScope result = null;

            var scope = scopes.GetEnumerator();

            while (true)
            {
                scope.MoveNext();

                if (scope.Current.IsNil)
                {
                    break;
                }

                var currentScope = pdb.GetLocalScope(scope.Current);

                var current = new SymbolScope(owner, null, currentScope.StartOffset, currentScope.EndOffset);

                if (result == null)
                {
                    result = current;
                }

                AddLocalVars(pdb, current, currentScope.GetLocalVariables());

                AddChildScopes(pdb, current, currentScope.GetChildren(), owner);
            }

            return(result);
        }
Esempio n. 3
0
        private static IEnumerable <LocalVariableHandleCollection> GetLocalVariableHandles(MetadataReader metadataReader, MethodDebugInformationHandle methodDebugHandle)
        {
            LocalScopeHandleCollection scopes = metadataReader.GetLocalScopes(methodDebugHandle);

            foreach (LocalScopeHandle scope in scopes)
            {
                LocalVariableHandleCollection localVariables = metadataReader.GetLocalScope(scope).GetLocalVariables();
                yield return(localVariables);
            }
        }
Esempio n. 4
0
        private static bool GetLocalsInfoForMethod(string assemblyPath, int methodToken, out List <LocalVarInfo> locals)
        {
            locals = null;

            OpenedReader openedReader = GetReader(assemblyPath, isFileLayout: true, peStream: null, pdbStream: null);

            if (openedReader == null)
            {
                return(false);
            }

            using (openedReader)
            {
                try
                {
                    Handle handle = MetadataTokens.Handle(methodToken);
                    if (handle.Kind != HandleKind.MethodDefinition)
                    {
                        return(false);
                    }

                    locals = new List <LocalVarInfo>();

                    MethodDebugInformationHandle methodDebugHandle =
                        ((MethodDefinitionHandle)handle).ToDebugInformationHandle();
                    LocalScopeHandleCollection localScopes = openedReader.Reader.GetLocalScopes(methodDebugHandle);
                    foreach (LocalScopeHandle scopeHandle in localScopes)
                    {
                        LocalScope scope = openedReader.Reader.GetLocalScope(scopeHandle);
                        LocalVariableHandleCollection localVars = scope.GetLocalVariables();
                        foreach (LocalVariableHandle varHandle in localVars)
                        {
                            LocalVariable localVar = openedReader.Reader.GetLocalVariable(varHandle);
                            if (localVar.Attributes == LocalVariableAttributes.DebuggerHidden)
                            {
                                continue;
                            }
                            LocalVarInfo info = new LocalVarInfo();
                            info.startOffset = scope.StartOffset;
                            info.endOffset   = scope.EndOffset;
                            info.name        = openedReader.Reader.GetString(localVar.Name);
                            locals.Add(info);
                        }
                    }
                }
                catch
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Helper method to return local variable name for given local index and IL offset.
        /// </summary>
        /// <param name="assemblyFileName">file name of the assembly</param>
        /// <param name="methodToken">method token</param>
        /// <param name="localIndex">local variable index</param>
        /// <param name="localVarName">local variable name return</param>
        /// <returns>true if name has been found</returns>
        public static bool GetLocalVariableByIndex(string assemblyFileName, int methodToken, int localIndex, out string localVarName)
        {
            MetadataReader peReader, pdbReader;

            localVarName = null;

            try
            {
                if (!GetReaders(assemblyFileName, out peReader, out pdbReader))
                {
                    return(false);
                }

                Handle handle = MetadataTokens.Handle(methodToken);
                if (handle.Kind != HandleKind.MethodDefinition)
                {
                    return(false);
                }

                MethodDebugInformationHandle methodDebugHandle = ((MethodDefinitionHandle)handle).ToDebugInformationHandle();
                LocalScopeHandleCollection   localScopes       = pdbReader.GetLocalScopes(methodDebugHandle);
                foreach (LocalScopeHandle scopeHandle in localScopes)
                {
                    LocalScope scope = pdbReader.GetLocalScope(scopeHandle);
                    LocalVariableHandleCollection localVars = scope.GetLocalVariables();
                    foreach (LocalVariableHandle varHandle in localVars)
                    {
                        LocalVariable localVar = pdbReader.GetLocalVariable(varHandle);
                        if (localVar.Index == localIndex)
                        {
                            if (localVar.Attributes == LocalVariableAttributes.DebuggerHidden)
                            {
                                return(false);
                            }
                            localVarName = pdbReader.GetString(localVar.Name);
                            return(true);
                        }
                    }
                }
                return(false);
            }
            finally
            {
                peReader  = null;
                pdbReader = null;
            }
        }
Esempio n. 6
0
        internal static bool GetLocalVariableAndScopeByIndex(IntPtr symbolReaderHandle, int methodToken, int localIndex, out string localVarName, out int ilStartOffset, out int ilEndOffset)
        {
            Debug.Assert(symbolReaderHandle != IntPtr.Zero);
            localVarName  = null;
            ilStartOffset = 0;
            ilEndOffset   = 0;

            GCHandle       gch    = GCHandle.FromIntPtr(symbolReaderHandle);
            MetadataReader reader = ((OpenedReader)gch.Target).Reader;

            try
            {
                Handle handle = MetadataTokens.Handle(methodToken);
                if (handle.Kind != HandleKind.MethodDefinition)
                {
                    return(false);
                }

                MethodDebugInformationHandle methodDebugHandle = ((MethodDefinitionHandle)handle).ToDebugInformationHandle();
                LocalScopeHandleCollection   localScopes       = reader.GetLocalScopes(methodDebugHandle);
                foreach (LocalScopeHandle scopeHandle in localScopes)
                {
                    LocalScope scope = reader.GetLocalScope(scopeHandle);
                    LocalVariableHandleCollection localVars = scope.GetLocalVariables();
                    foreach (LocalVariableHandle varHandle in localVars)
                    {
                        LocalVariable localVar = reader.GetLocalVariable(varHandle);
                        if (localVar.Index == localIndex)
                        {
                            if (localVar.Attributes == LocalVariableAttributes.DebuggerHidden)
                            {
                                return(false);
                            }

                            localVarName  = reader.GetString(localVar.Name);
                            ilStartOffset = scope.StartOffset;
                            ilEndOffset   = scope.EndOffset;
                            return(true);
                        }
                    }
                }
            }
            catch
            {
            }
            return(false);
        }
        /// <summary>
        /// Helper method to return local variable name for given local index and IL offset.
        /// </summary>
        /// <param name="openedReader">symbol reader returned by LoadSymbolsForModule</param>
        /// <param name="methodToken">method token</param>
        /// <param name="localIndex">local variable index</param>
        /// <param name="localVarName">local variable name return</param>
        /// <returns>true if name has been found</returns>
        private bool GetLocalVariableByIndex(
            OpenedReader openedReader,
            int methodToken,
            int localIndex,
            out string localVarName)
        {
            localVarName = null;
            MetadataReader reader = openedReader.Reader;

            try
            {
                Handle handle = MetadataTokens.Handle(methodToken);
                if (handle.Kind != HandleKind.MethodDefinition)
                {
                    return(false);
                }

                MethodDebugInformationHandle methodDebugHandle = ((MethodDefinitionHandle)handle).ToDebugInformationHandle();
                LocalScopeHandleCollection   localScopes       = reader.GetLocalScopes(methodDebugHandle);
                foreach (LocalScopeHandle scopeHandle in localScopes)
                {
                    LocalScope scope = reader.GetLocalScope(scopeHandle);
                    LocalVariableHandleCollection localVars = scope.GetLocalVariables();
                    foreach (LocalVariableHandle varHandle in localVars)
                    {
                        LocalVariable localVar = reader.GetLocalVariable(varHandle);
                        if (localVar.Index == localIndex)
                        {
                            if (localVar.Attributes == LocalVariableAttributes.DebuggerHidden)
                            {
                                return(false);
                            }

                            localVarName = reader.GetString(localVar.Name);
                            return(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError($"GetLocalVariableByIndex: {ex.Message}");
            }
            return(false);
        }
Esempio n. 8
0
        public MethodInfo(AssemblyInfo assembly, MethodDefinitionHandle methodDefHandle, int token, SourceFile source, TypeInfo type, MetadataReader asmMetadataReader, MetadataReader pdbMetadataReader)
        {
            this.IsAsync           = -1;
            this.Assembly          = assembly;
            this.methodDef         = asmMetadataReader.GetMethodDefinition(methodDefHandle);
            this.DebugInformation  = pdbMetadataReader.GetMethodDebugInformation(methodDefHandle.ToDebugInformationHandle());
            this.source            = source;
            this.Token             = token;
            this.methodDefHandle   = methodDefHandle;
            this.Name              = asmMetadataReader.GetString(methodDef.Name);
            this.pdbMetadataReader = pdbMetadataReader;
            this.IsEnCMethod       = false;
            if (!DebugInformation.SequencePointsBlob.IsNil)
            {
                var           sps   = DebugInformation.GetSequencePoints();
                SequencePoint start = sps.First();
                SequencePoint end   = sps.First();

                foreach (SequencePoint sp in sps)
                {
                    if (sp.StartLine < start.StartLine)
                    {
                        start = sp;
                    }
                    else if (sp.StartLine == start.StartLine && sp.StartColumn < start.StartColumn)
                    {
                        start = sp;
                    }

                    if (sp.EndLine > end.EndLine)
                    {
                        end = sp;
                    }
                    else if (sp.EndLine == end.EndLine && sp.EndColumn > end.EndColumn)
                    {
                        end = sp;
                    }
                }

                StartLocation = new SourceLocation(this, start);
                EndLocation   = new SourceLocation(this, end);
            }
            localScopes = pdbMetadataReader.GetLocalScopes(methodDefHandle);
        }
Esempio n. 9
0
        public void UpdateEnC(MetadataReader asmMetadataReader, MetadataReader pdbMetadataReaderParm, int method_idx)
        {
            this.DebugInformation  = pdbMetadataReaderParm.GetMethodDebugInformation(MetadataTokens.MethodDebugInformationHandle(method_idx));
            this.pdbMetadataReader = pdbMetadataReaderParm;
            this.IsEnCMethod       = true;
            if (!DebugInformation.SequencePointsBlob.IsNil)
            {
                var           sps   = DebugInformation.GetSequencePoints();
                SequencePoint start = sps.First();
                SequencePoint end   = sps.First();

                foreach (SequencePoint sp in sps)
                {
                    if (sp.StartLine < start.StartLine)
                    {
                        start = sp;
                    }
                    else if (sp.StartLine == start.StartLine && sp.StartColumn < start.StartColumn)
                    {
                        start = sp;
                    }

                    if (sp.EndLine > end.EndLine)
                    {
                        end = sp;
                    }
                    else if (sp.EndLine == end.EndLine && sp.EndColumn > end.EndColumn)
                    {
                        end = sp;
                    }
                }

                StartLocation = new SourceLocation(this, start);
                EndLocation   = new SourceLocation(this, end);
            }
            localScopes = pdbMetadataReader.GetLocalScopes(MetadataTokens.MethodDefinitionHandle(method_idx));
        }