Skip to content
/ cecil Public
forked from jbevain/cecil
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

ILProcessor should also update custom debug info #34

Merged
merged 3 commits into from
Jun 23, 2022

Conversation

vitek-karas
Copy link
Member

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 editting mostly works, or unresolved (store IL offset only) in which case they need to be resolved before the editting can occur (after the edit the original IL offsets are invalid and unresolvable).

This is effectively a continuation of jbevain#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 jbevain#687 to include async and state machine debug info (completely made up) and validate that it gets updated correctly.

When eidting 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 editting mostly works, or unresolved (store IL offset only) in which case they need to be resolved before the editting can occur (after the edit the original IL offsets are invalid and unresolvable).

This is effectively a continuation of jbevain#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 jbevain#687 to include async and state machine debug info (completely made up) and validate that it gets updated correctly.
@vitek-karas
Copy link
Member Author

@agocke @sbomer could you please take a look (I can't request official review on this repo)

This is a fix for the problem reported in dotnet/runtime#70720 (comment).

I verified that it fixes that problem.

The plan is to merge it to mono/cecil (and update linker with it - hopefully "soon", maybe even for P6?)
Then send a PR upstream.

Mono.Cecil.Cil/MethodBody.cs Outdated Show resolved Hide resolved

UpdateLocalScope (debug_info.Scope, removedInstruction, existingInstruction, ref cache);
if (method.debug_info != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this check different from the one 30 lines above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad - the one above should not be there anymore (I added this one and wanted to remove the one above, but forgot).


var customDebugInfo = method.custom_infos ?? method.debug_info?.custom_infos;
if (customDebugInfo != null) {
foreach (var custom_debug_info in customDebugInfo) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct in that this is basically the only interesting change -- also walk the state machine and async method infos, instead of just the local scope?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - that's the gist of it.
The rest is mainly refactoring to reuse the same code which was used only for the local scopes.

Renamed some parameters/locals to better match the existing code style.
@@ -306,12 +306,8 @@ void RemoveSequencePoint (Instruction instruction)
}
}

void UpdateDebugInformation (Instruction removedInstruction, Instruction existingInstruction)
void UpdateDebugInformation (Instruction removed_instruction, Instruction existing_instruction)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why to change the parameter names, seems the file uses normal C# parameters casing style?

Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@marek-safar marek-safar merged commit c74bbee into dotnet:main Jun 23, 2022
vitek-karas added a commit to vitek-karas/linker that referenced this pull request Jun 23, 2022
marek-safar pushed a commit to dotnet/linker that referenced this pull request Jun 23, 2022
@vitek-karas vitek-karas deleted the UpdateCustomDebugInfo branch June 29, 2022 13:58
marek-safar pushed a commit that referenced this pull request Oct 6, 2022
* ILProcessor should also update custom debug info (#34)

* ILProcessor should also update custom debug info

When eidting 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 editting mostly works, or unresolved (store IL offset only) in which case they need to be resolved before the editting can occur (after the edit the original IL offsets are invalid and unresolvable).

This is effectively a continuation of jbevain#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 jbevain#687 to include async and state machine debug info (completely made up) and validate that it gets updated correctly.

* PR Feedback

Renamed some parameters/locals to better match the existing code style.

* PR Feedback

* Fix test on Linux

Native PDB is not supported on Linux and the test infra falls back to portable PDB automatically. Since the two PDB implementations read the custom debug info from a different place the test constructing the input needs to adapt to this difference as well.
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants