From 84c5c67f3eb96749012491088d7970a57459e805 Mon Sep 17 00:00:00 2001 From: Mauro Agnoletti Date: Thu, 21 Sep 2023 13:16:20 -0400 Subject: [PATCH] Allow checking only runtime version when invoking VersionInfo.AtLeast (#405) Also, ensure we only check runtime version on EnC related checks This should fix a bug where C# Hot Reload was not working correctly on net7 --- .../Mono.Debugger.Soft/Connection.cs | 21 ++++++++++++------- .../Mono.Debugger.Soft/ModuleMirror.cs | 2 +- .../Mono.Debugger.Soft/VirtualMachine.cs | 6 +++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs b/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs index 2fd2462..265d68b 100644 --- a/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs +++ b/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs @@ -33,19 +33,24 @@ namespace Mono.Debugger.Soft /* * Check that this version is at least major:minor */ - public bool AtLeast (int major, int minor) { - if (debuggerLibsMajorVersion > 2 || (debuggerLibsMajorVersion == 2 && debuggerLibsMinorVersion >= 56)) + public bool AtLeast (int major, int minor, bool checkOnlyRuntime = false) { + if (checkOnlyRuntime) + return AtLeastRuntime (major, minor); + + if (AtLeastDebuggerLibs(2, 56)) { - if (((MajorVersion > major) || ((MajorVersion == major && MinorVersion >= minor))) && - ((debuggerLibsMajorVersion > major) || ((debuggerLibsMajorVersion == major && debuggerLibsMinorVersion >= minor)))) + if (AtLeastRuntime (major, minor) && AtLeastDebuggerLibs(major, minor)) return true; + return false; } - if ((MajorVersion > major) || ((MajorVersion == major && MinorVersion >= minor))) - return true; - else - return false; + + return AtLeastRuntime (major, minor); } + + bool AtLeastRuntime (int major, int minor) => MajorVersion > major || (MajorVersion == major && MinorVersion >= minor); + + bool AtLeastDebuggerLibs (int major, int minor) => debuggerLibsMajorVersion > major || (debuggerLibsMajorVersion == major && debuggerLibsMinorVersion >= minor); } struct SourceInfo { diff --git a/Mono.Debugger.Soft/Mono.Debugger.Soft/ModuleMirror.cs b/Mono.Debugger.Soft/Mono.Debugger.Soft/ModuleMirror.cs index 455360f..f8e5b05 100644 --- a/Mono.Debugger.Soft/Mono.Debugger.Soft/ModuleMirror.cs +++ b/Mono.Debugger.Soft/Mono.Debugger.Soft/ModuleMirror.cs @@ -77,7 +77,7 @@ namespace Mono.Debugger.Soft // Since protocol version 2.60 public void ApplyChanges (ArrayMirror dmeta, ArrayMirror dIL, Value dPDB) { /* dPDB is Value because it can be ArrayMirror or PrimitiveValue (vm, null) */ - vm.CheckProtocolVersion (2, 60); + vm.CheckProtocolVersion (2, 60, checkOnlyRuntime: true); vm.conn.Module_ApplyChanges (id, dmeta.Id, dIL.Id, dPDB.Id); } } diff --git a/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs b/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs index ee1350f..2e87b7c 100644 --- a/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs +++ b/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs @@ -791,14 +791,14 @@ namespace Mono.Debugger.Soft return res; } - internal void CheckProtocolVersion (int major, int minor) { - if (!conn.Version.AtLeast (major, minor)) + internal void CheckProtocolVersion (int major, int minor, bool checkOnlyRuntime = false) { + if (!conn.Version.AtLeast (major, minor, checkOnlyRuntime)) throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee."); } public string GetEnCCapabilities () { - if (conn.Version.AtLeast (2, 61)) + if (conn.Version.AtLeast (2, 61, checkOnlyRuntime: true)) return conn.VM_EnCCapabilities (); return "Baseline"; }