-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Enable embedding sources to Windows PDBs #21391
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c9dc666
Compare lines instead of using AssertXml when validating PDBs.
nguerrera 1f8565f
Reorder expected PDB XML nodes to match actual order
tmat 7c59af2
Update to the latest Microsoft.DiaSymReader.* packages.
tmat b6756c3
Enable embedding sources to Windows PDBs
tmat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
using Microsoft.CodeAnalysis.Emit; | ||
using Microsoft.CodeAnalysis.Test.Utilities; | ||
using Microsoft.CodeAnalysis.Text; | ||
using Microsoft.DiaSymReader; | ||
using Roslyn.Test.PdbUtilities; | ||
using Roslyn.Test.Utilities; | ||
using Roslyn.Utilities; | ||
using Xunit; | ||
|
@@ -1898,18 +1900,14 @@ public void Embed() | |
parsedArgs = DefaultParse(new[] { "/embed:a.txt", "/debug-", "a.cs" }, _baseDirectory); | ||
parsedArgs.Errors.Verify(Diagnostic(ErrorCode.ERR_CannotEmbedWithoutPdb)); | ||
|
||
// These should fail when native PDB support is added. | ||
parsedArgs = DefaultParse(new[] { "/embed", "/debug:full", "a.cs" }, _baseDirectory); | ||
parsedArgs.Errors.Verify(Diagnostic(ErrorCode.ERR_CannotEmbedWithoutPdb)); | ||
|
||
parsedArgs = DefaultParse(new[] { "/embed", "/debug:full", "a.cs" }, _baseDirectory); | ||
parsedArgs.Errors.Verify(Diagnostic(ErrorCode.ERR_CannotEmbedWithoutPdb)); | ||
parsedArgs.Errors.Verify(); | ||
|
||
parsedArgs = DefaultParse(new[] { "/embed", "/debug:pdbonly", "a.cs" }, _baseDirectory); | ||
parsedArgs.Errors.Verify(Diagnostic(ErrorCode.ERR_CannotEmbedWithoutPdb)); | ||
parsedArgs.Errors.Verify(); | ||
|
||
parsedArgs = DefaultParse(new[] { "/embed", "/debug+", "a.cs" }, _baseDirectory); | ||
parsedArgs.Errors.Verify(Diagnostic(ErrorCode.ERR_CannotEmbedWithoutPdb)); | ||
parsedArgs.Errors.Verify(); | ||
} | ||
|
||
[Theory] | ||
|
@@ -1921,7 +1919,7 @@ public void Embed() | |
[InlineData("/debug:embedded", "/embed:embed.cs", new[] { "embed.cs", "embed.xyz" })] | ||
[InlineData("/debug:embedded", "/embed:embed2.cs", new[] { "embed2.cs" })] | ||
[InlineData("/debug:embedded", "/embed:embed.xyz", new[] {"embed.xyz" })] | ||
public void Embed_EndToEnd(string debugSwitch, string embedSwitch, string[] expectedEmbedded) | ||
public void Embed_EndToEnd_Portable(string debugSwitch, string embedSwitch, string[] expectedEmbedded) | ||
{ | ||
// embed.cs: large enough to compress, has #line directives | ||
const string embed_cs = | ||
|
@@ -1981,14 +1979,32 @@ static void Main() { | |
int exitCode = csc.Run(output); | ||
Assert.Equal("", output.ToString().Trim()); | ||
Assert.Equal(0, exitCode); | ||
|
||
bool embedded = debugSwitch == "/debug:embedded"; | ||
|
||
switch (debugSwitch) | ||
{ | ||
case "/debug:embedded": | ||
ValidateEmbeddedSources_Portable(expectedEmbeddedMap, dir, isEmbeddedPdb: true); | ||
break; | ||
case "/debug:portable": | ||
ValidateEmbeddedSources_Portable(expectedEmbeddedMap, dir, isEmbeddedPdb: false); | ||
break; | ||
case "/debug:full": | ||
ValidateEmbeddedSources_Windows(expectedEmbeddedMap, dir); | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
} | ||
|
||
Assert.Empty(expectedEmbeddedMap); | ||
CleanupAllGeneratedFiles(src.Path); | ||
} | ||
|
||
private static void ValidateEmbeddedSources_Portable(Dictionary<string, string> expectedEmbeddedMap, TempDirectory dir, bool isEmbeddedPdb) | ||
{ | ||
using (var peReader = new PEReader(File.OpenRead(Path.Combine(dir.Path, "embed.exe")))) | ||
{ | ||
var entry = peReader.ReadDebugDirectory().SingleOrDefault(e => e.Type == DebugDirectoryEntryType.EmbeddedPortablePdb); | ||
Assert.Equal(embedded, entry.DataSize > 0); | ||
Assert.Equal(isEmbeddedPdb, entry.DataSize > 0); | ||
|
||
using (var mdProvider = embedded ? | ||
using (var mdProvider = isEmbeddedPdb ? | ||
peReader.ReadEmbeddedPortablePdbDebugDirectoryData(entry) : | ||
MetadataReaderProvider.FromPortablePdbStream(File.OpenRead(Path.Combine(dir.Path, "embed.pdb")))) | ||
{ | ||
|
@@ -2011,9 +2027,36 @@ static void Main() { | |
} | ||
} | ||
} | ||
} | ||
|
||
Assert.Empty(expectedEmbeddedMap); | ||
CleanupAllGeneratedFiles(src.Path); | ||
private static void ValidateEmbeddedSources_Windows(Dictionary<string, string> expectedEmbeddedMap, TempDirectory dir) | ||
{ | ||
ISymUnmanagedReader5 symReader = null; | ||
|
||
try | ||
{ | ||
symReader = SymReaderFactory.CreateReader(File.OpenRead(Path.Combine(dir.Path, "embed.pdb"))); | ||
|
||
foreach (var doc in symReader.GetDocuments()) | ||
{ | ||
var docPath = doc.GetName(); | ||
|
||
var sourceBlob = doc.GetEmbeddedSource(); | ||
if (sourceBlob.Array == null) | ||
{ | ||
continue; | ||
} | ||
|
||
var sourceStr = Encoding.UTF8.GetString(sourceBlob.Array, sourceBlob.Offset, sourceBlob.Count); | ||
|
||
Assert.Equal(expectedEmbeddedMap[docPath], sourceStr); | ||
Assert.True(expectedEmbeddedMap.Remove(docPath)); | ||
} | ||
} | ||
catch | ||
{ | ||
symReader?.Dispose(); | ||
} | ||
} | ||
|
||
[Fact] | ||
|
128 changes: 128 additions & 0 deletions
128
src/Compilers/CSharp/Test/Emit/PDB/PDBEmbeddedSourceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection.PortableExecutable; | ||
using Microsoft.CodeAnalysis.CSharp.Test.Utilities; | ||
using Microsoft.CodeAnalysis.Emit; | ||
using Microsoft.CodeAnalysis.Test.Utilities; | ||
using Microsoft.DiaSymReader; | ||
using Roslyn.Test.Utilities; | ||
using Xunit; | ||
|
||
namespace Microsoft.CodeAnalysis.CSharp.UnitTests.PDB | ||
{ | ||
public class PDBEmbeddedSourceTests : CSharpTestBase | ||
{ | ||
[Fact] | ||
public void StandalonePdb() | ||
{ | ||
string source1 = @" | ||
using System; | ||
class C | ||
{ | ||
public static void Main() | ||
{ | ||
Console.WriteLine(); | ||
} | ||
} | ||
"; | ||
string source2 = @" | ||
// no code | ||
"; | ||
|
||
var tree1 = Parse(source1, "f:/build/goo.cs"); | ||
var tree2 = Parse(source2, "f:/build/nocode.cs"); | ||
var c = CreateStandardCompilation(new[] { tree1, tree2 }, options: TestOptions.DebugDll); | ||
var embeddedTexts = new[] | ||
{ | ||
EmbeddedText.FromSource(tree1.FilePath, tree1.GetText()), | ||
EmbeddedText.FromSource(tree2.FilePath, tree2.GetText()) | ||
}; | ||
|
||
c.VerifyPdb(@" | ||
<symbols> | ||
<files> | ||
<file id=""1"" name=""f:/build/goo.cs"" language=""3f5162f8-07c6-11d3-9053-00c04fa302a1"" languageVendor=""994b45c4-e6e9-11d2-903f-00c04fa302a1"" documentType=""5a869d0b-6611-11d3-bd2a-0000f80849bd"" checkSumAlgorithmId=""ff1816ec-aa5e-4d10-87f7-6f4963833460"" checkSum=""5D, 7D, CF, 1B, 79, 12, E, A, 80, 13, E0, 98, 7E, 5C, AA, 3B, 63, D8, 7E, 4F, "" embeddedSourceLength=""98""><![CDATA[ | ||
using System; | ||
class C | ||
{ | ||
public static void Main() | ||
{ | ||
Console.WriteLine(); | ||
} | ||
} | ||
]]></file> | ||
<file id=""2"" name=""f:/build/nocode.cs"" language=""3f5162f8-07c6-11d3-9053-00c04fa302a1"" languageVendor=""994b45c4-e6e9-11d2-903f-00c04fa302a1"" documentType=""5a869d0b-6611-11d3-bd2a-0000f80849bd"" checkSumAlgorithmId=""ff1816ec-aa5e-4d10-87f7-6f4963833460"" checkSum=""8B, 1D, 3F, 75, E0, A8, 8F, 90, B2, D3, 52, CF, 71, 9B, 17, 29, 3C, 70, 7A, 42, "" embeddedSourceLength=""21""><![CDATA[ | ||
// no code | ||
]]></file> | ||
</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> | ||
", embeddedTexts); | ||
} | ||
|
||
[Fact] | ||
public void EmbeddedPdb() | ||
{ | ||
string source = @" | ||
using System; | ||
class C | ||
{ | ||
public static void Main() | ||
{ | ||
Console.WriteLine(); | ||
} | ||
} | ||
"; | ||
var tree = Parse(source, "f:/build/goo.cs"); | ||
var c = CreateStandardCompilation(tree, options: TestOptions.DebugDll); | ||
|
||
var pdbStream = new MemoryStream(); | ||
var peBlob = c.EmitToArray( | ||
EmitOptions.Default.WithDebugInformationFormat(DebugInformationFormat.Embedded), | ||
embeddedTexts: new[] { EmbeddedText.FromSource(tree.FilePath, tree.GetText()) }); | ||
pdbStream.Position = 0; | ||
|
||
using (var peReader = new PEReader(peBlob)) | ||
{ | ||
var embeddedEntry = peReader.ReadDebugDirectory().Single(e => e.Type == DebugDirectoryEntryType.EmbeddedPortablePdb); | ||
|
||
using (var embeddedMetadataProvider = peReader.ReadEmbeddedPortablePdbDebugDirectoryData(embeddedEntry)) | ||
{ | ||
var pdbReader = embeddedMetadataProvider.GetMetadataReader(); | ||
|
||
var embeddedSource = | ||
(from documentHandle in pdbReader.Documents | ||
let document = pdbReader.GetDocument(documentHandle) | ||
select new | ||
{ | ||
FilePath = pdbReader.GetString(document.Name), | ||
Text = pdbReader.GetEmbeddedSource(documentHandle) | ||
}).Single(); | ||
|
||
Assert.Equal(embeddedSource.FilePath, "f:/build/goo.cs"); | ||
Assert.Equal(source, embeddedSource.Text.ToString()); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll replace this with official bits once they are available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out VCTools are not being inserted into VS 15.5 yet. There won't be any official builds until next week. As long as we don't insert the private bits into VS (#21420 removes DSRN from insertion) it is ok to use them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the version of the native PDB writer that supports full determinism?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that change is in the branch I built from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you pull in the powershell change from this PR?
https://github.com/dotnet/roslyn/pull/20527/files
That should pass now and keep us clean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, let me do that in a separate PR. Determinism is not really related to this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. Don't worry about a second PR then. I'll just rebase mine against these changes once they're merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Have you seen my email to YongKang about PDBs not being deterministic when writing twice within the same process? Might affect compiler server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I saw that. It didn't seem to affect our tests for some reason. Maybe just got lucky. But definitely need to get that fixed before we declare it "done".