From d7c1e8dcf03879f0e7689b4c45f4312225bb6775 Mon Sep 17 00:00:00 2001 From: Thays Date: Mon, 20 Sep 2021 16:33:44 -0300 Subject: [PATCH 1/3] Keeping the old behavior of scope id what we have before start using debugger-agent. --- src/mono/mono/component/debugger-agent.c | 5 +++- .../DebuggerTestSuite/SteppingTests.cs | 20 +++++++++++++++ .../tests/debugger-test/debugger-test.cs | 25 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/component/debugger-agent.c b/src/mono/mono/component/debugger-agent.c index a49dc2a359b5a6..ed381fb22dd3dc 100644 --- a/src/mono/mono/component/debugger-agent.c +++ b/src/mono/mono/component/debugger-agent.c @@ -3083,6 +3083,7 @@ compute_frame_info (MonoInternalThread *thread, DebuggerTlsData *tls, gboolean f for (tmp = user_data.frames; tmp; tmp = tmp->next) { f = (StackFrame *)tmp->data; +#ifndef TARGET_WASM /* * Reuse the id for already existing stack frames, so invokes don't invalidate * the still valid stack frames. @@ -3096,7 +3097,9 @@ compute_frame_info (MonoInternalThread *thread, DebuggerTlsData *tls, gboolean f if (i >= tls->frame_count) f->id = mono_atomic_inc_i32 (&frame_id); - +#else //keep the same behavior that we have for wasm before start using debugger-agent + f->id = findex+1; +#endif new_frames [findex ++] = f; } diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs index e64348bc675eb0..de1bd7a829b2a4 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs @@ -928,5 +928,25 @@ await EvaluateAndCheck( await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-test.cs", 719, 8, "MoveNext"); await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-test.cs", 720, 4, "MoveNext"); } + + [Fact] + public async Task CheckResetFrameNumberForEachStep() + { + var bp_conditional = await SetBreakpointInMethod("debugger-test.dll", "SteppingInto", "MethodToStep", 1); + await EvaluateAndCheck( + "window.setTimeout(function() { invoke_static_method('[debugger-test] SteppingInto:MethodToStep'); }, 1);", + "dotnet://debugger-test.dll/debugger-test.cs", + bp_conditional.Value["locations"][0]["lineNumber"].Value(), + bp_conditional.Value["locations"][0]["columnNumber"].Value(), + "MethodToStep" + ); + var pause_location = await StepAndCheck(StepKind.Into, "dotnet://debugger-test.dll/debugger-test.cs", 799, 4, "Increment"); + pause_location = await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-test.cs", 800, 8, "Increment"); + Assert.Equal(pause_location["callFrames"][0]["callFrameId"], "dotnet:scope:1"); + pause_location = await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-test.cs", 801, 8, "Increment"); + Assert.Equal(pause_location["callFrames"][0]["callFrameId"], "dotnet:scope:1"); + pause_location = await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-test.cs", 806, 8, "Increment"); + Assert.Equal(pause_location["callFrames"][0]["callFrameId"], "dotnet:scope:1"); + } } } diff --git a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs index 4ef8045116a62c..2338c9e65d624a 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs @@ -782,3 +782,28 @@ public static void LoopToBreak() } } +public class SteppingInto +{ + static int currentCount = 0; + static MyIncrementer incrementer = new MyIncrementer(); + public static void MethodToStep() + { + currentCount = incrementer.Increment(currentCount); + } +} + +public class MyIncrementer +{ + private Func todayFunc = () => DateTime.Now; + + public int Increment(int count) + { + var today = todayFunc(); + if (today.DayOfWeek == DayOfWeek.Sunday) + { + return count + 2; + } + + return count + 1; + } +} From 8cac74054a458497a6199e7fa4926fcaca3091d2 Mon Sep 17 00:00:00 2001 From: Thays Date: Mon, 20 Sep 2021 16:59:22 -0300 Subject: [PATCH 2/3] Fix compilation. --- src/mono/mono/component/debugger-agent.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/component/debugger-agent.c b/src/mono/mono/component/debugger-agent.c index ed381fb22dd3dc..bfc0a80a5ed63b 100644 --- a/src/mono/mono/component/debugger-agent.c +++ b/src/mono/mono/component/debugger-agent.c @@ -3024,7 +3024,7 @@ compute_frame_info (MonoInternalThread *thread, DebuggerTlsData *tls, gboolean f { ComputeFramesUserData user_data; GSList *tmp; - int i, findex, new_frame_count; + int findex, new_frame_count; StackFrame **new_frames, *f; MonoUnwindOptions opts = (MonoUnwindOptions)(MONO_UNWIND_DEFAULT | MONO_UNWIND_REG_LOCATIONS); @@ -3084,6 +3084,7 @@ compute_frame_info (MonoInternalThread *thread, DebuggerTlsData *tls, gboolean f f = (StackFrame *)tmp->data; #ifndef TARGET_WASM + int i; /* * Reuse the id for already existing stack frames, so invokes don't invalidate * the still valid stack frames. From dd04c200f9141c03bf87285282b2dd1b1f6ef2d6 Mon Sep 17 00:00:00 2001 From: Thays Date: Mon, 20 Sep 2021 17:14:32 -0300 Subject: [PATCH 3/3] Fix compilation. --- src/mono/mono/component/debugger-agent.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mono/mono/component/debugger-agent.c b/src/mono/mono/component/debugger-agent.c index bfc0a80a5ed63b..7eebeb2455808a 100644 --- a/src/mono/mono/component/debugger-agent.c +++ b/src/mono/mono/component/debugger-agent.c @@ -355,7 +355,9 @@ static int objref_id = 0; static int event_request_id = 0; +#ifndef TARGET_WASM static int frame_id = 0; +#endif static GPtrArray *event_requests;