/// <summary> /// Produces a serialized blob of all constant initializers. /// Non-constant initializers are matched with a zero of corresponding size. /// </summary> private ImmutableArray<byte> GetRawData(ImmutableArray<BoundExpression> initializers) { // the initial size is a guess. // there is no point to be precise here as MemoryStream always has N + 1 storage // and will need to be trimmed regardless var writer = new BlobBuilder(initializers.Length * 4); SerializeArrayRecursive(writer, initializers); return writer.ToImmutableArray(); }
public void EditAndContinueLambdaAndClosureMap_NoLambdas() { // should not happen in practice, but EditAndContinueMethodDebugInformation should handle it just fine var slots = ImmutableArray<LocalSlotDebugInfo>.Empty; var closures = ImmutableArray<ClosureDebugInfo>.Empty; var lambdas = ImmutableArray<LambdaDebugInfo>.Empty; var cmw = new BlobBuilder(); new EditAndContinueMethodDebugInformation(10, slots, closures, lambdas).SerializeLambdaMap(cmw); var bytes = cmw.ToImmutableArray(); AssertEx.Equal(new byte[] { 0x0B, 0x01, 0x00 }, bytes); var deserialized = EditAndContinueMethodDebugInformation.Create(default(ImmutableArray<byte>), bytes); AssertEx.Equal(closures, deserialized.Closures); AssertEx.Equal(lambdas, deserialized.Lambdas); }
public void EditAndContinueLambdaAndClosureMap_NoClosures() { var slots = ImmutableArray<LocalSlotDebugInfo>.Empty; var closures = ImmutableArray<ClosureDebugInfo>.Empty; var lambdas = ImmutableArray.Create(new LambdaDebugInfo(20, new DebugId(0, 0), LambdaDebugInfo.StaticClosureOrdinal)); var cmw = new BlobBuilder(); new EditAndContinueMethodDebugInformation(-1, slots, closures, lambdas).SerializeLambdaMap(cmw); var bytes = cmw.ToImmutableArray(); AssertEx.Equal(new byte[] { 0x00, 0x01, 0x00, 0x15, 0x01 }, bytes); var deserialized = EditAndContinueMethodDebugInformation.Create(default(ImmutableArray<byte>), bytes); AssertEx.Equal(closures, deserialized.Closures); AssertEx.Equal(lambdas, deserialized.Lambdas); }
public void EditAndContinueLambdaAndClosureMap_NegativeSyntaxOffsets() { var slots = ImmutableArray<LocalSlotDebugInfo>.Empty; var closures = ImmutableArray.Create( new ClosureDebugInfo(-100, new DebugId(0, 0)), new ClosureDebugInfo(10, new DebugId(1, 0)), new ClosureDebugInfo(-200, new DebugId(2, 0))); var lambdas = ImmutableArray.Create( new LambdaDebugInfo(20, new DebugId(0, 0), 1), new LambdaDebugInfo(-50, new DebugId(1, 0), 0), new LambdaDebugInfo(-180, new DebugId(2, 0), LambdaDebugInfo.StaticClosureOrdinal)); var cmw = new BlobBuilder(); new EditAndContinueMethodDebugInformation(0x7b, slots, closures, lambdas).SerializeLambdaMap(cmw); var bytes = cmw.ToImmutableArray(); AssertEx.Equal(new byte[] { 0x7C, 0x80, 0xC8, 0x03, 0x64, 0x80, 0xD2, 0x00, 0x80, 0xDC, 0x03, 0x80, 0x96, 0x02, 0x14, 0x01 }, bytes); var deserialized = EditAndContinueMethodDebugInformation.Create(default(ImmutableArray<byte>), bytes); AssertEx.Equal(closures, deserialized.Closures); AssertEx.Equal(lambdas, deserialized.Lambdas); }
public void EditAndContinueLocalSlotMap_NegativeSyntaxOffsets() { var slots = ImmutableArray.Create( new LocalSlotDebugInfo(SynthesizedLocalKind.UserDefined, new LocalDebugId(-1, 10)), new LocalSlotDebugInfo(SynthesizedLocalKind.TryAwaitPendingCaughtException, new LocalDebugId(-20000, 10))); var closures = ImmutableArray<ClosureDebugInfo>.Empty; var lambdas = ImmutableArray<LambdaDebugInfo>.Empty; var cmw = new BlobBuilder(); new EditAndContinueMethodDebugInformation(123, slots, closures, lambdas).SerializeLocalSlots(cmw); var bytes = cmw.ToImmutableArray(); AssertEx.Equal(new byte[] { 0xFF, 0xC0, 0x00, 0x4E, 0x20, 0x81, 0xC0, 0x00, 0x4E, 0x1F, 0x0A, 0x9A, 0x00, 0x0A }, bytes); var deserialized = EditAndContinueMethodDebugInformation.Create(bytes, default(ImmutableArray<byte>)).LocalSlots; AssertEx.Equal(slots, deserialized); }
public void EmbeddedPortablePdb() { var b = new DebugDirectoryBuilder(); var pdb = new BlobBuilder(); pdb.WriteInt64(0x1122334455667788); b.AddEmbeddedPortablePdbEntry(pdb, portablePdbVersion: 0x0100); var blob = new BlobBuilder(); b.Serialize(blob, new SectionLocation(0, 0), sectionOffset: 0); var bytes = blob.ToImmutableArray(); AssertEx.Equal(new byte[] { 0x00, 0x00, 0x00, 0x00, // Characteristics 0x00, 0x00, 0x00, 0x00, // Stamp 0x00, 0x01, 0x00, 0x01, // Version 0x11, 0x00, 0x00, 0x00, // Type 0x12, 0x00, 0x00, 0x00, // SizeOfData 0x1C, 0x00, 0x00, 0x00, // AddressOfRawData 0x1C, 0x00, 0x00, 0x00, // PointerToRawData 0x4D, 0x50, 0x44, 0x42, // signature 0x08, 0x00, 0x00, 0x00, // uncompressed size 0xEB, 0x28, 0x4F, 0x0B, 0x75, 0x31, 0x56, 0x12, 0x04, 0x00 // compressed data }, bytes); using (var pinned = new PinnedBlob(bytes)) { var actual = PEReader.ReadDebugDirectoryEntries(pinned.CreateReader(0, DebugDirectoryEntry.Size)); Assert.Equal(1, actual.Length); Assert.Equal(0u, actual[0].Stamp); Assert.Equal(0x0100, actual[0].MajorVersion); Assert.Equal(0x0100, actual[0].MinorVersion); Assert.Equal(DebugDirectoryEntryType.EmbeddedPortablePdb, actual[0].Type); Assert.Equal(0x00000012, actual[0].DataSize); Assert.Equal(0x0000001c, actual[0].DataRelativeVirtualAddress); Assert.Equal(0x0000001c, actual[0].DataPointer); var provider = new ByteArrayMemoryProvider(bytes); using (var block = provider.GetMemoryBlock(actual[0].DataPointer, actual[0].DataSize)) { var decoded = PEReader.DecodeEmbeddedPortablePdbDebugDirectoryData(block); AssertEx.Equal(new byte[] { 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 }, decoded); } } }