Skip to content

Commit 49c5643

Browse files
authored
[wasm][debugger] Stepping into hidden function. (#61312)
* Add test for ignoring stepping into hidden function. * Corrected test to match Console App behaviour. * Corrected test logic. * Applied Thays's fix so that step into would work as step over in a hidden method. * Revert debugging changes. * Test for Debugger.Break(). * Col fix + checing the location after command execution. * Correct value of VisibleMethod entry line. * Move the breakpoint to the line 846. * Create tests that match behaviour of Console App. * Draft of Debugger.Break behaviour correction. * Draft: 2 pauses on hidden method with Debugger.Break inside. * Changed required behaviour to 2 pauses on the hidden method call.
1 parent b256b43 commit 49c5643

File tree

6 files changed

+144
-6
lines changed

6 files changed

+144
-6
lines changed

src/mono/wasm/debugger/BrowserDebugProxy/DevToolsHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public ExecutionContext(MonoSDBHelper sdbAgent, int id, object auxData)
287287

288288
public TaskCompletionSource<DebugStore> ready;
289289
public bool IsRuntimeReady => ready != null && ready.Task.IsCompleted;
290-
290+
public bool IsSkippingHiddenMethod { get; set; }
291291
public int ThreadId { get; set; }
292292
public int Id { get; set; }
293293
public object AuxData { get; set; }

src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ private async Task<bool> SendBreakpointsOfMethodUpdated(SessionId sessionId, Exe
735735
return true;
736736
}
737737

738-
private async Task<bool> SendCallStack(SessionId sessionId, ExecutionContext context, string reason, int thread_id, Breakpoint bp, JObject data, IEnumerable<JObject> orig_callframes, CancellationToken token)
738+
private async Task<bool> SendCallStack(SessionId sessionId, ExecutionContext context, string reason, int thread_id, Breakpoint bp, JObject data, IEnumerable<JObject> orig_callframes, EventKind event_kind, CancellationToken token)
739739
{
740740
var callFrames = new List<object>();
741741
var frames = new List<Frame>();
@@ -754,6 +754,26 @@ private async Task<bool> SendCallStack(SessionId sessionId, ExecutionContext con
754754
DebugStore store = await LoadStore(sessionId, token);
755755
var method = await context.SdbAgent.GetMethodInfo(methodId, token);
756756

757+
if (context.IsSkippingHiddenMethod == true)
758+
{
759+
context.IsSkippingHiddenMethod = false;
760+
if (event_kind != EventKind.UserBreak)
761+
{
762+
await context.SdbAgent.Step(context.ThreadId, StepKind.Over, token);
763+
await SendCommand(sessionId, "Debugger.resume", new JObject(), token);
764+
return true;
765+
}
766+
}
767+
768+
if (j == 0 && method?.Info.IsHiddenFromDebugger == true)
769+
{
770+
if (event_kind == EventKind.Step)
771+
context.IsSkippingHiddenMethod = true;
772+
await context.SdbAgent.Step(context.ThreadId, StepKind.Out, token);
773+
await SendCommand(sessionId, "Debugger.resume", new JObject(), token);
774+
return true;
775+
}
776+
757777
SourceLocation location = method?.Info.GetLocationByIl(il_pos);
758778

759779
// When hitting a breakpoint on the "IncrementCount" method in the standard
@@ -881,7 +901,7 @@ private async Task<bool> OnReceiveDebuggerAgentEvent(SessionId sessionId, JObjec
881901
objectId = $"dotnet:object:{object_id}"
882902
});
883903

884-
var ret = await SendCallStack(sessionId, context, reason, thread_id, null, data, args?["callFrames"]?.Values<JObject>(), token);
904+
var ret = await SendCallStack(sessionId, context, reason, thread_id, null, data, args?["callFrames"]?.Values<JObject>(), event_kind, token);
885905
return ret;
886906
}
887907
case EventKind.UserBreak:
@@ -893,7 +913,7 @@ private async Task<bool> OnReceiveDebuggerAgentEvent(SessionId sessionId, JObjec
893913
int methodId = 0;
894914
if (event_kind != EventKind.UserBreak)
895915
methodId = retDebuggerCmdReader.ReadInt32();
896-
var ret = await SendCallStack(sessionId, context, reason, thread_id, bp, null, args?["callFrames"]?.Values<JObject>(), token);
916+
var ret = await SendCallStack(sessionId, context, reason, thread_id, bp, null, args?["callFrames"]?.Values<JObject>(), event_kind, token);
897917
return ret;
898918
}
899919
}

src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ public async Task<bool> Step(int thread_id, StepKind kind, CancellationToken tok
11471147
commandParamsWriter.Write(thread_id);
11481148
commandParamsWriter.Write((int)StepSize.Line);
11491149
commandParamsWriter.Write((int)kind);
1150-
commandParamsWriter.Write((int)(StepFilter.StaticCtor | StepFilter.DebuggerHidden)); //filter
1150+
commandParamsWriter.Write((int)(StepFilter.StaticCtor)); //filter
11511151
using var retDebuggerCmdReader = await SendDebuggerAgentCommand(CmdEventRequest.Set, commandParamsWriter, token);
11521152
if (retDebuggerCmdReader.HasError)
11531153
return false;

src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,12 +651,38 @@ public async Task DebuggerAttributeNoStopInDebuggerHidden()
651651
var bp_visible = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "VisibleMethod", 1);
652652
Assert.Empty(bp_hidden.Value["locations"]);
653653
await EvaluateAndCheck(
654-
"window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:VisibleMethod'); }, 1);",
654+
"window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:Run'); }, 1);",
655655
"dotnet://debugger-test.dll/debugger-test.cs",
656656
bp_visible.Value["locations"][0]["lineNumber"].Value<int>(),
657657
bp_visible.Value["locations"][0]["columnNumber"].Value<int>(),
658658
"VisibleMethod"
659659
);
660660
}
661+
662+
[Fact]
663+
public async Task DebuggerAttributeStopOnDebuggerHiddenCallWithDebuggerBreakCall()
664+
{
665+
var bp_init = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "RunDebuggerBreak", 0);
666+
var init_location = await EvaluateAndCheck(
667+
"window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:RunDebuggerBreak'); }, 1);",
668+
"dotnet://debugger-test.dll/debugger-test.cs",
669+
bp_init.Value["locations"][0]["lineNumber"].Value<int>(),
670+
bp_init.Value["locations"][0]["columnNumber"].Value<int>(),
671+
"RunDebuggerBreak"
672+
);
673+
var pause_location = await SendCommandAndCheck(null, "Debugger.resume",
674+
"dotnet://debugger-test.dll/debugger-test.cs",
675+
bp_init.Value["locations"][0]["lineNumber"].Value<int>() + 1,
676+
8,
677+
"RunDebuggerBreak");
678+
Assert.Equal(init_location["callFrames"][0]["functionName"], pause_location["callFrames"][0]["functionName"]);
679+
var id = pause_location["callFrames"][0]["callFrameId"].Value<string>();
680+
await EvaluateOnCallFrame(id, "local_var", false);
681+
await SendCommandAndCheck(null, "Debugger.resume",
682+
"dotnet://debugger-test.dll/debugger-test.cs",
683+
835,
684+
8,
685+
"VisibleMethodDebuggerBreak");
686+
}
661687
}
662688
}

src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,5 +948,77 @@ await EvaluateAndCheck(
948948
pause_location = await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-test.cs", 806, 8, "Increment");
949949
Assert.Equal(pause_location["callFrames"][0]["callFrameId"], "dotnet:scope:1");
950950
}
951+
952+
[Fact]
953+
public async Task DebuggerAttributeIgnoreStepIntoDebuggerHidden()
954+
{
955+
var pause_location = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "Run", 1);
956+
await EvaluateAndCheck(
957+
"window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:Run'); }, 1);",
958+
"dotnet://debugger-test.dll/debugger-test.cs",
959+
pause_location.Value["locations"][0]["lineNumber"].Value<int>(),
960+
pause_location.Value["locations"][0]["columnNumber"].Value<int>(),
961+
"Run"
962+
);
963+
var step_into = await SendCommandAndCheck(null, $"Debugger.stepInto", null, -1, -1, null);
964+
965+
Assert.Equal(
966+
step_into["callFrames"][0]["location"]["lineNumber"].Value<int>(),
967+
pause_location.Value["locations"][0]["lineNumber"].Value<int>() + 1
968+
);
969+
970+
}
971+
972+
[Fact]
973+
public async Task DebuggerAttributeIgnoreStepIntoDebuggerHiddenWithDebuggerBreakCall()
974+
{
975+
var pause_location = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "RunDebuggerBreak", 1);
976+
await EvaluateAndCheck(
977+
"window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:RunDebuggerBreak'); }, 1);",
978+
"dotnet://debugger-test.dll/debugger-test.cs",
979+
pause_location.Value["locations"][0]["lineNumber"].Value<int>(),
980+
pause_location.Value["locations"][0]["columnNumber"].Value<int>(),
981+
"RunDebuggerBreak"
982+
);
983+
var step_into1 = await SendCommandAndCheck(null, $"Debugger.stepInto", null, -1, -1, null);
984+
985+
Assert.Equal(
986+
pause_location.Value["locations"][0]["lineNumber"].Value<int>(),
987+
step_into1["callFrames"][0]["location"]["lineNumber"].Value<int>()
988+
);
989+
990+
var step_into2 = await SendCommandAndCheck(null, $"Debugger.stepInto", null, -1, -1, null);
991+
992+
Assert.Equal(
993+
pause_location.Value["locations"][0]["lineNumber"].Value<int>() + 1,
994+
step_into2["callFrames"][0]["location"]["lineNumber"].Value<int>()
995+
);
996+
997+
}
998+
999+
[Fact]
1000+
public async Task DebuggerAttributeIgnoreStepOverDebuggerHiddenWithDebuggerBreakCall()
1001+
{
1002+
var pause_location = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "RunDebuggerBreak", 1);
1003+
await EvaluateAndCheck(
1004+
"window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:RunDebuggerBreak'); 1});",
1005+
"dotnet://debugger-test.dll/debugger-test.cs",
1006+
pause_location.Value["locations"][0]["lineNumber"].Value<int>(),
1007+
pause_location.Value["locations"][0]["columnNumber"].Value<int>(),
1008+
"RunDebuggerBreak"
1009+
);
1010+
var step_over1 = await SendCommandAndCheck(null, $"Debugger.stepOver", null, -1, -1, null);
1011+
Assert.Equal(
1012+
pause_location.Value["locations"][0]["lineNumber"].Value<int>(),
1013+
step_over1["callFrames"][0]["location"]["lineNumber"].Value<int>()
1014+
);
1015+
1016+
var step_over2 = await SendCommandAndCheck(null, $"Debugger.stepOver", null, -1, -1, null);
1017+
1018+
Assert.Equal(
1019+
pause_location.Value["locations"][0]["lineNumber"].Value<int>() + 1,
1020+
step_over2["callFrames"][0]["location"]["lineNumber"].Value<int>()
1021+
);
1022+
}
9511023
}
9521024
}

src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,14 +818,34 @@ public static void HiddenMethod()
818818
currentCount++;
819819
}
820820

821+
[System.Diagnostics.DebuggerHidden]
822+
public static void HiddenMethodDebuggerBreak()
823+
{
824+
var local_var = 12;
825+
System.Diagnostics.Debugger.Break();
826+
currentCount++;
827+
}
828+
821829
public static void VisibleMethod()
822830
{
823831
currentCount++;
824832
}
825833

834+
public static void VisibleMethodDebuggerBreak()
835+
{
836+
System.Diagnostics.Debugger.Break();
837+
currentCount++;
838+
}
839+
826840
public static void Run()
827841
{
828842
HiddenMethod();
829843
VisibleMethod();
830844
}
845+
846+
public static void RunDebuggerBreak()
847+
{
848+
HiddenMethodDebuggerBreak();
849+
VisibleMethodDebuggerBreak();
850+
}
831851
}

0 commit comments

Comments
 (0)