-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable embedding sources to Windows PDBs
- Loading branch information
Showing
22 changed files
with
445 additions
and
246 deletions.
There are no files selected for viewing
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
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()); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
6 changes: 3 additions & 3 deletions
6
src/Compilers/Core/Portable/CodeAnalysisResources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.