Example #1
0
        public unsafe PeDebugDirectory GetDebugDirectory()
        {
            ImageDebugDirectory debugDir = new ImageDebugDirectory();
            uint dataCount = 0;

            try
            {
                this.symWriter.GetDebugInfo(ref debugDir, 0, out dataCount, IntPtr.Zero);
            }
            catch (Exception ex)
            {
                throw new PdbWritingException(ex);
            }

            // See symwrite.cpp - the data don't depend on the content of metadata tables or IL
            // 
            // struct RSDSI                     
            // {
            //     DWORD dwSig;                 // "RSDS"
            //     GUID guidSig;
            //     DWORD age;
            //     char szPDB[0];               // zero-terminated UTF8 file name
            // };
            //
            byte[] data = new byte[dataCount];

            fixed (byte* pb = data)
            {
                try
                {
                    this.symWriter.GetDebugInfo(ref debugDir, dataCount, out dataCount, (IntPtr)pb);
                }
                catch (Exception ex)
                {
                    throw new PdbWritingException(ex);
                }
            }

            PeDebugDirectory result = new PeDebugDirectory();
            result.AddressOfRawData = (uint)debugDir.AddressOfRawData;
            result.Characteristics = (uint)debugDir.Characteristics;
            result.Data = data;
            result.MajorVersion = (ushort)debugDir.MajorVersion;
            result.MinorVersion = (ushort)debugDir.MinorVersion;
            result.PointerToRawData = (uint)debugDir.PointerToRawData;
            result.SizeOfData = (uint)debugDir.SizeOfData;
            result.TimeDateStamp = (uint)debugDir.TimeDateStamp;
            result.Type = (uint)debugDir.Type;

            return result;
        }
Example #2
0
        public unsafe ContentId GetContentId()
        {
            if (_deterministic)
            {
                // rewrite GUID and timestamp in the PDB with hash of a has of the log content:
                byte[] hash = _callLogger.GetLogHash();

                try
                {
                    fixed (byte* hashPtr = &hash[0])
                    {
                        ((ISymUnmanagedWriter7)_symWriter).UpdateSignatureByHashingContent(hashPtr, hash.Length);
                    }
                }
                catch (Exception ex)
                {
                    throw new PdbWritingException(ex);
                }
            }

            // See symwrite.cpp - the data byte[] doesn't depend on the content of metadata tables or IL.
            // The writer only sets two values of the ImageDebugDirectory struct.
            // 
            //   IMAGE_DEBUG_DIRECTORY *pIDD
            // 
            //   if ( pIDD == NULL ) return E_INVALIDARG;
            //   memset( pIDD, 0, sizeof( *pIDD ) );
            //   pIDD->Type = IMAGE_DEBUG_TYPE_CODEVIEW;
            //   pIDD->SizeOfData = cTheData;

            ImageDebugDirectory debugDir = new ImageDebugDirectory();
            uint dataLength;

            try
            {
                _symWriter.GetDebugInfo(ref debugDir, 0, out dataLength, IntPtr.Zero);
            }
            catch (Exception ex)
            {
                throw new PdbWritingException(ex);
            }

            byte[] data = new byte[dataLength];
            fixed (byte* pb = data)
            {
                try
                {
                    _symWriter.GetDebugInfo(ref debugDir, dataLength, out dataLength, (IntPtr)pb);
                }
                catch (Exception ex)
                {
                    throw new PdbWritingException(ex);
                }
            }

            // Data has the following structure:
            // struct RSDSI                     
            // {
            //     DWORD dwSig;                 // "RSDS"
            //     GUID guidSig;                // GUID
            //     DWORD age;                   // age
            //     char szPDB[0];               // zero-terminated UTF8 file name passed to the writer
            // };
            const int GuidSize = 16;
            byte[] guidBytes = new byte[GuidSize];
            Buffer.BlockCopy(data, 4, guidBytes, 0, guidBytes.Length);

            // Retrieve the timestamp the PDB writer generates when creating a new PDB stream.
            // Note that ImageDebugDirectory.TimeDateStamp is not set by GetDebugInfo, 
            // we need to go through IPdbWriter interface to get it.
            uint stamp;
            uint age;
            ((IPdbWriter)_symWriter).GetSignatureAge(out stamp, out age);
            Debug.Assert(age == Age);

            Debug.Assert(BitConverter.IsLittleEndian);
            return new ContentId(guidBytes, BitConverter.GetBytes(stamp));
        }
Example #3
0
 public unsafe PeDebugDirectory GetDebugDirectory() {
   ImageDebugDirectory debugDir = new ImageDebugDirectory();
   uint pcData = 0;
   this.SymWriter.GetDebugInfo(ref debugDir, 0, out pcData, IntPtr.Zero);
   byte[] data = new byte[pcData];
   fixed (byte* pb = data) {
     this.SymWriter.GetDebugInfo(ref debugDir, pcData, out pcData, (IntPtr)pb);
   }
   PeDebugDirectory result = new PeDebugDirectory();
   result.AddressOfRawData = (uint)debugDir.AddressOfRawData;
   result.Characteristics = (uint)debugDir.Characteristics;
   result.Data = data;
   result.MajorVersion = (ushort)debugDir.MajorVersion;
   result.MinorVersion = (ushort)debugDir.MinorVersion;
   result.PointerToRawData = (uint)debugDir.PointerToRawData;
   result.SizeOfData = (uint)debugDir.SizeOfData;
   result.TimeDateStamp = (uint)debugDir.TimeDateStamp;
   result.Type = (uint)debugDir.Type;
   return result;
 }
		public void GetDebugInfo (ref ImageDebugDirectory ptrIDD, uint dataCount, out uint dataCountPtr, IntPtr data)
		{
			// PdbWriter.GetContentId will use this function.
			//
			// Data has the following structure:
			// struct RSDSI                     
			// {
			//     DWORD dwSig;                 // "RSDS"
			//     GUID guidSig;                // GUID
			//     DWORD age;                   // age
			//     char szPDB[0];               // zero-terminated UTF8 file name passed to the writer
			// };

			dataCountPtr = 4 + 16 + 4 + 1;
		}
Example #5
0
        public unsafe ContentId GetContentId()
        {
            if (_deterministic)
            {
                // Call to GetDebugInfo fails for SymWriter initialized using InitializeDeterministic.
                // We already have all the info we need though.

                // TODO (https://github.com/dotnet/roslyn/issues/926): calculate sha1 hash
                var id = new ContentId(
                    new byte[] { 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, },
                    new byte[] { 0x12, 0x12, 0x12, 0x12 });

                try
                {
                    Debug.Assert(BitConverter.IsLittleEndian);
                    ((ISymUnmanagedWriter6)_symWriter).SetSignature(BitConverter.ToUInt32(id.Stamp, 0), new Guid(id.Guid));
                }
                catch (Exception ex)
                {
                    throw new PdbWritingException(ex);
                }

                return(id);
            }

            // See symwrite.cpp - the data byte[] doesn't depend on the content of metadata tables or IL.
            // The writer only sets two values of the ImageDebugDirectory struct.
            //
            //   IMAGE_DEBUG_DIRECTORY *pIDD
            //
            //   if ( pIDD == NULL ) return E_INVALIDARG;
            //   memset( pIDD, 0, sizeof( *pIDD ) );
            //   pIDD->Type = IMAGE_DEBUG_TYPE_CODEVIEW;
            //   pIDD->SizeOfData = cTheData;

            ImageDebugDirectory debugDir = new ImageDebugDirectory();
            uint dataLength;

            try
            {
                _symWriter.GetDebugInfo(ref debugDir, 0, out dataLength, IntPtr.Zero);
            }
            catch (Exception ex)
            {
                throw new PdbWritingException(ex);
            }

            byte[] data = new byte[dataLength];
            fixed(byte *pb = data)
            {
                try
                {
                    _symWriter.GetDebugInfo(ref debugDir, dataLength, out dataLength, (IntPtr)pb);
                }
                catch (Exception ex)
                {
                    throw new PdbWritingException(ex);
                }
            }

            // Data has the following structure:
            // struct RSDSI
            // {
            //     DWORD dwSig;                 // "RSDS"
            //     GUID guidSig;                // GUID
            //     DWORD age;                   // age
            //     char szPDB[0];               // zero-terminated UTF8 file name passed to the writer
            // };
            const int GuidSize = 16;

            byte[] guidBytes = new byte[GuidSize];
            Buffer.BlockCopy(data, 4, guidBytes, 0, guidBytes.Length);

            // Retrieve the timestamp the PDB writer generates when creating a new PDB stream.
            // Note that ImageDebugDirectory.TimeDateStamp is not set by GetDebugInfo,
            // we need to go thru IPdbWriter interface to get it.
            uint stamp;
            uint age;

            ((IPdbWriter)_symWriter).GetSignatureAge(out stamp, out age);
            Debug.Assert(age == Age);

            Debug.Assert(BitConverter.IsLittleEndian);
            return(new ContentId(guidBytes, BitConverter.GetBytes(stamp)));
        }
Example #6
0
        public unsafe ContentId GetContentId()
        {
            if (_deterministic)
            {
                // Call to GetDebugInfo fails for SymWriter initialized using InitializeDeterministic.
                // We already have all the info we need though.

                // TODO (https://github.com/dotnet/roslyn/issues/926): calculate sha1 hash
                var id = new ContentId(
                    new byte[] { 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, },
                    new byte[] { 0x12, 0x12, 0x12, 0x12 });

                try
                {
                    Debug.Assert(BitConverter.IsLittleEndian);
                    ((ISymUnmanagedWriter6)_symWriter).SetSignature(BitConverter.ToUInt32(id.Stamp, 0), new Guid(id.Guid));
                }
                catch (Exception ex)
                {
                    throw new PdbWritingException(ex);
                }

                return id;
            }

            // See symwrite.cpp - the data byte[] doesn't depend on the content of metadata tables or IL.
            // The writer only sets two values of the ImageDebugDirectory struct.
            // 
            //   IMAGE_DEBUG_DIRECTORY *pIDD
            // 
            //   if ( pIDD == NULL ) return E_INVALIDARG;
            //   memset( pIDD, 0, sizeof( *pIDD ) );
            //   pIDD->Type = IMAGE_DEBUG_TYPE_CODEVIEW;
            //   pIDD->SizeOfData = cTheData;
            
            ImageDebugDirectory debugDir = new ImageDebugDirectory();
            uint dataLength;

            try
            {
                _symWriter.GetDebugInfo(ref debugDir, 0, out dataLength, IntPtr.Zero);
            }
            catch (Exception ex)
            {
                throw new PdbWritingException(ex);
            }

            byte[] data = new byte[dataLength];
            fixed (byte* pb = data)
            {
                try
                {
                    _symWriter.GetDebugInfo(ref debugDir, dataLength, out dataLength, (IntPtr)pb);
                }
                catch (Exception ex)
                {
                    throw new PdbWritingException(ex);
                }
            }

            // Data has the following structure:
            // struct RSDSI                     
            // {
            //     DWORD dwSig;                 // "RSDS"
            //     GUID guidSig;                // GUID
            //     DWORD age;                   // age
            //     char szPDB[0];               // zero-terminated UTF8 file name passed to the writer
            // };
            const int GuidSize = 16;
            byte[] guidBytes = new byte[GuidSize];
            Buffer.BlockCopy(data, 4, guidBytes, 0, guidBytes.Length);

            // Retrieve the timestamp the PDB writer generates when creating a new PDB stream.
            // Note that ImageDebugDirectory.TimeDateStamp is not set by GetDebugInfo, 
            // we need to go thru IPdbWriter interface to get it.
            uint stamp;
            uint age;
            ((IPdbWriter)_symWriter).GetSignatureAge(out stamp, out age);
            Debug.Assert(age == Age);

            Debug.Assert(BitConverter.IsLittleEndian);
            return new ContentId(guidBytes, BitConverter.GetBytes(stamp));
        }