Beispiel #1
0
        private bool?TryReadSourceFileChecksumFromPdb(string sourceFilePath, Project project, out ImmutableArray <byte> checksum, out SourceHashAlgorithm algorithm)
        {
            checksum  = default;
            algorithm = default;

            try
            {
                var compilationOutputs = _debuggingSession.GetCompilationOutputs(project);

                DebugInformationReaderProvider?debugInfoReaderProvider;
                try
                {
                    debugInfoReaderProvider = compilationOutputs.OpenPdb();
                }
                catch (Exception e)
                {
                    EditAndContinueWorkspaceService.Log.Write("Source '{0}' doesn't match output PDB: error opening PDB '{1}': {2}", sourceFilePath, compilationOutputs.PdbDisplayPath, e.Message);
                    debugInfoReaderProvider = null;
                }

                if (debugInfoReaderProvider == null)
                {
                    EditAndContinueWorkspaceService.Log.Write("Source '{0}' doesn't match output PDB: PDB '{1}' not found", sourceFilePath, compilationOutputs.PdbDisplayPath);
                    return(null);
                }

                try
                {
                    var debugInfoReader = debugInfoReaderProvider.CreateEditAndContinueMethodDebugInfoReader();
                    if (!debugInfoReader.TryGetDocumentChecksum(sourceFilePath, out checksum, out var algorithmId))
                    {
                        EditAndContinueWorkspaceService.Log.Write("Source '{0}' doesn't match output PDB: no document", sourceFilePath);
                        return(false);
                    }

                    algorithm = SourceHashAlgorithms.GetSourceHashAlgorithm(algorithmId);
                    if (algorithm == SourceHashAlgorithm.None)
                    {
                        // This can only happen if the PDB was post-processed by a misbehaving tool.
                        EditAndContinueWorkspaceService.Log.Write("Source '{0}' doesn't match PDB: unknown checksum alg", sourceFilePath);
                    }

                    return(true);
                }
                catch (Exception e)
                {
                    EditAndContinueWorkspaceService.Log.Write("Source '{0}' doesn't match output PDB: error reading symbols: {1}", sourceFilePath, e.Message);
                }
                finally
                {
                    debugInfoReaderProvider.Dispose();
                }
            }
            catch (Exception e) when(FatalError.ReportWithoutCrashUnlessCanceled(e))
            {
                EditAndContinueWorkspaceService.Log.Write("Source '{0}' doesn't match PDB: unexpected exception: {1}", sourceFilePath, e.Message);
            }

            return(null);
        }
        public ImmutableArray <SourceDocument> FindSourceDocuments(ISymbol symbol)
        {
            var documentHandles = SymbolSourceDocumentFinder.FindDocumentHandles(symbol, _dllReader, _pdbReader);

            using var _ = ArrayBuilder <SourceDocument> .GetInstance(out var sourceDocuments);

            foreach (var handle in documentHandles)
            {
                var document = _pdbReader.GetDocument(handle);
                var filePath = _pdbReader.GetString(document.Name);

                var hashAlgorithmGuid = _pdbReader.GetGuid(document.HashAlgorithm);
                var hashAlgorithm     = SourceHashAlgorithms.GetSourceHashAlgorithm(hashAlgorithmGuid);
                var checksum          = _pdbReader.GetBlobContent(document.Hash);

                var embeddedText = TryGetEmbeddedSourceText(handle);

                sourceDocuments.Add(new SourceDocument(filePath, hashAlgorithm, checksum, embeddedText));
            }

            return(sourceDocuments.ToImmutable());
        }