From 93a2f4ea395c431ec61269b36e9a0f8c68a8e804 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Thu, 26 Mar 2020 19:04:09 -0300 Subject: [PATCH] Fix suspend_policy that will be sent to debugger-libs, because on debugger-libs we want to resume the VM only when it's suspended, but we were sending the wrong suspend_policy in the case of EVENT_KIND_VM_START and mono is started with suspend=y. (#19330) With this fix we can do this PR again: https://github.com/mono/debugger-libs/pull/264/ Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/999375/ --- .../Mono.Debugger.Soft/Connection.cs | 2 +- mcs/class/Mono.Debugger.Soft/Test/dtest.cs | 29 +++++++++++++++++++++- mono/mini/debugger-agent.c | 8 +++--- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs b/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs index 3e2cf5f33af..03724b7f7bc 100644 --- a/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs +++ b/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs @@ -436,7 +436,7 @@ namespace Mono.Debugger.Soft * with newer runtimes, and vice versa. */ internal const int MAJOR_VERSION = 2; - internal const int MINOR_VERSION = 54; + internal const int MINOR_VERSION = 55; enum WPSuspendPolicy { NONE = 0, diff --git a/mcs/class/Mono.Debugger.Soft/Test/dtest.cs b/mcs/class/Mono.Debugger.Soft/Test/dtest.cs index 60fcfe29c6f..473ce2f355e 100644 --- a/mcs/class/Mono.Debugger.Soft/Test/dtest.cs +++ b/mcs/class/Mono.Debugger.Soft/Test/dtest.cs @@ -5197,9 +5197,36 @@ public class DebuggerTests Assert.IsInstanceOfType (typeof (ArgumentException), ex); } } + + [Test] + public void CheckSuspendPolicySentWhenLaunchSuspendYes () { + vm.Exit (0); + var port = GetFreePort (); + // Launch the app using server=y,suspend=y + var pi = CreateStartInfo (dtest_app_path, "attach", $"--debugger-agent=transport=dt_socket,address=127.0.0.1:{port},server=y,suspend=y"); + pi.UseShellExecute = false; + var process = Diag.Process.Start (pi); - + string failMessage = null; + try { + vm = ConnectToPort (port); + + vm.EnableEvents (EventType.AssemblyLoad, EventType.ThreadStart); + var es = vm.GetNextEventSet (); + Assert.AreEqual (es.SuspendPolicy, SuspendPolicy.All); + Assert.AreEqual (EventType.VMStart, es[0].EventType); + } + catch (Exception ex) { + failMessage = ex.Message; + } + finally { + vm.Exit (0); + vm = null; + } + if (failMessage != null) + Assert.Fail (failMessage); + } #endif } // class DebuggerTests } // namespace diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 085cf52147e..38f856effb9 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -292,7 +292,7 @@ typedef struct { #define HEADER_LENGTH 11 #define MAJOR_VERSION 2 -#define MINOR_VERSION 54 +#define MINOR_VERSION 55 typedef enum { CMD_SET_VM = 1, @@ -3901,7 +3901,10 @@ process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx return; } } - + + if (event == EVENT_KIND_VM_START) + suspend_policy = agent_config.suspend ? SUSPEND_POLICY_ALL : SUSPEND_POLICY_NONE; + nevents = g_slist_length (events); buffer_init (&buf, 128); buffer_add_byte (&buf, suspend_policy); @@ -4012,7 +4015,6 @@ process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx } if (event == EVENT_KIND_VM_START) { - suspend_policy = agent_config.suspend ? SUSPEND_POLICY_ALL : SUSPEND_POLICY_NONE; if (!agent_config.defer) { ERROR_DECL (error); start_debugger_thread (error); -- 2.11.4.GIT