55using System . Diagnostics ;
66using System . IO ;
77
8+ #nullable enable
9+
810namespace BenchmarkDotNet . Disassemblers
911{
1012 internal class SourceCodeProvider : IDisposable
1113 {
1214 private readonly Dictionary < SourceFile , string [ ] > sourceFileCache = new Dictionary < SourceFile , string [ ] > ( ) ;
1315 private readonly Dictionary < SourceFile , string > sourceFilePathsCache = new Dictionary < SourceFile , string > ( ) ;
14- private readonly Dictionary < PdbInfo , ManagedSymbolModule > pdbReaders = new Dictionary < PdbInfo , ManagedSymbolModule > ( ) ;
16+ private readonly Dictionary < PdbInfo , ManagedSymbolModule ? > pdbReaders = new Dictionary < PdbInfo , ManagedSymbolModule ? > ( ) ;
1517 private readonly SymbolReader symbolReader = new SymbolReader ( TextWriter . Null ) { SymbolPath = SymbolPath . MicrosoftSymbolServerPath } ;
1618
1719 public void Dispose ( )
@@ -47,11 +49,11 @@ internal IEnumerable<Sharp> GetSource(ClrMethod method, ILToNativeMap map)
4749 }
4850
4951 private string GetFilePath ( SourceFile sourceFile )
50- => sourceFilePathsCache . TryGetValue ( sourceFile , out string filePath ) ? filePath : sourceFile . Url ;
52+ => sourceFilePathsCache . TryGetValue ( sourceFile , out var filePath ) ? filePath : sourceFile . Url ;
5153
52- private string ReadSourceLine ( SourceFile file , int line )
54+ private string ? ReadSourceLine ( SourceFile file , int line )
5355 {
54- if ( ! sourceFileCache . TryGetValue ( file , out string [ ] contents ) )
56+ if ( ! sourceFileCache . TryGetValue ( file , out var contents ) )
5557 {
5658 // GetSourceFile method returns path when file is stored on the same machine
5759 // otherwise it downloads it from the Symbol Server and returns the source code ;)
@@ -107,7 +109,7 @@ private static string GetSmartPointer(string sourceLine, int? start, int? end)
107109 return new string ( prefix ) ;
108110 }
109111
110- internal SourceLocation GetSourceLocation ( ClrMethod method , int ilOffset )
112+ internal SourceLocation ? GetSourceLocation ( ClrMethod method , int ilOffset )
111113 {
112114 var reader = GetReaderForMethod ( method ) ;
113115 if ( reader == null )
@@ -116,37 +118,10 @@ internal SourceLocation GetSourceLocation(ClrMethod method, int ilOffset)
116118 return reader . SourceLocationForManagedCode ( ( uint ) method . MetadataToken , ilOffset ) ;
117119 }
118120
119- internal SourceLocation GetSourceLocation ( ClrStackFrame frame )
120- {
121- var reader = GetReaderForMethod ( frame . Method ) ;
122- if ( reader == null )
123- return null ;
124-
125- return reader . SourceLocationForManagedCode ( ( uint ) frame . Method . MetadataToken , FindIlOffset ( frame ) ) ;
126- }
127-
128- private static int FindIlOffset ( ClrStackFrame frame )
129- {
130- ulong ip = frame . InstructionPointer ;
131- int last = - 1 ;
132- foreach ( ILToNativeMap item in frame . Method . ILOffsetMap )
133- {
134- if ( item . StartAddress > ip )
135- return last ;
136-
137- if ( ip <= item . EndAddress )
138- return item . ILOffset ;
139-
140- last = item . ILOffset ;
141- }
142-
143- return last ;
144- }
145-
146- private ManagedSymbolModule GetReaderForMethod ( ClrMethod method )
121+ private ManagedSymbolModule ? GetReaderForMethod ( ClrMethod ? method )
147122 {
148- ClrModule module = method ? . Type ? . Module ;
149- PdbInfo info = module ? . Pdb ;
123+ ClrModule ? module = method ? . Type ? . Module ;
124+ PdbInfo ? info = module ? . Pdb ;
150125
151126 ManagedSymbolModule ? reader = null ;
152127 if ( info != null )
0 commit comments