From d4f7613677bfe69db07ecad9075cea0158aaa1b0 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Thu, 27 Aug 2020 18:16:52 -0300 Subject: [PATCH 1/3] Remove unnecessary WriteLine. Fix #41447. --- src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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) From e54488f8d5dba3c1175d53e7b446a43f321b8d7f Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Fri, 28 Aug 2020 14:34:52 -0300 Subject: [PATCH 2/3] Creating unit test about remove breakpoint. --- .../debugger/DebuggerTestSuite/Support.cs | 12 +++++++ .../wasm/debugger/DebuggerTestSuite/Tests.cs | 32 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/Support.cs b/src/mono/wasm/debugger/DebuggerTestSuite/Support.cs index 81501e443d13e0..cac43ab40bd637 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/Support.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/Support.cs @@ -852,6 +852,18 @@ internal async Task GetProperties(string id, JToken fn_args = null, bool return (null, res); } + internal async Task RemoveBreakpoint(string id) + { + var remove_bp = JObject.FromObject(new + { + breakpointId = id + }); + + var bp1_res = await ctx.cli.SendCommand("Debugger.removeBreakpoint", remove_bp, ctx.token); + + return bp1_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 34dc5ef605de1b..93fbbed6d97d78 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs @@ -1523,6 +1523,38 @@ 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 wait_res = await EvaluateAndCheck( + "window.setTimeout(function() { invoke_add(); invoke_add()}, 1);", + "dotnet://debugger-test.dll/debugger-test.cs", 10, 8, + "IntAdd", + wait_for_event_fn: (pause_location) => + { + Assert.Equal("other", pause_location["reason"]?.Value()); + Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value()); + return Task.CompletedTask; + } + ); + var bp3 = 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"); + }); + } + //TODO add tests covering basic stepping behavior as step in/out/over } } From 83c27afb9b7ed3be482beda87262a470fedad938 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Mon, 31 Aug 2020 11:21:17 -0300 Subject: [PATCH 3/3] Implementing @radical suggestions! --- .../debugger/DebuggerTestSuite/Support.cs | 7 +- .../wasm/debugger/DebuggerTestSuite/Tests.cs | 76 ++++++++++++++++--- 2 files changed, 70 insertions(+), 13 deletions(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/Support.cs b/src/mono/wasm/debugger/DebuggerTestSuite/Support.cs index cac43ab40bd637..bd0987c0e43877 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/Support.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/Support.cs @@ -852,16 +852,17 @@ internal async Task GetProperties(string id, JToken fn_args = null, bool return (null, res); } - internal async Task RemoveBreakpoint(string id) + internal async Task RemoveBreakpoint(string id, bool expect_ok = true) { var remove_bp = JObject.FromObject(new { breakpointId = id }); - var bp1_res = await ctx.cli.SendCommand("Debugger.removeBreakpoint", remove_bp, ctx.token); + var res = await ctx.cli.SendCommand("Debugger.removeBreakpoint", remove_bp, ctx.token); + Assert.True(expect_ok ? res.IsOk : res.IsErr); - return bp1_res; + return res; } internal async Task SetBreakpoint(string url_key, int line, int column, bool expect_ok = true, bool use_regex = false) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs index 93fbbed6d97d78..c0c9a905165ed9 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs @@ -1538,23 +1538,79 @@ await insp.Ready(async (cli, token) => 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 wait_res = await EvaluateAndCheck( + var pause_location = await EvaluateAndCheck( "window.setTimeout(function() { invoke_add(); invoke_add()}, 1);", "dotnet://debugger-test.dll/debugger-test.cs", 10, 8, - "IntAdd", - wait_for_event_fn: (pause_location) => - { - Assert.Equal("other", pause_location["reason"]?.Value()); - Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value()); - return Task.CompletedTask; - } - ); - var bp3 = await RemoveBreakpoint(bp.Value["breakpointId"]?.ToString()); + "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 } }