1- using BenchmarkDotNet . Detectors ;
1+ using BenchmarkDotNet . Detectors ;
22using BenchmarkDotNet . Diagnosers ;
33using BenchmarkDotNet . Extensions ;
44using BenchmarkDotNet . Filters ;
@@ -41,41 +41,36 @@ private static bool IsValidAddress(ulong address)
4141
4242 private DataTarget Attach ( int processId )
4343 {
44+ var dataTargetOptions = new DataTargetOptions
45+ {
46+ SymbolPaths = [ "https://msdl.microsoft.com/download/symbols" ] ,
47+ // TODO: Configure DataTargetLimits default values
48+ } ;
49+
50+ // Ensure symbol cache directory exists https://github.com/microsoft/clrmd/issues/1417
51+ Directory . CreateDirectory ( dataTargetOptions . SymbolCachePath ) ;
52+
4453 bool isSelf = processId == System . Diagnostics . Process . GetCurrentProcess ( ) . Id ;
4554 if ( OsDetector . IsWindows ( ) )
4655 {
4756 // Windows CoreCLR fails to disassemble generic types when using CreateSnapshotAndAttach, and succeeds with AttachToProcess. https://github.com/microsoft/clrmd/issues/1334
4857 return isSelf && ! RuntimeInformation . IsNetCore
49- ? DataTarget . CreateSnapshotAndAttach ( processId )
50- : DataTarget . AttachToProcess ( processId , suspend : false ) ;
58+ ? DataTarget . CreateSnapshotAndAttach ( processId , dataTargetOptions )
59+ : DataTarget . AttachToProcess ( processId , suspend : false , dataTargetOptions ) ;
5160 }
5261 if ( OsDetector . IsLinux ( ) )
5362 {
5463 // Linux crashes when using AttachToProcess in the same process.
64+ // It seems not fixed by https://github.com/microsoft/clrmd/issues/1282
5565 return isSelf
5666 ? DataTarget . CreateSnapshotAndAttach ( processId )
5767 : DataTarget . AttachToProcess ( processId , suspend : false ) ;
5868 }
5969 if ( OsDetector . IsMacOS ( ) )
6070 {
61- // ClrMD does not support CreateSnapshotAndAttach on MacOS, and AttachToProcess is unreliable, so we have to create a dump file and load it.
62- string dumpPath = Path . GetTempFileName ( ) ;
63- try
64- {
65- try
66- {
67- new DiagnosticsClient ( processId ) . WriteDump ( DumpType . Full , dumpPath , logDumpGeneration : false ) ;
68- }
69- catch ( ServerErrorException sxe )
70- {
71- throw new ArgumentException ( $ "Unable to create a snapshot of process { processId : x} .", sxe ) ;
72- }
73- return DataTarget . LoadDump ( dumpPath ) ;
74- }
75- finally
76- {
77- File . Delete ( dumpPath ) ;
78- }
71+ // On macOS it need to use CreateSnapshotAndAttach API instead of AttachToProcess.
72+ // https://github.com/microsoft/clrmd/issues/1034
73+ return DataTarget . CreateSnapshotAndAttach ( processId , dataTargetOptions ) ;
7974 }
8075 throw new NotSupportedException ( $ "{ System . Runtime . InteropServices . RuntimeInformation . OSDescription } is not supported") ;
8176 }
@@ -86,8 +81,6 @@ internal DisassemblyResult AttachAndDisassemble(ClrMdArgs args)
8681
8782 var runtime = dataTarget . ClrVersions . Single ( ) . CreateRuntime ( ) ;
8883
89- ConfigureSymbols ( dataTarget ) ;
90-
9184 var state = new State ( runtime , args . TargetFrameworkMoniker ) ;
9285
9386 if ( args . Filters . Length > 0 )
@@ -120,12 +113,6 @@ internal DisassemblyResult AttachAndDisassemble(ClrMdArgs args)
120113 } ;
121114 }
122115
123- private static void ConfigureSymbols ( DataTarget dataTarget )
124- {
125- // code copied from https://github.com/Microsoft/clrmd/issues/34#issuecomment-161926535
126- dataTarget . SetSymbolPath ( "http://msdl.microsoft.com/download/symbols" ) ;
127- }
128-
129116 private static void FilterAndEnqueue ( State state , ClrMdArgs args )
130117 {
131118 Regex [ ] filters = GlobFilter . ToRegex ( args . Filters ) ;
0 commit comments