Skip to content

Commit

Permalink
[wasm][debugger] Breakpoint stopping after it's removed (dotnet#41479)
Browse files Browse the repository at this point in the history
* Remove unnecessary WriteLine.
Fix dotnet#41447.

* Creating unit test about remove breakpoint.

* Implementing @radical suggestions!
  • Loading branch information
thaystg authored Aug 31, 2020
1 parent a3e6ff5 commit 513ade6
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ protected override async Task<bool> AcceptCommand(MessageId id, string method, J

case "Debugger.enable":
{
System.Console.WriteLine("recebi o Debugger.enable");
var resp = await SendCommand(id, method, args, token);

context.DebuggerId = resp.Value["debuggerId"]?.ToString();
Expand Down Expand Up @@ -854,7 +853,7 @@ async Task RemoveBreakpoint(MessageId msg_id, JObject args, CancellationToken to
bp.State = BreakpointState.Disabled;
}
}
breakpointRequest.Locations.Clear();
context.BreakpointRequests.Remove(bpid);
}

async Task SetBreakpoint(SessionId sessionId, DebugStore store, BreakpointRequest req, bool sendResolvedEvent, CancellationToken token)
Expand Down
13 changes: 13 additions & 0 deletions src/mono/wasm/debugger/DebuggerTestSuite/Support.cs
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,19 @@ internal async Task<JToken> GetProperties(string id, JToken fn_args = null, bool
return (null, res);
}

internal async Task<Result> RemoveBreakpoint(string id, bool expect_ok = true)
{
var remove_bp = JObject.FromObject(new
{
breakpointId = id
});

var res = await ctx.cli.SendCommand("Debugger.removeBreakpoint", remove_bp, ctx.token);
Assert.True(expect_ok ? res.IsOk : res.IsErr);

return res;
}

internal async Task<Result> SetBreakpoint(string url_key, int line, int column, bool expect_ok = true, bool use_regex = false)
{
var bp1_req = !use_regex ?
Expand Down
88 changes: 88 additions & 0 deletions src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,94 @@ async Task<Result> _invoke_getter(string obj_id, string property_name, bool expe
}
}

[Fact]
public async Task CreateGoodBreakpointAndHitAndRemoveAndDontHit()
{
var insp = new Inspector();

//Collect events
var scripts = SubscribeToScripts(insp);

await Ready();
await insp.Ready(async (cli, token) =>
{
ctx = new DebugTestContext(cli, insp, token, scripts);
var bp = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, 8);
var bp2 = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 12, 8);
var pause_location = await EvaluateAndCheck(
"window.setTimeout(function() { invoke_add(); invoke_add()}, 1);",
"dotnet://debugger-test.dll/debugger-test.cs", 10, 8,
"IntAdd");
Assert.Equal("other", pause_location["reason"]?.Value<string>());
Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value<string>());
await RemoveBreakpoint(bp.Value["breakpointId"]?.ToString());
await SendCommandAndCheck(JObject.FromObject(new { }), "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", 12, 8, "IntAdd");
await SendCommandAndCheck(JObject.FromObject(new { }), "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", 12, 8, "IntAdd");
});
}

[Fact]
public async Task CreateGoodBreakpointAndHitAndRemoveTwice()
{
var insp = new Inspector();

//Collect events
var scripts = SubscribeToScripts(insp);

await Ready();
await insp.Ready(async (cli, token) =>
{
ctx = new DebugTestContext(cli, insp, token, scripts);
var bp = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, 8);
var bp2 = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 12, 8);
var pause_location = await EvaluateAndCheck(
"window.setTimeout(function() { invoke_add(); invoke_add()}, 1);",
"dotnet://debugger-test.dll/debugger-test.cs", 10, 8,
"IntAdd");
Assert.Equal("other", pause_location["reason"]?.Value<string>());
Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value<string>());
await RemoveBreakpoint(bp.Value["breakpointId"]?.ToString());
await RemoveBreakpoint(bp.Value["breakpointId"]?.ToString());
});
}

[Fact]
public async Task CreateGoodBreakpointAndHitAndRemoveAndDontHitAndCreateAgainAndHit()
{
var insp = new Inspector();

//Collect events
var scripts = SubscribeToScripts(insp);

await Ready();
await insp.Ready(async (cli, token) =>
{
ctx = new DebugTestContext(cli, insp, token, scripts);
var bp = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, 8);
var bp2 = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 12, 8);
var pause_location = await EvaluateAndCheck(
"window.setTimeout(function() { invoke_add(); invoke_add(); invoke_add(); invoke_add()}, 1);",
"dotnet://debugger-test.dll/debugger-test.cs", 10, 8,
"IntAdd");
Assert.Equal("other", pause_location["reason"]?.Value<string>());
Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value<string>());
await RemoveBreakpoint(bp.Value["breakpointId"]?.ToString());
await SendCommandAndCheck(JObject.FromObject(new { }), "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", 12, 8, "IntAdd");
await SendCommandAndCheck(JObject.FromObject(new { }), "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", 12, 8, "IntAdd");
bp = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, 8);
await SendCommandAndCheck(JObject.FromObject(new { }), "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", 10, 8, "IntAdd");
});
}
//TODO add tests covering basic stepping behavior as step in/out/over
}
}

0 comments on commit 513ade6

Please sign in to comment.