Skip to content

[wasm][debugger] Stepping into hidden function. #61312

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

Merged
merged 14 commits into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -732,7 +732,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 @@ -751,6 +751,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 @@ -878,7 +898,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 @@ -890,7 +910,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
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();
}
}