Skip to content

Commit

Permalink
Embedded PDB do not need streams (#220)
Browse files Browse the repository at this point in the history
When building with embedded PDBs the `Emit*` methods were incorrectly
passing a `Stream` for the PDB. That is not needed as the PDB is written
into the PE file directly
  • Loading branch information
jaredpar authored Feb 21, 2025
1 parent 93a36f0 commit 32b8477
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Basic.CompilerLog.UnitTests/CompilerLogFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ End Module
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DebugType>embedded</DebugType>
<EmbedAllSources>true</EmbedAllSources>
<CodeAnalysisRuleset>{scratchPath}\example.ruleset</CodeAnalysisRuleset>
<Win32Manifest>resource.txt</Win32Manifest>
Expand Down
3 changes: 2 additions & 1 deletion src/Basic.CompilerLog.UnitTests/UsingAllCompilerLogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Text;
using Xunit;

Expand Down Expand Up @@ -73,7 +74,7 @@ public async Task EmitToDisk()
Assert.NotEmpty(emitResult.AssemblyFilePath);

var emitFlags = data.EmitFlags;
if ((emitFlags & EmitFlags.IncludePdbStream) != 0)
if ((emitFlags & EmitFlags.IncludePdbStream) != 0 && data.EmitOptions.DebugInformationFormat != DebugInformationFormat.Embedded)
{
Assert.NotNull(emitResult.PdbFilePath);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Basic.CompilerLog.Util/CodeAnalysisExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static EmitMemoryResult EmitToMemory(
MemoryStream? xmlStream = null;
MemoryStream? metadataStream = null;

if ((emitFlags & EmitFlags.IncludePdbStream) != 0)
if ((emitFlags & EmitFlags.IncludePdbStream) != 0 && emitOptions.DebugInformationFormat != DebugInformationFormat.Embedded)
{
pdbStream = new MemoryStream();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Basic.CompilerLog.Util/CompilationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public EmitDiskResult EmitToDisk(string directory, EmitFlags emitFlags, EmitOpti
{
peStream = OpenFile(assemblyFilePath);

if ((emitFlags & EmitFlags.IncludePdbStream) != 0)
if ((emitFlags & EmitFlags.IncludePdbStream) != 0 && emitOptions.DebugInformationFormat != DebugInformationFormat.Embedded)
{
pdbFilePath = Path.Combine(directory, Path.ChangeExtension(assemblyName, ".pdb"));
pdbStream = OpenFile(pdbFilePath);
Expand Down
1 change: 1 addition & 0 deletions src/Basic.CompilerLog/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
{
WriteLine("Unexpected error");
WriteLine(e.Message);
WriteLine(e.StackTrace!);
RunHelp(null);
return ExitFailure;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Scratch/Scratch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Reflection;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Threading.Tasks;
using Basic.CompilerLog;
using Basic.CompilerLog.Util;
Expand All @@ -25,10 +26,8 @@

#pragma warning disable 8321

var zipFilePath = @"C:\Users\jaredpar\Downloads\msbuild_logs.zip";
//using var reader = CompilerLogReader.Create(zipFilePath);
RunComplog($"print -c {zipFilePath}");

RunComplog(@$"replay C:\Users\jaredpar\Downloads\msbuild.complog");


/*
Expand Down

0 comments on commit 32b8477

Please sign in to comment.