public void WritePdb(SymbolData symData) { m_docWriters = new Dictionary<int, ISymbolDocumentWriter>(); ImageDebugDirectory debugDirectory; byte[] debugInfo = null; // Rather than use the emitter here, we are just careful enough to emit pdb metadata that // matches what is already in the assembly image. object emitter = null; // We must be careful to close the writer before updating the debug headers. The writer has an // open file handle on the assembly we want to update. m_writer = SymbolAccess.GetWriterForFile(m_symFormat, m_outputAssembly, ref emitter); // We don't actually need the emitter in managed code at all, so release the CLR reference on it Marshal.FinalReleaseComObject(emitter); try { WriteEntryPoint(symData.entryPointToken); WriteFiles(symData.sourceFiles); WriteMethods(symData.methods); debugInfo = m_writer.GetDebugInfo(out debugDirectory); } catch(Exception ex) { throw; } finally { m_writer.Close(); ((IDisposable)m_writer).Dispose(); m_writer = null; m_docWriters.Clear(); } UpdatePEDebugHeaders(debugInfo); }
/// <summary> /// Load the PDB given the parameters at the ctor and spew it out to the XmlWriter specified /// at the ctor. /// </summary> public SymbolData ReadSymbols() { // Actually load the files SymbolData symbolData = new SymbolData(); // Actually load the files using (SymReader reader = SymbolAccess.GetPdbSymReader(_assemblyPath, null)) { if (reader == null) { Console.WriteLine("Error: No matching PDB could be found for the specified assembly."); return null; } m_fileMapping = new Dictionary<string, int>(); // Record what input file these symbols are for. symbolData.assembly = _assemblyPath; symbolData.entryPointToken = ReadEntryPoint(reader); symbolData.sourceFiles = ReadDocList(reader); symbolData.methods = ReadAllMethods(reader); } return symbolData; }