You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Notice the different order of variable names in the Use(X) statements. Looking at the types of variables makes the issue apparent too. It seems like ILSpy is shuffling around the names of the variables.
After some debugging, it turns out that the AssignVariableNames stage is at fault here. It processes the variables in the order returned by OrderBy(v => v.Name). When the stage encounters a non-synthetic variable it triggers this code path:
// don't use the name from the debug symbols if it looks like a generated name
v.Name=null;
}
else
{
// use the name from the debug symbols
// (but ensure we don't use the same name for two variables)
v.Name=GetAlternativeName(v.Name);
}
For the non-synthetic variables in this file the else block is triggered and a call to GetAlternativeName is made. This call is responsible for the change of F10 to F2 etc. This method uses an assignment algorithm that increments the number at the end of the variable and since the variables are processed in order returned by OrderBy(v => v.Name), F1 will be processed first, F10 next, F11, F12 etc. which causes the variable names to become incorrect.
In my opinion, the order should not really be the thing to worry about here but rather the approach the variable name assigner takes for local variables where the names are almost certainly what the user would want them to be and the processing of them should probably be restricted to validation of them and escaping strange characters in case of obfuscated PDB files.
Input code
Erroneous output
Notice the different order of variable names in the
Use(X)
statements. Looking at the types of variables makes the issue apparent too. It seems like ILSpy is shuffling around the names of the variables.After some debugging, it turns out that the
AssignVariableNames
stage is at fault here. It processes the variables in the order returned byOrderBy(v => v.Name)
. When the stage encounters a non-synthetic variable it triggers this code path:ILSpy/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs
Lines 215 to 228 in 4b60978
AssignName:
ILSpy/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs
Lines 234 to 246 in 4b60978
For the non-synthetic variables in this file the
else
block is triggered and a call toGetAlternativeName
is made. This call is responsible for the change ofF10
toF2
etc. This method uses an assignment algorithm that increments the number at the end of the variable and since the variables are processed in order returned byOrderBy(v => v.Name)
,F1
will be processed first,F10
next,F11
,F12
etc. which causes the variable names to become incorrect.In my opinion, the order should not really be the thing to worry about here but rather the approach the variable name assigner takes for local variables where the names are almost certainly what the user would want them to be and the processing of them should probably be restricted to validation of them and escaping strange characters in case of obfuscated PDB files.
Details
The text was updated successfully, but these errors were encountered: