cecil
cecil copied to clipboard
Assembly roundtrip discards documents from portable PDB
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.
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:
- add something like
ModuleDebugInformation
to be able to expose some of the top-level metadata, like the documents table -
Document
would need to be tied to that, so that it could have methods that determine whether it's used (and by which sequence points, assuming only sequence points refer to documents) - provide a
DocumentCollection
that manages documents- this could include a
RemovedUnusedEntries()
method - a document specified on a sequence point should be from such a collection (else exception)
- removing a document here should then either also remove all sequence points that refer to it, or throw if there are such sequence points
- corollary: can't just move sequence points between modules anymore, because the sequence point would need to refer to a
Document
from the target module
- this could include a
That sounds like a lot of work to make sure it's all tracked correctly, with a potentially major impact.
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.