未验证 提交 304800ec 编写于 作者: D dotnet-automerge-bot 提交者: GitHub

Merge pull request #32892 from dotnet/merges/master-to-dev16.1-preview1

Merge master to dev16.1-preview1
......@@ -9,8 +9,7 @@
namespace Microsoft.CodeAnalysis.CSharp
{
/// <summary>
/// An analysis that computes the set of variables that may be used
/// before being assigned anywhere within a method.
/// An analysis that computes all cases where the address is taken of a variable that has not yet been assigned
/// </summary>
internal class UnassignedAddressTakenVariablesWalker : DefiniteAssignmentPass
{
......
......@@ -1626,7 +1626,7 @@ static void M()
}";
var compilation0 = CreateCompilation(source0, options: TestOptions.DebugDll);
var v0 = CompileAndVerify(compilation0);
var v0 = CompileAndVerify(compilation0, emitOptions: EmitOptions.Default);
v0.VerifyIL("C.M", @"
{
// Code size 93 (0x5d)
......@@ -2167,7 +2167,7 @@ static void M()
var compilation0 = CreateCompilation(source0, options: TestOptions.DebugDll);
var compilation1 = compilation0.WithSource(source1);
var v0 = CompileAndVerify(compilation0);
var v0 = CompileAndVerify(compilation0, emitOptions: EmitOptions.Default);
// Validate presence of a hidden sequence point @IL_0007 that is required for proper function remapping.
v0.VerifyIL("C.M", @"
......
......@@ -48,7 +48,8 @@ public static class CompilationExtensions
options = (options ?? EmitOptions.Default).WithDebugInformationFormat(DebugInformationFormat.PortablePdb);
}
pdbStream = new MemoryStream();
var discretePdb = (object)options != null && options.DebugInformationFormat != DebugInformationFormat.Embedded;
pdbStream = discretePdb ? new MemoryStream() : null;
}
var emitResult = compilation.Emit(
......
......@@ -6,6 +6,9 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using Microsoft.CodeAnalysis;
......@@ -42,7 +45,33 @@ internal struct EmitOutput
internal EmitOutput(ImmutableArray<byte> assembly, ImmutableArray<byte> pdb)
{
Assembly = assembly;
if (pdb.IsDefault)
{
// We didn't emit a discrete PDB file, so we'll look for an embedded PDB instead.
using (var peReader = new PEReader(Assembly))
{
DebugDirectoryEntry portablePdbEntry = peReader.ReadDebugDirectory().FirstOrDefault(e => e.Type == DebugDirectoryEntryType.EmbeddedPortablePdb);
if (portablePdbEntry.DataSize != 0)
{
using (var embeddedMetadataProvider = peReader.ReadEmbeddedPortablePdbDebugDirectoryData(portablePdbEntry))
{
var mdReader = embeddedMetadataProvider.GetMetadataReader();
pdb = readMetadata(mdReader);
}
}
}
}
Pdb = pdb;
unsafe ImmutableArray<byte> readMetadata(MetadataReader mdReader)
{
var length = mdReader.MetadataLength;
var bytes = new byte[length];
Marshal.Copy((IntPtr)mdReader.MetadataPointer, bytes, 0, length);
return ImmutableArray.Create(bytes);
}
}
}
......@@ -202,11 +231,22 @@ EmitOptions emitOptions
EmitOptions emitOptions
)
{
if (emitOptions is null)
{
emitOptions = EmitOptions.Default.WithDebugInformationFormat(DebugInformationFormat.Embedded);
}
using (var executableStream = new MemoryStream())
{
var pdb = default(ImmutableArray<byte>);
var assembly = default(ImmutableArray<byte>);
var pdbStream = new MemoryStream();
var pdbStream = (emitOptions.DebugInformationFormat != DebugInformationFormat.Embedded) ? new MemoryStream() : null;
var embeddedTexts = compilation.SyntaxTrees
.Select(t => (filePath: t.FilePath, text: t.GetText()))
.Where(t => t.text.CanBeEmbedded && !string.IsNullOrEmpty(t.filePath))
.Select(t => EmbeddedText.FromSource(t.filePath, t.text))
.ToImmutableArray();
EmitResult result;
try
......@@ -221,9 +261,9 @@ EmitOptions emitOptions
options: emitOptions,
debugEntryPoint: null,
sourceLinkStream: null,
embeddedTexts: null,
embeddedTexts,
testData: testData,
cancellationToken: default(CancellationToken));
cancellationToken: default);
}
finally
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册