提交 b74c2a5a 编写于 作者: A acasey

Share constants between CustomDebugInfoReader and CustomDebugInfoWriter.

They weren't out of sync - let's keep them that way.

CR: JaredPar; ChuckS; VSadov (changeset 1375293)
上级 6e53036b
......@@ -322,6 +322,7 @@
<Compile Include="PEWriter\ClrHeader.cs" />
<Compile Include="PEWriter\Constants.cs" />
<Compile Include="PEWriter\Core.cs" />
<Compile Include="PEWriter\CustomDebugInfoConstants.cs" />
<Compile Include="PEWriter\CustomDebugInfoWriter.cs" />
<Compile Include="PEWriter\DebugSourceDocument.cs" />
<Compile Include="PEWriter\DirectoryEntry.cs" />
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.Cci
{
/// <summary>
/// Constants for producing and consuming streams of binary custom debug info.
/// </summary>
internal static class CustomDebugInfoConstants
{
// The version number of the custom debug info binary format.
// CDIVERSION in Dev10
internal const int CdiVersion = 4;
// The number of bytes at the beginning of the byte array that contain global header information.
// start after header (version byte + size byte + dword padding)
internal const int CdiGlobalHeaderSize = 4;
// The number of bytes at the beginning of each custom debug info record that contain header information
// common to all record types (i.e. byte, kind, size).
// version byte + kind byte + two bytes padding + size dword
internal const int CdiRecordHeaderSize = 8;
internal const byte CdiKindUsingInfo = 0;
internal const byte CdiKindForwardInfo = 1;
internal const byte CdiKindForwardToModuleInfo = 2;
internal const byte CdiKindStateMachineHoistedLocalScopes = 3;
internal const byte CdiKindForwardIterator = 4;
internal const byte CdiKindDynamicLocals = 5;
internal const byte CdiKindEditAndContinueLocalSlotMap = 6;
}
}
\ No newline at end of file
......@@ -5,9 +5,9 @@
using System.Diagnostics;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeGen;
using Microsoft.CodeAnalysis.Emit;
using Roslyn.Utilities;
using CDI = Microsoft.Cci.CustomDebugInfoConstants;
namespace Microsoft.Cci
{
......@@ -146,8 +146,8 @@ private static void SerializeReferenceToIteratorClass(string iteratorClassName,
if (iteratorClassName == null) return;
MemoryStream customMetadata = new MemoryStream();
BinaryWriter cmw = new BinaryWriter(customMetadata, true);
cmw.WriteByte(4); // version
cmw.WriteByte(4); // kind: ForwardIterator
cmw.WriteByte(CDI.CdiVersion);
cmw.WriteByte(CDI.CdiKindForwardIterator);
cmw.Align(4);
uint length = 10 + (uint)iteratorClassName.Length * 2;
if ((length & 3) != 0) length += 4 - (length & 3);
......@@ -169,8 +169,8 @@ private static void SerializeStateMachineLocalScopes(IMethodBody methodBody, Arr
uint numberOfScopes = (uint)scopes.Length;
MemoryStream customMetadata = new MemoryStream();
BinaryWriter cmw = new BinaryWriter(customMetadata);
cmw.WriteByte(4); // version
cmw.WriteByte(3); // kind: IteratorLocals
cmw.WriteByte(CDI.CdiVersion);
cmw.WriteByte(CDI.CdiKindStateMachineHoistedLocalScopes);
cmw.Align(4);
cmw.WriteUint(12 + numberOfScopes * 8);
cmw.WriteUint(numberOfScopes);
......@@ -218,8 +218,8 @@ private static void SerializeDynamicLocalInfo(IMethodBody methodBody, ArrayBuild
const int blobSize = 200;//DynamicAttribute - 64, DynamicAttributeLength - 4, SlotIndex -4, IdentifierName - 128
MemoryStream customMetadata = new MemoryStream();
BinaryWriter cmw = new BinaryWriter(customMetadata, true);
cmw.WriteByte(4);//Version
cmw.WriteByte(5);//Kind : Dynamic Locals
cmw.WriteByte(CDI.CdiVersion);
cmw.WriteByte(CDI.CdiKindDynamicLocals);
cmw.Align(4);
// size = Version,Kind + size + cBuckets + (dynamicCount * sizeOf(Local Blob))
cmw.WriteUint(4 + 4 + 4 + (uint)dynamicLocals.Count * blobSize);//Size of the Dynamic Block
......@@ -284,7 +284,7 @@ private static byte[] SerializeCustomDebugMetadata(ArrayBuilder<MemoryStream> cu
MemoryStream customMetadata = MemoryStream.GetInstance();
BinaryWriter cmw = new BinaryWriter(customMetadata);
cmw.WriteByte(4); // version
cmw.WriteByte(CDI.CdiVersion);
cmw.WriteByte((byte)customDebugInfo.Count); // count
cmw.Align(4);
foreach (MemoryStream ms in customDebugInfo)
......@@ -324,8 +324,8 @@ private void SerializeNamespaceScopeMetadata(IMethodBody methodBody, ArrayBuilde
if (usingCounts.Count > 0)
{
uint streamLength = 0;
cmw.WriteByte(4); // version
cmw.WriteByte(0); // kind: UsingInfo
cmw.WriteByte(CDI.CdiVersion);
cmw.WriteByte(CDI.CdiKindUsingInfo);
cmw.Align(4);
cmw.WriteUint(streamLength = BitArithmeticUtilities.Align((uint)usingCounts.Count * 2 + 10, 4));
......@@ -363,8 +363,8 @@ private void SerializeReferenceToMethodWithModuleInfo(ArrayBuilder<MemoryStream>
{
MemoryStream customMetadata = new MemoryStream(12);
BinaryWriter cmw = new BinaryWriter(customMetadata);
cmw.WriteByte(4); // version
cmw.WriteByte(2); // kind: ForwardToModuleInfo
cmw.WriteByte(CDI.CdiVersion);
cmw.WriteByte(CDI.CdiKindForwardToModuleInfo);
cmw.Align(4);
cmw.WriteUint(12);
cmw.WriteUint(this.methodTokenWithModuleInfo);
......@@ -375,8 +375,8 @@ private void SerializeReferenceToPreviousMethodWithUsingInfo(ArrayBuilder<Memory
{
MemoryStream customMetadata = new MemoryStream(12);
BinaryWriter cmw = new BinaryWriter(customMetadata);
cmw.WriteByte(4); // version
cmw.WriteByte(1); // kind: ForwardInfo
cmw.WriteByte(CDI.CdiVersion);
cmw.WriteByte(CDI.CdiKindForwardInfo);
cmw.Align(4);
cmw.WriteUint(12);
cmw.WriteUint(this.previousMethodTokenWithUsingInfo);
......
......@@ -18,6 +18,7 @@
using Microsoft.Samples.Debugging.SymbolStore;
using Roslyn.Utilities.Pdb;
using CDI = Roslyn.Utilities.Pdb.CustomDebugInfoReader;
using CDIC = Microsoft.Cci.CustomDebugInfoConstants;
using PooledStringBuilder = Microsoft.CodeAnalysis.Collections.PooledStringBuilder;
namespace Roslyn.Test.PdbUtilities
......@@ -282,7 +283,7 @@ private void WriteCustomDebugInfo(byte[] bytes)
int size;
CDI.ReadRecordHeader(bytes, ref offset, out version, out kind, out size);
if (version != CDI.CdiVersion)
if (version != CDIC.CdiVersion)
{
WriteUnknownCustomDebugInfo(version, kind, size, bytes, ref offset);
}
......@@ -537,7 +538,7 @@ private unsafe void WriteEditAndContinueLocalSlotMap(byte version, CustomDebugIn
WriteCustomDebugInfoRecordHeaderAttributes(version, kind, size);
int bodySize = size - CDI.CdiRecordHeaderSize;
int bodySize = size - CDIC.CdiRecordHeaderSize;
int syntaxOffsetBaseline = -1;
fixed (byte* compressedSlotMapPtr = &bytes[offset])
......
......@@ -83,6 +83,9 @@
<Compile Include="Pdb\PdbToXmlOptions.cs" />
<Compile Include="Pdb\TempPdbReader.cs" />
<Compile Include="Pdb\Token2SourceLineExporter.cs" />
<Compile Include="..\..\Compilers\Core\Portable\PEWriter\CustomDebugInfoConstants.cs">
<Link>Shared\CustomDebugInfoConstants.cs</Link>
</Compile>
<Compile Include="Shared\CustomDebugInfoReader.cs" />
<Compile Include="Shared\DummyMetadataImport.cs" />
<Compile Include="Shared\IMetadataImport.cs" />
......
......@@ -6,6 +6,7 @@
using System.Globalization;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Collections;
using CDI = Microsoft.Cci.CustomDebugInfoConstants;
namespace Roslyn.Utilities.Pdb
{
......@@ -17,19 +18,6 @@ namespace Roslyn.Utilities.Pdb
/// </remarks>
internal static class CustomDebugInfoReader
{
// The version number of the custom debug info binary format.
// CDIVERSION in Dev10
internal const int CdiVersion = 4;
// The number of bytes at the beginning of the byte array that contain global header information.
// start after header (version byte + size byte + dword padding)
private const int CdiGlobalHeaderSize = 4;
// The number of bytes at the beginning of each custom debug info record that contain header information
// common to all record types (i.e. byte, kind, size).
// version byte + kind byte + two bytes padding + size dword
internal const int CdiRecordHeaderSize = 8;
/// <summary>
/// This is the first header in the custom debug info blob.
/// </summary>
......@@ -37,7 +25,7 @@ public static void ReadGlobalHeader(byte[] bytes, ref int offset, out byte versi
{
version = bytes[offset + 0];
count = bytes[offset + 1];
offset += CdiGlobalHeaderSize;
offset += CDI.CdiGlobalHeaderSize;
}
/// <summary>
......@@ -52,12 +40,12 @@ public static void ReadRecordHeader(byte[] bytes, ref int offset, out byte versi
// two bytes of padding after kind
size = BitConverter.ToInt32(bytes, offset + 4);
offset += CdiRecordHeaderSize;
offset += CDI.CdiRecordHeaderSize;
}
internal static ImmutableArray<byte> TryGetCustomDebugInfoRecord(byte[] customDebugInfo, CustomDebugInfoKind recordKind)
{
if (customDebugInfo.Length < CdiGlobalHeaderSize)
if (customDebugInfo.Length < CDI.CdiGlobalHeaderSize)
{
return default(ImmutableArray<byte>);
}
......@@ -68,32 +56,32 @@ internal static ImmutableArray<byte> TryGetCustomDebugInfoRecord(byte[] customDe
byte globalCount;
ReadGlobalHeader(customDebugInfo, ref offset, out globalVersion, out globalCount);
if (globalVersion != CdiVersion)
if (globalVersion != CDI.CdiVersion)
{
return default(ImmutableArray<byte>);
}
while (offset <= customDebugInfo.Length - CdiRecordHeaderSize)
while (offset <= customDebugInfo.Length - CDI.CdiRecordHeaderSize)
{
byte version;
CustomDebugInfoKind kind;
int size;
ReadRecordHeader(customDebugInfo, ref offset, out version, out kind, out size);
if (size < CdiRecordHeaderSize)
if (size < CDI.CdiRecordHeaderSize)
{
// invalid header
break;
}
int bodySize = size - CdiRecordHeaderSize;
int bodySize = size - CDI.CdiRecordHeaderSize;
if (offset > customDebugInfo.Length - bodySize)
{
// invalid header
break;
}
if (version != CdiVersion || kind != recordKind)
if (version != CDI.CdiVersion || kind != recordKind)
{
offset += bodySize;
continue;
......@@ -130,7 +118,7 @@ public static void ReadUsingRecord(byte[] bytes, ref int offset, int size, out I
counts = builder.ToImmutableAndFree();
offset += size - CdiRecordHeaderSize;
offset += size - CDI.CdiRecordHeaderSize;
Debug.Assert(offset >= tempOffset);
}
......@@ -147,7 +135,7 @@ public static void ReadForwardRecord(byte[] bytes, ref int offset, int size, out
token = BitConverter.ToInt32(bytes, tempOffset);
offset += size - CdiRecordHeaderSize;
offset += size - CDI.CdiRecordHeaderSize;
Debug.Assert(offset >= tempOffset);
}
......@@ -164,7 +152,7 @@ public static void ReadForwardToModuleRecord(byte[] bytes, ref int offset, int s
token = BitConverter.ToInt32(bytes, tempOffset);
offset += size - CdiRecordHeaderSize;
offset += size - CDI.CdiRecordHeaderSize;
Debug.Assert(offset >= tempOffset);
}
......@@ -191,7 +179,7 @@ public static void ReadStateMachineHoistedLocalScopesRecord(byte[] bytes, ref in
scopes = builder.ToImmutableAndFree();
offset += size - CdiRecordHeaderSize;
offset += size - CDI.CdiRecordHeaderSize;
Debug.Assert(offset >= tempOffset);
}
......@@ -222,7 +210,7 @@ public static void ReadForwardIteratorRecord(byte[] bytes, ref int offset, int s
name = pooled.ToStringAndFree();
offset += size - CdiRecordHeaderSize;
offset += size - CDI.CdiRecordHeaderSize;
Debug.Assert(offset >= tempOffset);
}
......@@ -287,7 +275,7 @@ public static void ReadDynamicLocalsRecord(byte[] bytes, ref int offset, int siz
buckets = builder.ToImmutableAndFree();
offset += size - CdiRecordHeaderSize;
offset += size - CDI.CdiRecordHeaderSize;
Debug.Assert(offset >= tempOffset);
}
......@@ -296,7 +284,7 @@ public static void ReadDynamicLocalsRecord(byte[] bytes, ref int offset, int siz
/// </summary>
public static void ReadRawRecordBody(byte[] bytes, ref int offset, int size, out ImmutableArray<byte> body)
{
int bodySize = size - CdiRecordHeaderSize;
int bodySize = size - CDI.CdiRecordHeaderSize;
body = ImmutableArray.Create(bytes, offset, bodySize);
offset += bodySize;
}
......@@ -306,7 +294,7 @@ public static void ReadRawRecordBody(byte[] bytes, ref int offset, int size, out
/// </summary>
public static void SkipRecord(byte[] bytes, ref int offset, int size)
{
offset += size - CdiRecordHeaderSize;
offset += size - CDI.CdiRecordHeaderSize;
}
/// <summary>
......@@ -508,9 +496,9 @@ public static ImmutableArray<string> GetVisualBasicImportStrings(this ISymUnmana
private static void CheckVersion(byte globalVersion, int methodToken)
{
if (globalVersion != CdiVersion)
if (globalVersion != CDI.CdiVersion)
{
throw new InvalidOperationException(string.Format("Method {0}: Expected version {1}, but found version {2}.", FormatMethodToken(methodToken), CdiVersion, globalVersion));
throw new InvalidOperationException(string.Format("Method {0}: Expected version {1}, but found version {2}.", FormatMethodToken(methodToken), CDI.CdiVersion, globalVersion));
}
}
......@@ -950,12 +938,12 @@ public DynamicLocalBucket(int flagCount, ulong flags, int slotId, string name)
/// </summary>
internal enum CustomDebugInfoKind : byte
{
UsingInfo = 0,
ForwardInfo = 1,
ForwardToModuleInfo = 2,
StateMachineHoistedLocalScopes = 3,
ForwardIterator = 4,
DynamicLocals = 5,
EditAndContinueLocalSlotMap = 6,
UsingInfo = CDI.CdiKindUsingInfo,
ForwardInfo = CDI.CdiKindForwardInfo,
ForwardToModuleInfo = CDI.CdiKindForwardToModuleInfo,
StateMachineHoistedLocalScopes = CDI.CdiKindStateMachineHoistedLocalScopes,
ForwardIterator = CDI.CdiKindForwardIterator,
DynamicLocals = CDI.CdiKindDynamicLocals,
EditAndContinueLocalSlotMap = CDI.CdiKindEditAndContinueLocalSlotMap,
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册