Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pdb checksum debug headers #617

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
27 changes: 20 additions & 7 deletions Mono.Cecil.Cil/PortablePdb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,14 @@ void CheckMethodDebugInformationTable ()
}

public void Dispose ()
{
if (IsEmbedded)
return;

writer.stream.Dispose ();
}

public void Write ()
{
if (IsEmbedded)
return;
Expand All @@ -348,7 +356,6 @@ void WritePdbFile ()
writer.WriteMetadata ();

writer.Flush ();
writer.stream.Dispose ();
}

void WritePdbHeap ()
Expand Down Expand Up @@ -425,8 +432,6 @@ public ISymbolReaderProvider GetReaderProvider ()

public ImageDebugHeader GetDebugHeader ()
{
writer.Dispose ();

var directory = new ImageDebugDirectory {
Type = ImageDebugType.EmbeddedPortablePdb,
MajorVersion = 0x0100,
Expand All @@ -450,19 +455,27 @@ public ImageDebugHeader GetDebugHeader ()

directory.SizeOfData = (int) data.Length;

return new ImageDebugHeader (new [] {
writer.GetDebugHeader ().Entries [0],
new ImageDebugHeaderEntry (directory, data.ToArray ())
});
var header = writer.GetDebugHeader ();
var entries = new ImageDebugHeaderEntry [header.Entries.Length + 1];
Array.Copy (header.Entries, 0, entries, 0, header.Entries.Length);
entries [entries.Length - 1] = new ImageDebugHeaderEntry (directory, data.ToArray ());

return new ImageDebugHeader (entries);
}

public void Write (MethodDebugInformation info)
{
writer.Write (info);
}

public void Write ()
{
writer.Write ();
}

public void Dispose ()
{
writer.Dispose ();
}
}

Expand Down
2 changes: 2 additions & 0 deletions Mono.Cecil.Cil/Symbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public enum ImageDebugType {
CodeView = 2,
Deterministic = 16,
EmbeddedPortablePdb = 17,
PdbChecksum = 19,
}

public sealed class ImageDebugHeader {
Expand Down Expand Up @@ -1015,6 +1016,7 @@ public interface ISymbolWriter : IDisposable {
ISymbolReaderProvider GetReaderProvider ();
ImageDebugHeader GetDebugHeader ();
void Write (MethodDebugInformation info);
void Write ();
}

public interface ISymbolWriterProvider {
Expand Down
3 changes: 3 additions & 0 deletions Mono.Cecil/AssemblyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ static void Write (ModuleDefinition module, Disposable<Stream> stream, WriterPar
if (parameters.DeterministicMvid)
metadata.ComputeDeterministicMvid ();

if (symbol_writer != null)
symbol_writer.Write ();

var writer = ImageWriter.CreateWriter (module, metadata, stream);
stream.value.SetLength (0);
writer.WriteImage ();
Expand Down
5 changes: 5 additions & 0 deletions Test/Mono.Cecil.Tests/PortablePdbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,11 @@ public void Write (MethodDebugInformation info)
symbol_writer.Write (info);
}

public void Write ()
{
symbol_writer.Write ();
}

public void Dispose ()
{
symbol_writer.Dispose ();
Expand Down
6 changes: 5 additions & 1 deletion symbols/mdb/Mono.Cecil.Mdb/MdbWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,15 @@ public ImageDebugHeader GetDebugHeader ()
return new ImageDebugHeader ();
}

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

public void Dispose ()
{
}

class SourceFile : ISourceFile {

readonly CompileUnitEntry compilation_unit;
Expand Down
17 changes: 12 additions & 5 deletions symbols/pdb/Mono.Cecil.Pdb/NativePdbWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class NativePdbWriter : ISymbolWriter {
readonly Dictionary<string, SymDocumentWriter> documents;
readonly Dictionary<ImportDebugInformation, MetadataToken> import_info_to_parent;

ImageDebugDirectory debug_directory;
byte [] debug_info;

internal NativePdbWriter (ModuleDefinition module, SymWriter writer)
{
this.module = module;
Expand All @@ -44,10 +47,7 @@ public ISymbolReaderProvider GetReaderProvider ()

public ImageDebugHeader GetDebugHeader ()
{
ImageDebugDirectory directory;
var data = writer.GetDebugInfo (out directory);
directory.TimeDateStamp = (int) module.timestamp;
return new ImageDebugHeader (new ImageDebugHeaderEntry (directory, data));
return new ImageDebugHeader (new ImageDebugHeaderEntry (debug_directory, debug_info));
}

public void Write (MethodDebugInformation info)
Expand Down Expand Up @@ -253,14 +253,21 @@ SymDocumentWriter GetDocument (Document document)
return doc_writer;
}

public void Dispose ()
public void Write ()
{
var entry_point = module.EntryPoint;
if (entry_point != null)
writer.SetUserEntryPoint (entry_point.MetadataToken.ToInt32 ());

debug_info = writer.GetDebugInfo (out debug_directory);
debug_directory.TimeDateStamp = (int) module.timestamp;

writer.Close ();
}

public void Dispose ()
{
}
}

enum CustomMetadataType : byte {
Expand Down