diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs index 1ecd6eec8d0ad8..e47697ea8039dc 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs @@ -170,7 +170,6 @@ protected override async Task 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(); @@ -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) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/Support.cs b/src/mono/wasm/debugger/DebuggerTestSuite/Support.cs index 81501e443d13e0..bd0987c0e43877 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/Support.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/Support.cs @@ -852,6 +852,19 @@ internal async Task GetProperties(string id, JToken fn_args = null, bool return (null, res); } + internal async Task 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 SetBreakpoint(string url_key, int line, int column, bool expect_ok = true, bool use_regex = false) { var bp1_req = !use_regex ? diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs index 61e9086160add2..03fe684e110892 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs @@ -1558,6 +1558,94 @@ async Task _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()); + Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value()); + + 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()); + Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value()); + + 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()); + Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value()); + + 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 } }