@@ -315,39 +315,39 @@ public MetadataStringDecoder GetMetadataStringDecoder()
315
315
316
316
private PdbSymbolReader OpenAssociatedSymbolFile ( string peFilePath , PEReader peReader )
317
317
{
318
- // Assume that the .pdb file is next to the binary
319
- var pdbFilename = Path . ChangeExtension ( peFilePath , ".pdb" ) ;
320
- string searchPath = "" ;
318
+ string pdbFileName = null ;
319
+ BlobContentId pdbContentId = default ;
321
320
322
- if ( ! File . Exists ( pdbFilename ) )
321
+ foreach ( DebugDirectoryEntry debugEntry in peReader . ReadDebugDirectory ( ) )
323
322
{
324
- pdbFilename = null ;
323
+ if ( debugEntry . Type != DebugDirectoryEntryType . CodeView )
324
+ continue ;
325
325
326
- // If the file doesn't exist, try the path specified in the CodeView section of the image
327
- foreach ( DebugDirectoryEntry debugEntry in peReader . ReadDebugDirectory ( ) )
326
+ CodeViewDebugDirectoryData debugDirectoryData = peReader . ReadCodeViewDebugDirectoryData ( debugEntry ) ;
327
+
328
+ string candidatePath = debugDirectoryData . Path ;
329
+ if ( ! Path . IsPathRooted ( candidatePath ) || ! File . Exists ( candidatePath ) )
328
330
{
329
- if ( debugEntry . Type != DebugDirectoryEntryType . CodeView )
331
+ // Also check next to the PE file
332
+ candidatePath = Path . Combine ( Path . GetDirectoryName ( peFilePath ) , Path . GetFileName ( candidatePath ) ) ;
333
+ if ( ! File . Exists ( candidatePath ) )
330
334
continue ;
331
-
332
- string candidateFileName = peReader . ReadCodeViewDebugDirectoryData ( debugEntry ) . Path ;
333
- if ( Path . IsPathRooted ( candidateFileName ) && File . Exists ( candidateFileName ) )
334
- {
335
- pdbFilename = candidateFileName ;
336
- searchPath = Path . GetDirectoryName ( pdbFilename ) ;
337
- break ;
338
- }
339
335
}
340
-
341
- if ( pdbFilename == null )
342
- return null ;
336
+
337
+ pdbFileName = candidatePath ;
338
+ pdbContentId = new BlobContentId ( debugDirectoryData . Guid , debugEntry . Stamp ) ;
339
+ break ;
343
340
}
344
341
342
+ if ( pdbFileName == null )
343
+ return null ;
344
+
345
345
// Try to open the symbol file as portable pdb first
346
- PdbSymbolReader reader = PortablePdbSymbolReader . TryOpen ( pdbFilename , GetMetadataStringDecoder ( ) ) ;
346
+ PdbSymbolReader reader = PortablePdbSymbolReader . TryOpen ( pdbFileName , GetMetadataStringDecoder ( ) , pdbContentId ) ;
347
347
if ( reader == null )
348
348
{
349
349
// Fallback to the diasymreader for non-portable pdbs
350
- reader = UnmanagedPdbSymbolReader . TryOpenSymbolReaderForMetadataFile ( peFilePath , searchPath ) ;
350
+ reader = UnmanagedPdbSymbolReader . TryOpenSymbolReaderForMetadataFile ( peFilePath , Path . GetDirectoryName ( pdbFileName ) ) ;
351
351
}
352
352
353
353
return reader ;
0 commit comments