-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[wasm][debugger] Improvements in debugging in async methods #78651
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c37ec32
Fixing 2 variables with same names in different scopes in a async met…
thaystg 15a53ec
Implementing support to see local variables in async methods in VB co…
thaystg 3c704f0
Adding Test case as suggested by @radical
thaystg 7830b1c
Refactor Scope class
radical 83ca78d
slight test changes
radical 6914711
Split the tests, to be more readable in code, and in test results
radical c23bcd2
cleanup
radical 6b87c08
Merge branch 'dotnet:main' into thays_fix_77031
thaystg 0dd3980
addressing radical comments
thaystg 614db8f
addressing radical comments, fix test case
thaystg 716b598
addressing radical comments
thaystg 568e617
addressing @radical comments
thaystg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -804,7 +804,9 @@ internal sealed class MonoSDBHelper | |
private SessionId sessionId; | ||
|
||
internal readonly ILogger logger; | ||
private static readonly Regex regexForAsyncLocals = new (@"\<([^)]*)\>", RegexOptions.Singleline); | ||
private static readonly Regex regexForAsyncLocals = new(@"\<([^)]*)\>([^)]*)([_][_])([0-9]*)", RegexOptions.Singleline); //<testCSharpScope>5__1 | ||
private static readonly Regex regexForVBAsyncLocals = new(@"\$VB\$ResumableLocal_([^)]*)\$([0-9]*)", RegexOptions.Singleline); //$VB$ResumableLocal_testVbScope$2 | ||
private static readonly Regex regexForVBAsyncMethodName = new(@"VB\$StateMachine_([0-9]*)_([^)]*)", RegexOptions.Singleline); //VB$StateMachine_2_RunVBScope | ||
private static readonly Regex regexForAsyncMethodName = new (@"\<([^>]*)\>([d][_][_])([0-9]*)", RegexOptions.Compiled); | ||
private static readonly Regex regexForGenericArgs = new (@"[`][0-9]+", RegexOptions.Compiled); | ||
private static readonly Regex regexForNestedLeftRightAngleBrackets = new ("^(((?'Open'<)[^<>]*)+((?'Close-Open'>)[^<>]*)+)*(?(Open)(?!))[^<>]*", RegexOptions.Compiled); | ||
|
@@ -1285,6 +1287,11 @@ public async Task<string> GetPrettyMethodName(int methodId, bool isAnonymous, Ca | |
if (anonymousMethodId.LastIndexOf('_') >= 0) | ||
anonymousMethodId = klassName.Substring(klassName.LastIndexOf('_') + 1); | ||
} | ||
else if (klassName.StartsWith("VB$")) | ||
{ | ||
var match = regexForVBAsyncMethodName.Match(klassName); | ||
ret = ret.Insert(0, match.Groups[2].Value); | ||
} | ||
else | ||
{ | ||
var matchOnClassName = regexForNestedLeftRightAngleBrackets.Match(klassName); | ||
|
@@ -1965,7 +1972,7 @@ private static bool IsClosureReferenceField (string fieldName) | |
fieldName.StartsWith ("<>8__", StringComparison.Ordinal); | ||
} | ||
|
||
public async Task<JArray> GetHoistedLocalVariables(int objectId, IEnumerable<JToken> asyncLocals, CancellationToken token) | ||
public async Task<JArray> GetHoistedLocalVariables(MethodInfoWithDebugInformation method, int objectId, IEnumerable<JToken> asyncLocals, int offset, CancellationToken token) | ||
{ | ||
JArray asyncLocalsFull = new JArray(); | ||
List<int> objectsAlreadyRead = new(); | ||
|
@@ -1986,7 +1993,7 @@ public async Task<JArray> GetHoistedLocalVariables(int objectId, IEnumerable<JTo | |
{ | ||
var asyncProxyMembersFromObject = await MemberObjectsExplorer.GetObjectMemberValues( | ||
this, dotnetObjectId.Value, GetObjectCommandOptions.WithProperties, token); | ||
var hoistedLocalVariable = await GetHoistedLocalVariables(dotnetObjectId.Value, asyncProxyMembersFromObject.Flatten(), token); | ||
var hoistedLocalVariable = await GetHoistedLocalVariables(method, dotnetObjectId.Value, asyncProxyMembersFromObject.Flatten(), offset, token); | ||
asyncLocalsFull = new JArray(asyncLocalsFull.Union(hoistedLocalVariable)); | ||
} | ||
} | ||
|
@@ -1999,9 +2006,34 @@ public async Task<JArray> GetHoistedLocalVariables(int objectId, IEnumerable<JTo | |
{ | ||
var match = regexForAsyncLocals.Match(fieldName); | ||
if (match.Success) | ||
{ | ||
if (!method.Info.ContainsAsyncScope(Convert.ToInt32(match.Groups[4].Value), offset)) | ||
continue; | ||
asyncLocal["name"] = match.Groups[1].Value; | ||
} | ||
asyncLocalsFull.Add(asyncLocal); | ||
} | ||
//VB language | ||
else if (fieldName.StartsWith("$VB$Local_", StringComparison.Ordinal)) | ||
{ | ||
asyncLocal["name"] = fieldName.Remove(0, 10); | ||
asyncLocalsFull.Add(asyncLocal); | ||
} | ||
else if (fieldName.StartsWith("$VB$ResumableLocal_", StringComparison.Ordinal)) | ||
{ | ||
var match = regexForVBAsyncLocals.Match(fieldName); | ||
if (match.Success) | ||
{ | ||
if (!method.Info.ContainsAsyncScope(Convert.ToInt32(match.Groups[2].Value) + 1, offset)) | ||
continue; | ||
asyncLocal["name"] = match.Groups[1].Value; | ||
} | ||
asyncLocalsFull.Add(asyncLocal); | ||
} | ||
else if (fieldName.StartsWith("$")) | ||
{ | ||
continue; | ||
} | ||
else | ||
{ | ||
asyncLocalsFull.Add(asyncLocal); | ||
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. Should this be unconditional? It seems to be common, for the cases we don't |
||
|
@@ -2010,7 +2042,7 @@ public async Task<JArray> GetHoistedLocalVariables(int objectId, IEnumerable<JTo | |
return asyncLocalsFull; | ||
} | ||
|
||
public async Task<JArray> StackFrameGetValues(MethodInfoWithDebugInformation method, int thread_id, int frame_id, VarInfo[] varIds, CancellationToken token) | ||
public async Task<JArray> StackFrameGetValues(MethodInfoWithDebugInformation method, int thread_id, int frame_id, VarInfo[] varIds, int offset, CancellationToken token) | ||
{ | ||
using var commandParamsWriter = new MonoBinaryWriter(); | ||
commandParamsWriter.Write(thread_id); | ||
|
@@ -2027,7 +2059,7 @@ public async Task<JArray> StackFrameGetValues(MethodInfoWithDebugInformation met | |
retDebuggerCmdReader.ReadByte(); //ignore type | ||
var objectId = retDebuggerCmdReader.ReadInt32(); | ||
GetMembersResult asyncProxyMembers = await MemberObjectsExplorer.GetObjectMemberValues(this, objectId, GetObjectCommandOptions.WithProperties, token, includeStatic: true); | ||
var asyncLocals = await GetHoistedLocalVariables(objectId, asyncProxyMembers.Flatten(), token); | ||
var asyncLocals = await GetHoistedLocalVariables(method, objectId, asyncProxyMembers.Flatten(), offset, token); | ||
return asyncLocals; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/mono/wasm/debugger/tests/debugger-test-vb/debugger-test-vb.vb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Public Class TestVbScope | ||
Public Shared Async Function Run() As Task | ||
Await RunVBScope(10) | ||
Await RunVBScope(1000) | ||
End Function | ||
|
||
Public Shared Async Function RunVBScope(data As Integer) As Task(Of Integer) | ||
Dim a As Integer | ||
a = 10 | ||
If data < 999 Then | ||
Dim testVbScope As String | ||
Dim onlyInFirstScope As String | ||
testVbScope = "hello" | ||
onlyInFirstScope = "only-in-first-scope" | ||
System.Diagnostics.Debugger.Break() | ||
Await Task.Delay(1) | ||
Return data | ||
Else | ||
Dim testVbScope As String | ||
Dim onlyInSecondScope As String | ||
testVbScope = "hi" | ||
onlyInSecondScope = "only-in-second-scope" | ||
System.Diagnostics.Debugger.Break() | ||
Await Task.Delay(1) | ||
Return data | ||
End If | ||
|
||
End Function | ||
|
||
End Class |
8 changes: 8 additions & 0 deletions
8
src/mono/wasm/debugger/tests/debugger-test-vb/debugger-test-vb.vbproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<RootNamespace>DebuggerTestVB</RootNamespace> | ||
<TargetFramework>net7.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Check
match.Success
.