Exemplo n.º 1
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
            var reader = SymbolAccess.GetReaderForFile(symFormat, 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);
            assembly = System.Reflection.Assembly.ReflectionOnlyLoadFrom(assemblyPath);

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

            var symbolData = new SymbolData();

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

            symbolData.moduleVersion   = assembly.ManifestModule.ModuleVersionId;
            symbolData.entryPointToken = ReadEntryPoint(reader);
            symbolData.sourceFiles     = ReadDocList(reader);

            if (!skipMethods)
            {
                symbolData.methods = ReadAllMethods(reader);
            }

            return(symbolData);
        }
Exemplo 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);
        }
Exemplo n.º 3
0
        public static SymbolData GetPdbData(string asmPath, SymbolFormat symFormat, bool expandAttrs, bool skipMethods)
        {
            // Read the PDB into a SymbolData object
            SymbolDataReader reader  = new SymbolDataReader(asmPath, symFormat, expandAttrs, skipMethods);
            SymbolData       symData = reader.ReadSymbols();

            return(symData);
        }
Exemplo n.º 4
0
        public static void PdbToXML(string asmPath, string outputXml, SymbolFormat symFormat, bool expandAttrs, bool skipMethods)
        {
            // Read the PDB into a SymbolData object
            SymbolDataReader reader  = new SymbolDataReader(asmPath, symFormat, expandAttrs, skipMethods);
            SymbolData       symData = reader.ReadSymbols();

            if (symData != null)
            {
                PdbDataToXML(outputXml, symData);
            }
        }
Exemplo n.º 5
0
        public static void PdbDataToXML(string outputXml, SymbolData symData)
        {
            // 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);
            }
        }