Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing unused branches corrupts local scopes in the debugger information #1267

Closed
vitek-karas opened this issue Jun 11, 2020 · 2 comments
Closed

Comments

@vitek-karas
Copy link
Member

Repro:
Unzip PreTrim.zip which contains the pre-trim S.P.CoreLib.
Run linker with this command line linker.rsp.txt (adapt the paths to local ones).

The problem is in method System.Globalization.CharUnicodeInfo.GetNumericValueNoBoundsCheck. The method has two scopes the scope for the entire method and then a nested scope for the last branch (everything after the if).

With the embedded substitutions in the repro dll the last branch is going to be removed (as IsLittleEndian is set to true always). The RemoveUnreachableBlocksStep will remove the instructions at the end of the body, but it will not remove the associated nested scope. This causes problems with the PDB because it now contains scope which is outside of the method body (the scope starts at index 41, but the method body length is 40).

In the end Cecil will write the scope into the PDB with start offset 41 and length -1 -> the -1 is very problematic and will cause "crashes" in subsequent tools.

@vitek-karas
Copy link
Member Author

Cleaner way to fix this would be in Cecil itself. InstructionCollection.OnRemove already implements cleanup for sequence points, it should also implement cleanup/fixups for local scopes.

Somewhat more interesting question is what should happen in InstructionCollection.OnAdd if the insertion is on a local scope boundary. This is not needed for linker (yet?), but if the fix is done in Cecil should probably be done as part of the change.

@marek-safar
Copy link
Contributor

Fixed in master and 5.0 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants