From 5a9de36bd90a40850720aaf3199d4f0bb11450b8 Mon Sep 17 00:00:00 2001 From: Thays Date: Thu, 5 Nov 2020 12:33:45 -0300 Subject: [PATCH] Implementing support to Debugger::Break. --- src/mono/mono/mini/mini-wasm-debugger.c | 7 +++++++ src/mono/mono/mini/mini-wasm.h | 1 + .../wasm/debugger/DebuggerTestSuite/Tests.cs | 17 +++++++++++++++++ .../tests/debugger-test/debugger-test2.cs | 9 ++++++++- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/mini/mini-wasm-debugger.c b/src/mono/mono/mini/mini-wasm-debugger.c index 15951e1b7076f..9ac0eb602d922 100644 --- a/src/mono/mono/mini/mini-wasm-debugger.c +++ b/src/mono/mono/mini/mini-wasm-debugger.c @@ -444,6 +444,7 @@ mono_wasm_debugger_init (void) objrefs = g_hash_table_new_full (NULL, NULL, NULL, mono_debugger_free_objref); mini_get_dbg_callbacks ()->handle_exception = handle_exception; + mini_get_dbg_callbacks ()->user_break = mono_wasm_user_break; } MONO_API void @@ -663,6 +664,12 @@ mono_wasm_breakpoint_hit (void) // mono_wasm_fire_bp (); } +void +mono_wasm_user_break (void) +{ + mono_wasm_fire_bp (); +} + EMSCRIPTEN_KEEPALIVE int mono_wasm_current_bp_id (void) { diff --git a/src/mono/mono/mini/mini-wasm.h b/src/mono/mono/mini/mini-wasm.h index ac35ed3df33c5..26a97ffbd8bf1 100644 --- a/src/mono/mono/mini/mini-wasm.h +++ b/src/mono/mono/mini/mini-wasm.h @@ -111,6 +111,7 @@ void mono_wasm_set_timeout (int timeout, int id); void mono_wasm_single_step_hit (void); void mono_wasm_breakpoint_hit (void); +void mono_wasm_user_break (void); int mono_wasm_assembly_already_added (const char *assembly_name); diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs index c53a60b59fccb..2ac3cb620e468 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs @@ -1158,6 +1158,23 @@ async Task LoadAssemblyDynamically(string asm_file, string pdb_file) Assert.True(load_assemblies_res.IsOk); } + [Fact] + public async Task BreakOnDebuggerBreak() + { + 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); + await EvaluateAndCheck( + "window.setTimeout(function() { invoke_static_method_async('[debugger-test] UserBreak:BreakOnDebuggerBreakCommand'); }, 1);", + "dotnet://debugger-test.dll/debugger-test2.cs", 56, 4, + "BreakOnDebuggerBreakCommand"); + }); + } //TODO add tests covering basic stepping behavior as step in/out/over } } diff --git a/src/mono/wasm/debugger/tests/debugger-test/debugger-test2.cs b/src/mono/wasm/debugger/tests/debugger-test/debugger-test2.cs index 7275bf4a2f10e..b9d97c8e23484 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-test2.cs +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-test2.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; - +using System.Diagnostics; public class Misc { //Only append content to this class as the test suite depends on line info public static int CreateObject(int foo, int bar) @@ -49,3 +49,10 @@ public static void Types() var d = usMin + usMax; } } + +public class UserBreak { + public static void BreakOnDebuggerBreakCommand() + { + Debugger.Break(); + } +}