Removing instruction from method body can corrupt local scopes debug info #675
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Removing an instruction from method body currently doesn't update the attached debug information's local scope ranges. This can lead to incorrect or even corrupt debug information.
An example is removing instructions from the end of the method eventually removing enough so that the last local scope in the method should be removed. When such method is written the associated PDB still has the last local scope in it, but now its start offset points after the method body end. Depending on the reader this can lead to either confusion or plain crashes.
For example the PDB2PDB tool (which uses System.Reflection.Metadata reader for the portable PDB) will either fail to read or fail to process such PDB.
InstructionCollection.OnRemovealready contains logic to update sequence points in the debug info accordingly. This can be updated to handle local scopes as well.More complex problem is how to handle
OnAddandOnInsert. If the instruction is being inserted on a local scope boundary it's unclear to which scope it should fall into. The implemented behavior should works such thatILProcessor.Replacewhich internally inserts after and removes ends up updating the local scopes correctly (so that the replaced instruction ends up in the same local scope and the start/end of local scopes don't move around).Originally found in https://github.com/mono/linker/issues/1267
I plan to work on a PR for this unless somebody wants to pick it up first.