| ... | ... | @@ -144,7 +144,9 @@ const DebugInfo = struct { |
| 144 | 144 | debug_info.section.off(dwarf) + unit_ptr.off + unit_ptr.header_len + entry_ptr.off, |
| 145 | 145 | ) != abbrev_code_buf.len) return error.InputOutput; |
| 146 | 146 | var abbrev_code_reader: std.Io.Reader = .fixed(&abbrev_code_buf); |
| 147 | | return @enumFromInt(abbrev_code_reader.takeLeb128(@typeInfo(AbbrevCode).@"enum".tag_type) catch unreachable); |
| 147 | return @enumFromInt( |
| 148 | abbrev_code_reader.takeLeb128(@typeInfo(AbbrevCode).@"enum".tag_type) catch unreachable, |
| 149 | ); |
| 148 | 150 | } |
| 149 | 151 | |
| 150 | 152 | const trailer_bytes = 1 + 1; |
| ... | ... | @@ -369,7 +371,13 @@ pub const Section = struct { |
| 369 | 371 | return &sec.units.items[@intFromEnum(unit)]; |
| 370 | 372 | } |
| 371 | 373 | |
| 372 | | fn resizeEntry(sec: *Section, unit: Unit.Index, entry: Entry.Index, dwarf: *Dwarf, len: u32) UpdateError!void { |
| 374 | fn resizeEntry( |
| 375 | sec: *Section, |
| 376 | unit: Unit.Index, |
| 377 | entry: Entry.Index, |
| 378 | dwarf: *Dwarf, |
| 379 | len: u32, |
| 380 | ) (UpdateError || Writer.Error)!void { |
| 373 | 381 | const unit_ptr = sec.getUnit(unit); |
| 374 | 382 | const entry_ptr = unit_ptr.getEntry(entry); |
| 375 | 383 | if (len > 0) { |
| ... | ... | @@ -390,13 +398,24 @@ pub const Section = struct { |
| 390 | 398 | assert(entry_ptr.len == len); |
| 391 | 399 | } |
| 392 | 400 | |
| 393 | | fn replaceEntry(sec: *Section, unit: Unit.Index, entry: Entry.Index, dwarf: *Dwarf, contents: []const u8) UpdateError!void { |
| 401 | fn replaceEntry( |
| 402 | sec: *Section, |
| 403 | unit: Unit.Index, |
| 404 | entry: Entry.Index, |
| 405 | dwarf: *Dwarf, |
| 406 | contents: []const u8, |
| 407 | ) (UpdateError || Writer.Error)!void { |
| 394 | 408 | try sec.resizeEntry(unit, entry, dwarf, @intCast(contents.len)); |
| 395 | 409 | const unit_ptr = sec.getUnit(unit); |
| 396 | 410 | try unit_ptr.getEntry(entry).replace(unit_ptr, sec, dwarf, contents); |
| 397 | 411 | } |
| 398 | 412 | |
| 399 | | fn freeEntry(sec: *Section, unit: Unit.Index, entry: Entry.Index, dwarf: *Dwarf) UpdateError!void { |
| 413 | fn freeEntry( |
| 414 | sec: *Section, |
| 415 | unit: Unit.Index, |
| 416 | entry: Entry.Index, |
| 417 | dwarf: *Dwarf, |
| 418 | ) (UpdateError || Writer.Error)!void { |
| 400 | 419 | const unit_ptr = sec.getUnit(unit); |
| 401 | 420 | const entry_ptr = unit_ptr.getEntry(entry); |
| 402 | 421 | if (entry_ptr.len > 0) { |
| ... | ... | @@ -649,35 +668,37 @@ const Unit = struct { |
| 649 | 668 | assert(len >= unit.trailer_len); |
| 650 | 669 | if (sec == &dwarf.debug_line.section) { |
| 651 | 670 | var buf: [1 + uleb128Bytes(std.math.maxInt(u32)) + 1]u8 = undefined; |
| 652 | | var fbs = std.io.fixedBufferStream(&buf); |
| 653 | | const writer = fbs.writer(); |
| 654 | | writer.writeByte(DW.LNS.extended_op) catch unreachable; |
| 655 | | const extended_op_bytes = fbs.pos; |
| 671 | var fw: Writer = .fixed(&buf); |
| 672 | fw.writeByte(DW.LNS.extended_op) catch unreachable; |
| 673 | const extended_op_bytes = fw.end; |
| 656 | 674 | var op_len_bytes: u5 = 1; |
| 657 | 675 | while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << 7 * op_len_bytes)) { |
| 658 | | .lt => break uleb128(writer, len - extended_op_bytes - op_len_bytes) catch unreachable, |
| 676 | .lt => break fw.writeUleb128(len - extended_op_bytes - op_len_bytes) catch unreachable, |
| 659 | 677 | .eq => { |
| 660 | 678 | // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte |
| 661 | 679 | op_len_bytes += 1; |
| 662 | | std.leb.writeUnsignedExtended(buf[fbs.pos..][0..op_len_bytes], len - extended_op_bytes - op_len_bytes); |
| 663 | | fbs.pos += op_len_bytes; |
| 680 | std.leb.writeUnsignedExtended( |
| 681 | fw.writableSlice(op_len_bytes) catch unreachable, |
| 682 | len - extended_op_bytes - op_len_bytes, |
| 683 | ); |
| 664 | 684 | break; |
| 665 | 685 | }, |
| 666 | 686 | .gt => op_len_bytes += 1, |
| 667 | 687 | }; |
| 668 | | assert(fbs.pos == extended_op_bytes + op_len_bytes); |
| 669 | | writer.writeByte(DW.LNE.padding) catch unreachable; |
| 670 | | assert(fbs.pos >= unit.trailer_len and fbs.pos <= len); |
| 671 | | return dwarf.getFile().?.pwriteAll(fbs.getWritten(), sec.off(dwarf) + start); |
| 688 | assert(fw.end == extended_op_bytes + op_len_bytes); |
| 689 | fw.writeByte(DW.LNE.padding) catch unreachable; |
| 690 | assert(fw.end >= unit.trailer_len and fw.end <= len); |
| 691 | return dwarf.getFile().?.pwriteAll(fw.buffered(), sec.off(dwarf) + start); |
| 672 | 692 | } |
| 673 | | var trailer = try std.ArrayList(u8).initCapacity(dwarf.gpa, len); |
| 674 | | defer trailer.deinit(); |
| 693 | var trailer_aw: Writer.Allocating = try .initCapacity(dwarf.gpa, len); |
| 694 | defer trailer_aw.deinit(); |
| 695 | const tw = &trailer_aw.writer; |
| 675 | 696 | const fill_byte: u8 = if (sec == &dwarf.debug_abbrev.section) fill: { |
| 697 | tw.writeUleb128(@intFromEnum(AbbrevCode.null)) catch unreachable; |
| 676 | 698 | assert(uleb128Bytes(@intFromEnum(AbbrevCode.null)) == 1); |
| 677 | | trailer.appendAssumeCapacity(@intFromEnum(AbbrevCode.null)); |
| 678 | 699 | break :fill @intFromEnum(AbbrevCode.null); |
| 679 | 700 | } else if (sec == &dwarf.debug_aranges.section) fill: { |
| 680 | | trailer.appendNTimesAssumeCapacity(0, @intFromEnum(dwarf.address_size) * 2); |
| 701 | tw.splatByteAll(0, @intFromEnum(dwarf.address_size) * 2) catch unreachable; |
| 681 | 702 | break :fill 0; |
| 682 | 703 | } else if (sec == &dwarf.debug_frame.section) fill: { |
| 683 | 704 | switch (dwarf.debug_frame.header.format) { |
| ... | ... | @@ -685,49 +706,49 @@ const Unit = struct { |
| 685 | 706 | .debug_frame, .eh_frame => |format| { |
| 686 | 707 | const unit_len = len - dwarf.unitLengthBytes(); |
| 687 | 708 | switch (dwarf.format) { |
| 688 | | .@"32" => std.mem.writeInt(u32, trailer.addManyAsArrayAssumeCapacity(4), @intCast(unit_len), dwarf.endian), |
| 709 | .@"32" => tw.writeInt(u32, @intCast(unit_len), dwarf.endian) catch unreachable, |
| 689 | 710 | .@"64" => { |
| 690 | | std.mem.writeInt(u32, trailer.addManyAsArrayAssumeCapacity(4), std.math.maxInt(u32), dwarf.endian); |
| 691 | | std.mem.writeInt(u64, trailer.addManyAsArrayAssumeCapacity(8), unit_len, dwarf.endian); |
| 711 | tw.writeInt(u32, std.math.maxInt(u32), dwarf.endian) catch unreachable; |
| 712 | tw.writeInt(u64, unit_len, dwarf.endian) catch unreachable; |
| 692 | 713 | }, |
| 693 | 714 | } |
| 694 | 715 | switch (format) { |
| 695 | 716 | .none => unreachable, |
| 696 | 717 | .debug_frame => { |
| 697 | 718 | switch (dwarf.format) { |
| 698 | | .@"32" => std.mem.writeInt(u32, trailer.addManyAsArrayAssumeCapacity(4), std.math.maxInt(u32), dwarf.endian), |
| 699 | | .@"64" => std.mem.writeInt(u64, trailer.addManyAsArrayAssumeCapacity(8), std.math.maxInt(u64), dwarf.endian), |
| 719 | .@"32" => tw.writeInt(u32, std.math.maxInt(u32), dwarf.endian) catch unreachable, |
| 720 | .@"64" => tw.writeInt(u64, std.math.maxInt(u64), dwarf.endian) catch unreachable, |
| 700 | 721 | } |
| 701 | | trailer.appendAssumeCapacity(4); |
| 702 | | trailer.appendSliceAssumeCapacity("\x00"); |
| 703 | | trailer.appendAssumeCapacity(@intFromEnum(dwarf.address_size)); |
| 704 | | trailer.appendAssumeCapacity(0); |
| 722 | tw.writeByte(4) catch unreachable; |
| 723 | tw.writeAll("\x00") catch unreachable; |
| 724 | tw.writeByte(@intFromEnum(dwarf.address_size)) catch unreachable; |
| 725 | tw.writeByte(0) catch unreachable; |
| 705 | 726 | }, |
| 706 | 727 | .eh_frame => { |
| 707 | | std.mem.writeInt(u32, trailer.addManyAsArrayAssumeCapacity(4), 0, dwarf.endian); |
| 708 | | trailer.appendAssumeCapacity(1); |
| 709 | | trailer.appendSliceAssumeCapacity("\x00"); |
| 728 | tw.writeInt(u32, 0, dwarf.endian) catch unreachable; |
| 729 | tw.writeByte(1) catch unreachable; |
| 730 | tw.writeAll("\x00") catch unreachable; |
| 710 | 731 | }, |
| 711 | 732 | } |
| 712 | | uleb128(trailer.fixedWriter(), 1) catch unreachable; |
| 713 | | sleb128(trailer.fixedWriter(), 1) catch unreachable; |
| 714 | | uleb128(trailer.fixedWriter(), 0) catch unreachable; |
| 733 | tw.writeUleb128(1) catch unreachable; |
| 734 | tw.writeSleb128(1) catch unreachable; |
| 735 | tw.writeUleb128(0) catch unreachable; |
| 715 | 736 | }, |
| 716 | 737 | } |
| 717 | | trailer.appendNTimesAssumeCapacity(DW.CFA.nop, unit.trailer_len - trailer.items.len); |
| 738 | tw.splatByteAll(DW.CFA.nop, unit.trailer_len - tw.end) catch unreachable; |
| 718 | 739 | break :fill DW.CFA.nop; |
| 719 | 740 | } else if (sec == &dwarf.debug_info.section) fill: { |
| 741 | for (0..2) |_| tw.writeUleb128(@intFromEnum(AbbrevCode.null)) catch unreachable; |
| 720 | 742 | assert(uleb128Bytes(@intFromEnum(AbbrevCode.null)) == 1); |
| 721 | | trailer.appendNTimesAssumeCapacity(@intFromEnum(AbbrevCode.null), 2); |
| 722 | 743 | break :fill @intFromEnum(AbbrevCode.null); |
| 723 | 744 | } else if (sec == &dwarf.debug_rnglists.section) fill: { |
| 724 | | trailer.appendAssumeCapacity(DW.RLE.end_of_list); |
| 745 | tw.writeByte(DW.RLE.end_of_list) catch unreachable; |
| 725 | 746 | break :fill DW.RLE.end_of_list; |
| 726 | 747 | } else unreachable; |
| 727 | | assert(trailer.items.len == unit.trailer_len); |
| 728 | | trailer.appendNTimesAssumeCapacity(fill_byte, len - unit.trailer_len); |
| 729 | | assert(trailer.items.len == len); |
| 730 | | try dwarf.getFile().?.pwriteAll(trailer.items, sec.off(dwarf) + start); |
| 748 | assert(tw.end == unit.trailer_len); |
| 749 | tw.splatByteAll(fill_byte, len - unit.trailer_len) catch unreachable; |
| 750 | assert(tw.end == len); |
| 751 | try dwarf.getFile().?.pwriteAll(trailer_aw.getWritten(), sec.off(dwarf) + start); |
| 731 | 752 | } |
| 732 | 753 | |
| 733 | 754 | fn resolveRelocs(unit: *Unit, sec: *Section, dwarf: *Dwarf) RelocError!void { |
| ... | ... | @@ -806,7 +827,12 @@ const Entry = struct { |
| 806 | 827 | } |
| 807 | 828 | }; |
| 808 | 829 | |
| 809 | | fn pad(entry: *Entry, unit: *Unit, sec: *Section, dwarf: *Dwarf) UpdateError!void { |
| 830 | fn pad( |
| 831 | entry: *Entry, |
| 832 | unit: *Unit, |
| 833 | sec: *Section, |
| 834 | dwarf: *Dwarf, |
| 835 | ) (UpdateError || Writer.Error)!void { |
| 810 | 836 | assert(entry.len > 0); |
| 811 | 837 | const start = entry.off + entry.len; |
| 812 | 838 | if (sec == &dwarf.debug_frame.section) { |
| ... | ... | @@ -814,12 +840,10 @@ const Entry = struct { |
| 814 | 840 | unit.getEntry(next_entry).off - entry.off |
| 815 | 841 | else |
| 816 | 842 | entry.len; |
| 817 | | var unit_len: [8]u8 = undefined; |
| 818 | | dwarf.writeInt(unit_len[0..dwarf.sectionOffsetBytes()], len - dwarf.unitLengthBytes()); |
| 819 | | try dwarf.getFile().?.pwriteAll( |
| 820 | | unit_len[0..dwarf.sectionOffsetBytes()], |
| 821 | | sec.off(dwarf) + unit.off + unit.header_len + entry.off, |
| 822 | | ); |
| 843 | var unit_len_buf: [8]u8 = undefined; |
| 844 | const unit_len_bytes = unit_len_buf[0..dwarf.sectionOffsetBytes()]; |
| 845 | dwarf.writeInt(unit_len_bytes, len - dwarf.unitLengthBytes()); |
| 846 | try dwarf.getFile().?.pwriteAll(unit_len_bytes, sec.off(dwarf) + unit.off + unit.header_len + entry.off); |
| 823 | 847 | const buf = try dwarf.gpa.alloc(u8, len - entry.len); |
| 824 | 848 | defer dwarf.gpa.free(buf); |
| 825 | 849 | @memset(buf, DW.CFA.nop); |
| ... | ... | @@ -834,55 +858,64 @@ const Entry = struct { |
| 834 | 858 | 1 + uleb128Bytes(std.math.maxInt(u32)) + 1, |
| 835 | 859 | ) |
| 836 | 860 | ]u8 = undefined; |
| 837 | | var fbs = std.io.fixedBufferStream(&buf); |
| 838 | | const writer = fbs.writer(); |
| 861 | var fw: Writer = .fixed(&buf); |
| 839 | 862 | if (sec == &dwarf.debug_info.section) switch (len) { |
| 840 | 863 | 0 => {}, |
| 841 | | 1 => uleb128(writer, try dwarf.refAbbrevCode(.pad_1)) catch unreachable, |
| 864 | 1 => fw.writeUleb128(try dwarf.refAbbrevCode(.pad_1)) catch unreachable, |
| 842 | 865 | else => { |
| 843 | | uleb128(writer, try dwarf.refAbbrevCode(.pad_n)) catch unreachable; |
| 844 | | const abbrev_code_bytes = fbs.pos; |
| 866 | fw.writeUleb128(try dwarf.refAbbrevCode(.pad_n)) catch unreachable; |
| 867 | const abbrev_code_bytes = fw.end; |
| 845 | 868 | var block_len_bytes: u5 = 1; |
| 846 | 869 | while (true) switch (std.math.order(len - abbrev_code_bytes - block_len_bytes, @as(u32, 1) << 7 * block_len_bytes)) { |
| 847 | | .lt => break uleb128(writer, len - abbrev_code_bytes - block_len_bytes) catch unreachable, |
| 870 | .lt => break fw.writeUleb128(len - abbrev_code_bytes - block_len_bytes) catch unreachable, |
| 848 | 871 | .eq => { |
| 849 | 872 | // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte |
| 850 | 873 | block_len_bytes += 1; |
| 851 | | std.leb.writeUnsignedExtended(buf[fbs.pos..][0..block_len_bytes], len - abbrev_code_bytes - block_len_bytes); |
| 852 | | fbs.pos += block_len_bytes; |
| 874 | std.leb.writeUnsignedExtended( |
| 875 | fw.writableSlice(block_len_bytes) catch unreachable, |
| 876 | len - abbrev_code_bytes - block_len_bytes, |
| 877 | ); |
| 853 | 878 | break; |
| 854 | 879 | }, |
| 855 | 880 | .gt => block_len_bytes += 1, |
| 856 | 881 | }; |
| 857 | | assert(fbs.pos == abbrev_code_bytes + block_len_bytes); |
| 882 | assert(fw.end == abbrev_code_bytes + block_len_bytes); |
| 858 | 883 | }, |
| 859 | 884 | } else if (sec == &dwarf.debug_line.section) switch (len) { |
| 860 | 885 | 0 => {}, |
| 861 | | 1 => writer.writeByte(DW.LNS.const_add_pc) catch unreachable, |
| 886 | 1 => fw.writeByte(DW.LNS.const_add_pc) catch unreachable, |
| 862 | 887 | else => { |
| 863 | | writer.writeByte(DW.LNS.extended_op) catch unreachable; |
| 864 | | const extended_op_bytes = fbs.pos; |
| 888 | fw.writeByte(DW.LNS.extended_op) catch unreachable; |
| 889 | const extended_op_bytes = fw.end; |
| 865 | 890 | var op_len_bytes: u5 = 1; |
| 866 | 891 | while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << 7 * op_len_bytes)) { |
| 867 | | .lt => break uleb128(writer, len - extended_op_bytes - op_len_bytes) catch unreachable, |
| 892 | .lt => break fw.writeUleb128(len - extended_op_bytes - op_len_bytes) catch unreachable, |
| 868 | 893 | .eq => { |
| 869 | 894 | // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte |
| 870 | 895 | op_len_bytes += 1; |
| 871 | | std.leb.writeUnsignedExtended(buf[fbs.pos..][0..op_len_bytes], len - extended_op_bytes - op_len_bytes); |
| 872 | | fbs.pos += op_len_bytes; |
| 896 | std.leb.writeUnsignedExtended( |
| 897 | fw.writableSlice(op_len_bytes) catch unreachable, |
| 898 | len - extended_op_bytes - op_len_bytes, |
| 899 | ); |
| 873 | 900 | break; |
| 874 | 901 | }, |
| 875 | 902 | .gt => op_len_bytes += 1, |
| 876 | 903 | }; |
| 877 | | assert(fbs.pos == extended_op_bytes + op_len_bytes); |
| 878 | | if (len > 2) writer.writeByte(DW.LNE.padding) catch unreachable; |
| 904 | assert(fw.end == extended_op_bytes + op_len_bytes); |
| 905 | if (len > 2) fw.writeByte(DW.LNE.padding) catch unreachable; |
| 879 | 906 | }, |
| 880 | 907 | } else assert(!sec.pad_entries_to_ideal and len == 0); |
| 881 | | assert(fbs.pos <= len); |
| 882 | | try dwarf.getFile().?.pwriteAll(fbs.getWritten(), sec.off(dwarf) + unit.off + unit.header_len + start); |
| 908 | assert(fw.end <= len); |
| 909 | try dwarf.getFile().?.pwriteAll(fw.buffered(), sec.off(dwarf) + unit.off + unit.header_len + start); |
| 883 | 910 | } |
| 884 | 911 | |
| 885 | | fn resize(entry_ptr: *Entry, unit: *Unit, sec: *Section, dwarf: *Dwarf, len: u32) UpdateError!void { |
| 912 | fn resize( |
| 913 | entry_ptr: *Entry, |
| 914 | unit: *Unit, |
| 915 | sec: *Section, |
| 916 | dwarf: *Dwarf, |
| 917 | len: u32, |
| 918 | ) (UpdateError || Writer.Error)!void { |
| 886 | 919 | assert(len > 0); |
| 887 | 920 | assert(sec.alignment.check(len)); |
| 888 | 921 | if (entry_ptr.len == len) return; |
| ... | ... | @@ -1134,16 +1167,16 @@ pub const Loc = union(enum) { |
| 1134 | 1167 | }; |
| 1135 | 1168 | } |
| 1136 | 1169 | |
| 1137 | | fn writeReg(reg: u32, op0: u8, opx: u8, writer: anytype) !void { |
| 1170 | fn writeReg(reg: u32, op0: u8, opx: u8, writer: *Writer) Writer.Error!void { |
| 1138 | 1171 | if (std.math.cast(u5, reg)) |small_reg| { |
| 1139 | 1172 | try writer.writeByte(op0 + small_reg); |
| 1140 | 1173 | } else { |
| 1141 | 1174 | try writer.writeByte(opx); |
| 1142 | | try uleb128(writer, reg); |
| 1175 | try writer.writeUleb128(reg); |
| 1143 | 1176 | } |
| 1144 | 1177 | } |
| 1145 | 1178 | |
| 1146 | | fn write(loc: Loc, adapter: anytype) !void { |
| 1179 | fn write(loc: Loc, adapter: anytype) (UpdateError || Writer.Error)!void { |
| 1147 | 1180 | const writer = adapter.writer(); |
| 1148 | 1181 | switch (loc) { |
| 1149 | 1182 | .empty => {}, |
| ... | ... | @@ -1164,13 +1197,13 @@ pub const Loc = union(enum) { |
| 1164 | 1197 | try writer.writeInt(u16, const2u, adapter.endian()); |
| 1165 | 1198 | } else if (std.math.cast(u21, constu)) |const3u| { |
| 1166 | 1199 | try writer.writeByte(DW.OP.constu); |
| 1167 | | try uleb128(writer, const3u); |
| 1200 | try writer.writeUleb128(const3u); |
| 1168 | 1201 | } else if (std.math.cast(u32, constu)) |const4u| { |
| 1169 | 1202 | try writer.writeByte(DW.OP.const4u); |
| 1170 | 1203 | try writer.writeInt(u32, const4u, adapter.endian()); |
| 1171 | 1204 | } else if (std.math.cast(u49, constu)) |const7u| { |
| 1172 | 1205 | try writer.writeByte(DW.OP.constu); |
| 1173 | | try uleb128(writer, const7u); |
| 1206 | try writer.writeUleb128(const7u); |
| 1174 | 1207 | } else { |
| 1175 | 1208 | try writer.writeByte(DW.OP.const8u); |
| 1176 | 1209 | try writer.writeInt(u64, constu, adapter.endian()); |
| ... | ... | @@ -1182,13 +1215,13 @@ pub const Loc = union(enum) { |
| 1182 | 1215 | try writer.writeInt(i16, const2s, adapter.endian()); |
| 1183 | 1216 | } else if (std.math.cast(i21, consts)) |const3s| { |
| 1184 | 1217 | try writer.writeByte(DW.OP.consts); |
| 1185 | | try sleb128(writer, const3s); |
| 1218 | try writer.writeSleb128(const3s); |
| 1186 | 1219 | } else if (std.math.cast(i32, consts)) |const4s| { |
| 1187 | 1220 | try writer.writeByte(DW.OP.const4s); |
| 1188 | 1221 | try writer.writeInt(i32, const4s, adapter.endian()); |
| 1189 | 1222 | } else if (std.math.cast(i49, consts)) |const7s| { |
| 1190 | 1223 | try writer.writeByte(DW.OP.consts); |
| 1191 | | try sleb128(writer, const7s); |
| 1224 | try writer.writeSleb128(const7s); |
| 1192 | 1225 | } else { |
| 1193 | 1226 | try writer.writeByte(DW.OP.const8s); |
| 1194 | 1227 | try writer.writeInt(i64, consts, adapter.endian()); |
| ... | ... | @@ -1205,27 +1238,27 @@ pub const Loc = union(enum) { |
| 1205 | 1238 | if (plus[0].getBaseReg()) |breg| { |
| 1206 | 1239 | if (plus[1].getConst(i65)) |offset| { |
| 1207 | 1240 | try writeReg(breg, DW.OP.breg0, DW.OP.bregx, writer); |
| 1208 | | try sleb128(writer, offset); |
| 1241 | try writer.writeSleb128(offset); |
| 1209 | 1242 | break :done; |
| 1210 | 1243 | } |
| 1211 | 1244 | } |
| 1212 | 1245 | if (plus[1].getBaseReg()) |breg| { |
| 1213 | 1246 | if (plus[0].getConst(i65)) |offset| { |
| 1214 | 1247 | try writeReg(breg, DW.OP.breg0, DW.OP.bregx, writer); |
| 1215 | | try sleb128(writer, offset); |
| 1248 | try writer.writeSleb128(offset); |
| 1216 | 1249 | break :done; |
| 1217 | 1250 | } |
| 1218 | 1251 | } |
| 1219 | 1252 | if (plus[0].getConst(u64)) |uconst| { |
| 1220 | 1253 | try plus[1].write(adapter); |
| 1221 | 1254 | try writer.writeByte(DW.OP.plus_uconst); |
| 1222 | | try uleb128(writer, uconst); |
| 1255 | try writer.writeUleb128(uconst); |
| 1223 | 1256 | break :done; |
| 1224 | 1257 | } |
| 1225 | 1258 | if (plus[1].getConst(u64)) |uconst| { |
| 1226 | 1259 | try plus[0].write(adapter); |
| 1227 | 1260 | try writer.writeByte(DW.OP.plus_uconst); |
| 1228 | | try uleb128(writer, uconst); |
| 1261 | try writer.writeUleb128(uconst); |
| 1229 | 1262 | break :done; |
| 1230 | 1263 | } |
| 1231 | 1264 | try plus[0].write(adapter); |
| ... | ... | @@ -1235,7 +1268,7 @@ pub const Loc = union(enum) { |
| 1235 | 1268 | .reg => |reg| try writeReg(reg, DW.OP.reg0, DW.OP.regx, writer), |
| 1236 | 1269 | .breg => |breg| { |
| 1237 | 1270 | try writeReg(breg, DW.OP.breg0, DW.OP.bregx, writer); |
| 1238 | | try sleb128(writer, 0); |
| 1271 | try writer.writeSleb128(0); |
| 1239 | 1272 | }, |
| 1240 | 1273 | .push_object_address => try writer.writeByte(DW.OP.push_object_address), |
| 1241 | 1274 | .call => |call| { |
| ... | ... | @@ -1249,7 +1282,7 @@ pub const Loc = union(enum) { |
| 1249 | 1282 | }, |
| 1250 | 1283 | .implicit_value => |value| { |
| 1251 | 1284 | try writer.writeByte(DW.OP.implicit_value); |
| 1252 | | try uleb128(writer, value.len); |
| 1285 | try writer.writeUleb128(value.len); |
| 1253 | 1286 | try writer.writeAll(value); |
| 1254 | 1287 | }, |
| 1255 | 1288 | .stack_value => |value| { |
| ... | ... | @@ -1259,25 +1292,25 @@ pub const Loc = union(enum) { |
| 1259 | 1292 | .implicit_pointer => |implicit_pointer| { |
| 1260 | 1293 | try writer.writeByte(DW.OP.implicit_pointer); |
| 1261 | 1294 | try adapter.infoEntry(implicit_pointer.unit, implicit_pointer.entry); |
| 1262 | | try sleb128(writer, implicit_pointer.offset); |
| 1295 | try writer.writeSleb128(implicit_pointer.offset); |
| 1263 | 1296 | }, |
| 1264 | 1297 | .wasm_ext => |wasm_ext| { |
| 1265 | 1298 | try writer.writeByte(DW.OP.WASM_location); |
| 1266 | 1299 | switch (wasm_ext) { |
| 1267 | 1300 | .local => |local| { |
| 1268 | 1301 | try writer.writeByte(DW.OP.WASM_local); |
| 1269 | | try uleb128(writer, local); |
| 1302 | try writer.writeUleb128(local); |
| 1270 | 1303 | }, |
| 1271 | 1304 | .global => |global| if (std.math.cast(u21, global)) |global_u21| { |
| 1272 | 1305 | try writer.writeByte(DW.OP.WASM_global); |
| 1273 | | try uleb128(writer, global_u21); |
| 1306 | try writer.writeUleb128(global_u21); |
| 1274 | 1307 | } else { |
| 1275 | 1308 | try writer.writeByte(DW.OP.WASM_global_u32); |
| 1276 | 1309 | try writer.writeInt(u32, global, adapter.endian()); |
| 1277 | 1310 | }, |
| 1278 | 1311 | .operand_stack => |operand_stack| { |
| 1279 | 1312 | try writer.writeByte(DW.OP.WASM_operand_stack); |
| 1280 | | try uleb128(writer, operand_stack); |
| 1313 | try writer.writeUleb128(operand_stack); |
| 1281 | 1314 | }, |
| 1282 | 1315 | } |
| 1283 | 1316 | }, |
| ... | ... | @@ -1309,22 +1342,22 @@ pub const Cfa = union(enum) { |
| 1309 | 1342 | const RegOff = struct { reg: u32, off: i64 }; |
| 1310 | 1343 | const RegExpr = struct { reg: u32, expr: Loc }; |
| 1311 | 1344 | |
| 1312 | | fn write(cfa: Cfa, wip_nav: *WipNav) UpdateError!void { |
| 1313 | | const writer = wip_nav.debug_frame.writer(wip_nav.dwarf.gpa); |
| 1345 | fn write(cfa: Cfa, wip_nav: *WipNav) (UpdateError || Writer.Error)!void { |
| 1346 | const dfw = &wip_nav.debug_frame.writer; |
| 1314 | 1347 | switch (cfa) { |
| 1315 | | .nop => try writer.writeByte(DW.CFA.nop), |
| 1348 | .nop => try dfw.writeByte(DW.CFA.nop), |
| 1316 | 1349 | .advance_loc => |loc| { |
| 1317 | 1350 | const delta = @divExact(loc - wip_nav.cfi.loc, wip_nav.dwarf.debug_frame.header.code_alignment_factor); |
| 1318 | 1351 | if (delta == 0) {} else if (std.math.cast(u6, delta)) |small_delta| |
| 1319 | | try writer.writeByte(@as(u8, DW.CFA.advance_loc) + small_delta) |
| 1352 | try dfw.writeByte(@as(u8, DW.CFA.advance_loc) + small_delta) |
| 1320 | 1353 | else if (std.math.cast(u8, delta)) |ubyte_delta| |
| 1321 | | try writer.writeAll(&.{ DW.CFA.advance_loc1, ubyte_delta }) |
| 1354 | try dfw.writeAll(&.{ DW.CFA.advance_loc1, ubyte_delta }) |
| 1322 | 1355 | else if (std.math.cast(u16, delta)) |uhalf_delta| { |
| 1323 | | try writer.writeByte(DW.CFA.advance_loc2); |
| 1324 | | try writer.writeInt(u16, uhalf_delta, wip_nav.dwarf.endian); |
| 1356 | try dfw.writeByte(DW.CFA.advance_loc2); |
| 1357 | try dfw.writeInt(u16, uhalf_delta, wip_nav.dwarf.endian); |
| 1325 | 1358 | } else if (std.math.cast(u32, delta)) |uword_delta| { |
| 1326 | | try writer.writeByte(DW.CFA.advance_loc4); |
| 1327 | | try writer.writeInt(u32, uword_delta, wip_nav.dwarf.endian); |
| 1359 | try dfw.writeByte(DW.CFA.advance_loc4); |
| 1360 | try dfw.writeInt(u32, uword_delta, wip_nav.dwarf.endian); |
| 1328 | 1361 | } |
| 1329 | 1362 | wip_nav.cfi.loc = loc; |
| 1330 | 1363 | }, |
| ... | ... | @@ -1336,41 +1369,41 @@ pub const Cfa = union(enum) { |
| 1336 | 1369 | }, wip_nav.dwarf.debug_frame.header.data_alignment_factor); |
| 1337 | 1370 | if (std.math.cast(u63, factored_off)) |unsigned_off| { |
| 1338 | 1371 | if (std.math.cast(u6, reg_off.reg)) |small_reg| { |
| 1339 | | try writer.writeByte(@as(u8, DW.CFA.offset) + small_reg); |
| 1372 | try dfw.writeByte(@as(u8, DW.CFA.offset) + small_reg); |
| 1340 | 1373 | } else { |
| 1341 | | try writer.writeByte(DW.CFA.offset_extended); |
| 1342 | | try uleb128(writer, reg_off.reg); |
| 1374 | try dfw.writeByte(DW.CFA.offset_extended); |
| 1375 | try dfw.writeUleb128(reg_off.reg); |
| 1343 | 1376 | } |
| 1344 | | try uleb128(writer, unsigned_off); |
| 1377 | try dfw.writeUleb128(unsigned_off); |
| 1345 | 1378 | } else { |
| 1346 | | try writer.writeByte(DW.CFA.offset_extended_sf); |
| 1347 | | try uleb128(writer, reg_off.reg); |
| 1348 | | try sleb128(writer, factored_off); |
| 1379 | try dfw.writeByte(DW.CFA.offset_extended_sf); |
| 1380 | try dfw.writeUleb128(reg_off.reg); |
| 1381 | try dfw.writeSleb128(factored_off); |
| 1349 | 1382 | } |
| 1350 | 1383 | }, |
| 1351 | 1384 | .restore => |reg| if (std.math.cast(u6, reg)) |small_reg| |
| 1352 | | try writer.writeByte(@as(u8, DW.CFA.restore) + small_reg) |
| 1385 | try dfw.writeByte(@as(u8, DW.CFA.restore) + small_reg) |
| 1353 | 1386 | else { |
| 1354 | | try writer.writeByte(DW.CFA.restore_extended); |
| 1355 | | try uleb128(writer, reg); |
| 1387 | try dfw.writeByte(DW.CFA.restore_extended); |
| 1388 | try dfw.writeUleb128(reg); |
| 1356 | 1389 | }, |
| 1357 | 1390 | .undefined => |reg| { |
| 1358 | | try writer.writeByte(DW.CFA.undefined); |
| 1359 | | try uleb128(writer, reg); |
| 1391 | try dfw.writeByte(DW.CFA.undefined); |
| 1392 | try dfw.writeUleb128(reg); |
| 1360 | 1393 | }, |
| 1361 | 1394 | .same_value => |reg| { |
| 1362 | | try writer.writeByte(DW.CFA.same_value); |
| 1363 | | try uleb128(writer, reg); |
| 1395 | try dfw.writeByte(DW.CFA.same_value); |
| 1396 | try dfw.writeUleb128(reg); |
| 1364 | 1397 | }, |
| 1365 | 1398 | .register => |regs| if (regs[0] != regs[1]) { |
| 1366 | | try writer.writeByte(DW.CFA.register); |
| 1367 | | for (regs) |reg| try uleb128(writer, reg); |
| 1399 | try dfw.writeByte(DW.CFA.register); |
| 1400 | for (regs) |reg| try dfw.writeUleb128(reg); |
| 1368 | 1401 | } else { |
| 1369 | | try writer.writeByte(DW.CFA.same_value); |
| 1370 | | try uleb128(writer, regs[0]); |
| 1402 | try dfw.writeByte(DW.CFA.same_value); |
| 1403 | try dfw.writeUleb128(regs[0]); |
| 1371 | 1404 | }, |
| 1372 | | .remember_state => try writer.writeByte(DW.CFA.remember_state), |
| 1373 | | .restore_state => try writer.writeByte(DW.CFA.restore_state), |
| 1405 | .remember_state => try dfw.writeByte(DW.CFA.remember_state), |
| 1406 | .restore_state => try dfw.writeByte(DW.CFA.restore_state), |
| 1374 | 1407 | .def_cfa, .def_cfa_register, .def_cfa_offset, .adjust_cfa_offset => { |
| 1375 | 1408 | const reg_off: RegOff = switch (cfa) { |
| 1376 | 1409 | else => unreachable, |
| ... | ... | @@ -1383,51 +1416,51 @@ pub const Cfa = union(enum) { |
| 1383 | 1416 | const unsigned_off = std.math.cast(u63, reg_off.off); |
| 1384 | 1417 | if (reg_off.off == wip_nav.cfi.cfa.off) { |
| 1385 | 1418 | if (changed_reg) { |
| 1386 | | try writer.writeByte(DW.CFA.def_cfa_register); |
| 1387 | | try uleb128(writer, reg_off.reg); |
| 1419 | try dfw.writeByte(DW.CFA.def_cfa_register); |
| 1420 | try dfw.writeUleb128(reg_off.reg); |
| 1388 | 1421 | } |
| 1389 | 1422 | } else if (switch (wip_nav.dwarf.debug_frame.header.data_alignment_factor) { |
| 1390 | 1423 | 0 => unreachable, |
| 1391 | 1424 | 1 => unsigned_off != null, |
| 1392 | 1425 | else => |data_alignment_factor| @rem(reg_off.off, data_alignment_factor) != 0, |
| 1393 | 1426 | }) { |
| 1394 | | try writer.writeByte(if (changed_reg) DW.CFA.def_cfa else DW.CFA.def_cfa_offset); |
| 1395 | | if (changed_reg) try uleb128(writer, reg_off.reg); |
| 1396 | | try uleb128(writer, unsigned_off.?); |
| 1427 | try dfw.writeByte(if (changed_reg) DW.CFA.def_cfa else DW.CFA.def_cfa_offset); |
| 1428 | if (changed_reg) try dfw.writeUleb128(reg_off.reg); |
| 1429 | try dfw.writeUleb128(unsigned_off.?); |
| 1397 | 1430 | } else { |
| 1398 | | try writer.writeByte(if (changed_reg) DW.CFA.def_cfa_sf else DW.CFA.def_cfa_offset_sf); |
| 1399 | | if (changed_reg) try uleb128(writer, reg_off.reg); |
| 1400 | | try sleb128(writer, @divExact(reg_off.off, wip_nav.dwarf.debug_frame.header.data_alignment_factor)); |
| 1431 | try dfw.writeByte(if (changed_reg) DW.CFA.def_cfa_sf else DW.CFA.def_cfa_offset_sf); |
| 1432 | if (changed_reg) try dfw.writeUleb128(reg_off.reg); |
| 1433 | try dfw.writeSleb128(@divExact(reg_off.off, wip_nav.dwarf.debug_frame.header.data_alignment_factor)); |
| 1401 | 1434 | } |
| 1402 | 1435 | wip_nav.cfi.cfa = reg_off; |
| 1403 | 1436 | }, |
| 1404 | 1437 | .def_cfa_expression => |expr| { |
| 1405 | | try writer.writeByte(DW.CFA.def_cfa_expression); |
| 1438 | try dfw.writeByte(DW.CFA.def_cfa_expression); |
| 1406 | 1439 | try wip_nav.frameExprLoc(expr); |
| 1407 | 1440 | }, |
| 1408 | 1441 | .expression => |reg_expr| { |
| 1409 | | try writer.writeByte(DW.CFA.expression); |
| 1410 | | try uleb128(writer, reg_expr.reg); |
| 1442 | try dfw.writeByte(DW.CFA.expression); |
| 1443 | try dfw.writeUleb128(reg_expr.reg); |
| 1411 | 1444 | try wip_nav.frameExprLoc(reg_expr.expr); |
| 1412 | 1445 | }, |
| 1413 | 1446 | .val_offset => |reg_off| { |
| 1414 | 1447 | const factored_off = @divExact(reg_off.off, wip_nav.dwarf.debug_frame.header.data_alignment_factor); |
| 1415 | 1448 | if (std.math.cast(u63, factored_off)) |unsigned_off| { |
| 1416 | | try writer.writeByte(DW.CFA.val_offset); |
| 1417 | | try uleb128(writer, reg_off.reg); |
| 1418 | | try uleb128(writer, unsigned_off); |
| 1449 | try dfw.writeByte(DW.CFA.val_offset); |
| 1450 | try dfw.writeUleb128(reg_off.reg); |
| 1451 | try dfw.writeUleb128(unsigned_off); |
| 1419 | 1452 | } else { |
| 1420 | | try writer.writeByte(DW.CFA.val_offset_sf); |
| 1421 | | try uleb128(writer, reg_off.reg); |
| 1422 | | try sleb128(writer, factored_off); |
| 1453 | try dfw.writeByte(DW.CFA.val_offset_sf); |
| 1454 | try dfw.writeUleb128(reg_off.reg); |
| 1455 | try dfw.writeSleb128(factored_off); |
| 1423 | 1456 | } |
| 1424 | 1457 | }, |
| 1425 | 1458 | .val_expression => |reg_expr| { |
| 1426 | | try writer.writeByte(DW.CFA.val_expression); |
| 1427 | | try uleb128(writer, reg_expr.reg); |
| 1459 | try dfw.writeByte(DW.CFA.val_expression); |
| 1460 | try dfw.writeUleb128(reg_expr.reg); |
| 1428 | 1461 | try wip_nav.frameExprLoc(reg_expr.expr); |
| 1429 | 1462 | }, |
| 1430 | | .escape => |bytes| try writer.writeAll(bytes), |
| 1463 | .escape => |bytes| try dfw.writeAll(bytes), |
| 1431 | 1464 | } |
| 1432 | 1465 | } |
| 1433 | 1466 | }; |
| ... | ... | @@ -1450,24 +1483,30 @@ pub const WipNav = struct { |
| 1450 | 1483 | loc: u32, |
| 1451 | 1484 | cfa: Cfa.RegOff, |
| 1452 | 1485 | }, |
| 1453 | | debug_frame: std.ArrayListUnmanaged(u8), |
| 1454 | | debug_info: std.ArrayListUnmanaged(u8), |
| 1455 | | debug_line: std.ArrayListUnmanaged(u8), |
| 1456 | | debug_loclists: std.ArrayListUnmanaged(u8), |
| 1486 | debug_frame: Writer.Allocating, |
| 1487 | debug_info: Writer.Allocating, |
| 1488 | debug_line: Writer.Allocating, |
| 1489 | debug_loclists: Writer.Allocating, |
| 1457 | 1490 | pending_lazy: PendingLazy, |
| 1458 | 1491 | |
| 1459 | 1492 | pub fn deinit(wip_nav: *WipNav) void { |
| 1460 | 1493 | const gpa = wip_nav.dwarf.gpa; |
| 1461 | 1494 | if (wip_nav.func != .none) wip_nav.blocks.deinit(gpa); |
| 1462 | | wip_nav.debug_frame.deinit(gpa); |
| 1463 | | wip_nav.debug_info.deinit(gpa); |
| 1464 | | wip_nav.debug_line.deinit(gpa); |
| 1465 | | wip_nav.debug_loclists.deinit(gpa); |
| 1495 | wip_nav.debug_frame.deinit(); |
| 1496 | wip_nav.debug_info.deinit(); |
| 1497 | wip_nav.debug_line.deinit(); |
| 1498 | wip_nav.debug_loclists.deinit(); |
| 1466 | 1499 | wip_nav.pending_lazy.types.deinit(gpa); |
| 1467 | 1500 | wip_nav.pending_lazy.values.deinit(gpa); |
| 1468 | 1501 | } |
| 1469 | 1502 | |
| 1470 | 1503 | pub fn genDebugFrame(wip_nav: *WipNav, loc: u32, cfa: Cfa) UpdateError!void { |
| 1504 | return wip_nav.genDebugFrameWriterError(loc, cfa) catch |err| switch (err) { |
| 1505 | error.WriteFailed => error.OutOfMemory, |
| 1506 | else => |e| e, |
| 1507 | }; |
| 1508 | } |
| 1509 | fn genDebugFrameWriterError(wip_nav: *WipNav, loc: u32, cfa: Cfa) (UpdateError || Writer.Error)!void { |
| 1471 | 1510 | assert(wip_nav.func != .none); |
| 1472 | 1511 | if (wip_nav.dwarf.debug_frame.header.format == .none) return; |
| 1473 | 1512 | const loc_cfa: Cfa = .{ .advance_loc = loc }; |
| ... | ... | @@ -1483,6 +1522,18 @@ pub const WipNav = struct { |
| 1483 | 1522 | ty: Type, |
| 1484 | 1523 | loc: Loc, |
| 1485 | 1524 | ) UpdateError!void { |
| 1525 | return wip_nav.genLocalVarDebugInfoWriterError(tag, opt_name, ty, loc) catch |err| switch (err) { |
| 1526 | error.WriteFailed => error.OutOfMemory, |
| 1527 | else => |e| e, |
| 1528 | }; |
| 1529 | } |
| 1530 | fn genLocalVarDebugInfoWriterError( |
| 1531 | wip_nav: *WipNav, |
| 1532 | tag: LocalVarTag, |
| 1533 | opt_name: ?[]const u8, |
| 1534 | ty: Type, |
| 1535 | loc: Loc, |
| 1536 | ) (UpdateError || Writer.Error)!void { |
| 1486 | 1537 | assert(wip_nav.func != .none); |
| 1487 | 1538 | try wip_nav.abbrevCode(switch (tag) { |
| 1488 | 1539 | .arg => if (opt_name) |_| .arg else .unnamed_arg, |
| ... | ... | @@ -1502,6 +1553,18 @@ pub const WipNav = struct { |
| 1502 | 1553 | opt_name: ?[]const u8, |
| 1503 | 1554 | val: Value, |
| 1504 | 1555 | ) UpdateError!void { |
| 1556 | return wip_nav.genLocalConstDebugInfoWriterError(src_loc, tag, opt_name, val) catch |err| switch (err) { |
| 1557 | error.WriteFailed => error.OutOfMemory, |
| 1558 | else => |e| e, |
| 1559 | }; |
| 1560 | } |
| 1561 | fn genLocalConstDebugInfoWriterError( |
| 1562 | wip_nav: *WipNav, |
| 1563 | src_loc: Zcu.LazySrcLoc, |
| 1564 | tag: LocalConstTag, |
| 1565 | opt_name: ?[]const u8, |
| 1566 | val: Value, |
| 1567 | ) (UpdateError || Writer.Error)!void { |
| 1505 | 1568 | assert(wip_nav.func != .none); |
| 1506 | 1569 | const pt = wip_nav.pt; |
| 1507 | 1570 | const zcu = pt.zcu; |
| ... | ... | @@ -1529,17 +1592,28 @@ pub const WipNav = struct { |
| 1529 | 1592 | } |
| 1530 | 1593 | |
| 1531 | 1594 | pub fn genVarArgsDebugInfo(wip_nav: *WipNav) UpdateError!void { |
| 1595 | return wip_nav.genVarArgsDebugInfoWriterError() catch |err| switch (err) { |
| 1596 | error.WriteFailed => error.OutOfMemory, |
| 1597 | else => |e| e, |
| 1598 | }; |
| 1599 | } |
| 1600 | fn genVarArgsDebugInfoWriterError(wip_nav: *WipNav) (UpdateError || Writer.Error)!void { |
| 1532 | 1601 | assert(wip_nav.func != .none); |
| 1533 | 1602 | try wip_nav.abbrevCode(.is_var_args); |
| 1534 | 1603 | wip_nav.any_children = true; |
| 1535 | 1604 | } |
| 1536 | 1605 | |
| 1537 | | pub fn advancePCAndLine( |
| 1606 | pub fn advancePCAndLine(wip_nav: *WipNav, delta_line: i33, delta_pc: u64) Allocator.Error!void { |
| 1607 | return wip_nav.advancePCAndLineWriterError(delta_line, delta_pc) catch |err| switch (err) { |
| 1608 | error.WriteFailed => error.OutOfMemory, |
| 1609 | }; |
| 1610 | } |
| 1611 | fn advancePCAndLineWriterError( |
| 1538 | 1612 | wip_nav: *WipNav, |
| 1539 | 1613 | delta_line: i33, |
| 1540 | 1614 | delta_pc: u64, |
| 1541 | | ) error{OutOfMemory}!void { |
| 1542 | | const dlw = wip_nav.debug_line.writer(wip_nav.dwarf.gpa); |
| 1615 | ) Writer.Error!void { |
| 1616 | const dlw = &wip_nav.debug_line.writer; |
| 1543 | 1617 | |
| 1544 | 1618 | const header = wip_nav.dwarf.debug_line.header; |
| 1545 | 1619 | assert(header.maximum_operations_per_instruction == 1); |
| ... | ... | @@ -1550,7 +1624,7 @@ pub const WipNav = struct { |
| 1550 | 1624 | remaining: { |
| 1551 | 1625 | assert(delta_line != 0); |
| 1552 | 1626 | try dlw.writeByte(DW.LNS.advance_line); |
| 1553 | | try sleb128(dlw, delta_line); |
| 1627 | try dlw.writeSleb128(delta_line); |
| 1554 | 1628 | break :remaining 0; |
| 1555 | 1629 | } else delta_line); |
| 1556 | 1630 | |
| ... | ... | @@ -1559,7 +1633,7 @@ pub const WipNav = struct { |
| 1559 | 1633 | const max_op_advance: u9 = (std.math.maxInt(u8) - header.opcode_base) / header.line_range; |
| 1560 | 1634 | const remaining_op_advance: u8 = @intCast(if (op_advance >= 2 * max_op_advance) remaining: { |
| 1561 | 1635 | try dlw.writeByte(DW.LNS.advance_pc); |
| 1562 | | try uleb128(dlw, op_advance); |
| 1636 | try dlw.writeUleb128(op_advance); |
| 1563 | 1637 | break :remaining 0; |
| 1564 | 1638 | } else if (op_advance >= max_op_advance) remaining: { |
| 1565 | 1639 | try dlw.writeByte(DW.LNS.const_add_pc); |
| ... | ... | @@ -1573,53 +1647,82 @@ pub const WipNav = struct { |
| 1573 | 1647 | (header.line_range * remaining_op_advance) + header.opcode_base)); |
| 1574 | 1648 | } |
| 1575 | 1649 | |
| 1576 | | pub fn setColumn(wip_nav: *WipNav, column: u32) error{OutOfMemory}!void { |
| 1577 | | const dlw = wip_nav.debug_line.writer(wip_nav.dwarf.gpa); |
| 1650 | pub fn setColumn(wip_nav: *WipNav, column: u32) Allocator.Error!void { |
| 1651 | return wip_nav.setColumnWriterError(column) catch |err| switch (err) { |
| 1652 | error.WriteFailed => error.OutOfMemory, |
| 1653 | }; |
| 1654 | } |
| 1655 | fn setColumnWriterError(wip_nav: *WipNav, column: u32) Writer.Error!void { |
| 1656 | const dlw = &wip_nav.debug_line.writer; |
| 1578 | 1657 | try dlw.writeByte(DW.LNS.set_column); |
| 1579 | | try uleb128(dlw, column + 1); |
| 1658 | try dlw.writeUleb128(column + 1); |
| 1580 | 1659 | } |
| 1581 | 1660 | |
| 1582 | | pub fn negateStmt(wip_nav: *WipNav) error{OutOfMemory}!void { |
| 1583 | | const dlw = wip_nav.debug_line.writer(wip_nav.dwarf.gpa); |
| 1584 | | try dlw.writeByte(DW.LNS.negate_stmt); |
| 1661 | pub fn negateStmt(wip_nav: *WipNav) Allocator.Error!void { |
| 1662 | return wip_nav.negateStmtWriterError() catch |err| switch (err) { |
| 1663 | error.WriteFailed => error.OutOfMemory, |
| 1664 | }; |
| 1665 | } |
| 1666 | fn negateStmtWriterError(wip_nav: *WipNav) Writer.Error!void { |
| 1667 | try wip_nav.debug_line.writer.writeByte(DW.LNS.negate_stmt); |
| 1585 | 1668 | } |
| 1586 | 1669 | |
| 1587 | | pub fn setPrologueEnd(wip_nav: *WipNav) error{OutOfMemory}!void { |
| 1588 | | const dlw = wip_nav.debug_line.writer(wip_nav.dwarf.gpa); |
| 1589 | | try dlw.writeByte(DW.LNS.set_prologue_end); |
| 1670 | pub fn setPrologueEnd(wip_nav: *WipNav) Allocator.Error!void { |
| 1671 | return wip_nav.setPrologueEndWriterError() catch |err| switch (err) { |
| 1672 | error.WriteFailed => error.OutOfMemory, |
| 1673 | }; |
| 1674 | } |
| 1675 | fn setPrologueEndWriterError(wip_nav: *WipNav) Writer.Error!void { |
| 1676 | try wip_nav.debug_line.writer.writeByte(DW.LNS.set_prologue_end); |
| 1590 | 1677 | } |
| 1591 | 1678 | |
| 1592 | | pub fn setEpilogueBegin(wip_nav: *WipNav) error{OutOfMemory}!void { |
| 1593 | | const dlw = wip_nav.debug_line.writer(wip_nav.dwarf.gpa); |
| 1594 | | try dlw.writeByte(DW.LNS.set_epilogue_begin); |
| 1679 | pub fn setEpilogueBegin(wip_nav: *WipNav) Allocator.Error!void { |
| 1680 | return wip_nav.setEpilogueBeginWriterError() catch |err| switch (err) { |
| 1681 | error.WriteFailed => error.OutOfMemory, |
| 1682 | }; |
| 1683 | } |
| 1684 | fn setEpilogueBeginWriterError(wip_nav: *WipNav) Writer.Error!void { |
| 1685 | try wip_nav.debug_line.writer.writeByte(DW.LNS.set_epilogue_begin); |
| 1595 | 1686 | } |
| 1596 | 1687 | |
| 1597 | 1688 | pub fn enterBlock(wip_nav: *WipNav, code_off: u64) UpdateError!void { |
| 1689 | return wip_nav.enterBlockWriterError(code_off) catch |err| switch (err) { |
| 1690 | error.WriteFailed => error.OutOfMemory, |
| 1691 | else => |e| e, |
| 1692 | }; |
| 1693 | } |
| 1694 | fn enterBlockWriterError(wip_nav: *WipNav, code_off: u64) (UpdateError || Writer.Error)!void { |
| 1598 | 1695 | const dwarf = wip_nav.dwarf; |
| 1599 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 1696 | const diw = &wip_nav.debug_info.writer; |
| 1600 | 1697 | const block = try wip_nav.blocks.addOne(dwarf.gpa); |
| 1601 | 1698 | |
| 1602 | | block.abbrev_code = @intCast(wip_nav.debug_info.items.len); |
| 1699 | block.abbrev_code = @intCast(diw.end); |
| 1603 | 1700 | try wip_nav.abbrevCode(.block); |
| 1604 | 1701 | block.low_pc_off = code_off; |
| 1605 | 1702 | try wip_nav.infoAddrSym(wip_nav.func_sym_index, code_off); |
| 1606 | | block.high_pc = @intCast(wip_nav.debug_info.items.len); |
| 1703 | block.high_pc = @intCast(diw.end); |
| 1607 | 1704 | try diw.writeInt(u32, 0, dwarf.endian); |
| 1608 | 1705 | wip_nav.any_children = false; |
| 1609 | 1706 | } |
| 1610 | 1707 | |
| 1611 | 1708 | pub fn leaveBlock(wip_nav: *WipNav, code_off: u64) UpdateError!void { |
| 1709 | return wip_nav.leaveBlockWriterError(code_off) catch |err| switch (err) { |
| 1710 | error.WriteFailed => error.OutOfMemory, |
| 1711 | else => |e| e, |
| 1712 | }; |
| 1713 | } |
| 1714 | fn leaveBlockWriterError(wip_nav: *WipNav, code_off: u64) (UpdateError || Writer.Error)!void { |
| 1612 | 1715 | const block_bytes = comptime uleb128Bytes(@intFromEnum(AbbrevCode.block)); |
| 1613 | 1716 | const block = wip_nav.blocks.pop().?; |
| 1614 | 1717 | if (wip_nav.any_children) |
| 1615 | | try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), @intFromEnum(AbbrevCode.null)) |
| 1718 | try wip_nav.debug_info.writer.writeUleb128(@intFromEnum(AbbrevCode.null)) |
| 1616 | 1719 | else |
| 1617 | 1720 | std.leb.writeUnsignedFixed( |
| 1618 | 1721 | block_bytes, |
| 1619 | | wip_nav.debug_info.items[block.abbrev_code..][0..block_bytes], |
| 1722 | wip_nav.debug_info.getWritten()[block.abbrev_code..][0..block_bytes], |
| 1620 | 1723 | try wip_nav.dwarf.refAbbrevCode(.empty_block), |
| 1621 | 1724 | ); |
| 1622 | | std.mem.writeInt(u32, wip_nav.debug_info.items[block.high_pc..][0..4], @intCast(code_off - block.low_pc_off), wip_nav.dwarf.endian); |
| 1725 | std.mem.writeInt(u32, wip_nav.debug_info.getWritten()[block.high_pc..][0..4], @intCast(code_off - block.low_pc_off), wip_nav.dwarf.endian); |
| 1623 | 1726 | wip_nav.any_children = true; |
| 1624 | 1727 | } |
| 1625 | 1728 | |
| ... | ... | @@ -1630,41 +1733,69 @@ pub const WipNav = struct { |
| 1630 | 1733 | line: u32, |
| 1631 | 1734 | column: u32, |
| 1632 | 1735 | ) UpdateError!void { |
| 1736 | return wip_nav.enterInlineFuncWriterError(func, code_off, line, column) catch |err| switch (err) { |
| 1737 | error.WriteFailed => error.OutOfMemory, |
| 1738 | else => |e| e, |
| 1739 | }; |
| 1740 | } |
| 1741 | fn enterInlineFuncWriterError( |
| 1742 | wip_nav: *WipNav, |
| 1743 | func: InternPool.Index, |
| 1744 | code_off: u64, |
| 1745 | line: u32, |
| 1746 | column: u32, |
| 1747 | ) (UpdateError || Writer.Error)!void { |
| 1633 | 1748 | const dwarf = wip_nav.dwarf; |
| 1634 | 1749 | const zcu = wip_nav.pt.zcu; |
| 1635 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 1750 | const diw = &wip_nav.debug_info.writer; |
| 1636 | 1751 | const block = try wip_nav.blocks.addOne(dwarf.gpa); |
| 1637 | 1752 | |
| 1638 | | block.abbrev_code = @intCast(wip_nav.debug_info.items.len); |
| 1753 | block.abbrev_code = @intCast(diw.end); |
| 1639 | 1754 | try wip_nav.abbrevCode(.inlined_func); |
| 1640 | 1755 | try wip_nav.refNav(zcu.funcInfo(func).owner_nav); |
| 1641 | | try uleb128(diw, zcu.navSrcLine(zcu.funcInfo(wip_nav.func).owner_nav) + line + 1); |
| 1642 | | try uleb128(diw, column + 1); |
| 1756 | try diw.writeUleb128(zcu.navSrcLine(zcu.funcInfo(wip_nav.func).owner_nav) + line + 1); |
| 1757 | try diw.writeUleb128(column + 1); |
| 1643 | 1758 | block.low_pc_off = code_off; |
| 1644 | 1759 | try wip_nav.infoAddrSym(wip_nav.func_sym_index, code_off); |
| 1645 | | block.high_pc = @intCast(wip_nav.debug_info.items.len); |
| 1760 | block.high_pc = @intCast(diw.end); |
| 1646 | 1761 | try diw.writeInt(u32, 0, dwarf.endian); |
| 1647 | 1762 | try wip_nav.setInlineFunc(func); |
| 1648 | 1763 | wip_nav.any_children = false; |
| 1649 | 1764 | } |
| 1650 | 1765 | |
| 1651 | 1766 | pub fn leaveInlineFunc(wip_nav: *WipNav, func: InternPool.Index, code_off: u64) UpdateError!void { |
| 1767 | return wip_nav.leaveInlineFuncWriterError(func, code_off) catch |err| switch (err) { |
| 1768 | error.WriteFailed => error.OutOfMemory, |
| 1769 | else => |e| e, |
| 1770 | }; |
| 1771 | } |
| 1772 | fn leaveInlineFuncWriterError( |
| 1773 | wip_nav: *WipNav, |
| 1774 | func: InternPool.Index, |
| 1775 | code_off: u64, |
| 1776 | ) (UpdateError || Writer.Error)!void { |
| 1652 | 1777 | const inlined_func_bytes = comptime uleb128Bytes(@intFromEnum(AbbrevCode.inlined_func)); |
| 1653 | 1778 | const block = wip_nav.blocks.pop().?; |
| 1654 | 1779 | if (wip_nav.any_children) |
| 1655 | | try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), @intFromEnum(AbbrevCode.null)) |
| 1780 | try wip_nav.debug_info.writer.writeUleb128(@intFromEnum(AbbrevCode.null)) |
| 1656 | 1781 | else |
| 1657 | 1782 | std.leb.writeUnsignedFixed( |
| 1658 | 1783 | inlined_func_bytes, |
| 1659 | | wip_nav.debug_info.items[block.abbrev_code..][0..inlined_func_bytes], |
| 1784 | wip_nav.debug_info.getWritten()[block.abbrev_code..][0..inlined_func_bytes], |
| 1660 | 1785 | try wip_nav.dwarf.refAbbrevCode(.empty_inlined_func), |
| 1661 | 1786 | ); |
| 1662 | | std.mem.writeInt(u32, wip_nav.debug_info.items[block.high_pc..][0..4], @intCast(code_off - block.low_pc_off), wip_nav.dwarf.endian); |
| 1787 | std.mem.writeInt(u32, wip_nav.debug_info.getWritten()[block.high_pc..][0..4], @intCast(code_off - block.low_pc_off), wip_nav.dwarf.endian); |
| 1663 | 1788 | try wip_nav.setInlineFunc(func); |
| 1664 | 1789 | wip_nav.any_children = true; |
| 1665 | 1790 | } |
| 1666 | 1791 | |
| 1667 | 1792 | pub fn setInlineFunc(wip_nav: *WipNav, func: InternPool.Index) UpdateError!void { |
| 1793 | return wip_nav.setInlineFuncWriterError(func) catch |err| switch (err) { |
| 1794 | error.WriteFailed => error.OutOfMemory, |
| 1795 | else => |e| e, |
| 1796 | }; |
| 1797 | } |
| 1798 | fn setInlineFuncWriterError(wip_nav: *WipNav, func: InternPool.Index) (UpdateError || Writer.Error)!void { |
| 1668 | 1799 | const zcu = wip_nav.pt.zcu; |
| 1669 | 1800 | const dwarf = wip_nav.dwarf; |
| 1670 | 1801 | if (wip_nav.func == func) return; |
| ... | ... | @@ -1673,22 +1804,22 @@ pub const WipNav = struct { |
| 1673 | 1804 | const new_file = zcu.navFileScopeIndex(new_func_info.owner_nav); |
| 1674 | 1805 | const new_unit = try dwarf.getUnit(zcu.fileByIndex(new_file).mod.?); |
| 1675 | 1806 | |
| 1676 | | const dlw = wip_nav.debug_line.writer(dwarf.gpa); |
| 1807 | const dlw = &wip_nav.debug_line.writer; |
| 1677 | 1808 | if (dwarf.incremental()) { |
| 1678 | 1809 | const new_nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, new_func_info.owner_nav); |
| 1679 | 1810 | errdefer _ = if (!new_nav_gop.found_existing) dwarf.navs.pop(); |
| 1680 | 1811 | if (!new_nav_gop.found_existing) new_nav_gop.value_ptr.* = try dwarf.addCommonEntry(new_unit); |
| 1681 | 1812 | |
| 1682 | 1813 | try dlw.writeByte(DW.LNS.extended_op); |
| 1683 | | try uleb128(dlw, 1 + dwarf.sectionOffsetBytes()); |
| 1814 | try dlw.writeUleb128(1 + dwarf.sectionOffsetBytes()); |
| 1684 | 1815 | try dlw.writeByte(DW.LNE.ZIG_set_decl); |
| 1685 | 1816 | try dwarf.debug_line.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).cross_section_relocs.append(dwarf.gpa, .{ |
| 1686 | | .source_off = @intCast(wip_nav.debug_line.items.len), |
| 1817 | .source_off = @intCast(dlw.end), |
| 1687 | 1818 | .target_sec = .debug_info, |
| 1688 | 1819 | .target_unit = new_unit, |
| 1689 | 1820 | .target_entry = new_nav_gop.value_ptr.toOptional(), |
| 1690 | 1821 | }); |
| 1691 | | try dlw.writeByteNTimes(0, dwarf.sectionOffsetBytes()); |
| 1822 | try dlw.splatByteAll(0, dwarf.sectionOffsetBytes()); |
| 1692 | 1823 | return; |
| 1693 | 1824 | } |
| 1694 | 1825 | |
| ... | ... | @@ -1700,14 +1831,14 @@ pub const WipNav = struct { |
| 1700 | 1831 | const file_gop = try mod_info.files.getOrPut(dwarf.gpa, new_file); |
| 1701 | 1832 | |
| 1702 | 1833 | try dlw.writeByte(DW.LNS.set_file); |
| 1703 | | try uleb128(dlw, file_gop.index); |
| 1834 | try dlw.writeUleb128(file_gop.index); |
| 1704 | 1835 | } |
| 1705 | 1836 | |
| 1706 | 1837 | const old_src_line: i33 = zcu.navSrcLine(old_func_info.owner_nav); |
| 1707 | 1838 | const new_src_line: i33 = zcu.navSrcLine(new_func_info.owner_nav); |
| 1708 | 1839 | if (new_src_line != old_src_line) { |
| 1709 | 1840 | try dlw.writeByte(DW.LNS.advance_line); |
| 1710 | | try sleb128(dlw, new_src_line - old_src_line); |
| 1841 | try dlw.writeSleb128(new_src_line - old_src_line); |
| 1711 | 1842 | } |
| 1712 | 1843 | |
| 1713 | 1844 | wip_nav.func = func; |
| ... | ... | @@ -1725,16 +1856,23 @@ pub const WipNav = struct { |
| 1725 | 1856 | try wip_nav.externalReloc(&wip_nav.dwarf.debug_frame.section, reloc); |
| 1726 | 1857 | } |
| 1727 | 1858 | |
| 1728 | | fn abbrevCode(wip_nav: *WipNav, abbrev_code: AbbrevCode) UpdateError!void { |
| 1729 | | try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), try wip_nav.dwarf.refAbbrevCode(abbrev_code)); |
| 1859 | fn abbrevCode(wip_nav: *WipNav, abbrev_code: AbbrevCode) (UpdateError || Writer.Error)!void { |
| 1860 | try wip_nav.debug_info.writer.writeUleb128(try wip_nav.dwarf.refAbbrevCode(abbrev_code)); |
| 1730 | 1861 | } |
| 1731 | 1862 | |
| 1732 | | fn sectionOffset(wip_nav: *WipNav, comptime sec: Section.Index, target_sec: Section.Index, target_unit: Unit.Index, target_entry: Entry.Index, target_off: u32) UpdateError!void { |
| 1863 | fn sectionOffset( |
| 1864 | wip_nav: *WipNav, |
| 1865 | comptime sec: Section.Index, |
| 1866 | target_sec: Section.Index, |
| 1867 | target_unit: Unit.Index, |
| 1868 | target_entry: Entry.Index, |
| 1869 | target_off: u32, |
| 1870 | ) (UpdateError || Writer.Error)!void { |
| 1733 | 1871 | const dwarf = wip_nav.dwarf; |
| 1734 | 1872 | const gpa = dwarf.gpa; |
| 1735 | 1873 | const entry_ptr = @field(dwarf, @tagName(sec)).section.getUnit(wip_nav.unit).getEntry(wip_nav.entry); |
| 1736 | | const bytes = &@field(wip_nav, @tagName(sec)); |
| 1737 | | const source_off: u32 = @intCast(bytes.items.len); |
| 1874 | const sw = &@field(wip_nav, @tagName(sec)).writer; |
| 1875 | const source_off: u32 = @intCast(sw.end); |
| 1738 | 1876 | if (target_sec != sec) { |
| 1739 | 1877 | try entry_ptr.cross_section_relocs.append(gpa, .{ |
| 1740 | 1878 | .source_off = source_off, |
| ... | ... | @@ -1757,109 +1895,136 @@ pub const WipNav = struct { |
| 1757 | 1895 | .target_off = target_off, |
| 1758 | 1896 | }); |
| 1759 | 1897 | } |
| 1760 | | try bytes.appendNTimes(gpa, 0, dwarf.sectionOffsetBytes()); |
| 1898 | try sw.splatByteAll(0, dwarf.sectionOffsetBytes()); |
| 1761 | 1899 | } |
| 1762 | 1900 | |
| 1763 | | fn infoSectionOffset(wip_nav: *WipNav, target_sec: Section.Index, target_unit: Unit.Index, target_entry: Entry.Index, target_off: u32) UpdateError!void { |
| 1901 | fn infoSectionOffset( |
| 1902 | wip_nav: *WipNav, |
| 1903 | target_sec: Section.Index, |
| 1904 | target_unit: Unit.Index, |
| 1905 | target_entry: Entry.Index, |
| 1906 | target_off: u32, |
| 1907 | ) (UpdateError || Writer.Error)!void { |
| 1764 | 1908 | try wip_nav.sectionOffset(.debug_info, target_sec, target_unit, target_entry, target_off); |
| 1765 | 1909 | } |
| 1766 | 1910 | |
| 1767 | | fn strp(wip_nav: *WipNav, str: []const u8) UpdateError!void { |
| 1911 | fn strp(wip_nav: *WipNav, str: []const u8) (UpdateError || Writer.Error)!void { |
| 1768 | 1912 | try wip_nav.infoSectionOffset(.debug_str, StringSection.unit, try wip_nav.dwarf.debug_str.addString(wip_nav.dwarf, str), 0); |
| 1769 | 1913 | } |
| 1770 | 1914 | |
| 1771 | 1915 | const ExprLocCounter = struct { |
| 1772 | | stream: Writer.Discarding, |
| 1916 | dw: Writer.Discarding, |
| 1773 | 1917 | section_offset_bytes: u32, |
| 1774 | 1918 | address_size: AddressSize, |
| 1775 | | fn init(dwarf: *Dwarf, trash_buffer: []u8) ExprLocCounter { |
| 1919 | fn init(dwarf: *Dwarf, buf: []u8) ExprLocCounter { |
| 1776 | 1920 | return .{ |
| 1777 | | .stream = .init(trash_buffer), |
| 1921 | .dw = .init(buf), |
| 1778 | 1922 | .section_offset_bytes = dwarf.sectionOffsetBytes(), |
| 1779 | 1923 | .address_size = dwarf.address_size, |
| 1780 | 1924 | }; |
| 1781 | 1925 | } |
| 1782 | 1926 | fn writer(counter: *ExprLocCounter) *Writer { |
| 1783 | | return &counter.stream.writer; |
| 1927 | return &counter.dw.writer; |
| 1784 | 1928 | } |
| 1785 | 1929 | fn endian(_: ExprLocCounter) std.builtin.Endian { |
| 1786 | 1930 | return @import("builtin").cpu.arch.endian(); |
| 1787 | 1931 | } |
| 1788 | | fn addrSym(counter: *ExprLocCounter, _: u32) error{}!void { |
| 1789 | | counter.stream.count += @intFromEnum(counter.address_size); |
| 1932 | fn addrSym(counter: *ExprLocCounter, _: u32) Writer.Error!void { |
| 1933 | try counter.dw.writer.splatByteAll(undefined, @intFromEnum(counter.address_size)); |
| 1790 | 1934 | } |
| 1791 | | fn infoEntry(counter: *ExprLocCounter, _: Unit.Index, _: Entry.Index) error{}!void { |
| 1792 | | counter.stream.count += counter.section_offset_bytes; |
| 1935 | fn infoEntry(counter: *ExprLocCounter, _: Unit.Index, _: Entry.Index) Writer.Error!void { |
| 1936 | try counter.dw.writer.splatByteAll(undefined, counter.section_offset_bytes); |
| 1793 | 1937 | } |
| 1794 | 1938 | }; |
| 1795 | 1939 | |
| 1796 | | fn infoExprLoc(wip_nav: *WipNav, loc: Loc) UpdateError!void { |
| 1797 | | var trash_buffer: [64]u8 = undefined; |
| 1798 | | var counter: ExprLocCounter = .init(wip_nav.dwarf, &trash_buffer); |
| 1940 | fn infoExprLoc(wip_nav: *WipNav, loc: Loc) (UpdateError || Writer.Error)!void { |
| 1941 | var buf: [64]u8 = undefined; |
| 1942 | var counter: ExprLocCounter = .init(wip_nav.dwarf, &buf); |
| 1799 | 1943 | try loc.write(&counter); |
| 1800 | 1944 | |
| 1801 | 1945 | const adapter: struct { |
| 1802 | 1946 | wip_nav: *WipNav, |
| 1803 | | fn writer(ctx: @This()) std.ArrayListUnmanaged(u8).Writer { |
| 1804 | | return ctx.wip_nav.debug_info.writer(ctx.wip_nav.dwarf.gpa); |
| 1947 | fn writer(ctx: @This()) *Writer { |
| 1948 | return &ctx.wip_nav.debug_info.writer; |
| 1805 | 1949 | } |
| 1806 | 1950 | fn endian(ctx: @This()) std.builtin.Endian { |
| 1807 | 1951 | return ctx.wip_nav.dwarf.endian; |
| 1808 | 1952 | } |
| 1809 | | fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void { |
| 1953 | fn addrSym(ctx: @This(), sym_index: u32) (UpdateError || Writer.Error)!void { |
| 1810 | 1954 | try ctx.wip_nav.infoAddrSym(sym_index, 0); |
| 1811 | 1955 | } |
| 1812 | | fn infoEntry(ctx: @This(), unit: Unit.Index, entry: Entry.Index) UpdateError!void { |
| 1956 | fn infoEntry( |
| 1957 | ctx: @This(), |
| 1958 | unit: Unit.Index, |
| 1959 | entry: Entry.Index, |
| 1960 | ) (UpdateError || Writer.Error)!void { |
| 1813 | 1961 | try ctx.wip_nav.infoSectionOffset(.debug_info, unit, entry, 0); |
| 1814 | 1962 | } |
| 1815 | 1963 | } = .{ .wip_nav = wip_nav }; |
| 1816 | | try uleb128(adapter.writer(), counter.stream.fullCount()); |
| 1964 | try adapter.writer().writeUleb128(counter.dw.count + counter.dw.writer.end); |
| 1817 | 1965 | try loc.write(adapter); |
| 1818 | 1966 | } |
| 1819 | 1967 | |
| 1820 | | fn infoAddrSym(wip_nav: *WipNav, sym_index: u32, sym_off: u64) UpdateError!void { |
| 1968 | fn infoAddrSym( |
| 1969 | wip_nav: *WipNav, |
| 1970 | sym_index: u32, |
| 1971 | sym_off: u64, |
| 1972 | ) (UpdateError || Writer.Error)!void { |
| 1973 | const diw = &wip_nav.debug_info.writer; |
| 1821 | 1974 | try wip_nav.infoExternalReloc(.{ |
| 1822 | | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 1975 | .source_off = @intCast(diw.end), |
| 1823 | 1976 | .target_sym = sym_index, |
| 1824 | 1977 | .target_off = sym_off, |
| 1825 | 1978 | }); |
| 1826 | | try wip_nav.debug_info.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size)); |
| 1979 | try diw.splatByteAll(0, @intFromEnum(wip_nav.dwarf.address_size)); |
| 1827 | 1980 | } |
| 1828 | 1981 | |
| 1829 | | fn frameExprLoc(wip_nav: *WipNav, loc: Loc) UpdateError!void { |
| 1830 | | var trash_buffer: [64]u8 = undefined; |
| 1831 | | var counter: ExprLocCounter = .init(wip_nav.dwarf, &trash_buffer); |
| 1982 | fn frameExprLoc(wip_nav: *WipNav, loc: Loc) (UpdateError || Writer.Error)!void { |
| 1983 | var buf: [64]u8 = undefined; |
| 1984 | var counter: ExprLocCounter = .init(wip_nav.dwarf, &buf); |
| 1832 | 1985 | try loc.write(&counter); |
| 1833 | 1986 | |
| 1834 | 1987 | const adapter: struct { |
| 1835 | 1988 | wip_nav: *WipNav, |
| 1836 | | fn writer(ctx: @This()) std.ArrayListUnmanaged(u8).Writer { |
| 1837 | | return ctx.wip_nav.debug_frame.writer(ctx.wip_nav.dwarf.gpa); |
| 1989 | fn writer(ctx: @This()) *Writer { |
| 1990 | return &ctx.wip_nav.debug_frame.writer; |
| 1838 | 1991 | } |
| 1839 | 1992 | fn endian(ctx: @This()) std.builtin.Endian { |
| 1840 | 1993 | return ctx.wip_nav.dwarf.endian; |
| 1841 | 1994 | } |
| 1842 | | fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void { |
| 1995 | fn addrSym(ctx: @This(), sym_index: u32) (UpdateError || Writer.Error)!void { |
| 1843 | 1996 | try ctx.wip_nav.frameAddrSym(sym_index, 0); |
| 1844 | 1997 | } |
| 1845 | | fn infoEntry(ctx: @This(), unit: Unit.Index, entry: Entry.Index) UpdateError!void { |
| 1998 | fn infoEntry( |
| 1999 | ctx: @This(), |
| 2000 | unit: Unit.Index, |
| 2001 | entry: Entry.Index, |
| 2002 | ) (UpdateError || Writer.Error)!void { |
| 1846 | 2003 | try ctx.wip_nav.sectionOffset(.debug_frame, .debug_info, unit, entry, 0); |
| 1847 | 2004 | } |
| 1848 | 2005 | } = .{ .wip_nav = wip_nav }; |
| 1849 | | try uleb128(adapter.writer(), counter.stream.fullCount()); |
| 2006 | try adapter.writer().writeUleb128(counter.dw.count + counter.dw.writer.end); |
| 1850 | 2007 | try loc.write(adapter); |
| 1851 | 2008 | } |
| 1852 | 2009 | |
| 1853 | | fn frameAddrSym(wip_nav: *WipNav, sym_index: u32, sym_off: u64) UpdateError!void { |
| 2010 | fn frameAddrSym( |
| 2011 | wip_nav: *WipNav, |
| 2012 | sym_index: u32, |
| 2013 | sym_off: u64, |
| 2014 | ) (UpdateError || Writer.Error)!void { |
| 2015 | const dfw = &wip_nav.debug_frame.writer; |
| 1854 | 2016 | try wip_nav.frameExternalReloc(.{ |
| 1855 | | .source_off = @intCast(wip_nav.debug_frame.items.len), |
| 2017 | .source_off = @intCast(dfw.end), |
| 1856 | 2018 | .target_sym = sym_index, |
| 1857 | 2019 | .target_off = sym_off, |
| 1858 | 2020 | }); |
| 1859 | | try wip_nav.debug_frame.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size)); |
| 2021 | try dfw.splatByteAll(0, @intFromEnum(wip_nav.dwarf.address_size)); |
| 1860 | 2022 | } |
| 1861 | 2023 | |
| 1862 | | fn getNavEntry(wip_nav: *WipNav, nav_index: InternPool.Nav.Index) UpdateError!struct { Unit.Index, Entry.Index } { |
| 2024 | fn getNavEntry( |
| 2025 | wip_nav: *WipNav, |
| 2026 | nav_index: InternPool.Nav.Index, |
| 2027 | ) UpdateError!struct { Unit.Index, Entry.Index } { |
| 1863 | 2028 | const zcu = wip_nav.pt.zcu; |
| 1864 | 2029 | const ip = &zcu.intern_pool; |
| 1865 | 2030 | const nav = ip.getNav(nav_index); |
| ... | ... | @@ -1871,7 +2036,10 @@ pub const WipNav = struct { |
| 1871 | 2036 | return .{ unit, entry }; |
| 1872 | 2037 | } |
| 1873 | 2038 | |
| 1874 | | fn refNav(wip_nav: *WipNav, nav_index: InternPool.Nav.Index) UpdateError!void { |
| 2039 | fn refNav( |
| 2040 | wip_nav: *WipNav, |
| 2041 | nav_index: InternPool.Nav.Index, |
| 2042 | ) (UpdateError || Writer.Error)!void { |
| 1875 | 2043 | const unit, const entry = try wip_nav.getNavEntry(nav_index); |
| 1876 | 2044 | try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0); |
| 1877 | 2045 | } |
| ... | ... | @@ -1898,7 +2066,7 @@ pub const WipNav = struct { |
| 1898 | 2066 | return .{ unit, entry }; |
| 1899 | 2067 | } |
| 1900 | 2068 | |
| 1901 | | fn refType(wip_nav: *WipNav, ty: Type) UpdateError!void { |
| 2069 | fn refType(wip_nav: *WipNav, ty: Type) (UpdateError || Writer.Error)!void { |
| 1902 | 2070 | const unit, const entry = try wip_nav.getTypeEntry(ty); |
| 1903 | 2071 | try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0); |
| 1904 | 2072 | } |
| ... | ... | @@ -1919,47 +2087,54 @@ pub const WipNav = struct { |
| 1919 | 2087 | return .{ unit, entry }; |
| 1920 | 2088 | } |
| 1921 | 2089 | |
| 1922 | | fn refValue(wip_nav: *WipNav, value: Value) UpdateError!void { |
| 2090 | fn refValue(wip_nav: *WipNav, value: Value) (UpdateError || Writer.Error)!void { |
| 1923 | 2091 | const unit, const entry = try wip_nav.getValueEntry(value); |
| 1924 | 2092 | try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0); |
| 1925 | 2093 | } |
| 1926 | 2094 | |
| 1927 | | fn refForward(wip_nav: *WipNav) Allocator.Error!u32 { |
| 2095 | fn refForward(wip_nav: *WipNav) (Allocator.Error || Writer.Error)!u32 { |
| 1928 | 2096 | const dwarf = wip_nav.dwarf; |
| 2097 | const diw = &wip_nav.debug_info.writer; |
| 1929 | 2098 | const cross_entry_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).cross_entry_relocs; |
| 1930 | 2099 | const reloc_index: u32 = @intCast(cross_entry_relocs.items.len); |
| 1931 | 2100 | try cross_entry_relocs.append(dwarf.gpa, .{ |
| 1932 | | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 2101 | .source_off = @intCast(diw.end), |
| 1933 | 2102 | .target_entry = undefined, |
| 1934 | 2103 | .target_off = undefined, |
| 1935 | 2104 | }); |
| 1936 | | try wip_nav.debug_info.appendNTimes(dwarf.gpa, 0, dwarf.sectionOffsetBytes()); |
| 2105 | try diw.splatByteAll(0, dwarf.sectionOffsetBytes()); |
| 1937 | 2106 | return reloc_index; |
| 1938 | 2107 | } |
| 1939 | 2108 | |
| 1940 | 2109 | fn finishForward(wip_nav: *WipNav, reloc_index: u32) void { |
| 1941 | 2110 | const reloc = &wip_nav.dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).cross_entry_relocs.items[reloc_index]; |
| 1942 | 2111 | reloc.target_entry = wip_nav.entry.toOptional(); |
| 1943 | | reloc.target_off = @intCast(wip_nav.debug_info.items.len); |
| 2112 | reloc.target_off = @intCast(wip_nav.debug_info.writer.end); |
| 1944 | 2113 | } |
| 1945 | 2114 | |
| 1946 | | fn blockValue(wip_nav: *WipNav, src_loc: Zcu.LazySrcLoc, val: Value) UpdateError!void { |
| 2115 | fn blockValue( |
| 2116 | wip_nav: *WipNav, |
| 2117 | src_loc: Zcu.LazySrcLoc, |
| 2118 | val: Value, |
| 2119 | ) (UpdateError || Writer.Error)!void { |
| 1947 | 2120 | const ty = val.typeOf(wip_nav.pt.zcu); |
| 1948 | | const diw = wip_nav.debug_info.writer(wip_nav.dwarf.gpa); |
| 1949 | | const bytes = if (ty.hasRuntimeBits(wip_nav.pt.zcu)) ty.abiSize(wip_nav.pt.zcu) else 0; |
| 1950 | | try uleb128(diw, bytes); |
| 1951 | | if (bytes == 0) return; |
| 1952 | | const old_len = wip_nav.debug_info.items.len; |
| 2121 | const diw = &wip_nav.debug_info.writer; |
| 2122 | const size = if (ty.hasRuntimeBits(wip_nav.pt.zcu)) ty.abiSize(wip_nav.pt.zcu) else 0; |
| 2123 | try diw.writeUleb128(size); |
| 2124 | if (size == 0) return; |
| 2125 | var bytes = wip_nav.debug_info.toArrayList(); |
| 2126 | defer wip_nav.debug_info = .fromArrayList(wip_nav.dwarf.gpa, &bytes); |
| 2127 | const old_len = bytes.items.len; |
| 1953 | 2128 | try codegen.generateSymbol( |
| 1954 | 2129 | wip_nav.dwarf.bin_file, |
| 1955 | 2130 | wip_nav.pt, |
| 1956 | 2131 | src_loc, |
| 1957 | 2132 | val, |
| 1958 | | &wip_nav.debug_info, |
| 2133 | &bytes, |
| 1959 | 2134 | .{ .debug_output = .{ .dwarf = wip_nav } }, |
| 1960 | 2135 | ); |
| 1961 | | if (old_len + bytes != wip_nav.debug_info.items.len) { |
| 1962 | | std.debug.print("{f} [{}]: {} != {}\n", .{ ty.fmt(wip_nav.pt), ty.toIntern(), bytes, wip_nav.debug_info.items.len - old_len }); |
| 2136 | if (old_len + size != bytes.items.len) { |
| 2137 | std.debug.print("{f} [{}]: {} != {}\n", .{ ty.fmt(wip_nav.pt), ty.toIntern(), size, bytes.items.len - old_len }); |
| 1963 | 2138 | unreachable; |
| 1964 | 2139 | } |
| 1965 | 2140 | } |
| ... | ... | @@ -1975,9 +2150,9 @@ pub const WipNav = struct { |
| 1975 | 2150 | abbrev_code: AbbrevCodeForForm, |
| 1976 | 2151 | ty: Type, |
| 1977 | 2152 | big_int: std.math.big.int.Const, |
| 1978 | | ) UpdateError!void { |
| 2153 | ) (UpdateError || Writer.Error)!void { |
| 1979 | 2154 | const zcu = wip_nav.pt.zcu; |
| 1980 | | const diw = wip_nav.debug_info.writer(wip_nav.dwarf.gpa); |
| 2155 | const diw = &wip_nav.debug_info.writer; |
| 1981 | 2156 | const signedness = switch (ty.toIntern()) { |
| 1982 | 2157 | .comptime_int_type, .comptime_float_type => .signed, |
| 1983 | 2158 | else => ty.intInfo(zcu).signedness, |
| ... | ... | @@ -1988,7 +2163,7 @@ pub const WipNav = struct { |
| 1988 | 2163 | .signed => abbrev_code.sdata, |
| 1989 | 2164 | .unsigned => abbrev_code.udata, |
| 1990 | 2165 | }); |
| 1991 | | try wip_nav.debug_info.ensureUnusedCapacity(wip_nav.dwarf.gpa, std.math.divCeil(usize, bits, 7) catch unreachable); |
| 2166 | try wip_nav.debug_info.ensureUnusedCapacity(std.math.divCeil(usize, bits, 7) catch unreachable); |
| 1992 | 2167 | var bit: usize = 0; |
| 1993 | 2168 | var carry: u1 = 1; |
| 1994 | 2169 | while (bit < bits) { |
| ... | ... | @@ -2005,14 +2180,15 @@ pub const WipNav = struct { |
| 2005 | 2180 | break :twos_comp_part twos_comp_part; |
| 2006 | 2181 | }; |
| 2007 | 2182 | bit += 7; |
| 2008 | | wip_nav.debug_info.appendAssumeCapacity(@as(u8, if (bit < bits) 0x80 else 0x00) | twos_comp_part); |
| 2183 | diw.writeByte(@as(u8, if (bit < bits) 0x80 else 0x00) | twos_comp_part) catch unreachable; |
| 2009 | 2184 | } |
| 2010 | 2185 | } else { |
| 2011 | 2186 | try wip_nav.abbrevCode(abbrev_code.block); |
| 2012 | 2187 | const bytes = @max(ty.abiSize(zcu), std.math.divCeil(usize, bits, 8) catch unreachable); |
| 2013 | | try uleb128(diw, bytes); |
| 2188 | try diw.writeUleb128(bytes); |
| 2189 | try wip_nav.debug_info.ensureUnusedCapacity(@intCast(bytes)); |
| 2014 | 2190 | big_int.writeTwosComplement( |
| 2015 | | try wip_nav.debug_info.addManyAsSlice(wip_nav.dwarf.gpa, @intCast(bytes)), |
| 2191 | try diw.writableSlice(@intCast(bytes)), |
| 2016 | 2192 | wip_nav.dwarf.endian, |
| 2017 | 2193 | ); |
| 2018 | 2194 | } |
| ... | ... | @@ -2023,7 +2199,7 @@ pub const WipNav = struct { |
| 2023 | 2199 | loaded_enum: InternPool.LoadedEnumType, |
| 2024 | 2200 | abbrev_code: AbbrevCodeForForm, |
| 2025 | 2201 | field_index: usize, |
| 2026 | | ) UpdateError!void { |
| 2202 | ) (UpdateError || Writer.Error)!void { |
| 2027 | 2203 | const zcu = wip_nav.pt.zcu; |
| 2028 | 2204 | const ip = &zcu.intern_pool; |
| 2029 | 2205 | var big_int_space: Value.BigIntSpace = undefined; |
| ... | ... | @@ -2043,11 +2219,11 @@ pub const WipNav = struct { |
| 2043 | 2219 | nav: *const InternPool.Nav, |
| 2044 | 2220 | file: Zcu.File.Index, |
| 2045 | 2221 | decl: *const std.zig.Zir.Inst.Declaration.Unwrapped, |
| 2046 | | ) UpdateError!void { |
| 2222 | ) (UpdateError || Writer.Error)!void { |
| 2047 | 2223 | const zcu = wip_nav.pt.zcu; |
| 2048 | 2224 | const ip = &zcu.intern_pool; |
| 2049 | 2225 | const dwarf = wip_nav.dwarf; |
| 2050 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2226 | const diw = &wip_nav.debug_info.writer; |
| 2051 | 2227 | |
| 2052 | 2228 | const orig_entry = wip_nav.entry; |
| 2053 | 2229 | defer wip_nav.entry = orig_entry; |
| ... | ... | @@ -2098,15 +2274,15 @@ pub const WipNav = struct { |
| 2098 | 2274 | try wip_nav.abbrevCode(if (is_generic_decl) abbrev_code.generic_decl else abbrev_code.decl); |
| 2099 | 2275 | try wip_nav.refType((if (is_generic_decl) null else parent_type) orelse |
| 2100 | 2276 | .fromInterned(zcu.fileRootType(file))); |
| 2101 | | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| 2277 | assert(diw.end == DebugInfo.declEntryLineOff(dwarf)); |
| 2102 | 2278 | try diw.writeInt(u32, decl.src_line + 1, dwarf.endian); |
| 2103 | | try uleb128(diw, decl.src_column + 1); |
| 2279 | try diw.writeUleb128(decl.src_column + 1); |
| 2104 | 2280 | try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); |
| 2105 | 2281 | try wip_nav.strp(nav.name.toSlice(ip)); |
| 2106 | 2282 | |
| 2107 | 2283 | if (!is_generic_decl) return; |
| 2108 | 2284 | const generic_decl_entry = wip_nav.entry; |
| 2109 | | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, generic_decl_entry, dwarf, wip_nav.debug_info.items); |
| 2285 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, generic_decl_entry, dwarf, wip_nav.debug_info.getWritten()); |
| 2110 | 2286 | wip_nav.debug_info.clearRetainingCapacity(); |
| 2111 | 2287 | wip_nav.entry = orig_entry; |
| 2112 | 2288 | try wip_nav.abbrevCode(abbrev_code.decl_instance); |
| ... | ... | @@ -2121,7 +2297,7 @@ pub const WipNav = struct { |
| 2121 | 2297 | const empty: PendingLazy = .{ .types = .empty, .values = .empty }; |
| 2122 | 2298 | }; |
| 2123 | 2299 | |
| 2124 | | fn updateLazy(wip_nav: *WipNav, src_loc: Zcu.LazySrcLoc) UpdateError!void { |
| 2300 | fn updateLazy(wip_nav: *WipNav, src_loc: Zcu.LazySrcLoc) (UpdateError || Writer.Error)!void { |
| 2125 | 2301 | while (true) if (wip_nav.pending_lazy.types.pop()) |pending_ty| |
| 2126 | 2302 | try wip_nav.dwarf.updateLazyType(wip_nav.pt, src_loc, pending_ty, &wip_nav.pending_lazy) |
| 2127 | 2303 | else if (wip_nav.pending_lazy.values.pop()) |pending_val| |
| ... | ... | @@ -2411,8 +2587,8 @@ pub fn initWipNav( |
| 2411 | 2587 | sym_index: u32, |
| 2412 | 2588 | ) error{ OutOfMemory, CodegenFail }!?WipNav { |
| 2413 | 2589 | return initWipNavInner(dwarf, pt, nav_index, sym_index) catch |err| switch (err) { |
| 2414 | | error.OutOfMemory => return error.OutOfMemory, |
| 2415 | | else => |e| return pt.zcu.codegenFail(nav_index, "failed to init dwarf: {s}", .{@errorName(e)}), |
| 2590 | error.OutOfMemory => error.OutOfMemory, |
| 2591 | else => |e| pt.zcu.codegenFail(nav_index, "failed to init dwarf: {s}", .{@errorName(e)}), |
| 2416 | 2592 | }; |
| 2417 | 2593 | } |
| 2418 | 2594 | |
| ... | ... | @@ -2470,17 +2646,17 @@ fn initWipNavInner( |
| 2470 | 2646 | .func_high_pc = undefined, |
| 2471 | 2647 | .blocks = undefined, |
| 2472 | 2648 | .cfi = undefined, |
| 2473 | | .debug_frame = .empty, |
| 2474 | | .debug_info = .empty, |
| 2475 | | .debug_line = .empty, |
| 2476 | | .debug_loclists = .empty, |
| 2649 | .debug_frame = .init(dwarf.gpa), |
| 2650 | .debug_info = .init(dwarf.gpa), |
| 2651 | .debug_line = .init(dwarf.gpa), |
| 2652 | .debug_loclists = .init(dwarf.gpa), |
| 2477 | 2653 | .pending_lazy = .empty, |
| 2478 | 2654 | }; |
| 2479 | 2655 | errdefer wip_nav.deinit(); |
| 2480 | 2656 | |
| 2481 | 2657 | switch (nav_key) { |
| 2482 | 2658 | else => { |
| 2483 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2659 | const diw = &wip_nav.debug_info.writer; |
| 2484 | 2660 | try wip_nav.declCommon(.{ |
| 2485 | 2661 | .decl = .decl_var, |
| 2486 | 2662 | .generic_decl = .generic_decl_var, |
| ... | ... | @@ -2501,7 +2677,7 @@ fn initWipNavInner( |
| 2501 | 2677 | .@"const" => { |
| 2502 | 2678 | const const_ty_reloc_index = try wip_nav.refForward(); |
| 2503 | 2679 | try wip_nav.infoExprLoc(loc); |
| 2504 | | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse |
| 2680 | try diw.writeUleb128(nav.status.fully_resolved.alignment.toByteUnits() orelse |
| 2505 | 2681 | ty.abiAlignment(zcu).toByteUnits().?); |
| 2506 | 2682 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| 2507 | 2683 | wip_nav.finishForward(const_ty_reloc_index); |
| ... | ... | @@ -2511,7 +2687,7 @@ fn initWipNavInner( |
| 2511 | 2687 | .@"var" => { |
| 2512 | 2688 | try wip_nav.refType(ty); |
| 2513 | 2689 | try wip_nav.infoExprLoc(loc); |
| 2514 | | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse |
| 2690 | try diw.writeUleb128(nav.status.fully_resolved.alignment.toByteUnits() orelse |
| 2515 | 2691 | ty.abiAlignment(zcu).toByteUnits().?); |
| 2516 | 2692 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| 2517 | 2693 | }, |
| ... | ... | @@ -2538,7 +2714,7 @@ fn initWipNavInner( |
| 2538 | 2714 | .none => {}, |
| 2539 | 2715 | .debug_frame, .eh_frame => |format| { |
| 2540 | 2716 | const entry = dwarf.debug_frame.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry); |
| 2541 | | const dfw = wip_nav.debug_frame.writer(dwarf.gpa); |
| 2717 | const dfw = &wip_nav.debug_frame.writer; |
| 2542 | 2718 | switch (dwarf.format) { |
| 2543 | 2719 | .@"32" => try dfw.writeInt(u32, undefined, dwarf.endian), |
| 2544 | 2720 | .@"64" => { |
| ... | ... | @@ -2550,27 +2726,27 @@ fn initWipNavInner( |
| 2550 | 2726 | .none => unreachable, |
| 2551 | 2727 | .debug_frame => { |
| 2552 | 2728 | try entry.cross_entry_relocs.append(dwarf.gpa, .{ |
| 2553 | | .source_off = @intCast(wip_nav.debug_frame.items.len), |
| 2729 | .source_off = @intCast(dfw.end), |
| 2554 | 2730 | }); |
| 2555 | | try dfw.writeByteNTimes(0, dwarf.sectionOffsetBytes()); |
| 2731 | try dfw.splatByteAll(0, dwarf.sectionOffsetBytes()); |
| 2556 | 2732 | try wip_nav.frameAddrSym(sym_index, 0); |
| 2557 | | try dfw.writeByteNTimes(undefined, @intFromEnum(dwarf.address_size)); |
| 2733 | try dfw.splatByteAll(undefined, @intFromEnum(dwarf.address_size)); |
| 2558 | 2734 | }, |
| 2559 | 2735 | .eh_frame => { |
| 2560 | 2736 | try dfw.writeInt(u32, undefined, dwarf.endian); |
| 2561 | 2737 | try wip_nav.frameExternalReloc(.{ |
| 2562 | | .source_off = @intCast(wip_nav.debug_frame.items.len), |
| 2738 | .source_off = @intCast(dfw.end), |
| 2563 | 2739 | .target_sym = sym_index, |
| 2564 | 2740 | }); |
| 2565 | 2741 | try dfw.writeInt(u32, 0, dwarf.endian); |
| 2566 | 2742 | try dfw.writeInt(u32, undefined, dwarf.endian); |
| 2567 | | try uleb128(dfw, 0); |
| 2743 | try dfw.writeUleb128(0); |
| 2568 | 2744 | }, |
| 2569 | 2745 | } |
| 2570 | 2746 | }, |
| 2571 | 2747 | } |
| 2572 | 2748 | |
| 2573 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2749 | const diw = &wip_nav.debug_info.writer; |
| 2574 | 2750 | try wip_nav.declCommon(.{ |
| 2575 | 2751 | .decl = .decl_func, |
| 2576 | 2752 | .generic_decl = .generic_decl_func, |
| ... | ... | @@ -2579,48 +2755,48 @@ fn initWipNavInner( |
| 2579 | 2755 | try wip_nav.strp(nav.fqn.toSlice(ip)); |
| 2580 | 2756 | try wip_nav.refType(.fromInterned(func_type.return_type)); |
| 2581 | 2757 | try wip_nav.infoAddrSym(sym_index, 0); |
| 2582 | | wip_nav.func_high_pc = @intCast(wip_nav.debug_info.items.len); |
| 2758 | wip_nav.func_high_pc = @intCast(diw.end); |
| 2583 | 2759 | try diw.writeInt(u32, 0, dwarf.endian); |
| 2584 | 2760 | const target = &mod.resolved_target.result; |
| 2585 | | try uleb128(diw, switch (nav.status.fully_resolved.alignment) { |
| 2761 | try diw.writeUleb128(switch (nav.status.fully_resolved.alignment) { |
| 2586 | 2762 | .none => target_info.defaultFunctionAlignment(target), |
| 2587 | 2763 | else => |a| a.maxStrict(target_info.minFunctionAlignment(target)), |
| 2588 | 2764 | }.toByteUnits().?); |
| 2589 | 2765 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| 2590 | 2766 | try diw.writeByte(@intFromBool(func_type.return_type == .noreturn_type)); |
| 2591 | 2767 | |
| 2592 | | const dlw = wip_nav.debug_line.writer(dwarf.gpa); |
| 2768 | const dlw = &wip_nav.debug_line.writer; |
| 2593 | 2769 | try dlw.writeByte(DW.LNS.extended_op); |
| 2594 | 2770 | if (dwarf.incremental()) { |
| 2595 | | try uleb128(dlw, 1 + dwarf.sectionOffsetBytes()); |
| 2771 | try dlw.writeUleb128(1 + dwarf.sectionOffsetBytes()); |
| 2596 | 2772 | try dlw.writeByte(DW.LNE.ZIG_set_decl); |
| 2597 | 2773 | try dwarf.debug_line.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).cross_section_relocs.append(dwarf.gpa, .{ |
| 2598 | | .source_off = @intCast(wip_nav.debug_line.items.len), |
| 2774 | .source_off = @intCast(dlw.end), |
| 2599 | 2775 | .target_sec = .debug_info, |
| 2600 | 2776 | .target_unit = wip_nav.unit, |
| 2601 | 2777 | .target_entry = wip_nav.entry.toOptional(), |
| 2602 | 2778 | }); |
| 2603 | | try dlw.writeByteNTimes(0, dwarf.sectionOffsetBytes()); |
| 2779 | try dlw.splatByteAll(0, dwarf.sectionOffsetBytes()); |
| 2604 | 2780 | |
| 2605 | 2781 | try dlw.writeByte(DW.LNS.set_column); |
| 2606 | | try uleb128(dlw, func.lbrace_column + 1); |
| 2782 | try dlw.writeUleb128(func.lbrace_column + 1); |
| 2607 | 2783 | |
| 2608 | 2784 | try wip_nav.advancePCAndLine(func.lbrace_line, 0); |
| 2609 | 2785 | } else { |
| 2610 | | try uleb128(dlw, 1 + @intFromEnum(dwarf.address_size)); |
| 2786 | try dlw.writeUleb128(1 + @intFromEnum(dwarf.address_size)); |
| 2611 | 2787 | try dlw.writeByte(DW.LNE.set_address); |
| 2612 | 2788 | try dwarf.debug_line.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs.append(dwarf.gpa, .{ |
| 2613 | | .source_off = @intCast(wip_nav.debug_line.items.len), |
| 2789 | .source_off = @intCast(dlw.end), |
| 2614 | 2790 | .target_sym = sym_index, |
| 2615 | 2791 | }); |
| 2616 | | try dlw.writeByteNTimes(0, @intFromEnum(dwarf.address_size)); |
| 2792 | try dlw.splatByteAll(0, @intFromEnum(dwarf.address_size)); |
| 2617 | 2793 | |
| 2618 | 2794 | const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, inst_info.file); |
| 2619 | 2795 | try dlw.writeByte(DW.LNS.set_file); |
| 2620 | | try uleb128(dlw, file_gop.index); |
| 2796 | try dlw.writeUleb128(file_gop.index); |
| 2621 | 2797 | |
| 2622 | 2798 | try dlw.writeByte(DW.LNS.set_column); |
| 2623 | | try uleb128(dlw, func.lbrace_column + 1); |
| 2799 | try dlw.writeUleb128(func.lbrace_column + 1); |
| 2624 | 2800 | |
| 2625 | 2801 | try wip_nav.advancePCAndLine(@intCast(decl.src_line + func.lbrace_line), 0); |
| 2626 | 2802 | } |
| ... | ... | @@ -2636,6 +2812,18 @@ pub fn finishWipNavFunc( |
| 2636 | 2812 | code_size: u64, |
| 2637 | 2813 | wip_nav: *WipNav, |
| 2638 | 2814 | ) UpdateError!void { |
| 2815 | return dwarf.finishWipNavFuncWriterError(pt, nav_index, code_size, wip_nav) catch |err| switch (err) { |
| 2816 | error.WriteFailed => error.OutOfMemory, |
| 2817 | else => |e| e, |
| 2818 | }; |
| 2819 | } |
| 2820 | fn finishWipNavFuncWriterError( |
| 2821 | dwarf: *Dwarf, |
| 2822 | pt: Zcu.PerThread, |
| 2823 | nav_index: InternPool.Nav.Index, |
| 2824 | code_size: u64, |
| 2825 | wip_nav: *WipNav, |
| 2826 | ) (UpdateError || Writer.Error)!void { |
| 2639 | 2827 | const zcu = pt.zcu; |
| 2640 | 2828 | const ip = &zcu.intern_pool; |
| 2641 | 2829 | const nav = ip.getNav(nav_index); |
| ... | ... | @@ -2658,12 +2846,12 @@ pub fn finishWipNavFunc( |
| 2658 | 2846 | switch (dwarf.debug_frame.header.format) { |
| 2659 | 2847 | .none => {}, |
| 2660 | 2848 | .debug_frame, .eh_frame => |format| { |
| 2661 | | try wip_nav.debug_frame.appendNTimes( |
| 2662 | | dwarf.gpa, |
| 2849 | const dfw = &wip_nav.debug_frame.writer; |
| 2850 | try dfw.splatByteAll( |
| 2663 | 2851 | DW.CFA.nop, |
| 2664 | | @intCast(dwarf.debug_frame.section.alignment.forward(wip_nav.debug_frame.items.len) - wip_nav.debug_frame.items.len), |
| 2852 | @intCast(dwarf.debug_frame.section.alignment.forward(dfw.end) - dfw.end), |
| 2665 | 2853 | ); |
| 2666 | | const contents = wip_nav.debug_frame.items; |
| 2854 | const contents = wip_nav.debug_frame.getWritten(); |
| 2667 | 2855 | try dwarf.debug_frame.section.resizeEntry(wip_nav.unit, wip_nav.entry, dwarf, @intCast(contents.len)); |
| 2668 | 2856 | const unit = dwarf.debug_frame.section.getUnit(wip_nav.unit); |
| 2669 | 2857 | const entry = unit.getEntry(wip_nav.entry); |
| ... | ... | @@ -2690,14 +2878,16 @@ pub fn finishWipNavFunc( |
| 2690 | 2878 | }, |
| 2691 | 2879 | } |
| 2692 | 2880 | { |
| 2693 | | std.mem.writeInt(u32, wip_nav.debug_info.items[wip_nav.func_high_pc..][0..4], @intCast(code_size), dwarf.endian); |
| 2881 | std.mem.writeInt(u32, wip_nav.debug_info.getWritten()[wip_nav.func_high_pc..][0..4], @intCast(code_size), dwarf.endian); |
| 2694 | 2882 | if (wip_nav.any_children) { |
| 2695 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2696 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 2883 | const diw = &wip_nav.debug_info.writer; |
| 2884 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 2697 | 2885 | } else { |
| 2698 | | const abbrev_code_buf = wip_nav.debug_info.items[0..AbbrevCode.decl_bytes]; |
| 2699 | | var abbrev_code_fbs = std.io.fixedBufferStream(abbrev_code_buf); |
| 2700 | | const abbrev_code: AbbrevCode = @enumFromInt(std.leb.readUleb128(@typeInfo(AbbrevCode).@"enum".tag_type, abbrev_code_fbs.reader()) catch unreachable); |
| 2886 | const abbrev_code_buf = wip_nav.debug_info.getWritten()[0..AbbrevCode.decl_bytes]; |
| 2887 | var abbrev_code_fr: std.Io.Reader = .fixed(abbrev_code_buf); |
| 2888 | const abbrev_code: AbbrevCode = @enumFromInt( |
| 2889 | abbrev_code_fr.takeLeb128(@typeInfo(AbbrevCode).@"enum".tag_type) catch unreachable, |
| 2890 | ); |
| 2701 | 2891 | std.leb.writeUnsignedFixed( |
| 2702 | 2892 | AbbrevCode.decl_bytes, |
| 2703 | 2893 | abbrev_code_buf, |
| ... | ... | @@ -2738,28 +2928,39 @@ pub fn finishWipNav( |
| 2738 | 2928 | nav_index: InternPool.Nav.Index, |
| 2739 | 2929 | wip_nav: *WipNav, |
| 2740 | 2930 | ) UpdateError!void { |
| 2931 | return dwarf.finishWipNavWriterError(pt, nav_index, wip_nav) catch |err| switch (err) { |
| 2932 | error.WriteFailed => error.OutOfMemory, |
| 2933 | else => |e| e, |
| 2934 | }; |
| 2935 | } |
| 2936 | fn finishWipNavWriterError( |
| 2937 | dwarf: *Dwarf, |
| 2938 | pt: Zcu.PerThread, |
| 2939 | nav_index: InternPool.Nav.Index, |
| 2940 | wip_nav: *WipNav, |
| 2941 | ) (UpdateError || Writer.Error)!void { |
| 2741 | 2942 | const zcu = pt.zcu; |
| 2742 | 2943 | const ip = &zcu.intern_pool; |
| 2743 | 2944 | const nav = ip.getNav(nav_index); |
| 2744 | 2945 | log.debug("finishWipNav({f})", .{nav.fqn.fmt(ip)}); |
| 2745 | 2946 | |
| 2746 | | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items); |
| 2747 | | if (wip_nav.debug_line.items.len > 0) { |
| 2748 | | const dlw = wip_nav.debug_line.writer(dwarf.gpa); |
| 2947 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.getWritten()); |
| 2948 | const dlw = &wip_nav.debug_line.writer; |
| 2949 | if (dlw.end > 0) { |
| 2749 | 2950 | try dlw.writeByte(DW.LNS.extended_op); |
| 2750 | | try uleb128(dlw, 1); |
| 2951 | try dlw.writeUleb128(1); |
| 2751 | 2952 | try dlw.writeByte(DW.LNE.end_sequence); |
| 2752 | | try dwarf.debug_line.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_line.items); |
| 2953 | try dwarf.debug_line.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_line.getWritten()); |
| 2753 | 2954 | } |
| 2754 | | try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.items); |
| 2955 | try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.getWritten()); |
| 2755 | 2956 | |
| 2756 | 2957 | try wip_nav.updateLazy(zcu.navSrcLoc(nav_index)); |
| 2757 | 2958 | } |
| 2758 | 2959 | |
| 2759 | 2960 | pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) error{ OutOfMemory, CodegenFail }!void { |
| 2760 | 2961 | return updateComptimeNavInner(dwarf, pt, nav_index) catch |err| switch (err) { |
| 2761 | | error.OutOfMemory => return error.OutOfMemory, |
| 2762 | | else => |e| return pt.zcu.codegenFail(nav_index, "failed to update dwarf: {s}", .{@errorName(e)}), |
| 2962 | error.OutOfMemory => error.OutOfMemory, |
| 2963 | else => |e| pt.zcu.codegenFail(nav_index, "failed to update dwarf: {s}", .{@errorName(e)}), |
| 2763 | 2964 | }; |
| 2764 | 2965 | } |
| 2765 | 2966 | |
| ... | ... | @@ -2801,10 +3002,10 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2801 | 3002 | .func_high_pc = undefined, |
| 2802 | 3003 | .blocks = undefined, |
| 2803 | 3004 | .cfi = undefined, |
| 2804 | | .debug_frame = .empty, |
| 2805 | | .debug_info = .empty, |
| 2806 | | .debug_line = .empty, |
| 2807 | | .debug_loclists = .empty, |
| 3005 | .debug_frame = .init(dwarf.gpa), |
| 3006 | .debug_info = .init(dwarf.gpa), |
| 3007 | .debug_line = .init(dwarf.gpa), |
| 3008 | .debug_loclists = .init(dwarf.gpa), |
| 2808 | 3009 | .pending_lazy = .empty, |
| 2809 | 3010 | }; |
| 2810 | 3011 | defer wip_nav.deinit(); |
| ... | ... | @@ -2850,7 +3051,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2850 | 3051 | } |
| 2851 | 3052 | wip_nav.entry = nav_gop.value_ptr.*; |
| 2852 | 3053 | |
| 2853 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 3054 | const diw = &wip_nav.debug_info.writer; |
| 2854 | 3055 | |
| 2855 | 3056 | switch (loaded_struct.layout) { |
| 2856 | 3057 | .auto, .@"extern" => { |
| ... | ... | @@ -2864,8 +3065,8 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2864 | 3065 | .decl_instance = .decl_instance_struct, |
| 2865 | 3066 | }, &nav, inst_info.file, &decl); |
| 2866 | 3067 | if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else { |
| 2867 | | try uleb128(diw, nav_val.toType().abiSize(zcu)); |
| 2868 | | try uleb128(diw, nav_val.toType().abiAlignment(zcu).toByteUnits().?); |
| 3068 | try diw.writeUleb128(nav_val.toType().abiSize(zcu)); |
| 3069 | try diw.writeUleb128(nav_val.toType().abiAlignment(zcu).toByteUnits().?); |
| 2869 | 3070 | for (0..loaded_struct.field_types.len) |field_index| { |
| 2870 | 3071 | const is_comptime = loaded_struct.fieldIsComptime(ip, field_index); |
| 2871 | 3072 | const field_init = loaded_struct.fieldInit(ip, field_index); |
| ... | ... | @@ -2901,8 +3102,8 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2901 | 3102 | } |
| 2902 | 3103 | try wip_nav.refType(field_type); |
| 2903 | 3104 | if (!is_comptime) { |
| 2904 | | try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]); |
| 2905 | | try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse |
| 3105 | try diw.writeUleb128(loaded_struct.offsets.get(ip)[field_index]); |
| 3106 | try diw.writeUleb128(loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse |
| 2906 | 3107 | field_type.abiAlignment(zcu).toByteUnits().?); |
| 2907 | 3108 | } |
| 2908 | 3109 | if (has_comptime_state) |
| ... | ... | @@ -2910,7 +3111,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2910 | 3111 | else if (has_runtime_bits) |
| 2911 | 3112 | try wip_nav.blockValue(nav_src_loc, .fromInterned(field_init)); |
| 2912 | 3113 | } |
| 2913 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3114 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 2914 | 3115 | } |
| 2915 | 3116 | }, |
| 2916 | 3117 | .@"packed" => { |
| ... | ... | @@ -2926,10 +3127,10 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2926 | 3127 | try wip_nav.strp(loaded_struct.fieldName(ip, field_index).unwrap().?.toSlice(ip)); |
| 2927 | 3128 | const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]); |
| 2928 | 3129 | try wip_nav.refType(field_type); |
| 2929 | | try uleb128(diw, field_bit_offset); |
| 3130 | try diw.writeUleb128(field_bit_offset); |
| 2930 | 3131 | field_bit_offset += @intCast(field_type.bitSize(zcu)); |
| 2931 | 3132 | } |
| 2932 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3133 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 2933 | 3134 | }, |
| 2934 | 3135 | } |
| 2935 | 3136 | break :tag .done; |
| ... | ... | @@ -2952,7 +3153,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2952 | 3153 | type_gop.value_ptr.* = nav_gop.value_ptr.*; |
| 2953 | 3154 | } |
| 2954 | 3155 | wip_nav.entry = nav_gop.value_ptr.*; |
| 2955 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 3156 | const diw = &wip_nav.debug_info.writer; |
| 2956 | 3157 | try wip_nav.declCommon(if (loaded_enum.names.len > 0) .{ |
| 2957 | 3158 | .decl = .decl_enum, |
| 2958 | 3159 | .generic_decl = .generic_decl_const, |
| ... | ... | @@ -2971,7 +3172,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2971 | 3172 | }, field_index); |
| 2972 | 3173 | try wip_nav.strp(loaded_enum.names.get(ip)[field_index].toSlice(ip)); |
| 2973 | 3174 | } |
| 2974 | | if (loaded_enum.names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3175 | if (loaded_enum.names.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 2975 | 3176 | break :tag .done; |
| 2976 | 3177 | }, |
| 2977 | 3178 | .union_type => tag: { |
| ... | ... | @@ -2991,15 +3192,15 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2991 | 3192 | type_gop.value_ptr.* = nav_gop.value_ptr.*; |
| 2992 | 3193 | } |
| 2993 | 3194 | wip_nav.entry = nav_gop.value_ptr.*; |
| 2994 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 3195 | const diw = &wip_nav.debug_info.writer; |
| 2995 | 3196 | try wip_nav.declCommon(.{ |
| 2996 | 3197 | .decl = .decl_union, |
| 2997 | 3198 | .generic_decl = .generic_decl_const, |
| 2998 | 3199 | .decl_instance = .decl_instance_union, |
| 2999 | 3200 | }, &nav, inst_info.file, &decl); |
| 3000 | 3201 | const union_layout = Type.getUnionLayout(loaded_union, zcu); |
| 3001 | | try uleb128(diw, union_layout.abi_size); |
| 3002 | | try uleb128(diw, union_layout.abi_align.toByteUnits().?); |
| 3202 | try diw.writeUleb128(union_layout.abi_size); |
| 3203 | try diw.writeUleb128(union_layout.abi_align.toByteUnits().?); |
| 3003 | 3204 | const loaded_tag = loaded_union.loadTagType(ip); |
| 3004 | 3205 | if (loaded_union.hasTag(ip)) { |
| 3005 | 3206 | try wip_nav.abbrevCode(.tagged_union); |
| ... | ... | @@ -3007,13 +3208,13 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3007 | 3208 | .debug_info, |
| 3008 | 3209 | wip_nav.unit, |
| 3009 | 3210 | wip_nav.entry, |
| 3010 | | @intCast(wip_nav.debug_info.items.len + dwarf.sectionOffsetBytes()), |
| 3211 | @intCast(diw.end + dwarf.sectionOffsetBytes()), |
| 3011 | 3212 | ); |
| 3012 | 3213 | { |
| 3013 | 3214 | try wip_nav.abbrevCode(.generated_field); |
| 3014 | 3215 | try wip_nav.strp("tag"); |
| 3015 | 3216 | try wip_nav.refType(.fromInterned(loaded_union.enum_tag_ty)); |
| 3016 | | try uleb128(diw, union_layout.tagOffset()); |
| 3217 | try diw.writeUleb128(union_layout.tagOffset()); |
| 3017 | 3218 | |
| 3018 | 3219 | for (0..loaded_union.field_types.len) |field_index| { |
| 3019 | 3220 | try wip_nav.enumConstValue(loaded_tag, .{ |
| ... | ... | @@ -3026,23 +3227,23 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3026 | 3227 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); |
| 3027 | 3228 | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 3028 | 3229 | try wip_nav.refType(field_type); |
| 3029 | | try uleb128(diw, union_layout.payloadOffset()); |
| 3030 | | try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse |
| 3230 | try diw.writeUleb128(union_layout.payloadOffset()); |
| 3231 | try diw.writeUleb128(loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse |
| 3031 | 3232 | if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?); |
| 3032 | 3233 | } |
| 3033 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3234 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3034 | 3235 | } |
| 3035 | 3236 | } |
| 3036 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3237 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3037 | 3238 | } else for (0..loaded_union.field_types.len) |field_index| { |
| 3038 | 3239 | try wip_nav.abbrevCode(.untagged_union_field); |
| 3039 | 3240 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); |
| 3040 | 3241 | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 3041 | 3242 | try wip_nav.refType(field_type); |
| 3042 | | try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse |
| 3243 | try diw.writeUleb128(loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse |
| 3043 | 3244 | field_type.abiAlignment(zcu).toByteUnits().?); |
| 3044 | 3245 | } |
| 3045 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3246 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3046 | 3247 | break :tag .done; |
| 3047 | 3248 | }, |
| 3048 | 3249 | .opaque_type => tag: { |
| ... | ... | @@ -3062,7 +3263,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3062 | 3263 | type_gop.value_ptr.* = nav_gop.value_ptr.*; |
| 3063 | 3264 | } |
| 3064 | 3265 | wip_nav.entry = nav_gop.value_ptr.*; |
| 3065 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 3266 | const diw = &wip_nav.debug_info.writer; |
| 3066 | 3267 | try wip_nav.declCommon(.{ |
| 3067 | 3268 | .decl = .decl_namespace_struct, |
| 3068 | 3269 | .generic_decl = .generic_decl_const, |
| ... | ... | @@ -3106,7 +3307,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3106 | 3307 | const is_nullary = !func_type.is_var_args and for (0..func_type.param_types.len) |param_index| { |
| 3107 | 3308 | if (!func_type.paramIsComptime(std.math.cast(u5, param_index) orelse break false)) break false; |
| 3108 | 3309 | } else true; |
| 3109 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 3310 | const diw = &wip_nav.debug_info.writer; |
| 3110 | 3311 | try wip_nav.declCommon(if (is_nullary) .{ |
| 3111 | 3312 | .decl = .decl_nullary_func_generic, |
| 3112 | 3313 | .generic_decl = .generic_decl_func, |
| ... | ... | @@ -3125,7 +3326,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3125 | 3326 | try wip_nav.refType(.fromInterned(func_type.param_types.get(ip)[param_index])); |
| 3126 | 3327 | } |
| 3127 | 3328 | if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args); |
| 3128 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3329 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3129 | 3330 | } |
| 3130 | 3331 | break :tag .done; |
| 3131 | 3332 | }, |
| ... | ... | @@ -3150,7 +3351,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3150 | 3351 | try wip_nav.refType(nav_val.toType()); |
| 3151 | 3352 | }, |
| 3152 | 3353 | .decl_var => { |
| 3153 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 3354 | const diw = &wip_nav.debug_info.writer; |
| 3154 | 3355 | try wip_nav.declCommon(.{ |
| 3155 | 3356 | .decl = .decl_var, |
| 3156 | 3357 | .generic_decl = .generic_decl_var, |
| ... | ... | @@ -3160,12 +3361,12 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3160 | 3361 | const nav_ty = nav_val.typeOf(zcu); |
| 3161 | 3362 | try wip_nav.refType(nav_ty); |
| 3162 | 3363 | try wip_nav.blockValue(nav_src_loc, nav_val); |
| 3163 | | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse |
| 3364 | try diw.writeUleb128(nav.status.fully_resolved.alignment.toByteUnits() orelse |
| 3164 | 3365 | nav_ty.abiAlignment(zcu).toByteUnits().?); |
| 3165 | 3366 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| 3166 | 3367 | }, |
| 3167 | 3368 | .decl_const => { |
| 3168 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 3369 | const diw = &wip_nav.debug_info.writer; |
| 3169 | 3370 | const nav_ty = nav_val.typeOf(zcu); |
| 3170 | 3371 | const has_runtime_bits = nav_ty.hasRuntimeBits(zcu); |
| 3171 | 3372 | const has_comptime_state = nav_ty.comptimeOnly(zcu) and try nav_ty.onePossibleValue(pt) == null; |
| ... | ... | @@ -3188,7 +3389,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3188 | 3389 | }, &nav, inst_info.file, &decl); |
| 3189 | 3390 | try wip_nav.strp(nav.fqn.toSlice(ip)); |
| 3190 | 3391 | const nav_ty_reloc_index = try wip_nav.refForward(); |
| 3191 | | try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse |
| 3392 | try diw.writeUleb128(nav.status.fully_resolved.alignment.toByteUnits() orelse |
| 3192 | 3393 | nav_ty.abiAlignment(zcu).toByteUnits().?); |
| 3193 | 3394 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| 3194 | 3395 | if (has_runtime_bits) try wip_nav.blockValue(nav_src_loc, nav_val); |
| ... | ... | @@ -3206,7 +3407,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3206 | 3407 | try wip_nav.refNav(owner_nav); |
| 3207 | 3408 | }, |
| 3208 | 3409 | } |
| 3209 | | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items); |
| 3410 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.getWritten()); |
| 3210 | 3411 | try wip_nav.updateLazy(nav_src_loc); |
| 3211 | 3412 | } |
| 3212 | 3413 | |
| ... | ... | @@ -3216,7 +3417,7 @@ fn updateLazyType( |
| 3216 | 3417 | src_loc: Zcu.LazySrcLoc, |
| 3217 | 3418 | type_index: InternPool.Index, |
| 3218 | 3419 | pending_lazy: *WipNav.PendingLazy, |
| 3219 | | ) UpdateError!void { |
| 3420 | ) (UpdateError || Writer.Error)!void { |
| 3220 | 3421 | const zcu = pt.zcu; |
| 3221 | 3422 | const ip = &zcu.intern_pool; |
| 3222 | 3423 | assert(ip.typeOf(type_index) == .type_type); |
| ... | ... | @@ -3237,10 +3438,10 @@ fn updateLazyType( |
| 3237 | 3438 | .func_high_pc = undefined, |
| 3238 | 3439 | .blocks = undefined, |
| 3239 | 3440 | .cfi = undefined, |
| 3240 | | .debug_frame = .empty, |
| 3241 | | .debug_info = .empty, |
| 3242 | | .debug_line = .empty, |
| 3243 | | .debug_loclists = .empty, |
| 3441 | .debug_frame = .init(dwarf.gpa), |
| 3442 | .debug_info = .init(dwarf.gpa), |
| 3443 | .debug_line = .init(dwarf.gpa), |
| 3444 | .debug_loclists = .init(dwarf.gpa), |
| 3244 | 3445 | .pending_lazy = pending_lazy.*, |
| 3245 | 3446 | }; |
| 3246 | 3447 | defer { |
| ... | ... | @@ -3248,7 +3449,7 @@ fn updateLazyType( |
| 3248 | 3449 | wip_nav.pending_lazy = .empty; |
| 3249 | 3450 | wip_nav.deinit(); |
| 3250 | 3451 | } |
| 3251 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 3452 | const diw = &wip_nav.debug_info.writer; |
| 3252 | 3453 | const name = switch (type_index) { |
| 3253 | 3454 | .generic_poison_type => "", |
| 3254 | 3455 | else => try std.fmt.allocPrint(dwarf.gpa, "{f}", .{ty.fmt(pt)}), |
| ... | ... | @@ -3266,9 +3467,9 @@ fn updateLazyType( |
| 3266 | 3467 | try diw.writeByte(switch (int_type.signedness) { |
| 3267 | 3468 | inline .signed, .unsigned => |signedness| @field(DW.ATE, @tagName(signedness)), |
| 3268 | 3469 | }); |
| 3269 | | try uleb128(diw, int_type.bits); |
| 3270 | | try uleb128(diw, ty.abiSize(zcu)); |
| 3271 | | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); |
| 3470 | try diw.writeUleb128(int_type.bits); |
| 3471 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3472 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3272 | 3473 | }, |
| 3273 | 3474 | .ptr_type => |ptr_type| switch (ptr_type.flags.size) { |
| 3274 | 3475 | .one, .many, .c => { |
| ... | ... | @@ -3276,14 +3477,14 @@ fn updateLazyType( |
| 3276 | 3477 | try wip_nav.abbrevCode(if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type); |
| 3277 | 3478 | try wip_nav.strp(name); |
| 3278 | 3479 | if (ptr_type.sentinel != .none) try wip_nav.blockValue(src_loc, .fromInterned(ptr_type.sentinel)); |
| 3279 | | try uleb128(diw, ptr_type.flags.alignment.toByteUnits() orelse |
| 3480 | try diw.writeUleb128(ptr_type.flags.alignment.toByteUnits() orelse |
| 3280 | 3481 | ptr_child_type.abiAlignment(zcu).toByteUnits().?); |
| 3281 | 3482 | try diw.writeByte(@intFromEnum(ptr_type.flags.address_space)); |
| 3282 | 3483 | if (ptr_type.flags.is_const or ptr_type.flags.is_volatile) try wip_nav.infoSectionOffset( |
| 3283 | 3484 | .debug_info, |
| 3284 | 3485 | wip_nav.unit, |
| 3285 | 3486 | wip_nav.entry, |
| 3286 | | @intCast(wip_nav.debug_info.items.len + dwarf.sectionOffsetBytes()), |
| 3487 | @intCast(diw.end + dwarf.sectionOffsetBytes()), |
| 3287 | 3488 | ) else try wip_nav.refType(ptr_child_type); |
| 3288 | 3489 | if (ptr_type.flags.is_const) { |
| 3289 | 3490 | try wip_nav.abbrevCode(.is_const); |
| ... | ... | @@ -3291,7 +3492,7 @@ fn updateLazyType( |
| 3291 | 3492 | .debug_info, |
| 3292 | 3493 | wip_nav.unit, |
| 3293 | 3494 | wip_nav.entry, |
| 3294 | | @intCast(wip_nav.debug_info.items.len + dwarf.sectionOffsetBytes()), |
| 3495 | @intCast(diw.end + dwarf.sectionOffsetBytes()), |
| 3295 | 3496 | ) else try wip_nav.refType(ptr_child_type); |
| 3296 | 3497 | } |
| 3297 | 3498 | if (ptr_type.flags.is_volatile) { |
| ... | ... | @@ -3302,19 +3503,19 @@ fn updateLazyType( |
| 3302 | 3503 | .slice => { |
| 3303 | 3504 | try wip_nav.abbrevCode(.generated_struct_type); |
| 3304 | 3505 | try wip_nav.strp(name); |
| 3305 | | try uleb128(diw, ty.abiSize(zcu)); |
| 3306 | | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); |
| 3506 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3507 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3307 | 3508 | try wip_nav.abbrevCode(.generated_field); |
| 3308 | 3509 | try wip_nav.strp("ptr"); |
| 3309 | 3510 | const ptr_field_type = ty.slicePtrFieldType(zcu); |
| 3310 | 3511 | try wip_nav.refType(ptr_field_type); |
| 3311 | | try uleb128(diw, 0); |
| 3512 | try diw.writeUleb128(0); |
| 3312 | 3513 | try wip_nav.abbrevCode(.generated_field); |
| 3313 | 3514 | try wip_nav.strp("len"); |
| 3314 | 3515 | const len_field_type: Type = .usize; |
| 3315 | 3516 | try wip_nav.refType(len_field_type); |
| 3316 | | try uleb128(diw, len_field_type.abiAlignment(zcu).forward(ptr_field_type.abiSize(zcu))); |
| 3317 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3517 | try diw.writeUleb128(len_field_type.abiAlignment(zcu).forward(ptr_field_type.abiSize(zcu))); |
| 3518 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3318 | 3519 | }, |
| 3319 | 3520 | }, |
| 3320 | 3521 | .array_type => |array_type| { |
| ... | ... | @@ -3325,8 +3526,8 @@ fn updateLazyType( |
| 3325 | 3526 | try wip_nav.refType(array_child_type); |
| 3326 | 3527 | try wip_nav.abbrevCode(.array_index); |
| 3327 | 3528 | try wip_nav.refType(.usize); |
| 3328 | | try uleb128(diw, array_type.len); |
| 3329 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3529 | try diw.writeUleb128(array_type.len); |
| 3530 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3330 | 3531 | }, |
| 3331 | 3532 | .vector_type => |vector_type| { |
| 3332 | 3533 | try wip_nav.abbrevCode(.vector_type); |
| ... | ... | @@ -3334,22 +3535,22 @@ fn updateLazyType( |
| 3334 | 3535 | try wip_nav.refType(.fromInterned(vector_type.child)); |
| 3335 | 3536 | try wip_nav.abbrevCode(.array_index); |
| 3336 | 3537 | try wip_nav.refType(.usize); |
| 3337 | | try uleb128(diw, vector_type.len); |
| 3338 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3538 | try diw.writeUleb128(vector_type.len); |
| 3539 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3339 | 3540 | }, |
| 3340 | 3541 | .opt_type => |opt_child_type_index| { |
| 3341 | 3542 | const opt_child_type: Type = .fromInterned(opt_child_type_index); |
| 3342 | 3543 | const opt_repr = optRepr(opt_child_type, zcu); |
| 3343 | 3544 | try wip_nav.abbrevCode(.generated_union_type); |
| 3344 | 3545 | try wip_nav.strp(name); |
| 3345 | | try uleb128(diw, ty.abiSize(zcu)); |
| 3346 | | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); |
| 3546 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3547 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3347 | 3548 | switch (opt_repr) { |
| 3348 | 3549 | .opv_null => { |
| 3349 | 3550 | try wip_nav.abbrevCode(.generated_field); |
| 3350 | 3551 | try wip_nav.strp("null"); |
| 3351 | 3552 | try wip_nav.refType(.null); |
| 3352 | | try uleb128(diw, 0); |
| 3553 | try diw.writeUleb128(0); |
| 3353 | 3554 | }, |
| 3354 | 3555 | .unpacked, .error_set, .pointer => { |
| 3355 | 3556 | try wip_nav.abbrevCode(.tagged_union); |
| ... | ... | @@ -3357,7 +3558,7 @@ fn updateLazyType( |
| 3357 | 3558 | .debug_info, |
| 3358 | 3559 | wip_nav.unit, |
| 3359 | 3560 | wip_nav.entry, |
| 3360 | | @intCast(wip_nav.debug_info.items.len + dwarf.sectionOffsetBytes()), |
| 3561 | @intCast(diw.end + dwarf.sectionOffsetBytes()), |
| 3361 | 3562 | ); |
| 3362 | 3563 | { |
| 3363 | 3564 | try wip_nav.abbrevCode(.generated_field); |
| ... | ... | @@ -3366,7 +3567,7 @@ fn updateLazyType( |
| 3366 | 3567 | .opv_null => unreachable, |
| 3367 | 3568 | .unpacked => { |
| 3368 | 3569 | try wip_nav.refType(.bool); |
| 3369 | | try uleb128(diw, if (opt_child_type.hasRuntimeBits(zcu)) |
| 3570 | try diw.writeUleb128(if (opt_child_type.hasRuntimeBits(zcu)) |
| 3370 | 3571 | opt_child_type.abiSize(zcu) |
| 3371 | 3572 | else |
| 3372 | 3573 | 0); |
| ... | ... | @@ -3376,37 +3577,37 @@ fn updateLazyType( |
| 3376 | 3577 | .signedness = .unsigned, |
| 3377 | 3578 | .bits = zcu.errorSetBits(), |
| 3378 | 3579 | } }))); |
| 3379 | | try uleb128(diw, 0); |
| 3580 | try diw.writeUleb128(0); |
| 3380 | 3581 | }, |
| 3381 | 3582 | .pointer => { |
| 3382 | 3583 | try wip_nav.refType(.usize); |
| 3383 | | try uleb128(diw, 0); |
| 3584 | try diw.writeUleb128(0); |
| 3384 | 3585 | }, |
| 3385 | 3586 | } |
| 3386 | 3587 | |
| 3387 | 3588 | try wip_nav.abbrevCode(.unsigned_tagged_union_field); |
| 3388 | | try uleb128(diw, 0); |
| 3589 | try diw.writeUleb128(0); |
| 3389 | 3590 | { |
| 3390 | 3591 | try wip_nav.abbrevCode(.generated_field); |
| 3391 | 3592 | try wip_nav.strp("null"); |
| 3392 | 3593 | try wip_nav.refType(.null); |
| 3393 | | try uleb128(diw, 0); |
| 3594 | try diw.writeUleb128(0); |
| 3394 | 3595 | } |
| 3395 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3596 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3396 | 3597 | |
| 3397 | 3598 | try wip_nav.abbrevCode(.tagged_union_default_field); |
| 3398 | 3599 | { |
| 3399 | 3600 | try wip_nav.abbrevCode(.generated_field); |
| 3400 | 3601 | try wip_nav.strp("?"); |
| 3401 | 3602 | try wip_nav.refType(opt_child_type); |
| 3402 | | try uleb128(diw, 0); |
| 3603 | try diw.writeUleb128(0); |
| 3403 | 3604 | } |
| 3404 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3605 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3405 | 3606 | } |
| 3406 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3607 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3407 | 3608 | }, |
| 3408 | 3609 | } |
| 3409 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3610 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3410 | 3611 | }, |
| 3411 | 3612 | .anyframe_type => unreachable, |
| 3412 | 3613 | .error_union_type => |error_union_type| { |
| ... | ... | @@ -3425,11 +3626,11 @@ fn updateLazyType( |
| 3425 | 3626 | if (error_union_type.error_set_type != .generic_poison_type and |
| 3426 | 3627 | error_union_type.payload_type != .generic_poison_type) |
| 3427 | 3628 | { |
| 3428 | | try uleb128(diw, ty.abiSize(zcu)); |
| 3429 | | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); |
| 3629 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3630 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3430 | 3631 | } else { |
| 3431 | | try uleb128(diw, 0); |
| 3432 | | try uleb128(diw, 1); |
| 3632 | try diw.writeUleb128(0); |
| 3633 | try diw.writeUleb128(1); |
| 3433 | 3634 | } |
| 3434 | 3635 | { |
| 3435 | 3636 | try wip_nav.abbrevCode(.tagged_union); |
| ... | ... | @@ -3437,7 +3638,7 @@ fn updateLazyType( |
| 3437 | 3638 | .debug_info, |
| 3438 | 3639 | wip_nav.unit, |
| 3439 | 3640 | wip_nav.entry, |
| 3440 | | @intCast(wip_nav.debug_info.items.len + dwarf.sectionOffsetBytes()), |
| 3641 | @intCast(diw.end + dwarf.sectionOffsetBytes()), |
| 3441 | 3642 | ); |
| 3442 | 3643 | { |
| 3443 | 3644 | try wip_nav.abbrevCode(.generated_field); |
| ... | ... | @@ -3446,30 +3647,30 @@ fn updateLazyType( |
| 3446 | 3647 | .signedness = .unsigned, |
| 3447 | 3648 | .bits = zcu.errorSetBits(), |
| 3448 | 3649 | } }))); |
| 3449 | | try uleb128(diw, error_union_error_set_offset); |
| 3650 | try diw.writeUleb128(error_union_error_set_offset); |
| 3450 | 3651 | |
| 3451 | 3652 | try wip_nav.abbrevCode(.unsigned_tagged_union_field); |
| 3452 | | try uleb128(diw, 0); |
| 3653 | try diw.writeUleb128(0); |
| 3453 | 3654 | { |
| 3454 | 3655 | try wip_nav.abbrevCode(.generated_field); |
| 3455 | 3656 | try wip_nav.strp("value"); |
| 3456 | 3657 | try wip_nav.refType(error_union_payload_type); |
| 3457 | | try uleb128(diw, error_union_payload_offset); |
| 3658 | try diw.writeUleb128(error_union_payload_offset); |
| 3458 | 3659 | } |
| 3459 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3660 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3460 | 3661 | |
| 3461 | 3662 | try wip_nav.abbrevCode(.tagged_union_default_field); |
| 3462 | 3663 | { |
| 3463 | 3664 | try wip_nav.abbrevCode(.generated_field); |
| 3464 | 3665 | try wip_nav.strp("error"); |
| 3465 | 3666 | try wip_nav.refType(error_union_error_set_type); |
| 3466 | | try uleb128(diw, error_union_error_set_offset); |
| 3667 | try diw.writeUleb128(error_union_error_set_offset); |
| 3467 | 3668 | } |
| 3468 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3669 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3469 | 3670 | } |
| 3470 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3671 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3471 | 3672 | } |
| 3472 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3673 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3473 | 3674 | }, |
| 3474 | 3675 | .simple_type => |simple_type| switch (simple_type) { |
| 3475 | 3676 | .f16, |
| ... | ... | @@ -3503,9 +3704,9 @@ fn updateLazyType( |
| 3503 | 3704 | DW.ATE.unsigned |
| 3504 | 3705 | else |
| 3505 | 3706 | unreachable); |
| 3506 | | try uleb128(diw, ty.bitSize(zcu)); |
| 3507 | | try uleb128(diw, ty.abiSize(zcu)); |
| 3508 | | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); |
| 3707 | try diw.writeUleb128(ty.bitSize(zcu)); |
| 3708 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3709 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3509 | 3710 | }, |
| 3510 | 3711 | .anyopaque, |
| 3511 | 3712 | .void, |
| ... | ... | @@ -3535,8 +3736,8 @@ fn updateLazyType( |
| 3535 | 3736 | } else { |
| 3536 | 3737 | try wip_nav.abbrevCode(.generated_struct_type); |
| 3537 | 3738 | try wip_nav.strp(name); |
| 3538 | | try uleb128(diw, ty.abiSize(zcu)); |
| 3539 | | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); |
| 3739 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3740 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3540 | 3741 | var field_byte_offset: u64 = 0; |
| 3541 | 3742 | for (0..tuple_type.types.len) |field_index| { |
| 3542 | 3743 | const comptime_value = tuple_type.values.get(ip)[field_index]; |
| ... | ... | @@ -3565,8 +3766,8 @@ fn updateLazyType( |
| 3565 | 3766 | if (comptime_value == .none) { |
| 3566 | 3767 | const field_align = field_type.abiAlignment(zcu); |
| 3567 | 3768 | field_byte_offset = field_align.forward(field_byte_offset); |
| 3568 | | try uleb128(diw, field_byte_offset); |
| 3569 | | try uleb128(diw, field_type.abiAlignment(zcu).toByteUnits().?); |
| 3769 | try diw.writeUleb128(field_byte_offset); |
| 3770 | try diw.writeUleb128(field_type.abiAlignment(zcu).toByteUnits().?); |
| 3570 | 3771 | field_byte_offset += field_type.abiSize(zcu); |
| 3571 | 3772 | } |
| 3572 | 3773 | if (has_comptime_state) |
| ... | ... | @@ -3574,7 +3775,7 @@ fn updateLazyType( |
| 3574 | 3775 | else if (has_runtime_bits) |
| 3575 | 3776 | try wip_nav.blockValue(src_loc, .fromInterned(comptime_value)); |
| 3576 | 3777 | } |
| 3577 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3778 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3578 | 3779 | }, |
| 3579 | 3780 | .enum_type => { |
| 3580 | 3781 | const loaded_enum = ip.loadEnumType(type_index); |
| ... | ... | @@ -3589,7 +3790,7 @@ fn updateLazyType( |
| 3589 | 3790 | }, field_index); |
| 3590 | 3791 | try wip_nav.strp(loaded_enum.names.get(ip)[field_index].toSlice(ip)); |
| 3591 | 3792 | } |
| 3592 | | if (loaded_enum.names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3793 | if (loaded_enum.names.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3593 | 3794 | }, |
| 3594 | 3795 | .func_type => |func_type| { |
| 3595 | 3796 | const is_nullary = func_type.param_types.len == 0 and !func_type.is_var_args; |
| ... | ... | @@ -3665,7 +3866,7 @@ fn updateLazyType( |
| 3665 | 3866 | try wip_nav.refType(.fromInterned(func_type.param_types.get(ip)[param_index])); |
| 3666 | 3867 | } |
| 3667 | 3868 | if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args); |
| 3668 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3869 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3669 | 3870 | } |
| 3670 | 3871 | }, |
| 3671 | 3872 | .error_set_type => |error_set_type| { |
| ... | ... | @@ -3678,10 +3879,10 @@ fn updateLazyType( |
| 3678 | 3879 | for (0..error_set_type.names.len) |field_index| { |
| 3679 | 3880 | const field_name = error_set_type.names.get(ip)[field_index]; |
| 3680 | 3881 | try wip_nav.abbrevCode(.unsigned_enum_field); |
| 3681 | | try uleb128(diw, ip.getErrorValueIfExists(field_name).?); |
| 3882 | try diw.writeUleb128(ip.getErrorValueIfExists(field_name).?); |
| 3682 | 3883 | try wip_nav.strp(field_name.toSlice(ip)); |
| 3683 | 3884 | } |
| 3684 | | if (error_set_type.names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3885 | if (error_set_type.names.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3685 | 3886 | }, |
| 3686 | 3887 | .inferred_error_set_type => |func| { |
| 3687 | 3888 | try wip_nav.abbrevCode(.inferred_error_set_type); |
| ... | ... | @@ -3713,7 +3914,7 @@ fn updateLazyType( |
| 3713 | 3914 | .memoized_call, |
| 3714 | 3915 | => unreachable, |
| 3715 | 3916 | } |
| 3716 | | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items); |
| 3917 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.getWritten()); |
| 3717 | 3918 | } |
| 3718 | 3919 | |
| 3719 | 3920 | fn updateLazyValue( |
| ... | ... | @@ -3722,7 +3923,7 @@ fn updateLazyValue( |
| 3722 | 3923 | src_loc: Zcu.LazySrcLoc, |
| 3723 | 3924 | value_index: InternPool.Index, |
| 3724 | 3925 | pending_lazy: *WipNav.PendingLazy, |
| 3725 | | ) UpdateError!void { |
| 3926 | ) (UpdateError || Writer.Error)!void { |
| 3726 | 3927 | const zcu = pt.zcu; |
| 3727 | 3928 | const ip = &zcu.intern_pool; |
| 3728 | 3929 | assert(ip.typeOf(value_index) != .type_type); |
| ... | ... | @@ -3741,10 +3942,10 @@ fn updateLazyValue( |
| 3741 | 3942 | .func_high_pc = undefined, |
| 3742 | 3943 | .blocks = undefined, |
| 3743 | 3944 | .cfi = undefined, |
| 3744 | | .debug_frame = .empty, |
| 3745 | | .debug_info = .empty, |
| 3746 | | .debug_line = .empty, |
| 3747 | | .debug_loclists = .empty, |
| 3945 | .debug_frame = .init(dwarf.gpa), |
| 3946 | .debug_info = .init(dwarf.gpa), |
| 3947 | .debug_line = .init(dwarf.gpa), |
| 3948 | .debug_loclists = .init(dwarf.gpa), |
| 3748 | 3949 | .pending_lazy = pending_lazy.*, |
| 3749 | 3950 | }; |
| 3750 | 3951 | defer { |
| ... | ... | @@ -3752,7 +3953,7 @@ fn updateLazyValue( |
| 3752 | 3953 | wip_nav.pending_lazy = .empty; |
| 3753 | 3954 | wip_nav.deinit(); |
| 3754 | 3955 | } |
| 3755 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 3956 | const diw = &wip_nav.debug_info.writer; |
| 3756 | 3957 | var big_int_space: Value.BigIntSpace = undefined; |
| 3757 | 3958 | switch (ip.indexToKey(value_index)) { |
| 3758 | 3959 | .int_type, |
| ... | ... | @@ -3790,20 +3991,21 @@ fn updateLazyValue( |
| 3790 | 3991 | .err => |err| { |
| 3791 | 3992 | try wip_nav.abbrevCode(.udata_comptime_value); |
| 3792 | 3993 | try wip_nav.refType(.fromInterned(err.ty)); |
| 3793 | | try uleb128(diw, try pt.getErrorValue(err.name)); |
| 3994 | try diw.writeUleb128(try pt.getErrorValue(err.name)); |
| 3794 | 3995 | }, |
| 3795 | 3996 | .error_union => |error_union| { |
| 3796 | 3997 | try wip_nav.abbrevCode(.aggregate_comptime_value); |
| 3797 | | const err_abi_size = std.math.divCeil(u17, zcu.errorSetBits(), 8) catch unreachable; |
| 3798 | | const err_value = switch (error_union.val) { |
| 3998 | var err_buf: [4]u8 = undefined; |
| 3999 | const err_bytes = err_buf[0 .. std.math.divCeil(u17, zcu.errorSetBits(), 8) catch unreachable]; |
| 4000 | dwarf.writeInt(err_bytes, switch (error_union.val) { |
| 3799 | 4001 | .err_name => |err_name| try pt.getErrorValue(err_name), |
| 3800 | 4002 | .payload => 0, |
| 3801 | | }; |
| 4003 | }); |
| 3802 | 4004 | { |
| 3803 | 4005 | try wip_nav.abbrevCode(.comptime_value_field_runtime_bits); |
| 3804 | 4006 | try wip_nav.strp("is_error"); |
| 3805 | | try uleb128(diw, err_abi_size); |
| 3806 | | dwarf.writeInt(try wip_nav.debug_info.addManyAsSlice(dwarf.gpa, err_abi_size), err_value); |
| 4007 | try diw.writeUleb128(err_bytes.len); |
| 4008 | try diw.writeAll(err_bytes); |
| 3807 | 4009 | } |
| 3808 | 4010 | payload_field: switch (error_union.val) { |
| 3809 | 4011 | .err_name => {}, |
| ... | ... | @@ -3827,18 +4029,11 @@ fn updateLazyValue( |
| 3827 | 4029 | { |
| 3828 | 4030 | try wip_nav.abbrevCode(.comptime_value_field_runtime_bits); |
| 3829 | 4031 | try wip_nav.strp("error"); |
| 3830 | | try uleb128(diw, err_abi_size); |
| 3831 | | dwarf.writeInt(try wip_nav.debug_info.addManyAsSlice(dwarf.gpa, err_abi_size), err_value); |
| 3832 | | } |
| 3833 | | switch (error_union.val) { |
| 3834 | | .err_name => {}, |
| 3835 | | .payload => |payload| { |
| 3836 | | _ = payload; |
| 3837 | | try wip_nav.abbrevCode(.aggregate_comptime_value); |
| 3838 | | }, |
| 4032 | try diw.writeUleb128(err_bytes.len); |
| 4033 | try diw.writeAll(err_bytes); |
| 3839 | 4034 | } |
| 3840 | 4035 | try wip_nav.refType(.fromInterned(error_union.ty)); |
| 3841 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 4036 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3842 | 4037 | }, |
| 3843 | 4038 | .enum_literal => |enum_literal| { |
| 3844 | 4039 | try wip_nav.abbrevCode(.string_comptime_value); |
| ... | ... | @@ -3871,7 +4066,7 @@ fn updateLazyValue( |
| 3871 | 4066 | }, |
| 3872 | 4067 | .f80 => |f80_val| { |
| 3873 | 4068 | try wip_nav.abbrevCode(.block_comptime_value); |
| 3874 | | try uleb128(diw, @divExact(80, 8)); |
| 4069 | try diw.writeUleb128(@divExact(80, 8)); |
| 3875 | 4070 | try diw.writeInt(u80, @bitCast(f80_val), dwarf.endian); |
| 3876 | 4071 | }, |
| 3877 | 4072 | .f128 => |f128_val| { |
| ... | ... | @@ -3893,14 +4088,14 @@ fn updateLazyValue( |
| 3893 | 4088 | const uav_ty: Type = .fromInterned(ip.typeOf(uav.val)); |
| 3894 | 4089 | if (try uav_ty.onePossibleValue(pt)) |_| { |
| 3895 | 4090 | try wip_nav.abbrevCode(.udata_comptime_value); |
| 3896 | | try uleb128(diw, ip.indexToKey(uav.orig_ty).ptr_type.flags.alignment.toByteUnits() orelse |
| 4091 | try diw.writeUleb128(ip.indexToKey(uav.orig_ty).ptr_type.flags.alignment.toByteUnits() orelse |
| 3897 | 4092 | uav_ty.abiAlignment(zcu).toByteUnits().?); |
| 3898 | 4093 | break :location; |
| 3899 | 4094 | } else break try wip_nav.getValueEntry(.fromInterned(uav.val)); |
| 3900 | 4095 | }, |
| 3901 | 4096 | .int => { |
| 3902 | 4097 | try wip_nav.abbrevCode(.udata_comptime_value); |
| 3903 | | try uleb128(diw, byte_offset); |
| 4098 | try diw.writeUleb128(byte_offset); |
| 3904 | 4099 | break :location; |
| 3905 | 4100 | }, |
| 3906 | 4101 | .eu_payload => |eu_ptr| { |
| ... | ... | @@ -3939,7 +4134,7 @@ fn updateLazyValue( |
| 3939 | 4134 | try wip_nav.strp("len"); |
| 3940 | 4135 | try wip_nav.blockValue(src_loc, .fromInterned(slice.len)); |
| 3941 | 4136 | } |
| 3942 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 4137 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3943 | 4138 | }, |
| 3944 | 4139 | .opt => |opt| { |
| 3945 | 4140 | const opt_child_type: Type = .fromInterned(ip.indexToKey(opt.ty).opt_type); |
| ... | ... | @@ -3949,7 +4144,7 @@ fn updateLazyValue( |
| 3949 | 4144 | try wip_nav.abbrevCode(.comptime_value_field_runtime_bits); |
| 3950 | 4145 | try wip_nav.strp("has_value"); |
| 3951 | 4146 | switch (optRepr(opt_child_type, zcu)) { |
| 3952 | | .opv_null => try uleb128(diw, 0), |
| 4147 | .opv_null => try diw.writeUleb128(0), |
| 3953 | 4148 | .unpacked => try wip_nav.blockValue(src_loc, .makeBool(opt.val != .none)), |
| 3954 | 4149 | .error_set => try wip_nav.blockValue(src_loc, .fromInterned(value_index)), |
| 3955 | 4150 | .pointer => if (opt_child_type.comptimeOnly(zcu)) { |
| ... | ... | @@ -3959,7 +4154,7 @@ fn updateLazyValue( |
| 3959 | 4154 | .none => 0, |
| 3960 | 4155 | else => opt_child_type.ptrAlignment(zcu).toByteUnits().?, |
| 3961 | 4156 | }); |
| 3962 | | try uleb128(diw, bytes.len); |
| 4157 | try diw.writeUleb128(bytes.len); |
| 3963 | 4158 | try diw.writeAll(bytes); |
| 3964 | 4159 | } else try wip_nav.blockValue(src_loc, .fromInterned(value_index)), |
| 3965 | 4160 | } |
| ... | ... | @@ -3979,7 +4174,7 @@ fn updateLazyValue( |
| 3979 | 4174 | else |
| 3980 | 4175 | try wip_nav.blockValue(src_loc, .fromInterned(opt.val)); |
| 3981 | 4176 | } |
| 3982 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 4177 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3983 | 4178 | }, |
| 3984 | 4179 | .aggregate => |aggregate| { |
| 3985 | 4180 | try wip_nav.abbrevCode(.aggregate_comptime_value); |
| ... | ... | @@ -4064,7 +4259,7 @@ fn updateLazyValue( |
| 4064 | 4259 | }, |
| 4065 | 4260 | else => unreachable, |
| 4066 | 4261 | } |
| 4067 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 4262 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4068 | 4263 | }, |
| 4069 | 4264 | .un => |un| { |
| 4070 | 4265 | try wip_nav.abbrevCode(.aggregate_comptime_value); |
| ... | ... | @@ -4089,11 +4284,11 @@ fn updateLazyValue( |
| 4089 | 4284 | else |
| 4090 | 4285 | try wip_nav.blockValue(src_loc, .fromInterned(un.val)); |
| 4091 | 4286 | } |
| 4092 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 4287 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4093 | 4288 | }, |
| 4094 | 4289 | .memoized_call => unreachable, // not a value |
| 4095 | 4290 | } |
| 4096 | | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items); |
| 4291 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.getWritten()); |
| 4097 | 4292 | } |
| 4098 | 4293 | |
| 4099 | 4294 | fn optRepr(opt_child_type: Type, zcu: *const Zcu) enum { |
| ... | ... | @@ -4113,7 +4308,21 @@ fn optRepr(opt_child_type: Type, zcu: *const Zcu) enum { |
| 4113 | 4308 | }; |
| 4114 | 4309 | } |
| 4115 | 4310 | |
| 4116 | | pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternPool.Index) UpdateError!void { |
| 4311 | pub fn updateContainerType( |
| 4312 | dwarf: *Dwarf, |
| 4313 | pt: Zcu.PerThread, |
| 4314 | type_index: InternPool.Index, |
| 4315 | ) UpdateError!void { |
| 4316 | return dwarf.updateContainerTypeWriterError(pt, type_index) catch |err| switch (err) { |
| 4317 | error.WriteFailed => error.OutOfMemory, |
| 4318 | else => |e| e, |
| 4319 | }; |
| 4320 | } |
| 4321 | fn updateContainerTypeWriterError( |
| 4322 | dwarf: *Dwarf, |
| 4323 | pt: Zcu.PerThread, |
| 4324 | type_index: InternPool.Index, |
| 4325 | ) (UpdateError || Writer.Error)!void { |
| 4117 | 4326 | const zcu = pt.zcu; |
| 4118 | 4327 | const ip = &zcu.intern_pool; |
| 4119 | 4328 | const ty: Type = .fromInterned(type_index); |
| ... | ... | @@ -4138,23 +4347,23 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4138 | 4347 | .func_high_pc = undefined, |
| 4139 | 4348 | .blocks = undefined, |
| 4140 | 4349 | .cfi = undefined, |
| 4141 | | .debug_frame = .empty, |
| 4142 | | .debug_info = .empty, |
| 4143 | | .debug_line = .empty, |
| 4144 | | .debug_loclists = .empty, |
| 4350 | .debug_frame = .init(dwarf.gpa), |
| 4351 | .debug_info = .init(dwarf.gpa), |
| 4352 | .debug_line = .init(dwarf.gpa), |
| 4353 | .debug_loclists = .init(dwarf.gpa), |
| 4145 | 4354 | .pending_lazy = .empty, |
| 4146 | 4355 | }; |
| 4147 | 4356 | defer wip_nav.deinit(); |
| 4148 | 4357 | |
| 4149 | 4358 | const loaded_struct = ip.loadStructType(type_index); |
| 4150 | 4359 | |
| 4151 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 4360 | const diw = &wip_nav.debug_info.writer; |
| 4152 | 4361 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .empty_file else .file); |
| 4153 | | try uleb128(diw, file_gop.index); |
| 4362 | try diw.writeUleb128(file_gop.index); |
| 4154 | 4363 | try wip_nav.strp(loaded_struct.name.toSlice(ip)); |
| 4155 | 4364 | if (loaded_struct.field_types.len > 0) { |
| 4156 | | try uleb128(diw, ty.abiSize(zcu)); |
| 4157 | | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); |
| 4365 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 4366 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 4158 | 4367 | for (0..loaded_struct.field_types.len) |field_index| { |
| 4159 | 4368 | const is_comptime = loaded_struct.fieldIsComptime(ip, field_index); |
| 4160 | 4369 | const field_init = loaded_struct.fieldInit(ip, field_index); |
| ... | ... | @@ -4190,8 +4399,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4190 | 4399 | } |
| 4191 | 4400 | try wip_nav.refType(field_type); |
| 4192 | 4401 | if (!is_comptime) { |
| 4193 | | try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]); |
| 4194 | | try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse |
| 4402 | try diw.writeUleb128(loaded_struct.offsets.get(ip)[field_index]); |
| 4403 | try diw.writeUleb128(loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse |
| 4195 | 4404 | field_type.abiAlignment(zcu).toByteUnits().?); |
| 4196 | 4405 | } |
| 4197 | 4406 | if (has_comptime_state) |
| ... | ... | @@ -4199,10 +4408,10 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4199 | 4408 | else if (has_runtime_bits) |
| 4200 | 4409 | try wip_nav.blockValue(ty_src_loc, .fromInterned(field_init)); |
| 4201 | 4410 | } |
| 4202 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 4411 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4203 | 4412 | } |
| 4204 | 4413 | |
| 4205 | | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items); |
| 4414 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.getWritten()); |
| 4206 | 4415 | try wip_nav.updateLazy(ty_src_loc); |
| 4207 | 4416 | } else { |
| 4208 | 4417 | { |
| ... | ... | @@ -4239,14 +4448,14 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4239 | 4448 | .func_high_pc = undefined, |
| 4240 | 4449 | .blocks = undefined, |
| 4241 | 4450 | .cfi = undefined, |
| 4242 | | .debug_frame = .empty, |
| 4243 | | .debug_info = .empty, |
| 4244 | | .debug_line = .empty, |
| 4245 | | .debug_loclists = .empty, |
| 4451 | .debug_frame = .init(dwarf.gpa), |
| 4452 | .debug_info = .init(dwarf.gpa), |
| 4453 | .debug_line = .init(dwarf.gpa), |
| 4454 | .debug_loclists = .init(dwarf.gpa), |
| 4246 | 4455 | .pending_lazy = .empty, |
| 4247 | 4456 | }; |
| 4248 | 4457 | defer wip_nav.deinit(); |
| 4249 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 4458 | const diw = &wip_nav.debug_info.writer; |
| 4250 | 4459 | const name = try std.fmt.allocPrint(dwarf.gpa, "{f}", .{ty.fmt(pt)}); |
| 4251 | 4460 | defer dwarf.gpa.free(name); |
| 4252 | 4461 | |
| ... | ... | @@ -4256,11 +4465,11 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4256 | 4465 | switch (loaded_struct.layout) { |
| 4257 | 4466 | .auto, .@"extern" => { |
| 4258 | 4467 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .empty_struct_type else .struct_type); |
| 4259 | | try uleb128(diw, file_gop.index); |
| 4468 | try diw.writeUleb128(file_gop.index); |
| 4260 | 4469 | try wip_nav.strp(name); |
| 4261 | 4470 | if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else { |
| 4262 | | try uleb128(diw, ty.abiSize(zcu)); |
| 4263 | | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); |
| 4471 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 4472 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 4264 | 4473 | for (0..loaded_struct.field_types.len) |field_index| { |
| 4265 | 4474 | const is_comptime = loaded_struct.fieldIsComptime(ip, field_index); |
| 4266 | 4475 | const field_init = loaded_struct.fieldInit(ip, field_index); |
| ... | ... | @@ -4296,8 +4505,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4296 | 4505 | } |
| 4297 | 4506 | try wip_nav.refType(field_type); |
| 4298 | 4507 | if (!is_comptime) { |
| 4299 | | try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]); |
| 4300 | | try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse |
| 4508 | try diw.writeUleb128(loaded_struct.offsets.get(ip)[field_index]); |
| 4509 | try diw.writeUleb128(loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse |
| 4301 | 4510 | field_type.abiAlignment(zcu).toByteUnits().?); |
| 4302 | 4511 | } |
| 4303 | 4512 | if (has_comptime_state) |
| ... | ... | @@ -4305,12 +4514,12 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4305 | 4514 | else if (has_runtime_bits) |
| 4306 | 4515 | try wip_nav.blockValue(ty_src_loc, .fromInterned(field_init)); |
| 4307 | 4516 | } |
| 4308 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 4517 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4309 | 4518 | } |
| 4310 | 4519 | }, |
| 4311 | 4520 | .@"packed" => { |
| 4312 | 4521 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len > 0) .packed_struct_type else .empty_packed_struct_type); |
| 4313 | | try uleb128(diw, file_gop.index); |
| 4522 | try diw.writeUleb128(file_gop.index); |
| 4314 | 4523 | try wip_nav.strp(name); |
| 4315 | 4524 | try wip_nav.refType(.fromInterned(loaded_struct.backingIntTypeUnordered(ip))); |
| 4316 | 4525 | var field_bit_offset: u16 = 0; |
| ... | ... | @@ -4319,17 +4528,17 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4319 | 4528 | try wip_nav.strp(loaded_struct.fieldName(ip, field_index).unwrap().?.toSlice(ip)); |
| 4320 | 4529 | const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]); |
| 4321 | 4530 | try wip_nav.refType(field_type); |
| 4322 | | try uleb128(diw, field_bit_offset); |
| 4531 | try diw.writeUleb128(field_bit_offset); |
| 4323 | 4532 | field_bit_offset += @intCast(field_type.bitSize(zcu)); |
| 4324 | 4533 | } |
| 4325 | | if (loaded_struct.field_types.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 4534 | if (loaded_struct.field_types.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4326 | 4535 | }, |
| 4327 | 4536 | } |
| 4328 | 4537 | }, |
| 4329 | 4538 | .enum_type => { |
| 4330 | 4539 | const loaded_enum = ip.loadEnumType(type_index); |
| 4331 | 4540 | try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .enum_type else .empty_enum_type); |
| 4332 | | try uleb128(diw, file_gop.index); |
| 4541 | try diw.writeUleb128(file_gop.index); |
| 4333 | 4542 | try wip_nav.strp(name); |
| 4334 | 4543 | try wip_nav.refType(.fromInterned(loaded_enum.tag_ty)); |
| 4335 | 4544 | for (0..loaded_enum.names.len) |field_index| { |
| ... | ... | @@ -4340,16 +4549,16 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4340 | 4549 | }, field_index); |
| 4341 | 4550 | try wip_nav.strp(loaded_enum.names.get(ip)[field_index].toSlice(ip)); |
| 4342 | 4551 | } |
| 4343 | | if (loaded_enum.names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 4552 | if (loaded_enum.names.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4344 | 4553 | }, |
| 4345 | 4554 | .union_type => { |
| 4346 | 4555 | const loaded_union = ip.loadUnionType(type_index); |
| 4347 | 4556 | try wip_nav.abbrevCode(if (loaded_union.field_types.len > 0) .union_type else .empty_union_type); |
| 4348 | | try uleb128(diw, file_gop.index); |
| 4557 | try diw.writeUleb128(file_gop.index); |
| 4349 | 4558 | try wip_nav.strp(name); |
| 4350 | 4559 | const union_layout = Type.getUnionLayout(loaded_union, zcu); |
| 4351 | | try uleb128(diw, union_layout.abi_size); |
| 4352 | | try uleb128(diw, union_layout.abi_align.toByteUnits().?); |
| 4560 | try diw.writeUleb128(union_layout.abi_size); |
| 4561 | try diw.writeUleb128(union_layout.abi_align.toByteUnits().?); |
| 4353 | 4562 | const loaded_tag = loaded_union.loadTagType(ip); |
| 4354 | 4563 | if (loaded_union.hasTag(ip)) { |
| 4355 | 4564 | try wip_nav.abbrevCode(.tagged_union); |
| ... | ... | @@ -4357,13 +4566,13 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4357 | 4566 | .debug_info, |
| 4358 | 4567 | wip_nav.unit, |
| 4359 | 4568 | wip_nav.entry, |
| 4360 | | @intCast(wip_nav.debug_info.items.len + dwarf.sectionOffsetBytes()), |
| 4569 | @intCast(diw.end + dwarf.sectionOffsetBytes()), |
| 4361 | 4570 | ); |
| 4362 | 4571 | { |
| 4363 | 4572 | try wip_nav.abbrevCode(.generated_field); |
| 4364 | 4573 | try wip_nav.strp("tag"); |
| 4365 | 4574 | try wip_nav.refType(.fromInterned(loaded_union.enum_tag_ty)); |
| 4366 | | try uleb128(diw, union_layout.tagOffset()); |
| 4575 | try diw.writeUleb128(union_layout.tagOffset()); |
| 4367 | 4576 | |
| 4368 | 4577 | for (0..loaded_union.field_types.len) |field_index| { |
| 4369 | 4578 | try wip_nav.enumConstValue(loaded_tag, .{ |
| ... | ... | @@ -4376,34 +4585,34 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4376 | 4585 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); |
| 4377 | 4586 | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 4378 | 4587 | try wip_nav.refType(field_type); |
| 4379 | | try uleb128(diw, union_layout.payloadOffset()); |
| 4380 | | try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse |
| 4588 | try diw.writeUleb128(union_layout.payloadOffset()); |
| 4589 | try diw.writeUleb128(loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse |
| 4381 | 4590 | if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?); |
| 4382 | 4591 | } |
| 4383 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 4592 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4384 | 4593 | } |
| 4385 | 4594 | } |
| 4386 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 4595 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4387 | 4596 | } else for (0..loaded_union.field_types.len) |field_index| { |
| 4388 | 4597 | try wip_nav.abbrevCode(.untagged_union_field); |
| 4389 | 4598 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); |
| 4390 | 4599 | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 4391 | 4600 | try wip_nav.refType(field_type); |
| 4392 | | try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse |
| 4601 | try diw.writeUleb128(loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse |
| 4393 | 4602 | field_type.abiAlignment(zcu).toByteUnits().?); |
| 4394 | 4603 | } |
| 4395 | | if (loaded_union.field_types.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 4604 | if (loaded_union.field_types.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4396 | 4605 | }, |
| 4397 | 4606 | .opaque_type => { |
| 4398 | 4607 | try wip_nav.abbrevCode(.empty_struct_type); |
| 4399 | | try uleb128(diw, file_gop.index); |
| 4608 | try diw.writeUleb128(file_gop.index); |
| 4400 | 4609 | try wip_nav.strp(name); |
| 4401 | 4610 | try diw.writeByte(@intFromBool(true)); |
| 4402 | 4611 | }, |
| 4403 | 4612 | else => unreachable, |
| 4404 | 4613 | } |
| 4405 | | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items); |
| 4406 | | try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.items); |
| 4614 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.getWritten()); |
| 4615 | try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.getWritten()); |
| 4407 | 4616 | try wip_nav.updateLazy(ty_src_loc); |
| 4408 | 4617 | } |
| 4409 | 4618 | } |
| ... | ... | @@ -4436,24 +4645,33 @@ pub fn freeNav(dwarf: *Dwarf, nav_index: InternPool.Nav.Index) void { |
| 4436 | 4645 | _ = nav_index; |
| 4437 | 4646 | } |
| 4438 | 4647 | |
| 4439 | | fn refAbbrevCode(dwarf: *Dwarf, abbrev_code: AbbrevCode) UpdateError!@typeInfo(AbbrevCode).@"enum".tag_type { |
| 4648 | fn refAbbrevCode( |
| 4649 | dwarf: *Dwarf, |
| 4650 | abbrev_code: AbbrevCode, |
| 4651 | ) (UpdateError || Writer.Error)!@typeInfo(AbbrevCode).@"enum".tag_type { |
| 4440 | 4652 | assert(abbrev_code != .null); |
| 4441 | 4653 | const entry: Entry.Index = @enumFromInt(@intFromEnum(abbrev_code)); |
| 4442 | 4654 | if (dwarf.debug_abbrev.section.getUnit(DebugAbbrev.unit).getEntry(entry).len > 0) return @intFromEnum(abbrev_code); |
| 4443 | | var debug_abbrev: std.ArrayList(u8) = .init(dwarf.gpa); |
| 4444 | | defer debug_abbrev.deinit(); |
| 4445 | | const daw = debug_abbrev.writer(); |
| 4655 | var debug_abbrev_aw: Writer.Allocating = .init(dwarf.gpa); |
| 4656 | defer debug_abbrev_aw.deinit(); |
| 4657 | const daw = &debug_abbrev_aw.writer; |
| 4446 | 4658 | const abbrev = AbbrevCode.abbrevs.get(abbrev_code); |
| 4447 | | try uleb128(daw, @intFromEnum(abbrev_code)); |
| 4448 | | try uleb128(daw, @intFromEnum(abbrev.tag)); |
| 4659 | try daw.writeUleb128(@intFromEnum(abbrev_code)); |
| 4660 | try daw.writeUleb128(@intFromEnum(abbrev.tag)); |
| 4449 | 4661 | try daw.writeByte(if (abbrev.children) DW.CHILDREN.yes else DW.CHILDREN.no); |
| 4450 | | for (abbrev.attrs) |*attr| inline for (attr) |info| try uleb128(daw, @intFromEnum(info)); |
| 4451 | | for (0..2) |_| try uleb128(daw, 0); |
| 4452 | | try dwarf.debug_abbrev.section.replaceEntry(DebugAbbrev.unit, entry, dwarf, debug_abbrev.items); |
| 4662 | for (abbrev.attrs) |*attr| inline for (attr) |info| try daw.writeUleb128(@intFromEnum(info)); |
| 4663 | for (0..2) |_| try daw.writeUleb128(0); |
| 4664 | try dwarf.debug_abbrev.section.replaceEntry(DebugAbbrev.unit, entry, dwarf, debug_abbrev_aw.getWritten()); |
| 4453 | 4665 | return @intFromEnum(abbrev_code); |
| 4454 | 4666 | } |
| 4455 | 4667 | |
| 4456 | 4668 | pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4669 | return dwarf.flushWriterError(pt) catch |err| switch (err) { |
| 4670 | error.WriteFailed => error.OutOfMemory, |
| 4671 | else => |e| e, |
| 4672 | }; |
| 4673 | } |
| 4674 | fn flushWriterError(dwarf: *Dwarf, pt: Zcu.PerThread) (FlushError || Writer.Error)!void { |
| 4457 | 4675 | const zcu = pt.zcu; |
| 4458 | 4676 | const ip = &zcu.intern_pool; |
| 4459 | 4677 | |
| ... | ... | @@ -4471,14 +4689,14 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4471 | 4689 | .func_high_pc = undefined, |
| 4472 | 4690 | .blocks = undefined, |
| 4473 | 4691 | .cfi = undefined, |
| 4474 | | .debug_frame = .empty, |
| 4475 | | .debug_info = .empty, |
| 4476 | | .debug_line = .empty, |
| 4477 | | .debug_loclists = .empty, |
| 4692 | .debug_frame = .init(dwarf.gpa), |
| 4693 | .debug_info = .init(dwarf.gpa), |
| 4694 | .debug_line = .init(dwarf.gpa), |
| 4695 | .debug_loclists = .init(dwarf.gpa), |
| 4478 | 4696 | .pending_lazy = .empty, |
| 4479 | 4697 | }; |
| 4480 | 4698 | defer wip_nav.deinit(); |
| 4481 | | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 4699 | const diw = &wip_nav.debug_info.writer; |
| 4482 | 4700 | const global_error_set_names = ip.global_error_set.getNamesFromMainThread(); |
| 4483 | 4701 | try wip_nav.abbrevCode(if (global_error_set_names.len == 0) .generated_empty_enum_type else .generated_enum_type); |
| 4484 | 4702 | try wip_nav.strp("anyerror"); |
| ... | ... | @@ -4488,11 +4706,11 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4488 | 4706 | } }))); |
| 4489 | 4707 | for (global_error_set_names, 1..) |name, value| { |
| 4490 | 4708 | try wip_nav.abbrevCode(.unsigned_enum_field); |
| 4491 | | try uleb128(diw, value); |
| 4709 | try diw.writeUleb128(value); |
| 4492 | 4710 | try wip_nav.strp(name.toSlice(ip)); |
| 4493 | 4711 | } |
| 4494 | | if (global_error_set_names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 4495 | | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items); |
| 4712 | if (global_error_set_names.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4713 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.getWritten()); |
| 4496 | 4714 | try wip_nav.updateLazy(.unneeded); |
| 4497 | 4715 | } |
| 4498 | 4716 | |
| ... | ... | @@ -4502,36 +4720,38 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4502 | 4720 | mod_info.root_dir_path = try dwarf.debug_line_str.addString(dwarf, root_dir_path); |
| 4503 | 4721 | } |
| 4504 | 4722 | |
| 4505 | | var header: std.ArrayList(u8) = .init(dwarf.gpa); |
| 4506 | | defer header.deinit(); |
| 4723 | var header_aw: Writer.Allocating = .init(dwarf.gpa); |
| 4724 | defer header_aw.deinit(); |
| 4725 | const hw = &header_aw.writer; |
| 4507 | 4726 | if (dwarf.debug_aranges.section.dirty) { |
| 4508 | 4727 | for (dwarf.debug_aranges.section.units.items, 0..) |*unit_ptr, unit_index| { |
| 4509 | 4728 | const unit: Unit.Index = @enumFromInt(unit_index); |
| 4510 | 4729 | unit_ptr.clear(); |
| 4511 | 4730 | try unit_ptr.cross_section_relocs.ensureTotalCapacity(dwarf.gpa, 1); |
| 4512 | | header.clearRetainingCapacity(); |
| 4513 | | try header.ensureTotalCapacity(unit_ptr.header_len); |
| 4731 | header_aw.clearRetainingCapacity(); |
| 4732 | try header_aw.ensureTotalCapacity(unit_ptr.header_len); |
| 4514 | 4733 | const unit_len = (if (unit_ptr.next.unwrap()) |next_unit| |
| 4515 | 4734 | dwarf.debug_aranges.section.getUnit(next_unit).off |
| 4516 | 4735 | else |
| 4517 | 4736 | dwarf.debug_aranges.section.len) - unit_ptr.off - dwarf.unitLengthBytes(); |
| 4518 | 4737 | switch (dwarf.format) { |
| 4519 | | .@"32" => std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), @intCast(unit_len), dwarf.endian), |
| 4738 | .@"32" => hw.writeInt(u32, @intCast(unit_len), dwarf.endian) catch unreachable, |
| 4520 | 4739 | .@"64" => { |
| 4521 | | std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), std.math.maxInt(u32), dwarf.endian); |
| 4522 | | std.mem.writeInt(u64, header.addManyAsArrayAssumeCapacity(8), unit_len, dwarf.endian); |
| 4740 | hw.writeInt(u32, std.math.maxInt(u32), dwarf.endian) catch unreachable; |
| 4741 | hw.writeInt(u64, unit_len, dwarf.endian) catch unreachable; |
| 4523 | 4742 | }, |
| 4524 | 4743 | } |
| 4525 | | std.mem.writeInt(u16, header.addManyAsArrayAssumeCapacity(2), 2, dwarf.endian); |
| 4744 | hw.writeInt(u16, 2, dwarf.endian) catch unreachable; |
| 4526 | 4745 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4527 | | .source_off = @intCast(header.items.len), |
| 4746 | .source_off = @intCast(hw.end), |
| 4528 | 4747 | .target_sec = .debug_info, |
| 4529 | 4748 | .target_unit = unit, |
| 4530 | 4749 | }); |
| 4531 | | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 4532 | | header.appendSliceAssumeCapacity(&.{ @intFromEnum(dwarf.address_size), 0 }); |
| 4533 | | header.appendNTimesAssumeCapacity(0, unit_ptr.header_len - header.items.len); |
| 4534 | | try unit_ptr.replaceHeader(&dwarf.debug_aranges.section, dwarf, header.items); |
| 4750 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4751 | hw.writeByte(@intFromEnum(dwarf.address_size)) catch unreachable; |
| 4752 | hw.writeByte(0) catch unreachable; |
| 4753 | hw.splatByteAll(0, unit_ptr.header_len - hw.end) catch unreachable; |
| 4754 | try unit_ptr.replaceHeader(&dwarf.debug_aranges.section, dwarf, header_aw.getWritten()); |
| 4535 | 4755 | try unit_ptr.writeTrailer(&dwarf.debug_aranges.section, dwarf); |
| 4536 | 4756 | } |
| 4537 | 4757 | dwarf.debug_aranges.section.dirty = false; |
| ... | ... | @@ -4546,31 +4766,31 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4546 | 4766 | dev.check(.x86_64_backend); |
| 4547 | 4767 | const Register = @import("../arch/x86_64/bits.zig").Register; |
| 4548 | 4768 | for (dwarf.debug_frame.section.units.items) |*unit| { |
| 4549 | | header.clearRetainingCapacity(); |
| 4550 | | try header.ensureTotalCapacity(unit.header_len); |
| 4769 | header_aw.clearRetainingCapacity(); |
| 4770 | try header_aw.ensureTotalCapacity(unit.header_len); |
| 4551 | 4771 | const unit_len = unit.header_len - dwarf.unitLengthBytes(); |
| 4552 | 4772 | switch (dwarf.format) { |
| 4553 | | .@"32" => std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), @intCast(unit_len), dwarf.endian), |
| 4773 | .@"32" => hw.writeInt(u32, @intCast(unit_len), dwarf.endian) catch unreachable, |
| 4554 | 4774 | .@"64" => { |
| 4555 | | std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), std.math.maxInt(u32), dwarf.endian); |
| 4556 | | std.mem.writeInt(u64, header.addManyAsArrayAssumeCapacity(8), unit_len, dwarf.endian); |
| 4775 | hw.writeInt(u32, std.math.maxInt(u32), dwarf.endian) catch unreachable; |
| 4776 | hw.writeInt(u64, unit_len, dwarf.endian) catch unreachable; |
| 4557 | 4777 | }, |
| 4558 | 4778 | } |
| 4559 | | header.appendNTimesAssumeCapacity(0, 4); |
| 4560 | | header.appendAssumeCapacity(1); |
| 4561 | | header.appendSliceAssumeCapacity("zR\x00"); |
| 4562 | | uleb128(header.fixedWriter(), dwarf.debug_frame.header.code_alignment_factor) catch unreachable; |
| 4563 | | sleb128(header.fixedWriter(), dwarf.debug_frame.header.data_alignment_factor) catch unreachable; |
| 4564 | | uleb128(header.fixedWriter(), dwarf.debug_frame.header.return_address_register) catch unreachable; |
| 4565 | | uleb128(header.fixedWriter(), 1) catch unreachable; |
| 4566 | | header.appendAssumeCapacity(DW.EH.PE.pcrel | DW.EH.PE.sdata4); |
| 4567 | | header.appendAssumeCapacity(DW.CFA.def_cfa_sf); |
| 4568 | | uleb128(header.fixedWriter(), Register.rsp.dwarfNum()) catch unreachable; |
| 4569 | | sleb128(header.fixedWriter(), -1) catch unreachable; |
| 4570 | | header.appendAssumeCapacity(@as(u8, DW.CFA.offset) + Register.rip.dwarfNum()); |
| 4571 | | uleb128(header.fixedWriter(), 1) catch unreachable; |
| 4572 | | header.appendNTimesAssumeCapacity(DW.CFA.nop, unit.header_len - header.items.len); |
| 4573 | | try unit.replaceHeader(&dwarf.debug_frame.section, dwarf, header.items); |
| 4779 | hw.splatByteAll(0, 4) catch unreachable; |
| 4780 | hw.writeByte(1) catch unreachable; |
| 4781 | hw.writeAll("zR\x00") catch unreachable; |
| 4782 | hw.writeUleb128(dwarf.debug_frame.header.code_alignment_factor) catch unreachable; |
| 4783 | hw.writeSleb128(dwarf.debug_frame.header.data_alignment_factor) catch unreachable; |
| 4784 | hw.writeUleb128(dwarf.debug_frame.header.return_address_register) catch unreachable; |
| 4785 | hw.writeUleb128(1) catch unreachable; |
| 4786 | hw.writeByte(DW.EH.PE.pcrel | DW.EH.PE.sdata4) catch unreachable; |
| 4787 | hw.writeByte(DW.CFA.def_cfa_sf) catch unreachable; |
| 4788 | hw.writeUleb128(Register.rsp.dwarfNum()) catch unreachable; |
| 4789 | hw.writeSleb128(-1) catch unreachable; |
| 4790 | hw.writeByte(@as(u8, DW.CFA.offset) + Register.rip.dwarfNum()) catch unreachable; |
| 4791 | hw.writeUleb128(1) catch unreachable; |
| 4792 | hw.splatByteAll(DW.CFA.nop, unit.header_len - hw.end) catch unreachable; |
| 4793 | try unit.replaceHeader(&dwarf.debug_frame.section, dwarf, header_aw.getWritten()); |
| 4574 | 4794 | try unit.writeTrailer(&dwarf.debug_frame.section, dwarf); |
| 4575 | 4795 | } |
| 4576 | 4796 | }, |
| ... | ... | @@ -4585,81 +4805,82 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4585 | 4805 | unit_ptr.clear(); |
| 4586 | 4806 | try unit_ptr.cross_unit_relocs.ensureTotalCapacity(dwarf.gpa, 1); |
| 4587 | 4807 | try unit_ptr.cross_section_relocs.ensureTotalCapacity(dwarf.gpa, 7); |
| 4588 | | header.clearRetainingCapacity(); |
| 4589 | | try header.ensureTotalCapacity(unit_ptr.header_len); |
| 4808 | header_aw.clearRetainingCapacity(); |
| 4809 | try header_aw.ensureTotalCapacity(unit_ptr.header_len); |
| 4590 | 4810 | const unit_len = (if (unit_ptr.next.unwrap()) |next_unit| |
| 4591 | 4811 | dwarf.debug_info.section.getUnit(next_unit).off |
| 4592 | 4812 | else |
| 4593 | 4813 | dwarf.debug_info.section.len) - unit_ptr.off - dwarf.unitLengthBytes(); |
| 4594 | 4814 | switch (dwarf.format) { |
| 4595 | | .@"32" => std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), @intCast(unit_len), dwarf.endian), |
| 4815 | .@"32" => hw.writeInt(u32, @intCast(unit_len), dwarf.endian) catch unreachable, |
| 4596 | 4816 | .@"64" => { |
| 4597 | | std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), std.math.maxInt(u32), dwarf.endian); |
| 4598 | | std.mem.writeInt(u64, header.addManyAsArrayAssumeCapacity(8), unit_len, dwarf.endian); |
| 4817 | hw.writeInt(u32, std.math.maxInt(u32), dwarf.endian) catch unreachable; |
| 4818 | hw.writeInt(u64, unit_len, dwarf.endian) catch unreachable; |
| 4599 | 4819 | }, |
| 4600 | 4820 | } |
| 4601 | | std.mem.writeInt(u16, header.addManyAsArrayAssumeCapacity(2), 5, dwarf.endian); |
| 4602 | | header.appendSliceAssumeCapacity(&.{ DW.UT.compile, @intFromEnum(dwarf.address_size) }); |
| 4821 | hw.writeInt(u16, 5, dwarf.endian) catch unreachable; |
| 4822 | hw.writeByte(DW.UT.compile) catch unreachable; |
| 4823 | hw.writeByte(@intFromEnum(dwarf.address_size)) catch unreachable; |
| 4603 | 4824 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4604 | | .source_off = @intCast(header.items.len), |
| 4825 | .source_off = @intCast(hw.end), |
| 4605 | 4826 | .target_sec = .debug_abbrev, |
| 4606 | 4827 | .target_unit = DebugAbbrev.unit, |
| 4607 | 4828 | }); |
| 4608 | | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 4609 | | const compile_unit_off: u32 = @intCast(header.items.len); |
| 4610 | | uleb128(header.fixedWriter(), try dwarf.refAbbrevCode(.compile_unit)) catch unreachable; |
| 4611 | | header.appendAssumeCapacity(DW.LANG.Zig); |
| 4829 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4830 | const compile_unit_off: u32 = @intCast(hw.end); |
| 4831 | hw.writeUleb128(try dwarf.refAbbrevCode(.compile_unit)) catch unreachable; |
| 4832 | hw.writeByte(DW.LANG.Zig) catch unreachable; |
| 4612 | 4833 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4613 | | .source_off = @intCast(header.items.len), |
| 4834 | .source_off = @intCast(hw.end), |
| 4614 | 4835 | .target_sec = .debug_line_str, |
| 4615 | 4836 | .target_unit = StringSection.unit, |
| 4616 | 4837 | .target_entry = (try dwarf.debug_line_str.addString(dwarf, "zig " ++ @import("build_options").version)).toOptional(), |
| 4617 | 4838 | }); |
| 4618 | | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 4839 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4619 | 4840 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4620 | | .source_off = @intCast(header.items.len), |
| 4841 | .source_off = @intCast(hw.end), |
| 4621 | 4842 | .target_sec = .debug_line_str, |
| 4622 | 4843 | .target_unit = StringSection.unit, |
| 4623 | 4844 | .target_entry = mod_info.root_dir_path.toOptional(), |
| 4624 | 4845 | }); |
| 4625 | | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 4846 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4626 | 4847 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4627 | | .source_off = @intCast(header.items.len), |
| 4848 | .source_off = @intCast(hw.end), |
| 4628 | 4849 | .target_sec = .debug_line_str, |
| 4629 | 4850 | .target_unit = StringSection.unit, |
| 4630 | 4851 | .target_entry = (try dwarf.debug_line_str.addString(dwarf, mod.root_src_path)).toOptional(), |
| 4631 | 4852 | }); |
| 4632 | | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 4853 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4633 | 4854 | unit_ptr.cross_unit_relocs.appendAssumeCapacity(.{ |
| 4634 | | .source_off = @intCast(header.items.len), |
| 4855 | .source_off = @intCast(hw.end), |
| 4635 | 4856 | .target_unit = .main, |
| 4636 | 4857 | .target_off = compile_unit_off, |
| 4637 | 4858 | }); |
| 4638 | | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 4859 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4639 | 4860 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4640 | | .source_off = @intCast(header.items.len), |
| 4861 | .source_off = @intCast(hw.end), |
| 4641 | 4862 | .target_sec = .debug_line, |
| 4642 | 4863 | .target_unit = unit, |
| 4643 | 4864 | }); |
| 4644 | | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 4865 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4645 | 4866 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4646 | | .source_off = @intCast(header.items.len), |
| 4867 | .source_off = @intCast(hw.end), |
| 4647 | 4868 | .target_sec = .debug_rnglists, |
| 4648 | 4869 | .target_unit = unit, |
| 4649 | 4870 | .target_off = DebugRngLists.baseOffset(dwarf), |
| 4650 | 4871 | }); |
| 4651 | | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 4652 | | uleb128(header.fixedWriter(), 0) catch unreachable; |
| 4653 | | uleb128(header.fixedWriter(), try dwarf.refAbbrevCode(.module)) catch unreachable; |
| 4872 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4873 | hw.writeUleb128(0) catch unreachable; |
| 4874 | hw.writeUleb128(try dwarf.refAbbrevCode(.module)) catch unreachable; |
| 4654 | 4875 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4655 | | .source_off = @intCast(header.items.len), |
| 4876 | .source_off = @intCast(hw.end), |
| 4656 | 4877 | .target_sec = .debug_str, |
| 4657 | 4878 | .target_unit = StringSection.unit, |
| 4658 | 4879 | .target_entry = (try dwarf.debug_str.addString(dwarf, mod.fully_qualified_name)).toOptional(), |
| 4659 | 4880 | }); |
| 4660 | | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 4661 | | uleb128(header.fixedWriter(), 0) catch unreachable; |
| 4662 | | try unit_ptr.replaceHeader(&dwarf.debug_info.section, dwarf, header.items); |
| 4881 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4882 | hw.writeUleb128(0) catch unreachable; |
| 4883 | try unit_ptr.replaceHeader(&dwarf.debug_info.section, dwarf, header_aw.getWritten()); |
| 4663 | 4884 | try unit_ptr.writeTrailer(&dwarf.debug_info.section, dwarf); |
| 4664 | 4885 | } |
| 4665 | 4886 | dwarf.debug_info.section.dirty = false; |
| ... | ... | @@ -4684,32 +4905,36 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4684 | 4905 | for (dwarf.mods.values(), dwarf.debug_line.section.units.items) |mod_info, *unit| { |
| 4685 | 4906 | unit.clear(); |
| 4686 | 4907 | try unit.cross_section_relocs.ensureTotalCapacity(dwarf.gpa, mod_info.dirs.count() + 2 * (mod_info.files.count())); |
| 4687 | | header.clearRetainingCapacity(); |
| 4688 | | try header.ensureTotalCapacity(unit.header_len); |
| 4908 | header_aw.clearRetainingCapacity(); |
| 4909 | try header_aw.ensureTotalCapacity(unit.header_len); |
| 4689 | 4910 | const unit_len = (if (unit.next.unwrap()) |next_unit| |
| 4690 | 4911 | dwarf.debug_line.section.getUnit(next_unit).off |
| 4691 | 4912 | else |
| 4692 | 4913 | dwarf.debug_line.section.len) - unit.off - dwarf.unitLengthBytes(); |
| 4693 | 4914 | switch (dwarf.format) { |
| 4694 | | .@"32" => std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), @intCast(unit_len), dwarf.endian), |
| 4915 | .@"32" => hw.writeInt(u32, @intCast(unit_len), dwarf.endian) catch unreachable, |
| 4695 | 4916 | .@"64" => { |
| 4696 | | std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), std.math.maxInt(u32), dwarf.endian); |
| 4697 | | std.mem.writeInt(u64, header.addManyAsArrayAssumeCapacity(8), unit_len, dwarf.endian); |
| 4917 | hw.writeInt(u32, std.math.maxInt(u32), dwarf.endian) catch unreachable; |
| 4918 | hw.writeInt(u64, unit_len, dwarf.endian) catch unreachable; |
| 4698 | 4919 | }, |
| 4699 | 4920 | } |
| 4700 | | std.mem.writeInt(u16, header.addManyAsArrayAssumeCapacity(2), 5, dwarf.endian); |
| 4701 | | header.appendSliceAssumeCapacity(&.{ @intFromEnum(dwarf.address_size), 0 }); |
| 4702 | | dwarf.writeInt(header.addManyAsSliceAssumeCapacity(dwarf.sectionOffsetBytes()), unit.header_len - header.items.len); |
| 4921 | hw.writeInt(u16, 5, dwarf.endian) catch unreachable; |
| 4922 | hw.writeByte(@intFromEnum(dwarf.address_size)) catch unreachable; |
| 4923 | hw.writeByte(0) catch unreachable; |
| 4924 | switch (dwarf.format) { |
| 4925 | .@"32" => hw.writeInt(u32, @intCast(unit.header_len - hw.end - 4), dwarf.endian) catch unreachable, |
| 4926 | .@"64" => hw.writeInt(u64, @intCast(unit.header_len - hw.end - 8), dwarf.endian) catch unreachable, |
| 4927 | } |
| 4703 | 4928 | const StandardOpcode = DeclValEnum(DW.LNS); |
| 4704 | | header.appendSliceAssumeCapacity(&[_]u8{ |
| 4929 | hw.writeAll(&.{ |
| 4705 | 4930 | dwarf.debug_line.header.minimum_instruction_length, |
| 4706 | 4931 | dwarf.debug_line.header.maximum_operations_per_instruction, |
| 4707 | 4932 | @intFromBool(dwarf.debug_line.header.default_is_stmt), |
| 4708 | 4933 | @bitCast(dwarf.debug_line.header.line_base), |
| 4709 | 4934 | dwarf.debug_line.header.line_range, |
| 4710 | 4935 | dwarf.debug_line.header.opcode_base, |
| 4711 | | }); |
| 4712 | | header.appendSliceAssumeCapacity(std.enums.EnumArray(StandardOpcode, u8).init(.{ |
| 4936 | }) catch unreachable; |
| 4937 | hw.writeAll(std.enums.EnumArray(StandardOpcode, u8).init(.{ |
| 4713 | 4938 | .extended_op = undefined, |
| 4714 | 4939 | .copy = 0, |
| 4715 | 4940 | .advance_pc = 1, |
| ... | ... | @@ -4723,44 +4948,46 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4723 | 4948 | .set_prologue_end = 0, |
| 4724 | 4949 | .set_epilogue_begin = 0, |
| 4725 | 4950 | .set_isa = 1, |
| 4726 | | }).values[1..dwarf.debug_line.header.opcode_base]); |
| 4727 | | header.appendAssumeCapacity(1); |
| 4728 | | uleb128(header.fixedWriter(), DW.LNCT.path) catch unreachable; |
| 4729 | | uleb128(header.fixedWriter(), DW.FORM.line_strp) catch unreachable; |
| 4730 | | uleb128(header.fixedWriter(), mod_info.dirs.count()) catch unreachable; |
| 4951 | }).values[1..dwarf.debug_line.header.opcode_base]) catch unreachable; |
| 4952 | hw.writeByte(1) catch unreachable; |
| 4953 | hw.writeUleb128(DW.LNCT.path) catch unreachable; |
| 4954 | hw.writeUleb128(DW.FORM.line_strp) catch unreachable; |
| 4955 | hw.writeUleb128(mod_info.dirs.count()) catch unreachable; |
| 4731 | 4956 | for (mod_info.dirs.keys()) |dir_unit| { |
| 4732 | 4957 | unit.cross_section_relocs.appendAssumeCapacity(.{ |
| 4733 | | .source_off = @intCast(header.items.len), |
| 4958 | .source_off = @intCast(hw.end), |
| 4734 | 4959 | .target_sec = .debug_line_str, |
| 4735 | 4960 | .target_unit = StringSection.unit, |
| 4736 | 4961 | .target_entry = dwarf.getModInfo(dir_unit).root_dir_path.toOptional(), |
| 4737 | 4962 | }); |
| 4738 | | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 4963 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4739 | 4964 | } |
| 4740 | 4965 | const dir_index_info = DebugLine.dirIndexInfo(@intCast(mod_info.dirs.count())); |
| 4741 | | header.appendAssumeCapacity(3); |
| 4742 | | uleb128(header.fixedWriter(), DW.LNCT.path) catch unreachable; |
| 4743 | | uleb128(header.fixedWriter(), DW.FORM.line_strp) catch unreachable; |
| 4744 | | uleb128(header.fixedWriter(), DW.LNCT.directory_index) catch unreachable; |
| 4745 | | uleb128(header.fixedWriter(), @intFromEnum(dir_index_info.form)) catch unreachable; |
| 4746 | | uleb128(header.fixedWriter(), DW.LNCT.LLVM_source) catch unreachable; |
| 4747 | | uleb128(header.fixedWriter(), DW.FORM.line_strp) catch unreachable; |
| 4748 | | uleb128(header.fixedWriter(), mod_info.files.count()) catch unreachable; |
| 4966 | hw.writeByte(3) catch unreachable; |
| 4967 | hw.writeUleb128(DW.LNCT.path) catch unreachable; |
| 4968 | hw.writeUleb128(DW.FORM.line_strp) catch unreachable; |
| 4969 | hw.writeUleb128(DW.LNCT.directory_index) catch unreachable; |
| 4970 | hw.writeUleb128(@intFromEnum(dir_index_info.form)) catch unreachable; |
| 4971 | hw.writeUleb128(DW.LNCT.LLVM_source) catch unreachable; |
| 4972 | hw.writeUleb128(DW.FORM.line_strp) catch unreachable; |
| 4973 | hw.writeUleb128(mod_info.files.count()) catch unreachable; |
| 4749 | 4974 | for (mod_info.files.keys()) |file_index| { |
| 4750 | 4975 | const file = zcu.fileByIndex(file_index); |
| 4751 | 4976 | unit.cross_section_relocs.appendAssumeCapacity(.{ |
| 4752 | | .source_off = @intCast(header.items.len), |
| 4977 | .source_off = @intCast(hw.end), |
| 4753 | 4978 | .target_sec = .debug_line_str, |
| 4754 | 4979 | .target_unit = StringSection.unit, |
| 4755 | 4980 | .target_entry = (try dwarf.debug_line_str.addString(dwarf, file.sub_file_path)).toOptional(), |
| 4756 | 4981 | }); |
| 4757 | | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 4758 | | dwarf.writeInt( |
| 4759 | | header.addManyAsSliceAssumeCapacity(dir_index_info.bytes), |
| 4760 | | mod_info.dirs.getIndex(dwarf.getUnitIfExists(file.mod.?).?) orelse 0, |
| 4761 | | ); |
| 4982 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4983 | const dir_index = mod_info.dirs.getIndex(dwarf.getUnitIfExists(file.mod.?).?) orelse 0; |
| 4984 | switch (dir_index_info.bytes) { |
| 4985 | else => unreachable, |
| 4986 | 1 => hw.writeByte(@intCast(dir_index)) catch unreachable, |
| 4987 | 2 => hw.writeInt(u16, @intCast(dir_index), dwarf.endian) catch unreachable, |
| 4988 | } |
| 4762 | 4989 | unit.cross_section_relocs.appendAssumeCapacity(.{ |
| 4763 | | .source_off = @intCast(header.items.len), |
| 4990 | .source_off = @intCast(hw.end), |
| 4764 | 4991 | .target_sec = .debug_line_str, |
| 4765 | 4992 | .target_unit = StringSection.unit, |
| 4766 | 4993 | .target_entry = (try dwarf.debug_line_str.addString( |
| ... | ... | @@ -4768,9 +4995,9 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4768 | 4995 | if (file.is_builtin) file.source.? else "", |
| 4769 | 4996 | )).toOptional(), |
| 4770 | 4997 | }); |
| 4771 | | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 4998 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4772 | 4999 | } |
| 4773 | | try unit.replaceHeader(&dwarf.debug_line.section, dwarf, header.items); |
| 5000 | try unit.replaceHeader(&dwarf.debug_line.section, dwarf, header_aw.getWritten()); |
| 4774 | 5001 | try unit.writeTrailer(&dwarf.debug_line.section, dwarf); |
| 4775 | 5002 | } |
| 4776 | 5003 | dwarf.debug_line.section.dirty = false; |
| ... | ... | @@ -4786,24 +5013,28 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4786 | 5013 | } |
| 4787 | 5014 | if (dwarf.debug_rnglists.section.dirty) { |
| 4788 | 5015 | for (dwarf.debug_rnglists.section.units.items) |*unit| { |
| 4789 | | header.clearRetainingCapacity(); |
| 4790 | | try header.ensureTotalCapacity(unit.header_len); |
| 5016 | header_aw.clearRetainingCapacity(); |
| 5017 | try header_aw.ensureTotalCapacity(unit.header_len); |
| 4791 | 5018 | const unit_len = (if (unit.next.unwrap()) |next_unit| |
| 4792 | 5019 | dwarf.debug_rnglists.section.getUnit(next_unit).off |
| 4793 | 5020 | else |
| 4794 | 5021 | dwarf.debug_rnglists.section.len) - unit.off - dwarf.unitLengthBytes(); |
| 4795 | 5022 | switch (dwarf.format) { |
| 4796 | | .@"32" => std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), @intCast(unit_len), dwarf.endian), |
| 5023 | .@"32" => hw.writeInt(u32, @intCast(unit_len), dwarf.endian) catch unreachable, |
| 4797 | 5024 | .@"64" => { |
| 4798 | | std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), std.math.maxInt(u32), dwarf.endian); |
| 4799 | | std.mem.writeInt(u64, header.addManyAsArrayAssumeCapacity(8), unit_len, dwarf.endian); |
| 5025 | hw.writeInt(u32, std.math.maxInt(u32), dwarf.endian) catch unreachable; |
| 5026 | hw.writeInt(u64, unit_len, dwarf.endian) catch unreachable; |
| 4800 | 5027 | }, |
| 4801 | 5028 | } |
| 4802 | | std.mem.writeInt(u16, header.addManyAsArrayAssumeCapacity(2), 5, dwarf.endian); |
| 4803 | | header.appendSliceAssumeCapacity(&.{ @intFromEnum(dwarf.address_size), 0 }); |
| 4804 | | std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), 1, dwarf.endian); |
| 4805 | | dwarf.writeInt(header.addManyAsSliceAssumeCapacity(dwarf.sectionOffsetBytes()), dwarf.sectionOffsetBytes() * 1); |
| 4806 | | try unit.replaceHeader(&dwarf.debug_rnglists.section, dwarf, header.items); |
| 5029 | hw.writeInt(u16, 5, dwarf.endian) catch unreachable; |
| 5030 | hw.writeByte(@intFromEnum(dwarf.address_size)) catch unreachable; |
| 5031 | hw.writeByte(0) catch unreachable; |
| 5032 | hw.writeInt(u32, 1, dwarf.endian) catch unreachable; |
| 5033 | switch (dwarf.format) { |
| 5034 | .@"32" => hw.writeInt(u32, dwarf.sectionOffsetBytes() * 1, dwarf.endian) catch unreachable, |
| 5035 | .@"64" => hw.writeInt(u64, dwarf.sectionOffsetBytes() * 1, dwarf.endian) catch unreachable, |
| 5036 | } |
| 5037 | try unit.replaceHeader(&dwarf.debug_rnglists.section, dwarf, header_aw.getWritten()); |
| 4807 | 5038 | try unit.writeTrailer(&dwarf.debug_rnglists.section, dwarf); |
| 4808 | 5039 | } |
| 4809 | 5040 | dwarf.debug_rnglists.section.dirty = false; |
| ... | ... | @@ -5983,7 +6214,11 @@ fn addCommonEntry(dwarf: *Dwarf, unit: Unit.Index) UpdateError!Entry.Index { |
| 5983 | 6214 | return entry; |
| 5984 | 6215 | } |
| 5985 | 6216 | |
| 5986 | | fn freeCommonEntry(dwarf: *Dwarf, unit: Unit.Index, entry: Entry.Index) UpdateError!void { |
| 6217 | fn freeCommonEntry( |
| 6218 | dwarf: *Dwarf, |
| 6219 | unit: Unit.Index, |
| 6220 | entry: Entry.Index, |
| 6221 | ) (UpdateError || Writer.Error)!void { |
| 5987 | 6222 | try dwarf.debug_aranges.section.freeEntry(unit, entry, dwarf); |
| 5988 | 6223 | try dwarf.debug_frame.section.freeEntry(unit, entry, dwarf); |
| 5989 | 6224 | try dwarf.debug_info.section.freeEntry(unit, entry, dwarf); |
| ... | ... | @@ -6023,17 +6258,17 @@ fn sectionOffsetBytes(dwarf: *Dwarf) u32 { |
| 6023 | 6258 | } |
| 6024 | 6259 | |
| 6025 | 6260 | fn uleb128Bytes(value: anytype) u32 { |
| 6026 | | var trash_buffer: [64]u8 = undefined; |
| 6027 | | var d: Writer.Discarding = .init(&trash_buffer); |
| 6028 | | d.writer.writeUleb128(value) catch unreachable; |
| 6029 | | return @intCast(d.count + d.writer.end); |
| 6261 | var buf: [64]u8 = undefined; |
| 6262 | var dw: Writer.Discarding = .init(&buf); |
| 6263 | dw.writer.writeUleb128(value) catch unreachable; |
| 6264 | return @intCast(dw.count + dw.writer.end); |
| 6030 | 6265 | } |
| 6031 | 6266 | |
| 6032 | 6267 | fn sleb128Bytes(value: anytype) u32 { |
| 6033 | | var trash_buffer: [64]u8 = undefined; |
| 6034 | | var d: Writer.Discarding = .init(&trash_buffer); |
| 6035 | | d.writer.writeSleb128(value) catch unreachable; |
| 6036 | | return @intCast(d.count + d.writer.end); |
| 6268 | var buf: [64]u8 = undefined; |
| 6269 | var dw: Writer.Discarding = .init(&buf); |
| 6270 | dw.writer.writeSleb128(value) catch unreachable; |
| 6271 | return @intCast(dw.count + dw.writer.end); |
| 6037 | 6272 | } |
| 6038 | 6273 | |
| 6039 | 6274 | /// overrides `-fno-incremental` for testing incremental debug info until `-fincremental` is functional |
| ... | ... | @@ -6042,6 +6277,7 @@ inline fn incremental(dwarf: Dwarf) bool { |
| 6042 | 6277 | return force_incremental or dwarf.bin_file.comp.incremental; |
| 6043 | 6278 | } |
| 6044 | 6279 | |
| 6280 | const Allocator = std.mem.Allocator; |
| 6045 | 6281 | const DW = std.dwarf; |
| 6046 | 6282 | const Dwarf = @This(); |
| 6047 | 6283 | const InternPool = @import("../InternPool.zig"); |
| ... | ... | @@ -6055,9 +6291,6 @@ const codegen = @import("../codegen.zig"); |
| 6055 | 6291 | const dev = @import("../dev.zig"); |
| 6056 | 6292 | const link = @import("../link.zig"); |
| 6057 | 6293 | const log = std.log.scoped(.dwarf); |
| 6058 | | const sleb128 = std.leb.writeIleb128; |
| 6059 | 6294 | const std = @import("std"); |
| 6060 | 6295 | const target_info = @import("../target.zig"); |
| 6061 | | const uleb128 = std.leb.writeUleb128; |
| 6062 | | const Allocator = std.mem.Allocator; |
| 6063 | 6296 | const Writer = std.Io.Writer; |