Пример #1
0
 private ISymbolReader getSymbolReader(CorModule module)
 {
     ISymbolReader reader = null;
     string sympath = Path.GetDirectoryName(module.Name);
     string moduleName = module.Name;
     try
     {
         SymbolBinder binder = new SymbolBinder();
         var importer = new CorMetadataImport(module);
         reader = binder.GetReaderForFile(importer.RawCOMObject, moduleName, sympath);
     }
     catch (COMException ex)
     {
         if (ex.ErrorCode == unchecked((int)0x806D0014))  // E_PDB_CORRUPT
         {
             // Ignore it.
             // This may happen for mismatched pdbs
         }
         else
             throw;
     }
     return reader;
 }
Пример #2
0
        public void SetBreakPoint(int lineNumber, string moduleNameHint, string fileNameHint)
        {
            if (state == ProcessState.Terminated) throw new InvalidProcessException();
            List<CorModule> matchingModules =
                modules.Where(module => module.Name.Contains(moduleNameHint)).ToList();
            if (matchingModules.Count > 1) throw new MultipleMatchException();
            if (matchingModules.Count == 0) throw new NoMatchException();
            CorModule corModule = matchingModules.First();
            var pdbFile = new FileInfo(corModule.Name);
            var binder = new SymbolBinder();
            var metadataImport = corModule.GetMetaDataInterface<IMetadataImport>();
            ISymbolReader reader = binder.GetReaderForFile(metadataImport, pdbFile.FullName, null,
                                                           SymSearchPolicies.AllowOriginalPathAccess |
                                                           SymSearchPolicies.AllowReferencePathAccess);

            Index(reader, corModule);
            ISymbolDocument[] documents = reader.GetDocuments();
            List<ISymbolDocument> matchingDocuments =
                documents.Where(document => Regex.Match(document.URL, fileNameHint).Success).ToList();
            if (matchingDocuments.Count > 1) throw new MultipleMatchException();
            if (matchingDocuments.Count == 0) throw new NoMatchException();
            ISymbolDocument source = matchingDocuments.First();
            int line = source.FindClosestLine(lineNumber);
            ISymbolMethod method = reader.GetMethodFromDocumentPosition(source, line, 1);
            CorFunction function = corModule.GetFunctionFromToken(method.Token.GetToken());
            SequencePoints points = SequencePoints.From(method);
            SequencePoint pointToBreak =
                points.Where(point => lineNumber >= point.StartLine && line <= point.EndLine).First();

            CorFunctionBreakpoint breakpoint = function.ILCode.CreateBreakpoint(pointToBreak.Offset);
            breakpoints.Add(breakpoint);
            breakpoint.Activate(true);
            subscriber.Published(string.Format("Successfully set breakpoint on line {0} in file {1} in module {2}",
                                               lineNumber, source.URL, corModule.Name));
        }