예제 #1
0
 private void Add(PdbState state)
 {
     if (state == null)
     {
         return;
     }
     Add(state.UserEntryPoint);
 }
예제 #2
0
 WindowsPdbWriter(PdbState pdbState, Metadata metadata)
 {
     this.pdbState = pdbState;
     this.metadata = metadata;
     module        = metadata.Module;
     instrToOffset = new Dictionary <Instruction, uint>();
     customDebugInfoWriterContext = new PdbCustomDebugInfoWriterContext();
     localsEndScopeIncValue       = PdbUtils.IsEndInclusive(PdbFileKind.WindowsPDB, pdbState.Compiler) ? 1 : 0;
 }
예제 #3
0
 WindowsPdbWriter(PdbState pdbState, MetaData metaData)
 {
     this.pdbState      = pdbState;
     this.metaData      = metaData;
     this.module        = metaData.Module;
     this.instrToOffset = new Dictionary <Instruction, uint>();
     this.customDebugInfoWriterContext = new PdbCustomDebugInfoWriterContext();
     this.localsEndScopeIncValue       = pdbState.Compiler == Compiler.VisualBasic ? 1 : 0;
 }
예제 #4
0
 public WindowsPdbWriter(SymbolWriter writer, PdbState pdbState, Metadata metadata)
     : this(pdbState, metadata)
 {
     if (pdbState is null)
     {
         throw new ArgumentNullException(nameof(pdbState));
     }
     if (metadata is null)
     {
         throw new ArgumentNullException(nameof(metadata));
     }
     this.writer = writer ?? throw new ArgumentNullException(nameof(writer));
     writer.Initialize(metadata);
 }
예제 #5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="writer">Symbol writer</param>
 /// <param name="pdbState">PDB state</param>
 /// <param name="metaData">Meta data</param>
 public WindowsPdbWriter(ISymbolWriter3 writer, PdbState pdbState, MetaData metaData)
     : this(pdbState, metaData)
 {
     if (writer == null)
     {
         throw new ArgumentNullException("writer");
     }
     if (pdbState == null)
     {
         throw new ArgumentNullException("pdbState");
     }
     if (metaData == null)
     {
         throw new ArgumentNullException("metaData");
     }
     this.writer  = writer;
     this.writer3 = writer;
     writer.Initialize(metaData);
 }
예제 #6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="writer">Symbol writer, it should implement <see cref="ISymbolWriter3"/></param>
 /// <param name="pdbState">PDB state</param>
 /// <param name="metaData">Meta data</param>
 public WindowsPdbWriter(ISymbolWriter2 writer, PdbState pdbState, MetaData metaData)
     : this(pdbState, metaData)
 {
     if (writer == null)
     {
         throw new ArgumentNullException("writer");
     }
     if (pdbState == null)
     {
         throw new ArgumentNullException("pdbState");
     }
     if (metaData == null)
     {
         throw new ArgumentNullException("metaData");
     }
     this.writer  = writer;
     this.writer3 = writer as ISymbolWriter3;
     Debug.Assert(writer3 != null, "Symbol writer doesn't implement interface ISymbolWriter3");
     writer.Initialize(metaData);
 }
예제 #7
0
        void WriteWindowsPdb(PdbState pdbState)
        {
            var symWriter = GetWindowsPdbSymbolWriter();

            if (symWriter == null)
            {
                Error("Could not create a PDB symbol writer. A Windows OS might be required.");
                return;
            }

            using (var pdbWriter = new WindowsPdbWriter(symWriter, pdbState, metaData)) {
                pdbWriter.Logger = TheOptions.Logger;
                pdbWriter.Write();

                IMAGE_DEBUG_DIRECTORY idd;
                var data  = pdbWriter.GetDebugInfo(out idd);
                var entry = debugDirectory.Add(data);
                entry.DebugDirectory = idd;
                entry.DebugDirectory.TimeDateStamp = GetTimeDateStamp();
            }
        }
예제 #8
0
        /// <summary>
        /// Writes the module to a <see cref="Stream"/>
        /// </summary>
        /// <param name="dest">Destination stream</param>
        public void Write(Stream dest)
        {
            pdbState = TheOptions.WritePdb && Module.PdbState != null ? Module.PdbState : null;
            if (TheOptions.DelaySign)
            {
                Debug.Assert(TheOptions.StrongNamePublicKey != null, "Options.StrongNamePublicKey must be initialized when delay signing the assembly");
                Debug.Assert(TheOptions.StrongNameKey == null, "Options.StrongNameKey must be null when delay signing the assembly");
                TheOptions.Cor20HeaderOptions.Flags &= ~ComImageFlags.StrongNameSigned;
            }
            else if (TheOptions.StrongNameKey != null || TheOptions.StrongNamePublicKey != null)
            {
                TheOptions.Cor20HeaderOptions.Flags |= ComImageFlags.StrongNameSigned;
            }

            Listener             = TheOptions.Listener ?? DummyModuleWriterListener.Instance;
            destStream           = dest;
            destStreamBaseOffset = destStream.Position;
            Listener.OnWriterEvent(this, ModuleWriterEvent.Begin);
            var imageLength = WriteImpl();

            destStream.Position = destStreamBaseOffset + imageLength;
            Listener.OnWriterEvent(this, ModuleWriterEvent.End);
        }
예제 #9
0
 void Add(PdbState state)
 {
     if (state == null)
         return;
     Add(state.UserEntryPoint);
 }
예제 #10
0
        void WritePortablePdb(PdbState pdbState, bool isEmbeddedPortablePdb)
        {
            bool   ownsStream = false;
            Stream pdbStream  = null;

            try {
                MemoryStream embeddedMemoryStream = null;
                if (isEmbeddedPortablePdb)
                {
                    pdbStream  = embeddedMemoryStream = new MemoryStream();
                    ownsStream = true;
                }
                else
                {
                    pdbStream = GetStandalonePortablePdbStream(out ownsStream);
                }

                var pdbFilename = TheOptions.PdbFileName ?? GetStreamName(pdbStream) ?? GetDefaultPdbFileName();
                if (isEmbeddedPortablePdb)
                {
                    pdbFilename = Path.GetFileName(pdbFilename);
                }

                uint entryPointToken;
                if (pdbState.UserEntryPoint == null)
                {
                    entryPointToken = 0;
                }
                else
                {
                    entryPointToken = new MDToken(Table.Method, metaData.GetRid(pdbState.UserEntryPoint)).Raw;
                }

                var pdbId       = new byte[20];
                var pdbIdWriter = new BinaryWriter(new MemoryStream(pdbId));
                var pdbGuid     = TheOptions.PdbGuid;
                pdbIdWriter.Write(pdbGuid.ToByteArray());
                pdbIdWriter.Write(GetTimeDateStamp());
                Debug.Assert(pdbIdWriter.BaseStream.Position == pdbId.Length);

                metaData.WritePortablePdb(pdbStream, entryPointToken, pdbId);

                const uint age     = 1;
                var        cvEntry = debugDirectory.Add(GetCodeViewData(pdbGuid, age, pdbFilename));
                cvEntry.DebugDirectory.TimeDateStamp = GetTimeDateStamp();
                cvEntry.DebugDirectory.MajorVersion  = PortablePdbConstants.FormatVersion;
                cvEntry.DebugDirectory.MinorVersion  = PortablePdbConstants.PortableCodeViewVersionMagic;
                cvEntry.DebugDirectory.Type          = ImageDebugType.CodeView;

                if (isEmbeddedPortablePdb)
                {
                    Debug.Assert(embeddedMemoryStream != null);
                    var embedEntry = debugDirectory.Add(CreateEmbeddedPortablePdbBlob(embeddedMemoryStream));
                    embedEntry.DebugDirectory.TimeDateStamp = 0;
                    embedEntry.DebugDirectory.MajorVersion  = PortablePdbConstants.FormatVersion;
                    embedEntry.DebugDirectory.MinorVersion  = PortablePdbConstants.EmbeddedVersion;
                    embedEntry.DebugDirectory.Type          = ImageDebugType.EmbeddedPortablePdb;
                }
            }
            finally {
                if (ownsStream && pdbStream != null)
                {
                    pdbStream.Dispose();
                }
            }
        }