Skip to content

Commit 513ade6

Browse files
authored
[wasm][debugger] Breakpoint stopping after it's removed (#41479)
* Remove unnecessary WriteLine. Fix #41447. * Creating unit test about remove breakpoint. * Implementing @radical suggestions!
1 parent a3e6ff5 commit 513ade6

File tree

3 files changed

+102
-2
lines changed

3 files changed

+102
-2
lines changed

src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ protected override async Task<bool> AcceptCommand(MessageId id, string method, J
170170

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

176175
context.DebuggerId = resp.Value["debuggerId"]?.ToString();
@@ -854,7 +853,7 @@ async Task RemoveBreakpoint(MessageId msg_id, JObject args, CancellationToken to
854853
bp.State = BreakpointState.Disabled;
855854
}
856855
}
857-
breakpointRequest.Locations.Clear();
856+
context.BreakpointRequests.Remove(bpid);
858857
}
859858

860859
async Task SetBreakpoint(SessionId sessionId, DebugStore store, BreakpointRequest req, bool sendResolvedEvent, CancellationToken token)

src/mono/wasm/debugger/DebuggerTestSuite/Support.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,19 @@ internal async Task<JToken> GetProperties(string id, JToken fn_args = null, bool
852852
return (null, res);
853853
}
854854

855+
internal async Task<Result> RemoveBreakpoint(string id, bool expect_ok = true)
856+
{
857+
var remove_bp = JObject.FromObject(new
858+
{
859+
breakpointId = id
860+
});
861+
862+
var res = await ctx.cli.SendCommand("Debugger.removeBreakpoint", remove_bp, ctx.token);
863+
Assert.True(expect_ok ? res.IsOk : res.IsErr);
864+
865+
return res;
866+
}
867+
855868
internal async Task<Result> SetBreakpoint(string url_key, int line, int column, bool expect_ok = true, bool use_regex = false)
856869
{
857870
var bp1_req = !use_regex ?

src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,94 @@ async Task<Result> _invoke_getter(string obj_id, string property_name, bool expe
15581558
}
15591559
}
15601560

1561+
[Fact]
1562+
public async Task CreateGoodBreakpointAndHitAndRemoveAndDontHit()
1563+
{
1564+
var insp = new Inspector();
1565+
1566+
//Collect events
1567+
var scripts = SubscribeToScripts(insp);
1568+
1569+
await Ready();
1570+
await insp.Ready(async (cli, token) =>
1571+
{
1572+
ctx = new DebugTestContext(cli, insp, token, scripts);
1573+
1574+
var bp = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, 8);
1575+
var bp2 = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 12, 8);
1576+
var pause_location = await EvaluateAndCheck(
1577+
"window.setTimeout(function() { invoke_add(); invoke_add()}, 1);",
1578+
"dotnet://debugger-test.dll/debugger-test.cs", 10, 8,
1579+
"IntAdd");
1580+
1581+
Assert.Equal("other", pause_location["reason"]?.Value<string>());
1582+
Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value<string>());
1583+
1584+
await RemoveBreakpoint(bp.Value["breakpointId"]?.ToString());
1585+
await SendCommandAndCheck(JObject.FromObject(new { }), "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", 12, 8, "IntAdd");
1586+
await SendCommandAndCheck(JObject.FromObject(new { }), "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", 12, 8, "IntAdd");
1587+
});
1588+
}
1589+
1590+
[Fact]
1591+
public async Task CreateGoodBreakpointAndHitAndRemoveTwice()
1592+
{
1593+
var insp = new Inspector();
1594+
1595+
//Collect events
1596+
var scripts = SubscribeToScripts(insp);
1597+
1598+
await Ready();
1599+
await insp.Ready(async (cli, token) =>
1600+
{
1601+
ctx = new DebugTestContext(cli, insp, token, scripts);
1602+
1603+
var bp = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, 8);
1604+
var bp2 = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 12, 8);
1605+
var pause_location = await EvaluateAndCheck(
1606+
"window.setTimeout(function() { invoke_add(); invoke_add()}, 1);",
1607+
"dotnet://debugger-test.dll/debugger-test.cs", 10, 8,
1608+
"IntAdd");
1609+
1610+
Assert.Equal("other", pause_location["reason"]?.Value<string>());
1611+
Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value<string>());
1612+
1613+
await RemoveBreakpoint(bp.Value["breakpointId"]?.ToString());
1614+
await RemoveBreakpoint(bp.Value["breakpointId"]?.ToString());
1615+
});
1616+
}
1617+
1618+
[Fact]
1619+
public async Task CreateGoodBreakpointAndHitAndRemoveAndDontHitAndCreateAgainAndHit()
1620+
{
1621+
var insp = new Inspector();
1622+
1623+
//Collect events
1624+
var scripts = SubscribeToScripts(insp);
1625+
1626+
await Ready();
1627+
await insp.Ready(async (cli, token) =>
1628+
{
1629+
ctx = new DebugTestContext(cli, insp, token, scripts);
1630+
1631+
var bp = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, 8);
1632+
var bp2 = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 12, 8);
1633+
var pause_location = await EvaluateAndCheck(
1634+
"window.setTimeout(function() { invoke_add(); invoke_add(); invoke_add(); invoke_add()}, 1);",
1635+
"dotnet://debugger-test.dll/debugger-test.cs", 10, 8,
1636+
"IntAdd");
1637+
1638+
Assert.Equal("other", pause_location["reason"]?.Value<string>());
1639+
Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value<string>());
1640+
1641+
await RemoveBreakpoint(bp.Value["breakpointId"]?.ToString());
1642+
await SendCommandAndCheck(JObject.FromObject(new { }), "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", 12, 8, "IntAdd");
1643+
await SendCommandAndCheck(JObject.FromObject(new { }), "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", 12, 8, "IntAdd");
1644+
bp = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, 8);
1645+
await SendCommandAndCheck(JObject.FromObject(new { }), "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", 10, 8, "IntAdd");
1646+
1647+
});
1648+
}
15611649
//TODO add tests covering basic stepping behavior as step in/out/over
15621650
}
15631651
}

0 commit comments

Comments
 (0)