1- using BenchmarkDotNet . Detectors ;
1+ using BenchmarkDotNet . Detectors ;
22using BenchmarkDotNet . Diagnosers ;
33using BenchmarkDotNet . Extensions ;
44using BenchmarkDotNet . Filters ;
@@ -41,41 +41,33 @@ 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 cache directory exists
51+ // Ensure symbol cache directory exists https://github.com/microsoft/clrmd/issues/1417
52+ Directory . CreateDirectory ( dataTargetOptions . SymbolCachePath ) ;
53+
4454 bool isSelf = processId == System . Diagnostics . Process . GetCurrentProcess ( ) . Id ;
4555 if ( OsDetector . IsWindows ( ) )
4656 {
4757 // Windows CoreCLR fails to disassemble generic types when using CreateSnapshotAndAttach, and succeeds with AttachToProcess. https://github.com/microsoft/clrmd/issues/1334
4858 return isSelf && ! RuntimeInformation . IsNetCore
49- ? DataTarget . CreateSnapshotAndAttach ( processId )
50- : DataTarget . AttachToProcess ( processId , suspend : false ) ;
59+ ? DataTarget . CreateSnapshotAndAttach ( processId , dataTargetOptions )
60+ : DataTarget . AttachToProcess ( processId , suspend : false , dataTargetOptions ) ;
5161 }
5262 if ( OsDetector . IsLinux ( ) )
5363 {
54- // Linux crashes when using AttachToProcess in the same process.
55- return isSelf
56- ? DataTarget . CreateSnapshotAndAttach ( processId )
57- : DataTarget . AttachToProcess ( processId , suspend : false ) ;
64+ return DataTarget . AttachToProcess ( processId , suspend : false , dataTargetOptions ) ;
5865 }
5966 if ( OsDetector . IsMacOS ( ) )
6067 {
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- }
68+ // On macOS it need to use CreateSnapshotAndAttach API instead of AttachToProcess.
69+ // https://github.com/microsoft/clrmd/issues/1034
70+ return DataTarget . CreateSnapshotAndAttach ( processId , dataTargetOptions ) ;
7971 }
8072 throw new NotSupportedException ( $ "{ System . Runtime . InteropServices . RuntimeInformation . OSDescription } is not supported") ;
8173 }
@@ -86,8 +78,6 @@ internal DisassemblyResult AttachAndDisassemble(ClrMdArgs args)
8678
8779 var runtime = dataTarget . ClrVersions . Single ( ) . CreateRuntime ( ) ;
8880
89- ConfigureSymbols ( dataTarget ) ;
90-
9181 var state = new State ( runtime , args . TargetFrameworkMoniker ) ;
9282
9383 if ( args . Filters . Length > 0 )
@@ -120,12 +110,6 @@ internal DisassemblyResult AttachAndDisassemble(ClrMdArgs args)
120110 } ;
121111 }
122112
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-
129113 private static void FilterAndEnqueue ( State state , ClrMdArgs args )
130114 {
131115 Regex [ ] filters = GlobFilter . ToRegex ( args . Filters ) ;
0 commit comments