jbevain / cecil

Cecil is a library to inspect, modify and create .NET programs and libraries.
MIT License
2.77k stars 630 forks source link

Assembly roundtrip discards documents from portable PDB #839

Open Zastai opened 2 years ago

Zastai commented 2 years ago

Compilation output will include all sources involved in the build as Document entries in the (portable) PDB.

This includes non-code sources, such as the AssemblyInfo.cs files generated by the build, for assembly/module attributes.

After loading an assembly with Mono.Cecil with symbol processing enabled and then writing it back, I observe that this has been reduced to a smaller set, presumably discarding any document that is not used by any sequence points.

I don't mind having methods like DiscardUnusedDocuments() available to "trim" debug info if I want to do so, but I would not expect that to happen by default. This discards potentially useful information.

Zastai commented 2 years ago

Of course, a document could be unused at write time because Cecil was used to remove some code and/or sequence points. In that case, those should probably be discarded. But ones that were present in the PDB before reaching Cecil should probably be retained (especially when source code is embedded as well).

One approach might be to:

That sounds like a lot of work to make sure it's all tracked correctly, with a potentially major impact.

jbevain commented 2 years ago

That sounds like a lot of work to make sure it's all tracked correctly, with a potentially major impact.

Yeah, that one is not going to be fun. Need to think about how best to approach it.