Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
24 changes: 24 additions & 0 deletions src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12044,6 +12044,30 @@ private struct S
CleanupAllGeneratedFiles(dir.Path);
}

[Fact]
public void RefOnly_EmbeddedDebugInformation()
{
var dir = Temp.CreateDirectory();
var src = dir.CreateFile("a.cs");
src.WriteAllText("public class C { }");

var outWriter = new StringWriter(CultureInfo.InvariantCulture);
var csc = CreateCSharpCompiler(null, dir.Path,
new[] { "/nologo", "/target:library", "/out:a.dll", "/refonly", "/debug:embedded", "/deterministic", "a.cs" });

Assert.Equal(0, csc.Run(outWriter));
Assert.Equal("", outWriter.ToString());

using (var peReader = new PEReader(File.OpenRead(Path.Combine(dir.Path, "a.dll"))))
{
AssertEx.Equal(
new[] { DebugDirectoryEntryType.Reproducible },
peReader.ReadDebugDirectory().Select(entry => entry.Type));
}
Comment on lines +12058 to +12066

CleanupAllGeneratedFiles(dir.Path);
}

[Fact]
public void CompilingCodeWithInvalidPreProcessorSymbolsShouldProvideDiagnostics()
{
Expand Down
29 changes: 25 additions & 4 deletions src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2709,19 +2709,40 @@ void verifyEmbeddedDebugInfo(MemoryStream stream, DebugDirectoryEntryType[] expe
}

[Fact]
public void EmitMetadataOnly_DisallowEmbeddingPdb()
public void EmitMetadataOnly_IgnoreEmbeddedPdb()
{
CSharpCompilation comp = CreateEmptyCompilation("", references: new[] { MscorlibRef },
options: TestOptions.DebugDll);
options: TestOptions.DebugDll.WithDeterministic(true));

using (var output = new MemoryStream())
{
Assert.Throws<ArgumentException>(() => comp.Emit(output,
var result = comp.Emit(output,
options: EmitOptions.Default.WithEmitMetadataOnly(true)
.WithDebugInformationFormat(DebugInformationFormat.Embedded)));
.WithDebugInformationFormat(DebugInformationFormat.Embedded));

Assert.True(result.Success);
using var peReader = new PEReader(output.ToImmutable());
AssertEx.Equal(
new[] { DebugDirectoryEntryType.Reproducible },
peReader.ReadDebugDirectory().Select(entry => entry.Type));
}
}

[Fact]
public void EmitMetadataOnly_IgnorePdb()
{
CSharpCompilation comp = CreateEmptyCompilation("", references: new[] { MscorlibRef },
options: TestOptions.DebugDll.WithDeterministic(true));

var output = comp.EmitToArray(
EmitOptions.Default.WithEmitMetadataOnly(true).WithDebugInformationFormat(DebugInformationFormat.Pdb));

using var peReader = new PEReader(output);
AssertEx.Equal(
new[] { DebugDirectoryEntryType.Reproducible },
peReader.ReadDebugDirectory().Select(entry => entry.Type));
}

[Fact]
public void EmitMetadata()
{
Expand Down
3 changes: 0 additions & 3 deletions src/Compilers/Core/Portable/CodeAnalysisResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,6 @@
<data name="IncludingPrivateMembersUnexpectedWhenEmittingToMetadataPeStream" xml:space="preserve">
<value>Including private members should not be used when emitting to the secondary assembly output.</value>
</data>
<data name="EmbeddingPdbUnexpectedWhenEmittingMetadata" xml:space="preserve">
<value>Embedding PDB is not allowed when emitting metadata.</value>
</data>
<data name="CannotTargetNetModuleWhenEmittingRefAssembly" xml:space="preserve">
<value>Cannot target net module when emitting ref assembly.</value>
</data>
Expand Down
5 changes: 3 additions & 2 deletions src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,7 @@ private void CompileAndEmit(
diagnostics.Add(MessageProvider.CreateDiagnostic(MessageProvider.FTL_InvalidInputFileName, Location.None, finalPdbFilePath));
}

bool emitPdb = Arguments.EmitPdb && !emitOptions.EmitMetadataOnly;
Comment thread
jaredpar marked this conversation as resolved.
Resolved
var moduleBeingBuilt = compilation.CheckOptionsAndCreateModuleBuilder(
diagnostics,
Arguments.ManifestResources,
Expand All @@ -1338,7 +1339,7 @@ private void CompileAndEmit(
{
success = compilation.CompileMethods(
moduleBeingBuilt,
Arguments.EmitPdb,
emitPdb,
diagnostics,
filterOpt: null,
cancellationToken: cancellationToken);
Expand Down Expand Up @@ -1457,7 +1458,7 @@ private void CompileAndEmit(
if (success)
{
var peStreamProvider = new CompilerEmitStreamProvider(this, finalPeFilePath);
var pdbStreamProviderOpt = Arguments.EmitPdbFile ? new CompilerEmitStreamProvider(this, finalPdbFilePath) : null;
var pdbStreamProviderOpt = emitPdb && Arguments.EmitPdbFile ? new CompilerEmitStreamProvider(this, finalPdbFilePath) : null;

string? finalRefPeFilePath = Arguments.OutputRefFilePath;
var refPeStreamProviderOpt = finalRefPeFilePath != null ? new CompilerEmitStreamProvider(this, finalRefPeFilePath) : null;
Expand Down
19 changes: 10 additions & 9 deletions src/Compilers/Core/Portable/Compilation/Compilation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2887,12 +2887,6 @@ internal EmitResult Emit(
options = options.WithIncludePrivateMembers(true);
}

if (options?.DebugInformationFormat == DebugInformationFormat.Embedded &&
options?.EmitMetadataOnly == true)
Comment thread
jaredpar marked this conversation as resolved.
Resolved
{
throw new ArgumentException(CodeAnalysisResources.EmbeddingPdbUnexpectedWhenEmittingMetadata, nameof(metadataPEStream));
Comment thread
jaredpar marked this conversation as resolved.
Resolved
}

if (this.Options.OutputKind == OutputKind.NetModule)
{
if (metadataPEStream != null)
Expand Down Expand Up @@ -2964,6 +2958,7 @@ internal EmitResult Emit(
options = options ?? EmitOptions.Default.WithIncludePrivateMembers(metadataPEStream == null);

bool embedPdb = options.DebugInformationFormat == DebugInformationFormat.Embedded;
bool emitPdb = !options.EmitMetadataOnly && (pdbStream != null || embedPdb);
Debug.Assert(!embedPdb || pdbStream == null);
Debug.Assert(metadataPEStream == null || !options.IncludePrivateMembers); // you may not use a secondary stream and include private members together

Expand All @@ -2989,7 +2984,7 @@ internal EmitResult Emit(
{
success = CompileMethods(
moduleBeingBuilt,
emittingPdb: pdbStream != null || embedPdb,
emittingPdb: emitPdb,
diagnostics: diagnostics,
filterOpt: null,
cancellationToken: cancellationToken);
Expand Down Expand Up @@ -3038,7 +3033,7 @@ internal EmitResult Emit(
moduleBeingBuilt,
new SimpleEmitStreamProvider(peStream),
(metadataPEStream != null) ? new SimpleEmitStreamProvider(metadataPEStream) : null,
(pdbStream != null) ? new SimpleEmitStreamProvider(pdbStream) : null,
(emitPdb && pdbStream != null) ? new SimpleEmitStreamProvider(pdbStream) : null,
rebuildData,
testData?.SymWriterFactory,
diagnostics,
Expand Down Expand Up @@ -3271,10 +3266,16 @@ internal bool SerializeToPeStream(

// PDB Stream provider should not be given if PDB is to be embedded into the PE file:
Debug.Assert(moduleBeingBuilt.DebugInformationFormat != DebugInformationFormat.Embedded || pdbStreamProvider == null);
Debug.Assert(!emitOptions.EmitMetadataOnly || pdbStreamProvider == null);

string? pePdbFilePath = emitOptions.PdbFilePath;

if (moduleBeingBuilt.DebugInformationFormat == DebugInformationFormat.Embedded || pdbStreamProvider != null)
if (emitOptions.EmitMetadataOnly)
{
// Metadata-only output has no associated PDB. Clear the path so the PE writer doesn't emit a CodeView entry.
pePdbFilePath = null;
}
Comment thread
jaredpar marked this conversation as resolved.
Resolved
else if (moduleBeingBuilt.DebugInformationFormat == DebugInformationFormat.Embedded || pdbStreamProvider != null)
{
pePdbFilePath = pePdbFilePath ?? FileNameUtilities.ChangeExtension(SourceModule.Name, "pdb");
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ internal static ImmutableArray<byte> EmitToArray(
{
var peStream = new MemoryStream();

if (pdbStream == null && compilation.Options.OptimizationLevel == OptimizationLevel.Debug && options?.DebugInformationFormat != DebugInformationFormat.Embedded)
if (pdbStream == null &&
compilation.Options.OptimizationLevel == OptimizationLevel.Debug &&
options?.EmitMetadataOnly != true &&
options?.DebugInformationFormat != DebugInformationFormat.Embedded)
{
if (MonoHelpers.IsRunningOnMono() || PathUtilities.IsUnixLikePlatform)
{
Expand Down
Loading