private static DbgId?GetDbgIdFromPEFile(string peFilePath) { DbgId?dbgId = null; using (var file = File.Open(peFilePath, FileMode.Open, FileAccess.Read)) { using (var portableExecutableReader = new PEReader(file)) { foreach (var debugDirectory in portableExecutableReader.ReadDebugDirectory()) { if (debugDirectory.Type == DebugDirectoryEntryType.CodeView) { var cv = portableExecutableReader.ReadCodeViewDebugDirectoryData(debugDirectory); dbgId = new DbgId(cv.Guid, (uint)cv.Age, cv.Path); break; } } } } return(dbgId); }
public async ValueTask <IPdbSymbolReader> GetSymbolReader(string peFilePath, Guid signature, uint age, string pdbName) { var sigKey = new DbgId(signature, age, pdbName); if (!this.signaturePdbSymbolReaderMap.TryGetValue(sigKey, out var pdbSymbolReader)) { // now check if we can find this pdb adjacent to the dll and obviously validate its guid and age string pdbPath = Path.ChangeExtension(peFilePath, ".pdb"); bool validPdb = false; bool validPortablePdb = IsValidPortablePdb(pdbPath, signature); if (!validPortablePdb) { // now check to see if the filename embedded in the debug info works pdbPath = pdbName; validPortablePdb = IsValidPortablePdb(pdbPath, signature); if (!validPortablePdb) { // now goto the symbol server pdbPath = await this.symbolServerArtifactRetriever.DownloadPortablePdb(Path.GetFileName(pdbName), signature, skipSymbolServer : false); validPortablePdb = pdbPath != null; // convention, we return null on failure from symbol servers if (!validPortablePdb) { // now check if we can find this pdb adjacent to the dll and obviously validate its guid and age pdbPath = Path.ChangeExtension(peFilePath, ".pdb"); validPdb = IsValidPdb(pdbPath, signature, age); if (!validPdb) { // now check to see if the filename embedded in the debug info works pdbPath = pdbName; validPdb = IsValidPdb(pdbPath, signature, age); if (!validPdb) { // now goto the symbol server pdbPath = await this.symbolServerArtifactRetriever.DownloadPdb(Path.GetFileName(pdbName), signature, age, skipSymbolServer : false); validPdb = pdbPath != null; // convention, we return null on failure from symbol servers } } } } } if (validPdb) { pdbSymbolReader = new WindowsPdbSymbolReader(pdbPath); } else if (validPortablePdb) { pdbSymbolReader = new PortablePdbSymbolReader(pdbPath); } this.signaturePdbSymbolReaderMap.Add(sigKey, pdbSymbolReader); // pdbSymbolReader can be null, which means we couldn't find one } return(pdbSymbolReader); }