private static void SerializeStateMachineLocalScopes(IMethodBody methodBody, ArrayBuilder <PooledBlobBuilder> customDebugInfo) { System.Collections.Immutable.ImmutableArray <StateMachineHoistedLocalScope> scopes = methodBody.StateMachineHoistedLocalScopes; if (scopes.IsDefaultOrEmpty) { return; } uint numberOfScopes = (uint)scopes.Length; PooledBlobBuilder cmw = PooledBlobBuilder.GetInstance(); cmw.WriteByte(CustomDebugInfoConstants.Version); cmw.WriteByte((byte)CustomDebugInfoKind.StateMachineHoistedLocalScopes); cmw.Align(4); cmw.WriteUInt32(12 + numberOfScopes * 8); cmw.WriteUInt32(numberOfScopes); foreach (StateMachineHoistedLocalScope scope in scopes) { if (scope.IsDefault) { cmw.WriteUInt32(0); cmw.WriteUInt32(0); } else { // Dev12 C# emits end-inclusive range cmw.WriteUInt32((uint)scope.StartOffset); cmw.WriteUInt32((uint)scope.EndOffset - 1); } } customDebugInfo.Add(cmw); }
private static PooledBlobBuilder SerializeRecord <T>( CustomDebugInfoKind kind, T debugInfo, Action <T, BlobBuilder> recordSerializer) { PooledBlobBuilder cmw = PooledBlobBuilder.GetInstance(); cmw.WriteByte(CustomDebugInfoConstants.Version); cmw.WriteByte((byte)kind); cmw.WriteByte(0); // alignment size and length (will be patched) BlobWriter alignmentSizeAndLengthWriter = new BlobWriter(cmw.ReserveBytes(sizeof(byte) + sizeof(uint))); recordSerializer(debugInfo, cmw); int length = cmw.Count; int alignedLength = 4 * ((length + 3) / 4); byte alignmentSize = (byte)(alignedLength - length); cmw.WriteBytes(0, alignmentSize); // fill in alignment size and length: alignmentSizeAndLengthWriter.WriteByte(alignmentSize); alignmentSizeAndLengthWriter.WriteUInt32((uint)alignedLength); return(cmw); }
private void SerializeReferenceToPreviousMethodWithUsingInfo(ArrayBuilder <PooledBlobBuilder> customDebugInfo) { PooledBlobBuilder cmw = PooledBlobBuilder.GetInstance(12); cmw.WriteByte(CustomDebugInfoConstants.Version); cmw.WriteByte((byte)CustomDebugInfoKind.ForwardInfo); cmw.Align(4); cmw.WriteUInt32(12); cmw.WriteUInt32((uint)_previousMethodTokenWithUsingInfo); customDebugInfo.Add(cmw); }
private void SerializeNamespaceScopeMetadata(EmitContext context, IMethodBody methodBody, ArrayBuilder <PooledBlobBuilder> customDebugInfo) { if (context.Module.GenerateVisualBasicStylePdb) { return; } if (ShouldForwardToPreviousMethodWithUsingInfo(context, methodBody)) { Debug.Assert(!ReferenceEquals(_previousMethodBodyWithUsingInfo, methodBody)); SerializeReferenceToPreviousMethodWithUsingInfo(customDebugInfo); return; } List <ushort> usingCounts = new List <ushort>(); PooledBlobBuilder cmw = PooledBlobBuilder.GetInstance(); for (IImportScope scope = methodBody.ImportScope; scope != null; scope = scope.Parent) { usingCounts.Add((ushort)scope.GetUsedNamespaces().Length); } // ACASEY: This originally wrote (uint)12, (ushort)1, (ushort)0 in the // case where usingCounts was empty, but I'm not sure why. if (usingCounts.Count > 0) { uint streamLength; cmw.WriteByte(CustomDebugInfoConstants.Version); cmw.WriteByte((byte)CustomDebugInfoKind.UsingInfo); cmw.Align(4); cmw.WriteUInt32(streamLength = BitArithmeticUtilities.Align((uint)usingCounts.Count * 2 + 10, 4)); cmw.WriteUInt16((ushort)usingCounts.Count); foreach (ushort uc in usingCounts) { cmw.WriteUInt16(uc); } cmw.Align(4); Debug.Assert(streamLength == cmw.Count); customDebugInfo.Add(cmw); } if (_methodBodyWithModuleInfo != null && !ReferenceEquals(_methodBodyWithModuleInfo, methodBody)) { SerializeReferenceToMethodWithModuleInfo(customDebugInfo); } }
private static void SerializeReferenceToIteratorClass(string iteratorClassName, ArrayBuilder <PooledBlobBuilder> customDebugInfo) { if (iteratorClassName == null) { return; } PooledBlobBuilder cmw = PooledBlobBuilder.GetInstance(); cmw.WriteByte(CustomDebugInfoConstants.Version); cmw.WriteByte((byte)CustomDebugInfoKind.ForwardIterator); cmw.Align(4); uint length = 10 + (uint)iteratorClassName.Length * 2; if ((length & 3) != 0) { length += 4 - (length & 3); } cmw.WriteUInt32(length); WriteUtf16String(cmw, iteratorClassName); cmw.Align(4); Debug.Assert(cmw.Count == length); customDebugInfo.Add(cmw); }
private static void SerializeDynamicLocalInfo(IMethodBody methodBody, ArrayBuilder <PooledBlobBuilder> customDebugInfo) { if (!methodBody.HasDynamicLocalVariables) { return; //There are no dynamic locals } const int dynamicAttributeSize = 64; const int identifierSize = 64; ArrayBuilder <ILocalDefinition> dynamicLocals = GetLocalInfoToSerialize( methodBody, local => { System.Collections.Immutable.ImmutableArray <TypedConstant> dynamicTransformFlags = local.DynamicTransformFlags; return(!dynamicTransformFlags.IsEmpty && dynamicTransformFlags.Length <= dynamicAttributeSize && local.Name.Length < identifierSize); }, (scope, local) => local); if (dynamicLocals == null) { return; } const int blobSize = dynamicAttributeSize + 4 + 4 + identifierSize * 2;//DynamicAttribute: 64, DynamicAttributeLength: 4, SlotIndex: 4, IdentifierName: 128 PooledBlobBuilder cmw = PooledBlobBuilder.GetInstance(); cmw.WriteByte(CustomDebugInfoConstants.Version); cmw.WriteByte((byte)CustomDebugInfoKind.DynamicLocals); cmw.Align(4); // size = Version,Kind + size + cBuckets + (dynamicCount * sizeOf(Local Blob)) cmw.WriteUInt32(4 + 4 + 4 + (uint)dynamicLocals.Count * blobSize);//Size of the Dynamic Block cmw.WriteUInt32((uint)dynamicLocals.Count); foreach (ILocalDefinition local in dynamicLocals) { System.Collections.Immutable.ImmutableArray <TypedConstant> dynamicTransformFlags = local.DynamicTransformFlags; byte[] flag = new byte[dynamicAttributeSize]; for (int k = 0; k < dynamicTransformFlags.Length; k++) { if ((bool)dynamicTransformFlags[k].Value) { flag[k] = 1; } } cmw.WriteBytes(flag); //Written Flag cmw.WriteUInt32((uint)dynamicTransformFlags.Length); //Written Length int localIndex = local.SlotIndex; cmw.WriteUInt32((localIndex < 0) ? 0u : (uint)localIndex); char[] localName = new char[identifierSize]; local.Name.CopyTo(0, localName, 0, local.Name.Length); cmw.WriteUTF16(localName); } dynamicLocals.Free(); customDebugInfo.Add(cmw); }