Пример #1
0
        public ISymbolMethod GetMethod(SymbolToken method)
        {
            SymbolMethod result = null;

            methodTokenLookup.TryGetValue(method.GetToken(), out result);

            return(result);
        }
Пример #2
0
        private void AddChildScopes(MetadataReader pdb, SymbolScope parent, IEnumerator <LocalScopeHandle> scopes, SymbolMethod owner)
        {
            while (true)
            {
                scopes.MoveNext();

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

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

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

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

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

                parent.AddChild(current);
            }
        }
Пример #3
0
        private bool LoadPdbFile(string pdbFileName)
        {
            if (!System.IO.File.Exists(pdbFileName))
            {
                return(false);
            }

            var fileToSourceFileInfos = new Dictionary <string, List <SourceFileDebugInfo> >();

            sourceFilesDebugInfo[pdbFileName] = fileToSourceFileInfos;
            using (var fs = new FileStream(pdbFileName, FileMode.Open))
                using (var metadataReader = MetadataReaderProvider.FromPortablePdbStream(fs))
                {
                    var pdb = metadataReader.GetMetadataReader();
                    if (pdb.Documents.Count == 0)//If .pdb has 0 documents consider it invalid
                    {
                        return(false);
                    }

                    var methodMapping = new Dictionary <DocumentHandle, List <SymbolMethod> >(pdb.Documents.Count);

                    foreach (var methodHandle in pdb.MethodDebugInformation)
                    {
                        var method = pdb.GetMethodDebugInformation(methodHandle);

                        if (method.Document.IsNil)
                        {
                            continue;
                        }
                        List <SymbolMethod> list;
                        if (!methodMapping.TryGetValue(method.Document, out list))
                        {
                            methodMapping[method.Document] = list = new List <SymbolMethod>();
                        }

                        var methodToken = MetadataTokens.GetToken(methodHandle.ToDefinitionHandle());

                        var token = new SymbolToken(methodToken);

                        var newMethod = new SymbolMethod(method.GetSequencePoints(), token);
                        methodTokenLookup.Add(token.GetToken(), newMethod);
                        list.Add(newMethod);

                        var def = pdb.GetMethodDefinition(methodHandle.ToDefinitionHandle());

                        newMethod.SetRootScope(CreateSymbolScope(pdb, pdb.GetLocalScopes(methodHandle.ToDefinitionHandle()), newMethod, 0));
                    }

                    foreach (var documentHandle in pdb.Documents)
                    {
                        // A CompileUnit may not have methods, so guard against this.
                        List <SymbolMethod> list;
                        if (!methodMapping.TryGetValue(documentHandle, out list))
                        {
                            list = new List <SymbolMethod>();
                        }

                        SourceFileDebugInfo info = new SourceFileDebugInfo(list);

                        var document = pdb.GetDocument(documentHandle);
                        info.Hash          = pdb.GetBlobBytes(document.Hash);
                        info.HashAlgorithm = pdb.GetGuid(document.HashAlgorithm);
                        info.FileID        = 0;
                        info.FullFilePath  = pdb.GetString(document.Name);

                        foreach (var method in list)
                        {
                            method.Document = info;
                        }

                        fileToSourceFileInfos[info.FullFilePath] = new List <SourceFileDebugInfo>();

                        if (!fileToSourceFileInfos.ContainsKey(System.IO.Path.GetFileName(info.FullFilePath)))
                        {
                            fileToSourceFileInfos[System.IO.Path.GetFileName(info.FullFilePath)] = new List <SourceFileDebugInfo>();
                        }

                        fileToSourceFileInfos[info.FullFilePath].Add(info);
                        fileToSourceFileInfos[System.IO.Path.GetFileName(info.FullFilePath)].Add(info);
                    }
                }

            return(true);
        }
Пример #4
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);
        }