Removing local variable from method body does not remove it from debug info #674

Closed
opened 2020-06-16 05:57:29 -05:00 by vitek-karas · 0 comments
vitek-karas commented 2020-06-16 05:57:29 -05:00 (Migrated from github.com)

Editing method body by removing one of the local variables does not update the attached debug information by removing debug info for the local variable. When saved the PDB still has the local variable information in it and some tools get confused (for example PDB2PDB writes out a warning).

I think the correct way to handle this would be to add logic into VariableDefinitionCollection.OnRemove to also remove the variable from the debug info (if it's there) by its index.

I don't think there's anything to do in OnAdd as adding VariableDefinition doesn't carry any information which should be preserved in the debug info (like the name of the variable). So not adding a debug info for the new variable seems to be OK.

Originally found in https://github.com/mono/linker/issues/1260.

I plan to work on the PR for this unless somebody wants to pick it up first.

Editing method body by removing one of the local variables does not update the attached debug information by removing debug info for the local variable. When saved the PDB still has the local variable information in it and some tools get confused (for example PDB2PDB writes out a warning). I think the correct way to handle this would be to add logic into [`VariableDefinitionCollection.OnRemove`](https://github.com/jbevain/cecil/blob/c1a3c199c31b76e3064316a5f24e176ca780b0af/Mono.Cecil.Cil/MethodBody.cs#L164) to also remove the variable from the debug info (if it's there) by its index. I don't think there's anything to do in `OnAdd` as adding `VariableDefinition` doesn't carry any information which should be preserved in the debug info (like the name of the variable). So not adding a debug info for the new variable seems to be OK. Originally found in https://github.com/mono/linker/issues/1260. I plan to work on the PR for this unless somebody wants to pick it up first.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-jbevain/cecil#674
No description provided.