protected override void UpdateLayout(DwarfLayoutContext layoutContext) { ulong sizeOf = 0; // unit_length sizeOf += DwarfHelper.SizeOfUnitLength(Is64BitEncoding); // version sizeOf += 2; // debug_info_offset sizeOf += DwarfHelper.SizeOfUInt(Is64BitEncoding); // Address size sizeOf += 1; // segment selector size sizeOf += 1; var align = (ulong)SegmentSelectorSize + (ulong)AddressSize * 2; // SPECS 7.21: The first tuple following the header in each set begins at an offset that is a multiple of the size of a single tuple sizeOf = AlignHelper.AlignToUpper(sizeOf, align); // SizeOf ranges + 1 (for last 0 entry) sizeOf += ((ulong)Ranges.Count + 1UL) * align; Size = sizeOf; if (Unit != null) { DebugInfoOffset = Unit.Offset; } }
protected override void Write(DwarfWriter writer) { var startOffset = writer.Offset; // unit_length writer.WriteUnitLength(Size - DwarfHelper.SizeOfUnitLength(Is64BitEncoding)); // version writer.WriteU16(Version); // debug_info_offset var debugInfoOffset = DebugInfoOffset; if (writer.EnableRelocation) { writer.RecordRelocation(DwarfRelocationTarget.DebugInfo, writer.SizeOfUIntEncoding(), debugInfoOffset); debugInfoOffset = 0; } writer.WriteUIntFromEncoding(debugInfoOffset); // address_size writer.AddressSize = AddressSize; writer.WriteU8((byte)AddressSize); writer.WriteU8((byte)SegmentSelectorSize); var align = (ulong)SegmentSelectorSize + (ulong)AddressSize * 2; // SPECS 7.21: The first tuple following the header in each set begins at an offset that is a multiple of the size of a single tuple var nextOffset = AlignHelper.AlignToUpper(writer.Offset, align); for (ulong offset = writer.Offset; offset < nextOffset; offset++) { writer.WriteU8(0); } Debug.Assert(writer.Offset == nextOffset); foreach (var range in Ranges) { if (SegmentSelectorSize != 0) { switch (SegmentSelectorSize) { case DwarfAddressSize.Bit8: writer.WriteU8((byte)range.Segment); break; case DwarfAddressSize.Bit16: writer.WriteU16((ushort)range.Segment); break; case DwarfAddressSize.Bit32: writer.WriteU32((uint)range.Segment); break; case DwarfAddressSize.Bit64: writer.WriteU64((ulong)range.Segment); break; } } writer.WriteAddress(DwarfRelocationTarget.Code, range.Address); writer.WriteUInt(range.Length); } if (SegmentSelectorSize != 0) { switch (SegmentSelectorSize) { case DwarfAddressSize.Bit8: writer.WriteU8(0); break; case DwarfAddressSize.Bit16: writer.WriteU16(0); break; case DwarfAddressSize.Bit32: writer.WriteU32(0); break; case DwarfAddressSize.Bit64: writer.WriteU64(0); break; } } switch (AddressSize) { case DwarfAddressSize.Bit8: writer.WriteU16(0); break; case DwarfAddressSize.Bit16: writer.WriteU32(0); break; case DwarfAddressSize.Bit32: writer.WriteU64(0); break; case DwarfAddressSize.Bit64: writer.WriteU64(0); writer.WriteU64(0); break; } Debug.Assert(writer.Offset - startOffset == Size); }