Esempio n. 1
0
 public void CloseTokenSourceLocationsScope()
 {
     if (this.symWriter5 != null)
     {
         this.symWriter5.CloseMapTokensToSourceSpans();
     }
     this.symWriter5 = null;
 }
Esempio n. 2
0
        public void WriteDefinitionLocations(PeWriter peWriter, MultiDictionary <Cci.DebugSourceDocument, Cci.DefinitionWithLocation> file2definitions)
        {
            ISymUnmanagedWriter5 writer5 = this.symWriter as ISymUnmanagedWriter5;

            if ((object)writer5 != null)
            {
                // NOTE: ISymUnmanagedWriter5 reports HRESULT = 0x806D000E in case we open and close
                //       the map without writing any resords with MapTokenToSourceSpan(...)
                bool open = false;

                foreach (var doc in file2definitions.Keys)
                {
                    ISymUnmanagedDocumentWriter docWriter = GetDocumentWriter(doc);
                    foreach (var definition in file2definitions[doc])
                    {
                        if (!open)
                        {
                            try
                            {
                                writer5.OpenMapTokensToSourceSpans();
                            }
                            catch (Exception ex)
                            {
                                throw new PdbWritingException(ex);
                            }

                            open = true;
                        }

                        uint token = peWriter.GetTokenForDefinition(definition.Definition);
                        Debug.Assert(token != 0);

                        try
                        {
                            writer5.MapTokenToSourceSpan(token, docWriter,
                                                         definition.StartLine + 1, definition.StartColumn + 1, definition.EndLine + 1, definition.EndColumn + 1);
                        }
                        catch (Exception ex)
                        {
                            throw new PdbWritingException(ex);
                        }
                    }
                }

                if (open)
                {
                    try
                    {
                        writer5.CloseMapTokensToSourceSpans();
                    }
                    catch (Exception ex)
                    {
                        throw new PdbWritingException(ex);
                    }
                }
            }
        }
Esempio n. 3
0
        internal SymUnmanagedWriterImpl(ComMemoryStream pdbStream, ISymUnmanagedWriter5 symWriter, string symWriterModuleName)
        {
            Debug.Assert(pdbStream != null);
            Debug.Assert(symWriter != null);
            Debug.Assert(symWriterModuleName != null);

            _pdbStream           = pdbStream;
            _symWriter           = symWriter;
            _documentWriters     = new List <ISymUnmanagedDocumentWriter>();
            _symWriterModuleName = symWriterModuleName;
        }
Esempio n. 4
0
        public void SetMetadataEmitter(object metadataEmitter)
        {
            Type t = Type.GetTypeFromProgID("CorSymWriter_SxS", false);

            if (t != null)
            {
                this.symWriter = (ISymUnmanagedWriter2)Activator.CreateInstance(t);
                this.symWriter.Initialize(metadataEmitter, this.fileName, null, true);
                if (this.emitTokenSourceInfo)
                {
                    this.symWriter5 = this.symWriter as ISymUnmanagedWriter5;
                }
            }
        }
Esempio n. 5
0
        public void SetMetadataEmitter(object metadataEmitter)
        {
            object symWriterObject = CoCreateInstance(
                ref CLSID_CorSymWriter_SxS, IntPtr.Zero, CLSCTX_INPROC_SERVER, ref IID_ISymUnmanagedWriter2);

            if (symWriterObject != null)
            {
                this.symWriter = (ISymUnmanagedWriter2)symWriterObject;
                this.symWriter.Initialize(metadataEmitter, this.fileName, null, true);
                if (this.emitTokenSourceInfo)
                {
                    this.symWriter5 = this.symWriter as ISymUnmanagedWriter5;
                }
            }
        }
Esempio n. 6
0
        public void SetMetadataEmitter(MetadataWriter metadataWriter)
        {
            try
            {
                var symWriter = (ISymUnmanagedWriter5)(_symWriterFactory != null ? _symWriterFactory() : CreateSymWriterWorker());

                // Correctness: If the stream is not specified or if it is non-empty the SymWriter appends data to it (provided it contains valid PDB)
                // and the resulting PDB has Age = existing_age + 1.
                _pdbStream = new ComMemoryStream();

                if (_deterministic)
                {
                    if (!(symWriter is ISymUnmanagedWriter7))
                    {
                        throw new NotSupportedException(CodeAnalysisResources.SymWriterNotDeterministic);
                    }

                    ((ISymUnmanagedWriter7)symWriter).InitializeDeterministic(new PdbMetadataWrapper(metadataWriter), _pdbStream);
                }
                else
                {
                    symWriter.Initialize(new PdbMetadataWrapper(metadataWriter), _fileName, _pdbStream, fullBuild: true);
                }

                _metadataWriter = metadataWriter;
                _symWriter = symWriter;
            }
            catch (Exception ex)
            {
                throw new PdbWritingException(ex);
            }
        }
Esempio n. 7
0
 private void Close()
 {
     try
     {
         _symWriter?.Close();
         _symWriter = null;
         _pdbStream = null;
     }
     catch (Exception ex)
     {
         throw new PdbWritingException(ex);
     }
 }
Esempio n. 8
0
        public unsafe void WriteTo(Stream stream)
        {
            Debug.Assert(_pdbStream != null);
            Debug.Assert(_symWriter != null);

            try
            {
                // SymWriter flushes data to the native stream on close:
                _symWriter.Close();
                _symWriter = null;
                _pdbStream.CopyTo(stream);
            }
            catch (Exception ex)
            {
                throw new PdbWritingException(ex);
            }
        }
Esempio n. 9
0
 public void CloseTokenSourceLocationsScope() {
   if (this.symWriter5 != null)
     this.symWriter5.CloseMapTokensToSourceSpans();
   this.symWriter5 = null;
 }
Esempio n. 10
0
 public void SetMetadataEmitter(object metadataEmitter) {
   Type t = Type.GetTypeFromProgID("CorSymWriter_SxS", false);
   if (t != null) {
     this.symWriter = (ISymUnmanagedWriter2)Activator.CreateInstance(t);
     this.symWriter.Initialize(metadataEmitter, this.fileName, null, true);
     if (this.emitTokenSourceInfo)
       this.symWriter5 = this.symWriter as ISymUnmanagedWriter5;
   }
 }
Esempio n. 11
0
    public void SetMetadataEmitter(object metadataEmitter) {
      object symWriterObject = CoCreateInstance(
          ref CLSID_CorSymWriter_SxS, IntPtr.Zero, CLSCTX_INPROC_SERVER, ref IID_ISymUnmanagedWriter2);

      if (symWriterObject != null) {
        this.symWriter = (ISymUnmanagedWriter2)symWriterObject;
        this.symWriter.Initialize(metadataEmitter, this.fileName, null, true);
        if (this.emitTokenSourceInfo)
          this.symWriter5 = this.symWriter as ISymUnmanagedWriter5;
      }
    }