| ... | @@ -144,7 +144,9 @@ const DebugInfo = struct { | ... | @@ -144,7 +144,9 @@ const DebugInfo = struct { |
| 144 | debug_info.section.off(dwarf) + unit_ptr.off + unit_ptr.header_len + entry_ptr.off, | 144 | debug_info.section.off(dwarf) + unit_ptr.off + unit_ptr.header_len + entry_ptr.off, |
| 145 | ) != abbrev_code_buf.len) return error.InputOutput; | 145 | ) != abbrev_code_buf.len) return error.InputOutput; |
| 146 | var abbrev_code_reader: std.Io.Reader = .fixed(&abbrev_code_buf); | 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 | const trailer_bytes = 1 + 1; | 152 | const trailer_bytes = 1 + 1; |
| ... | @@ -369,7 +371,13 @@ pub const Section = struct { | ... | @@ -369,7 +371,13 @@ pub const Section = struct { |
| 369 | return &sec.units.items[@intFromEnum(unit)]; | 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 | const unit_ptr = sec.getUnit(unit); | 381 | const unit_ptr = sec.getUnit(unit); |
| 374 | const entry_ptr = unit_ptr.getEntry(entry); | 382 | const entry_ptr = unit_ptr.getEntry(entry); |
| 375 | if (len > 0) { | 383 | if (len > 0) { |
| ... | @@ -390,13 +398,24 @@ pub const Section = struct { | ... | @@ -390,13 +398,24 @@ pub const Section = struct { |
| 390 | assert(entry_ptr.len == len); | 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 | try sec.resizeEntry(unit, entry, dwarf, @intCast(contents.len)); | 408 | try sec.resizeEntry(unit, entry, dwarf, @intCast(contents.len)); |
| 395 | const unit_ptr = sec.getUnit(unit); | 409 | const unit_ptr = sec.getUnit(unit); |
| 396 | try unit_ptr.getEntry(entry).replace(unit_ptr, sec, dwarf, contents); | 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 | const unit_ptr = sec.getUnit(unit); | 419 | const unit_ptr = sec.getUnit(unit); |
| 401 | const entry_ptr = unit_ptr.getEntry(entry); | 420 | const entry_ptr = unit_ptr.getEntry(entry); |
| 402 | if (entry_ptr.len > 0) { | 421 | if (entry_ptr.len > 0) { |
| ... | @@ -649,35 +668,37 @@ const Unit = struct { | ... | @@ -649,35 +668,37 @@ const Unit = struct { |
| 649 | assert(len >= unit.trailer_len); | 668 | assert(len >= unit.trailer_len); |
| 650 | if (sec == &dwarf.debug_line.section) { | 669 | if (sec == &dwarf.debug_line.section) { |
| 651 | var buf: [1 + uleb128Bytes(std.math.maxInt(u32)) + 1]u8 = undefined; | 670 | var buf: [1 + uleb128Bytes(std.math.maxInt(u32)) + 1]u8 = undefined; |
| 652 | var fbs = std.io.fixedBufferStream(&buf); | 671 | var fw: Writer = .fixed(&buf); |
| 653 | const writer = fbs.writer(); | 672 | fw.writeByte(DW.LNS.extended_op) catch unreachable; |
| 654 | writer.writeByte(DW.LNS.extended_op) catch unreachable; | 673 | const extended_op_bytes = fw.end; |
| 655 | const extended_op_bytes = fbs.pos; | | |
| 656 | var op_len_bytes: u5 = 1; | 674 | var op_len_bytes: u5 = 1; |
| 657 | while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << 7 * op_len_bytes)) { | 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 | .eq => { | 677 | .eq => { |
| 660 | // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte | 678 | // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte |
| 661 | op_len_bytes += 1; | 679 | op_len_bytes += 1; |
| 662 | std.leb.writeUnsignedExtended(buf[fbs.pos..][0..op_len_bytes], len - extended_op_bytes - op_len_bytes); | 680 | std.leb.writeUnsignedExtended( |
| 663 | fbs.pos += op_len_bytes; | 681 | fw.writableSlice(op_len_bytes) catch unreachable, |
| | 682 | len - extended_op_bytes - op_len_bytes, |
| | 683 | ); |
| 664 | break; | 684 | break; |
| 665 | }, | 685 | }, |
| 666 | .gt => op_len_bytes += 1, | 686 | .gt => op_len_bytes += 1, |
| 667 | }; | 687 | }; |
| 668 | assert(fbs.pos == extended_op_bytes + op_len_bytes); | 688 | assert(fw.end == extended_op_bytes + op_len_bytes); |
| 669 | writer.writeByte(DW.LNE.padding) catch unreachable; | 689 | fw.writeByte(DW.LNE.padding) catch unreachable; |
| 670 | assert(fbs.pos >= unit.trailer_len and fbs.pos <= len); | 690 | assert(fw.end >= unit.trailer_len and fw.end <= len); |
| 671 | return dwarf.getFile().?.pwriteAll(fbs.getWritten(), sec.off(dwarf) + start); | 691 | return dwarf.getFile().?.pwriteAll(fw.buffered(), sec.off(dwarf) + start); |
| 672 | } | 692 | } |
| 673 | var trailer = try std.ArrayList(u8).initCapacity(dwarf.gpa, len); | 693 | var trailer_aw: Writer.Allocating = try .initCapacity(dwarf.gpa, len); |
| 674 | defer trailer.deinit(); | 694 | defer trailer_aw.deinit(); |
| | 695 | const tw = &trailer_aw.writer; |
| 675 | const fill_byte: u8 = if (sec == &dwarf.debug_abbrev.section) fill: { | 696 | const fill_byte: u8 = if (sec == &dwarf.debug_abbrev.section) fill: { |
| | 697 | tw.writeUleb128(@intFromEnum(AbbrevCode.null)) catch unreachable; |
| 676 | assert(uleb128Bytes(@intFromEnum(AbbrevCode.null)) == 1); | 698 | assert(uleb128Bytes(@intFromEnum(AbbrevCode.null)) == 1); |
| 677 | trailer.appendAssumeCapacity(@intFromEnum(AbbrevCode.null)); | | |
| 678 | break :fill @intFromEnum(AbbrevCode.null); | 699 | break :fill @intFromEnum(AbbrevCode.null); |
| 679 | } else if (sec == &dwarf.debug_aranges.section) fill: { | 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 | break :fill 0; | 702 | break :fill 0; |
| 682 | } else if (sec == &dwarf.debug_frame.section) fill: { | 703 | } else if (sec == &dwarf.debug_frame.section) fill: { |
| 683 | switch (dwarf.debug_frame.header.format) { | 704 | switch (dwarf.debug_frame.header.format) { |
| ... | @@ -685,49 +706,49 @@ const Unit = struct { | ... | @@ -685,49 +706,49 @@ const Unit = struct { |
| 685 | .debug_frame, .eh_frame => |format| { | 706 | .debug_frame, .eh_frame => |format| { |
| 686 | const unit_len = len - dwarf.unitLengthBytes(); | 707 | const unit_len = len - dwarf.unitLengthBytes(); |
| 687 | switch (dwarf.format) { | 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 | .@"64" => { | 710 | .@"64" => { |
| 690 | std.mem.writeInt(u32, trailer.addManyAsArrayAssumeCapacity(4), std.math.maxInt(u32), dwarf.endian); | 711 | tw.writeInt(u32, std.math.maxInt(u32), dwarf.endian) catch unreachable; |
| 691 | std.mem.writeInt(u64, trailer.addManyAsArrayAssumeCapacity(8), unit_len, dwarf.endian); | 712 | tw.writeInt(u64, unit_len, dwarf.endian) catch unreachable; |
| 692 | }, | 713 | }, |
| 693 | } | 714 | } |
| 694 | switch (format) { | 715 | switch (format) { |
| 695 | .none => unreachable, | 716 | .none => unreachable, |
| 696 | .debug_frame => { | 717 | .debug_frame => { |
| 697 | switch (dwarf.format) { | 718 | switch (dwarf.format) { |
| 698 | .@"32" => std.mem.writeInt(u32, trailer.addManyAsArrayAssumeCapacity(4), std.math.maxInt(u32), dwarf.endian), | 719 | .@"32" => tw.writeInt(u32, std.math.maxInt(u32), dwarf.endian) catch unreachable, |
| 699 | .@"64" => std.mem.writeInt(u64, trailer.addManyAsArrayAssumeCapacity(8), std.math.maxInt(u64), dwarf.endian), | 720 | .@"64" => tw.writeInt(u64, std.math.maxInt(u64), dwarf.endian) catch unreachable, |
| 700 | } | 721 | } |
| 701 | trailer.appendAssumeCapacity(4); | 722 | tw.writeByte(4) catch unreachable; |
| 702 | trailer.appendSliceAssumeCapacity("\x00"); | 723 | tw.writeAll("\x00") catch unreachable; |
| 703 | trailer.appendAssumeCapacity(@intFromEnum(dwarf.address_size)); | 724 | tw.writeByte(@intFromEnum(dwarf.address_size)) catch unreachable; |
| 704 | trailer.appendAssumeCapacity(0); | 725 | tw.writeByte(0) catch unreachable; |
| 705 | }, | 726 | }, |
| 706 | .eh_frame => { | 727 | .eh_frame => { |
| 707 | std.mem.writeInt(u32, trailer.addManyAsArrayAssumeCapacity(4), 0, dwarf.endian); | 728 | tw.writeInt(u32, 0, dwarf.endian) catch unreachable; |
| 708 | trailer.appendAssumeCapacity(1); | 729 | tw.writeByte(1) catch unreachable; |
| 709 | trailer.appendSliceAssumeCapacity("\x00"); | 730 | tw.writeAll("\x00") catch unreachable; |
| 710 | }, | 731 | }, |
| 711 | } | 732 | } |
| 712 | uleb128(trailer.fixedWriter(), 1) catch unreachable; | 733 | tw.writeUleb128(1) catch unreachable; |
| 713 | sleb128(trailer.fixedWriter(), 1) catch unreachable; | 734 | tw.writeSleb128(1) catch unreachable; |
| 714 | uleb128(trailer.fixedWriter(), 0) 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 | break :fill DW.CFA.nop; | 739 | break :fill DW.CFA.nop; |
| 719 | } else if (sec == &dwarf.debug_info.section) fill: { | 740 | } else if (sec == &dwarf.debug_info.section) fill: { |
| | 741 | for (0..2) |_| tw.writeUleb128(@intFromEnum(AbbrevCode.null)) catch unreachable; |
| 720 | assert(uleb128Bytes(@intFromEnum(AbbrevCode.null)) == 1); | 742 | assert(uleb128Bytes(@intFromEnum(AbbrevCode.null)) == 1); |
| 721 | trailer.appendNTimesAssumeCapacity(@intFromEnum(AbbrevCode.null), 2); | | |
| 722 | break :fill @intFromEnum(AbbrevCode.null); | 743 | break :fill @intFromEnum(AbbrevCode.null); |
| 723 | } else if (sec == &dwarf.debug_rnglists.section) fill: { | 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 | break :fill DW.RLE.end_of_list; | 746 | break :fill DW.RLE.end_of_list; |
| 726 | } else unreachable; | 747 | } else unreachable; |
| 727 | assert(trailer.items.len == unit.trailer_len); | 748 | assert(tw.end == unit.trailer_len); |
| 728 | trailer.appendNTimesAssumeCapacity(fill_byte, len - unit.trailer_len); | 749 | tw.splatByteAll(fill_byte, len - unit.trailer_len) catch unreachable; |
| 729 | assert(trailer.items.len == len); | 750 | assert(tw.end == len); |
| 730 | try dwarf.getFile().?.pwriteAll(trailer.items, sec.off(dwarf) + start); | 751 | try dwarf.getFile().?.pwriteAll(trailer_aw.getWritten(), sec.off(dwarf) + start); |
| 731 | } | 752 | } |
| 732 | | 753 | |
| 733 | fn resolveRelocs(unit: *Unit, sec: *Section, dwarf: *Dwarf) RelocError!void { | 754 | fn resolveRelocs(unit: *Unit, sec: *Section, dwarf: *Dwarf) RelocError!void { |
| ... | @@ -806,7 +827,12 @@ const Entry = struct { | ... | @@ -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 | assert(entry.len > 0); | 836 | assert(entry.len > 0); |
| 811 | const start = entry.off + entry.len; | 837 | const start = entry.off + entry.len; |
| 812 | if (sec == &dwarf.debug_frame.section) { | 838 | if (sec == &dwarf.debug_frame.section) { |
| ... | @@ -814,12 +840,10 @@ const Entry = struct { | ... | @@ -814,12 +840,10 @@ const Entry = struct { |
| 814 | unit.getEntry(next_entry).off - entry.off | 840 | unit.getEntry(next_entry).off - entry.off |
| 815 | else | 841 | else |
| 816 | entry.len; | 842 | entry.len; |
| 817 | var unit_len: [8]u8 = undefined; | 843 | var unit_len_buf: [8]u8 = undefined; |
| 818 | dwarf.writeInt(unit_len[0..dwarf.sectionOffsetBytes()], len - dwarf.unitLengthBytes()); | 844 | const unit_len_bytes = unit_len_buf[0..dwarf.sectionOffsetBytes()]; |
| 819 | try dwarf.getFile().?.pwriteAll( | 845 | dwarf.writeInt(unit_len_bytes, len - dwarf.unitLengthBytes()); |
| 820 | unit_len[0..dwarf.sectionOffsetBytes()], | 846 | try dwarf.getFile().?.pwriteAll(unit_len_bytes, sec.off(dwarf) + unit.off + unit.header_len + entry.off); |
| 821 | sec.off(dwarf) + unit.off + unit.header_len + entry.off, | | |
| 822 | ); | | |
| 823 | const buf = try dwarf.gpa.alloc(u8, len - entry.len); | 847 | const buf = try dwarf.gpa.alloc(u8, len - entry.len); |
| 824 | defer dwarf.gpa.free(buf); | 848 | defer dwarf.gpa.free(buf); |
| 825 | @memset(buf, DW.CFA.nop); | 849 | @memset(buf, DW.CFA.nop); |
| ... | @@ -834,55 +858,64 @@ const Entry = struct { | ... | @@ -834,55 +858,64 @@ const Entry = struct { |
| 834 | 1 + uleb128Bytes(std.math.maxInt(u32)) + 1, | 858 | 1 + uleb128Bytes(std.math.maxInt(u32)) + 1, |
| 835 | ) | 859 | ) |
| 836 | ]u8 = undefined; | 860 | ]u8 = undefined; |
| 837 | var fbs = std.io.fixedBufferStream(&buf); | 861 | var fw: Writer = .fixed(&buf); |
| 838 | const writer = fbs.writer(); | | |
| 839 | if (sec == &dwarf.debug_info.section) switch (len) { | 862 | if (sec == &dwarf.debug_info.section) switch (len) { |
| 840 | 0 => {}, | 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 | else => { | 865 | else => { |
| 843 | uleb128(writer, try dwarf.refAbbrevCode(.pad_n)) catch unreachable; | 866 | fw.writeUleb128(try dwarf.refAbbrevCode(.pad_n)) catch unreachable; |
| 844 | const abbrev_code_bytes = fbs.pos; | 867 | const abbrev_code_bytes = fw.end; |
| 845 | var block_len_bytes: u5 = 1; | 868 | var block_len_bytes: u5 = 1; |
| 846 | while (true) switch (std.math.order(len - abbrev_code_bytes - block_len_bytes, @as(u32, 1) << 7 * block_len_bytes)) { | 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 | .eq => { | 871 | .eq => { |
| 849 | // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte | 872 | // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte |
| 850 | block_len_bytes += 1; | 873 | block_len_bytes += 1; |
| 851 | std.leb.writeUnsignedExtended(buf[fbs.pos..][0..block_len_bytes], len - abbrev_code_bytes - block_len_bytes); | 874 | std.leb.writeUnsignedExtended( |
| 852 | fbs.pos += block_len_bytes; | 875 | fw.writableSlice(block_len_bytes) catch unreachable, |
| | 876 | len - abbrev_code_bytes - block_len_bytes, |
| | 877 | ); |
| 853 | break; | 878 | break; |
| 854 | }, | 879 | }, |
| 855 | .gt => block_len_bytes += 1, | 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 | } else if (sec == &dwarf.debug_line.section) switch (len) { | 884 | } else if (sec == &dwarf.debug_line.section) switch (len) { |
| 860 | 0 => {}, | 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 | else => { | 887 | else => { |
| 863 | writer.writeByte(DW.LNS.extended_op) catch unreachable; | 888 | fw.writeByte(DW.LNS.extended_op) catch unreachable; |
| 864 | const extended_op_bytes = fbs.pos; | 889 | const extended_op_bytes = fw.end; |
| 865 | var op_len_bytes: u5 = 1; | 890 | var op_len_bytes: u5 = 1; |
| 866 | while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << 7 * op_len_bytes)) { | 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 | .eq => { | 893 | .eq => { |
| 869 | // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte | 894 | // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte |
| 870 | op_len_bytes += 1; | 895 | op_len_bytes += 1; |
| 871 | std.leb.writeUnsignedExtended(buf[fbs.pos..][0..op_len_bytes], len - extended_op_bytes - op_len_bytes); | 896 | std.leb.writeUnsignedExtended( |
| 872 | fbs.pos += op_len_bytes; | 897 | fw.writableSlice(op_len_bytes) catch unreachable, |
| | 898 | len - extended_op_bytes - op_len_bytes, |
| | 899 | ); |
| 873 | break; | 900 | break; |
| 874 | }, | 901 | }, |
| 875 | .gt => op_len_bytes += 1, | 902 | .gt => op_len_bytes += 1, |
| 876 | }; | 903 | }; |
| 877 | assert(fbs.pos == extended_op_bytes + op_len_bytes); | 904 | assert(fw.end == extended_op_bytes + op_len_bytes); |
| 878 | if (len > 2) writer.writeByte(DW.LNE.padding) catch unreachable; | 905 | if (len > 2) fw.writeByte(DW.LNE.padding) catch unreachable; |
| 879 | }, | 906 | }, |
| 880 | } else assert(!sec.pad_entries_to_ideal and len == 0); | 907 | } else assert(!sec.pad_entries_to_ideal and len == 0); |
| 881 | assert(fbs.pos <= len); | 908 | assert(fw.end <= len); |
| 882 | try dwarf.getFile().?.pwriteAll(fbs.getWritten(), sec.off(dwarf) + unit.off + unit.header_len + start); | 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 | assert(len > 0); | 919 | assert(len > 0); |
| 887 | assert(sec.alignment.check(len)); | 920 | assert(sec.alignment.check(len)); |
| 888 | if (entry_ptr.len == len) return; | 921 | if (entry_ptr.len == len) return; |
| ... | @@ -1134,16 +1167,16 @@ pub const Loc = union(enum) { | ... | @@ -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 | if (std.math.cast(u5, reg)) |small_reg| { | 1171 | if (std.math.cast(u5, reg)) |small_reg| { |
| 1139 | try writer.writeByte(op0 + small_reg); | 1172 | try writer.writeByte(op0 + small_reg); |
| 1140 | } else { | 1173 | } else { |
| 1141 | try writer.writeByte(opx); | 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 | const writer = adapter.writer(); | 1180 | const writer = adapter.writer(); |
| 1148 | switch (loc) { | 1181 | switch (loc) { |
| 1149 | .empty => {}, | 1182 | .empty => {}, |
| ... | @@ -1164,13 +1197,13 @@ pub const Loc = union(enum) { | ... | @@ -1164,13 +1197,13 @@ pub const Loc = union(enum) { |
| 1164 | try writer.writeInt(u16, const2u, adapter.endian()); | 1197 | try writer.writeInt(u16, const2u, adapter.endian()); |
| 1165 | } else if (std.math.cast(u21, constu)) |const3u| { | 1198 | } else if (std.math.cast(u21, constu)) |const3u| { |
| 1166 | try writer.writeByte(DW.OP.constu); | 1199 | try writer.writeByte(DW.OP.constu); |
| 1167 | try uleb128(writer, const3u); | 1200 | try writer.writeUleb128(const3u); |
| 1168 | } else if (std.math.cast(u32, constu)) |const4u| { | 1201 | } else if (std.math.cast(u32, constu)) |const4u| { |
| 1169 | try writer.writeByte(DW.OP.const4u); | 1202 | try writer.writeByte(DW.OP.const4u); |
| 1170 | try writer.writeInt(u32, const4u, adapter.endian()); | 1203 | try writer.writeInt(u32, const4u, adapter.endian()); |
| 1171 | } else if (std.math.cast(u49, constu)) |const7u| { | 1204 | } else if (std.math.cast(u49, constu)) |const7u| { |
| 1172 | try writer.writeByte(DW.OP.constu); | 1205 | try writer.writeByte(DW.OP.constu); |
| 1173 | try uleb128(writer, const7u); | 1206 | try writer.writeUleb128(const7u); |
| 1174 | } else { | 1207 | } else { |
| 1175 | try writer.writeByte(DW.OP.const8u); | 1208 | try writer.writeByte(DW.OP.const8u); |
| 1176 | try writer.writeInt(u64, constu, adapter.endian()); | 1209 | try writer.writeInt(u64, constu, adapter.endian()); |
| ... | @@ -1182,13 +1215,13 @@ pub const Loc = union(enum) { | ... | @@ -1182,13 +1215,13 @@ pub const Loc = union(enum) { |
| 1182 | try writer.writeInt(i16, const2s, adapter.endian()); | 1215 | try writer.writeInt(i16, const2s, adapter.endian()); |
| 1183 | } else if (std.math.cast(i21, consts)) |const3s| { | 1216 | } else if (std.math.cast(i21, consts)) |const3s| { |
| 1184 | try writer.writeByte(DW.OP.consts); | 1217 | try writer.writeByte(DW.OP.consts); |
| 1185 | try sleb128(writer, const3s); | 1218 | try writer.writeSleb128(const3s); |
| 1186 | } else if (std.math.cast(i32, consts)) |const4s| { | 1219 | } else if (std.math.cast(i32, consts)) |const4s| { |
| 1187 | try writer.writeByte(DW.OP.const4s); | 1220 | try writer.writeByte(DW.OP.const4s); |
| 1188 | try writer.writeInt(i32, const4s, adapter.endian()); | 1221 | try writer.writeInt(i32, const4s, adapter.endian()); |
| 1189 | } else if (std.math.cast(i49, consts)) |const7s| { | 1222 | } else if (std.math.cast(i49, consts)) |const7s| { |
| 1190 | try writer.writeByte(DW.OP.consts); | 1223 | try writer.writeByte(DW.OP.consts); |
| 1191 | try sleb128(writer, const7s); | 1224 | try writer.writeSleb128(const7s); |
| 1192 | } else { | 1225 | } else { |
| 1193 | try writer.writeByte(DW.OP.const8s); | 1226 | try writer.writeByte(DW.OP.const8s); |
| 1194 | try writer.writeInt(i64, consts, adapter.endian()); | 1227 | try writer.writeInt(i64, consts, adapter.endian()); |
| ... | @@ -1205,27 +1238,27 @@ pub const Loc = union(enum) { | ... | @@ -1205,27 +1238,27 @@ pub const Loc = union(enum) { |
| 1205 | if (plus[0].getBaseReg()) |breg| { | 1238 | if (plus[0].getBaseReg()) |breg| { |
| 1206 | if (plus[1].getConst(i65)) |offset| { | 1239 | if (plus[1].getConst(i65)) |offset| { |
| 1207 | try writeReg(breg, DW.OP.breg0, DW.OP.bregx, writer); | 1240 | try writeReg(breg, DW.OP.breg0, DW.OP.bregx, writer); |
| 1208 | try sleb128(writer, offset); | 1241 | try writer.writeSleb128(offset); |
| 1209 | break :done; | 1242 | break :done; |
| 1210 | } | 1243 | } |
| 1211 | } | 1244 | } |
| 1212 | if (plus[1].getBaseReg()) |breg| { | 1245 | if (plus[1].getBaseReg()) |breg| { |
| 1213 | if (plus[0].getConst(i65)) |offset| { | 1246 | if (plus[0].getConst(i65)) |offset| { |
| 1214 | try writeReg(breg, DW.OP.breg0, DW.OP.bregx, writer); | 1247 | try writeReg(breg, DW.OP.breg0, DW.OP.bregx, writer); |
| 1215 | try sleb128(writer, offset); | 1248 | try writer.writeSleb128(offset); |
| 1216 | break :done; | 1249 | break :done; |
| 1217 | } | 1250 | } |
| 1218 | } | 1251 | } |
| 1219 | if (plus[0].getConst(u64)) |uconst| { | 1252 | if (plus[0].getConst(u64)) |uconst| { |
| 1220 | try plus[1].write(adapter); | 1253 | try plus[1].write(adapter); |
| 1221 | try writer.writeByte(DW.OP.plus_uconst); | 1254 | try writer.writeByte(DW.OP.plus_uconst); |
| 1222 | try uleb128(writer, uconst); | 1255 | try writer.writeUleb128(uconst); |
| 1223 | break :done; | 1256 | break :done; |
| 1224 | } | 1257 | } |
| 1225 | if (plus[1].getConst(u64)) |uconst| { | 1258 | if (plus[1].getConst(u64)) |uconst| { |
| 1226 | try plus[0].write(adapter); | 1259 | try plus[0].write(adapter); |
| 1227 | try writer.writeByte(DW.OP.plus_uconst); | 1260 | try writer.writeByte(DW.OP.plus_uconst); |
| 1228 | try uleb128(writer, uconst); | 1261 | try writer.writeUleb128(uconst); |
| 1229 | break :done; | 1262 | break :done; |
| 1230 | } | 1263 | } |
| 1231 | try plus[0].write(adapter); | 1264 | try plus[0].write(adapter); |
| ... | @@ -1235,7 +1268,7 @@ pub const Loc = union(enum) { | ... | @@ -1235,7 +1268,7 @@ pub const Loc = union(enum) { |
| 1235 | .reg => |reg| try writeReg(reg, DW.OP.reg0, DW.OP.regx, writer), | 1268 | .reg => |reg| try writeReg(reg, DW.OP.reg0, DW.OP.regx, writer), |
| 1236 | .breg => |breg| { | 1269 | .breg => |breg| { |
| 1237 | try writeReg(breg, DW.OP.breg0, DW.OP.bregx, writer); | 1270 | try writeReg(breg, DW.OP.breg0, DW.OP.bregx, writer); |
| 1238 | try sleb128(writer, 0); | 1271 | try writer.writeSleb128(0); |
| 1239 | }, | 1272 | }, |
| 1240 | .push_object_address => try writer.writeByte(DW.OP.push_object_address), | 1273 | .push_object_address => try writer.writeByte(DW.OP.push_object_address), |
| 1241 | .call => |call| { | 1274 | .call => |call| { |
| ... | @@ -1249,7 +1282,7 @@ pub const Loc = union(enum) { | ... | @@ -1249,7 +1282,7 @@ pub const Loc = union(enum) { |
| 1249 | }, | 1282 | }, |
| 1250 | .implicit_value => |value| { | 1283 | .implicit_value => |value| { |
| 1251 | try writer.writeByte(DW.OP.implicit_value); | 1284 | try writer.writeByte(DW.OP.implicit_value); |
| 1252 | try uleb128(writer, value.len); | 1285 | try writer.writeUleb128(value.len); |
| 1253 | try writer.writeAll(value); | 1286 | try writer.writeAll(value); |
| 1254 | }, | 1287 | }, |
| 1255 | .stack_value => |value| { | 1288 | .stack_value => |value| { |
| ... | @@ -1259,25 +1292,25 @@ pub const Loc = union(enum) { | ... | @@ -1259,25 +1292,25 @@ pub const Loc = union(enum) { |
| 1259 | .implicit_pointer => |implicit_pointer| { | 1292 | .implicit_pointer => |implicit_pointer| { |
| 1260 | try writer.writeByte(DW.OP.implicit_pointer); | 1293 | try writer.writeByte(DW.OP.implicit_pointer); |
| 1261 | try adapter.infoEntry(implicit_pointer.unit, implicit_pointer.entry); | 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 | .wasm_ext => |wasm_ext| { | 1297 | .wasm_ext => |wasm_ext| { |
| 1265 | try writer.writeByte(DW.OP.WASM_location); | 1298 | try writer.writeByte(DW.OP.WASM_location); |
| 1266 | switch (wasm_ext) { | 1299 | switch (wasm_ext) { |
| 1267 | .local => |local| { | 1300 | .local => |local| { |
| 1268 | try writer.writeByte(DW.OP.WASM_local); | 1301 | try writer.writeByte(DW.OP.WASM_local); |
| 1269 | try uleb128(writer, local); | 1302 | try writer.writeUleb128(local); |
| 1270 | }, | 1303 | }, |
| 1271 | .global => |global| if (std.math.cast(u21, global)) |global_u21| { | 1304 | .global => |global| if (std.math.cast(u21, global)) |global_u21| { |
| 1272 | try writer.writeByte(DW.OP.WASM_global); | 1305 | try writer.writeByte(DW.OP.WASM_global); |
| 1273 | try uleb128(writer, global_u21); | 1306 | try writer.writeUleb128(global_u21); |
| 1274 | } else { | 1307 | } else { |
| 1275 | try writer.writeByte(DW.OP.WASM_global_u32); | 1308 | try writer.writeByte(DW.OP.WASM_global_u32); |
| 1276 | try writer.writeInt(u32, global, adapter.endian()); | 1309 | try writer.writeInt(u32, global, adapter.endian()); |
| 1277 | }, | 1310 | }, |
| 1278 | .operand_stack => |operand_stack| { | 1311 | .operand_stack => |operand_stack| { |
| 1279 | try writer.writeByte(DW.OP.WASM_operand_stack); | 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,22 +1342,22 @@ pub const Cfa = union(enum) { |
| 1309 | const RegOff = struct { reg: u32, off: i64 }; | 1342 | const RegOff = struct { reg: u32, off: i64 }; |
| 1310 | const RegExpr = struct { reg: u32, expr: Loc }; | 1343 | const RegExpr = struct { reg: u32, expr: Loc }; |
| 1311 | | 1344 | |
| 1312 | fn write(cfa: Cfa, wip_nav: *WipNav) UpdateError!void { | 1345 | fn write(cfa: Cfa, wip_nav: *WipNav) (UpdateError || Writer.Error)!void { |
| 1313 | const writer = wip_nav.debug_frame.writer(wip_nav.dwarf.gpa); | 1346 | const dfw = &wip_nav.debug_frame.writer; |
| 1314 | switch (cfa) { | 1347 | switch (cfa) { |
| 1315 | .nop => try writer.writeByte(DW.CFA.nop), | 1348 | .nop => try dfw.writeByte(DW.CFA.nop), |
| 1316 | .advance_loc => |loc| { | 1349 | .advance_loc => |loc| { |
| 1317 | const delta = @divExact(loc - wip_nav.cfi.loc, wip_nav.dwarf.debug_frame.header.code_alignment_factor); | 1350 | const delta = @divExact(loc - wip_nav.cfi.loc, wip_nav.dwarf.debug_frame.header.code_alignment_factor); |
| 1318 | if (delta == 0) {} else if (std.math.cast(u6, delta)) |small_delta| | 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 | else if (std.math.cast(u8, delta)) |ubyte_delta| | 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 | else if (std.math.cast(u16, delta)) |uhalf_delta| { | 1355 | else if (std.math.cast(u16, delta)) |uhalf_delta| { |
| 1323 | try writer.writeByte(DW.CFA.advance_loc2); | 1356 | try dfw.writeByte(DW.CFA.advance_loc2); |
| 1324 | try writer.writeInt(u16, uhalf_delta, wip_nav.dwarf.endian); | 1357 | try dfw.writeInt(u16, uhalf_delta, wip_nav.dwarf.endian); |
| 1325 | } else if (std.math.cast(u32, delta)) |uword_delta| { | 1358 | } else if (std.math.cast(u32, delta)) |uword_delta| { |
| 1326 | try writer.writeByte(DW.CFA.advance_loc4); | 1359 | try dfw.writeByte(DW.CFA.advance_loc4); |
| 1327 | try writer.writeInt(u32, uword_delta, wip_nav.dwarf.endian); | 1360 | try dfw.writeInt(u32, uword_delta, wip_nav.dwarf.endian); |
| 1328 | } | 1361 | } |
| 1329 | wip_nav.cfi.loc = loc; | 1362 | wip_nav.cfi.loc = loc; |
| 1330 | }, | 1363 | }, |
| ... | @@ -1336,41 +1369,41 @@ pub const Cfa = union(enum) { | ... | @@ -1336,41 +1369,41 @@ pub const Cfa = union(enum) { |
| 1336 | }, wip_nav.dwarf.debug_frame.header.data_alignment_factor); | 1369 | }, wip_nav.dwarf.debug_frame.header.data_alignment_factor); |
| 1337 | if (std.math.cast(u63, factored_off)) |unsigned_off| { | 1370 | if (std.math.cast(u63, factored_off)) |unsigned_off| { |
| 1338 | if (std.math.cast(u6, reg_off.reg)) |small_reg| { | 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 | } else { | 1373 | } else { |
| 1341 | try writer.writeByte(DW.CFA.offset_extended); | 1374 | try dfw.writeByte(DW.CFA.offset_extended); |
| 1342 | try uleb128(writer, reg_off.reg); | 1375 | try dfw.writeUleb128(reg_off.reg); |
| 1343 | } | 1376 | } |
| 1344 | try uleb128(writer, unsigned_off); | 1377 | try dfw.writeUleb128(unsigned_off); |
| 1345 | } else { | 1378 | } else { |
| 1346 | try writer.writeByte(DW.CFA.offset_extended_sf); | 1379 | try dfw.writeByte(DW.CFA.offset_extended_sf); |
| 1347 | try uleb128(writer, reg_off.reg); | 1380 | try dfw.writeUleb128(reg_off.reg); |
| 1348 | try sleb128(writer, factored_off); | 1381 | try dfw.writeSleb128(factored_off); |
| 1349 | } | 1382 | } |
| 1350 | }, | 1383 | }, |
| 1351 | .restore => |reg| if (std.math.cast(u6, reg)) |small_reg| | 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 | else { | 1386 | else { |
| 1354 | try writer.writeByte(DW.CFA.restore_extended); | 1387 | try dfw.writeByte(DW.CFA.restore_extended); |
| 1355 | try uleb128(writer, reg); | 1388 | try dfw.writeUleb128(reg); |
| 1356 | }, | 1389 | }, |
| 1357 | .undefined => |reg| { | 1390 | .undefined => |reg| { |
| 1358 | try writer.writeByte(DW.CFA.undefined); | 1391 | try dfw.writeByte(DW.CFA.undefined); |
| 1359 | try uleb128(writer, reg); | 1392 | try dfw.writeUleb128(reg); |
| 1360 | }, | 1393 | }, |
| 1361 | .same_value => |reg| { | 1394 | .same_value => |reg| { |
| 1362 | try writer.writeByte(DW.CFA.same_value); | 1395 | try dfw.writeByte(DW.CFA.same_value); |
| 1363 | try uleb128(writer, reg); | 1396 | try dfw.writeUleb128(reg); |
| 1364 | }, | 1397 | }, |
| 1365 | .register => |regs| if (regs[0] != regs[1]) { | 1398 | .register => |regs| if (regs[0] != regs[1]) { |
| 1366 | try writer.writeByte(DW.CFA.register); | 1399 | try dfw.writeByte(DW.CFA.register); |
| 1367 | for (regs) |reg| try uleb128(writer, reg); | 1400 | for (regs) |reg| try dfw.writeUleb128(reg); |
| 1368 | } else { | 1401 | } else { |
| 1369 | try writer.writeByte(DW.CFA.same_value); | 1402 | try dfw.writeByte(DW.CFA.same_value); |
| 1370 | try uleb128(writer, regs[0]); | 1403 | try dfw.writeUleb128(regs[0]); |
| 1371 | }, | 1404 | }, |
| 1372 | .remember_state => try writer.writeByte(DW.CFA.remember_state), | 1405 | .remember_state => try dfw.writeByte(DW.CFA.remember_state), |
| 1373 | .restore_state => try writer.writeByte(DW.CFA.restore_state), | 1406 | .restore_state => try dfw.writeByte(DW.CFA.restore_state), |
| 1374 | .def_cfa, .def_cfa_register, .def_cfa_offset, .adjust_cfa_offset => { | 1407 | .def_cfa, .def_cfa_register, .def_cfa_offset, .adjust_cfa_offset => { |
| 1375 | const reg_off: RegOff = switch (cfa) { | 1408 | const reg_off: RegOff = switch (cfa) { |
| 1376 | else => unreachable, | 1409 | else => unreachable, |
| ... | @@ -1383,51 +1416,51 @@ pub const Cfa = union(enum) { | ... | @@ -1383,51 +1416,51 @@ pub const Cfa = union(enum) { |
| 1383 | const unsigned_off = std.math.cast(u63, reg_off.off); | 1416 | const unsigned_off = std.math.cast(u63, reg_off.off); |
| 1384 | if (reg_off.off == wip_nav.cfi.cfa.off) { | 1417 | if (reg_off.off == wip_nav.cfi.cfa.off) { |
| 1385 | if (changed_reg) { | 1418 | if (changed_reg) { |
| 1386 | try writer.writeByte(DW.CFA.def_cfa_register); | 1419 | try dfw.writeByte(DW.CFA.def_cfa_register); |
| 1387 | try uleb128(writer, reg_off.reg); | 1420 | try dfw.writeUleb128(reg_off.reg); |
| 1388 | } | 1421 | } |
| 1389 | } else if (switch (wip_nav.dwarf.debug_frame.header.data_alignment_factor) { | 1422 | } else if (switch (wip_nav.dwarf.debug_frame.header.data_alignment_factor) { |
| 1390 | 0 => unreachable, | 1423 | 0 => unreachable, |
| 1391 | 1 => unsigned_off != null, | 1424 | 1 => unsigned_off != null, |
| 1392 | else => |data_alignment_factor| @rem(reg_off.off, data_alignment_factor) != 0, | 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); | 1427 | try dfw.writeByte(if (changed_reg) DW.CFA.def_cfa else DW.CFA.def_cfa_offset); |
| 1395 | if (changed_reg) try uleb128(writer, reg_off.reg); | 1428 | if (changed_reg) try dfw.writeUleb128(reg_off.reg); |
| 1396 | try uleb128(writer, unsigned_off.?); | 1429 | try dfw.writeUleb128(unsigned_off.?); |
| 1397 | } else { | 1430 | } else { |
| 1398 | try writer.writeByte(if (changed_reg) DW.CFA.def_cfa_sf else DW.CFA.def_cfa_offset_sf); | 1431 | try dfw.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); | 1432 | if (changed_reg) try dfw.writeUleb128(reg_off.reg); |
| 1400 | try sleb128(writer, @divExact(reg_off.off, wip_nav.dwarf.debug_frame.header.data_alignment_factor)); | 1433 | try dfw.writeSleb128(@divExact(reg_off.off, wip_nav.dwarf.debug_frame.header.data_alignment_factor)); |
| 1401 | } | 1434 | } |
| 1402 | wip_nav.cfi.cfa = reg_off; | 1435 | wip_nav.cfi.cfa = reg_off; |
| 1403 | }, | 1436 | }, |
| 1404 | .def_cfa_expression => |expr| { | 1437 | .def_cfa_expression => |expr| { |
| 1405 | try writer.writeByte(DW.CFA.def_cfa_expression); | 1438 | try dfw.writeByte(DW.CFA.def_cfa_expression); |
| 1406 | try wip_nav.frameExprLoc(expr); | 1439 | try wip_nav.frameExprLoc(expr); |
| 1407 | }, | 1440 | }, |
| 1408 | .expression => |reg_expr| { | 1441 | .expression => |reg_expr| { |
| 1409 | try writer.writeByte(DW.CFA.expression); | 1442 | try dfw.writeByte(DW.CFA.expression); |
| 1410 | try uleb128(writer, reg_expr.reg); | 1443 | try dfw.writeUleb128(reg_expr.reg); |
| 1411 | try wip_nav.frameExprLoc(reg_expr.expr); | 1444 | try wip_nav.frameExprLoc(reg_expr.expr); |
| 1412 | }, | 1445 | }, |
| 1413 | .val_offset => |reg_off| { | 1446 | .val_offset => |reg_off| { |
| 1414 | const factored_off = @divExact(reg_off.off, wip_nav.dwarf.debug_frame.header.data_alignment_factor); | 1447 | const factored_off = @divExact(reg_off.off, wip_nav.dwarf.debug_frame.header.data_alignment_factor); |
| 1415 | if (std.math.cast(u63, factored_off)) |unsigned_off| { | 1448 | if (std.math.cast(u63, factored_off)) |unsigned_off| { |
| 1416 | try writer.writeByte(DW.CFA.val_offset); | 1449 | try dfw.writeByte(DW.CFA.val_offset); |
| 1417 | try uleb128(writer, reg_off.reg); | 1450 | try dfw.writeUleb128(reg_off.reg); |
| 1418 | try uleb128(writer, unsigned_off); | 1451 | try dfw.writeUleb128(unsigned_off); |
| 1419 | } else { | 1452 | } else { |
| 1420 | try writer.writeByte(DW.CFA.val_offset_sf); | 1453 | try dfw.writeByte(DW.CFA.val_offset_sf); |
| 1421 | try uleb128(writer, reg_off.reg); | 1454 | try dfw.writeUleb128(reg_off.reg); |
| 1422 | try sleb128(writer, factored_off); | 1455 | try dfw.writeSleb128(factored_off); |
| 1423 | } | 1456 | } |
| 1424 | }, | 1457 | }, |
| 1425 | .val_expression => |reg_expr| { | 1458 | .val_expression => |reg_expr| { |
| 1426 | try writer.writeByte(DW.CFA.val_expression); | 1459 | try dfw.writeByte(DW.CFA.val_expression); |
| 1427 | try uleb128(writer, reg_expr.reg); | 1460 | try dfw.writeUleb128(reg_expr.reg); |
| 1428 | try wip_nav.frameExprLoc(reg_expr.expr); | 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,24 +1483,30 @@ pub const WipNav = struct { |
| 1450 | loc: u32, | 1483 | loc: u32, |
| 1451 | cfa: Cfa.RegOff, | 1484 | cfa: Cfa.RegOff, |
| 1452 | }, | 1485 | }, |
| 1453 | debug_frame: std.ArrayListUnmanaged(u8), | 1486 | debug_frame: Writer.Allocating, |
| 1454 | debug_info: std.ArrayListUnmanaged(u8), | 1487 | debug_info: Writer.Allocating, |
| 1455 | debug_line: std.ArrayListUnmanaged(u8), | 1488 | debug_line: Writer.Allocating, |
| 1456 | debug_loclists: std.ArrayListUnmanaged(u8), | 1489 | debug_loclists: Writer.Allocating, |
| 1457 | pending_lazy: PendingLazy, | 1490 | pending_lazy: PendingLazy, |
| 1458 | | 1491 | |
| 1459 | pub fn deinit(wip_nav: *WipNav) void { | 1492 | pub fn deinit(wip_nav: *WipNav) void { |
| 1460 | const gpa = wip_nav.dwarf.gpa; | 1493 | const gpa = wip_nav.dwarf.gpa; |
| 1461 | if (wip_nav.func != .none) wip_nav.blocks.deinit(gpa); | 1494 | if (wip_nav.func != .none) wip_nav.blocks.deinit(gpa); |
| 1462 | wip_nav.debug_frame.deinit(gpa); | 1495 | wip_nav.debug_frame.deinit(); |
| 1463 | wip_nav.debug_info.deinit(gpa); | 1496 | wip_nav.debug_info.deinit(); |
| 1464 | wip_nav.debug_line.deinit(gpa); | 1497 | wip_nav.debug_line.deinit(); |
| 1465 | wip_nav.debug_loclists.deinit(gpa); | 1498 | wip_nav.debug_loclists.deinit(); |
| 1466 | wip_nav.pending_lazy.types.deinit(gpa); | 1499 | wip_nav.pending_lazy.types.deinit(gpa); |
| 1467 | wip_nav.pending_lazy.values.deinit(gpa); | 1500 | wip_nav.pending_lazy.values.deinit(gpa); |
| 1468 | } | 1501 | } |
| 1469 | | 1502 | |
| 1470 | pub fn genDebugFrame(wip_nav: *WipNav, loc: u32, cfa: Cfa) UpdateError!void { | 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 | assert(wip_nav.func != .none); | 1510 | assert(wip_nav.func != .none); |
| 1472 | if (wip_nav.dwarf.debug_frame.header.format == .none) return; | 1511 | if (wip_nav.dwarf.debug_frame.header.format == .none) return; |
| 1473 | const loc_cfa: Cfa = .{ .advance_loc = loc }; | 1512 | const loc_cfa: Cfa = .{ .advance_loc = loc }; |
| ... | @@ -1483,6 +1522,18 @@ pub const WipNav = struct { | ... | @@ -1483,6 +1522,18 @@ pub const WipNav = struct { |
| 1483 | ty: Type, | 1522 | ty: Type, |
| 1484 | loc: Loc, | 1523 | loc: Loc, |
| 1485 | ) UpdateError!void { | 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 | assert(wip_nav.func != .none); | 1537 | assert(wip_nav.func != .none); |
| 1487 | try wip_nav.abbrevCode(switch (tag) { | 1538 | try wip_nav.abbrevCode(switch (tag) { |
| 1488 | .arg => if (opt_name) |_| .arg else .unnamed_arg, | 1539 | .arg => if (opt_name) |_| .arg else .unnamed_arg, |
| ... | @@ -1502,6 +1553,18 @@ pub const WipNav = struct { | ... | @@ -1502,6 +1553,18 @@ pub const WipNav = struct { |
| 1502 | opt_name: ?[]const u8, | 1553 | opt_name: ?[]const u8, |
| 1503 | val: Value, | 1554 | val: Value, |
| 1504 | ) UpdateError!void { | 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 | assert(wip_nav.func != .none); | 1568 | assert(wip_nav.func != .none); |
| 1506 | const pt = wip_nav.pt; | 1569 | const pt = wip_nav.pt; |
| 1507 | const zcu = pt.zcu; | 1570 | const zcu = pt.zcu; |
| ... | @@ -1529,17 +1592,28 @@ pub const WipNav = struct { | ... | @@ -1529,17 +1592,28 @@ pub const WipNav = struct { |
| 1529 | } | 1592 | } |
| 1530 | | 1593 | |
| 1531 | pub fn genVarArgsDebugInfo(wip_nav: *WipNav) UpdateError!void { | 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 | assert(wip_nav.func != .none); | 1601 | assert(wip_nav.func != .none); |
| 1533 | try wip_nav.abbrevCode(.is_var_args); | 1602 | try wip_nav.abbrevCode(.is_var_args); |
| 1534 | wip_nav.any_children = true; | 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 | wip_nav: *WipNav, | 1612 | wip_nav: *WipNav, |
| 1539 | delta_line: i33, | 1613 | delta_line: i33, |
| 1540 | delta_pc: u64, | 1614 | delta_pc: u64, |
| 1541 | ) error{OutOfMemory}!void { | 1615 | ) Writer.Error!void { |
| 1542 | const dlw = wip_nav.debug_line.writer(wip_nav.dwarf.gpa); | 1616 | const dlw = &wip_nav.debug_line.writer; |
| 1543 | | 1617 | |
| 1544 | const header = wip_nav.dwarf.debug_line.header; | 1618 | const header = wip_nav.dwarf.debug_line.header; |
| 1545 | assert(header.maximum_operations_per_instruction == 1); | 1619 | assert(header.maximum_operations_per_instruction == 1); |
| ... | @@ -1550,7 +1624,7 @@ pub const WipNav = struct { | ... | @@ -1550,7 +1624,7 @@ pub const WipNav = struct { |
| 1550 | remaining: { | 1624 | remaining: { |
| 1551 | assert(delta_line != 0); | 1625 | assert(delta_line != 0); |
| 1552 | try dlw.writeByte(DW.LNS.advance_line); | 1626 | try dlw.writeByte(DW.LNS.advance_line); |
| 1553 | try sleb128(dlw, delta_line); | 1627 | try dlw.writeSleb128(delta_line); |
| 1554 | break :remaining 0; | 1628 | break :remaining 0; |
| 1555 | } else delta_line); | 1629 | } else delta_line); |
| 1556 | | 1630 | |
| ... | @@ -1559,7 +1633,7 @@ pub const WipNav = struct { | ... | @@ -1559,7 +1633,7 @@ pub const WipNav = struct { |
| 1559 | const max_op_advance: u9 = (std.math.maxInt(u8) - header.opcode_base) / header.line_range; | 1633 | const max_op_advance: u9 = (std.math.maxInt(u8) - header.opcode_base) / header.line_range; |
| 1560 | const remaining_op_advance: u8 = @intCast(if (op_advance >= 2 * max_op_advance) remaining: { | 1634 | const remaining_op_advance: u8 = @intCast(if (op_advance >= 2 * max_op_advance) remaining: { |
| 1561 | try dlw.writeByte(DW.LNS.advance_pc); | 1635 | try dlw.writeByte(DW.LNS.advance_pc); |
| 1562 | try uleb128(dlw, op_advance); | 1636 | try dlw.writeUleb128(op_advance); |
| 1563 | break :remaining 0; | 1637 | break :remaining 0; |
| 1564 | } else if (op_advance >= max_op_advance) remaining: { | 1638 | } else if (op_advance >= max_op_advance) remaining: { |
| 1565 | try dlw.writeByte(DW.LNS.const_add_pc); | 1639 | try dlw.writeByte(DW.LNS.const_add_pc); |
| ... | @@ -1573,53 +1647,82 @@ pub const WipNav = struct { | ... | @@ -1573,53 +1647,82 @@ pub const WipNav = struct { |
| 1573 | (header.line_range * remaining_op_advance) + header.opcode_base)); | 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 { | 1650 | pub fn setColumn(wip_nav: *WipNav, column: u32) Allocator.Error!void { |
| 1577 | const dlw = wip_nav.debug_line.writer(wip_nav.dwarf.gpa); | 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 | try dlw.writeByte(DW.LNS.set_column); | 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 { | 1661 | pub fn negateStmt(wip_nav: *WipNav) Allocator.Error!void { |
| 1583 | const dlw = wip_nav.debug_line.writer(wip_nav.dwarf.gpa); | 1662 | return wip_nav.negateStmtWriterError() catch |err| switch (err) { |
| 1584 | try dlw.writeByte(DW.LNS.negate_stmt); | 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 { | 1670 | pub fn setPrologueEnd(wip_nav: *WipNav) Allocator.Error!void { |
| 1588 | const dlw = wip_nav.debug_line.writer(wip_nav.dwarf.gpa); | 1671 | return wip_nav.setPrologueEndWriterError() catch |err| switch (err) { |
| 1589 | try dlw.writeByte(DW.LNS.set_prologue_end); | 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 { | 1679 | pub fn setEpilogueBegin(wip_nav: *WipNav) Allocator.Error!void { |
| 1593 | const dlw = wip_nav.debug_line.writer(wip_nav.dwarf.gpa); | 1680 | return wip_nav.setEpilogueBeginWriterError() catch |err| switch (err) { |
| 1594 | try dlw.writeByte(DW.LNS.set_epilogue_begin); | 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 | pub fn enterBlock(wip_nav: *WipNav, code_off: u64) UpdateError!void { | 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 | const dwarf = wip_nav.dwarf; | 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 | const block = try wip_nav.blocks.addOne(dwarf.gpa); | 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 | try wip_nav.abbrevCode(.block); | 1700 | try wip_nav.abbrevCode(.block); |
| 1604 | block.low_pc_off = code_off; | 1701 | block.low_pc_off = code_off; |
| 1605 | try wip_nav.infoAddrSym(wip_nav.func_sym_index, code_off); | 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 | try diw.writeInt(u32, 0, dwarf.endian); | 1704 | try diw.writeInt(u32, 0, dwarf.endian); |
| 1608 | wip_nav.any_children = false; | 1705 | wip_nav.any_children = false; |
| 1609 | } | 1706 | } |
| 1610 | | 1707 | |
| 1611 | pub fn leaveBlock(wip_nav: *WipNav, code_off: u64) UpdateError!void { | 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 | const block_bytes = comptime uleb128Bytes(@intFromEnum(AbbrevCode.block)); | 1715 | const block_bytes = comptime uleb128Bytes(@intFromEnum(AbbrevCode.block)); |
| 1613 | const block = wip_nav.blocks.pop().?; | 1716 | const block = wip_nav.blocks.pop().?; |
| 1614 | if (wip_nav.any_children) | 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 | else | 1719 | else |
| 1617 | std.leb.writeUnsignedFixed( | 1720 | std.leb.writeUnsignedFixed( |
| 1618 | block_bytes, | 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 | try wip_nav.dwarf.refAbbrevCode(.empty_block), | 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 | wip_nav.any_children = true; | 1726 | wip_nav.any_children = true; |
| 1624 | } | 1727 | } |
| 1625 | | 1728 | |
| ... | @@ -1630,41 +1733,69 @@ pub const WipNav = struct { | ... | @@ -1630,41 +1733,69 @@ pub const WipNav = struct { |
| 1630 | line: u32, | 1733 | line: u32, |
| 1631 | column: u32, | 1734 | column: u32, |
| 1632 | ) UpdateError!void { | 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 | const dwarf = wip_nav.dwarf; | 1748 | const dwarf = wip_nav.dwarf; |
| 1634 | const zcu = wip_nav.pt.zcu; | 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 | const block = try wip_nav.blocks.addOne(dwarf.gpa); | 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 | try wip_nav.abbrevCode(.inlined_func); | 1754 | try wip_nav.abbrevCode(.inlined_func); |
| 1640 | try wip_nav.refNav(zcu.funcInfo(func).owner_nav); | 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); | 1756 | try diw.writeUleb128(zcu.navSrcLine(zcu.funcInfo(wip_nav.func).owner_nav) + line + 1); |
| 1642 | try uleb128(diw, column + 1); | 1757 | try diw.writeUleb128(column + 1); |
| 1643 | block.low_pc_off = code_off; | 1758 | block.low_pc_off = code_off; |
| 1644 | try wip_nav.infoAddrSym(wip_nav.func_sym_index, code_off); | 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 | try diw.writeInt(u32, 0, dwarf.endian); | 1761 | try diw.writeInt(u32, 0, dwarf.endian); |
| 1647 | try wip_nav.setInlineFunc(func); | 1762 | try wip_nav.setInlineFunc(func); |
| 1648 | wip_nav.any_children = false; | 1763 | wip_nav.any_children = false; |
| 1649 | } | 1764 | } |
| 1650 | | 1765 | |
| 1651 | pub fn leaveInlineFunc(wip_nav: *WipNav, func: InternPool.Index, code_off: u64) UpdateError!void { | 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 | const inlined_func_bytes = comptime uleb128Bytes(@intFromEnum(AbbrevCode.inlined_func)); | 1777 | const inlined_func_bytes = comptime uleb128Bytes(@intFromEnum(AbbrevCode.inlined_func)); |
| 1653 | const block = wip_nav.blocks.pop().?; | 1778 | const block = wip_nav.blocks.pop().?; |
| 1654 | if (wip_nav.any_children) | 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 | else | 1781 | else |
| 1657 | std.leb.writeUnsignedFixed( | 1782 | std.leb.writeUnsignedFixed( |
| 1658 | inlined_func_bytes, | 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 | try wip_nav.dwarf.refAbbrevCode(.empty_inlined_func), | 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 | try wip_nav.setInlineFunc(func); | 1788 | try wip_nav.setInlineFunc(func); |
| 1664 | wip_nav.any_children = true; | 1789 | wip_nav.any_children = true; |
| 1665 | } | 1790 | } |
| 1666 | | 1791 | |
| 1667 | pub fn setInlineFunc(wip_nav: *WipNav, func: InternPool.Index) UpdateError!void { | 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 | const zcu = wip_nav.pt.zcu; | 1799 | const zcu = wip_nav.pt.zcu; |
| 1669 | const dwarf = wip_nav.dwarf; | 1800 | const dwarf = wip_nav.dwarf; |
| 1670 | if (wip_nav.func == func) return; | 1801 | if (wip_nav.func == func) return; |
| ... | @@ -1673,22 +1804,22 @@ pub const WipNav = struct { | ... | @@ -1673,22 +1804,22 @@ pub const WipNav = struct { |
| 1673 | const new_file = zcu.navFileScopeIndex(new_func_info.owner_nav); | 1804 | const new_file = zcu.navFileScopeIndex(new_func_info.owner_nav); |
| 1674 | const new_unit = try dwarf.getUnit(zcu.fileByIndex(new_file).mod.?); | 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 | if (dwarf.incremental()) { | 1808 | if (dwarf.incremental()) { |
| 1678 | const new_nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, new_func_info.owner_nav); | 1809 | const new_nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, new_func_info.owner_nav); |
| 1679 | errdefer _ = if (!new_nav_gop.found_existing) dwarf.navs.pop(); | 1810 | errdefer _ = if (!new_nav_gop.found_existing) dwarf.navs.pop(); |
| 1680 | if (!new_nav_gop.found_existing) new_nav_gop.value_ptr.* = try dwarf.addCommonEntry(new_unit); | 1811 | if (!new_nav_gop.found_existing) new_nav_gop.value_ptr.* = try dwarf.addCommonEntry(new_unit); |
| 1681 | | 1812 | |
| 1682 | try dlw.writeByte(DW.LNS.extended_op); | 1813 | try dlw.writeByte(DW.LNS.extended_op); |
| 1683 | try uleb128(dlw, 1 + dwarf.sectionOffsetBytes()); | 1814 | try dlw.writeUleb128(1 + dwarf.sectionOffsetBytes()); |
| 1684 | try dlw.writeByte(DW.LNE.ZIG_set_decl); | 1815 | try dlw.writeByte(DW.LNE.ZIG_set_decl); |
| 1685 | try dwarf.debug_line.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).cross_section_relocs.append(dwarf.gpa, .{ | 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 | .target_sec = .debug_info, | 1818 | .target_sec = .debug_info, |
| 1688 | .target_unit = new_unit, | 1819 | .target_unit = new_unit, |
| 1689 | .target_entry = new_nav_gop.value_ptr.toOptional(), | 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 | return; | 1823 | return; |
| 1693 | } | 1824 | } |
| 1694 | | 1825 | |
| ... | @@ -1700,14 +1831,14 @@ pub const WipNav = struct { | ... | @@ -1700,14 +1831,14 @@ pub const WipNav = struct { |
| 1700 | const file_gop = try mod_info.files.getOrPut(dwarf.gpa, new_file); | 1831 | const file_gop = try mod_info.files.getOrPut(dwarf.gpa, new_file); |
| 1701 | | 1832 | |
| 1702 | try dlw.writeByte(DW.LNS.set_file); | 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 | const old_src_line: i33 = zcu.navSrcLine(old_func_info.owner_nav); | 1837 | const old_src_line: i33 = zcu.navSrcLine(old_func_info.owner_nav); |
| 1707 | const new_src_line: i33 = zcu.navSrcLine(new_func_info.owner_nav); | 1838 | const new_src_line: i33 = zcu.navSrcLine(new_func_info.owner_nav); |
| 1708 | if (new_src_line != old_src_line) { | 1839 | if (new_src_line != old_src_line) { |
| 1709 | try dlw.writeByte(DW.LNS.advance_line); | 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 | wip_nav.func = func; | 1844 | wip_nav.func = func; |
| ... | @@ -1725,16 +1856,23 @@ pub const WipNav = struct { | ... | @@ -1725,16 +1856,23 @@ pub const WipNav = struct { |
| 1725 | try wip_nav.externalReloc(&wip_nav.dwarf.debug_frame.section, reloc); | 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 { | 1859 | fn abbrevCode(wip_nav: *WipNav, abbrev_code: AbbrevCode) (UpdateError || Writer.Error)!void { |
| 1729 | try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), try wip_nav.dwarf.refAbbrevCode(abbrev_code)); | 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 | const dwarf = wip_nav.dwarf; | 1871 | const dwarf = wip_nav.dwarf; |
| 1734 | const gpa = dwarf.gpa; | 1872 | const gpa = dwarf.gpa; |
| 1735 | const entry_ptr = @field(dwarf, @tagName(sec)).section.getUnit(wip_nav.unit).getEntry(wip_nav.entry); | 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)); | 1874 | const sw = &@field(wip_nav, @tagName(sec)).writer; |
| 1737 | const source_off: u32 = @intCast(bytes.items.len); | 1875 | const source_off: u32 = @intCast(sw.end); |
| 1738 | if (target_sec != sec) { | 1876 | if (target_sec != sec) { |
| 1739 | try entry_ptr.cross_section_relocs.append(gpa, .{ | 1877 | try entry_ptr.cross_section_relocs.append(gpa, .{ |
| 1740 | .source_off = source_off, | 1878 | .source_off = source_off, |
| ... | @@ -1757,109 +1895,136 @@ pub const WipNav = struct { | ... | @@ -1757,109 +1895,136 @@ pub const WipNav = struct { |
| 1757 | .target_off = target_off, | 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 | try wip_nav.sectionOffset(.debug_info, target_sec, target_unit, target_entry, target_off); | 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 | try wip_nav.infoSectionOffset(.debug_str, StringSection.unit, try wip_nav.dwarf.debug_str.addString(wip_nav.dwarf, str), 0); | 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 | const ExprLocCounter = struct { | 1915 | const ExprLocCounter = struct { |
| 1772 | stream: Writer.Discarding, | 1916 | dw: Writer.Discarding, |
| 1773 | section_offset_bytes: u32, | 1917 | section_offset_bytes: u32, |
| 1774 | address_size: AddressSize, | 1918 | address_size: AddressSize, |
| 1775 | fn init(dwarf: *Dwarf, trash_buffer: []u8) ExprLocCounter { | 1919 | fn init(dwarf: *Dwarf, buf: []u8) ExprLocCounter { |
| 1776 | return .{ | 1920 | return .{ |
| 1777 | .stream = .init(trash_buffer), | 1921 | .dw = .init(buf), |
| 1778 | .section_offset_bytes = dwarf.sectionOffsetBytes(), | 1922 | .section_offset_bytes = dwarf.sectionOffsetBytes(), |
| 1779 | .address_size = dwarf.address_size, | 1923 | .address_size = dwarf.address_size, |
| 1780 | }; | 1924 | }; |
| 1781 | } | 1925 | } |
| 1782 | fn writer(counter: *ExprLocCounter) *Writer { | 1926 | fn writer(counter: *ExprLocCounter) *Writer { |
| 1783 | return &counter.stream.writer; | 1927 | return &counter.dw.writer; |
| 1784 | } | 1928 | } |
| 1785 | fn endian(_: ExprLocCounter) std.builtin.Endian { | 1929 | fn endian(_: ExprLocCounter) std.builtin.Endian { |
| 1786 | return @import("builtin").cpu.arch.endian(); | 1930 | return @import("builtin").cpu.arch.endian(); |
| 1787 | } | 1931 | } |
| 1788 | fn addrSym(counter: *ExprLocCounter, _: u32) error{}!void { | 1932 | fn addrSym(counter: *ExprLocCounter, _: u32) Writer.Error!void { |
| 1789 | counter.stream.count += @intFromEnum(counter.address_size); | 1933 | try counter.dw.writer.splatByteAll(undefined, @intFromEnum(counter.address_size)); |
| 1790 | } | 1934 | } |
| 1791 | fn infoEntry(counter: *ExprLocCounter, _: Unit.Index, _: Entry.Index) error{}!void { | 1935 | fn infoEntry(counter: *ExprLocCounter, _: Unit.Index, _: Entry.Index) Writer.Error!void { |
| 1792 | counter.stream.count += counter.section_offset_bytes; | 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 { | 1940 | fn infoExprLoc(wip_nav: *WipNav, loc: Loc) (UpdateError || Writer.Error)!void { |
| 1797 | var trash_buffer: [64]u8 = undefined; | 1941 | var buf: [64]u8 = undefined; |
| 1798 | var counter: ExprLocCounter = .init(wip_nav.dwarf, &trash_buffer); | 1942 | var counter: ExprLocCounter = .init(wip_nav.dwarf, &buf); |
| 1799 | try loc.write(&counter); | 1943 | try loc.write(&counter); |
| 1800 | | 1944 | |
| 1801 | const adapter: struct { | 1945 | const adapter: struct { |
| 1802 | wip_nav: *WipNav, | 1946 | wip_nav: *WipNav, |
| 1803 | fn writer(ctx: @This()) std.ArrayListUnmanaged(u8).Writer { | 1947 | fn writer(ctx: @This()) *Writer { |
| 1804 | return ctx.wip_nav.debug_info.writer(ctx.wip_nav.dwarf.gpa); | 1948 | return &ctx.wip_nav.debug_info.writer; |
| 1805 | } | 1949 | } |
| 1806 | fn endian(ctx: @This()) std.builtin.Endian { | 1950 | fn endian(ctx: @This()) std.builtin.Endian { |
| 1807 | return ctx.wip_nav.dwarf.endian; | 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 | try ctx.wip_nav.infoAddrSym(sym_index, 0); | 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 | try ctx.wip_nav.infoSectionOffset(.debug_info, unit, entry, 0); | 1961 | try ctx.wip_nav.infoSectionOffset(.debug_info, unit, entry, 0); |
| 1814 | } | 1962 | } |
| 1815 | } = .{ .wip_nav = wip_nav }; | 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 | try loc.write(adapter); | 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 | try wip_nav.infoExternalReloc(.{ | 1974 | try wip_nav.infoExternalReloc(.{ |
| 1822 | .source_off = @intCast(wip_nav.debug_info.items.len), | 1975 | .source_off = @intCast(diw.end), |
| 1823 | .target_sym = sym_index, | 1976 | .target_sym = sym_index, |
| 1824 | .target_off = sym_off, | 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 { | 1982 | fn frameExprLoc(wip_nav: *WipNav, loc: Loc) (UpdateError || Writer.Error)!void { |
| 1830 | var trash_buffer: [64]u8 = undefined; | 1983 | var buf: [64]u8 = undefined; |
| 1831 | var counter: ExprLocCounter = .init(wip_nav.dwarf, &trash_buffer); | 1984 | var counter: ExprLocCounter = .init(wip_nav.dwarf, &buf); |
| 1832 | try loc.write(&counter); | 1985 | try loc.write(&counter); |
| 1833 | | 1986 | |
| 1834 | const adapter: struct { | 1987 | const adapter: struct { |
| 1835 | wip_nav: *WipNav, | 1988 | wip_nav: *WipNav, |
| 1836 | fn writer(ctx: @This()) std.ArrayListUnmanaged(u8).Writer { | 1989 | fn writer(ctx: @This()) *Writer { |
| 1837 | return ctx.wip_nav.debug_frame.writer(ctx.wip_nav.dwarf.gpa); | 1990 | return &ctx.wip_nav.debug_frame.writer; |
| 1838 | } | 1991 | } |
| 1839 | fn endian(ctx: @This()) std.builtin.Endian { | 1992 | fn endian(ctx: @This()) std.builtin.Endian { |
| 1840 | return ctx.wip_nav.dwarf.endian; | 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 | try ctx.wip_nav.frameAddrSym(sym_index, 0); | 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 | try ctx.wip_nav.sectionOffset(.debug_frame, .debug_info, unit, entry, 0); | 2003 | try ctx.wip_nav.sectionOffset(.debug_frame, .debug_info, unit, entry, 0); |
| 1847 | } | 2004 | } |
| 1848 | } = .{ .wip_nav = wip_nav }; | 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 | try loc.write(adapter); | 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 | try wip_nav.frameExternalReloc(.{ | 2016 | try wip_nav.frameExternalReloc(.{ |
| 1855 | .source_off = @intCast(wip_nav.debug_frame.items.len), | 2017 | .source_off = @intCast(dfw.end), |
| 1856 | .target_sym = sym_index, | 2018 | .target_sym = sym_index, |
| 1857 | .target_off = sym_off, | 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 | const zcu = wip_nav.pt.zcu; | 2028 | const zcu = wip_nav.pt.zcu; |
| 1864 | const ip = &zcu.intern_pool; | 2029 | const ip = &zcu.intern_pool; |
| 1865 | const nav = ip.getNav(nav_index); | 2030 | const nav = ip.getNav(nav_index); |
| ... | @@ -1871,7 +2036,10 @@ pub const WipNav = struct { | ... | @@ -1871,7 +2036,10 @@ pub const WipNav = struct { |
| 1871 | return .{ unit, entry }; | 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 | const unit, const entry = try wip_nav.getNavEntry(nav_index); | 2043 | const unit, const entry = try wip_nav.getNavEntry(nav_index); |
| 1876 | try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0); | 2044 | try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0); |
| 1877 | } | 2045 | } |
| ... | @@ -1898,7 +2066,7 @@ pub const WipNav = struct { | ... | @@ -1898,7 +2066,7 @@ pub const WipNav = struct { |
| 1898 | return .{ unit, entry }; | 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 | const unit, const entry = try wip_nav.getTypeEntry(ty); | 2070 | const unit, const entry = try wip_nav.getTypeEntry(ty); |
| 1903 | try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0); | 2071 | try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0); |
| 1904 | } | 2072 | } |
| ... | @@ -1919,47 +2087,54 @@ pub const WipNav = struct { | ... | @@ -1919,47 +2087,54 @@ pub const WipNav = struct { |
| 1919 | return .{ unit, entry }; | 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 | const unit, const entry = try wip_nav.getValueEntry(value); | 2091 | const unit, const entry = try wip_nav.getValueEntry(value); |
| 1924 | try wip_nav.infoSectionOffset(.debug_info, unit, entry, 0); | 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 | const dwarf = wip_nav.dwarf; | 2096 | const dwarf = wip_nav.dwarf; |
| | 2097 | const diw = &wip_nav.debug_info.writer; |
| 1929 | const cross_entry_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).cross_entry_relocs; | 2098 | const cross_entry_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).cross_entry_relocs; |
| 1930 | const reloc_index: u32 = @intCast(cross_entry_relocs.items.len); | 2099 | const reloc_index: u32 = @intCast(cross_entry_relocs.items.len); |
| 1931 | try cross_entry_relocs.append(dwarf.gpa, .{ | 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 | .target_entry = undefined, | 2102 | .target_entry = undefined, |
| 1934 | .target_off = undefined, | 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 | return reloc_index; | 2106 | return reloc_index; |
| 1938 | } | 2107 | } |
| 1939 | | 2108 | |
| 1940 | fn finishForward(wip_nav: *WipNav, reloc_index: u32) void { | 2109 | fn finishForward(wip_nav: *WipNav, reloc_index: u32) void { |
| 1941 | const reloc = &wip_nav.dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).cross_entry_relocs.items[reloc_index]; | 2110 | const reloc = &wip_nav.dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).cross_entry_relocs.items[reloc_index]; |
| 1942 | reloc.target_entry = wip_nav.entry.toOptional(); | 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 | const ty = val.typeOf(wip_nav.pt.zcu); | 2120 | const ty = val.typeOf(wip_nav.pt.zcu); |
| 1948 | const diw = wip_nav.debug_info.writer(wip_nav.dwarf.gpa); | 2121 | const diw = &wip_nav.debug_info.writer; |
| 1949 | const bytes = if (ty.hasRuntimeBits(wip_nav.pt.zcu)) ty.abiSize(wip_nav.pt.zcu) else 0; | 2122 | const size = if (ty.hasRuntimeBits(wip_nav.pt.zcu)) ty.abiSize(wip_nav.pt.zcu) else 0; |
| 1950 | try uleb128(diw, bytes); | 2123 | try diw.writeUleb128(size); |
| 1951 | if (bytes == 0) return; | 2124 | if (size == 0) return; |
| 1952 | const old_len = wip_nav.debug_info.items.len; | 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 | try codegen.generateSymbol( | 2128 | try codegen.generateSymbol( |
| 1954 | wip_nav.dwarf.bin_file, | 2129 | wip_nav.dwarf.bin_file, |
| 1955 | wip_nav.pt, | 2130 | wip_nav.pt, |
| 1956 | src_loc, | 2131 | src_loc, |
| 1957 | val, | 2132 | val, |
| 1958 | &wip_nav.debug_info, | 2133 | &bytes, |
| 1959 | .{ .debug_output = .{ .dwarf = wip_nav } }, | 2134 | .{ .debug_output = .{ .dwarf = wip_nav } }, |
| 1960 | ); | 2135 | ); |
| 1961 | if (old_len + bytes != wip_nav.debug_info.items.len) { | 2136 | if (old_len + size != bytes.items.len) { |
| 1962 | std.debug.print("{f} [{}]: {} != {}\n", .{ ty.fmt(wip_nav.pt), ty.toIntern(), bytes, wip_nav.debug_info.items.len - old_len }); | 2137 | std.debug.print("{f} [{}]: {} != {}\n", .{ ty.fmt(wip_nav.pt), ty.toIntern(), size, bytes.items.len - old_len }); |
| 1963 | unreachable; | 2138 | unreachable; |
| 1964 | } | 2139 | } |
| 1965 | } | 2140 | } |
| ... | @@ -1975,9 +2150,9 @@ pub const WipNav = struct { | ... | @@ -1975,9 +2150,9 @@ pub const WipNav = struct { |
| 1975 | abbrev_code: AbbrevCodeForForm, | 2150 | abbrev_code: AbbrevCodeForForm, |
| 1976 | ty: Type, | 2151 | ty: Type, |
| 1977 | big_int: std.math.big.int.Const, | 2152 | big_int: std.math.big.int.Const, |
| 1978 | ) UpdateError!void { | 2153 | ) (UpdateError || Writer.Error)!void { |
| 1979 | const zcu = wip_nav.pt.zcu; | 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 | const signedness = switch (ty.toIntern()) { | 2156 | const signedness = switch (ty.toIntern()) { |
| 1982 | .comptime_int_type, .comptime_float_type => .signed, | 2157 | .comptime_int_type, .comptime_float_type => .signed, |
| 1983 | else => ty.intInfo(zcu).signedness, | 2158 | else => ty.intInfo(zcu).signedness, |
| ... | @@ -1988,7 +2163,7 @@ pub const WipNav = struct { | ... | @@ -1988,7 +2163,7 @@ pub const WipNav = struct { |
| 1988 | .signed => abbrev_code.sdata, | 2163 | .signed => abbrev_code.sdata, |
| 1989 | .unsigned => abbrev_code.udata, | 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 | var bit: usize = 0; | 2167 | var bit: usize = 0; |
| 1993 | var carry: u1 = 1; | 2168 | var carry: u1 = 1; |
| 1994 | while (bit < bits) { | 2169 | while (bit < bits) { |
| ... | @@ -2005,14 +2180,15 @@ pub const WipNav = struct { | ... | @@ -2005,14 +2180,15 @@ pub const WipNav = struct { |
| 2005 | break :twos_comp_part twos_comp_part; | 2180 | break :twos_comp_part twos_comp_part; |
| 2006 | }; | 2181 | }; |
| 2007 | bit += 7; | 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 | } else { | 2185 | } else { |
| 2011 | try wip_nav.abbrevCode(abbrev_code.block); | 2186 | try wip_nav.abbrevCode(abbrev_code.block); |
| 2012 | const bytes = @max(ty.abiSize(zcu), std.math.divCeil(usize, bits, 8) catch unreachable); | 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 | big_int.writeTwosComplement( | 2190 | big_int.writeTwosComplement( |
| 2015 | try wip_nav.debug_info.addManyAsSlice(wip_nav.dwarf.gpa, @intCast(bytes)), | 2191 | try diw.writableSlice(@intCast(bytes)), |
| 2016 | wip_nav.dwarf.endian, | 2192 | wip_nav.dwarf.endian, |
| 2017 | ); | 2193 | ); |
| 2018 | } | 2194 | } |
| ... | @@ -2023,7 +2199,7 @@ pub const WipNav = struct { | ... | @@ -2023,7 +2199,7 @@ pub const WipNav = struct { |
| 2023 | loaded_enum: InternPool.LoadedEnumType, | 2199 | loaded_enum: InternPool.LoadedEnumType, |
| 2024 | abbrev_code: AbbrevCodeForForm, | 2200 | abbrev_code: AbbrevCodeForForm, |
| 2025 | field_index: usize, | 2201 | field_index: usize, |
| 2026 | ) UpdateError!void { | 2202 | ) (UpdateError || Writer.Error)!void { |
| 2027 | const zcu = wip_nav.pt.zcu; | 2203 | const zcu = wip_nav.pt.zcu; |
| 2028 | const ip = &zcu.intern_pool; | 2204 | const ip = &zcu.intern_pool; |
| 2029 | var big_int_space: Value.BigIntSpace = undefined; | 2205 | var big_int_space: Value.BigIntSpace = undefined; |
| ... | @@ -2043,11 +2219,11 @@ pub const WipNav = struct { | ... | @@ -2043,11 +2219,11 @@ pub const WipNav = struct { |
| 2043 | nav: *const InternPool.Nav, | 2219 | nav: *const InternPool.Nav, |
| 2044 | file: Zcu.File.Index, | 2220 | file: Zcu.File.Index, |
| 2045 | decl: *const std.zig.Zir.Inst.Declaration.Unwrapped, | 2221 | decl: *const std.zig.Zir.Inst.Declaration.Unwrapped, |
| 2046 | ) UpdateError!void { | 2222 | ) (UpdateError || Writer.Error)!void { |
| 2047 | const zcu = wip_nav.pt.zcu; | 2223 | const zcu = wip_nav.pt.zcu; |
| 2048 | const ip = &zcu.intern_pool; | 2224 | const ip = &zcu.intern_pool; |
| 2049 | const dwarf = wip_nav.dwarf; | 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 | const orig_entry = wip_nav.entry; | 2228 | const orig_entry = wip_nav.entry; |
| 2053 | defer wip_nav.entry = orig_entry; | 2229 | defer wip_nav.entry = orig_entry; |
| ... | @@ -2098,15 +2274,15 @@ pub const WipNav = struct { | ... | @@ -2098,15 +2274,15 @@ pub const WipNav = struct { |
| 2098 | try wip_nav.abbrevCode(if (is_generic_decl) abbrev_code.generic_decl else abbrev_code.decl); | 2274 | try wip_nav.abbrevCode(if (is_generic_decl) abbrev_code.generic_decl else abbrev_code.decl); |
| 2099 | try wip_nav.refType((if (is_generic_decl) null else parent_type) orelse | 2275 | try wip_nav.refType((if (is_generic_decl) null else parent_type) orelse |
| 2100 | .fromInterned(zcu.fileRootType(file))); | 2276 | .fromInterned(zcu.fileRootType(file))); |
| 2101 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); | 2277 | assert(diw.end == DebugInfo.declEntryLineOff(dwarf)); |
| 2102 | try diw.writeInt(u32, decl.src_line + 1, dwarf.endian); | 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 | try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); | 2280 | try diw.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); |
| 2105 | try wip_nav.strp(nav.name.toSlice(ip)); | 2281 | try wip_nav.strp(nav.name.toSlice(ip)); |
| 2106 | | 2282 | |
| 2107 | if (!is_generic_decl) return; | 2283 | if (!is_generic_decl) return; |
| 2108 | const generic_decl_entry = wip_nav.entry; | 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 | wip_nav.debug_info.clearRetainingCapacity(); | 2286 | wip_nav.debug_info.clearRetainingCapacity(); |
| 2111 | wip_nav.entry = orig_entry; | 2287 | wip_nav.entry = orig_entry; |
| 2112 | try wip_nav.abbrevCode(abbrev_code.decl_instance); | 2288 | try wip_nav.abbrevCode(abbrev_code.decl_instance); |
| ... | @@ -2121,7 +2297,7 @@ pub const WipNav = struct { | ... | @@ -2121,7 +2297,7 @@ pub const WipNav = struct { |
| 2121 | const empty: PendingLazy = .{ .types = .empty, .values = .empty }; | 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 | while (true) if (wip_nav.pending_lazy.types.pop()) |pending_ty| | 2301 | while (true) if (wip_nav.pending_lazy.types.pop()) |pending_ty| |
| 2126 | try wip_nav.dwarf.updateLazyType(wip_nav.pt, src_loc, pending_ty, &wip_nav.pending_lazy) | 2302 | try wip_nav.dwarf.updateLazyType(wip_nav.pt, src_loc, pending_ty, &wip_nav.pending_lazy) |
| 2127 | else if (wip_nav.pending_lazy.values.pop()) |pending_val| | 2303 | else if (wip_nav.pending_lazy.values.pop()) |pending_val| |
| ... | @@ -2411,8 +2587,8 @@ pub fn initWipNav( | ... | @@ -2411,8 +2587,8 @@ pub fn initWipNav( |
| 2411 | sym_index: u32, | 2587 | sym_index: u32, |
| 2412 | ) error{ OutOfMemory, CodegenFail }!?WipNav { | 2588 | ) error{ OutOfMemory, CodegenFail }!?WipNav { |
| 2413 | return initWipNavInner(dwarf, pt, nav_index, sym_index) catch |err| switch (err) { | 2589 | return initWipNavInner(dwarf, pt, nav_index, sym_index) catch |err| switch (err) { |
| 2414 | error.OutOfMemory => return error.OutOfMemory, | 2590 | error.OutOfMemory => error.OutOfMemory, |
| 2415 | else => |e| return pt.zcu.codegenFail(nav_index, "failed to init dwarf: {s}", .{@errorName(e)}), | 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,17 +2646,17 @@ fn initWipNavInner( |
| 2470 | .func_high_pc = undefined, | 2646 | .func_high_pc = undefined, |
| 2471 | .blocks = undefined, | 2647 | .blocks = undefined, |
| 2472 | .cfi = undefined, | 2648 | .cfi = undefined, |
| 2473 | .debug_frame = .empty, | 2649 | .debug_frame = .init(dwarf.gpa), |
| 2474 | .debug_info = .empty, | 2650 | .debug_info = .init(dwarf.gpa), |
| 2475 | .debug_line = .empty, | 2651 | .debug_line = .init(dwarf.gpa), |
| 2476 | .debug_loclists = .empty, | 2652 | .debug_loclists = .init(dwarf.gpa), |
| 2477 | .pending_lazy = .empty, | 2653 | .pending_lazy = .empty, |
| 2478 | }; | 2654 | }; |
| 2479 | errdefer wip_nav.deinit(); | 2655 | errdefer wip_nav.deinit(); |
| 2480 | | 2656 | |
| 2481 | switch (nav_key) { | 2657 | switch (nav_key) { |
| 2482 | else => { | 2658 | else => { |
| 2483 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 2659 | const diw = &wip_nav.debug_info.writer; |
| 2484 | try wip_nav.declCommon(.{ | 2660 | try wip_nav.declCommon(.{ |
| 2485 | .decl = .decl_var, | 2661 | .decl = .decl_var, |
| 2486 | .generic_decl = .generic_decl_var, | 2662 | .generic_decl = .generic_decl_var, |
| ... | @@ -2501,7 +2677,7 @@ fn initWipNavInner( | ... | @@ -2501,7 +2677,7 @@ fn initWipNavInner( |
| 2501 | .@"const" => { | 2677 | .@"const" => { |
| 2502 | const const_ty_reloc_index = try wip_nav.refForward(); | 2678 | const const_ty_reloc_index = try wip_nav.refForward(); |
| 2503 | try wip_nav.infoExprLoc(loc); | 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 | ty.abiAlignment(zcu).toByteUnits().?); | 2681 | ty.abiAlignment(zcu).toByteUnits().?); |
| 2506 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); | 2682 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| 2507 | wip_nav.finishForward(const_ty_reloc_index); | 2683 | wip_nav.finishForward(const_ty_reloc_index); |
| ... | @@ -2511,7 +2687,7 @@ fn initWipNavInner( | ... | @@ -2511,7 +2687,7 @@ fn initWipNavInner( |
| 2511 | .@"var" => { | 2687 | .@"var" => { |
| 2512 | try wip_nav.refType(ty); | 2688 | try wip_nav.refType(ty); |
| 2513 | try wip_nav.infoExprLoc(loc); | 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 | ty.abiAlignment(zcu).toByteUnits().?); | 2691 | ty.abiAlignment(zcu).toByteUnits().?); |
| 2516 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); | 2692 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| 2517 | }, | 2693 | }, |
| ... | @@ -2538,7 +2714,7 @@ fn initWipNavInner( | ... | @@ -2538,7 +2714,7 @@ fn initWipNavInner( |
| 2538 | .none => {}, | 2714 | .none => {}, |
| 2539 | .debug_frame, .eh_frame => |format| { | 2715 | .debug_frame, .eh_frame => |format| { |
| 2540 | const entry = dwarf.debug_frame.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry); | 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 | switch (dwarf.format) { | 2718 | switch (dwarf.format) { |
| 2543 | .@"32" => try dfw.writeInt(u32, undefined, dwarf.endian), | 2719 | .@"32" => try dfw.writeInt(u32, undefined, dwarf.endian), |
| 2544 | .@"64" => { | 2720 | .@"64" => { |
| ... | @@ -2550,27 +2726,27 @@ fn initWipNavInner( | ... | @@ -2550,27 +2726,27 @@ fn initWipNavInner( |
| 2550 | .none => unreachable, | 2726 | .none => unreachable, |
| 2551 | .debug_frame => { | 2727 | .debug_frame => { |
| 2552 | try entry.cross_entry_relocs.append(dwarf.gpa, .{ | 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 | try wip_nav.frameAddrSym(sym_index, 0); | 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 | .eh_frame => { | 2735 | .eh_frame => { |
| 2560 | try dfw.writeInt(u32, undefined, dwarf.endian); | 2736 | try dfw.writeInt(u32, undefined, dwarf.endian); |
| 2561 | try wip_nav.frameExternalReloc(.{ | 2737 | try wip_nav.frameExternalReloc(.{ |
| 2562 | .source_off = @intCast(wip_nav.debug_frame.items.len), | 2738 | .source_off = @intCast(dfw.end), |
| 2563 | .target_sym = sym_index, | 2739 | .target_sym = sym_index, |
| 2564 | }); | 2740 | }); |
| 2565 | try dfw.writeInt(u32, 0, dwarf.endian); | 2741 | try dfw.writeInt(u32, 0, dwarf.endian); |
| 2566 | try dfw.writeInt(u32, undefined, dwarf.endian); | 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 | try wip_nav.declCommon(.{ | 2750 | try wip_nav.declCommon(.{ |
| 2575 | .decl = .decl_func, | 2751 | .decl = .decl_func, |
| 2576 | .generic_decl = .generic_decl_func, | 2752 | .generic_decl = .generic_decl_func, |
| ... | @@ -2579,48 +2755,48 @@ fn initWipNavInner( | ... | @@ -2579,48 +2755,48 @@ fn initWipNavInner( |
| 2579 | try wip_nav.strp(nav.fqn.toSlice(ip)); | 2755 | try wip_nav.strp(nav.fqn.toSlice(ip)); |
| 2580 | try wip_nav.refType(.fromInterned(func_type.return_type)); | 2756 | try wip_nav.refType(.fromInterned(func_type.return_type)); |
| 2581 | try wip_nav.infoAddrSym(sym_index, 0); | 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 | try diw.writeInt(u32, 0, dwarf.endian); | 2759 | try diw.writeInt(u32, 0, dwarf.endian); |
| 2584 | const target = &mod.resolved_target.result; | 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 | .none => target_info.defaultFunctionAlignment(target), | 2762 | .none => target_info.defaultFunctionAlignment(target), |
| 2587 | else => |a| a.maxStrict(target_info.minFunctionAlignment(target)), | 2763 | else => |a| a.maxStrict(target_info.minFunctionAlignment(target)), |
| 2588 | }.toByteUnits().?); | 2764 | }.toByteUnits().?); |
| 2589 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); | 2765 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| 2590 | try diw.writeByte(@intFromBool(func_type.return_type == .noreturn_type)); | 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 | try dlw.writeByte(DW.LNS.extended_op); | 2769 | try dlw.writeByte(DW.LNS.extended_op); |
| 2594 | if (dwarf.incremental()) { | 2770 | if (dwarf.incremental()) { |
| 2595 | try uleb128(dlw, 1 + dwarf.sectionOffsetBytes()); | 2771 | try dlw.writeUleb128(1 + dwarf.sectionOffsetBytes()); |
| 2596 | try dlw.writeByte(DW.LNE.ZIG_set_decl); | 2772 | try dlw.writeByte(DW.LNE.ZIG_set_decl); |
| 2597 | try dwarf.debug_line.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).cross_section_relocs.append(dwarf.gpa, .{ | 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 | .target_sec = .debug_info, | 2775 | .target_sec = .debug_info, |
| 2600 | .target_unit = wip_nav.unit, | 2776 | .target_unit = wip_nav.unit, |
| 2601 | .target_entry = wip_nav.entry.toOptional(), | 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 | try dlw.writeByte(DW.LNS.set_column); | 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 | try wip_nav.advancePCAndLine(func.lbrace_line, 0); | 2784 | try wip_nav.advancePCAndLine(func.lbrace_line, 0); |
| 2609 | } else { | 2785 | } else { |
| 2610 | try uleb128(dlw, 1 + @intFromEnum(dwarf.address_size)); | 2786 | try dlw.writeUleb128(1 + @intFromEnum(dwarf.address_size)); |
| 2611 | try dlw.writeByte(DW.LNE.set_address); | 2787 | try dlw.writeByte(DW.LNE.set_address); |
| 2612 | try dwarf.debug_line.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs.append(dwarf.gpa, .{ | 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 | .target_sym = sym_index, | 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 | const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, inst_info.file); | 2794 | const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, inst_info.file); |
| 2619 | try dlw.writeByte(DW.LNS.set_file); | 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 | try dlw.writeByte(DW.LNS.set_column); | 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 | try wip_nav.advancePCAndLine(@intCast(decl.src_line + func.lbrace_line), 0); | 2801 | try wip_nav.advancePCAndLine(@intCast(decl.src_line + func.lbrace_line), 0); |
| 2626 | } | 2802 | } |
| ... | @@ -2636,6 +2812,18 @@ pub fn finishWipNavFunc( | ... | @@ -2636,6 +2812,18 @@ pub fn finishWipNavFunc( |
| 2636 | code_size: u64, | 2812 | code_size: u64, |
| 2637 | wip_nav: *WipNav, | 2813 | wip_nav: *WipNav, |
| 2638 | ) UpdateError!void { | 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 | const zcu = pt.zcu; | 2827 | const zcu = pt.zcu; |
| 2640 | const ip = &zcu.intern_pool; | 2828 | const ip = &zcu.intern_pool; |
| 2641 | const nav = ip.getNav(nav_index); | 2829 | const nav = ip.getNav(nav_index); |
| ... | @@ -2658,12 +2846,12 @@ pub fn finishWipNavFunc( | ... | @@ -2658,12 +2846,12 @@ pub fn finishWipNavFunc( |
| 2658 | switch (dwarf.debug_frame.header.format) { | 2846 | switch (dwarf.debug_frame.header.format) { |
| 2659 | .none => {}, | 2847 | .none => {}, |
| 2660 | .debug_frame, .eh_frame => |format| { | 2848 | .debug_frame, .eh_frame => |format| { |
| 2661 | try wip_nav.debug_frame.appendNTimes( | 2849 | const dfw = &wip_nav.debug_frame.writer; |
| 2662 | dwarf.gpa, | 2850 | try dfw.splatByteAll( |
| 2663 | DW.CFA.nop, | 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 | try dwarf.debug_frame.section.resizeEntry(wip_nav.unit, wip_nav.entry, dwarf, @intCast(contents.len)); | 2855 | try dwarf.debug_frame.section.resizeEntry(wip_nav.unit, wip_nav.entry, dwarf, @intCast(contents.len)); |
| 2668 | const unit = dwarf.debug_frame.section.getUnit(wip_nav.unit); | 2856 | const unit = dwarf.debug_frame.section.getUnit(wip_nav.unit); |
| 2669 | const entry = unit.getEntry(wip_nav.entry); | 2857 | const entry = unit.getEntry(wip_nav.entry); |
| ... | @@ -2690,14 +2878,16 @@ pub fn finishWipNavFunc( | ... | @@ -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 | if (wip_nav.any_children) { | 2882 | if (wip_nav.any_children) { |
| 2695 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 2883 | const diw = &wip_nav.debug_info.writer; |
| 2696 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); | 2884 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 2697 | } else { | 2885 | } else { |
| 2698 | const abbrev_code_buf = wip_nav.debug_info.items[0..AbbrevCode.decl_bytes]; | 2886 | const abbrev_code_buf = wip_nav.debug_info.getWritten()[0..AbbrevCode.decl_bytes]; |
| 2699 | var abbrev_code_fbs = std.io.fixedBufferStream(abbrev_code_buf); | 2887 | var abbrev_code_fr: std.Io.Reader = .fixed(abbrev_code_buf); |
| 2700 | const abbrev_code: AbbrevCode = @enumFromInt(std.leb.readUleb128(@typeInfo(AbbrevCode).@"enum".tag_type, abbrev_code_fbs.reader()) catch unreachable); | 2888 | const abbrev_code: AbbrevCode = @enumFromInt( |
| | 2889 | abbrev_code_fr.takeLeb128(@typeInfo(AbbrevCode).@"enum".tag_type) catch unreachable, |
| | 2890 | ); |
| 2701 | std.leb.writeUnsignedFixed( | 2891 | std.leb.writeUnsignedFixed( |
| 2702 | AbbrevCode.decl_bytes, | 2892 | AbbrevCode.decl_bytes, |
| 2703 | abbrev_code_buf, | 2893 | abbrev_code_buf, |
| ... | @@ -2738,28 +2928,39 @@ pub fn finishWipNav( | ... | @@ -2738,28 +2928,39 @@ pub fn finishWipNav( |
| 2738 | nav_index: InternPool.Nav.Index, | 2928 | nav_index: InternPool.Nav.Index, |
| 2739 | wip_nav: *WipNav, | 2929 | wip_nav: *WipNav, |
| 2740 | ) UpdateError!void { | 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 | const zcu = pt.zcu; | 2942 | const zcu = pt.zcu; |
| 2742 | const ip = &zcu.intern_pool; | 2943 | const ip = &zcu.intern_pool; |
| 2743 | const nav = ip.getNav(nav_index); | 2944 | const nav = ip.getNav(nav_index); |
| 2744 | log.debug("finishWipNav({f})", .{nav.fqn.fmt(ip)}); | 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); | 2947 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.getWritten()); |
| 2747 | if (wip_nav.debug_line.items.len > 0) { | 2948 | const dlw = &wip_nav.debug_line.writer; |
| 2748 | const dlw = wip_nav.debug_line.writer(dwarf.gpa); | 2949 | if (dlw.end > 0) { |
| 2749 | try dlw.writeByte(DW.LNS.extended_op); | 2950 | try dlw.writeByte(DW.LNS.extended_op); |
| 2750 | try uleb128(dlw, 1); | 2951 | try dlw.writeUleb128(1); |
| 2751 | try dlw.writeByte(DW.LNE.end_sequence); | 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 | try wip_nav.updateLazy(zcu.navSrcLoc(nav_index)); | 2957 | try wip_nav.updateLazy(zcu.navSrcLoc(nav_index)); |
| 2757 | } | 2958 | } |
| 2758 | | 2959 | |
| 2759 | pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) error{ OutOfMemory, CodegenFail }!void { | 2960 | pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) error{ OutOfMemory, CodegenFail }!void { |
| 2760 | return updateComptimeNavInner(dwarf, pt, nav_index) catch |err| switch (err) { | 2961 | return updateComptimeNavInner(dwarf, pt, nav_index) catch |err| switch (err) { |
| 2761 | error.OutOfMemory => return error.OutOfMemory, | 2962 | error.OutOfMemory => error.OutOfMemory, |
| 2762 | else => |e| return pt.zcu.codegenFail(nav_index, "failed to update dwarf: {s}", .{@errorName(e)}), | 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,10 +3002,10 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2801 | .func_high_pc = undefined, | 3002 | .func_high_pc = undefined, |
| 2802 | .blocks = undefined, | 3003 | .blocks = undefined, |
| 2803 | .cfi = undefined, | 3004 | .cfi = undefined, |
| 2804 | .debug_frame = .empty, | 3005 | .debug_frame = .init(dwarf.gpa), |
| 2805 | .debug_info = .empty, | 3006 | .debug_info = .init(dwarf.gpa), |
| 2806 | .debug_line = .empty, | 3007 | .debug_line = .init(dwarf.gpa), |
| 2807 | .debug_loclists = .empty, | 3008 | .debug_loclists = .init(dwarf.gpa), |
| 2808 | .pending_lazy = .empty, | 3009 | .pending_lazy = .empty, |
| 2809 | }; | 3010 | }; |
| 2810 | defer wip_nav.deinit(); | 3011 | defer wip_nav.deinit(); |
| ... | @@ -2850,7 +3051,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo | ... | @@ -2850,7 +3051,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2850 | } | 3051 | } |
| 2851 | wip_nav.entry = nav_gop.value_ptr.*; | 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 | switch (loaded_struct.layout) { | 3056 | switch (loaded_struct.layout) { |
| 2856 | .auto, .@"extern" => { | 3057 | .auto, .@"extern" => { |
| ... | @@ -2864,8 +3065,8 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo | ... | @@ -2864,8 +3065,8 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2864 | .decl_instance = .decl_instance_struct, | 3065 | .decl_instance = .decl_instance_struct, |
| 2865 | }, &nav, inst_info.file, &decl); | 3066 | }, &nav, inst_info.file, &decl); |
| 2866 | if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else { | 3067 | if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else { |
| 2867 | try uleb128(diw, nav_val.toType().abiSize(zcu)); | 3068 | try diw.writeUleb128(nav_val.toType().abiSize(zcu)); |
| 2868 | try uleb128(diw, nav_val.toType().abiAlignment(zcu).toByteUnits().?); | 3069 | try diw.writeUleb128(nav_val.toType().abiAlignment(zcu).toByteUnits().?); |
| 2869 | for (0..loaded_struct.field_types.len) |field_index| { | 3070 | for (0..loaded_struct.field_types.len) |field_index| { |
| 2870 | const is_comptime = loaded_struct.fieldIsComptime(ip, field_index); | 3071 | const is_comptime = loaded_struct.fieldIsComptime(ip, field_index); |
| 2871 | const field_init = loaded_struct.fieldInit(ip, field_index); | 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,8 +3102,8 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2901 | } | 3102 | } |
| 2902 | try wip_nav.refType(field_type); | 3103 | try wip_nav.refType(field_type); |
| 2903 | if (!is_comptime) { | 3104 | if (!is_comptime) { |
| 2904 | try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]); | 3105 | try diw.writeUleb128(loaded_struct.offsets.get(ip)[field_index]); |
| 2905 | try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse | 3106 | try diw.writeUleb128(loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse |
| 2906 | field_type.abiAlignment(zcu).toByteUnits().?); | 3107 | field_type.abiAlignment(zcu).toByteUnits().?); |
| 2907 | } | 3108 | } |
| 2908 | if (has_comptime_state) | 3109 | if (has_comptime_state) |
| ... | @@ -2910,7 +3111,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo | ... | @@ -2910,7 +3111,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2910 | else if (has_runtime_bits) | 3111 | else if (has_runtime_bits) |
| 2911 | try wip_nav.blockValue(nav_src_loc, .fromInterned(field_init)); | 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 | .@"packed" => { | 3117 | .@"packed" => { |
| ... | @@ -2926,10 +3127,10 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo | ... | @@ -2926,10 +3127,10 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2926 | try wip_nav.strp(loaded_struct.fieldName(ip, field_index).unwrap().?.toSlice(ip)); | 3127 | try wip_nav.strp(loaded_struct.fieldName(ip, field_index).unwrap().?.toSlice(ip)); |
| 2927 | const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]); | 3128 | const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]); |
| 2928 | try wip_nav.refType(field_type); | 3129 | try wip_nav.refType(field_type); |
| 2929 | try uleb128(diw, field_bit_offset); | 3130 | try diw.writeUleb128(field_bit_offset); |
| 2930 | field_bit_offset += @intCast(field_type.bitSize(zcu)); | 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 | break :tag .done; | 3136 | break :tag .done; |
| ... | @@ -2952,7 +3153,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo | ... | @@ -2952,7 +3153,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2952 | type_gop.value_ptr.* = nav_gop.value_ptr.*; | 3153 | type_gop.value_ptr.* = nav_gop.value_ptr.*; |
| 2953 | } | 3154 | } |
| 2954 | wip_nav.entry = nav_gop.value_ptr.*; | 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 | try wip_nav.declCommon(if (loaded_enum.names.len > 0) .{ | 3157 | try wip_nav.declCommon(if (loaded_enum.names.len > 0) .{ |
| 2957 | .decl = .decl_enum, | 3158 | .decl = .decl_enum, |
| 2958 | .generic_decl = .generic_decl_const, | 3159 | .generic_decl = .generic_decl_const, |
| ... | @@ -2971,7 +3172,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo | ... | @@ -2971,7 +3172,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2971 | }, field_index); | 3172 | }, field_index); |
| 2972 | try wip_nav.strp(loaded_enum.names.get(ip)[field_index].toSlice(ip)); | 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 | break :tag .done; | 3176 | break :tag .done; |
| 2976 | }, | 3177 | }, |
| 2977 | .union_type => tag: { | 3178 | .union_type => tag: { |
| ... | @@ -2991,15 +3192,15 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo | ... | @@ -2991,15 +3192,15 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2991 | type_gop.value_ptr.* = nav_gop.value_ptr.*; | 3192 | type_gop.value_ptr.* = nav_gop.value_ptr.*; |
| 2992 | } | 3193 | } |
| 2993 | wip_nav.entry = nav_gop.value_ptr.*; | 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 | try wip_nav.declCommon(.{ | 3196 | try wip_nav.declCommon(.{ |
| 2996 | .decl = .decl_union, | 3197 | .decl = .decl_union, |
| 2997 | .generic_decl = .generic_decl_const, | 3198 | .generic_decl = .generic_decl_const, |
| 2998 | .decl_instance = .decl_instance_union, | 3199 | .decl_instance = .decl_instance_union, |
| 2999 | }, &nav, inst_info.file, &decl); | 3200 | }, &nav, inst_info.file, &decl); |
| 3000 | const union_layout = Type.getUnionLayout(loaded_union, zcu); | 3201 | const union_layout = Type.getUnionLayout(loaded_union, zcu); |
| 3001 | try uleb128(diw, union_layout.abi_size); | 3202 | try diw.writeUleb128(union_layout.abi_size); |
| 3002 | try uleb128(diw, union_layout.abi_align.toByteUnits().?); | 3203 | try diw.writeUleb128(union_layout.abi_align.toByteUnits().?); |
| 3003 | const loaded_tag = loaded_union.loadTagType(ip); | 3204 | const loaded_tag = loaded_union.loadTagType(ip); |
| 3004 | if (loaded_union.hasTag(ip)) { | 3205 | if (loaded_union.hasTag(ip)) { |
| 3005 | try wip_nav.abbrevCode(.tagged_union); | 3206 | try wip_nav.abbrevCode(.tagged_union); |
| ... | @@ -3007,13 +3208,13 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo | ... | @@ -3007,13 +3208,13 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3007 | .debug_info, | 3208 | .debug_info, |
| 3008 | wip_nav.unit, | 3209 | wip_nav.unit, |
| 3009 | wip_nav.entry, | 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 | try wip_nav.abbrevCode(.generated_field); | 3214 | try wip_nav.abbrevCode(.generated_field); |
| 3014 | try wip_nav.strp("tag"); | 3215 | try wip_nav.strp("tag"); |
| 3015 | try wip_nav.refType(.fromInterned(loaded_union.enum_tag_ty)); | 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 | for (0..loaded_union.field_types.len) |field_index| { | 3219 | for (0..loaded_union.field_types.len) |field_index| { |
| 3019 | try wip_nav.enumConstValue(loaded_tag, .{ | 3220 | try wip_nav.enumConstValue(loaded_tag, .{ |
| ... | @@ -3026,23 +3227,23 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo | ... | @@ -3026,23 +3227,23 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3026 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); | 3227 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); |
| 3027 | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); | 3228 | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 3028 | try wip_nav.refType(field_type); | 3229 | try wip_nav.refType(field_type); |
| 3029 | try uleb128(diw, union_layout.payloadOffset()); | 3230 | try diw.writeUleb128(union_layout.payloadOffset()); |
| 3030 | try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse | 3231 | try diw.writeUleb128(loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse |
| 3031 | if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?); | 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 | } else for (0..loaded_union.field_types.len) |field_index| { | 3238 | } else for (0..loaded_union.field_types.len) |field_index| { |
| 3038 | try wip_nav.abbrevCode(.untagged_union_field); | 3239 | try wip_nav.abbrevCode(.untagged_union_field); |
| 3039 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); | 3240 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); |
| 3040 | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); | 3241 | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 3041 | try wip_nav.refType(field_type); | 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 | field_type.abiAlignment(zcu).toByteUnits().?); | 3244 | field_type.abiAlignment(zcu).toByteUnits().?); |
| 3044 | } | 3245 | } |
| 3045 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); | 3246 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3046 | break :tag .done; | 3247 | break :tag .done; |
| 3047 | }, | 3248 | }, |
| 3048 | .opaque_type => tag: { | 3249 | .opaque_type => tag: { |
| ... | @@ -3062,7 +3263,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo | ... | @@ -3062,7 +3263,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3062 | type_gop.value_ptr.* = nav_gop.value_ptr.*; | 3263 | type_gop.value_ptr.* = nav_gop.value_ptr.*; |
| 3063 | } | 3264 | } |
| 3064 | wip_nav.entry = nav_gop.value_ptr.*; | 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 | try wip_nav.declCommon(.{ | 3267 | try wip_nav.declCommon(.{ |
| 3067 | .decl = .decl_namespace_struct, | 3268 | .decl = .decl_namespace_struct, |
| 3068 | .generic_decl = .generic_decl_const, | 3269 | .generic_decl = .generic_decl_const, |
| ... | @@ -3106,7 +3307,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo | ... | @@ -3106,7 +3307,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3106 | const is_nullary = !func_type.is_var_args and for (0..func_type.param_types.len) |param_index| { | 3307 | const is_nullary = !func_type.is_var_args and for (0..func_type.param_types.len) |param_index| { |
| 3107 | if (!func_type.paramIsComptime(std.math.cast(u5, param_index) orelse break false)) break false; | 3308 | if (!func_type.paramIsComptime(std.math.cast(u5, param_index) orelse break false)) break false; |
| 3108 | } else true; | 3309 | } else true; |
| 3109 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 3310 | const diw = &wip_nav.debug_info.writer; |
| 3110 | try wip_nav.declCommon(if (is_nullary) .{ | 3311 | try wip_nav.declCommon(if (is_nullary) .{ |
| 3111 | .decl = .decl_nullary_func_generic, | 3312 | .decl = .decl_nullary_func_generic, |
| 3112 | .generic_decl = .generic_decl_func, | 3313 | .generic_decl = .generic_decl_func, |
| ... | @@ -3125,7 +3326,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo | ... | @@ -3125,7 +3326,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3125 | try wip_nav.refType(.fromInterned(func_type.param_types.get(ip)[param_index])); | 3326 | try wip_nav.refType(.fromInterned(func_type.param_types.get(ip)[param_index])); |
| 3126 | } | 3327 | } |
| 3127 | if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args); | 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 | break :tag .done; | 3331 | break :tag .done; |
| 3131 | }, | 3332 | }, |
| ... | @@ -3150,7 +3351,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo | ... | @@ -3150,7 +3351,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3150 | try wip_nav.refType(nav_val.toType()); | 3351 | try wip_nav.refType(nav_val.toType()); |
| 3151 | }, | 3352 | }, |
| 3152 | .decl_var => { | 3353 | .decl_var => { |
| 3153 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 3354 | const diw = &wip_nav.debug_info.writer; |
| 3154 | try wip_nav.declCommon(.{ | 3355 | try wip_nav.declCommon(.{ |
| 3155 | .decl = .decl_var, | 3356 | .decl = .decl_var, |
| 3156 | .generic_decl = .generic_decl_var, | 3357 | .generic_decl = .generic_decl_var, |
| ... | @@ -3160,12 +3361,12 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo | ... | @@ -3160,12 +3361,12 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3160 | const nav_ty = nav_val.typeOf(zcu); | 3361 | const nav_ty = nav_val.typeOf(zcu); |
| 3161 | try wip_nav.refType(nav_ty); | 3362 | try wip_nav.refType(nav_ty); |
| 3162 | try wip_nav.blockValue(nav_src_loc, nav_val); | 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 | nav_ty.abiAlignment(zcu).toByteUnits().?); | 3365 | nav_ty.abiAlignment(zcu).toByteUnits().?); |
| 3165 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); | 3366 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| 3166 | }, | 3367 | }, |
| 3167 | .decl_const => { | 3368 | .decl_const => { |
| 3168 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 3369 | const diw = &wip_nav.debug_info.writer; |
| 3169 | const nav_ty = nav_val.typeOf(zcu); | 3370 | const nav_ty = nav_val.typeOf(zcu); |
| 3170 | const has_runtime_bits = nav_ty.hasRuntimeBits(zcu); | 3371 | const has_runtime_bits = nav_ty.hasRuntimeBits(zcu); |
| 3171 | const has_comptime_state = nav_ty.comptimeOnly(zcu) and try nav_ty.onePossibleValue(pt) == null; | 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,7 +3389,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3188 | }, &nav, inst_info.file, &decl); | 3389 | }, &nav, inst_info.file, &decl); |
| 3189 | try wip_nav.strp(nav.fqn.toSlice(ip)); | 3390 | try wip_nav.strp(nav.fqn.toSlice(ip)); |
| 3190 | const nav_ty_reloc_index = try wip_nav.refForward(); | 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 | nav_ty.abiAlignment(zcu).toByteUnits().?); | 3393 | nav_ty.abiAlignment(zcu).toByteUnits().?); |
| 3193 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); | 3394 | try diw.writeByte(@intFromBool(decl.linkage != .normal)); |
| 3194 | if (has_runtime_bits) try wip_nav.blockValue(nav_src_loc, nav_val); | 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,7 +3407,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 3206 | try wip_nav.refNav(owner_nav); | 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 | try wip_nav.updateLazy(nav_src_loc); | 3411 | try wip_nav.updateLazy(nav_src_loc); |
| 3211 | } | 3412 | } |
| 3212 | | 3413 | |
| ... | @@ -3216,7 +3417,7 @@ fn updateLazyType( | ... | @@ -3216,7 +3417,7 @@ fn updateLazyType( |
| 3216 | src_loc: Zcu.LazySrcLoc, | 3417 | src_loc: Zcu.LazySrcLoc, |
| 3217 | type_index: InternPool.Index, | 3418 | type_index: InternPool.Index, |
| 3218 | pending_lazy: *WipNav.PendingLazy, | 3419 | pending_lazy: *WipNav.PendingLazy, |
| 3219 | ) UpdateError!void { | 3420 | ) (UpdateError || Writer.Error)!void { |
| 3220 | const zcu = pt.zcu; | 3421 | const zcu = pt.zcu; |
| 3221 | const ip = &zcu.intern_pool; | 3422 | const ip = &zcu.intern_pool; |
| 3222 | assert(ip.typeOf(type_index) == .type_type); | 3423 | assert(ip.typeOf(type_index) == .type_type); |
| ... | @@ -3237,10 +3438,10 @@ fn updateLazyType( | ... | @@ -3237,10 +3438,10 @@ fn updateLazyType( |
| 3237 | .func_high_pc = undefined, | 3438 | .func_high_pc = undefined, |
| 3238 | .blocks = undefined, | 3439 | .blocks = undefined, |
| 3239 | .cfi = undefined, | 3440 | .cfi = undefined, |
| 3240 | .debug_frame = .empty, | 3441 | .debug_frame = .init(dwarf.gpa), |
| 3241 | .debug_info = .empty, | 3442 | .debug_info = .init(dwarf.gpa), |
| 3242 | .debug_line = .empty, | 3443 | .debug_line = .init(dwarf.gpa), |
| 3243 | .debug_loclists = .empty, | 3444 | .debug_loclists = .init(dwarf.gpa), |
| 3244 | .pending_lazy = pending_lazy.*, | 3445 | .pending_lazy = pending_lazy.*, |
| 3245 | }; | 3446 | }; |
| 3246 | defer { | 3447 | defer { |
| ... | @@ -3248,7 +3449,7 @@ fn updateLazyType( | ... | @@ -3248,7 +3449,7 @@ fn updateLazyType( |
| 3248 | wip_nav.pending_lazy = .empty; | 3449 | wip_nav.pending_lazy = .empty; |
| 3249 | wip_nav.deinit(); | 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 | const name = switch (type_index) { | 3453 | const name = switch (type_index) { |
| 3253 | .generic_poison_type => "", | 3454 | .generic_poison_type => "", |
| 3254 | else => try std.fmt.allocPrint(dwarf.gpa, "{f}", .{ty.fmt(pt)}), | 3455 | else => try std.fmt.allocPrint(dwarf.gpa, "{f}", .{ty.fmt(pt)}), |
| ... | @@ -3266,9 +3467,9 @@ fn updateLazyType( | ... | @@ -3266,9 +3467,9 @@ fn updateLazyType( |
| 3266 | try diw.writeByte(switch (int_type.signedness) { | 3467 | try diw.writeByte(switch (int_type.signedness) { |
| 3267 | inline .signed, .unsigned => |signedness| @field(DW.ATE, @tagName(signedness)), | 3468 | inline .signed, .unsigned => |signedness| @field(DW.ATE, @tagName(signedness)), |
| 3268 | }); | 3469 | }); |
| 3269 | try uleb128(diw, int_type.bits); | 3470 | try diw.writeUleb128(int_type.bits); |
| 3270 | try uleb128(diw, ty.abiSize(zcu)); | 3471 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3271 | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); | 3472 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3272 | }, | 3473 | }, |
| 3273 | .ptr_type => |ptr_type| switch (ptr_type.flags.size) { | 3474 | .ptr_type => |ptr_type| switch (ptr_type.flags.size) { |
| 3274 | .one, .many, .c => { | 3475 | .one, .many, .c => { |
| ... | @@ -3276,14 +3477,14 @@ fn updateLazyType( | ... | @@ -3276,14 +3477,14 @@ fn updateLazyType( |
| 3276 | try wip_nav.abbrevCode(if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type); | 3477 | try wip_nav.abbrevCode(if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type); |
| 3277 | try wip_nav.strp(name); | 3478 | try wip_nav.strp(name); |
| 3278 | if (ptr_type.sentinel != .none) try wip_nav.blockValue(src_loc, .fromInterned(ptr_type.sentinel)); | 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 | ptr_child_type.abiAlignment(zcu).toByteUnits().?); | 3481 | ptr_child_type.abiAlignment(zcu).toByteUnits().?); |
| 3281 | try diw.writeByte(@intFromEnum(ptr_type.flags.address_space)); | 3482 | try diw.writeByte(@intFromEnum(ptr_type.flags.address_space)); |
| 3282 | if (ptr_type.flags.is_const or ptr_type.flags.is_volatile) try wip_nav.infoSectionOffset( | 3483 | if (ptr_type.flags.is_const or ptr_type.flags.is_volatile) try wip_nav.infoSectionOffset( |
| 3283 | .debug_info, | 3484 | .debug_info, |
| 3284 | wip_nav.unit, | 3485 | wip_nav.unit, |
| 3285 | wip_nav.entry, | 3486 | wip_nav.entry, |
| 3286 | @intCast(wip_nav.debug_info.items.len + dwarf.sectionOffsetBytes()), | 3487 | @intCast(diw.end + dwarf.sectionOffsetBytes()), |
| 3287 | ) else try wip_nav.refType(ptr_child_type); | 3488 | ) else try wip_nav.refType(ptr_child_type); |
| 3288 | if (ptr_type.flags.is_const) { | 3489 | if (ptr_type.flags.is_const) { |
| 3289 | try wip_nav.abbrevCode(.is_const); | 3490 | try wip_nav.abbrevCode(.is_const); |
| ... | @@ -3291,7 +3492,7 @@ fn updateLazyType( | ... | @@ -3291,7 +3492,7 @@ fn updateLazyType( |
| 3291 | .debug_info, | 3492 | .debug_info, |
| 3292 | wip_nav.unit, | 3493 | wip_nav.unit, |
| 3293 | wip_nav.entry, | 3494 | wip_nav.entry, |
| 3294 | @intCast(wip_nav.debug_info.items.len + dwarf.sectionOffsetBytes()), | 3495 | @intCast(diw.end + dwarf.sectionOffsetBytes()), |
| 3295 | ) else try wip_nav.refType(ptr_child_type); | 3496 | ) else try wip_nav.refType(ptr_child_type); |
| 3296 | } | 3497 | } |
| 3297 | if (ptr_type.flags.is_volatile) { | 3498 | if (ptr_type.flags.is_volatile) { |
| ... | @@ -3302,19 +3503,19 @@ fn updateLazyType( | ... | @@ -3302,19 +3503,19 @@ fn updateLazyType( |
| 3302 | .slice => { | 3503 | .slice => { |
| 3303 | try wip_nav.abbrevCode(.generated_struct_type); | 3504 | try wip_nav.abbrevCode(.generated_struct_type); |
| 3304 | try wip_nav.strp(name); | 3505 | try wip_nav.strp(name); |
| 3305 | try uleb128(diw, ty.abiSize(zcu)); | 3506 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3306 | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); | 3507 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3307 | try wip_nav.abbrevCode(.generated_field); | 3508 | try wip_nav.abbrevCode(.generated_field); |
| 3308 | try wip_nav.strp("ptr"); | 3509 | try wip_nav.strp("ptr"); |
| 3309 | const ptr_field_type = ty.slicePtrFieldType(zcu); | 3510 | const ptr_field_type = ty.slicePtrFieldType(zcu); |
| 3310 | try wip_nav.refType(ptr_field_type); | 3511 | try wip_nav.refType(ptr_field_type); |
| 3311 | try uleb128(diw, 0); | 3512 | try diw.writeUleb128(0); |
| 3312 | try wip_nav.abbrevCode(.generated_field); | 3513 | try wip_nav.abbrevCode(.generated_field); |
| 3313 | try wip_nav.strp("len"); | 3514 | try wip_nav.strp("len"); |
| 3314 | const len_field_type: Type = .usize; | 3515 | const len_field_type: Type = .usize; |
| 3315 | try wip_nav.refType(len_field_type); | 3516 | try wip_nav.refType(len_field_type); |
| 3316 | try uleb128(diw, len_field_type.abiAlignment(zcu).forward(ptr_field_type.abiSize(zcu))); | 3517 | try diw.writeUleb128(len_field_type.abiAlignment(zcu).forward(ptr_field_type.abiSize(zcu))); |
| 3317 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); | 3518 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3318 | }, | 3519 | }, |
| 3319 | }, | 3520 | }, |
| 3320 | .array_type => |array_type| { | 3521 | .array_type => |array_type| { |
| ... | @@ -3325,8 +3526,8 @@ fn updateLazyType( | ... | @@ -3325,8 +3526,8 @@ fn updateLazyType( |
| 3325 | try wip_nav.refType(array_child_type); | 3526 | try wip_nav.refType(array_child_type); |
| 3326 | try wip_nav.abbrevCode(.array_index); | 3527 | try wip_nav.abbrevCode(.array_index); |
| 3327 | try wip_nav.refType(.usize); | 3528 | try wip_nav.refType(.usize); |
| 3328 | try uleb128(diw, array_type.len); | 3529 | try diw.writeUleb128(array_type.len); |
| 3329 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); | 3530 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3330 | }, | 3531 | }, |
| 3331 | .vector_type => |vector_type| { | 3532 | .vector_type => |vector_type| { |
| 3332 | try wip_nav.abbrevCode(.vector_type); | 3533 | try wip_nav.abbrevCode(.vector_type); |
| ... | @@ -3334,22 +3535,22 @@ fn updateLazyType( | ... | @@ -3334,22 +3535,22 @@ fn updateLazyType( |
| 3334 | try wip_nav.refType(.fromInterned(vector_type.child)); | 3535 | try wip_nav.refType(.fromInterned(vector_type.child)); |
| 3335 | try wip_nav.abbrevCode(.array_index); | 3536 | try wip_nav.abbrevCode(.array_index); |
| 3336 | try wip_nav.refType(.usize); | 3537 | try wip_nav.refType(.usize); |
| 3337 | try uleb128(diw, vector_type.len); | 3538 | try diw.writeUleb128(vector_type.len); |
| 3338 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); | 3539 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 3339 | }, | 3540 | }, |
| 3340 | .opt_type => |opt_child_type_index| { | 3541 | .opt_type => |opt_child_type_index| { |
| 3341 | const opt_child_type: Type = .fromInterned(opt_child_type_index); | 3542 | const opt_child_type: Type = .fromInterned(opt_child_type_index); |
| 3342 | const opt_repr = optRepr(opt_child_type, zcu); | 3543 | const opt_repr = optRepr(opt_child_type, zcu); |
| 3343 | try wip_nav.abbrevCode(.generated_union_type); | 3544 | try wip_nav.abbrevCode(.generated_union_type); |
| 3344 | try wip_nav.strp(name); | 3545 | try wip_nav.strp(name); |
| 3345 | try uleb128(diw, ty.abiSize(zcu)); | 3546 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3346 | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); | 3547 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3347 | switch (opt_repr) { | 3548 | switch (opt_repr) { |
| 3348 | .opv_null => { | 3549 | .opv_null => { |
| 3349 | try wip_nav.abbrevCode(.generated_field); | 3550 | try wip_nav.abbrevCode(.generated_field); |
| 3350 | try wip_nav.strp("null"); | 3551 | try wip_nav.strp("null"); |
| 3351 | try wip_nav.refType(.null); | 3552 | try wip_nav.refType(.null); |
| 3352 | try uleb128(diw, 0); | 3553 | try diw.writeUleb128(0); |
| 3353 | }, | 3554 | }, |
| 3354 | .unpacked, .error_set, .pointer => { | 3555 | .unpacked, .error_set, .pointer => { |
| 3355 | try wip_nav.abbrevCode(.tagged_union); | 3556 | try wip_nav.abbrevCode(.tagged_union); |
| ... | @@ -3357,7 +3558,7 @@ fn updateLazyType( | ... | @@ -3357,7 +3558,7 @@ fn updateLazyType( |
| 3357 | .debug_info, | 3558 | .debug_info, |
| 3358 | wip_nav.unit, | 3559 | wip_nav.unit, |
| 3359 | wip_nav.entry, | 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 | try wip_nav.abbrevCode(.generated_field); | 3564 | try wip_nav.abbrevCode(.generated_field); |
| ... | @@ -3366,7 +3567,7 @@ fn updateLazyType( | ... | @@ -3366,7 +3567,7 @@ fn updateLazyType( |
| 3366 | .opv_null => unreachable, | 3567 | .opv_null => unreachable, |
| 3367 | .unpacked => { | 3568 | .unpacked => { |
| 3368 | try wip_nav.refType(.bool); | 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 | opt_child_type.abiSize(zcu) | 3571 | opt_child_type.abiSize(zcu) |
| 3371 | else | 3572 | else |
| 3372 | 0); | 3573 | 0); |
| ... | @@ -3376,37 +3577,37 @@ fn updateLazyType( | ... | @@ -3376,37 +3577,37 @@ fn updateLazyType( |
| 3376 | .signedness = .unsigned, | 3577 | .signedness = .unsigned, |
| 3377 | .bits = zcu.errorSetBits(), | 3578 | .bits = zcu.errorSetBits(), |
| 3378 | } }))); | 3579 | } }))); |
| 3379 | try uleb128(diw, 0); | 3580 | try diw.writeUleb128(0); |
| 3380 | }, | 3581 | }, |
| 3381 | .pointer => { | 3582 | .pointer => { |
| 3382 | try wip_nav.refType(.usize); | 3583 | try wip_nav.refType(.usize); |
| 3383 | try uleb128(diw, 0); | 3584 | try diw.writeUleb128(0); |
| 3384 | }, | 3585 | }, |
| 3385 | } | 3586 | } |
| 3386 | | 3587 | |
| 3387 | try wip_nav.abbrevCode(.unsigned_tagged_union_field); | 3588 | try wip_nav.abbrevCode(.unsigned_tagged_union_field); |
| 3388 | try uleb128(diw, 0); | 3589 | try diw.writeUleb128(0); |
| 3389 | { | 3590 | { |
| 3390 | try wip_nav.abbrevCode(.generated_field); | 3591 | try wip_nav.abbrevCode(.generated_field); |
| 3391 | try wip_nav.strp("null"); | 3592 | try wip_nav.strp("null"); |
| 3392 | try wip_nav.refType(.null); | 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 | try wip_nav.abbrevCode(.tagged_union_default_field); | 3598 | try wip_nav.abbrevCode(.tagged_union_default_field); |
| 3398 | { | 3599 | { |
| 3399 | try wip_nav.abbrevCode(.generated_field); | 3600 | try wip_nav.abbrevCode(.generated_field); |
| 3400 | try wip_nav.strp("?"); | 3601 | try wip_nav.strp("?"); |
| 3401 | try wip_nav.refType(opt_child_type); | 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 | .anyframe_type => unreachable, | 3612 | .anyframe_type => unreachable, |
| 3412 | .error_union_type => |error_union_type| { | 3613 | .error_union_type => |error_union_type| { |
| ... | @@ -3425,11 +3626,11 @@ fn updateLazyType( | ... | @@ -3425,11 +3626,11 @@ fn updateLazyType( |
| 3425 | if (error_union_type.error_set_type != .generic_poison_type and | 3626 | if (error_union_type.error_set_type != .generic_poison_type and |
| 3426 | error_union_type.payload_type != .generic_poison_type) | 3627 | error_union_type.payload_type != .generic_poison_type) |
| 3427 | { | 3628 | { |
| 3428 | try uleb128(diw, ty.abiSize(zcu)); | 3629 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3429 | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); | 3630 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3430 | } else { | 3631 | } else { |
| 3431 | try uleb128(diw, 0); | 3632 | try diw.writeUleb128(0); |
| 3432 | try uleb128(diw, 1); | 3633 | try diw.writeUleb128(1); |
| 3433 | } | 3634 | } |
| 3434 | { | 3635 | { |
| 3435 | try wip_nav.abbrevCode(.tagged_union); | 3636 | try wip_nav.abbrevCode(.tagged_union); |
| ... | @@ -3437,7 +3638,7 @@ fn updateLazyType( | ... | @@ -3437,7 +3638,7 @@ fn updateLazyType( |
| 3437 | .debug_info, | 3638 | .debug_info, |
| 3438 | wip_nav.unit, | 3639 | wip_nav.unit, |
| 3439 | wip_nav.entry, | 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 | try wip_nav.abbrevCode(.generated_field); | 3644 | try wip_nav.abbrevCode(.generated_field); |
| ... | @@ -3446,30 +3647,30 @@ fn updateLazyType( | ... | @@ -3446,30 +3647,30 @@ fn updateLazyType( |
| 3446 | .signedness = .unsigned, | 3647 | .signedness = .unsigned, |
| 3447 | .bits = zcu.errorSetBits(), | 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 | try wip_nav.abbrevCode(.unsigned_tagged_union_field); | 3652 | try wip_nav.abbrevCode(.unsigned_tagged_union_field); |
| 3452 | try uleb128(diw, 0); | 3653 | try diw.writeUleb128(0); |
| 3453 | { | 3654 | { |
| 3454 | try wip_nav.abbrevCode(.generated_field); | 3655 | try wip_nav.abbrevCode(.generated_field); |
| 3455 | try wip_nav.strp("value"); | 3656 | try wip_nav.strp("value"); |
| 3456 | try wip_nav.refType(error_union_payload_type); | 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 | try wip_nav.abbrevCode(.tagged_union_default_field); | 3662 | try wip_nav.abbrevCode(.tagged_union_default_field); |
| 3462 | { | 3663 | { |
| 3463 | try wip_nav.abbrevCode(.generated_field); | 3664 | try wip_nav.abbrevCode(.generated_field); |
| 3464 | try wip_nav.strp("error"); | 3665 | try wip_nav.strp("error"); |
| 3465 | try wip_nav.refType(error_union_error_set_type); | 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 | .simple_type => |simple_type| switch (simple_type) { | 3675 | .simple_type => |simple_type| switch (simple_type) { |
| 3475 | .f16, | 3676 | .f16, |
| ... | @@ -3503,9 +3704,9 @@ fn updateLazyType( | ... | @@ -3503,9 +3704,9 @@ fn updateLazyType( |
| 3503 | DW.ATE.unsigned | 3704 | DW.ATE.unsigned |
| 3504 | else | 3705 | else |
| 3505 | unreachable); | 3706 | unreachable); |
| 3506 | try uleb128(diw, ty.bitSize(zcu)); | 3707 | try diw.writeUleb128(ty.bitSize(zcu)); |
| 3507 | try uleb128(diw, ty.abiSize(zcu)); | 3708 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3508 | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); | 3709 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3509 | }, | 3710 | }, |
| 3510 | .anyopaque, | 3711 | .anyopaque, |
| 3511 | .void, | 3712 | .void, |
| ... | @@ -3535,8 +3736,8 @@ fn updateLazyType( | ... | @@ -3535,8 +3736,8 @@ fn updateLazyType( |
| 3535 | } else { | 3736 | } else { |
| 3536 | try wip_nav.abbrevCode(.generated_struct_type); | 3737 | try wip_nav.abbrevCode(.generated_struct_type); |
| 3537 | try wip_nav.strp(name); | 3738 | try wip_nav.strp(name); |
| 3538 | try uleb128(diw, ty.abiSize(zcu)); | 3739 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 3539 | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); | 3740 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 3540 | var field_byte_offset: u64 = 0; | 3741 | var field_byte_offset: u64 = 0; |
| 3541 | for (0..tuple_type.types.len) |field_index| { | 3742 | for (0..tuple_type.types.len) |field_index| { |
| 3542 | const comptime_value = tuple_type.values.get(ip)[field_index]; | 3743 | const comptime_value = tuple_type.values.get(ip)[field_index]; |
| ... | @@ -3565,8 +3766,8 @@ fn updateLazyType( | ... | @@ -3565,8 +3766,8 @@ fn updateLazyType( |
| 3565 | if (comptime_value == .none) { | 3766 | if (comptime_value == .none) { |
| 3566 | const field_align = field_type.abiAlignment(zcu); | 3767 | const field_align = field_type.abiAlignment(zcu); |
| 3567 | field_byte_offset = field_align.forward(field_byte_offset); | 3768 | field_byte_offset = field_align.forward(field_byte_offset); |
| 3568 | try uleb128(diw, field_byte_offset); | 3769 | try diw.writeUleb128(field_byte_offset); |
| 3569 | try uleb128(diw, field_type.abiAlignment(zcu).toByteUnits().?); | 3770 | try diw.writeUleb128(field_type.abiAlignment(zcu).toByteUnits().?); |
| 3570 | field_byte_offset += field_type.abiSize(zcu); | 3771 | field_byte_offset += field_type.abiSize(zcu); |
| 3571 | } | 3772 | } |
| 3572 | if (has_comptime_state) | 3773 | if (has_comptime_state) |
| ... | @@ -3574,7 +3775,7 @@ fn updateLazyType( | ... | @@ -3574,7 +3775,7 @@ fn updateLazyType( |
| 3574 | else if (has_runtime_bits) | 3775 | else if (has_runtime_bits) |
| 3575 | try wip_nav.blockValue(src_loc, .fromInterned(comptime_value)); | 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 | .enum_type => { | 3780 | .enum_type => { |
| 3580 | const loaded_enum = ip.loadEnumType(type_index); | 3781 | const loaded_enum = ip.loadEnumType(type_index); |
| ... | @@ -3589,7 +3790,7 @@ fn updateLazyType( | ... | @@ -3589,7 +3790,7 @@ fn updateLazyType( |
| 3589 | }, field_index); | 3790 | }, field_index); |
| 3590 | try wip_nav.strp(loaded_enum.names.get(ip)[field_index].toSlice(ip)); | 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 | .func_type => |func_type| { | 3795 | .func_type => |func_type| { |
| 3595 | const is_nullary = func_type.param_types.len == 0 and !func_type.is_var_args; | 3796 | const is_nullary = func_type.param_types.len == 0 and !func_type.is_var_args; |
| ... | @@ -3665,7 +3866,7 @@ fn updateLazyType( | ... | @@ -3665,7 +3866,7 @@ fn updateLazyType( |
| 3665 | try wip_nav.refType(.fromInterned(func_type.param_types.get(ip)[param_index])); | 3866 | try wip_nav.refType(.fromInterned(func_type.param_types.get(ip)[param_index])); |
| 3666 | } | 3867 | } |
| 3667 | if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args); | 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 | .error_set_type => |error_set_type| { | 3872 | .error_set_type => |error_set_type| { |
| ... | @@ -3678,10 +3879,10 @@ fn updateLazyType( | ... | @@ -3678,10 +3879,10 @@ fn updateLazyType( |
| 3678 | for (0..error_set_type.names.len) |field_index| { | 3879 | for (0..error_set_type.names.len) |field_index| { |
| 3679 | const field_name = error_set_type.names.get(ip)[field_index]; | 3880 | const field_name = error_set_type.names.get(ip)[field_index]; |
| 3680 | try wip_nav.abbrevCode(.unsigned_enum_field); | 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 | try wip_nav.strp(field_name.toSlice(ip)); | 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 | .inferred_error_set_type => |func| { | 3887 | .inferred_error_set_type => |func| { |
| 3687 | try wip_nav.abbrevCode(.inferred_error_set_type); | 3888 | try wip_nav.abbrevCode(.inferred_error_set_type); |
| ... | @@ -3713,7 +3914,7 @@ fn updateLazyType( | ... | @@ -3713,7 +3914,7 @@ fn updateLazyType( |
| 3713 | .memoized_call, | 3914 | .memoized_call, |
| 3714 | => unreachable, | 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 | fn updateLazyValue( | 3920 | fn updateLazyValue( |
| ... | @@ -3722,7 +3923,7 @@ fn updateLazyValue( | ... | @@ -3722,7 +3923,7 @@ fn updateLazyValue( |
| 3722 | src_loc: Zcu.LazySrcLoc, | 3923 | src_loc: Zcu.LazySrcLoc, |
| 3723 | value_index: InternPool.Index, | 3924 | value_index: InternPool.Index, |
| 3724 | pending_lazy: *WipNav.PendingLazy, | 3925 | pending_lazy: *WipNav.PendingLazy, |
| 3725 | ) UpdateError!void { | 3926 | ) (UpdateError || Writer.Error)!void { |
| 3726 | const zcu = pt.zcu; | 3927 | const zcu = pt.zcu; |
| 3727 | const ip = &zcu.intern_pool; | 3928 | const ip = &zcu.intern_pool; |
| 3728 | assert(ip.typeOf(value_index) != .type_type); | 3929 | assert(ip.typeOf(value_index) != .type_type); |
| ... | @@ -3741,10 +3942,10 @@ fn updateLazyValue( | ... | @@ -3741,10 +3942,10 @@ fn updateLazyValue( |
| 3741 | .func_high_pc = undefined, | 3942 | .func_high_pc = undefined, |
| 3742 | .blocks = undefined, | 3943 | .blocks = undefined, |
| 3743 | .cfi = undefined, | 3944 | .cfi = undefined, |
| 3744 | .debug_frame = .empty, | 3945 | .debug_frame = .init(dwarf.gpa), |
| 3745 | .debug_info = .empty, | 3946 | .debug_info = .init(dwarf.gpa), |
| 3746 | .debug_line = .empty, | 3947 | .debug_line = .init(dwarf.gpa), |
| 3747 | .debug_loclists = .empty, | 3948 | .debug_loclists = .init(dwarf.gpa), |
| 3748 | .pending_lazy = pending_lazy.*, | 3949 | .pending_lazy = pending_lazy.*, |
| 3749 | }; | 3950 | }; |
| 3750 | defer { | 3951 | defer { |
| ... | @@ -3752,7 +3953,7 @@ fn updateLazyValue( | ... | @@ -3752,7 +3953,7 @@ fn updateLazyValue( |
| 3752 | wip_nav.pending_lazy = .empty; | 3953 | wip_nav.pending_lazy = .empty; |
| 3753 | wip_nav.deinit(); | 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 | var big_int_space: Value.BigIntSpace = undefined; | 3957 | var big_int_space: Value.BigIntSpace = undefined; |
| 3757 | switch (ip.indexToKey(value_index)) { | 3958 | switch (ip.indexToKey(value_index)) { |
| 3758 | .int_type, | 3959 | .int_type, |
| ... | @@ -3790,20 +3991,21 @@ fn updateLazyValue( | ... | @@ -3790,20 +3991,21 @@ fn updateLazyValue( |
| 3790 | .err => |err| { | 3991 | .err => |err| { |
| 3791 | try wip_nav.abbrevCode(.udata_comptime_value); | 3992 | try wip_nav.abbrevCode(.udata_comptime_value); |
| 3792 | try wip_nav.refType(.fromInterned(err.ty)); | 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 | .error_union => |error_union| { | 3996 | .error_union => |error_union| { |
| 3796 | try wip_nav.abbrevCode(.aggregate_comptime_value); | 3997 | try wip_nav.abbrevCode(.aggregate_comptime_value); |
| 3797 | const err_abi_size = std.math.divCeil(u17, zcu.errorSetBits(), 8) catch unreachable; | 3998 | var err_buf: [4]u8 = undefined; |
| 3798 | const err_value = switch (error_union.val) { | 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 | .err_name => |err_name| try pt.getErrorValue(err_name), | 4001 | .err_name => |err_name| try pt.getErrorValue(err_name), |
| 3800 | .payload => 0, | 4002 | .payload => 0, |
| 3801 | }; | 4003 | }); |
| 3802 | { | 4004 | { |
| 3803 | try wip_nav.abbrevCode(.comptime_value_field_runtime_bits); | 4005 | try wip_nav.abbrevCode(.comptime_value_field_runtime_bits); |
| 3804 | try wip_nav.strp("is_error"); | 4006 | try wip_nav.strp("is_error"); |
| 3805 | try uleb128(diw, err_abi_size); | 4007 | try diw.writeUleb128(err_bytes.len); |
| 3806 | dwarf.writeInt(try wip_nav.debug_info.addManyAsSlice(dwarf.gpa, err_abi_size), err_value); | 4008 | try diw.writeAll(err_bytes); |
| 3807 | } | 4009 | } |
| 3808 | payload_field: switch (error_union.val) { | 4010 | payload_field: switch (error_union.val) { |
| 3809 | .err_name => {}, | 4011 | .err_name => {}, |
| ... | @@ -3827,18 +4029,11 @@ fn updateLazyValue( | ... | @@ -3827,18 +4029,11 @@ fn updateLazyValue( |
| 3827 | { | 4029 | { |
| 3828 | try wip_nav.abbrevCode(.comptime_value_field_runtime_bits); | 4030 | try wip_nav.abbrevCode(.comptime_value_field_runtime_bits); |
| 3829 | try wip_nav.strp("error"); | 4031 | try wip_nav.strp("error"); |
| 3830 | try uleb128(diw, err_abi_size); | 4032 | try diw.writeUleb128(err_bytes.len); |
| 3831 | dwarf.writeInt(try wip_nav.debug_info.addManyAsSlice(dwarf.gpa, err_abi_size), err_value); | 4033 | try diw.writeAll(err_bytes); |
| 3832 | } | | |
| 3833 | switch (error_union.val) { | | |
| 3834 | .err_name => {}, | | |
| 3835 | .payload => |payload| { | | |
| 3836 | _ = payload; | | |
| 3837 | try wip_nav.abbrevCode(.aggregate_comptime_value); | | |
| 3838 | }, | | |
| 3839 | } | 4034 | } |
| 3840 | try wip_nav.refType(.fromInterned(error_union.ty)); | 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 | .enum_literal => |enum_literal| { | 4038 | .enum_literal => |enum_literal| { |
| 3844 | try wip_nav.abbrevCode(.string_comptime_value); | 4039 | try wip_nav.abbrevCode(.string_comptime_value); |
| ... | @@ -3871,7 +4066,7 @@ fn updateLazyValue( | ... | @@ -3871,7 +4066,7 @@ fn updateLazyValue( |
| 3871 | }, | 4066 | }, |
| 3872 | .f80 => |f80_val| { | 4067 | .f80 => |f80_val| { |
| 3873 | try wip_nav.abbrevCode(.block_comptime_value); | 4068 | try wip_nav.abbrevCode(.block_comptime_value); |
| 3874 | try uleb128(diw, @divExact(80, 8)); | 4069 | try diw.writeUleb128(@divExact(80, 8)); |
| 3875 | try diw.writeInt(u80, @bitCast(f80_val), dwarf.endian); | 4070 | try diw.writeInt(u80, @bitCast(f80_val), dwarf.endian); |
| 3876 | }, | 4071 | }, |
| 3877 | .f128 => |f128_val| { | 4072 | .f128 => |f128_val| { |
| ... | @@ -3893,14 +4088,14 @@ fn updateLazyValue( | ... | @@ -3893,14 +4088,14 @@ fn updateLazyValue( |
| 3893 | const uav_ty: Type = .fromInterned(ip.typeOf(uav.val)); | 4088 | const uav_ty: Type = .fromInterned(ip.typeOf(uav.val)); |
| 3894 | if (try uav_ty.onePossibleValue(pt)) |_| { | 4089 | if (try uav_ty.onePossibleValue(pt)) |_| { |
| 3895 | try wip_nav.abbrevCode(.udata_comptime_value); | 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 | uav_ty.abiAlignment(zcu).toByteUnits().?); | 4092 | uav_ty.abiAlignment(zcu).toByteUnits().?); |
| 3898 | break :location; | 4093 | break :location; |
| 3899 | } else break try wip_nav.getValueEntry(.fromInterned(uav.val)); | 4094 | } else break try wip_nav.getValueEntry(.fromInterned(uav.val)); |
| 3900 | }, | 4095 | }, |
| 3901 | .int => { | 4096 | .int => { |
| 3902 | try wip_nav.abbrevCode(.udata_comptime_value); | 4097 | try wip_nav.abbrevCode(.udata_comptime_value); |
| 3903 | try uleb128(diw, byte_offset); | 4098 | try diw.writeUleb128(byte_offset); |
| 3904 | break :location; | 4099 | break :location; |
| 3905 | }, | 4100 | }, |
| 3906 | .eu_payload => |eu_ptr| { | 4101 | .eu_payload => |eu_ptr| { |
| ... | @@ -3939,7 +4134,7 @@ fn updateLazyValue( | ... | @@ -3939,7 +4134,7 @@ fn updateLazyValue( |
| 3939 | try wip_nav.strp("len"); | 4134 | try wip_nav.strp("len"); |
| 3940 | try wip_nav.blockValue(src_loc, .fromInterned(slice.len)); | 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 | .opt => |opt| { | 4139 | .opt => |opt| { |
| 3945 | const opt_child_type: Type = .fromInterned(ip.indexToKey(opt.ty).opt_type); | 4140 | const opt_child_type: Type = .fromInterned(ip.indexToKey(opt.ty).opt_type); |
| ... | @@ -3949,7 +4144,7 @@ fn updateLazyValue( | ... | @@ -3949,7 +4144,7 @@ fn updateLazyValue( |
| 3949 | try wip_nav.abbrevCode(.comptime_value_field_runtime_bits); | 4144 | try wip_nav.abbrevCode(.comptime_value_field_runtime_bits); |
| 3950 | try wip_nav.strp("has_value"); | 4145 | try wip_nav.strp("has_value"); |
| 3951 | switch (optRepr(opt_child_type, zcu)) { | 4146 | switch (optRepr(opt_child_type, zcu)) { |
| 3952 | .opv_null => try uleb128(diw, 0), | 4147 | .opv_null => try diw.writeUleb128(0), |
| 3953 | .unpacked => try wip_nav.blockValue(src_loc, .makeBool(opt.val != .none)), | 4148 | .unpacked => try wip_nav.blockValue(src_loc, .makeBool(opt.val != .none)), |
| 3954 | .error_set => try wip_nav.blockValue(src_loc, .fromInterned(value_index)), | 4149 | .error_set => try wip_nav.blockValue(src_loc, .fromInterned(value_index)), |
| 3955 | .pointer => if (opt_child_type.comptimeOnly(zcu)) { | 4150 | .pointer => if (opt_child_type.comptimeOnly(zcu)) { |
| ... | @@ -3959,7 +4154,7 @@ fn updateLazyValue( | ... | @@ -3959,7 +4154,7 @@ fn updateLazyValue( |
| 3959 | .none => 0, | 4154 | .none => 0, |
| 3960 | else => opt_child_type.ptrAlignment(zcu).toByteUnits().?, | 4155 | else => opt_child_type.ptrAlignment(zcu).toByteUnits().?, |
| 3961 | }); | 4156 | }); |
| 3962 | try uleb128(diw, bytes.len); | 4157 | try diw.writeUleb128(bytes.len); |
| 3963 | try diw.writeAll(bytes); | 4158 | try diw.writeAll(bytes); |
| 3964 | } else try wip_nav.blockValue(src_loc, .fromInterned(value_index)), | 4159 | } else try wip_nav.blockValue(src_loc, .fromInterned(value_index)), |
| 3965 | } | 4160 | } |
| ... | @@ -3979,7 +4174,7 @@ fn updateLazyValue( | ... | @@ -3979,7 +4174,7 @@ fn updateLazyValue( |
| 3979 | else | 4174 | else |
| 3980 | try wip_nav.blockValue(src_loc, .fromInterned(opt.val)); | 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 | .aggregate => |aggregate| { | 4179 | .aggregate => |aggregate| { |
| 3985 | try wip_nav.abbrevCode(.aggregate_comptime_value); | 4180 | try wip_nav.abbrevCode(.aggregate_comptime_value); |
| ... | @@ -4064,7 +4259,7 @@ fn updateLazyValue( | ... | @@ -4064,7 +4259,7 @@ fn updateLazyValue( |
| 4064 | }, | 4259 | }, |
| 4065 | else => unreachable, | 4260 | else => unreachable, |
| 4066 | } | 4261 | } |
| 4067 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); | 4262 | try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4068 | }, | 4263 | }, |
| 4069 | .un => |un| { | 4264 | .un => |un| { |
| 4070 | try wip_nav.abbrevCode(.aggregate_comptime_value); | 4265 | try wip_nav.abbrevCode(.aggregate_comptime_value); |
| ... | @@ -4089,11 +4284,11 @@ fn updateLazyValue( | ... | @@ -4089,11 +4284,11 @@ fn updateLazyValue( |
| 4089 | else | 4284 | else |
| 4090 | try wip_nav.blockValue(src_loc, .fromInterned(un.val)); | 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 | .memoized_call => unreachable, // not a value | 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 | fn optRepr(opt_child_type: Type, zcu: *const Zcu) enum { | 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,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 | const zcu = pt.zcu; | 4326 | const zcu = pt.zcu; |
| 4118 | const ip = &zcu.intern_pool; | 4327 | const ip = &zcu.intern_pool; |
| 4119 | const ty: Type = .fromInterned(type_index); | 4328 | const ty: Type = .fromInterned(type_index); |
| ... | @@ -4138,23 +4347,23 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -4138,23 +4347,23 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4138 | .func_high_pc = undefined, | 4347 | .func_high_pc = undefined, |
| 4139 | .blocks = undefined, | 4348 | .blocks = undefined, |
| 4140 | .cfi = undefined, | 4349 | .cfi = undefined, |
| 4141 | .debug_frame = .empty, | 4350 | .debug_frame = .init(dwarf.gpa), |
| 4142 | .debug_info = .empty, | 4351 | .debug_info = .init(dwarf.gpa), |
| 4143 | .debug_line = .empty, | 4352 | .debug_line = .init(dwarf.gpa), |
| 4144 | .debug_loclists = .empty, | 4353 | .debug_loclists = .init(dwarf.gpa), |
| 4145 | .pending_lazy = .empty, | 4354 | .pending_lazy = .empty, |
| 4146 | }; | 4355 | }; |
| 4147 | defer wip_nav.deinit(); | 4356 | defer wip_nav.deinit(); |
| 4148 | | 4357 | |
| 4149 | const loaded_struct = ip.loadStructType(type_index); | 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 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .empty_file else .file); | 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 | try wip_nav.strp(loaded_struct.name.toSlice(ip)); | 4363 | try wip_nav.strp(loaded_struct.name.toSlice(ip)); |
| 4155 | if (loaded_struct.field_types.len > 0) { | 4364 | if (loaded_struct.field_types.len > 0) { |
| 4156 | try uleb128(diw, ty.abiSize(zcu)); | 4365 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 4157 | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); | 4366 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 4158 | for (0..loaded_struct.field_types.len) |field_index| { | 4367 | for (0..loaded_struct.field_types.len) |field_index| { |
| 4159 | const is_comptime = loaded_struct.fieldIsComptime(ip, field_index); | 4368 | const is_comptime = loaded_struct.fieldIsComptime(ip, field_index); |
| 4160 | const field_init = loaded_struct.fieldInit(ip, field_index); | 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,8 +4399,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4190 | } | 4399 | } |
| 4191 | try wip_nav.refType(field_type); | 4400 | try wip_nav.refType(field_type); |
| 4192 | if (!is_comptime) { | 4401 | if (!is_comptime) { |
| 4193 | try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]); | 4402 | try diw.writeUleb128(loaded_struct.offsets.get(ip)[field_index]); |
| 4194 | try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse | 4403 | try diw.writeUleb128(loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse |
| 4195 | field_type.abiAlignment(zcu).toByteUnits().?); | 4404 | field_type.abiAlignment(zcu).toByteUnits().?); |
| 4196 | } | 4405 | } |
| 4197 | if (has_comptime_state) | 4406 | if (has_comptime_state) |
| ... | @@ -4199,10 +4408,10 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -4199,10 +4408,10 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4199 | else if (has_runtime_bits) | 4408 | else if (has_runtime_bits) |
| 4200 | try wip_nav.blockValue(ty_src_loc, .fromInterned(field_init)); | 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 | try wip_nav.updateLazy(ty_src_loc); | 4415 | try wip_nav.updateLazy(ty_src_loc); |
| 4207 | } else { | 4416 | } else { |
| 4208 | { | 4417 | { |
| ... | @@ -4239,14 +4448,14 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -4239,14 +4448,14 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4239 | .func_high_pc = undefined, | 4448 | .func_high_pc = undefined, |
| 4240 | .blocks = undefined, | 4449 | .blocks = undefined, |
| 4241 | .cfi = undefined, | 4450 | .cfi = undefined, |
| 4242 | .debug_frame = .empty, | 4451 | .debug_frame = .init(dwarf.gpa), |
| 4243 | .debug_info = .empty, | 4452 | .debug_info = .init(dwarf.gpa), |
| 4244 | .debug_line = .empty, | 4453 | .debug_line = .init(dwarf.gpa), |
| 4245 | .debug_loclists = .empty, | 4454 | .debug_loclists = .init(dwarf.gpa), |
| 4246 | .pending_lazy = .empty, | 4455 | .pending_lazy = .empty, |
| 4247 | }; | 4456 | }; |
| 4248 | defer wip_nav.deinit(); | 4457 | defer wip_nav.deinit(); |
| 4249 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 4458 | const diw = &wip_nav.debug_info.writer; |
| 4250 | const name = try std.fmt.allocPrint(dwarf.gpa, "{f}", .{ty.fmt(pt)}); | 4459 | const name = try std.fmt.allocPrint(dwarf.gpa, "{f}", .{ty.fmt(pt)}); |
| 4251 | defer dwarf.gpa.free(name); | 4460 | defer dwarf.gpa.free(name); |
| 4252 | | 4461 | |
| ... | @@ -4256,11 +4465,11 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -4256,11 +4465,11 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4256 | switch (loaded_struct.layout) { | 4465 | switch (loaded_struct.layout) { |
| 4257 | .auto, .@"extern" => { | 4466 | .auto, .@"extern" => { |
| 4258 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .empty_struct_type else .struct_type); | 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 | try wip_nav.strp(name); | 4469 | try wip_nav.strp(name); |
| 4261 | if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else { | 4470 | if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else { |
| 4262 | try uleb128(diw, ty.abiSize(zcu)); | 4471 | try diw.writeUleb128(ty.abiSize(zcu)); |
| 4263 | try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); | 4472 | try diw.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 4264 | for (0..loaded_struct.field_types.len) |field_index| { | 4473 | for (0..loaded_struct.field_types.len) |field_index| { |
| 4265 | const is_comptime = loaded_struct.fieldIsComptime(ip, field_index); | 4474 | const is_comptime = loaded_struct.fieldIsComptime(ip, field_index); |
| 4266 | const field_init = loaded_struct.fieldInit(ip, field_index); | 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,8 +4505,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4296 | } | 4505 | } |
| 4297 | try wip_nav.refType(field_type); | 4506 | try wip_nav.refType(field_type); |
| 4298 | if (!is_comptime) { | 4507 | if (!is_comptime) { |
| 4299 | try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]); | 4508 | try diw.writeUleb128(loaded_struct.offsets.get(ip)[field_index]); |
| 4300 | try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse | 4509 | try diw.writeUleb128(loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse |
| 4301 | field_type.abiAlignment(zcu).toByteUnits().?); | 4510 | field_type.abiAlignment(zcu).toByteUnits().?); |
| 4302 | } | 4511 | } |
| 4303 | if (has_comptime_state) | 4512 | if (has_comptime_state) |
| ... | @@ -4305,12 +4514,12 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -4305,12 +4514,12 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4305 | else if (has_runtime_bits) | 4514 | else if (has_runtime_bits) |
| 4306 | try wip_nav.blockValue(ty_src_loc, .fromInterned(field_init)); | 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 | .@"packed" => { | 4520 | .@"packed" => { |
| 4312 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len > 0) .packed_struct_type else .empty_packed_struct_type); | 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 | try wip_nav.strp(name); | 4523 | try wip_nav.strp(name); |
| 4315 | try wip_nav.refType(.fromInterned(loaded_struct.backingIntTypeUnordered(ip))); | 4524 | try wip_nav.refType(.fromInterned(loaded_struct.backingIntTypeUnordered(ip))); |
| 4316 | var field_bit_offset: u16 = 0; | 4525 | var field_bit_offset: u16 = 0; |
| ... | @@ -4319,17 +4528,17 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -4319,17 +4528,17 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4319 | try wip_nav.strp(loaded_struct.fieldName(ip, field_index).unwrap().?.toSlice(ip)); | 4528 | try wip_nav.strp(loaded_struct.fieldName(ip, field_index).unwrap().?.toSlice(ip)); |
| 4320 | const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]); | 4529 | const field_type: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]); |
| 4321 | try wip_nav.refType(field_type); | 4530 | try wip_nav.refType(field_type); |
| 4322 | try uleb128(diw, field_bit_offset); | 4531 | try diw.writeUleb128(field_bit_offset); |
| 4323 | field_bit_offset += @intCast(field_type.bitSize(zcu)); | 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 | .enum_type => { | 4538 | .enum_type => { |
| 4330 | const loaded_enum = ip.loadEnumType(type_index); | 4539 | const loaded_enum = ip.loadEnumType(type_index); |
| 4331 | try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .enum_type else .empty_enum_type); | 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 | try wip_nav.strp(name); | 4542 | try wip_nav.strp(name); |
| 4334 | try wip_nav.refType(.fromInterned(loaded_enum.tag_ty)); | 4543 | try wip_nav.refType(.fromInterned(loaded_enum.tag_ty)); |
| 4335 | for (0..loaded_enum.names.len) |field_index| { | 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,16 +4549,16 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4340 | }, field_index); | 4549 | }, field_index); |
| 4341 | try wip_nav.strp(loaded_enum.names.get(ip)[field_index].toSlice(ip)); | 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 | .union_type => { | 4554 | .union_type => { |
| 4346 | const loaded_union = ip.loadUnionType(type_index); | 4555 | const loaded_union = ip.loadUnionType(type_index); |
| 4347 | try wip_nav.abbrevCode(if (loaded_union.field_types.len > 0) .union_type else .empty_union_type); | 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 | try wip_nav.strp(name); | 4558 | try wip_nav.strp(name); |
| 4350 | const union_layout = Type.getUnionLayout(loaded_union, zcu); | 4559 | const union_layout = Type.getUnionLayout(loaded_union, zcu); |
| 4351 | try uleb128(diw, union_layout.abi_size); | 4560 | try diw.writeUleb128(union_layout.abi_size); |
| 4352 | try uleb128(diw, union_layout.abi_align.toByteUnits().?); | 4561 | try diw.writeUleb128(union_layout.abi_align.toByteUnits().?); |
| 4353 | const loaded_tag = loaded_union.loadTagType(ip); | 4562 | const loaded_tag = loaded_union.loadTagType(ip); |
| 4354 | if (loaded_union.hasTag(ip)) { | 4563 | if (loaded_union.hasTag(ip)) { |
| 4355 | try wip_nav.abbrevCode(.tagged_union); | 4564 | try wip_nav.abbrevCode(.tagged_union); |
| ... | @@ -4357,13 +4566,13 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -4357,13 +4566,13 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4357 | .debug_info, | 4566 | .debug_info, |
| 4358 | wip_nav.unit, | 4567 | wip_nav.unit, |
| 4359 | wip_nav.entry, | 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 | try wip_nav.abbrevCode(.generated_field); | 4572 | try wip_nav.abbrevCode(.generated_field); |
| 4364 | try wip_nav.strp("tag"); | 4573 | try wip_nav.strp("tag"); |
| 4365 | try wip_nav.refType(.fromInterned(loaded_union.enum_tag_ty)); | 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 | for (0..loaded_union.field_types.len) |field_index| { | 4577 | for (0..loaded_union.field_types.len) |field_index| { |
| 4369 | try wip_nav.enumConstValue(loaded_tag, .{ | 4578 | try wip_nav.enumConstValue(loaded_tag, .{ |
| ... | @@ -4376,34 +4585,34 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP | ... | @@ -4376,34 +4585,34 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4376 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); | 4585 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); |
| 4377 | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); | 4586 | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 4378 | try wip_nav.refType(field_type); | 4587 | try wip_nav.refType(field_type); |
| 4379 | try uleb128(diw, union_layout.payloadOffset()); | 4588 | try diw.writeUleb128(union_layout.payloadOffset()); |
| 4380 | try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse | 4589 | try diw.writeUleb128(loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse |
| 4381 | if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?); | 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 | } else for (0..loaded_union.field_types.len) |field_index| { | 4596 | } else for (0..loaded_union.field_types.len) |field_index| { |
| 4388 | try wip_nav.abbrevCode(.untagged_union_field); | 4597 | try wip_nav.abbrevCode(.untagged_union_field); |
| 4389 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); | 4598 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); |
| 4390 | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); | 4599 | const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 4391 | try wip_nav.refType(field_type); | 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 | field_type.abiAlignment(zcu).toByteUnits().?); | 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 | .opaque_type => { | 4606 | .opaque_type => { |
| 4398 | try wip_nav.abbrevCode(.empty_struct_type); | 4607 | try wip_nav.abbrevCode(.empty_struct_type); |
| 4399 | try uleb128(diw, file_gop.index); | 4608 | try diw.writeUleb128(file_gop.index); |
| 4400 | try wip_nav.strp(name); | 4609 | try wip_nav.strp(name); |
| 4401 | try diw.writeByte(@intFromBool(true)); | 4610 | try diw.writeByte(@intFromBool(true)); |
| 4402 | }, | 4611 | }, |
| 4403 | else => unreachable, | 4612 | else => unreachable, |
| 4404 | } | 4613 | } |
| 4405 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items); | 4614 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.getWritten()); |
| 4406 | try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.items); | 4615 | try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.getWritten()); |
| 4407 | try wip_nav.updateLazy(ty_src_loc); | 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,24 +4645,33 @@ pub fn freeNav(dwarf: *Dwarf, nav_index: InternPool.Nav.Index) void { |
| 4436 | _ = nav_index; | 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 | assert(abbrev_code != .null); | 4652 | assert(abbrev_code != .null); |
| 4441 | const entry: Entry.Index = @enumFromInt(@intFromEnum(abbrev_code)); | 4653 | const entry: Entry.Index = @enumFromInt(@intFromEnum(abbrev_code)); |
| 4442 | if (dwarf.debug_abbrev.section.getUnit(DebugAbbrev.unit).getEntry(entry).len > 0) return @intFromEnum(abbrev_code); | 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); | 4655 | var debug_abbrev_aw: Writer.Allocating = .init(dwarf.gpa); |
| 4444 | defer debug_abbrev.deinit(); | 4656 | defer debug_abbrev_aw.deinit(); |
| 4445 | const daw = debug_abbrev.writer(); | 4657 | const daw = &debug_abbrev_aw.writer; |
| 4446 | const abbrev = AbbrevCode.abbrevs.get(abbrev_code); | 4658 | const abbrev = AbbrevCode.abbrevs.get(abbrev_code); |
| 4447 | try uleb128(daw, @intFromEnum(abbrev_code)); | 4659 | try daw.writeUleb128(@intFromEnum(abbrev_code)); |
| 4448 | try uleb128(daw, @intFromEnum(abbrev.tag)); | 4660 | try daw.writeUleb128(@intFromEnum(abbrev.tag)); |
| 4449 | try daw.writeByte(if (abbrev.children) DW.CHILDREN.yes else DW.CHILDREN.no); | 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)); | 4662 | for (abbrev.attrs) |*attr| inline for (attr) |info| try daw.writeUleb128(@intFromEnum(info)); |
| 4451 | for (0..2) |_| try uleb128(daw, 0); | 4663 | for (0..2) |_| try daw.writeUleb128(0); |
| 4452 | try dwarf.debug_abbrev.section.replaceEntry(DebugAbbrev.unit, entry, dwarf, debug_abbrev.items); | 4664 | try dwarf.debug_abbrev.section.replaceEntry(DebugAbbrev.unit, entry, dwarf, debug_abbrev_aw.getWritten()); |
| 4453 | return @intFromEnum(abbrev_code); | 4665 | return @intFromEnum(abbrev_code); |
| 4454 | } | 4666 | } |
| 4455 | | 4667 | |
| 4456 | pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | 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 | const zcu = pt.zcu; | 4675 | const zcu = pt.zcu; |
| 4458 | const ip = &zcu.intern_pool; | 4676 | const ip = &zcu.intern_pool; |
| 4459 | | 4677 | |
| ... | @@ -4471,14 +4689,14 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -4471,14 +4689,14 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4471 | .func_high_pc = undefined, | 4689 | .func_high_pc = undefined, |
| 4472 | .blocks = undefined, | 4690 | .blocks = undefined, |
| 4473 | .cfi = undefined, | 4691 | .cfi = undefined, |
| 4474 | .debug_frame = .empty, | 4692 | .debug_frame = .init(dwarf.gpa), |
| 4475 | .debug_info = .empty, | 4693 | .debug_info = .init(dwarf.gpa), |
| 4476 | .debug_line = .empty, | 4694 | .debug_line = .init(dwarf.gpa), |
| 4477 | .debug_loclists = .empty, | 4695 | .debug_loclists = .init(dwarf.gpa), |
| 4478 | .pending_lazy = .empty, | 4696 | .pending_lazy = .empty, |
| 4479 | }; | 4697 | }; |
| 4480 | defer wip_nav.deinit(); | 4698 | defer wip_nav.deinit(); |
| 4481 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 4699 | const diw = &wip_nav.debug_info.writer; |
| 4482 | const global_error_set_names = ip.global_error_set.getNamesFromMainThread(); | 4700 | const global_error_set_names = ip.global_error_set.getNamesFromMainThread(); |
| 4483 | try wip_nav.abbrevCode(if (global_error_set_names.len == 0) .generated_empty_enum_type else .generated_enum_type); | 4701 | try wip_nav.abbrevCode(if (global_error_set_names.len == 0) .generated_empty_enum_type else .generated_enum_type); |
| 4484 | try wip_nav.strp("anyerror"); | 4702 | try wip_nav.strp("anyerror"); |
| ... | @@ -4488,11 +4706,11 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -4488,11 +4706,11 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4488 | } }))); | 4706 | } }))); |
| 4489 | for (global_error_set_names, 1..) |name, value| { | 4707 | for (global_error_set_names, 1..) |name, value| { |
| 4490 | try wip_nav.abbrevCode(.unsigned_enum_field); | 4708 | try wip_nav.abbrevCode(.unsigned_enum_field); |
| 4491 | try uleb128(diw, value); | 4709 | try diw.writeUleb128(value); |
| 4492 | try wip_nav.strp(name.toSlice(ip)); | 4710 | try wip_nav.strp(name.toSlice(ip)); |
| 4493 | } | 4711 | } |
| 4494 | if (global_error_set_names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); | 4712 | if (global_error_set_names.len > 0) try diw.writeUleb128(@intFromEnum(AbbrevCode.null)); |
| 4495 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items); | 4713 | try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.getWritten()); |
| 4496 | try wip_nav.updateLazy(.unneeded); | 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,36 +4720,38 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4502 | mod_info.root_dir_path = try dwarf.debug_line_str.addString(dwarf, root_dir_path); | 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); | 4723 | var header_aw: Writer.Allocating = .init(dwarf.gpa); |
| 4506 | defer header.deinit(); | 4724 | defer header_aw.deinit(); |
| | 4725 | const hw = &header_aw.writer; |
| 4507 | if (dwarf.debug_aranges.section.dirty) { | 4726 | if (dwarf.debug_aranges.section.dirty) { |
| 4508 | for (dwarf.debug_aranges.section.units.items, 0..) |*unit_ptr, unit_index| { | 4727 | for (dwarf.debug_aranges.section.units.items, 0..) |*unit_ptr, unit_index| { |
| 4509 | const unit: Unit.Index = @enumFromInt(unit_index); | 4728 | const unit: Unit.Index = @enumFromInt(unit_index); |
| 4510 | unit_ptr.clear(); | 4729 | unit_ptr.clear(); |
| 4511 | try unit_ptr.cross_section_relocs.ensureTotalCapacity(dwarf.gpa, 1); | 4730 | try unit_ptr.cross_section_relocs.ensureTotalCapacity(dwarf.gpa, 1); |
| 4512 | header.clearRetainingCapacity(); | 4731 | header_aw.clearRetainingCapacity(); |
| 4513 | try header.ensureTotalCapacity(unit_ptr.header_len); | 4732 | try header_aw.ensureTotalCapacity(unit_ptr.header_len); |
| 4514 | const unit_len = (if (unit_ptr.next.unwrap()) |next_unit| | 4733 | const unit_len = (if (unit_ptr.next.unwrap()) |next_unit| |
| 4515 | dwarf.debug_aranges.section.getUnit(next_unit).off | 4734 | dwarf.debug_aranges.section.getUnit(next_unit).off |
| 4516 | else | 4735 | else |
| 4517 | dwarf.debug_aranges.section.len) - unit_ptr.off - dwarf.unitLengthBytes(); | 4736 | dwarf.debug_aranges.section.len) - unit_ptr.off - dwarf.unitLengthBytes(); |
| 4518 | switch (dwarf.format) { | 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 | .@"64" => { | 4739 | .@"64" => { |
| 4521 | std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), std.math.maxInt(u32), dwarf.endian); | 4740 | hw.writeInt(u32, std.math.maxInt(u32), dwarf.endian) catch unreachable; |
| 4522 | std.mem.writeInt(u64, header.addManyAsArrayAssumeCapacity(8), unit_len, dwarf.endian); | 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 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ | 4745 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4527 | .source_off = @intCast(header.items.len), | 4746 | .source_off = @intCast(hw.end), |
| 4528 | .target_sec = .debug_info, | 4747 | .target_sec = .debug_info, |
| 4529 | .target_unit = unit, | 4748 | .target_unit = unit, |
| 4530 | }); | 4749 | }); |
| 4531 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); | 4750 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4532 | header.appendSliceAssumeCapacity(&.{ @intFromEnum(dwarf.address_size), 0 }); | 4751 | hw.writeByte(@intFromEnum(dwarf.address_size)) catch unreachable; |
| 4533 | header.appendNTimesAssumeCapacity(0, unit_ptr.header_len - header.items.len); | 4752 | hw.writeByte(0) catch unreachable; |
| 4534 | try unit_ptr.replaceHeader(&dwarf.debug_aranges.section, dwarf, header.items); | 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 | try unit_ptr.writeTrailer(&dwarf.debug_aranges.section, dwarf); | 4755 | try unit_ptr.writeTrailer(&dwarf.debug_aranges.section, dwarf); |
| 4536 | } | 4756 | } |
| 4537 | dwarf.debug_aranges.section.dirty = false; | 4757 | dwarf.debug_aranges.section.dirty = false; |
| ... | @@ -4546,31 +4766,31 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -4546,31 +4766,31 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4546 | dev.check(.x86_64_backend); | 4766 | dev.check(.x86_64_backend); |
| 4547 | const Register = @import("../arch/x86_64/bits.zig").Register; | 4767 | const Register = @import("../arch/x86_64/bits.zig").Register; |
| 4548 | for (dwarf.debug_frame.section.units.items) |*unit| { | 4768 | for (dwarf.debug_frame.section.units.items) |*unit| { |
| 4549 | header.clearRetainingCapacity(); | 4769 | header_aw.clearRetainingCapacity(); |
| 4550 | try header.ensureTotalCapacity(unit.header_len); | 4770 | try header_aw.ensureTotalCapacity(unit.header_len); |
| 4551 | const unit_len = unit.header_len - dwarf.unitLengthBytes(); | 4771 | const unit_len = unit.header_len - dwarf.unitLengthBytes(); |
| 4552 | switch (dwarf.format) { | 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 | .@"64" => { | 4774 | .@"64" => { |
| 4555 | std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), std.math.maxInt(u32), dwarf.endian); | 4775 | hw.writeInt(u32, std.math.maxInt(u32), dwarf.endian) catch unreachable; |
| 4556 | std.mem.writeInt(u64, header.addManyAsArrayAssumeCapacity(8), unit_len, dwarf.endian); | 4776 | hw.writeInt(u64, unit_len, dwarf.endian) catch unreachable; |
| 4557 | }, | 4777 | }, |
| 4558 | } | 4778 | } |
| 4559 | header.appendNTimesAssumeCapacity(0, 4); | 4779 | hw.splatByteAll(0, 4) catch unreachable; |
| 4560 | header.appendAssumeCapacity(1); | 4780 | hw.writeByte(1) catch unreachable; |
| 4561 | header.appendSliceAssumeCapacity("zR\x00"); | 4781 | hw.writeAll("zR\x00") catch unreachable; |
| 4562 | uleb128(header.fixedWriter(), dwarf.debug_frame.header.code_alignment_factor) catch unreachable; | 4782 | hw.writeUleb128(dwarf.debug_frame.header.code_alignment_factor) catch unreachable; |
| 4563 | sleb128(header.fixedWriter(), dwarf.debug_frame.header.data_alignment_factor) catch unreachable; | 4783 | hw.writeSleb128(dwarf.debug_frame.header.data_alignment_factor) catch unreachable; |
| 4564 | uleb128(header.fixedWriter(), dwarf.debug_frame.header.return_address_register) catch unreachable; | 4784 | hw.writeUleb128(dwarf.debug_frame.header.return_address_register) catch unreachable; |
| 4565 | uleb128(header.fixedWriter(), 1) catch unreachable; | 4785 | hw.writeUleb128(1) catch unreachable; |
| 4566 | header.appendAssumeCapacity(DW.EH.PE.pcrel | DW.EH.PE.sdata4); | 4786 | hw.writeByte(DW.EH.PE.pcrel | DW.EH.PE.sdata4) catch unreachable; |
| 4567 | header.appendAssumeCapacity(DW.CFA.def_cfa_sf); | 4787 | hw.writeByte(DW.CFA.def_cfa_sf) catch unreachable; |
| 4568 | uleb128(header.fixedWriter(), Register.rsp.dwarfNum()) catch unreachable; | 4788 | hw.writeUleb128(Register.rsp.dwarfNum()) catch unreachable; |
| 4569 | sleb128(header.fixedWriter(), -1) catch unreachable; | 4789 | hw.writeSleb128(-1) catch unreachable; |
| 4570 | header.appendAssumeCapacity(@as(u8, DW.CFA.offset) + Register.rip.dwarfNum()); | 4790 | hw.writeByte(@as(u8, DW.CFA.offset) + Register.rip.dwarfNum()) catch unreachable; |
| 4571 | uleb128(header.fixedWriter(), 1) catch unreachable; | 4791 | hw.writeUleb128(1) catch unreachable; |
| 4572 | header.appendNTimesAssumeCapacity(DW.CFA.nop, unit.header_len - header.items.len); | 4792 | hw.splatByteAll(DW.CFA.nop, unit.header_len - hw.end) catch unreachable; |
| 4573 | try unit.replaceHeader(&dwarf.debug_frame.section, dwarf, header.items); | 4793 | try unit.replaceHeader(&dwarf.debug_frame.section, dwarf, header_aw.getWritten()); |
| 4574 | try unit.writeTrailer(&dwarf.debug_frame.section, dwarf); | 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,81 +4805,82 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4585 | unit_ptr.clear(); | 4805 | unit_ptr.clear(); |
| 4586 | try unit_ptr.cross_unit_relocs.ensureTotalCapacity(dwarf.gpa, 1); | 4806 | try unit_ptr.cross_unit_relocs.ensureTotalCapacity(dwarf.gpa, 1); |
| 4587 | try unit_ptr.cross_section_relocs.ensureTotalCapacity(dwarf.gpa, 7); | 4807 | try unit_ptr.cross_section_relocs.ensureTotalCapacity(dwarf.gpa, 7); |
| 4588 | header.clearRetainingCapacity(); | 4808 | header_aw.clearRetainingCapacity(); |
| 4589 | try header.ensureTotalCapacity(unit_ptr.header_len); | 4809 | try header_aw.ensureTotalCapacity(unit_ptr.header_len); |
| 4590 | const unit_len = (if (unit_ptr.next.unwrap()) |next_unit| | 4810 | const unit_len = (if (unit_ptr.next.unwrap()) |next_unit| |
| 4591 | dwarf.debug_info.section.getUnit(next_unit).off | 4811 | dwarf.debug_info.section.getUnit(next_unit).off |
| 4592 | else | 4812 | else |
| 4593 | dwarf.debug_info.section.len) - unit_ptr.off - dwarf.unitLengthBytes(); | 4813 | dwarf.debug_info.section.len) - unit_ptr.off - dwarf.unitLengthBytes(); |
| 4594 | switch (dwarf.format) { | 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 | .@"64" => { | 4816 | .@"64" => { |
| 4597 | std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), std.math.maxInt(u32), dwarf.endian); | 4817 | hw.writeInt(u32, std.math.maxInt(u32), dwarf.endian) catch unreachable; |
| 4598 | std.mem.writeInt(u64, header.addManyAsArrayAssumeCapacity(8), unit_len, dwarf.endian); | 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); | 4821 | hw.writeInt(u16, 5, dwarf.endian) catch unreachable; |
| 4602 | header.appendSliceAssumeCapacity(&.{ DW.UT.compile, @intFromEnum(dwarf.address_size) }); | 4822 | hw.writeByte(DW.UT.compile) catch unreachable; |
| | 4823 | hw.writeByte(@intFromEnum(dwarf.address_size)) catch unreachable; |
| 4603 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ | 4824 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4604 | .source_off = @intCast(header.items.len), | 4825 | .source_off = @intCast(hw.end), |
| 4605 | .target_sec = .debug_abbrev, | 4826 | .target_sec = .debug_abbrev, |
| 4606 | .target_unit = DebugAbbrev.unit, | 4827 | .target_unit = DebugAbbrev.unit, |
| 4607 | }); | 4828 | }); |
| 4608 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); | 4829 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4609 | const compile_unit_off: u32 = @intCast(header.items.len); | 4830 | const compile_unit_off: u32 = @intCast(hw.end); |
| 4610 | uleb128(header.fixedWriter(), try dwarf.refAbbrevCode(.compile_unit)) catch unreachable; | 4831 | hw.writeUleb128(try dwarf.refAbbrevCode(.compile_unit)) catch unreachable; |
| 4611 | header.appendAssumeCapacity(DW.LANG.Zig); | 4832 | hw.writeByte(DW.LANG.Zig) catch unreachable; |
| 4612 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ | 4833 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4613 | .source_off = @intCast(header.items.len), | 4834 | .source_off = @intCast(hw.end), |
| 4614 | .target_sec = .debug_line_str, | 4835 | .target_sec = .debug_line_str, |
| 4615 | .target_unit = StringSection.unit, | 4836 | .target_unit = StringSection.unit, |
| 4616 | .target_entry = (try dwarf.debug_line_str.addString(dwarf, "zig " ++ @import("build_options").version)).toOptional(), | 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 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ | 4840 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4620 | .source_off = @intCast(header.items.len), | 4841 | .source_off = @intCast(hw.end), |
| 4621 | .target_sec = .debug_line_str, | 4842 | .target_sec = .debug_line_str, |
| 4622 | .target_unit = StringSection.unit, | 4843 | .target_unit = StringSection.unit, |
| 4623 | .target_entry = mod_info.root_dir_path.toOptional(), | 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 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ | 4847 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4627 | .source_off = @intCast(header.items.len), | 4848 | .source_off = @intCast(hw.end), |
| 4628 | .target_sec = .debug_line_str, | 4849 | .target_sec = .debug_line_str, |
| 4629 | .target_unit = StringSection.unit, | 4850 | .target_unit = StringSection.unit, |
| 4630 | .target_entry = (try dwarf.debug_line_str.addString(dwarf, mod.root_src_path)).toOptional(), | 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 | unit_ptr.cross_unit_relocs.appendAssumeCapacity(.{ | 4854 | unit_ptr.cross_unit_relocs.appendAssumeCapacity(.{ |
| 4634 | .source_off = @intCast(header.items.len), | 4855 | .source_off = @intCast(hw.end), |
| 4635 | .target_unit = .main, | 4856 | .target_unit = .main, |
| 4636 | .target_off = compile_unit_off, | 4857 | .target_off = compile_unit_off, |
| 4637 | }); | 4858 | }); |
| 4638 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); | 4859 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4639 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ | 4860 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4640 | .source_off = @intCast(header.items.len), | 4861 | .source_off = @intCast(hw.end), |
| 4641 | .target_sec = .debug_line, | 4862 | .target_sec = .debug_line, |
| 4642 | .target_unit = unit, | 4863 | .target_unit = unit, |
| 4643 | }); | 4864 | }); |
| 4644 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); | 4865 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4645 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ | 4866 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4646 | .source_off = @intCast(header.items.len), | 4867 | .source_off = @intCast(hw.end), |
| 4647 | .target_sec = .debug_rnglists, | 4868 | .target_sec = .debug_rnglists, |
| 4648 | .target_unit = unit, | 4869 | .target_unit = unit, |
| 4649 | .target_off = DebugRngLists.baseOffset(dwarf), | 4870 | .target_off = DebugRngLists.baseOffset(dwarf), |
| 4650 | }); | 4871 | }); |
| 4651 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); | 4872 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4652 | uleb128(header.fixedWriter(), 0) catch unreachable; | 4873 | hw.writeUleb128(0) catch unreachable; |
| 4653 | uleb128(header.fixedWriter(), try dwarf.refAbbrevCode(.module)) catch unreachable; | 4874 | hw.writeUleb128(try dwarf.refAbbrevCode(.module)) catch unreachable; |
| 4654 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ | 4875 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 4655 | .source_off = @intCast(header.items.len), | 4876 | .source_off = @intCast(hw.end), |
| 4656 | .target_sec = .debug_str, | 4877 | .target_sec = .debug_str, |
| 4657 | .target_unit = StringSection.unit, | 4878 | .target_unit = StringSection.unit, |
| 4658 | .target_entry = (try dwarf.debug_str.addString(dwarf, mod.fully_qualified_name)).toOptional(), | 4879 | .target_entry = (try dwarf.debug_str.addString(dwarf, mod.fully_qualified_name)).toOptional(), |
| 4659 | }); | 4880 | }); |
| 4660 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); | 4881 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4661 | uleb128(header.fixedWriter(), 0) catch unreachable; | 4882 | hw.writeUleb128(0) catch unreachable; |
| 4662 | try unit_ptr.replaceHeader(&dwarf.debug_info.section, dwarf, header.items); | 4883 | try unit_ptr.replaceHeader(&dwarf.debug_info.section, dwarf, header_aw.getWritten()); |
| 4663 | try unit_ptr.writeTrailer(&dwarf.debug_info.section, dwarf); | 4884 | try unit_ptr.writeTrailer(&dwarf.debug_info.section, dwarf); |
| 4664 | } | 4885 | } |
| 4665 | dwarf.debug_info.section.dirty = false; | 4886 | dwarf.debug_info.section.dirty = false; |
| ... | @@ -4684,32 +4905,36 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -4684,32 +4905,36 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4684 | for (dwarf.mods.values(), dwarf.debug_line.section.units.items) |mod_info, *unit| { | 4905 | for (dwarf.mods.values(), dwarf.debug_line.section.units.items) |mod_info, *unit| { |
| 4685 | unit.clear(); | 4906 | unit.clear(); |
| 4686 | try unit.cross_section_relocs.ensureTotalCapacity(dwarf.gpa, mod_info.dirs.count() + 2 * (mod_info.files.count())); | 4907 | try unit.cross_section_relocs.ensureTotalCapacity(dwarf.gpa, mod_info.dirs.count() + 2 * (mod_info.files.count())); |
| 4687 | header.clearRetainingCapacity(); | 4908 | header_aw.clearRetainingCapacity(); |
| 4688 | try header.ensureTotalCapacity(unit.header_len); | 4909 | try header_aw.ensureTotalCapacity(unit.header_len); |
| 4689 | const unit_len = (if (unit.next.unwrap()) |next_unit| | 4910 | const unit_len = (if (unit.next.unwrap()) |next_unit| |
| 4690 | dwarf.debug_line.section.getUnit(next_unit).off | 4911 | dwarf.debug_line.section.getUnit(next_unit).off |
| 4691 | else | 4912 | else |
| 4692 | dwarf.debug_line.section.len) - unit.off - dwarf.unitLengthBytes(); | 4913 | dwarf.debug_line.section.len) - unit.off - dwarf.unitLengthBytes(); |
| 4693 | switch (dwarf.format) { | 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 | .@"64" => { | 4916 | .@"64" => { |
| 4696 | std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), std.math.maxInt(u32), dwarf.endian); | 4917 | hw.writeInt(u32, std.math.maxInt(u32), dwarf.endian) catch unreachable; |
| 4697 | std.mem.writeInt(u64, header.addManyAsArrayAssumeCapacity(8), unit_len, dwarf.endian); | 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); | 4921 | hw.writeInt(u16, 5, dwarf.endian) catch unreachable; |
| 4701 | header.appendSliceAssumeCapacity(&.{ @intFromEnum(dwarf.address_size), 0 }); | 4922 | hw.writeByte(@intFromEnum(dwarf.address_size)) catch unreachable; |
| 4702 | dwarf.writeInt(header.addManyAsSliceAssumeCapacity(dwarf.sectionOffsetBytes()), unit.header_len - header.items.len); | 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 | const StandardOpcode = DeclValEnum(DW.LNS); | 4928 | const StandardOpcode = DeclValEnum(DW.LNS); |
| 4704 | header.appendSliceAssumeCapacity(&[_]u8{ | 4929 | hw.writeAll(&.{ |
| 4705 | dwarf.debug_line.header.minimum_instruction_length, | 4930 | dwarf.debug_line.header.minimum_instruction_length, |
| 4706 | dwarf.debug_line.header.maximum_operations_per_instruction, | 4931 | dwarf.debug_line.header.maximum_operations_per_instruction, |
| 4707 | @intFromBool(dwarf.debug_line.header.default_is_stmt), | 4932 | @intFromBool(dwarf.debug_line.header.default_is_stmt), |
| 4708 | @bitCast(dwarf.debug_line.header.line_base), | 4933 | @bitCast(dwarf.debug_line.header.line_base), |
| 4709 | dwarf.debug_line.header.line_range, | 4934 | dwarf.debug_line.header.line_range, |
| 4710 | dwarf.debug_line.header.opcode_base, | 4935 | dwarf.debug_line.header.opcode_base, |
| 4711 | }); | 4936 | }) catch unreachable; |
| 4712 | header.appendSliceAssumeCapacity(std.enums.EnumArray(StandardOpcode, u8).init(.{ | 4937 | hw.writeAll(std.enums.EnumArray(StandardOpcode, u8).init(.{ |
| 4713 | .extended_op = undefined, | 4938 | .extended_op = undefined, |
| 4714 | .copy = 0, | 4939 | .copy = 0, |
| 4715 | .advance_pc = 1, | 4940 | .advance_pc = 1, |
| ... | @@ -4723,44 +4948,46 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -4723,44 +4948,46 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4723 | .set_prologue_end = 0, | 4948 | .set_prologue_end = 0, |
| 4724 | .set_epilogue_begin = 0, | 4949 | .set_epilogue_begin = 0, |
| 4725 | .set_isa = 1, | 4950 | .set_isa = 1, |
| 4726 | }).values[1..dwarf.debug_line.header.opcode_base]); | 4951 | }).values[1..dwarf.debug_line.header.opcode_base]) catch unreachable; |
| 4727 | header.appendAssumeCapacity(1); | 4952 | hw.writeByte(1) catch unreachable; |
| 4728 | uleb128(header.fixedWriter(), DW.LNCT.path) catch unreachable; | 4953 | hw.writeUleb128(DW.LNCT.path) catch unreachable; |
| 4729 | uleb128(header.fixedWriter(), DW.FORM.line_strp) catch unreachable; | 4954 | hw.writeUleb128(DW.FORM.line_strp) catch unreachable; |
| 4730 | uleb128(header.fixedWriter(), mod_info.dirs.count()) catch unreachable; | 4955 | hw.writeUleb128(mod_info.dirs.count()) catch unreachable; |
| 4731 | for (mod_info.dirs.keys()) |dir_unit| { | 4956 | for (mod_info.dirs.keys()) |dir_unit| { |
| 4732 | unit.cross_section_relocs.appendAssumeCapacity(.{ | 4957 | unit.cross_section_relocs.appendAssumeCapacity(.{ |
| 4733 | .source_off = @intCast(header.items.len), | 4958 | .source_off = @intCast(hw.end), |
| 4734 | .target_sec = .debug_line_str, | 4959 | .target_sec = .debug_line_str, |
| 4735 | .target_unit = StringSection.unit, | 4960 | .target_unit = StringSection.unit, |
| 4736 | .target_entry = dwarf.getModInfo(dir_unit).root_dir_path.toOptional(), | 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 | const dir_index_info = DebugLine.dirIndexInfo(@intCast(mod_info.dirs.count())); | 4965 | const dir_index_info = DebugLine.dirIndexInfo(@intCast(mod_info.dirs.count())); |
| 4741 | header.appendAssumeCapacity(3); | 4966 | hw.writeByte(3) catch unreachable; |
| 4742 | uleb128(header.fixedWriter(), DW.LNCT.path) catch unreachable; | 4967 | hw.writeUleb128(DW.LNCT.path) catch unreachable; |
| 4743 | uleb128(header.fixedWriter(), DW.FORM.line_strp) catch unreachable; | 4968 | hw.writeUleb128(DW.FORM.line_strp) catch unreachable; |
| 4744 | uleb128(header.fixedWriter(), DW.LNCT.directory_index) catch unreachable; | 4969 | hw.writeUleb128(DW.LNCT.directory_index) catch unreachable; |
| 4745 | uleb128(header.fixedWriter(), @intFromEnum(dir_index_info.form)) catch unreachable; | 4970 | hw.writeUleb128(@intFromEnum(dir_index_info.form)) catch unreachable; |
| 4746 | uleb128(header.fixedWriter(), DW.LNCT.LLVM_source) catch unreachable; | 4971 | hw.writeUleb128(DW.LNCT.LLVM_source) catch unreachable; |
| 4747 | uleb128(header.fixedWriter(), DW.FORM.line_strp) catch unreachable; | 4972 | hw.writeUleb128(DW.FORM.line_strp) catch unreachable; |
| 4748 | uleb128(header.fixedWriter(), mod_info.files.count()) catch unreachable; | 4973 | hw.writeUleb128(mod_info.files.count()) catch unreachable; |
| 4749 | for (mod_info.files.keys()) |file_index| { | 4974 | for (mod_info.files.keys()) |file_index| { |
| 4750 | const file = zcu.fileByIndex(file_index); | 4975 | const file = zcu.fileByIndex(file_index); |
| 4751 | unit.cross_section_relocs.appendAssumeCapacity(.{ | 4976 | unit.cross_section_relocs.appendAssumeCapacity(.{ |
| 4752 | .source_off = @intCast(header.items.len), | 4977 | .source_off = @intCast(hw.end), |
| 4753 | .target_sec = .debug_line_str, | 4978 | .target_sec = .debug_line_str, |
| 4754 | .target_unit = StringSection.unit, | 4979 | .target_unit = StringSection.unit, |
| 4755 | .target_entry = (try dwarf.debug_line_str.addString(dwarf, file.sub_file_path)).toOptional(), | 4980 | .target_entry = (try dwarf.debug_line_str.addString(dwarf, file.sub_file_path)).toOptional(), |
| 4756 | }); | 4981 | }); |
| 4757 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); | 4982 | hw.splatByteAll(0, dwarf.sectionOffsetBytes()) catch unreachable; |
| 4758 | dwarf.writeInt( | 4983 | const dir_index = mod_info.dirs.getIndex(dwarf.getUnitIfExists(file.mod.?).?) orelse 0; |
| 4759 | header.addManyAsSliceAssumeCapacity(dir_index_info.bytes), | 4984 | switch (dir_index_info.bytes) { |
| 4760 | mod_info.dirs.getIndex(dwarf.getUnitIfExists(file.mod.?).?) orelse 0, | 4985 | else => unreachable, |
| 4761 | ); | 4986 | 1 => hw.writeByte(@intCast(dir_index)) catch unreachable, |
| | 4987 | 2 => hw.writeInt(u16, @intCast(dir_index), dwarf.endian) catch unreachable, |
| | 4988 | } |
| 4762 | unit.cross_section_relocs.appendAssumeCapacity(.{ | 4989 | unit.cross_section_relocs.appendAssumeCapacity(.{ |
| 4763 | .source_off = @intCast(header.items.len), | 4990 | .source_off = @intCast(hw.end), |
| 4764 | .target_sec = .debug_line_str, | 4991 | .target_sec = .debug_line_str, |
| 4765 | .target_unit = StringSection.unit, | 4992 | .target_unit = StringSection.unit, |
| 4766 | .target_entry = (try dwarf.debug_line_str.addString( | 4993 | .target_entry = (try dwarf.debug_line_str.addString( |
| ... | @@ -4768,9 +4995,9 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -4768,9 +4995,9 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4768 | if (file.is_builtin) file.source.? else "", | 4995 | if (file.is_builtin) file.source.? else "", |
| 4769 | )).toOptional(), | 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 | try unit.writeTrailer(&dwarf.debug_line.section, dwarf); | 5001 | try unit.writeTrailer(&dwarf.debug_line.section, dwarf); |
| 4775 | } | 5002 | } |
| 4776 | dwarf.debug_line.section.dirty = false; | 5003 | dwarf.debug_line.section.dirty = false; |
| ... | @@ -4786,24 +5013,28 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -4786,24 +5013,28 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4786 | } | 5013 | } |
| 4787 | if (dwarf.debug_rnglists.section.dirty) { | 5014 | if (dwarf.debug_rnglists.section.dirty) { |
| 4788 | for (dwarf.debug_rnglists.section.units.items) |*unit| { | 5015 | for (dwarf.debug_rnglists.section.units.items) |*unit| { |
| 4789 | header.clearRetainingCapacity(); | 5016 | header_aw.clearRetainingCapacity(); |
| 4790 | try header.ensureTotalCapacity(unit.header_len); | 5017 | try header_aw.ensureTotalCapacity(unit.header_len); |
| 4791 | const unit_len = (if (unit.next.unwrap()) |next_unit| | 5018 | const unit_len = (if (unit.next.unwrap()) |next_unit| |
| 4792 | dwarf.debug_rnglists.section.getUnit(next_unit).off | 5019 | dwarf.debug_rnglists.section.getUnit(next_unit).off |
| 4793 | else | 5020 | else |
| 4794 | dwarf.debug_rnglists.section.len) - unit.off - dwarf.unitLengthBytes(); | 5021 | dwarf.debug_rnglists.section.len) - unit.off - dwarf.unitLengthBytes(); |
| 4795 | switch (dwarf.format) { | 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 | .@"64" => { | 5024 | .@"64" => { |
| 4798 | std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), std.math.maxInt(u32), dwarf.endian); | 5025 | hw.writeInt(u32, std.math.maxInt(u32), dwarf.endian) catch unreachable; |
| 4799 | std.mem.writeInt(u64, header.addManyAsArrayAssumeCapacity(8), unit_len, dwarf.endian); | 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); | 5029 | hw.writeInt(u16, 5, dwarf.endian) catch unreachable; |
| 4803 | header.appendSliceAssumeCapacity(&.{ @intFromEnum(dwarf.address_size), 0 }); | 5030 | hw.writeByte(@intFromEnum(dwarf.address_size)) catch unreachable; |
| 4804 | std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(4), 1, dwarf.endian); | 5031 | hw.writeByte(0) catch unreachable; |
| 4805 | dwarf.writeInt(header.addManyAsSliceAssumeCapacity(dwarf.sectionOffsetBytes()), dwarf.sectionOffsetBytes() * 1); | 5032 | hw.writeInt(u32, 1, dwarf.endian) catch unreachable; |
| 4806 | try unit.replaceHeader(&dwarf.debug_rnglists.section, dwarf, header.items); | 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 | try unit.writeTrailer(&dwarf.debug_rnglists.section, dwarf); | 5038 | try unit.writeTrailer(&dwarf.debug_rnglists.section, dwarf); |
| 4808 | } | 5039 | } |
| 4809 | dwarf.debug_rnglists.section.dirty = false; | 5040 | dwarf.debug_rnglists.section.dirty = false; |
| ... | @@ -5983,7 +6214,11 @@ fn addCommonEntry(dwarf: *Dwarf, unit: Unit.Index) UpdateError!Entry.Index { | ... | @@ -5983,7 +6214,11 @@ fn addCommonEntry(dwarf: *Dwarf, unit: Unit.Index) UpdateError!Entry.Index { |
| 5983 | return entry; | 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 | try dwarf.debug_aranges.section.freeEntry(unit, entry, dwarf); | 6222 | try dwarf.debug_aranges.section.freeEntry(unit, entry, dwarf); |
| 5988 | try dwarf.debug_frame.section.freeEntry(unit, entry, dwarf); | 6223 | try dwarf.debug_frame.section.freeEntry(unit, entry, dwarf); |
| 5989 | try dwarf.debug_info.section.freeEntry(unit, entry, dwarf); | 6224 | try dwarf.debug_info.section.freeEntry(unit, entry, dwarf); |
| ... | @@ -6023,17 +6258,17 @@ fn sectionOffsetBytes(dwarf: *Dwarf) u32 { | ... | @@ -6023,17 +6258,17 @@ fn sectionOffsetBytes(dwarf: *Dwarf) u32 { |
| 6023 | } | 6258 | } |
| 6024 | | 6259 | |
| 6025 | fn uleb128Bytes(value: anytype) u32 { | 6260 | fn uleb128Bytes(value: anytype) u32 { |
| 6026 | var trash_buffer: [64]u8 = undefined; | 6261 | var buf: [64]u8 = undefined; |
| 6027 | var d: Writer.Discarding = .init(&trash_buffer); | 6262 | var dw: Writer.Discarding = .init(&buf); |
| 6028 | d.writer.writeUleb128(value) catch unreachable; | 6263 | dw.writer.writeUleb128(value) catch unreachable; |
| 6029 | return @intCast(d.count + d.writer.end); | 6264 | return @intCast(dw.count + dw.writer.end); |
| 6030 | } | 6265 | } |
| 6031 | | 6266 | |
| 6032 | fn sleb128Bytes(value: anytype) u32 { | 6267 | fn sleb128Bytes(value: anytype) u32 { |
| 6033 | var trash_buffer: [64]u8 = undefined; | 6268 | var buf: [64]u8 = undefined; |
| 6034 | var d: Writer.Discarding = .init(&trash_buffer); | 6269 | var dw: Writer.Discarding = .init(&buf); |
| 6035 | d.writer.writeSleb128(value) catch unreachable; | 6270 | dw.writer.writeSleb128(value) catch unreachable; |
| 6036 | return @intCast(d.count + d.writer.end); | 6271 | return @intCast(dw.count + dw.writer.end); |
| 6037 | } | 6272 | } |
| 6038 | | 6273 | |
| 6039 | /// overrides `-fno-incremental` for testing incremental debug info until `-fincremental` is functional | 6274 | /// overrides `-fno-incremental` for testing incremental debug info until `-fincremental` is functional |
| ... | @@ -6042,6 +6277,7 @@ inline fn incremental(dwarf: Dwarf) bool { | ... | @@ -6042,6 +6277,7 @@ inline fn incremental(dwarf: Dwarf) bool { |
| 6042 | return force_incremental or dwarf.bin_file.comp.incremental; | 6277 | return force_incremental or dwarf.bin_file.comp.incremental; |
| 6043 | } | 6278 | } |
| 6044 | | 6279 | |
| | 6280 | const Allocator = std.mem.Allocator; |
| 6045 | const DW = std.dwarf; | 6281 | const DW = std.dwarf; |
| 6046 | const Dwarf = @This(); | 6282 | const Dwarf = @This(); |
| 6047 | const InternPool = @import("../InternPool.zig"); | 6283 | const InternPool = @import("../InternPool.zig"); |
| ... | @@ -6055,9 +6291,6 @@ const codegen = @import("../codegen.zig"); | ... | @@ -6055,9 +6291,6 @@ const codegen = @import("../codegen.zig"); |
| 6055 | const dev = @import("../dev.zig"); | 6291 | const dev = @import("../dev.zig"); |
| 6056 | const link = @import("../link.zig"); | 6292 | const link = @import("../link.zig"); |
| 6057 | const log = std.log.scoped(.dwarf); | 6293 | const log = std.log.scoped(.dwarf); |
| 6058 | const sleb128 = std.leb.writeIleb128; | | |
| 6059 | const std = @import("std"); | 6294 | const std = @import("std"); |
| 6060 | const target_info = @import("../target.zig"); | 6295 | const target_info = @import("../target.zig"); |
| 6061 | const uleb128 = std.leb.writeUleb128; | | |
| 6062 | const Allocator = std.mem.Allocator; | | |
| 6063 | const Writer = std.Io.Writer; | 6296 | const Writer = std.Io.Writer; |