Beispiel #1
0
        private static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: dumppdb PDBFILE");
                Console.WriteLine("Dumps the parsed symbols from the given PDBFILE in CSV format.");
                return;
            }

            string                 pdbFile          = args[0];
            string                 assemblyName     = Path.GetFileNameWithoutExtension(pdbFile);
            MethodMapper           mapper           = new MethodMapper();
            AssemblyMethodMappings assemblyMappings = mapper.GetMethodMappings(pdbFile, assemblyName);
            // sorts the elements by source file and then line number since OrderBy guarantees a stable sort
            IEnumerable <MethodMapping> sortedMappings = assemblyMappings.MethodMappings.OrderBy(mapping => mapping.StartLine)
                                                         .OrderBy(mapping => mapping.SourceFile);

            Console.WriteLine("MethodToken, StartLine, EndLine, SourceFile");
            foreach (MethodMapping mapping in assemblyMappings.MethodMappings)
            {
                // we pad all fields to the length of the corresponding header plus the comma to align
                // the fields nicely on the console for easy readability
                // the source file is the last field because we cannot pad it to a fixed length
                string tokenField     = $"{mapping.MethodToken},".PadRight(12);
                string startLineField = $"{mapping.StartLine},".PadRight(10);
                string endLineField   = $"{mapping.EndLine},".PadRight(8);
                Console.WriteLine($"{tokenField} {startLineField} {endLineField} {mapping.SourceFile}");
            }
        }
        public void CompilerHiddenLinesShouldBeIgnored()
        {
            ParsedTraceFile traceFile = new ParsedTraceFile(new string[] {
                "Assembly=Test:2 Version:1.0.0.0",
                "Inlined=2:1234",
            }, "coverage_12345_1234.txt");

            AssemblyMethodMappings mappings = new AssemblyMethodMappings
            {
                AssemblyName   = "Test",
                SymbolFileName = "Test.pdb",
            };

            mappings.MethodMappings.Add(new MethodMapping
            {
                MethodToken = 1234,
                SourceFile  = "",
                StartLine   = 16707566,
                EndLine     = 16707566,
            });
            mappings.MethodMappings.Add(new MethodMapping
            {
                MethodToken = 1234,
                SourceFile  = @"c:\some\file.cs",
                StartLine   = 16707566,
                EndLine     = 16707566,
            });

            SymbolCollection symbolCollection = new SymbolCollection(new List <AssemblyMethodMappings>()
            {
                mappings
            });

            Dictionary <string, FileCoverage> coverage = LineCoverageSynthesizer.ConvertToLineCoverage(traceFile, symbolCollection, TestUtils.TestDataDirectory,
                                                                                                       new GlobPatternList(new List <string> {
                "*"
            }, new List <string> {
            }));

            Assert.That(coverage, Is.Empty);
        }
        /// <summary>
        /// Creates a symbol collection from the given PDB files.
        /// </summary>
        public static SymbolCollection CreateFromFiles(IEnumerable <string> pdbFilePaths)
        {
            MethodMapper mapper = new MethodMapper();
            List <AssemblyMethodMappings> mappings = new List <AssemblyMethodMappings>();

            foreach (string filePath in pdbFilePaths)
            {
                logger.Debug("Loading mappings from PDB {filePath}", filePath);
                string assemblyName = Path.GetFileNameWithoutExtension(filePath);
                try
                {
                    AssemblyMethodMappings assemblyMappings = mapper.GetMethodMappings(filePath, assemblyName);
                    mappings.Add(assemblyMappings);
                }
                catch (Exception e)
                {
                    logger.Error(e, "Failed to parse PDB file {pdbFile}. This file will be ignored and no coverage will be reported for its corresponding assembly." +
                                 " You may get follow-up errors that method IDs cannot be resolved for this assembly", filePath);
                }
            }
            return(new SymbolCollection(mappings));
        }