Skip to content

Commit 3136847

Browse files
authored
Preserve Documents debug info (#965)
* Preserve Documents * Target net6.0 To remove reference to RefSafetyRulesAttribute * Target .NET Framework To avoid references to System.Runtime
1 parent f1c428a commit 3136847

File tree

7 files changed

+49
-0
lines changed

7 files changed

+49
-0
lines changed

Mono.Cecil.Cil/PortablePdb.cs

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ static int ReadInt32 (byte [] bytes, int start)
119119
void ReadModule ()
120120
{
121121
module.custom_infos = debug_reader.GetCustomDebugInformation (module);
122+
module.documents = debug_reader.GetDocuments ();
122123
}
123124

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

297298
pdb_metadata.AddCustomDebugInformations (module);
299+
pdb_metadata.AddDocuments (module);
298300
}
299301

300302
internal PortablePdbWriter (MetadataBuilder pdb_metadata, ModuleDefinition module, ImageWriter writer, Disposable<Stream> final_stream)

Mono.Cecil/AssemblyReader.cs

+7
Original file line numberDiff line numberDiff line change
@@ -2834,6 +2834,13 @@ void InitializeDocuments ()
28342834
}
28352835
}
28362836

2837+
internal Collection<Document> GetDocuments ()
2838+
{
2839+
InitializeDocuments ();
2840+
2841+
return new Collection<Document> (metadata.Documents);
2842+
}
2843+
28372844
public Collection<SequencePoint> ReadSequencePoints (MethodDefinition method)
28382845
{
28392846
InitializeDocuments ();

Mono.Cecil/AssemblyWriter.cs

+11
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,17 @@ void AddSecurityDeclarations (ISecurityDeclarationProvider owner)
20132013
}
20142014
}
20152015

2016+
internal void AddDocuments (ModuleDefinition module)
2017+
{
2018+
if (module.HasDocuments)
2019+
{
2020+
var documents = module.Documents;
2021+
for (int i = 0; i < documents.Count; i++) {
2022+
GetDocumentToken (documents[i]);
2023+
}
2024+
}
2025+
}
2026+
20162027
MetadataToken GetMemberRefToken (MemberReference member)
20172028
{
20182029
var row = CreateMemberRefRow (member);

Mono.Cecil/ModuleDefinition.cs

+16
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ public sealed class ModuleDefinition : ModuleReference, ICustomAttributeProvider
273273
TypeDefinitionCollection types;
274274

275275
internal Collection<CustomDebugInformation> custom_infos;
276+
internal Collection<Document> documents;
276277

277278
internal MetadataBuilder metadata_builder;
278279

@@ -572,6 +573,21 @@ public Collection<CustomDebugInformation> CustomDebugInformations {
572573
}
573574
}
574575

576+
internal bool HasDocuments {
577+
get {
578+
return documents != null && documents.Count > 0;
579+
}
580+
}
581+
582+
internal Collection<Document> Documents {
583+
get {
584+
if (documents == null)
585+
Interlocked.CompareExchange (ref documents, new Collection<Document> (), null);
586+
587+
return documents;
588+
}
589+
}
590+
575591
internal ModuleDefinition ()
576592
{
577593
this.MetadataSystem = new MetadataSystem ();

Test/Mono.Cecil.Tests/PortablePdbTests.cs

+13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ namespace Mono.Cecil.Tests {
1515
[TestFixture]
1616
public class PortablePdbTests : BaseTestFixture {
1717

18+
[Test]
19+
public void Documents ()
20+
{
21+
TestModule ("DocumentsTestTarget.dll", module => {
22+
var documents = module.Documents;
23+
Assert.AreEqual(1, documents.Count);
24+
var document = documents[0];
25+
Assert.IsNotNull (document);
26+
Assert.AreEqual ("/_/DocumentsTestTarget.cs", document.Url);
27+
Assert.AreEqual (DocumentLanguage.CSharp, document.Language);
28+
}, symbolReaderProvider: typeof(PortablePdbReaderProvider), symbolWriterProvider: typeof(PortablePdbWriterProvider));
29+
}
30+
1831
[Test]
1932
public void SequencePoints ()
2033
{
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)