Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include source files w/o method bodies in the PDB documents #39136

Merged
merged 9 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Test/Emit/PDB/CheckSumTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ static void Main()
<file id=""2"" name=""USED2.cs"" language=""C#"" checksumAlgorithm=""406ea660-64cf-4c82-b6f0-42d48172a799"" checksum=""AB-00-7F-1D-23-D9"" />
<file id=""3"" name=""b.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""C0-51-F0-6F-D3-ED-44-A2-11-4D-03-70-89-20-A6-05-11-62-14-BE"" />
<file id=""4"" name=""a.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""F0-C4-23-63-A5-89-B9-29-AF-94-07-85-2F-3A-40-D3-70-14-8F-9B"" />
<file id=""5"" name=""UNUSED.cs"" language=""C#"" checksumAlgorithm=""406ea660-64cf-4c82-b6f0-42d48172a799"" checksum=""AB-00-7F-1D-23-D9"" />
</files>
<methods>
<method containingType=""C"" name=""Main"">
Expand Down Expand Up @@ -305,6 +306,7 @@ class C { void M() { } }
<symbols>
<files>
<file id=""1"" name=""a\..\a.cs"" language=""C#"" checksumAlgorithm=""406ea660-64cf-4c82-b6f0-42d48172a799"" checksum=""AB-00-7F-1D-23-D5"" />
<file id=""2"" name=""C:\a\..\b.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""36-39-3C-83-56-97-F2-F0-60-95-A4-A0-32-C6-32-C7-B2-4B-16-92"" />
</files>
<methods>
<method containingType=""C"" name=""M"">
Expand Down
73 changes: 73 additions & 0 deletions src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10511,6 +10511,7 @@ public async void M1()
@"<symbols>
<files>
<file id=""1"" name=""C:\Async.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""DB-EB-2A-06-7B-2F-0E-0D-67-8A-00-2C-58-7A-28-06-05-6C-3D-CE"" />
<file id=""2"" name=""HIDDEN.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""8A-92-EE-2F-D6-6F-C0-69-F4-A8-54-CB-11-BE-A3-06-76-2C-9C-98"" />
</files>
<methods>
<method containingType=""C"" name=""M1"">
Expand Down Expand Up @@ -10577,6 +10578,7 @@ partial class C
<symbols>
<files>
<file id=""1"" name=""constructor.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""EA-D6-0A-16-6C-6A-BC-C1-5D-98-0F-B7-4B-78-13-93-FB-C7-C2-5A"" />
<file id=""2"" name=""initializer.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""84-32-24-D7-FE-32-63-BA-41-D5-17-A2-D5-90-23-B8-12-3C-AF-D5"" />
</files>
<methods>
<method containingType=""C"" name="".ctor"">
Expand Down Expand Up @@ -11037,5 +11039,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(@"
<symbols>
<files>
<file id=""1"" name=""f:/build/goo.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""5D-7D-CF-1B-79-12-0E-0A-80-13-E0-98-7E-5C-AA-3B-63-D8-7E-4F"" />
<file id=""2"" name=""f:/build/nocode.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""8B-1D-3F-75-E0-A8-8F-90-B2-D3-52-CF-71-9B-17-29-3C-70-7A-42"" />
</files>
<methods>
<method containingType=""C"" name=""Main"">
<customDebugInfo>
<using>
<namespace usingCount=""1"" />
</using>
</customDebugInfo>
<sequencePoints>
<entry offset=""0x0"" startLine=""7"" startColumn=""5"" endLine=""7"" endColumn=""6"" document=""1"" />
<entry offset=""0x1"" startLine=""8"" startColumn=""9"" endLine=""8"" endColumn=""29"" document=""1"" />
<entry offset=""0x7"" startLine=""9"" startColumn=""5"" endLine=""9"" endColumn=""6"" document=""1"" />
</sequencePoints>
<scope startOffset=""0x0"" endOffset=""0x8"">
<namespace name=""System"" />
</scope>
</method>
</methods>
</symbols>
");
}

[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(@"
<symbols>
<files>
<file id=""1"" name=""f:/build/nocode.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""8B-1D-3F-75-E0-A8-8F-90-B2-D3-52-CF-71-9B-17-29-3C-70-7A-42"" />
</files>
<methods />
</symbols>
");
}
}
}
3 changes: 3 additions & 0 deletions src/Compilers/Core/Portable/Emit/DebugDocumentsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ internal void AddDebugDocument(Cci.DebugSourceDocument document)
_debugDocuments.Add(document.Location, document);
}

internal ImmutableArray<Cci.DebugSourceDocument> GetAllDebugDocuments()
=> _debugDocuments.Values.ToImmutableArray();
Copy link
Member

@tmat tmat Oct 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_debugDocuments.Values.ToImmutableArray(); [](start = 15, length = 42)

This will result in non-deterministic PDB. We need to order the documents somehow. #Resolved

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also optimize this to avoid allocations and extra work. Return IReadOnlyDictionary from this method. Enumerate the dictionary in AddRemainingDebugDocuments to filter out documents that are already indexed. Sort the remaining and add them.


In reply to: 333275492 [](ancestors = 333275492)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I just think that filtering is not necessary because we add only item not yet added.


In reply to: 333278515 [](ancestors = 333278515,333275492)

Copy link
Member

@tmat tmat Oct 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filtering is an optimization, so that we don't need to sort all the documents upfront just to realize we only need to add a few. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me try


In reply to: 333303087 [](ancestors = 333303087)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @tmat! Updated.


In reply to: 333303897 [](ancestors = 333303897,333303087)


internal Cci.DebugSourceDocument TryGetDebugDocument(string path, string basePath)
{
return TryGetDebugDocumentForNormalizedPath(NormalizeDebugDocumentPath(path, basePath));
Expand Down
17 changes: 16 additions & 1 deletion src/Compilers/Core/Portable/NativePdbWriter/PdbWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,13 +748,28 @@ 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.
/// </remarks>
public void WriteRemainingEmbeddedDocuments(IEnumerable<DebugSourceDocument> embeddedDocuments)
public void WriteRemainingEmbeddedDocuments(ImmutableArray<DebugSourceDocument> embeddedDocuments)
{
foreach (var document in embeddedDocuments)
{
Debug.Assert(!document.GetSourceInfo().EmbeddedTextBlob.IsDefault);
GetDocumentIndex(document);
}
}

/// <summary>
/// Write document entries for all debug documents that does not yet have an entry.
/// </summary>
/// <remarks>
/// This is done after serializing method debug info to ensure that we embed all requested
/// text even if there are no corresponding sequence points.
/// </remarks>
public void WriteRemainingDebugDocuments(ImmutableArray<DebugSourceDocument> documents)
{
foreach (var document in documents)
{
GetDocumentIndex(document);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </remarks>
public void AddRemainingEmbeddedDocuments(IEnumerable<DebugSourceDocument> documents)
public void AddRemainingEmbeddedDocuments(ImmutableArray<DebugSourceDocument> documents)
{
foreach (var document in documents)
{
Expand All @@ -768,6 +768,21 @@ public void AddRemainingEmbeddedDocuments(IEnumerable<DebugSourceDocument> docum
}
}

/// <summary>
/// Add document entries for all debug documents that does not yet have an entry.
Copy link
Member

@tmat tmat Oct 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does [](start = 62, length = 4)

typo: do #Resolved

/// </summary>
/// <remarks>
/// This is done after serializing method debug info to ensure that we embed all requested
/// text even if there are no corresponding sequence points.
/// </remarks>
public void AddRemainingDebugDocuments(ImmutableArray<DebugSourceDocument> documents)
{
foreach (var document in documents)
{
GetOrAddDocument(document, _documentIndex);
}
}
Copy link
Member

@tmat tmat Oct 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need two methods? They seem to be doing the same thing. #Resolved


#endregion

#region Edit and Continue
Expand Down
2 changes: 2 additions & 0 deletions src/Compilers/Core/Portable/PEWriter/PeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ internal static bool WritePeToStream(
}

nativePdbWriterOpt.WriteRemainingEmbeddedDocuments(mdWriter.Module.DebugDocumentsBuilder.EmbeddedDocuments);
Copy link
Member

@tmat tmat Oct 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WriteRemainingEmbeddedDocuments [](start = 35, length = 31)

I don't think this is necessary anymore - embedded sources are added to the set of all debug documents on the document builder in CreateDebugDocuments. If we make sure we add an entry for each document then it follows that all embedded documents will also be added.

Also, once we remove this call we can remove EmbeddedDocuments array from DebugDocumentsBuilder. #Resolved

nativePdbWriterOpt.WriteRemainingDebugDocuments(mdWriter.Module.DebugDocumentsBuilder.GetAllDebugDocuments());
Copy link
Member

@jaredpar jaredpar Oct 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this boxes the ImmutableArray<T> into IEnumerable<T>. Given both these APIs are new consider changing the type of one to avoid the box. #Resolved

}

Stream peStream = getPeStream();
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/Compilers/VisualBasic/Test/Emit/PDB/ChecksumTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ End Class
<files>
<file id="1" name="b:\base\line.vb" language="VB"/>
<file id="2" name="q:\absolute\line.vb" language="VB"/>
<file id="3" name="b:\base\b.vb" language="VB" checksumAlgorithm="SHA1" checksum="F9-90-00-9D-9E-45-97-F2-3D-67-1C-D8-47-A8-9B-DA-4A-91-AA-7F"/>
</files>
<methods>
<method containingType="C" name="M">
Expand Down Expand Up @@ -312,6 +313,7 @@ End Class
<file id="3" name="b:\base\c.vb" language="VB" checksumAlgorithm="406ea660-64cf-4c82-b6f0-42d48172a79a" checksum="AB-00-7F-1D-23-DC"/>
<file id="4" name="b:\base\d.vb" language="VB" checksumAlgorithm="406ea660-64cf-4c82-b6f0-42d48172a79a" checksum="AB-00-7F-1D-23-DD"/>
<file id="5" name="b:\base\e.vb" language="VB" checksumAlgorithm="406ea660-64cf-4c82-b6f0-42d48172a79a" checksum="AB-00-7F-1D-23-DE"/>
<file id="6" name="b:\base\file.vb" language="VB" checksumAlgorithm="SHA1" checksum="C2-46-C6-34-F6-20-D3-FE-28-B9-D8-62-0F-A9-FB-2F-89-E7-48-23"/>
</files>
<methods>
<method containingType="C" name="M">
Expand Down Expand Up @@ -363,6 +365,7 @@ End Class
<file id="1" name="a.vb" language="VB" checksumAlgorithm="406ea660-64cf-4c82-b6f0-42d48172a79a" checksum="AB-00-7F-1D-23-DA"/>
<file id="2" name="./a.vb" language="VB"/>
<file id="3" name="b.vb" language="VB"/>
<file id="4" name="file.vb" language="VB" checksumAlgorithm="SHA1" checksum="23-C1-6B-94-B0-D4-06-26-C8-D2-82-21-63-07-53-11-4D-5A-02-BC"/>
</files>
<methods>
<method containingType="C" name="M">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ End Class
<symbols>
<files>
<file id="1" name="C:\abc\def.vb" language="VB"/>
<file id="2" name="a.vb" language="VB" checksumAlgorithm="SHA1" checksum="70-82-DD-9A-57-B3-BE-57-7E-E8-B4-AE-B8-1E-1B-75-38-9D-13-C9"/>
</files>
<entryPoint declaringType="C1" methodName="Main"/>
<methods>
Expand Down Expand Up @@ -120,6 +121,7 @@ End Class
<files>
<file id="1" name="C:\abc\def.vb" language="VB"/>
<file id="2" name="C:\abc\def2.vb" language="VB"/>
<file id="3" name="a.vb" language="VB" checksumAlgorithm="SHA1" checksum="DB-A9-94-EF-BC-DF-10-C9-60-0F-C0-C4-9F-E4-77-F9-37-CF-E1-CE"/>
</files>
<entryPoint declaringType="C1" methodName="Main"/>
<methods>
Expand Down Expand Up @@ -359,6 +361,9 @@ End Class
' Care about the fact that there are no sequence points or referenced files
compilation.VerifyPdb(
<symbols>
<files>
<file id="1" name="a.vb" language="VB" checksumAlgorithm="SHA1" checksum="B6-80-9E-65-43-38-00-C1-35-7F-AE-D0-60-F2-24-44-A8-11-C2-63"/>
</files>
<entryPoint declaringType="C1" methodName="Main"/>
<methods>
<method containingType="C1" name="Main" format="windows">
Expand Down Expand Up @@ -418,6 +423,9 @@ End Class
' Care about the fact that no files are referenced
compilation.VerifyPdb(
<symbols>
<files>
<file id="1" name="a.vb" language="VB" checksumAlgorithm="SHA1" checksum="73-05-84-40-AC-E0-15-63-CC-FE-BD-9A-99-23-AA-BD-24-40-24-44"/>
</files>
<entryPoint declaringType="C1" methodName="Main"/>
<methods>
<method containingType="C1" name="Main" format="windows">
Expand Down Expand Up @@ -503,6 +511,9 @@ End Class
<files>
<file id="1" name="C:\abc\def1.vb" language="VB"/>
<file id="2" name="C:\abc\def2.vb" language="VB" checksumAlgorithm="406ea660-64cf-4c82-b6f0-42d48172a799" checksum="12-34"/>
<file id="3" name="b.vb" language="VB" checksumAlgorithm="SHA1" checksum="7F-D8-35-3F-B4-08-17-37-3E-37-30-26-2A-3F-0C-20-6F-48-2A-7A"/>
<file id="4" name="BOGUS.vb" language="VB" checksumAlgorithm="406ea660-64cf-4c82-b6f0-42d48172a799" checksum="12-34"/>
<file id="5" name="C:\Abc\ACTUAL.vb" language="VB" checksumAlgorithm="SHA1" checksum="27-52-E9-85-5A-AC-31-05-A5-6F-70-40-55-3A-9C-43-D2-07-0D-4B"/>
</files>
<entryPoint declaringType="C1" methodName="Main" parameterNames="args"/>
<methods>
Expand Down Expand Up @@ -704,6 +715,7 @@ End Module
<symbols>
<files>
<file id="1" name="C:\abc\def.vb" language="VB"/>
<file id="2" name="a.vb" language="VB" checksumAlgorithm="SHA1" checksum="D2-FF-05-F8-B7-A2-25-B0-96-D9-97-2F-05-F8-F0-B5-81-8D-98-1D"/>
</files>
<entryPoint declaringType="Program" methodName="Main"/>
<methods>
Expand Down Expand Up @@ -757,6 +769,7 @@ End Class
<symbols>
<files>
<file id="1" name="C:\Folder1\Test2.vb" language="VB" checksumAlgorithm="406ea660-64cf-4c82-b6f0-42d48172a799" checksum="DB-78-88-82-72-1B-2B-27-C9-05-79-D5-FE-2A-04-18"/>
<file id="2" name="C:\Folder1\Folder2\Test1.vb" language="VB" checksumAlgorithm="SHA1" checksum="B9-49-3D-62-89-9B-B2-2F-B6-72-90-A1-2D-01-11-89-B4-C2-83-B4"/>
</files>
<methods>
<method containingType="Test1" name="Main">
Expand Down
65 changes: 65 additions & 0 deletions src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -4614,5 +4614,70 @@ End Class"
result.Diagnostics.Verify(Diagnostic(ERRID.FTL_InvalidInputFileName).WithArguments("test\\?.pdb").WithLocation(1, 1))
End Using
End Sub

<Fact>
<WorkItem(38954, "https://github.com/dotnet/roslyn/issues/38954")>
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("
<symbols>
<files>
<file id=""1"" name=""f:/build/goo.vb"" language=""VB"" checksumAlgorithm=""SHA1"" checksum=""48-27-3C-50-9D-24-D4-0D-51-87-6C-E2-FB-2F-AA-1C-80-96-0B-B7"" />
<file id=""2"" name=""f:/build/nocode.vb"" language=""VB"" checksumAlgorithm=""SHA1"" checksum=""40-43-2C-44-BA-1C-C7-1A-B3-F3-68-E5-96-7C-65-9D-61-85-D5-44"" />
</files>
<methods>
<method containingType=""C"" name=""Main"">
<sequencePoints>
<entry offset=""0x0"" startLine=""4"" startColumn=""5"" endLine=""4"" endColumn=""29"" document=""1"" />
<entry offset=""0x1"" startLine=""5"" startColumn=""9"" endLine=""5"" endColumn=""28"" document=""1"" />
<entry offset=""0x7"" startLine=""6"" startColumn=""5"" endLine=""6"" endColumn=""12"" document=""1"" />
</sequencePoints>
<scope startOffset=""0x0"" endOffset=""0x8"">
<namespace name=""System"" importlevel=""file"" />
<currentnamespace name="""" />
</scope>
</method>
</methods>
</symbols>
")
End Sub

<Fact>
<WorkItem(38954, "https://github.com/dotnet/roslyn/issues/38954")>
Public Sub SingleFileWithNoMethodBody()
Dim source =
"
' no code
"

Dim tree = Parse(source, "f:/build/nocode.vb")
Dim c = CreateCompilation({tree}, options:=TestOptions.DebugDll)

c.VerifyPdb("
<symbols>
<files>
<file id=""1"" name=""f:/build/nocode.vb"" language=""VB"" checksumAlgorithm=""SHA1"" checksum=""40-43-2C-44-BA-1C-C7-1A-B3-F3-68-E5-96-7C-65-9D-61-85-D5-44"" />
</files>
<methods />
</symbols>
")
End Sub
End Class
End Namespace