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

Automatically update local variable debug info #676

Merged
merged 4 commits into from
Jul 23, 2020

Conversation

vitek-karas
Copy link
Contributor

When manipulating the local variables collection on a method body, automatically update the debug info for all affected local variables.

When removing a local variable, also remove the debug info for that local variable from the scopes.

When removing or inserting update the indices of local variable debug infos which are afected by the action. Note the local variable debug info either holds just a backpointer to the local variable in which case it doesn't store the index at all (and thus nothing to do), or it stores the index explicitly in which case it needs to be updated.

Added tests for both insert and remove cases.

Fixes #674

/cc @marek-safar

When manipulating the local variables collection on a method body, automatically update the debug info for all affected local variables.

When removing a local variable, also remove the debug info for that local variable from the scopes.

When removing or inserting update the indeces of local variable debug infos which are afected by the action. Note the local variable debug info either holds just a backpointer to the local variable in which case it doesn't store the index at all (and thus nothing to do), or it stores the index explicitly in which case it needs to be updated.

Added tests for both insert and remove cases.
}

foreach (var variable in variables) {
if (variable.index.index.HasValue && variable.index.index.Value >= startIndex) {
Copy link
Owner

Choose a reason for hiding this comment

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

Because this looks a bit odd, I think we want to comment as to why we're doing this. In that case my understanding is that you want to update the indexes of variables that have not been resolved into a VariableDefinition, while a VariableIndex can represent both the resolved and not resolved case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hopefully the new version is more readable (and I also added a comment) - and it now also handles removal of resolved variable debug infos.

@jbevain
Copy link
Owner

jbevain commented Jun 25, 2020

Thanks, this looks good!

@jbevain
Copy link
Owner

jbevain commented Jun 25, 2020

Looking at this PR and the other one, one thing that would be neat is to add a internal property to InstructionOffset and VariableIndex, like bool IsResolved. This way you can have internal logic for the non resolved case, which you have in both PR, and access the relevant data without having to poke at the internals. That would avoid the .index.index access which does look weird.

…pulate it.

Reworked the `UpdateVariableIndeces` to only loop over variables once and also to handle removal of resolved variable debug infos.
@vitek-karas
Copy link
Contributor Author

I ended up adding two new internal properties (to both VariableIndex and InstructionOffset):

  • IsResolved per your suggestion
  • ResolvedVariable/ResolvedInstruction as the code still needs to be able to access the resolved reference to check for removal of the target.

@vitek-karas
Copy link
Contributor Author

@jbevain could you please let me know if the latest state of this PR and the friend in #677 is such that it will get merged sometime soon-ish? I'm trying to decide if we need to port it over to mono/cecil and use the fork there to ship the linker for .NET 5, or if we should keep using the cecil from this repo. (Without these fixes we are having trouble using the linker in the dotnet/runtime repo to build the libraries for .NET 5)

return;

foreach (var scope in debug_info.GetScopes ()) {
if (scope.HasVariables) {
Copy link
Owner

Choose a reason for hiding this comment

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

Please transform this condition into an early continue if there's no variable to reduce nesting.

@jbevain
Copy link
Owner

jbevain commented Jul 23, 2020

@vitek-karas yes, please just address the nitpick and this is good to go. Thanks for the contribution!

@jbevain jbevain merged commit 5e37f44 into jbevain:master Jul 23, 2020
@jbevain
Copy link
Owner

jbevain commented Jul 23, 2020

Thank you!

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.

Removing local variable from method body does not remove it from debug info
2 participants