From f28f9d89f6962c47d9c3cf698e57ba157ae4e19f Mon Sep 17 00:00:00 2001 From: Mike McLaughlin Date: Thu, 6 Jun 2024 10:52:48 -0700 Subject: [PATCH] Change SOS breaking change from warning to error; better dotnet-dump target errors (#4713) * Change DAC breaking change behavior from warning to error. * Better dotnet-dump analyze error message for cross OS dumps. Don't allow Linux and Windows dumps when running on MacOS; don't allow OSX and Windows dumps when running on Linux. --- src/SOS/Strike/strike.cpp | 17 +++++++++++++---- src/SOS/Strike/util.cpp | 6 +++--- src/Tools/dotnet-dump/Analyzer.cs | 11 ++++++----- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/SOS/Strike/strike.cpp b/src/SOS/Strike/strike.cpp index 4dbb74da9..b6f42fef6 100644 --- a/src/SOS/Strike/strike.cpp +++ b/src/SOS/Strike/strike.cpp @@ -2892,7 +2892,10 @@ DECLARE_API(PrintException) return E_INVALIDARG; } - CheckBreakingRuntimeChange(); + if (CheckBreakingRuntimeChange()) + { + return E_FAIL; + } if (bLineNumbers) { @@ -4802,8 +4805,10 @@ DECLARE_API(Threads) if (bSupported) { - CheckBreakingRuntimeChange(); - + if (CheckBreakingRuntimeChange()) + { + return E_FAIL; + } HRESULT Status2 = PrintSpecialThreads(); if (!SUCCEEDED(Status2)) Status = Status2; @@ -7451,7 +7456,11 @@ DECLARE_API(DumpLog) return E_FAIL; } - CheckBreakingRuntimeChange(); + if (CheckBreakingRuntimeChange()) + { + return E_FAIL; + } + LoadRuntimeSymbols(); const char* fileName = "StressLog.txt"; diff --git a/src/SOS/Strike/util.cpp b/src/SOS/Strike/util.cpp index c850f74a8..63001e199 100644 --- a/src/SOS/Strike/util.cpp +++ b/src/SOS/Strike/util.cpp @@ -3391,9 +3391,9 @@ bool CheckBreakingRuntimeChange(int* pVersion) { if (version > SOS_BREAKING_CHANGE_VERSION) { - ExtWarn("WARNING: SOS needs to be upgraded for this version of the runtime. Some commands may not work correctly.\n"); - ExtWarn("For more information see https://go.microsoft.com/fwlink/?linkid=2135652\n"); - ExtWarn("\n"); + ExtErr("SOS needs to be upgraded for this version of the runtime. Some commands may not work correctly.\n"); + ExtErr("For more information see https://go.microsoft.com/fwlink/?linkid=2135652\n"); + ExtErr("\n"); result = true; } } diff --git a/src/Tools/dotnet-dump/Analyzer.cs b/src/Tools/dotnet-dump/Analyzer.cs index 0fa51a64b..321488433 100644 --- a/src/Tools/dotnet-dump/Analyzer.cs +++ b/src/Tools/dotnet-dump/Analyzer.cs @@ -115,13 +115,14 @@ namespace Microsoft.Diagnostics.Tools.Dump try { using DataTarget dataTarget = DataTarget.LoadDump(dump_path.FullName); - OSPlatform targetPlatform = dataTarget.DataReader.TargetPlatform; - if (targetPlatform != OSPlatform.OSX && - (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || - dataTarget.DataReader.EnumerateModules().Any((module) => Path.GetExtension(module.FileName) == ".dylib"))) + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && (targetPlatform != OSPlatform.OSX)) + { + throw new NotSupportedException("Analyzing Windows or Linux dumps not supported when running on MacOS"); + } + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && (targetPlatform != OSPlatform.Linux)) { - targetPlatform = OSPlatform.OSX; + throw new NotSupportedException("Analyzing Windows or MacOS dumps not supported when running on Linux"); } TargetFromDataReader target = new(dataTarget.DataReader, targetPlatform, this, _targetIdFactory++, dump_path.FullName); contextService.SetCurrentTarget(target); -- 2.34.1