Esempio n. 1
0
        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);
            }
            finally
            {
                m_writer.Close();
                ((IDisposable)m_writer).Dispose();
                m_writer = null;
                m_docWriters.Clear();
            }

            UpdatePEDebugHeaders(debugInfo);
        }
Esempio n. 2
0
        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);
            }
            finally
            {
                m_writer.Close();
                ((IDisposable)m_writer).Dispose();
                m_writer = null;
                m_docWriters.Clear();
            }

            UpdatePEDebugHeaders(debugInfo);
        }
Esempio n. 3
0
        /// <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
            ISymbolReader reader = SymbolAccess.GetReaderForFile(m_symFormat, m_assemblyPath, null);

            if (reader == null)
            {
                Console.WriteLine("Error: No matching PDB could be found for the specified assembly.");
                return(null);
            }

            AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);
            m_assembly = System.Reflection.Assembly.ReflectionOnlyLoadFrom(m_assemblyPath);

            m_fileMapping = new Dictionary <string, int>();

            SymbolData symbolData = new SymbolData();

            // Record what input file these symbols are for.
            symbolData.assembly = m_assemblyPath;

            symbolData.entryPointToken = ReadEntryPoint(reader);
            symbolData.sourceFiles     = ReadDocList(reader);
            symbolData.methods         = ReadAllMethods(reader);

            return(symbolData);
        }
Esempio n. 4
0
        private static void PdbToXML(string asmPath, string outputXml, SymbolFormat symFormat, bool expandAttrs)
        {
            Console.WriteLine("Reading the {0} symbol file for assembly: {1}", symFormat, asmPath);
            Console.WriteLine("Writing XML file: {0}", outputXml);

            try
            {
                // Read the PDB into a SymbolData object
                SymbolDataReader reader  = new SymbolDataReader(asmPath, symFormat, expandAttrs);
                SymbolData       symData = reader.ReadSymbols();

                if (symData != null)
                {
                    // Use XML serialization to write out the symbol data
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.ConformanceLevel = ConformanceLevel.Document;
                    settings.Indent           = true;
                    XmlSerializer ser = new XmlSerializer(typeof(SymbolData));
                    using (XmlWriter writer = XmlWriter.Create(outputXml, settings))
                    {
                        ser.Serialize(writer, symData);
                    }
                }
            }
            catch (ReflectionTypeLoadException ex)
            {
                foreach (var e in ex.LoaderExceptions)
                {
                    Console.WriteLine(e.Message);
                }
                throw;
            }
        }
Esempio n. 5
0
        /// <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
            ISymbolReader reader = SymbolAccess.GetReaderForFile(m_symFormat, m_assemblyPath, null);
            if (reader == null)
            {
                Console.WriteLine("Error: No matching PDB could be found for the specified assembly.");
                return null;
            }

            AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);
            m_assembly = System.Reflection.Assembly.ReflectionOnlyLoadFrom(m_assemblyPath);

            m_fileMapping = new Dictionary<string, int>();

            SymbolData symbolData = new SymbolData();

            // Record what input file these symbols are for.
            symbolData.assembly = m_assemblyPath;

            symbolData.entryPointToken = ReadEntryPoint(reader);
            symbolData.sourceFiles = ReadDocList(reader);
            symbolData.methods = ReadAllMethods(reader);

            return symbolData;
        }