From b9608c909a4bfc63b41103ba594d3c859652b94b Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Sat, 11 Apr 2026 18:40:19 +0900 Subject: [PATCH] deps: update clrmd version --- src/BenchmarkDotNet/BenchmarkDotNet.csproj | 2 +- .../Disassemblers/ClrMdDisassembler.cs | 45 +++++++------------ 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/BenchmarkDotNet/BenchmarkDotNet.csproj b/src/BenchmarkDotNet/BenchmarkDotNet.csproj index 40dfe132a6..a8e08b8ca6 100644 --- a/src/BenchmarkDotNet/BenchmarkDotNet.csproj +++ b/src/BenchmarkDotNet/BenchmarkDotNet.csproj @@ -27,7 +27,7 @@ - + diff --git a/src/BenchmarkDotNet/Disassemblers/ClrMdDisassembler.cs b/src/BenchmarkDotNet/Disassemblers/ClrMdDisassembler.cs index d5d894e0e3..c92c84620c 100644 --- a/src/BenchmarkDotNet/Disassemblers/ClrMdDisassembler.cs +++ b/src/BenchmarkDotNet/Disassemblers/ClrMdDisassembler.cs @@ -1,4 +1,4 @@ -using BenchmarkDotNet.Detectors; +using BenchmarkDotNet.Detectors; using BenchmarkDotNet.Diagnosers; using BenchmarkDotNet.Extensions; using BenchmarkDotNet.Filters; @@ -41,41 +41,36 @@ private static bool IsValidAddress(ulong address) private DataTarget Attach(int processId) { + var dataTargetOptions = new DataTargetOptions + { + SymbolPaths = ["https://msdl.microsoft.com/download/symbols"], + // TODO: Configure DataTargetLimits default values + }; + + // Ensure symbol cache directory exists https://github.com/microsoft/clrmd/issues/1417 + Directory.CreateDirectory(dataTargetOptions.SymbolCachePath); + bool isSelf = processId == System.Diagnostics.Process.GetCurrentProcess().Id; if (OsDetector.IsWindows()) { // Windows CoreCLR fails to disassemble generic types when using CreateSnapshotAndAttach, and succeeds with AttachToProcess. https://github.com/microsoft/clrmd/issues/1334 return isSelf && !RuntimeInformation.IsNetCore - ? DataTarget.CreateSnapshotAndAttach(processId) - : DataTarget.AttachToProcess(processId, suspend: false); + ? DataTarget.CreateSnapshotAndAttach(processId, dataTargetOptions) + : DataTarget.AttachToProcess(processId, suspend: false, dataTargetOptions); } if (OsDetector.IsLinux()) { // Linux crashes when using AttachToProcess in the same process. + // It seems not fixed by https://github.com/microsoft/clrmd/issues/1282 return isSelf ? DataTarget.CreateSnapshotAndAttach(processId) : DataTarget.AttachToProcess(processId, suspend: false); } if (OsDetector.IsMacOS()) { - // ClrMD does not support CreateSnapshotAndAttach on MacOS, and AttachToProcess is unreliable, so we have to create a dump file and load it. - string dumpPath = Path.GetTempFileName(); - try - { - try - { - new DiagnosticsClient(processId).WriteDump(DumpType.Full, dumpPath, logDumpGeneration: false); - } - catch (ServerErrorException sxe) - { - throw new ArgumentException($"Unable to create a snapshot of process {processId:x}.", sxe); - } - return DataTarget.LoadDump(dumpPath); - } - finally - { - File.Delete(dumpPath); - } + // On macOS it need to use CreateSnapshotAndAttach API instead of AttachToProcess. + // https://github.com/microsoft/clrmd/issues/1034 + return DataTarget.CreateSnapshotAndAttach(processId, dataTargetOptions); } throw new NotSupportedException($"{System.Runtime.InteropServices.RuntimeInformation.OSDescription} is not supported"); } @@ -86,8 +81,6 @@ internal DisassemblyResult AttachAndDisassemble(ClrMdArgs args) var runtime = dataTarget.ClrVersions.Single().CreateRuntime(); - ConfigureSymbols(dataTarget); - var state = new State(runtime, args.TargetFrameworkMoniker); if (args.Filters.Length > 0) @@ -120,12 +113,6 @@ internal DisassemblyResult AttachAndDisassemble(ClrMdArgs args) }; } - private static void ConfigureSymbols(DataTarget dataTarget) - { - // code copied from https://github.com/Microsoft/clrmd/issues/34#issuecomment-161926535 - dataTarget.SetSymbolPath("http://msdl.microsoft.com/download/symbols"); - } - private static void FilterAndEnqueue(State state, ClrMdArgs args) { Regex[] filters = GlobFilter.ToRegex(args.Filters);