jbevain / cecil

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

ILProcessor should also update custom debug info #867

Closed vitek-karas closed 2 years ago

vitek-karas commented 2 years ago

When editing IL with ILProcessor various pieces of debug information have references to the origin IL instructions. These references can be either resolved (point to Instruction instance), in which case the editing mostly works, or unresolved (store IL offset only) in which case they need to be resolved before the editing can occur (after the edit the original IL offsets are invalid and unresolvable).

This is effectively a continuation of https://github.com/jbevain/cecil/pull/687 which implemented this for local scopes. This change extends this to async method stepping info and state machine scopes.

The change refactors the code to make it easier to reuse the same logic between the various debug infos being processed.

Updated the existing tests from https://github.com/jbevain/cecil/pull/687 to include async and state machine debug info (completely made up) and validate that it gets updated correctly.

This is an upstream port of https://github.com/mono/cecil/pull/34

ltrzesniewski commented 2 years ago

Is there any chance this would fix https://github.com/Fody/Fody/issues/1110 (VS not being able to debug an assembly written by Cecil)?

vitek-karas commented 2 years ago

I don't think that the same problem. This problem (wrong custom debug info) has been in Cecil since forever it seems.

ltrzesniewski commented 2 years ago

We noticed it after updating Cecil to f7b64f7, it didn't happen in the previous version that Fody used (a0a6ce4). It may be due to #810 or #824.

(sorry for the off-topic message)