Repository navigation
Automatically update local variable debug info #676
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
Changes from 1 commit
29c5b7e
3866928
3069f1f
94a308c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,7 +81,7 @@ public bool HasVariables { | |
| public Collection<VariableDefinition> Variables { | ||
| get { | ||
| if (variables == null) | ||
| Interlocked.CompareExchange (ref variables, new VariableDefinitionCollection (), null); | ||
| Interlocked.CompareExchange (ref variables, new VariableDefinitionCollection (this.method), null); | ||
|
|
||
| return variables; | ||
| } | ||
|
|
@@ -134,13 +134,17 @@ public ILProcessor GetILProcessor () | |
|
|
||
| sealed class VariableDefinitionCollection : Collection<VariableDefinition> { | ||
|
|
||
| internal VariableDefinitionCollection () | ||
| readonly MethodDefinition method; | ||
|
|
||
| internal VariableDefinitionCollection (MethodDefinition method) | ||
| { | ||
| this.method = method; | ||
| } | ||
|
|
||
| internal VariableDefinitionCollection (int capacity) | ||
| internal VariableDefinitionCollection (MethodDefinition method, int capacity) | ||
| : base (capacity) | ||
| { | ||
| this.method = method; | ||
| } | ||
|
|
||
| protected override void OnAdd (VariableDefinition item, int index) | ||
|
|
@@ -151,9 +155,7 @@ protected override void OnAdd (VariableDefinition item, int index) | |
| protected override void OnInsert (VariableDefinition item, int index) | ||
| { | ||
| item.index = index; | ||
|
|
||
| for (int i = index; i < size; i++) | ||
| items [i].index = i + 1; | ||
| UpdateVariableIndices (index, 1); | ||
| } | ||
|
|
||
| protected override void OnSet (VariableDefinition item, int index) | ||
|
|
@@ -163,10 +165,35 @@ protected override void OnSet (VariableDefinition item, int index) | |
|
|
||
| protected override void OnRemove (VariableDefinition item, int index) | ||
| { | ||
| UpdateVariableIndices (index + 1, -1, index); | ||
| item.index = -1; | ||
| } | ||
|
|
||
| for (int i = index + 1; i < size; i++) | ||
| items [i].index = i - 1; | ||
| void UpdateVariableIndices (int startIndex, int offset, int indexToRemove = -1) | ||
| { | ||
| for (int i = startIndex; i < size; i++) | ||
| items [i].index = i + offset; | ||
|
|
||
| var debug_info = method == null ? null : method.debug_info; | ||
| if (debug_info == null || debug_info.Scope == null) | ||
| return; | ||
|
|
||
| foreach (var scope in debug_info.GetScopes ()) { | ||
| if (scope.HasVariables) { | ||
| var variables = scope.Variables; | ||
| for (int i = 0; i < variables.Count; i++) { | ||
| if (variables [i].Index == indexToRemove) { | ||
| variables.RemoveAt (i); | ||
| } | ||
| } | ||
|
|
||
| foreach (var variable in variables) { | ||
| if (variable.index.index.HasValue && variable.index.index.Value >= startIndex) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| variable.index.index += offset; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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.