Exemplo n.º 1
0
 internal static void ValidateChecksumAlgorithm(SourceHashAlgorithm checksumAlgorithm)
 {
     if (!SourceHashAlgorithms.IsSupportedAlgorithm(checksumAlgorithm))
     {
         throw new ArgumentException(CodeAnalysisResources.UnsupportedHashAlgorithm, nameof(checksumAlgorithm));
     }
 }
Exemplo n.º 2
0
 public DebugSourceInfo(
     ImmutableArray <byte> checksum,
     SourceHashAlgorithm checksumAlgorithm,
     ImmutableArray <byte> embeddedTextBlob = default)
     : this(checksum, SourceHashAlgorithms.GetAlgorithmGuid(checksumAlgorithm), embeddedTextBlob)
 {
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        private EmbeddedText(string filePath, ImmutableArray <byte> checksum, SourceHashAlgorithm checksumAlgorithm, ImmutableArray <byte> blob)
        {
            Debug.Assert(filePath.Length > 0);
            Debug.Assert(SourceHashAlgorithms.IsSupportedAlgorithm(checksumAlgorithm));
            Debug.Assert(!blob.IsDefault && blob.Length >= sizeof(int));

            FilePath          = filePath;
            Checksum          = checksum;
            ChecksumAlgorithm = checksumAlgorithm;
            Blob = blob;
        }
Exemplo n.º 5
0
        static Cci.DebugSourceDocument CreateDebugSourceDocument(string normalizedPath, MethodSymbol method)
        {
            // TODO: method might be synthesized and we create an incomplete DebugSourceDocument

            var srcf = (method as SourceRoutineSymbol)?.ContainingFile;

            if (srcf != null && srcf.SyntaxTree.TryGetText(out var srctext))
            {
                return(new Cci.DebugSourceDocument(
                           normalizedPath,
                           Constants.CorSymLanguageTypePeachpie,
                           srctext.GetChecksum(),
                           SourceHashAlgorithms.GetAlgorithmGuid(srctext.ChecksumAlgorithm)));
            }
            else
            {
                return(new Cci.DebugSourceDocument(normalizedPath, Constants.CorSymLanguageTypePeachpie));
            }
        }
Exemplo n.º 6
0
        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());
        }