Skip to content

Commit

Permalink
Fix MdbWriter to produce the correct MVID in case deterministic outpu…
Browse files Browse the repository at this point in the history
…t is required (#681)

This is a fix for #680.

The MdbWriter must not cache the MVID upon writer construction, but it needs to get it only after it was computed - so basically only when it's about to actually write.
  • Loading branch information
vitek-karas authored Jul 21, 2020
1 parent c1a3c19 commit c5edadc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
10 changes: 5 additions & 5 deletions symbols/mdb/Mono.Cecil.Mdb/MdbWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ISymbolWriter GetSymbolWriter (ModuleDefinition module, string fileName)
Mixin.CheckModule (module);
Mixin.CheckFileName (fileName);

return new MdbWriter (module.Mvid, fileName);
return new MdbWriter (module, fileName);
}

public ISymbolWriter GetSymbolWriter (ModuleDefinition module, Stream symbolStream)
Expand All @@ -36,13 +36,13 @@ public ISymbolWriter GetSymbolWriter (ModuleDefinition module, Stream symbolStre

public sealed class MdbWriter : ISymbolWriter {

readonly Guid mvid;
readonly ModuleDefinition module;
readonly MonoSymbolWriter writer;
readonly Dictionary<string, SourceFile> source_files;

public MdbWriter (Guid mvid, string assembly)
public MdbWriter (ModuleDefinition module, string assembly)
{
this.mvid = mvid;
this.module = module;
this.writer = new MonoSymbolWriter (assembly);
this.source_files = new Dictionary<string, SourceFile> ();
}
Expand Down Expand Up @@ -169,7 +169,7 @@ public ImageDebugHeader GetDebugHeader ()

public void Dispose ()
{
writer.WriteSymbolFile (mvid);
writer.WriteSymbolFile (module.Mvid);
}

class SourceFile : ISourceFile {
Expand Down
16 changes: 16 additions & 0 deletions symbols/mdb/Test/Mono.Cecil.Tests/MdbTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Mono.Cecil.Cil;
using Mono.Cecil.Mdb;

using NUnit.Framework;
using System.IO;

namespace Mono.Cecil.Tests {

Expand Down Expand Up @@ -80,5 +82,19 @@ public void PartialClass ()

}, symbolReaderProvider: typeof(MdbReaderProvider), symbolWriterProvider: typeof(MdbWriterProvider));
}

[Test]
public void WriteAndReadAgainModuleWithDeterministicMvid ()
{
const string resource = "simplemdb.exe";
string destination = Path.GetTempFileName ();

using (var module = GetResourceModule (resource, new ReaderParameters { SymbolReaderProvider = new DefaultSymbolReaderProvider (true) })) {
module.Write (destination, new WriterParameters { WriteSymbols = true, DeterministicMvid = true });
}

using (var module = ModuleDefinition.ReadModule (destination, new ReaderParameters { SymbolReaderProvider = new DefaultSymbolReaderProvider (true) })) {
}
}
}
}

0 comments on commit c5edadc

Please sign in to comment.