Skip to content

Commit

Permalink
[wasm][debugger] Stepping into hidden function. (#61312)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ilonatommy committed Nov 26, 2021
1 parent b256b43 commit 49c5643
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/mono/wasm/debugger/BrowserDebugProxy/DevToolsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public ExecutionContext(MonoSDBHelper sdbAgent, int id, object auxData)

public TaskCompletionSource<DebugStore> ready;
public bool IsRuntimeReady => ready != null && ready.Task.IsCompleted;

public bool IsSkippingHiddenMethod { get; set; }
public int ThreadId { get; set; }
public int Id { get; set; }
public object AuxData { get; set; }
Expand Down
26 changes: 23 additions & 3 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ private async Task<bool> SendBreakpointsOfMethodUpdated(SessionId sessionId, Exe
return true;
}

private async Task<bool> SendCallStack(SessionId sessionId, ExecutionContext context, string reason, int thread_id, Breakpoint bp, JObject data, IEnumerable<JObject> orig_callframes, CancellationToken token)
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)
{
var callFrames = new List<object>();
var frames = new List<Frame>();
Expand All @@ -754,6 +754,26 @@ private async Task<bool> SendCallStack(SessionId sessionId, ExecutionContext con
DebugStore store = await LoadStore(sessionId, token);
var method = await context.SdbAgent.GetMethodInfo(methodId, token);

if (context.IsSkippingHiddenMethod == true)
{
context.IsSkippingHiddenMethod = false;
if (event_kind != EventKind.UserBreak)
{
await context.SdbAgent.Step(context.ThreadId, StepKind.Over, token);
await SendCommand(sessionId, "Debugger.resume", new JObject(), token);
return true;
}
}

if (j == 0 && method?.Info.IsHiddenFromDebugger == true)
{
if (event_kind == EventKind.Step)
context.IsSkippingHiddenMethod = true;
await context.SdbAgent.Step(context.ThreadId, StepKind.Out, token);
await SendCommand(sessionId, "Debugger.resume", new JObject(), token);
return true;
}

SourceLocation location = method?.Info.GetLocationByIl(il_pos);

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

var ret = await SendCallStack(sessionId, context, reason, thread_id, null, data, args?["callFrames"]?.Values<JObject>(), token);
var ret = await SendCallStack(sessionId, context, reason, thread_id, null, data, args?["callFrames"]?.Values<JObject>(), event_kind, token);
return ret;
}
case EventKind.UserBreak:
Expand All @@ -893,7 +913,7 @@ private async Task<bool> OnReceiveDebuggerAgentEvent(SessionId sessionId, JObjec
int methodId = 0;
if (event_kind != EventKind.UserBreak)
methodId = retDebuggerCmdReader.ReadInt32();
var ret = await SendCallStack(sessionId, context, reason, thread_id, bp, null, args?["callFrames"]?.Values<JObject>(), token);
var ret = await SendCallStack(sessionId, context, reason, thread_id, bp, null, args?["callFrames"]?.Values<JObject>(), event_kind, token);
return ret;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ public async Task<bool> Step(int thread_id, StepKind kind, CancellationToken tok
commandParamsWriter.Write(thread_id);
commandParamsWriter.Write((int)StepSize.Line);
commandParamsWriter.Write((int)kind);
commandParamsWriter.Write((int)(StepFilter.StaticCtor | StepFilter.DebuggerHidden)); //filter
commandParamsWriter.Write((int)(StepFilter.StaticCtor)); //filter
using var retDebuggerCmdReader = await SendDebuggerAgentCommand(CmdEventRequest.Set, commandParamsWriter, token);
if (retDebuggerCmdReader.HasError)
return false;
Expand Down
28 changes: 27 additions & 1 deletion src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -651,12 +651,38 @@ public async Task DebuggerAttributeNoStopInDebuggerHidden()
var bp_visible = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "VisibleMethod", 1);
Assert.Empty(bp_hidden.Value["locations"]);
await EvaluateAndCheck(
"window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:VisibleMethod'); }, 1);",
"window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:Run'); }, 1);",
"dotnet://debugger-test.dll/debugger-test.cs",
bp_visible.Value["locations"][0]["lineNumber"].Value<int>(),
bp_visible.Value["locations"][0]["columnNumber"].Value<int>(),
"VisibleMethod"
);
}

[Fact]
public async Task DebuggerAttributeStopOnDebuggerHiddenCallWithDebuggerBreakCall()
{
var bp_init = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "RunDebuggerBreak", 0);
var init_location = await EvaluateAndCheck(
"window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:RunDebuggerBreak'); }, 1);",
"dotnet://debugger-test.dll/debugger-test.cs",
bp_init.Value["locations"][0]["lineNumber"].Value<int>(),
bp_init.Value["locations"][0]["columnNumber"].Value<int>(),
"RunDebuggerBreak"
);
var pause_location = await SendCommandAndCheck(null, "Debugger.resume",
"dotnet://debugger-test.dll/debugger-test.cs",
bp_init.Value["locations"][0]["lineNumber"].Value<int>() + 1,
8,
"RunDebuggerBreak");
Assert.Equal(init_location["callFrames"][0]["functionName"], pause_location["callFrames"][0]["functionName"]);
var id = pause_location["callFrames"][0]["callFrameId"].Value<string>();
await EvaluateOnCallFrame(id, "local_var", false);
await SendCommandAndCheck(null, "Debugger.resume",
"dotnet://debugger-test.dll/debugger-test.cs",
835,
8,
"VisibleMethodDebuggerBreak");
}
}
}
72 changes: 72 additions & 0 deletions src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -948,5 +948,77 @@ await EvaluateAndCheck(
pause_location = await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-test.cs", 806, 8, "Increment");
Assert.Equal(pause_location["callFrames"][0]["callFrameId"], "dotnet:scope:1");
}

[Fact]
public async Task DebuggerAttributeIgnoreStepIntoDebuggerHidden()
{
var pause_location = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "Run", 1);
await EvaluateAndCheck(
"window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:Run'); }, 1);",
"dotnet://debugger-test.dll/debugger-test.cs",
pause_location.Value["locations"][0]["lineNumber"].Value<int>(),
pause_location.Value["locations"][0]["columnNumber"].Value<int>(),
"Run"
);
var step_into = await SendCommandAndCheck(null, $"Debugger.stepInto", null, -1, -1, null);

Assert.Equal(
step_into["callFrames"][0]["location"]["lineNumber"].Value<int>(),
pause_location.Value["locations"][0]["lineNumber"].Value<int>() + 1
);

}

[Fact]
public async Task DebuggerAttributeIgnoreStepIntoDebuggerHiddenWithDebuggerBreakCall()
{
var pause_location = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "RunDebuggerBreak", 1);
await EvaluateAndCheck(
"window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:RunDebuggerBreak'); }, 1);",
"dotnet://debugger-test.dll/debugger-test.cs",
pause_location.Value["locations"][0]["lineNumber"].Value<int>(),
pause_location.Value["locations"][0]["columnNumber"].Value<int>(),
"RunDebuggerBreak"
);
var step_into1 = await SendCommandAndCheck(null, $"Debugger.stepInto", null, -1, -1, null);

Assert.Equal(
pause_location.Value["locations"][0]["lineNumber"].Value<int>(),
step_into1["callFrames"][0]["location"]["lineNumber"].Value<int>()
);

var step_into2 = await SendCommandAndCheck(null, $"Debugger.stepInto", null, -1, -1, null);

Assert.Equal(
pause_location.Value["locations"][0]["lineNumber"].Value<int>() + 1,
step_into2["callFrames"][0]["location"]["lineNumber"].Value<int>()
);

}

[Fact]
public async Task DebuggerAttributeIgnoreStepOverDebuggerHiddenWithDebuggerBreakCall()
{
var pause_location = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "RunDebuggerBreak", 1);
await EvaluateAndCheck(
"window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:RunDebuggerBreak'); 1});",
"dotnet://debugger-test.dll/debugger-test.cs",
pause_location.Value["locations"][0]["lineNumber"].Value<int>(),
pause_location.Value["locations"][0]["columnNumber"].Value<int>(),
"RunDebuggerBreak"
);
var step_over1 = await SendCommandAndCheck(null, $"Debugger.stepOver", null, -1, -1, null);
Assert.Equal(
pause_location.Value["locations"][0]["lineNumber"].Value<int>(),
step_over1["callFrames"][0]["location"]["lineNumber"].Value<int>()
);

var step_over2 = await SendCommandAndCheck(null, $"Debugger.stepOver", null, -1, -1, null);

Assert.Equal(
pause_location.Value["locations"][0]["lineNumber"].Value<int>() + 1,
step_over2["callFrames"][0]["location"]["lineNumber"].Value<int>()
);
}
}
}
20 changes: 20 additions & 0 deletions src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -818,14 +818,34 @@ public static void HiddenMethod()
currentCount++;
}

[System.Diagnostics.DebuggerHidden]
public static void HiddenMethodDebuggerBreak()
{
var local_var = 12;
System.Diagnostics.Debugger.Break();
currentCount++;
}

public static void VisibleMethod()
{
currentCount++;
}

public static void VisibleMethodDebuggerBreak()
{
System.Diagnostics.Debugger.Break();
currentCount++;
}

public static void Run()
{
HiddenMethod();
VisibleMethod();
}

public static void RunDebuggerBreak()
{
HiddenMethodDebuggerBreak();
VisibleMethodDebuggerBreak();
}
}

0 comments on commit 49c5643

Please sign in to comment.