From d26e2ef7f1dde4ef4d4d422052d3c4cd4f883dc8 Mon Sep 17 00:00:00 2001 From: Ivan Basov Date: Tue, 8 Oct 2019 15:01:28 -0700 Subject: [PATCH 1/9] Include source files w/o method bodies in the PDB documents --- .../CSharp/Test/Emit/PDB/PDBTests.cs | 71 +++++++++++++++++++ .../Portable/Emit/DebugDocumentsBuilder.cs | 3 + .../Portable/NativePdbWriter/PdbWriter.cs | 15 ++++ .../PEWriter/MetadataWriter.PortablePdb.cs | 15 ++++ .../Core/Portable/PEWriter/PeWriter.cs | 2 + .../VisualBasic/Test/Emit/PDB/PDBTests.vb | 65 +++++++++++++++++ 6 files changed, 171 insertions(+) diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs index 1c9e77910f56c..ae7172739b7d4 100644 --- a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs +++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs @@ -11037,5 +11037,76 @@ public void InvalidCharacterInPdbPath() Diagnostic(ErrorCode.FTL_InvalidInputFileName).WithArguments("test\\?.pdb").WithLocation(1, 1)); } } + + [Fact] + [WorkItem(38954, "https://github.com/dotnet/roslyn/issues/38954")] + public void FilesOneWithNoMethodBody() + { + string source1 = WithWindowsLineBreaks(@" +using System; + +class C +{ + public static void Main() + { + Console.WriteLine(); + } +} +"); + string source2 = WithWindowsLineBreaks(@" +// no code +"); + + var tree1 = Parse(source1, "f:/build/goo.cs"); + var tree2 = Parse(source2, "f:/build/nocode.cs"); + var c = CreateCompilation(new[] { tree1, tree2 }, options: TestOptions.DebugDll); + + c.VerifyPdb(@" + + + + + + + + + + + + + + + + + + + + + + + +"); + } + + [Fact] + [WorkItem(38954, "https://github.com/dotnet/roslyn/issues/38954")] + public void SingleFileWithNoMethodBody() + { + string source = WithWindowsLineBreaks(@" +// no code +"); + + var tree = Parse(source, "f:/build/nocode.cs"); + var c = CreateCompilation(new[] { tree }, options: TestOptions.DebugDll); + + c.VerifyPdb(@" + + + + + + +"); + } } } diff --git a/src/Compilers/Core/Portable/Emit/DebugDocumentsBuilder.cs b/src/Compilers/Core/Portable/Emit/DebugDocumentsBuilder.cs index 96d42c1181cde..4cde968007f72 100644 --- a/src/Compilers/Core/Portable/Emit/DebugDocumentsBuilder.cs +++ b/src/Compilers/Core/Portable/Emit/DebugDocumentsBuilder.cs @@ -47,6 +47,9 @@ internal void AddDebugDocument(Cci.DebugSourceDocument document) _debugDocuments.Add(document.Location, document); } + internal ImmutableArray GetAllDebugDocuments() + => _debugDocuments.Values.ToImmutableArray(); + internal Cci.DebugSourceDocument TryGetDebugDocument(string path, string basePath) { return TryGetDebugDocumentForNormalizedPath(NormalizeDebugDocumentPath(path, basePath)); diff --git a/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs b/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs index abd0a16ff0623..fd4e4fe3a6d08 100644 --- a/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs +++ b/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs @@ -756,5 +756,20 @@ public void WriteRemainingEmbeddedDocuments(IEnumerable emb GetDocumentIndex(document); } } + + /// + /// Write document entries for all debug documents that does not yet have an entry. + /// + /// + /// This is done after serializing method debug info to ensure that we embed all requested + /// text even if there are no corresponding sequence points. + /// + public void WriteRemainingDebugDocuments(IEnumerable documents) + { + foreach (var document in documents) + { + GetDocumentIndex(document); + } + } } } diff --git a/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs b/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs index c24f59a87e41e..5883e49bdb673 100644 --- a/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs +++ b/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs @@ -768,6 +768,21 @@ public void AddRemainingEmbeddedDocuments(IEnumerable docum } } + /// + /// Add document entries for all debug documents that does not yet have an entry. + /// + /// + /// This is done after serializing method debug info to ensure that we embed all requested + /// text even if there are no corresponding sequence points. + /// + public void AddRemainingDebugDocuments(IEnumerable documents) + { + foreach (var document in documents) + { + GetOrAddDocument(document, _documentIndex); + } + } + #endregion #region Edit and Continue diff --git a/src/Compilers/Core/Portable/PEWriter/PeWriter.cs b/src/Compilers/Core/Portable/PEWriter/PeWriter.cs index 225bb1439835d..0f6fa8d719d29 100644 --- a/src/Compilers/Core/Portable/PEWriter/PeWriter.cs +++ b/src/Compilers/Core/Portable/PEWriter/PeWriter.cs @@ -104,6 +104,7 @@ internal static bool WritePeToStream( } nativePdbWriterOpt.WriteRemainingEmbeddedDocuments(mdWriter.Module.DebugDocumentsBuilder.EmbeddedDocuments); + nativePdbWriterOpt.WriteRemainingDebugDocuments(mdWriter.Module.DebugDocumentsBuilder.GetAllDebugDocuments()); } Stream peStream = getPeStream(); @@ -152,6 +153,7 @@ internal static bool WritePeToStream( if (mdWriter.EmitPortableDebugMetadata) { mdWriter.AddRemainingEmbeddedDocuments(mdWriter.Module.DebugDocumentsBuilder.EmbeddedDocuments); + mdWriter.AddRemainingDebugDocuments(mdWriter.Module.DebugDocumentsBuilder.GetAllDebugDocuments()); // The algorithm must be specified for deterministic builds (checked earlier). Debug.Assert(!isDeterministic || context.Module.PdbChecksumAlgorithm.Name != null); diff --git a/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb b/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb index 93cc3be4d0658..751cc74619991 100644 --- a/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb @@ -4614,5 +4614,70 @@ End Class" result.Diagnostics.Verify(Diagnostic(ERRID.FTL_InvalidInputFileName).WithArguments("test\\?.pdb").WithLocation(1, 1)) End Using End Sub + + + + Public Sub FilesOneWithNoMethodBody() + Dim source1 = +"Imports System + +Class C + Public Shared Sub Main() + Console.WriteLine() + End Sub +End Class +" + Dim source2 = +" +' no code +" + + Dim tree1 = Parse(source1, "f:/build/goo.vb") + Dim tree2 = Parse(source2, "f:/build/nocode.vb") + Dim c = CreateCompilation({tree1, tree2}, options:=TestOptions.DebugDll) + + c.VerifyPdb(" + + + + + + + + + + + + + + + + + + + +") + End Sub + + + + Public Sub SingleFileWithNoMethodBody() + Dim source = +" +' no code +" + + Dim tree = Parse(source, "f:/build/nocode.vb") + Dim c = CreateCompilation({tree}, options:=TestOptions.DebugDll) + + c.VerifyPdb(" + + + + + + +") + End Sub End Class End Namespace From 68bb295c6fceae7c9dd329a10711fa3e8da6bdce Mon Sep 17 00:00:00 2001 From: Ivan Basov Date: Wed, 9 Oct 2019 14:15:49 -0700 Subject: [PATCH 2/9] code review feedback --- src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs | 4 ++-- .../Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs b/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs index fd4e4fe3a6d08..4544f3f194d4c 100644 --- a/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs +++ b/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs @@ -748,7 +748,7 @@ public void EmbedSourceLink(Stream stream) /// This is done after serializing method debug info to ensure that we embed all requested /// text even if there are no corresponding sequence points. /// - public void WriteRemainingEmbeddedDocuments(IEnumerable embeddedDocuments) + public void WriteRemainingEmbeddedDocuments(ImmutableArray embeddedDocuments) { foreach (var document in embeddedDocuments) { @@ -764,7 +764,7 @@ public void WriteRemainingEmbeddedDocuments(IEnumerable emb /// This is done after serializing method debug info to ensure that we embed all requested /// text even if there are no corresponding sequence points. /// - public void WriteRemainingDebugDocuments(IEnumerable documents) + public void WriteRemainingDebugDocuments(ImmutableArray documents) { foreach (var document in documents) { diff --git a/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs b/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs index 5883e49bdb673..822b9cec12b96 100644 --- a/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs +++ b/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs @@ -759,7 +759,7 @@ private DocumentHandle GetOrAddDocument(DebugSourceDocument document, Dictionary /// This is done after serializing method debug info to ensure that we embed all requested /// text even if there are no corresponding sequence points. /// - public void AddRemainingEmbeddedDocuments(IEnumerable documents) + public void AddRemainingEmbeddedDocuments(ImmutableArray documents) { foreach (var document in documents) { @@ -775,7 +775,7 @@ public void AddRemainingEmbeddedDocuments(IEnumerable docum /// This is done after serializing method debug info to ensure that we embed all requested /// text even if there are no corresponding sequence points. /// - public void AddRemainingDebugDocuments(IEnumerable documents) + public void AddRemainingDebugDocuments(ImmutableArray documents) { foreach (var document in documents) { From a4cef18e26cbe265cb87b4b3dacdbe122c080c11 Mon Sep 17 00:00:00 2001 From: Ivan Basov Date: Wed, 9 Oct 2019 15:33:54 -0700 Subject: [PATCH 3/9] updated PDB tests --- src/Compilers/CSharp/Test/Emit/PDB/CheckSumTest.cs | 2 ++ src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs | 2 ++ .../VisualBasic/Test/Emit/PDB/ChecksumTests.vb | 3 +++ .../Emit/PDB/PDBExternalSourceDirectiveTests.vb | 13 +++++++++++++ 4 files changed, 20 insertions(+) diff --git a/src/Compilers/CSharp/Test/Emit/PDB/CheckSumTest.cs b/src/Compilers/CSharp/Test/Emit/PDB/CheckSumTest.cs index b6fc2670df011..92b3232da90f8 100644 --- a/src/Compilers/CSharp/Test/Emit/PDB/CheckSumTest.cs +++ b/src/Compilers/CSharp/Test/Emit/PDB/CheckSumTest.cs @@ -232,6 +232,7 @@ static void Main() + @@ -305,6 +306,7 @@ class C { void M() { } } + diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs index ae7172739b7d4..057305e027ace 100644 --- a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs +++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs @@ -10511,6 +10511,7 @@ public async void M1() @" + @@ -10577,6 +10578,7 @@ partial class C + diff --git a/src/Compilers/VisualBasic/Test/Emit/PDB/ChecksumTests.vb b/src/Compilers/VisualBasic/Test/Emit/PDB/ChecksumTests.vb index aae0339291564..6ad4992c88f1a 100644 --- a/src/Compilers/VisualBasic/Test/Emit/PDB/ChecksumTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/PDB/ChecksumTests.vb @@ -248,6 +248,7 @@ End Class + @@ -312,6 +313,7 @@ End Class + @@ -363,6 +365,7 @@ End Class + diff --git a/src/Compilers/VisualBasic/Test/Emit/PDB/PDBExternalSourceDirectiveTests.vb b/src/Compilers/VisualBasic/Test/Emit/PDB/PDBExternalSourceDirectiveTests.vb index 21dfb7a05ff10..3b42eea4ddf97 100644 --- a/src/Compilers/VisualBasic/Test/Emit/PDB/PDBExternalSourceDirectiveTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/PDB/PDBExternalSourceDirectiveTests.vb @@ -46,6 +46,7 @@ End Class + @@ -120,6 +121,7 @@ End Class + @@ -359,6 +361,9 @@ End Class ' Care about the fact that there are no sequence points or referenced files compilation.VerifyPdb( + + + @@ -418,6 +423,9 @@ End Class ' Care about the fact that no files are referenced compilation.VerifyPdb( + + + @@ -503,6 +511,9 @@ End Class + + + @@ -704,6 +715,7 @@ End Module + @@ -757,6 +769,7 @@ End Class + From 7b98102a1023078444e59c78c6e32f2b8e6339e3 Mon Sep 17 00:00:00 2001 From: Ivan Basov Date: Wed, 9 Oct 2019 19:08:55 -0700 Subject: [PATCH 4/9] code review feedback --- .../Core/Portable/Compilation/Compilation.cs | 5 ---- .../Portable/Emit/DebugDocumentsBuilder.cs | 15 +++-------- .../Portable/NativePdbWriter/PdbWriter.cs | 27 ++++--------------- .../PEWriter/MetadataWriter.PortablePdb.cs | 24 +++-------------- .../Core/Portable/PEWriter/PeWriter.cs | 6 ++--- 5 files changed, 14 insertions(+), 63 deletions(-) diff --git a/src/Compilers/Core/Portable/Compilation/Compilation.cs b/src/Compilers/Core/Portable/Compilation/Compilation.cs index 6e49054c93979..04e878455375d 100644 --- a/src/Compilers/Core/Portable/Compilation/Compilation.cs +++ b/src/Compilers/Core/Portable/Compilation/Compilation.cs @@ -2068,8 +2068,6 @@ internal bool CreateDebugDocuments(DebugDocumentsBuilder documentsBuilder, IEnum // takes priority over the syntax tree pass, which will not embed. if (!embeddedTexts.IsEmpty()) { - var embeddedDocuments = ArrayBuilder.GetInstance(); - foreach (var text in embeddedTexts) { Debug.Assert(!string.IsNullOrEmpty(text.FilePath)); @@ -2083,11 +2081,8 @@ internal bool CreateDebugDocuments(DebugDocumentsBuilder documentsBuilder, IEnum () => text.GetDebugSourceInfo()); documentsBuilder.AddDebugDocument(document); - embeddedDocuments.Add(document); } } - - documentsBuilder.EmbeddedDocuments = embeddedDocuments.ToImmutableAndFree(); } // Add debug documents for all trees with distinct paths. diff --git a/src/Compilers/Core/Portable/Emit/DebugDocumentsBuilder.cs b/src/Compilers/Core/Portable/Emit/DebugDocumentsBuilder.cs index 4cde968007f72..70b5bee1bc1f9 100644 --- a/src/Compilers/Core/Portable/Emit/DebugDocumentsBuilder.cs +++ b/src/Compilers/Core/Portable/Emit/DebugDocumentsBuilder.cs @@ -3,8 +3,7 @@ using Roslyn.Utilities; using System; using System.Collections.Concurrent; -using System.Collections.Immutable; -using System.Diagnostics; +using System.Collections.Generic; namespace Microsoft.CodeAnalysis.Emit { @@ -19,7 +18,6 @@ internal sealed class DebugDocumentsBuilder private readonly ConcurrentDictionary _debugDocuments; private readonly ConcurrentCache<(string, string), string> _normalizedPathsCache; private readonly SourceReferenceResolver _resolverOpt; - private ImmutableArray _embeddedDocuments; public DebugDocumentsBuilder(SourceReferenceResolver resolverOpt, bool isDocumentNameCaseSensitive) { @@ -31,13 +29,6 @@ public DebugDocumentsBuilder(SourceReferenceResolver resolverOpt, bool isDocumen StringComparer.OrdinalIgnoreCase); _normalizedPathsCache = new ConcurrentCache<(string, string), string>(16); - _embeddedDocuments = ImmutableArray.Empty; - } - - internal ImmutableArray EmbeddedDocuments - { - get { return _embeddedDocuments; } - set { Debug.Assert(value != null); _embeddedDocuments = value; } } internal int DebugDocumentCount => _debugDocuments.Count; @@ -47,8 +38,8 @@ internal void AddDebugDocument(Cci.DebugSourceDocument document) _debugDocuments.Add(document.Location, document); } - internal ImmutableArray GetAllDebugDocuments() - => _debugDocuments.Values.ToImmutableArray(); + internal IReadOnlyDictionary DebugDocuments + => _debugDocuments; internal Cci.DebugSourceDocument TryGetDebugDocument(string path, string basePath) { diff --git a/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs b/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs index 4544f3f194d4c..22402952fc579 100644 --- a/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs +++ b/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs @@ -5,11 +5,10 @@ using System.Collections.Immutable; using System.Diagnostics; using System.IO; +using System.Linq; using System.Reflection.Metadata; using System.Reflection.Metadata.Ecma335; -using System.Runtime.InteropServices; using System.Security.Cryptography; -using System.Text; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Emit; using Microsoft.CodeAnalysis.PooledObjects; @@ -742,33 +741,17 @@ public void EmbedSourceLink(Stream stream) } /// - /// Write document entries for any embedded text document that does not yet have an entry. + /// Write document entries for all debug documents that do not yet have an entry. /// /// /// This is done after serializing method debug info to ensure that we embed all requested /// text even if there are no corresponding sequence points. /// - public void WriteRemainingEmbeddedDocuments(ImmutableArray embeddedDocuments) + public void WriteRemainingDebugDocuments(IReadOnlyDictionary documents) { - foreach (var document in embeddedDocuments) + foreach (var kvp in documents.OrderBy(kvp => kvp.Key)) { - Debug.Assert(!document.GetSourceInfo().EmbeddedTextBlob.IsDefault); - GetDocumentIndex(document); - } - } - - /// - /// Write document entries for all debug documents that does not yet have an entry. - /// - /// - /// This is done after serializing method debug info to ensure that we embed all requested - /// text even if there are no corresponding sequence points. - /// - public void WriteRemainingDebugDocuments(ImmutableArray documents) - { - foreach (var document in documents) - { - GetDocumentIndex(document); + GetDocumentIndex(kvp.Value); } } } diff --git a/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs b/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs index 822b9cec12b96..edf8cd2791036 100644 --- a/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs +++ b/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs @@ -753,33 +753,17 @@ private DocumentHandle GetOrAddDocument(DebugSourceDocument document, Dictionary } /// - /// Add document entries for any embedded text document that does not yet have an entry. + /// Add document entries for all debug documents that do not yet have an entry. /// /// /// This is done after serializing method debug info to ensure that we embed all requested /// text even if there are no corresponding sequence points. /// - public void AddRemainingEmbeddedDocuments(ImmutableArray documents) + public void AddRemainingDebugDocuments(IReadOnlyDictionary documents) { - foreach (var document in documents) + foreach (var kvp in documents.OrderBy(kvp => kvp.Key)) { - Debug.Assert(document.GetSourceInfo().EmbeddedTextBlob != null); - GetOrAddDocument(document, _documentIndex); - } - } - - /// - /// Add document entries for all debug documents that does not yet have an entry. - /// - /// - /// This is done after serializing method debug info to ensure that we embed all requested - /// text even if there are no corresponding sequence points. - /// - public void AddRemainingDebugDocuments(ImmutableArray documents) - { - foreach (var document in documents) - { - GetOrAddDocument(document, _documentIndex); + GetOrAddDocument(kvp.Value, _documentIndex); } } diff --git a/src/Compilers/Core/Portable/PEWriter/PeWriter.cs b/src/Compilers/Core/Portable/PEWriter/PeWriter.cs index 0f6fa8d719d29..7d47c15c803f0 100644 --- a/src/Compilers/Core/Portable/PEWriter/PeWriter.cs +++ b/src/Compilers/Core/Portable/PEWriter/PeWriter.cs @@ -103,8 +103,7 @@ internal static bool WritePeToStream( #endif } - nativePdbWriterOpt.WriteRemainingEmbeddedDocuments(mdWriter.Module.DebugDocumentsBuilder.EmbeddedDocuments); - nativePdbWriterOpt.WriteRemainingDebugDocuments(mdWriter.Module.DebugDocumentsBuilder.GetAllDebugDocuments()); + nativePdbWriterOpt.WriteRemainingDebugDocuments(mdWriter.Module.DebugDocumentsBuilder.DebugDocuments); } Stream peStream = getPeStream(); @@ -152,8 +151,7 @@ internal static bool WritePeToStream( BlobBuilder portablePdbToEmbed = null; if (mdWriter.EmitPortableDebugMetadata) { - mdWriter.AddRemainingEmbeddedDocuments(mdWriter.Module.DebugDocumentsBuilder.EmbeddedDocuments); - mdWriter.AddRemainingDebugDocuments(mdWriter.Module.DebugDocumentsBuilder.GetAllDebugDocuments()); + mdWriter.AddRemainingDebugDocuments(mdWriter.Module.DebugDocumentsBuilder.DebugDocuments); // The algorithm must be specified for deterministic builds (checked earlier). Debug.Assert(!isDeterministic || context.Module.PdbChecksumAlgorithm.Name != null); From a200fc8b241f012752faaf54e5a3907d9dbc109f Mon Sep 17 00:00:00 2001 From: Ivan Basov Date: Wed, 9 Oct 2019 19:19:28 -0700 Subject: [PATCH 5/9] code review feedback --- src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs | 4 +++- .../Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs b/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs index 22402952fc579..c09aac4ce9be2 100644 --- a/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs +++ b/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs @@ -749,7 +749,9 @@ public void EmbedSourceLink(Stream stream) /// public void WriteRemainingDebugDocuments(IReadOnlyDictionary documents) { - foreach (var kvp in documents.OrderBy(kvp => kvp.Key)) + foreach (var kvp in documents + .Where(kvp => !_documentIndex.ContainsKey(kvp.Value)) + .OrderBy(kvp => kvp.Key)) { GetDocumentIndex(kvp.Value); } diff --git a/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs b/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs index edf8cd2791036..4772f464e21e6 100644 --- a/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs +++ b/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs @@ -761,7 +761,9 @@ private DocumentHandle GetOrAddDocument(DebugSourceDocument document, Dictionary /// public void AddRemainingDebugDocuments(IReadOnlyDictionary documents) { - foreach (var kvp in documents.OrderBy(kvp => kvp.Key)) + foreach (var kvp in documents + .Where(kvp => !_documentIndex.ContainsKey(kvp.Value)) + .OrderBy(kvp => kvp.Key)) { GetOrAddDocument(kvp.Value, _documentIndex); } From 25ee210dae7eee5e2def680c45464d5e7a980f69 Mon Sep 17 00:00:00 2001 From: Ivan Basov Date: Thu, 10 Oct 2019 11:33:03 -0700 Subject: [PATCH 6/9] skipping windows tests in mac and linux --- src/Compilers/CSharp/Test/Emit/PDB/CheckSumTest.cs | 2 +- src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs | 4 ++-- src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/PDB/CheckSumTest.cs b/src/Compilers/CSharp/Test/Emit/PDB/CheckSumTest.cs index 92b3232da90f8..7afd473af8a6e 100644 --- a/src/Compilers/CSharp/Test/Emit/PDB/CheckSumTest.cs +++ b/src/Compilers/CSharp/Test/Emit/PDB/CheckSumTest.cs @@ -287,7 +287,7 @@ void M() "); } - [Fact] + [ConditionalFact(typeof(WindowsOnly))] public void NoResolver() { var comp = CSharpCompilation.Create( diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs index 057305e027ace..5fe7a44c1c453 100644 --- a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs +++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs @@ -11040,7 +11040,7 @@ public void InvalidCharacterInPdbPath() } } - [Fact] + [ConditionalFact(typeof(WindowsDesktopOnly), Reason = ConditionalSkipReason.NativePdbRequiresDesktop)] [WorkItem(38954, "https://github.com/dotnet/roslyn/issues/38954")] public void FilesOneWithNoMethodBody() { @@ -11090,7 +11090,7 @@ public static void Main() "); } - [Fact] + [ConditionalFact(typeof(WindowsDesktopOnly), Reason = ConditionalSkipReason.NativePdbRequiresDesktop)] [WorkItem(38954, "https://github.com/dotnet/roslyn/issues/38954")] public void SingleFileWithNoMethodBody() { diff --git a/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb b/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb index 751cc74619991..63cbb709ed30e 100644 --- a/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb @@ -4615,7 +4615,7 @@ End Class" End Using End Sub - + Public Sub FilesOneWithNoMethodBody() Dim source1 = @@ -4659,7 +4659,7 @@ End Class ") End Sub - + Public Sub SingleFileWithNoMethodBody() Dim source = From c08e2a27c9c51be416a19b96547485ecb4225896 Mon Sep 17 00:00:00 2001 From: Ivan Basov Date: Thu, 10 Oct 2019 13:31:24 -0700 Subject: [PATCH 7/9] minor refactoring --- .../Portable/NativePdbWriter/PdbWriter.cs | 9 +++- .../PEWriter/MetadataWriter.PortablePdb.cs | 41 +++++++++++-------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs b/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs index c09aac4ce9be2..b316c2e506fa2 100644 --- a/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs +++ b/src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs @@ -571,6 +571,11 @@ private int GetDocumentIndex(DebugSourceDocument document) return documentIndex; } + return AddDocumentIndex(document); + } + + private int AddDocumentIndex(DebugSourceDocument document) + { Guid algorithmId; ReadOnlySpan checksum; ReadOnlySpan embeddedSource; @@ -596,7 +601,7 @@ private int GetDocumentIndex(DebugSourceDocument document) embeddedSource = null; } - documentIndex = _symWriter.DefineDocument( + int documentIndex = _symWriter.DefineDocument( document.Location, document.Language, document.LanguageVendor, @@ -753,7 +758,7 @@ public void WriteRemainingDebugDocuments(IReadOnlyDictionary !_documentIndex.ContainsKey(kvp.Value)) .OrderBy(kvp => kvp.Key)) { - GetDocumentIndex(kvp.Value); + AddDocumentIndex(kvp.Value); } } } diff --git a/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs b/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs index 4772f464e21e6..bb52611ff267b 100644 --- a/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs +++ b/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs @@ -727,26 +727,33 @@ private void SerializeDeltaLinesAndColumns(BlobBuilder writer, SequencePoint seq private DocumentHandle GetOrAddDocument(DebugSourceDocument document, Dictionary index) { - DocumentHandle documentHandle; - if (!index.TryGetValue(document, out documentHandle)) + if (index.TryGetValue(document, out var documentHandle)) { - DebugSourceInfo info = document.GetSourceInfo(); + return documentHandle; + } - documentHandle = _debugMetadataOpt.AddDocument( - name: _debugMetadataOpt.GetOrAddDocumentName(document.Location), - hashAlgorithm: info.Checksum.IsDefault ? default(GuidHandle) : _debugMetadataOpt.GetOrAddGuid(info.ChecksumAlgorithmId), - hash: info.Checksum.IsDefault ? default(BlobHandle) : _debugMetadataOpt.GetOrAddBlob(info.Checksum), - language: _debugMetadataOpt.GetOrAddGuid(document.Language)); + return AddDocument(document, index); + } - index.Add(document, documentHandle); + private DocumentHandle AddDocument(DebugSourceDocument document, Dictionary index) + { + DocumentHandle documentHandle; + DebugSourceInfo info = document.GetSourceInfo(); - if (info.EmbeddedTextBlob != null) - { - _debugMetadataOpt.AddCustomDebugInformation( - parent: documentHandle, - kind: _debugMetadataOpt.GetOrAddGuid(PortableCustomDebugInfoKinds.EmbeddedSource), - value: _debugMetadataOpt.GetOrAddBlob(info.EmbeddedTextBlob)); - } + documentHandle = _debugMetadataOpt.AddDocument( + name: _debugMetadataOpt.GetOrAddDocumentName(document.Location), + hashAlgorithm: info.Checksum.IsDefault ? default(GuidHandle) : _debugMetadataOpt.GetOrAddGuid(info.ChecksumAlgorithmId), + hash: info.Checksum.IsDefault ? default(BlobHandle) : _debugMetadataOpt.GetOrAddBlob(info.Checksum), + language: _debugMetadataOpt.GetOrAddGuid(document.Language)); + + index.Add(document, documentHandle); + + if (info.EmbeddedTextBlob != null) + { + _debugMetadataOpt.AddCustomDebugInformation( + parent: documentHandle, + kind: _debugMetadataOpt.GetOrAddGuid(PortableCustomDebugInfoKinds.EmbeddedSource), + value: _debugMetadataOpt.GetOrAddBlob(info.EmbeddedTextBlob)); } return documentHandle; @@ -765,7 +772,7 @@ public void AddRemainingDebugDocuments(IReadOnlyDictionary !_documentIndex.ContainsKey(kvp.Value)) .OrderBy(kvp => kvp.Key)) { - GetOrAddDocument(kvp.Value, _documentIndex); + AddDocument(kvp.Value, _documentIndex); } } From eaab9f38d674aac606709847c9777df222ace648 Mon Sep 17 00:00:00 2001 From: Ivan Basov Date: Thu, 10 Oct 2019 13:37:32 -0700 Subject: [PATCH 8/9] revert skipping C# tests in linus and mac --- src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs index 5fe7a44c1c453..057305e027ace 100644 --- a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs +++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs @@ -11040,7 +11040,7 @@ public void InvalidCharacterInPdbPath() } } - [ConditionalFact(typeof(WindowsDesktopOnly), Reason = ConditionalSkipReason.NativePdbRequiresDesktop)] + [Fact] [WorkItem(38954, "https://github.com/dotnet/roslyn/issues/38954")] public void FilesOneWithNoMethodBody() { @@ -11090,7 +11090,7 @@ public static void Main() "); } - [ConditionalFact(typeof(WindowsDesktopOnly), Reason = ConditionalSkipReason.NativePdbRequiresDesktop)] + [Fact] [WorkItem(38954, "https://github.com/dotnet/roslyn/issues/38954")] public void SingleFileWithNoMethodBody() { From 28c8b8259fd8a36048b2263da40b635603f48ba1 Mon Sep 17 00:00:00 2001 From: Ivan Basov Date: Mon, 14 Oct 2019 11:44:05 -0700 Subject: [PATCH 9/9] disabling skipped test --- .../EditAndContinue/EditAndContinueWorkspaceServiceTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EditorFeatures/Test/EditAndContinue/EditAndContinueWorkspaceServiceTests.cs b/src/EditorFeatures/Test/EditAndContinue/EditAndContinueWorkspaceServiceTests.cs index c4220f77c9179..e0c2984de4af1 100644 --- a/src/EditorFeatures/Test/EditAndContinue/EditAndContinueWorkspaceServiceTests.cs +++ b/src/EditorFeatures/Test/EditAndContinue/EditAndContinueWorkspaceServiceTests.cs @@ -972,7 +972,7 @@ public async Task BreakMode_RudeEdits_DocumentOutOfSync() }, _telemetryLog); } - [Fact] + [Fact(Skip = "https://github.com/dotnet/roslyn/issues/39271")] public async Task BreakMode_RudeEdits_DocumentWithoutSequencePoints() { var source1 = "abstract class C { public abstract void M(); }";