Skip to content
/ cecil Public
forked from jbevain/cecil
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

Preserve Documents debug info #270

Open
wants to merge 1 commit into
base: main
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
2 changes: 2 additions & 0 deletions Mono.Cecil.Cil/PortablePdb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ static int ReadInt32 (byte [] bytes, int start)
void ReadModule ()
{
module.custom_infos = debug_reader.GetCustomDebugInformation (module);
module.documents = debug_reader.GetDocuments ();
}

public MethodDebugInformation Read (MethodDefinition method)
Expand Down Expand Up @@ -295,6 +296,7 @@ internal PortablePdbWriter (MetadataBuilder pdb_metadata, ModuleDefinition modul
this.pdb_metadata.metadata_builder = this.module_metadata;

pdb_metadata.AddCustomDebugInformations (module);
pdb_metadata.AddDocuments (module);
}

internal PortablePdbWriter (MetadataBuilder pdb_metadata, ModuleDefinition module, ImageWriter writer, Disposable<Stream> final_stream)
Expand Down
7 changes: 7 additions & 0 deletions Mono.Cecil/AssemblyReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2834,6 +2834,13 @@ void InitializeDocuments ()
}
}

internal Collection<Document> GetDocuments ()
{
InitializeDocuments ();

return new Collection<Document> (metadata.Documents);
}

public Collection<SequencePoint> ReadSequencePoints (MethodDefinition method)
{
InitializeDocuments ();
Expand Down
11 changes: 11 additions & 0 deletions Mono.Cecil/AssemblyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,17 @@ void AddSecurityDeclarations (ISecurityDeclarationProvider owner)
}
}

internal void AddDocuments (ModuleDefinition module)
{
if (module.HasDocuments)
{
var documents = module.Documents;
for (int i = 0; i < documents.Count; i++) {
GetDocumentToken (documents[i]);
}
}
}

MetadataToken GetMemberRefToken (MemberReference member)
{
var row = CreateMemberRefRow (member);
Expand Down
16 changes: 16 additions & 0 deletions Mono.Cecil/ModuleDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ public sealed class ModuleDefinition : ModuleReference, ICustomAttributeProvider
TypeDefinitionCollection types;

internal Collection<CustomDebugInformation> custom_infos;
internal Collection<Document> documents;

internal MetadataBuilder metadata_builder;

Expand Down Expand Up @@ -601,6 +602,21 @@ public Collection<CustomDebugInformation> CustomDebugInformations {
}
}

internal bool HasDocuments {
get {
return documents != null && documents.Count > 0;
}
}

internal Collection<Document> Documents {
get {
if (documents == null)
Interlocked.CompareExchange (ref documents, new Collection<Document> (), null);

return documents;
}
}

internal ModuleDefinition ()
{
this.MetadataSystem = new MetadataSystem ();
Expand Down
13 changes: 13 additions & 0 deletions Test/Mono.Cecil.Tests/PortablePdbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ namespace Mono.Cecil.Tests {
[TestFixture]
public class PortablePdbTests : BaseTestFixture {

[Test]
public void Documents ()
{
TestModule ("DocumentsTestTarget.dll", module => {
var documents = module.Documents;
Assert.AreEqual(1, documents.Count);
var document = documents[0];
Assert.IsNotNull (document);
Assert.AreEqual ("/_/DocumentsTestTarget.cs", document.Url);
Assert.AreEqual (DocumentLanguage.CSharp, document.Language);
}, symbolReaderProvider: typeof(PortablePdbReaderProvider), symbolWriterProvider: typeof(PortablePdbWriterProvider));
}

[Test]
public void SequencePoints ()
{
Expand Down
Binary file not shown.
Binary file added Test/Resources/assemblies/DocumentsTestTarget.pdb
Binary file not shown.