| ... | ... | @@ -55,7 +55,10 @@ const ModInfo = struct { |
| 55 | 55 | const DebugAbbrev = struct { |
| 56 | 56 | section: Section, |
| 57 | 57 | const unit: Unit.Index = @enumFromInt(0); |
| 58 | | const entry: Entry.Index = @enumFromInt(0); |
| 58 | |
| 59 | const header_bytes = 0; |
| 60 | |
| 61 | const trailer_bytes = uleb128Bytes(@intFromEnum(AbbrevCode.null)); |
| 59 | 62 | }; |
| 60 | 63 | |
| 61 | 64 | const DebugAranges = struct { |
| ... | ... | @@ -119,8 +122,7 @@ const DebugLine = struct { |
| 119 | 122 | 1 + uleb128Bytes(DW.LNCT.path) + uleb128Bytes(DW.FORM.line_strp) + uleb128Bytes(DW.LNCT.directory_index) + uleb128Bytes(@intFromEnum(dir_index_info.form)) + uleb128Bytes(DW.LNCT.LLVM_source) + uleb128Bytes(DW.FORM.line_strp) + uleb128Bytes(file_count) + (dwarf.sectionOffsetBytes() + dir_index_info.bytes + dwarf.sectionOffsetBytes()) * file_count; |
| 120 | 123 | } |
| 121 | 124 | |
| 122 | | const trailer_bytes = 1 + uleb128Bytes(0) + |
| 123 | | 1 + uleb128Bytes(1) + 1; |
| 125 | const trailer_bytes = 1 + uleb128Bytes(1) + 1; |
| 124 | 126 | }; |
| 125 | 127 | |
| 126 | 128 | const DebugLocLists = struct { |
| ... | ... | @@ -173,10 +175,15 @@ const StringSection = struct { |
| 173 | 175 | errdefer _ = str_sec.map.pop(); |
| 174 | 176 | const entry: Entry.Index = @enumFromInt(gop.index); |
| 175 | 177 | if (!gop.found_existing) { |
| 176 | | assert(try str_sec.section.addEntry(unit, dwarf) == entry); |
| 177 | | errdefer _ = str_sec.section.getUnit(unit).entries.pop(); |
| 178 | | const entry_ptr = str_sec.section.getUnit(unit).getEntry(entry); |
| 179 | | assert(entry_ptr.off == str_sec.contents.items.len); |
| 178 | const unit_ptr = str_sec.section.getUnit(unit); |
| 179 | assert(try str_sec.section.getUnit(unit).addEntry(dwarf.gpa) == entry); |
| 180 | errdefer _ = unit_ptr.entries.pop(); |
| 181 | const entry_ptr = unit_ptr.getEntry(entry); |
| 182 | if (unit_ptr.last.unwrap()) |last_entry| |
| 183 | unit_ptr.getEntry(last_entry).next = entry.toOptional(); |
| 184 | entry_ptr.prev = unit_ptr.last; |
| 185 | unit_ptr.last = entry.toOptional(); |
| 186 | entry_ptr.off = @intCast(str_sec.contents.items.len); |
| 180 | 187 | entry_ptr.len = @intCast(str.len + 1); |
| 181 | 188 | try str_sec.contents.ensureUnusedCapacity(dwarf.gpa, str.len + 1); |
| 182 | 189 | str_sec.contents.appendSliceAssumeCapacity(str); |
| ... | ... | @@ -243,7 +250,7 @@ pub const Section = struct { |
| 243 | 250 | fn addUnit(sec: *Section, header_len: u32, trailer_len: u32, dwarf: *Dwarf) UpdateError!Unit.Index { |
| 244 | 251 | const unit: Unit.Index = @enumFromInt(sec.units.items.len); |
| 245 | 252 | const unit_ptr = try sec.units.addOne(dwarf.gpa); |
| 246 | | errdefer sec.popUnit(); |
| 253 | errdefer sec.popUnit(dwarf.gpa); |
| 247 | 254 | unit_ptr.* = .{ |
| 248 | 255 | .prev = sec.last, |
| 249 | 256 | .next = .none, |
| ... | ... | @@ -277,14 +284,11 @@ pub const Section = struct { |
| 277 | 284 | if (sec.last.unwrap().? == unit) sec.last = unit_ptr.prev; |
| 278 | 285 | } |
| 279 | 286 | |
| 280 | | fn popUnit(sec: *Section) void { |
| 281 | | const unit: Unit.Index = @enumFromInt(sec.units.items.len - 1); |
| 282 | | sec.unlinkUnit(unit); |
| 283 | | _ = sec.units.pop(); |
| 284 | | } |
| 285 | | |
| 286 | | fn addEntry(sec: *Section, unit: Unit.Index, dwarf: *Dwarf) UpdateError!Entry.Index { |
| 287 | | return sec.getUnit(unit).addEntry(sec, dwarf); |
| 287 | fn popUnit(sec: *Section, gpa: std.mem.Allocator) void { |
| 288 | const unit_index: Unit.Index = @enumFromInt(sec.units.items.len - 1); |
| 289 | sec.unlinkUnit(unit_index); |
| 290 | var unit = sec.units.pop(); |
| 291 | unit.deinit(gpa); |
| 288 | 292 | } |
| 289 | 293 | |
| 290 | 294 | pub fn getUnit(sec: *Section, unit: Unit.Index) *Unit { |
| ... | ... | @@ -293,7 +297,21 @@ pub const Section = struct { |
| 293 | 297 | |
| 294 | 298 | fn replaceEntry(sec: *Section, unit: Unit.Index, entry: Entry.Index, dwarf: *Dwarf, contents: []const u8) UpdateError!void { |
| 295 | 299 | const unit_ptr = sec.getUnit(unit); |
| 296 | | try unit_ptr.getEntry(entry).replace(unit_ptr, sec, dwarf, contents); |
| 300 | const entry_ptr = unit_ptr.getEntry(entry); |
| 301 | if (contents.len > 0) { |
| 302 | if (entry_ptr.len == 0) { |
| 303 | assert(entry_ptr.prev == .none and entry_ptr.next == .none); |
| 304 | entry_ptr.off = if (unit_ptr.last.unwrap()) |last_entry| off: { |
| 305 | const last_entry_ptr = unit_ptr.getEntry(last_entry); |
| 306 | last_entry_ptr.next = entry.toOptional(); |
| 307 | break :off last_entry_ptr.off + sec.padToIdeal(last_entry_ptr.len); |
| 308 | } else 0; |
| 309 | entry_ptr.prev = unit_ptr.last; |
| 310 | unit_ptr.last = entry.toOptional(); |
| 311 | } |
| 312 | try entry_ptr.replace(unit_ptr, sec, dwarf, contents); |
| 313 | } |
| 314 | assert(entry_ptr.len == contents.len); |
| 297 | 315 | } |
| 298 | 316 | |
| 299 | 317 | fn resize(sec: *Section, dwarf: *Dwarf, len: u64) UpdateError!void { |
| ... | ... | @@ -391,11 +409,11 @@ const Unit = struct { |
| 391 | 409 | unit.* = undefined; |
| 392 | 410 | } |
| 393 | 411 | |
| 394 | | fn addEntry(unit: *Unit, sec: *Section, dwarf: *Dwarf) UpdateError!Entry.Index { |
| 412 | fn addEntry(unit: *Unit, gpa: std.mem.Allocator) std.mem.Allocator.Error!Entry.Index { |
| 395 | 413 | const entry: Entry.Index = @enumFromInt(unit.entries.items.len); |
| 396 | | const entry_ptr = try unit.entries.addOne(dwarf.gpa); |
| 414 | const entry_ptr = try unit.entries.addOne(gpa); |
| 397 | 415 | entry_ptr.* = .{ |
| 398 | | .prev = unit.last, |
| 416 | .prev = .none, |
| 399 | 417 | .next = .none, |
| 400 | 418 | .off = 0, |
| 401 | 419 | .len = 0, |
| ... | ... | @@ -404,14 +422,6 @@ const Unit = struct { |
| 404 | 422 | .cross_section_relocs = .{}, |
| 405 | 423 | .external_relocs = .{}, |
| 406 | 424 | }; |
| 407 | | if (unit.last.unwrap()) |last_entry| { |
| 408 | | const last_entry_ptr = unit.getEntry(last_entry); |
| 409 | | last_entry_ptr.next = entry.toOptional(); |
| 410 | | entry_ptr.off = last_entry_ptr.off + sec.padToIdeal(last_entry_ptr.len); |
| 411 | | } |
| 412 | | if (unit.first == .none) |
| 413 | | unit.first = entry.toOptional(); |
| 414 | | unit.last = entry.toOptional(); |
| 415 | 425 | return entry; |
| 416 | 426 | } |
| 417 | 427 | |
| ... | ... | @@ -509,42 +519,52 @@ const Unit = struct { |
| 509 | 519 | const last_entry_ptr = unit.getEntry(last_entry); |
| 510 | 520 | break :end last_entry_ptr.off + last_entry_ptr.len; |
| 511 | 521 | } else 0; |
| 512 | | const end = if (unit.next.unwrap()) |next_unit| |
| 513 | | sec.getUnit(next_unit).off |
| 514 | | else |
| 515 | | sec.len; |
| 516 | | const trailer_len: usize = @intCast(end - start); |
| 517 | | assert(trailer_len >= unit.trailer_len); |
| 518 | | var trailer = try std.ArrayList(u8).initCapacity(dwarf.gpa, trailer_len); |
| 522 | const end = if (unit.next.unwrap()) |next_unit| sec.getUnit(next_unit).off else sec.len; |
| 523 | const len: usize = @intCast(end - start); |
| 524 | assert(len >= unit.trailer_len); |
| 525 | if (sec == &dwarf.debug_line.section) { |
| 526 | var buf: [1 + uleb128Bytes(std.math.maxInt(u32)) + 1]u8 = undefined; |
| 527 | var fbs = std.io.fixedBufferStream(&buf); |
| 528 | const writer = fbs.writer(); |
| 529 | writer.writeByte(DW.LNS.extended_op) catch unreachable; |
| 530 | const extended_op_bytes = fbs.pos; |
| 531 | var op_len_bytes: u5 = 1; |
| 532 | while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << 7 * op_len_bytes)) { |
| 533 | .lt => break uleb128(writer, len - extended_op_bytes - op_len_bytes) catch unreachable, |
| 534 | .eq => { |
| 535 | // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte |
| 536 | op_len_bytes += 1; |
| 537 | std.leb.writeUnsignedExtended(buf[fbs.pos..][0..op_len_bytes], len - extended_op_bytes - op_len_bytes); |
| 538 | fbs.pos += op_len_bytes; |
| 539 | break; |
| 540 | }, |
| 541 | .gt => op_len_bytes += 1, |
| 542 | }; |
| 543 | assert(fbs.pos == extended_op_bytes + op_len_bytes); |
| 544 | writer.writeByte(DW.LNE.padding) catch unreachable; |
| 545 | assert(fbs.pos >= unit.trailer_len and fbs.pos <= len); |
| 546 | return dwarf.getFile().?.pwriteAll(fbs.getWritten(), sec.off + start); |
| 547 | } |
| 548 | var trailer = try std.ArrayList(u8).initCapacity(dwarf.gpa, len); |
| 519 | 549 | defer trailer.deinit(); |
| 520 | | const fill_byte: u8 = if (sec == &dwarf.debug_aranges.section) fill: { |
| 550 | const fill_byte: u8 = if (sec == &dwarf.debug_abbrev.section) fill: { |
| 551 | assert(uleb128Bytes(@intFromEnum(AbbrevCode.null)) == 1); |
| 552 | trailer.appendAssumeCapacity(@intFromEnum(AbbrevCode.null)); |
| 553 | break :fill @intFromEnum(AbbrevCode.null); |
| 554 | } else if (sec == &dwarf.debug_aranges.section) fill: { |
| 521 | 555 | trailer.appendNTimesAssumeCapacity(0, @intFromEnum(dwarf.address_size) * 2); |
| 522 | 556 | break :fill 0; |
| 523 | 557 | } else if (sec == &dwarf.debug_info.section) fill: { |
| 524 | 558 | assert(uleb128Bytes(@intFromEnum(AbbrevCode.null)) == 1); |
| 525 | 559 | trailer.appendNTimesAssumeCapacity(@intFromEnum(AbbrevCode.null), 2); |
| 526 | 560 | break :fill @intFromEnum(AbbrevCode.null); |
| 527 | | } else if (sec == &dwarf.debug_line.section) fill: { |
| 528 | | unit.len -= unit.trailer_len; |
| 529 | | const extra_len: u32 = @intCast((trailer_len - DebugLine.trailer_bytes) & 1); |
| 530 | | unit.trailer_len = DebugLine.trailer_bytes + extra_len; |
| 531 | | unit.len += unit.trailer_len; |
| 532 | | |
| 533 | | // prevent end sequence from emitting an invalid file index |
| 534 | | trailer.appendAssumeCapacity(DW.LNS.set_file); |
| 535 | | uleb128(trailer.fixedWriter(), 0) catch unreachable; |
| 536 | | |
| 537 | | trailer.appendAssumeCapacity(DW.LNS.extended_op); |
| 538 | | std.leb.writeUnsignedExtended(trailer.addManyAsSliceAssumeCapacity(uleb128Bytes(1) + extra_len), 1); |
| 539 | | trailer.appendAssumeCapacity(DW.LNE.end_sequence); |
| 540 | | break :fill DW.LNS.extended_op; |
| 541 | 561 | } else if (sec == &dwarf.debug_rnglists.section) fill: { |
| 542 | 562 | trailer.appendAssumeCapacity(DW.RLE.end_of_list); |
| 543 | 563 | break :fill DW.RLE.end_of_list; |
| 544 | 564 | } else unreachable; |
| 545 | 565 | assert(trailer.items.len == unit.trailer_len); |
| 546 | | trailer.appendNTimesAssumeCapacity(fill_byte, trailer_len - trailer.items.len); |
| 547 | | assert(trailer.items.len == trailer_len); |
| 566 | trailer.appendNTimesAssumeCapacity(fill_byte, len - trailer.items.len); |
| 567 | assert(trailer.items.len == len); |
| 548 | 568 | try dwarf.getFile().?.pwriteAll(trailer.items, sec.off + start); |
| 549 | 569 | } |
| 550 | 570 | |
| ... | ... | @@ -625,45 +645,62 @@ const Entry = struct { |
| 625 | 645 | }; |
| 626 | 646 | |
| 627 | 647 | fn pad(entry: *Entry, unit: *Unit, sec: *Section, dwarf: *Dwarf) UpdateError!void { |
| 648 | assert(entry.len > 0); |
| 628 | 649 | const start = entry.off + entry.len; |
| 629 | 650 | const len = unit.getEntry(entry.next.unwrap() orelse return).off - start; |
| 630 | | if (sec == &dwarf.debug_info.section) { |
| 631 | | var buf: [ |
| 632 | | @max( |
| 633 | | uleb128Bytes(@intFromEnum(AbbrevCode.pad_1)), |
| 634 | | uleb128Bytes(@intFromEnum(AbbrevCode.pad_n)) + uleb128Bytes(std.math.maxInt(u32)), |
| 635 | | ) |
| 636 | | ]u8 = undefined; |
| 637 | | var fbs = std.io.fixedBufferStream(&buf); |
| 638 | | switch (len) { |
| 639 | | 0 => {}, |
| 640 | | 1 => uleb128(fbs.writer(), @intFromEnum(AbbrevCode.pad_1)) catch unreachable, |
| 641 | | else => { |
| 642 | | uleb128(fbs.writer(), @intFromEnum(AbbrevCode.pad_n)) catch unreachable; |
| 643 | | const abbrev_code_bytes = fbs.pos; |
| 644 | | var block_len_bytes: u5 = 1; |
| 645 | | while (true) switch (std.math.order(len - abbrev_code_bytes - block_len_bytes, @as(u32, 1) << 7 * block_len_bytes)) { |
| 646 | | .lt => break uleb128(fbs.writer(), len - abbrev_code_bytes - block_len_bytes) catch unreachable, |
| 647 | | .eq => { |
| 648 | | // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte |
| 649 | | block_len_bytes += 1; |
| 650 | | std.leb.writeUnsignedExtended(buf[fbs.pos..][0..block_len_bytes], len - abbrev_code_bytes - block_len_bytes); |
| 651 | | fbs.pos += block_len_bytes; |
| 652 | | break; |
| 653 | | }, |
| 654 | | .gt => block_len_bytes += 1, |
| 655 | | }; |
| 656 | | assert(fbs.pos == abbrev_code_bytes + block_len_bytes); |
| 657 | | }, |
| 658 | | } |
| 659 | | assert(fbs.pos <= len); |
| 660 | | try dwarf.getFile().?.pwriteAll(fbs.getWritten(), sec.off + unit.off + unit.header_len + start); |
| 661 | | } else if (sec == &dwarf.debug_line.section) { |
| 662 | | const buf = try dwarf.gpa.alloc(u8, len); |
| 663 | | defer dwarf.gpa.free(buf); |
| 664 | | @memset(buf, DW.LNS.const_add_pc); |
| 665 | | try dwarf.getFile().?.pwriteAll(buf, sec.off + unit.off + unit.header_len + start); |
| 651 | var buf: [ |
| 652 | @max( |
| 653 | uleb128Bytes(@intFromEnum(AbbrevCode.pad_1)), |
| 654 | uleb128Bytes(@intFromEnum(AbbrevCode.pad_n)) + uleb128Bytes(std.math.maxInt(u32)), |
| 655 | 1 + uleb128Bytes(std.math.maxInt(u32)) + 1, |
| 656 | ) |
| 657 | ]u8 = undefined; |
| 658 | var fbs = std.io.fixedBufferStream(&buf); |
| 659 | const writer = fbs.writer(); |
| 660 | if (sec == &dwarf.debug_info.section) switch (len) { |
| 661 | 0 => {}, |
| 662 | 1 => uleb128(writer, try dwarf.refAbbrevCode(.pad_1)) catch unreachable, |
| 663 | else => { |
| 664 | uleb128(writer, try dwarf.refAbbrevCode(.pad_n)) catch unreachable; |
| 665 | const abbrev_code_bytes = fbs.pos; |
| 666 | var block_len_bytes: u5 = 1; |
| 667 | while (true) switch (std.math.order(len - abbrev_code_bytes - block_len_bytes, @as(u32, 1) << 7 * block_len_bytes)) { |
| 668 | .lt => break uleb128(writer, len - abbrev_code_bytes - block_len_bytes) catch unreachable, |
| 669 | .eq => { |
| 670 | // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte |
| 671 | block_len_bytes += 1; |
| 672 | std.leb.writeUnsignedExtended(buf[fbs.pos..][0..block_len_bytes], len - abbrev_code_bytes - block_len_bytes); |
| 673 | fbs.pos += block_len_bytes; |
| 674 | break; |
| 675 | }, |
| 676 | .gt => block_len_bytes += 1, |
| 677 | }; |
| 678 | assert(fbs.pos == abbrev_code_bytes + block_len_bytes); |
| 679 | }, |
| 680 | } else if (sec == &dwarf.debug_line.section) switch (len) { |
| 681 | 0 => {}, |
| 682 | 1 => writer.writeByte(DW.LNS.const_add_pc) catch unreachable, |
| 683 | else => { |
| 684 | writer.writeByte(DW.LNS.extended_op) catch unreachable; |
| 685 | const extended_op_bytes = fbs.pos; |
| 686 | var op_len_bytes: u5 = 1; |
| 687 | while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << 7 * op_len_bytes)) { |
| 688 | .lt => break uleb128(writer, len - extended_op_bytes - op_len_bytes) catch unreachable, |
| 689 | .eq => { |
| 690 | // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte |
| 691 | op_len_bytes += 1; |
| 692 | std.leb.writeUnsignedExtended(buf[fbs.pos..][0..op_len_bytes], len - extended_op_bytes - op_len_bytes); |
| 693 | fbs.pos += op_len_bytes; |
| 694 | break; |
| 695 | }, |
| 696 | .gt => op_len_bytes += 1, |
| 697 | }; |
| 698 | assert(fbs.pos == extended_op_bytes + op_len_bytes); |
| 699 | if (len > 2) writer.writeByte(DW.LNE.padding) catch unreachable; |
| 700 | }, |
| 666 | 701 | } else assert(!sec.pad_to_ideal and len == 0); |
| 702 | assert(fbs.pos <= len); |
| 703 | try dwarf.getFile().?.pwriteAll(fbs.getWritten(), sec.off + unit.off + unit.header_len + start); |
| 667 | 704 | } |
| 668 | 705 | |
| 669 | 706 | fn replace(entry_ptr: *Entry, unit: *Unit, sec: *Section, dwarf: *Dwarf, contents: []const u8) UpdateError!void { |
| ... | ... | @@ -691,15 +728,7 @@ const Entry = struct { |
| 691 | 728 | try unit.resize(sec, dwarf, 0, @intCast(unit.header_len + entry_ptr.off + sec.padToIdeal(contents.len) + unit.trailer_len)); |
| 692 | 729 | } |
| 693 | 730 | entry_ptr.len = @intCast(contents.len); |
| 694 | | { |
| 695 | | var prev_entry_ptr = entry_ptr; |
| 696 | | while (prev_entry_ptr.prev.unwrap()) |prev_entry| { |
| 697 | | prev_entry_ptr = unit.getEntry(prev_entry); |
| 698 | | if (prev_entry_ptr.len == 0) continue; |
| 699 | | try prev_entry_ptr.pad(unit, sec, dwarf); |
| 700 | | break; |
| 701 | | } |
| 702 | | } |
| 731 | if (entry_ptr.prev.unwrap()) |prev_entry| try unit.getEntry(prev_entry).pad(unit, sec, dwarf); |
| 703 | 732 | try dwarf.getFile().?.pwriteAll(contents, sec.off + unit.off + unit.header_len + entry_ptr.off); |
| 704 | 733 | try entry_ptr.pad(unit, sec, dwarf); |
| 705 | 734 | if (false) { |
| ... | ... | @@ -1039,7 +1068,10 @@ pub const WipNav = struct { |
| 1039 | 1068 | func: InternPool.Index, |
| 1040 | 1069 | func_sym_index: u32, |
| 1041 | 1070 | func_high_reloc: u32, |
| 1042 | | inlined_funcs_high_reloc: std.ArrayListUnmanaged(u32), |
| 1071 | inlined_funcs: std.ArrayListUnmanaged(struct { |
| 1072 | abbrev_code: u32, |
| 1073 | high_reloc: u32, |
| 1074 | }), |
| 1043 | 1075 | debug_info: std.ArrayListUnmanaged(u8), |
| 1044 | 1076 | debug_line: std.ArrayListUnmanaged(u8), |
| 1045 | 1077 | debug_loclists: std.ArrayListUnmanaged(u8), |
| ... | ... | @@ -1047,7 +1079,7 @@ pub const WipNav = struct { |
| 1047 | 1079 | |
| 1048 | 1080 | pub fn deinit(wip_nav: *WipNav) void { |
| 1049 | 1081 | const gpa = wip_nav.dwarf.gpa; |
| 1050 | | if (wip_nav.func != .none) wip_nav.inlined_funcs_high_reloc.deinit(gpa); |
| 1082 | if (wip_nav.func != .none) wip_nav.inlined_funcs.deinit(gpa); |
| 1051 | 1083 | wip_nav.debug_info.deinit(gpa); |
| 1052 | 1084 | wip_nav.debug_line.deinit(gpa); |
| 1053 | 1085 | wip_nav.debug_loclists.deinit(gpa); |
| ... | ... | @@ -1066,15 +1098,14 @@ pub const WipNav = struct { |
| 1066 | 1098 | ty: Type, |
| 1067 | 1099 | loc: Loc, |
| 1068 | 1100 | ) UpdateError!void { |
| 1069 | | wip_nav.any_children = true; |
| 1070 | 1101 | assert(wip_nav.func != .none); |
| 1071 | | const diw = wip_nav.debug_info.writer(wip_nav.dwarf.gpa); |
| 1072 | | try uleb128(diw, @intFromEnum(switch (tag) { |
| 1102 | try wip_nav.abbrevCode(switch (tag) { |
| 1073 | 1103 | inline else => |ct_tag| @field(AbbrevCode, @tagName(ct_tag)), |
| 1074 | | })); |
| 1104 | }); |
| 1075 | 1105 | try wip_nav.strp(name); |
| 1076 | 1106 | try wip_nav.refType(ty); |
| 1077 | 1107 | try wip_nav.exprloc(loc); |
| 1108 | wip_nav.any_children = true; |
| 1078 | 1109 | } |
| 1079 | 1110 | |
| 1080 | 1111 | pub fn advancePCAndLine( |
| ... | ... | @@ -1136,9 +1167,10 @@ pub const WipNav = struct { |
| 1136 | 1167 | const dwarf = wip_nav.dwarf; |
| 1137 | 1168 | const zcu = wip_nav.pt.zcu; |
| 1138 | 1169 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 1139 | | try wip_nav.inlined_funcs_high_reloc.ensureUnusedCapacity(dwarf.gpa, 1); |
| 1170 | const inlined_func = try wip_nav.inlined_funcs.addOne(dwarf.gpa); |
| 1140 | 1171 | |
| 1141 | | try uleb128(diw, @intFromEnum(AbbrevCode.inlined_func)); |
| 1172 | inlined_func.abbrev_code = @intCast(wip_nav.debug_info.items.len); |
| 1173 | try wip_nav.abbrevCode(.inlined_func); |
| 1142 | 1174 | try wip_nav.refNav(zcu.funcInfo(func).owner_nav); |
| 1143 | 1175 | try uleb128(diw, zcu.navSrcLine(zcu.funcInfo(wip_nav.func).owner_nav) + line + 1); |
| 1144 | 1176 | try uleb128(diw, column + 1); |
| ... | ... | @@ -1150,7 +1182,7 @@ pub const WipNav = struct { |
| 1150 | 1182 | .target_off = code_off, |
| 1151 | 1183 | }); |
| 1152 | 1184 | try diw.writeByteNTimes(0, @intFromEnum(dwarf.address_size)); |
| 1153 | | wip_nav.inlined_funcs_high_reloc.appendAssumeCapacity(@intCast(external_relocs.items.len)); |
| 1185 | inlined_func.high_reloc = @intCast(external_relocs.items.len); |
| 1154 | 1186 | external_relocs.appendAssumeCapacity(.{ |
| 1155 | 1187 | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 1156 | 1188 | .target_sym = wip_nav.func_sym_index, |
| ... | ... | @@ -1158,17 +1190,27 @@ pub const WipNav = struct { |
| 1158 | 1190 | }); |
| 1159 | 1191 | try diw.writeByteNTimes(0, @intFromEnum(dwarf.address_size)); |
| 1160 | 1192 | try wip_nav.setInlineFunc(func); |
| 1193 | wip_nav.any_children = false; |
| 1161 | 1194 | } |
| 1162 | 1195 | |
| 1163 | 1196 | pub fn leaveInlineFunc(wip_nav: *WipNav, func: InternPool.Index, code_off: u64) UpdateError!void { |
| 1197 | const inlined_func_bytes = comptime uleb128Bytes(@intFromEnum(AbbrevCode.inlined_func)); |
| 1198 | const inlined_func = wip_nav.inlined_funcs.pop(); |
| 1164 | 1199 | const external_relocs = &wip_nav.dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs; |
| 1165 | | external_relocs.items[wip_nav.inlined_funcs_high_reloc.pop()].target_off = code_off; |
| 1166 | | try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), @intFromEnum(AbbrevCode.null)); |
| 1200 | external_relocs.items[inlined_func.high_reloc].target_off = code_off; |
| 1201 | if (wip_nav.any_children) |
| 1202 | try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), @intFromEnum(AbbrevCode.null)) |
| 1203 | else |
| 1204 | std.leb.writeUnsignedFixed( |
| 1205 | inlined_func_bytes, |
| 1206 | wip_nav.debug_info.items[inlined_func.abbrev_code..][0..inlined_func_bytes], |
| 1207 | try wip_nav.dwarf.refAbbrevCode(.empty_inlined_func), |
| 1208 | ); |
| 1167 | 1209 | try wip_nav.setInlineFunc(func); |
| 1210 | wip_nav.any_children = true; |
| 1168 | 1211 | } |
| 1169 | 1212 | |
| 1170 | 1213 | pub fn setInlineFunc(wip_nav: *WipNav, func: InternPool.Index) UpdateError!void { |
| 1171 | | wip_nav.any_children = true; |
| 1172 | 1214 | const zcu = wip_nav.pt.zcu; |
| 1173 | 1215 | const dwarf = wip_nav.dwarf; |
| 1174 | 1216 | if (wip_nav.func == func) return; |
| ... | ... | @@ -1219,6 +1261,10 @@ pub const WipNav = struct { |
| 1219 | 1261 | wip_nav.func = func; |
| 1220 | 1262 | } |
| 1221 | 1263 | |
| 1264 | fn abbrevCode(wip_nav: *WipNav, abbrev_code: AbbrevCode) UpdateError!void { |
| 1265 | try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), try wip_nav.dwarf.refAbbrevCode(abbrev_code)); |
| 1266 | } |
| 1267 | |
| 1222 | 1268 | fn infoSectionOffset(wip_nav: *WipNav, sec: Section.Index, unit: Unit.Index, entry: Entry.Index, off: u32) UpdateError!void { |
| 1223 | 1269 | const dwarf = wip_nav.dwarf; |
| 1224 | 1270 | const gpa = dwarf.gpa; |
| ... | ... | @@ -1336,7 +1382,7 @@ pub const WipNav = struct { |
| 1336 | 1382 | loaded_enum: InternPool.LoadedEnumType, |
| 1337 | 1383 | abbrev_code: std.enums.EnumFieldStruct(std.builtin.Signedness, AbbrevCode, null), |
| 1338 | 1384 | field_index: usize, |
| 1339 | | ) std.mem.Allocator.Error!void { |
| 1385 | ) UpdateError!void { |
| 1340 | 1386 | const zcu = wip_nav.pt.zcu; |
| 1341 | 1387 | const ip = &zcu.intern_pool; |
| 1342 | 1388 | const diw = wip_nav.debug_info.writer(wip_nav.dwarf.gpa); |
| ... | ... | @@ -1344,9 +1390,9 @@ pub const WipNav = struct { |
| 1344 | 1390 | .comptime_int_type => .signed, |
| 1345 | 1391 | else => Type.fromInterned(loaded_enum.tag_ty).intInfo(zcu).signedness, |
| 1346 | 1392 | }; |
| 1347 | | try uleb128(diw, @intFromEnum(switch (signedness) { |
| 1393 | try wip_nav.abbrevCode(switch (signedness) { |
| 1348 | 1394 | inline .signed, .unsigned => |ct_signedness| @field(abbrev_code, @tagName(ct_signedness)), |
| 1349 | | })); |
| 1395 | }); |
| 1350 | 1396 | if (loaded_enum.values.len > 0) switch (ip.indexToKey(loaded_enum.values.get(ip)[field_index]).int.storage) { |
| 1351 | 1397 | .u64 => |value| switch (signedness) { |
| 1352 | 1398 | .signed => try sleb128(diw, value), |
| ... | ... | @@ -1535,20 +1581,21 @@ pub fn initMetadata(dwarf: *Dwarf) UpdateError!void { |
| 1535 | 1581 | dwarf.reloadSectionMetadata(); |
| 1536 | 1582 | |
| 1537 | 1583 | dwarf.debug_abbrev.section.pad_to_ideal = false; |
| 1538 | | assert(try dwarf.debug_abbrev.section.addUnit(0, 0, dwarf) == DebugAbbrev.unit); |
| 1539 | | errdefer dwarf.debug_abbrev.section.popUnit(); |
| 1540 | | assert(try dwarf.debug_abbrev.section.addEntry(DebugAbbrev.unit, dwarf) == DebugAbbrev.entry); |
| 1584 | assert(try dwarf.debug_abbrev.section.addUnit(DebugAbbrev.header_bytes, DebugAbbrev.trailer_bytes, dwarf) == DebugAbbrev.unit); |
| 1585 | errdefer dwarf.debug_abbrev.section.popUnit(dwarf.gpa); |
| 1586 | for (std.enums.values(AbbrevCode)) |abbrev_code| |
| 1587 | assert(@intFromEnum(try dwarf.debug_abbrev.section.getUnit(DebugAbbrev.unit).addEntry(dwarf.gpa)) == @intFromEnum(abbrev_code)); |
| 1541 | 1588 | |
| 1542 | 1589 | dwarf.debug_aranges.section.pad_to_ideal = false; |
| 1543 | 1590 | dwarf.debug_aranges.section.alignment = InternPool.Alignment.fromNonzeroByteUnits(@intFromEnum(dwarf.address_size) * 2); |
| 1544 | 1591 | |
| 1545 | 1592 | dwarf.debug_line_str.section.pad_to_ideal = false; |
| 1546 | 1593 | assert(try dwarf.debug_line_str.section.addUnit(0, 0, dwarf) == StringSection.unit); |
| 1547 | | errdefer dwarf.debug_line_str.section.popUnit(); |
| 1594 | errdefer dwarf.debug_line_str.section.popUnit(dwarf.gpa); |
| 1548 | 1595 | |
| 1549 | 1596 | dwarf.debug_str.section.pad_to_ideal = false; |
| 1550 | 1597 | assert(try dwarf.debug_str.section.addUnit(0, 0, dwarf) == StringSection.unit); |
| 1551 | | errdefer dwarf.debug_str.section.popUnit(); |
| 1598 | errdefer dwarf.debug_str.section.popUnit(dwarf.gpa); |
| 1552 | 1599 | |
| 1553 | 1600 | dwarf.debug_loclists.section.pad_to_ideal = false; |
| 1554 | 1601 | |
| ... | ... | @@ -1589,31 +1636,31 @@ fn getUnit(dwarf: *Dwarf, mod: *Module) UpdateError!Unit.Index { |
| 1589 | 1636 | DebugAranges.trailerBytes(dwarf), |
| 1590 | 1637 | dwarf, |
| 1591 | 1638 | ) == unit); |
| 1592 | | errdefer dwarf.debug_aranges.section.popUnit(); |
| 1639 | errdefer dwarf.debug_aranges.section.popUnit(dwarf.gpa); |
| 1593 | 1640 | assert(try dwarf.debug_info.section.addUnit( |
| 1594 | 1641 | DebugInfo.headerBytes(dwarf), |
| 1595 | 1642 | DebugInfo.trailer_bytes, |
| 1596 | 1643 | dwarf, |
| 1597 | 1644 | ) == unit); |
| 1598 | | errdefer dwarf.debug_info.section.popUnit(); |
| 1645 | errdefer dwarf.debug_info.section.popUnit(dwarf.gpa); |
| 1599 | 1646 | assert(try dwarf.debug_line.section.addUnit( |
| 1600 | 1647 | DebugLine.headerBytes(dwarf, 5, 25), |
| 1601 | 1648 | DebugLine.trailer_bytes, |
| 1602 | 1649 | dwarf, |
| 1603 | 1650 | ) == unit); |
| 1604 | | errdefer dwarf.debug_line.section.popUnit(); |
| 1651 | errdefer dwarf.debug_line.section.popUnit(dwarf.gpa); |
| 1605 | 1652 | assert(try dwarf.debug_loclists.section.addUnit( |
| 1606 | 1653 | DebugLocLists.headerBytes(dwarf), |
| 1607 | 1654 | DebugLocLists.trailer_bytes, |
| 1608 | 1655 | dwarf, |
| 1609 | 1656 | ) == unit); |
| 1610 | | errdefer dwarf.debug_loclists.section.popUnit(); |
| 1657 | errdefer dwarf.debug_loclists.section.popUnit(dwarf.gpa); |
| 1611 | 1658 | assert(try dwarf.debug_rnglists.section.addUnit( |
| 1612 | 1659 | DebugRngLists.headerBytes(dwarf), |
| 1613 | 1660 | DebugRngLists.trailer_bytes, |
| 1614 | 1661 | dwarf, |
| 1615 | 1662 | ) == unit); |
| 1616 | | errdefer dwarf.debug_rnglists.section.popUnit(); |
| 1663 | errdefer dwarf.debug_rnglists.section.popUnit(dwarf.gpa); |
| 1617 | 1664 | } |
| 1618 | 1665 | return unit; |
| 1619 | 1666 | } |
| ... | ... | @@ -1658,7 +1705,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 1658 | 1705 | .func = .none, |
| 1659 | 1706 | .func_sym_index = undefined, |
| 1660 | 1707 | .func_high_reloc = undefined, |
| 1661 | | .inlined_funcs_high_reloc = undefined, |
| 1708 | .inlined_funcs = undefined, |
| 1662 | 1709 | .debug_info = .{}, |
| 1663 | 1710 | .debug_line = .{}, |
| 1664 | 1711 | .debug_loclists = .{}, |
| ... | ... | @@ -1699,7 +1746,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 1699 | 1746 | } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private }; |
| 1700 | 1747 | |
| 1701 | 1748 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 1702 | | try uleb128(diw, @intFromEnum(AbbrevCode.decl_var)); |
| 1749 | try wip_nav.abbrevCode(.decl_var); |
| 1703 | 1750 | try wip_nav.refType(Type.fromInterned(parent_type)); |
| 1704 | 1751 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| 1705 | 1752 | try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian); |
| ... | ... | @@ -1714,7 +1761,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 1714 | 1761 | ty.abiAlignment(pt).toByteUnits().?); |
| 1715 | 1762 | try diw.writeByte(@intFromBool(false)); |
| 1716 | 1763 | wip_nav.finishForward(ty_reloc_index); |
| 1717 | | try uleb128(diw, @intFromEnum(AbbrevCode.is_const)); |
| 1764 | try wip_nav.abbrevCode(.is_const); |
| 1718 | 1765 | try wip_nav.refType(ty); |
| 1719 | 1766 | }, |
| 1720 | 1767 | .variable => |variable| { |
| ... | ... | @@ -1749,7 +1796,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 1749 | 1796 | } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private }; |
| 1750 | 1797 | |
| 1751 | 1798 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 1752 | | try uleb128(diw, @intFromEnum(AbbrevCode.decl_var)); |
| 1799 | try wip_nav.abbrevCode(.decl_var); |
| 1753 | 1800 | try wip_nav.refType(Type.fromInterned(parent_type)); |
| 1754 | 1801 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| 1755 | 1802 | try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian); |
| ... | ... | @@ -1799,10 +1846,10 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 1799 | 1846 | const func_type = ip.indexToKey(func.ty).func_type; |
| 1800 | 1847 | wip_nav.func = nav_val.toIntern(); |
| 1801 | 1848 | wip_nav.func_sym_index = sym_index; |
| 1802 | | wip_nav.inlined_funcs_high_reloc = .{}; |
| 1849 | wip_nav.inlined_funcs = .{}; |
| 1803 | 1850 | |
| 1804 | 1851 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 1805 | | try uleb128(diw, @intFromEnum(AbbrevCode.decl_func)); |
| 1852 | try wip_nav.abbrevCode(.decl_func); |
| 1806 | 1853 | try wip_nav.refType(Type.fromInterned(parent_type)); |
| 1807 | 1854 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| 1808 | 1855 | try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian); |
| ... | ... | @@ -1891,7 +1938,7 @@ pub fn finishWipNav( |
| 1891 | 1938 | } else std.leb.writeUnsignedFixed( |
| 1892 | 1939 | AbbrevCode.decl_bytes, |
| 1893 | 1940 | wip_nav.debug_info.items[0..AbbrevCode.decl_bytes], |
| 1894 | | @intFromEnum(AbbrevCode.decl_func_empty), |
| 1941 | try dwarf.refAbbrevCode(.decl_empty_func), |
| 1895 | 1942 | ); |
| 1896 | 1943 | |
| 1897 | 1944 | var aranges_entry = [1]u8{0} ** (8 + 8); |
| ... | ... | @@ -1967,7 +2014,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 1967 | 2014 | .func = .none, |
| 1968 | 2015 | .func_sym_index = undefined, |
| 1969 | 2016 | .func_high_reloc = undefined, |
| 1970 | | .inlined_funcs_high_reloc = undefined, |
| 2017 | .inlined_funcs = undefined, |
| 1971 | 2018 | .debug_info = .{}, |
| 1972 | 2019 | .debug_line = .{}, |
| 1973 | 2020 | .debug_loclists = .{}, |
| ... | ... | @@ -1990,12 +2037,12 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 1990 | 2037 | ) != abbrev_code_buf.len) return error.InputOutput; |
| 1991 | 2038 | var abbrev_code_fbs = std.io.fixedBufferStream(&abbrev_code_buf); |
| 1992 | 2039 | const abbrev_code: AbbrevCode = @enumFromInt( |
| 1993 | | try std.leb.readUleb128(@typeInfo(AbbrevCode).Enum.tag_type, abbrev_code_fbs.reader()), |
| 2040 | std.leb.readUleb128(@typeInfo(AbbrevCode).Enum.tag_type, abbrev_code_fbs.reader()) catch unreachable, |
| 1994 | 2041 | ); |
| 1995 | 2042 | switch (abbrev_code) { |
| 1996 | 2043 | else => unreachable, |
| 1997 | | .decl_func, .decl_func_empty => return, |
| 1998 | | .decl_func_generic, .decl_func_generic_empty => {}, |
| 2044 | .decl_func, .decl_empty_func => return, |
| 2045 | .decl_func_generic, .decl_empty_func_generic => {}, |
| 1999 | 2046 | } |
| 2000 | 2047 | } |
| 2001 | 2048 | entry_ptr.clear(); |
| ... | ... | @@ -2017,7 +2064,10 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2017 | 2064 | |
| 2018 | 2065 | const func_type = ip.indexToKey(func.ty).func_type; |
| 2019 | 2066 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2020 | | try uleb128(diw, @intFromEnum(@as(AbbrevCode, if (func_type.param_types.len > 0 or func_type.is_var_args) .decl_func_generic else .decl_func_generic_empty))); |
| 2067 | try wip_nav.abbrevCode(if (func_type.param_types.len > 0 or func_type.is_var_args) |
| 2068 | .decl_func_generic |
| 2069 | else |
| 2070 | .decl_empty_func_generic); |
| 2021 | 2071 | try wip_nav.refType(Type.fromInterned(parent_type)); |
| 2022 | 2072 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| 2023 | 2073 | try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian); |
| ... | ... | @@ -2027,10 +2077,10 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2027 | 2077 | try wip_nav.refType(Type.fromInterned(func_type.return_type)); |
| 2028 | 2078 | if (func_type.param_types.len > 0 or func_type.is_var_args) { |
| 2029 | 2079 | for (0..func_type.param_types.len) |param_index| { |
| 2030 | | try uleb128(diw, @intFromEnum(AbbrevCode.func_type_param)); |
| 2080 | try wip_nav.abbrevCode(.func_type_param); |
| 2031 | 2081 | try wip_nav.refType(Type.fromInterned(func_type.param_types.get(ip)[param_index])); |
| 2032 | 2082 | } |
| 2033 | | if (func_type.is_var_args) try uleb128(diw, @intFromEnum(AbbrevCode.is_var_args)); |
| 2083 | if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args); |
| 2034 | 2084 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 2035 | 2085 | } |
| 2036 | 2086 | }, |
| ... | ... | @@ -2088,10 +2138,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2088 | 2138 | |
| 2089 | 2139 | switch (loaded_struct.layout) { |
| 2090 | 2140 | .auto, .@"extern" => { |
| 2091 | | try uleb128(diw, @intFromEnum(@as(AbbrevCode, if (loaded_struct.field_types.len == 0) |
| 2092 | | .decl_namespace_struct |
| 2093 | | else |
| 2094 | | .decl_struct))); |
| 2141 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .decl_namespace_struct else .decl_struct); |
| 2095 | 2142 | try wip_nav.refType(Type.fromInterned(parent_type)); |
| 2096 | 2143 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| 2097 | 2144 | try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian); |
| ... | ... | @@ -2103,7 +2150,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2103 | 2150 | try uleb128(diw, nav_val.toType().abiAlignment(pt).toByteUnits().?); |
| 2104 | 2151 | for (0..loaded_struct.field_types.len) |field_index| { |
| 2105 | 2152 | const is_comptime = loaded_struct.fieldIsComptime(ip, field_index); |
| 2106 | | try uleb128(diw, @intFromEnum(@as(AbbrevCode, if (is_comptime) .struct_field_comptime else .struct_field))); |
| 2153 | try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field); |
| 2107 | 2154 | if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else { |
| 2108 | 2155 | const field_name = try std.fmt.allocPrint(dwarf.gpa, "{d}", .{field_index}); |
| 2109 | 2156 | defer dwarf.gpa.free(field_name); |
| ... | ... | @@ -2121,7 +2168,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2121 | 2168 | } |
| 2122 | 2169 | }, |
| 2123 | 2170 | .@"packed" => { |
| 2124 | | try uleb128(diw, @intFromEnum(AbbrevCode.decl_packed_struct)); |
| 2171 | try wip_nav.abbrevCode(.decl_packed_struct); |
| 2125 | 2172 | try wip_nav.refType(Type.fromInterned(parent_type)); |
| 2126 | 2173 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| 2127 | 2174 | try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian); |
| ... | ... | @@ -2131,7 +2178,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2131 | 2178 | try wip_nav.refType(Type.fromInterned(loaded_struct.backingIntTypeUnordered(ip))); |
| 2132 | 2179 | var field_bit_offset: u16 = 0; |
| 2133 | 2180 | for (0..loaded_struct.field_types.len) |field_index| { |
| 2134 | | try uleb128(diw, @intFromEnum(@as(AbbrevCode, .packed_struct_field))); |
| 2181 | try wip_nav.abbrevCode(.packed_struct_field); |
| 2135 | 2182 | try wip_nav.strp(loaded_struct.fieldName(ip, field_index).unwrap().?.toSlice(ip)); |
| 2136 | 2183 | const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]); |
| 2137 | 2184 | try wip_nav.refType(field_type); |
| ... | ... | @@ -2150,7 +2197,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2150 | 2197 | nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit); |
| 2151 | 2198 | wip_nav.entry = nav_gop.value_ptr.*; |
| 2152 | 2199 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2153 | | try uleb128(diw, @intFromEnum(AbbrevCode.decl_alias)); |
| 2200 | try wip_nav.abbrevCode(.decl_alias); |
| 2154 | 2201 | try wip_nav.refType(Type.fromInterned(parent_type)); |
| 2155 | 2202 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| 2156 | 2203 | try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian); |
| ... | ... | @@ -2210,7 +2257,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2210 | 2257 | } |
| 2211 | 2258 | wip_nav.entry = nav_gop.value_ptr.*; |
| 2212 | 2259 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2213 | | try uleb128(diw, @intFromEnum(AbbrevCode.decl_enum)); |
| 2260 | try wip_nav.abbrevCode(if (loaded_enum.names.len > 0) .decl_enum else .decl_empty_enum); |
| 2214 | 2261 | try wip_nav.refType(Type.fromInterned(parent_type)); |
| 2215 | 2262 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| 2216 | 2263 | try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian); |
| ... | ... | @@ -2225,7 +2272,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2225 | 2272 | }, field_index); |
| 2226 | 2273 | try wip_nav.strp(loaded_enum.names.get(ip)[field_index].toSlice(ip)); |
| 2227 | 2274 | } |
| 2228 | | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 2275 | if (loaded_enum.names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 2229 | 2276 | break :done; |
| 2230 | 2277 | } |
| 2231 | 2278 | |
| ... | ... | @@ -2235,7 +2282,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2235 | 2282 | nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit); |
| 2236 | 2283 | wip_nav.entry = nav_gop.value_ptr.*; |
| 2237 | 2284 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2238 | | try uleb128(diw, @intFromEnum(AbbrevCode.decl_alias)); |
| 2285 | try wip_nav.abbrevCode(.decl_alias); |
| 2239 | 2286 | try wip_nav.refType(Type.fromInterned(parent_type)); |
| 2240 | 2287 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| 2241 | 2288 | try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian); |
| ... | ... | @@ -2293,7 +2340,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2293 | 2340 | } |
| 2294 | 2341 | wip_nav.entry = nav_gop.value_ptr.*; |
| 2295 | 2342 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2296 | | try uleb128(diw, @intFromEnum(AbbrevCode.decl_union)); |
| 2343 | try wip_nav.abbrevCode(.decl_union); |
| 2297 | 2344 | try wip_nav.refType(Type.fromInterned(parent_type)); |
| 2298 | 2345 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| 2299 | 2346 | try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian); |
| ... | ... | @@ -2305,7 +2352,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2305 | 2352 | try uleb128(diw, union_layout.abi_align.toByteUnits().?); |
| 2306 | 2353 | const loaded_tag = loaded_union.loadTagType(ip); |
| 2307 | 2354 | if (loaded_union.hasTag(ip)) { |
| 2308 | | try uleb128(diw, @intFromEnum(AbbrevCode.tagged_union)); |
| 2355 | try wip_nav.abbrevCode(.tagged_union); |
| 2309 | 2356 | try wip_nav.infoSectionOffset( |
| 2310 | 2357 | .debug_info, |
| 2311 | 2358 | wip_nav.unit, |
| ... | ... | @@ -2313,7 +2360,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2313 | 2360 | @intCast(wip_nav.debug_info.items.len + dwarf.sectionOffsetBytes()), |
| 2314 | 2361 | ); |
| 2315 | 2362 | { |
| 2316 | | try uleb128(diw, @intFromEnum(AbbrevCode.generated_field)); |
| 2363 | try wip_nav.abbrevCode(.generated_field); |
| 2317 | 2364 | try wip_nav.strp("tag"); |
| 2318 | 2365 | try wip_nav.refType(Type.fromInterned(loaded_union.enum_tag_ty)); |
| 2319 | 2366 | try uleb128(diw, union_layout.tagOffset()); |
| ... | ... | @@ -2324,7 +2371,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2324 | 2371 | .unsigned = .unsigned_tagged_union_field, |
| 2325 | 2372 | }, field_index); |
| 2326 | 2373 | { |
| 2327 | | try uleb128(diw, @intFromEnum(AbbrevCode.struct_field)); |
| 2374 | try wip_nav.abbrevCode(.struct_field); |
| 2328 | 2375 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); |
| 2329 | 2376 | const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 2330 | 2377 | try wip_nav.refType(field_type); |
| ... | ... | @@ -2340,7 +2387,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2340 | 2387 | if (ip.indexToKey(loaded_union.enum_tag_ty).enum_type == .generated_tag) |
| 2341 | 2388 | try wip_nav.pending_types.append(dwarf.gpa, loaded_union.enum_tag_ty); |
| 2342 | 2389 | } else for (0..loaded_union.field_types.len) |field_index| { |
| 2343 | | try uleb128(diw, @intFromEnum(AbbrevCode.untagged_union_field)); |
| 2390 | try wip_nav.abbrevCode(.untagged_union_field); |
| 2344 | 2391 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); |
| 2345 | 2392 | const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 2346 | 2393 | try wip_nav.refType(field_type); |
| ... | ... | @@ -2357,7 +2404,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2357 | 2404 | nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit); |
| 2358 | 2405 | wip_nav.entry = nav_gop.value_ptr.*; |
| 2359 | 2406 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2360 | | try uleb128(diw, @intFromEnum(AbbrevCode.decl_alias)); |
| 2407 | try wip_nav.abbrevCode(.decl_alias); |
| 2361 | 2408 | try wip_nav.refType(Type.fromInterned(parent_type)); |
| 2362 | 2409 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| 2363 | 2410 | try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian); |
| ... | ... | @@ -2415,7 +2462,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2415 | 2462 | } |
| 2416 | 2463 | wip_nav.entry = nav_gop.value_ptr.*; |
| 2417 | 2464 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2418 | | try uleb128(diw, @intFromEnum(AbbrevCode.decl_namespace_struct)); |
| 2465 | try wip_nav.abbrevCode(.decl_namespace_struct); |
| 2419 | 2466 | try wip_nav.refType(Type.fromInterned(parent_type)); |
| 2420 | 2467 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| 2421 | 2468 | try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian); |
| ... | ... | @@ -2432,7 +2479,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2432 | 2479 | nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit); |
| 2433 | 2480 | wip_nav.entry = nav_gop.value_ptr.*; |
| 2434 | 2481 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2435 | | try uleb128(diw, @intFromEnum(AbbrevCode.decl_alias)); |
| 2482 | try wip_nav.abbrevCode(.decl_alias); |
| 2436 | 2483 | try wip_nav.refType(Type.fromInterned(parent_type)); |
| 2437 | 2484 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| 2438 | 2485 | try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian); |
| ... | ... | @@ -2473,7 +2520,7 @@ fn updateType( |
| 2473 | 2520 | .func = .none, |
| 2474 | 2521 | .func_sym_index = undefined, |
| 2475 | 2522 | .func_high_reloc = undefined, |
| 2476 | | .inlined_funcs_high_reloc = undefined, |
| 2523 | .inlined_funcs = undefined, |
| 2477 | 2524 | .debug_info = .{}, |
| 2478 | 2525 | .debug_line = .{}, |
| 2479 | 2526 | .debug_loclists = .{}, |
| ... | ... | @@ -2493,7 +2540,7 @@ fn updateType( |
| 2493 | 2540 | |
| 2494 | 2541 | switch (ip.indexToKey(type_index)) { |
| 2495 | 2542 | .int_type => |int_type| { |
| 2496 | | try uleb128(diw, @intFromEnum(AbbrevCode.numeric_type)); |
| 2543 | try wip_nav.abbrevCode(.numeric_type); |
| 2497 | 2544 | try wip_nav.strp(name); |
| 2498 | 2545 | try diw.writeByte(switch (int_type.signedness) { |
| 2499 | 2546 | inline .signed, .unsigned => |signedness| @field(DW.ATE, @tagName(signedness)), |
| ... | ... | @@ -2505,7 +2552,7 @@ fn updateType( |
| 2505 | 2552 | .ptr_type => |ptr_type| switch (ptr_type.flags.size) { |
| 2506 | 2553 | .One, .Many, .C => { |
| 2507 | 2554 | const ptr_child_type = Type.fromInterned(ptr_type.child); |
| 2508 | | try uleb128(diw, @intFromEnum(AbbrevCode.ptr_type)); |
| 2555 | try wip_nav.abbrevCode(.ptr_type); |
| 2509 | 2556 | try wip_nav.strp(name); |
| 2510 | 2557 | try uleb128(diw, ptr_type.flags.alignment.toByteUnits() orelse |
| 2511 | 2558 | ptr_child_type.abiAlignment(pt).toByteUnits().?); |
| ... | ... | @@ -2517,7 +2564,7 @@ fn updateType( |
| 2517 | 2564 | @intCast(wip_nav.debug_info.items.len + dwarf.sectionOffsetBytes()), |
| 2518 | 2565 | ) else try wip_nav.refType(ptr_child_type); |
| 2519 | 2566 | if (ptr_type.flags.is_const) { |
| 2520 | | try uleb128(diw, @intFromEnum(AbbrevCode.is_const)); |
| 2567 | try wip_nav.abbrevCode(.is_const); |
| 2521 | 2568 | if (ptr_type.flags.is_volatile) try wip_nav.infoSectionOffset( |
| 2522 | 2569 | .debug_info, |
| 2523 | 2570 | wip_nav.unit, |
| ... | ... | @@ -2526,21 +2573,21 @@ fn updateType( |
| 2526 | 2573 | ) else try wip_nav.refType(ptr_child_type); |
| 2527 | 2574 | } |
| 2528 | 2575 | if (ptr_type.flags.is_volatile) { |
| 2529 | | try uleb128(diw, @intFromEnum(AbbrevCode.is_volatile)); |
| 2576 | try wip_nav.abbrevCode(.is_volatile); |
| 2530 | 2577 | try wip_nav.refType(ptr_child_type); |
| 2531 | 2578 | } |
| 2532 | 2579 | }, |
| 2533 | 2580 | .Slice => { |
| 2534 | | try uleb128(diw, @intFromEnum(AbbrevCode.struct_type)); |
| 2581 | try wip_nav.abbrevCode(.struct_type); |
| 2535 | 2582 | try wip_nav.strp(name); |
| 2536 | 2583 | try uleb128(diw, ty.abiSize(pt)); |
| 2537 | 2584 | try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?); |
| 2538 | | try uleb128(diw, @intFromEnum(AbbrevCode.generated_field)); |
| 2585 | try wip_nav.abbrevCode(.generated_field); |
| 2539 | 2586 | try wip_nav.strp("ptr"); |
| 2540 | 2587 | const ptr_field_type = ty.slicePtrFieldType(zcu); |
| 2541 | 2588 | try wip_nav.refType(ptr_field_type); |
| 2542 | 2589 | try uleb128(diw, 0); |
| 2543 | | try uleb128(diw, @intFromEnum(AbbrevCode.generated_field)); |
| 2590 | try wip_nav.abbrevCode(.generated_field); |
| 2544 | 2591 | try wip_nav.strp("len"); |
| 2545 | 2592 | const len_field_type = Type.usize; |
| 2546 | 2593 | try wip_nav.refType(len_field_type); |
| ... | ... | @@ -2549,28 +2596,28 @@ fn updateType( |
| 2549 | 2596 | }, |
| 2550 | 2597 | }, |
| 2551 | 2598 | inline .array_type, .vector_type => |array_type, ty_tag| { |
| 2552 | | try uleb128(diw, @intFromEnum(AbbrevCode.array_type)); |
| 2599 | try wip_nav.abbrevCode(.array_type); |
| 2553 | 2600 | try wip_nav.strp(name); |
| 2554 | 2601 | try wip_nav.refType(Type.fromInterned(array_type.child)); |
| 2555 | 2602 | try diw.writeByte(@intFromBool(ty_tag == .vector_type)); |
| 2556 | | try uleb128(diw, @intFromEnum(AbbrevCode.array_index)); |
| 2603 | try wip_nav.abbrevCode(.array_index); |
| 2557 | 2604 | try wip_nav.refType(Type.usize); |
| 2558 | 2605 | try uleb128(diw, array_type.len); |
| 2559 | 2606 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 2560 | 2607 | }, |
| 2561 | 2608 | .opt_type => |opt_child_type_index| { |
| 2562 | 2609 | const opt_child_type = Type.fromInterned(opt_child_type_index); |
| 2563 | | try uleb128(diw, @intFromEnum(AbbrevCode.union_type)); |
| 2610 | try wip_nav.abbrevCode(.union_type); |
| 2564 | 2611 | try wip_nav.strp(name); |
| 2565 | 2612 | try uleb128(diw, ty.abiSize(pt)); |
| 2566 | 2613 | try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?); |
| 2567 | 2614 | if (opt_child_type.isNoReturn(zcu)) { |
| 2568 | | try uleb128(diw, @intFromEnum(AbbrevCode.generated_field)); |
| 2615 | try wip_nav.abbrevCode(.generated_field); |
| 2569 | 2616 | try wip_nav.strp("null"); |
| 2570 | 2617 | try wip_nav.refType(Type.null); |
| 2571 | 2618 | try uleb128(diw, 0); |
| 2572 | 2619 | } else { |
| 2573 | | try uleb128(diw, @intFromEnum(AbbrevCode.tagged_union)); |
| 2620 | try wip_nav.abbrevCode(.tagged_union); |
| 2574 | 2621 | try wip_nav.infoSectionOffset( |
| 2575 | 2622 | .debug_info, |
| 2576 | 2623 | wip_nav.unit, |
| ... | ... | @@ -2578,7 +2625,7 @@ fn updateType( |
| 2578 | 2625 | @intCast(wip_nav.debug_info.items.len + dwarf.sectionOffsetBytes()), |
| 2579 | 2626 | ); |
| 2580 | 2627 | { |
| 2581 | | try uleb128(diw, @intFromEnum(AbbrevCode.generated_field)); |
| 2628 | try wip_nav.abbrevCode(.generated_field); |
| 2582 | 2629 | try wip_nav.strp("has_value"); |
| 2583 | 2630 | const repr: enum { unpacked, error_set, pointer } = switch (opt_child_type_index) { |
| 2584 | 2631 | .anyerror_type => .error_set, |
| ... | ... | @@ -2609,19 +2656,19 @@ fn updateType( |
| 2609 | 2656 | }, |
| 2610 | 2657 | } |
| 2611 | 2658 | |
| 2612 | | try uleb128(diw, @intFromEnum(AbbrevCode.unsigned_tagged_union_field)); |
| 2659 | try wip_nav.abbrevCode(.unsigned_tagged_union_field); |
| 2613 | 2660 | try uleb128(diw, 0); |
| 2614 | 2661 | { |
| 2615 | | try uleb128(diw, @intFromEnum(AbbrevCode.generated_field)); |
| 2662 | try wip_nav.abbrevCode(.generated_field); |
| 2616 | 2663 | try wip_nav.strp("null"); |
| 2617 | 2664 | try wip_nav.refType(Type.null); |
| 2618 | 2665 | try uleb128(diw, 0); |
| 2619 | 2666 | } |
| 2620 | 2667 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 2621 | 2668 | |
| 2622 | | try uleb128(diw, @intFromEnum(AbbrevCode.tagged_union_default_field)); |
| 2669 | try wip_nav.abbrevCode(.tagged_union_default_field); |
| 2623 | 2670 | { |
| 2624 | | try uleb128(diw, @intFromEnum(AbbrevCode.generated_field)); |
| 2671 | try wip_nav.abbrevCode(.generated_field); |
| 2625 | 2672 | try wip_nav.strp("?"); |
| 2626 | 2673 | try wip_nav.refType(opt_child_type); |
| 2627 | 2674 | try uleb128(diw, 0); |
| ... | ... | @@ -2644,7 +2691,7 @@ fn updateType( |
| 2644 | 2691 | }, |
| 2645 | 2692 | }; |
| 2646 | 2693 | |
| 2647 | | try uleb128(diw, @intFromEnum(AbbrevCode.union_type)); |
| 2694 | try wip_nav.abbrevCode(.union_type); |
| 2648 | 2695 | try wip_nav.strp(name); |
| 2649 | 2696 | if (error_union_type.error_set_type != .generic_poison_type and |
| 2650 | 2697 | error_union_type.payload_type != .generic_poison_type) |
| ... | ... | @@ -2656,7 +2703,7 @@ fn updateType( |
| 2656 | 2703 | try uleb128(diw, 1); |
| 2657 | 2704 | } |
| 2658 | 2705 | { |
| 2659 | | try uleb128(diw, @intFromEnum(AbbrevCode.tagged_union)); |
| 2706 | try wip_nav.abbrevCode(.tagged_union); |
| 2660 | 2707 | try wip_nav.infoSectionOffset( |
| 2661 | 2708 | .debug_info, |
| 2662 | 2709 | wip_nav.unit, |
| ... | ... | @@ -2664,7 +2711,7 @@ fn updateType( |
| 2664 | 2711 | @intCast(wip_nav.debug_info.items.len + dwarf.sectionOffsetBytes()), |
| 2665 | 2712 | ); |
| 2666 | 2713 | { |
| 2667 | | try uleb128(diw, @intFromEnum(AbbrevCode.generated_field)); |
| 2714 | try wip_nav.abbrevCode(.generated_field); |
| 2668 | 2715 | try wip_nav.strp("is_error"); |
| 2669 | 2716 | try wip_nav.refType(Type.fromInterned(try pt.intern(.{ .int_type = .{ |
| 2670 | 2717 | .signedness = .unsigned, |
| ... | ... | @@ -2672,19 +2719,19 @@ fn updateType( |
| 2672 | 2719 | } }))); |
| 2673 | 2720 | try uleb128(diw, error_union_error_set_offset); |
| 2674 | 2721 | |
| 2675 | | try uleb128(diw, @intFromEnum(AbbrevCode.unsigned_tagged_union_field)); |
| 2722 | try wip_nav.abbrevCode(.unsigned_tagged_union_field); |
| 2676 | 2723 | try uleb128(diw, 0); |
| 2677 | 2724 | { |
| 2678 | | try uleb128(diw, @intFromEnum(AbbrevCode.generated_field)); |
| 2725 | try wip_nav.abbrevCode(.generated_field); |
| 2679 | 2726 | try wip_nav.strp("value"); |
| 2680 | 2727 | try wip_nav.refType(error_union_payload_type); |
| 2681 | 2728 | try uleb128(diw, error_union_payload_offset); |
| 2682 | 2729 | } |
| 2683 | 2730 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 2684 | 2731 | |
| 2685 | | try uleb128(diw, @intFromEnum(AbbrevCode.tagged_union_default_field)); |
| 2732 | try wip_nav.abbrevCode(.tagged_union_default_field); |
| 2686 | 2733 | { |
| 2687 | | try uleb128(diw, @intFromEnum(AbbrevCode.generated_field)); |
| 2734 | try wip_nav.abbrevCode(.generated_field); |
| 2688 | 2735 | try wip_nav.strp("error"); |
| 2689 | 2736 | try wip_nav.refType(error_union_error_set_type); |
| 2690 | 2737 | try uleb128(diw, error_union_error_set_offset); |
| ... | ... | @@ -2715,7 +2762,7 @@ fn updateType( |
| 2715 | 2762 | .c_longdouble, |
| 2716 | 2763 | .bool, |
| 2717 | 2764 | => { |
| 2718 | | try uleb128(diw, @intFromEnum(AbbrevCode.numeric_type)); |
| 2765 | try wip_nav.abbrevCode(.numeric_type); |
| 2719 | 2766 | try wip_nav.strp(name); |
| 2720 | 2767 | try diw.writeByte(if (type_index == .bool_type) |
| 2721 | 2768 | DW.ATE.boolean |
| ... | ... | @@ -2742,7 +2789,7 @@ fn updateType( |
| 2742 | 2789 | .enum_literal, |
| 2743 | 2790 | .generic_poison, |
| 2744 | 2791 | => { |
| 2745 | | try uleb128(diw, @intFromEnum(AbbrevCode.void_type)); |
| 2792 | try wip_nav.abbrevCode(.void_type); |
| 2746 | 2793 | try wip_nav.strp(if (type_index == .generic_poison_type) "anytype" else name); |
| 2747 | 2794 | }, |
| 2748 | 2795 | .anyerror => return, // delay until flush |
| ... | ... | @@ -2752,15 +2799,19 @@ fn updateType( |
| 2752 | 2799 | .union_type, |
| 2753 | 2800 | .opaque_type, |
| 2754 | 2801 | => unreachable, |
| 2755 | | .anon_struct_type => |anon_struct_type| { |
| 2756 | | try uleb128(diw, @intFromEnum(AbbrevCode.struct_type)); |
| 2802 | .anon_struct_type => |anon_struct_type| if (anon_struct_type.types.len == 0) { |
| 2803 | try wip_nav.abbrevCode(.namespace_struct_type); |
| 2804 | try wip_nav.strp(name); |
| 2805 | try diw.writeByte(@intFromBool(false)); |
| 2806 | } else { |
| 2807 | try wip_nav.abbrevCode(.struct_type); |
| 2757 | 2808 | try wip_nav.strp(name); |
| 2758 | 2809 | try uleb128(diw, ty.abiSize(pt)); |
| 2759 | 2810 | try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?); |
| 2760 | 2811 | var field_byte_offset: u64 = 0; |
| 2761 | 2812 | for (0..anon_struct_type.types.len) |field_index| { |
| 2762 | 2813 | const comptime_value = anon_struct_type.values.get(ip)[field_index]; |
| 2763 | | try uleb128(diw, @intFromEnum(@as(AbbrevCode, if (comptime_value != .none) .struct_field_comptime else .struct_field))); |
| 2814 | try wip_nav.abbrevCode(if (comptime_value != .none) .struct_field_comptime else .struct_field); |
| 2764 | 2815 | if (anon_struct_type.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else { |
| 2765 | 2816 | const field_name = try std.fmt.allocPrint(dwarf.gpa, "{d}", .{field_index}); |
| 2766 | 2817 | defer dwarf.gpa.free(field_name); |
| ... | ... | @@ -2780,7 +2831,7 @@ fn updateType( |
| 2780 | 2831 | }, |
| 2781 | 2832 | .enum_type => { |
| 2782 | 2833 | const loaded_enum = ip.loadEnumType(type_index); |
| 2783 | | try uleb128(diw, @intFromEnum(AbbrevCode.enum_type)); |
| 2834 | try wip_nav.abbrevCode(.enum_type); |
| 2784 | 2835 | try wip_nav.strp(name); |
| 2785 | 2836 | try wip_nav.refType(Type.fromInterned(loaded_enum.tag_ty)); |
| 2786 | 2837 | for (0..loaded_enum.names.len) |field_index| { |
| ... | ... | @@ -2794,7 +2845,7 @@ fn updateType( |
| 2794 | 2845 | }, |
| 2795 | 2846 | .func_type => |func_type| { |
| 2796 | 2847 | const is_nullary = func_type.param_types.len == 0 and !func_type.is_var_args; |
| 2797 | | try uleb128(diw, @intFromEnum(@as(AbbrevCode, if (is_nullary) .nullary_func_type else .func_type))); |
| 2848 | try wip_nav.abbrevCode(if (is_nullary) .nullary_func_type else .func_type); |
| 2798 | 2849 | try wip_nav.strp(name); |
| 2799 | 2850 | try diw.writeByte(@intFromEnum(@as(DW.CC, switch (func_type.cc) { |
| 2800 | 2851 | .Unspecified, .C => .normal, |
| ... | ... | @@ -2814,15 +2865,15 @@ fn updateType( |
| 2814 | 2865 | try wip_nav.refType(Type.fromInterned(func_type.return_type)); |
| 2815 | 2866 | if (!is_nullary) { |
| 2816 | 2867 | for (0..func_type.param_types.len) |param_index| { |
| 2817 | | try uleb128(diw, @intFromEnum(AbbrevCode.func_type_param)); |
| 2868 | try wip_nav.abbrevCode(.func_type_param); |
| 2818 | 2869 | try wip_nav.refType(Type.fromInterned(func_type.param_types.get(ip)[param_index])); |
| 2819 | 2870 | } |
| 2820 | | if (func_type.is_var_args) try uleb128(diw, @intFromEnum(AbbrevCode.is_var_args)); |
| 2871 | if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args); |
| 2821 | 2872 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 2822 | 2873 | } |
| 2823 | 2874 | }, |
| 2824 | 2875 | .error_set_type => |error_set_type| { |
| 2825 | | try uleb128(diw, @intFromEnum(@as(AbbrevCode, if (error_set_type.names.len > 0) .enum_type else .empty_enum_type))); |
| 2876 | try wip_nav.abbrevCode(if (error_set_type.names.len > 0) .enum_type else .empty_enum_type); |
| 2826 | 2877 | try wip_nav.strp(name); |
| 2827 | 2878 | try wip_nav.refType(Type.fromInterned(try pt.intern(.{ .int_type = .{ |
| 2828 | 2879 | .signedness = .unsigned, |
| ... | ... | @@ -2830,7 +2881,7 @@ fn updateType( |
| 2830 | 2881 | } }))); |
| 2831 | 2882 | for (0..error_set_type.names.len) |field_index| { |
| 2832 | 2883 | const field_name = error_set_type.names.get(ip)[field_index]; |
| 2833 | | try uleb128(diw, @intFromEnum(AbbrevCode.unsigned_enum_field)); |
| 2884 | try wip_nav.abbrevCode(.unsigned_enum_field); |
| 2834 | 2885 | try uleb128(diw, ip.getErrorValueIfExists(field_name).?); |
| 2835 | 2886 | try wip_nav.strp(field_name.toSlice(ip)); |
| 2836 | 2887 | } |
| ... | ... | @@ -2838,11 +2889,11 @@ fn updateType( |
| 2838 | 2889 | }, |
| 2839 | 2890 | .inferred_error_set_type => |func| switch (ip.funcIesResolvedUnordered(func)) { |
| 2840 | 2891 | .none => { |
| 2841 | | try uleb128(diw, @intFromEnum(AbbrevCode.void_type)); |
| 2892 | try wip_nav.abbrevCode(.void_type); |
| 2842 | 2893 | try wip_nav.strp(name); |
| 2843 | 2894 | }, |
| 2844 | 2895 | else => |ies| { |
| 2845 | | try uleb128(diw, @intFromEnum(AbbrevCode.inferred_error_set_type)); |
| 2896 | try wip_nav.abbrevCode(.inferred_error_set_type); |
| 2846 | 2897 | try wip_nav.strp(name); |
| 2847 | 2898 | try wip_nav.refType(Type.fromInterned(ies)); |
| 2848 | 2899 | }, |
| ... | ... | @@ -2894,7 +2945,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 2894 | 2945 | .func = .none, |
| 2895 | 2946 | .func_sym_index = undefined, |
| 2896 | 2947 | .func_high_reloc = undefined, |
| 2897 | | .inlined_funcs_high_reloc = undefined, |
| 2948 | .inlined_funcs = undefined, |
| 2898 | 2949 | .debug_info = .{}, |
| 2899 | 2950 | .debug_line = .{}, |
| 2900 | 2951 | .debug_loclists = .{}, |
| ... | ... | @@ -2905,7 +2956,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 2905 | 2956 | const loaded_struct = ip.loadStructType(type_index); |
| 2906 | 2957 | |
| 2907 | 2958 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 2908 | | try uleb128(diw, @intFromEnum(@as(AbbrevCode, if (loaded_struct.field_types.len == 0) .namespace_file else .file))); |
| 2959 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .namespace_file else .file); |
| 2909 | 2960 | const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, inst_info.file); |
| 2910 | 2961 | try uleb128(diw, file_gop.index); |
| 2911 | 2962 | try wip_nav.strp(loaded_struct.name.toSlice(ip)); |
| ... | ... | @@ -2914,7 +2965,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 2914 | 2965 | try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?); |
| 2915 | 2966 | for (0..loaded_struct.field_types.len) |field_index| { |
| 2916 | 2967 | const is_comptime = loaded_struct.fieldIsComptime(ip, field_index); |
| 2917 | | try uleb128(diw, @intFromEnum(@as(AbbrevCode, if (is_comptime) .struct_field_comptime else .struct_field))); |
| 2968 | try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field); |
| 2918 | 2969 | if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else { |
| 2919 | 2970 | const field_name = try std.fmt.allocPrint(dwarf.gpa, "{d}", .{field_index}); |
| 2920 | 2971 | defer dwarf.gpa.free(field_name); |
| ... | ... | @@ -2957,7 +3008,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 2957 | 3008 | .func = .none, |
| 2958 | 3009 | .func_sym_index = undefined, |
| 2959 | 3010 | .func_high_reloc = undefined, |
| 2960 | | .inlined_funcs_high_reloc = undefined, |
| 3011 | .inlined_funcs = undefined, |
| 2961 | 3012 | .debug_info = .{}, |
| 2962 | 3013 | .debug_line = .{}, |
| 2963 | 3014 | .debug_loclists = .{}, |
| ... | ... | @@ -2973,17 +3024,14 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 2973 | 3024 | const loaded_struct = ip.loadStructType(type_index); |
| 2974 | 3025 | switch (loaded_struct.layout) { |
| 2975 | 3026 | .auto, .@"extern" => { |
| 2976 | | try uleb128(diw, @intFromEnum(@as(AbbrevCode, if (loaded_struct.field_types.len == 0) |
| 2977 | | .namespace_struct_type |
| 2978 | | else |
| 2979 | | .struct_type))); |
| 3027 | try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .namespace_struct_type else .struct_type); |
| 2980 | 3028 | try wip_nav.strp(name); |
| 2981 | 3029 | if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else { |
| 2982 | 3030 | try uleb128(diw, ty.abiSize(pt)); |
| 2983 | 3031 | try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?); |
| 2984 | 3032 | for (0..loaded_struct.field_types.len) |field_index| { |
| 2985 | 3033 | const is_comptime = loaded_struct.fieldIsComptime(ip, field_index); |
| 2986 | | try uleb128(diw, @intFromEnum(@as(AbbrevCode, if (is_comptime) .struct_field_comptime else .struct_field))); |
| 3034 | try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field); |
| 2987 | 3035 | if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else { |
| 2988 | 3036 | const field_name = try std.fmt.allocPrint(dwarf.gpa, "{d}", .{field_index}); |
| 2989 | 3037 | defer dwarf.gpa.free(field_name); |
| ... | ... | @@ -3001,12 +3049,12 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3001 | 3049 | } |
| 3002 | 3050 | }, |
| 3003 | 3051 | .@"packed" => { |
| 3004 | | try uleb128(diw, @intFromEnum(AbbrevCode.packed_struct_type)); |
| 3052 | try wip_nav.abbrevCode(.packed_struct_type); |
| 3005 | 3053 | try wip_nav.strp(name); |
| 3006 | 3054 | try wip_nav.refType(Type.fromInterned(loaded_struct.backingIntTypeUnordered(ip))); |
| 3007 | 3055 | var field_bit_offset: u16 = 0; |
| 3008 | 3056 | for (0..loaded_struct.field_types.len) |field_index| { |
| 3009 | | try uleb128(diw, @intFromEnum(@as(AbbrevCode, .packed_struct_field))); |
| 3057 | try wip_nav.abbrevCode(.packed_struct_field); |
| 3010 | 3058 | try wip_nav.strp(loaded_struct.fieldName(ip, field_index).unwrap().?.toSlice(ip)); |
| 3011 | 3059 | const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]); |
| 3012 | 3060 | try wip_nav.refType(field_type); |
| ... | ... | @@ -3019,7 +3067,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3019 | 3067 | }, |
| 3020 | 3068 | .enum_type => { |
| 3021 | 3069 | const loaded_enum = ip.loadEnumType(type_index); |
| 3022 | | try uleb128(diw, @intFromEnum(AbbrevCode.enum_type)); |
| 3070 | try wip_nav.abbrevCode(.enum_type); |
| 3023 | 3071 | try wip_nav.strp(name); |
| 3024 | 3072 | try wip_nav.refType(Type.fromInterned(loaded_enum.tag_ty)); |
| 3025 | 3073 | for (0..loaded_enum.names.len) |field_index| { |
| ... | ... | @@ -3033,14 +3081,14 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3033 | 3081 | }, |
| 3034 | 3082 | .union_type => { |
| 3035 | 3083 | const loaded_union = ip.loadUnionType(type_index); |
| 3036 | | try uleb128(diw, @intFromEnum(AbbrevCode.union_type)); |
| 3084 | try wip_nav.abbrevCode(.union_type); |
| 3037 | 3085 | try wip_nav.strp(name); |
| 3038 | 3086 | const union_layout = pt.getUnionLayout(loaded_union); |
| 3039 | 3087 | try uleb128(diw, union_layout.abi_size); |
| 3040 | 3088 | try uleb128(diw, union_layout.abi_align.toByteUnits().?); |
| 3041 | 3089 | const loaded_tag = loaded_union.loadTagType(ip); |
| 3042 | 3090 | if (loaded_union.hasTag(ip)) { |
| 3043 | | try uleb128(diw, @intFromEnum(AbbrevCode.tagged_union)); |
| 3091 | try wip_nav.abbrevCode(.tagged_union); |
| 3044 | 3092 | try wip_nav.infoSectionOffset( |
| 3045 | 3093 | .debug_info, |
| 3046 | 3094 | wip_nav.unit, |
| ... | ... | @@ -3048,7 +3096,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3048 | 3096 | @intCast(wip_nav.debug_info.items.len + dwarf.sectionOffsetBytes()), |
| 3049 | 3097 | ); |
| 3050 | 3098 | { |
| 3051 | | try uleb128(diw, @intFromEnum(AbbrevCode.generated_field)); |
| 3099 | try wip_nav.abbrevCode(.generated_field); |
| 3052 | 3100 | try wip_nav.strp("tag"); |
| 3053 | 3101 | try wip_nav.refType(Type.fromInterned(loaded_union.enum_tag_ty)); |
| 3054 | 3102 | try uleb128(diw, union_layout.tagOffset()); |
| ... | ... | @@ -3059,7 +3107,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3059 | 3107 | .unsigned = .unsigned_tagged_union_field, |
| 3060 | 3108 | }, field_index); |
| 3061 | 3109 | { |
| 3062 | | try uleb128(diw, @intFromEnum(AbbrevCode.struct_field)); |
| 3110 | try wip_nav.abbrevCode(.struct_field); |
| 3063 | 3111 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); |
| 3064 | 3112 | const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 3065 | 3113 | try wip_nav.refType(field_type); |
| ... | ... | @@ -3075,7 +3123,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3075 | 3123 | if (ip.indexToKey(loaded_union.enum_tag_ty).enum_type == .generated_tag) |
| 3076 | 3124 | try wip_nav.pending_types.append(dwarf.gpa, loaded_union.enum_tag_ty); |
| 3077 | 3125 | } else for (0..loaded_union.field_types.len) |field_index| { |
| 3078 | | try uleb128(diw, @intFromEnum(AbbrevCode.untagged_union_field)); |
| 3126 | try wip_nav.abbrevCode(.untagged_union_field); |
| 3079 | 3127 | try wip_nav.strp(loaded_tag.names.get(ip)[field_index].toSlice(ip)); |
| 3080 | 3128 | const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]); |
| 3081 | 3129 | try wip_nav.refType(field_type); |
| ... | ... | @@ -3085,7 +3133,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 3085 | 3133 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 3086 | 3134 | }, |
| 3087 | 3135 | .opaque_type => { |
| 3088 | | try uleb128(diw, @intFromEnum(AbbrevCode.namespace_struct_type)); |
| 3136 | try wip_nav.abbrevCode(.namespace_struct_type); |
| 3089 | 3137 | try wip_nav.strp(name); |
| 3090 | 3138 | try diw.writeByte(@intFromBool(true)); |
| 3091 | 3139 | }, |
| ... | ... | @@ -3121,6 +3169,23 @@ pub fn freeNav(dwarf: *Dwarf, nav_index: InternPool.Nav.Index) void { |
| 3121 | 3169 | _ = nav_index; |
| 3122 | 3170 | } |
| 3123 | 3171 | |
| 3172 | fn refAbbrevCode(dwarf: *Dwarf, abbrev_code: AbbrevCode) UpdateError!@typeInfo(AbbrevCode).Enum.tag_type { |
| 3173 | assert(abbrev_code != .null); |
| 3174 | const entry: Entry.Index = @enumFromInt(@intFromEnum(abbrev_code)); |
| 3175 | if (dwarf.debug_abbrev.section.getUnit(DebugAbbrev.unit).getEntry(entry).len > 0) return @intFromEnum(abbrev_code); |
| 3176 | var debug_abbrev = std.ArrayList(u8).init(dwarf.gpa); |
| 3177 | defer debug_abbrev.deinit(); |
| 3178 | const daw = debug_abbrev.writer(); |
| 3179 | const abbrev = AbbrevCode.abbrevs.get(abbrev_code); |
| 3180 | try uleb128(daw, @intFromEnum(abbrev_code)); |
| 3181 | try uleb128(daw, @intFromEnum(abbrev.tag)); |
| 3182 | try daw.writeByte(if (abbrev.children) DW.CHILDREN.yes else DW.CHILDREN.no); |
| 3183 | for (abbrev.attrs) |*attr| inline for (attr) |info| try uleb128(daw, @intFromEnum(info)); |
| 3184 | for (0..2) |_| try uleb128(daw, 0); |
| 3185 | try dwarf.debug_abbrev.section.replaceEntry(DebugAbbrev.unit, entry, dwarf, debug_abbrev.items); |
| 3186 | return @intFromEnum(abbrev_code); |
| 3187 | } |
| 3188 | |
| 3124 | 3189 | pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3125 | 3190 | const ip = &pt.zcu.intern_pool; |
| 3126 | 3191 | if (dwarf.types.get(.anyerror_type)) |entry| { |
| ... | ... | @@ -3133,7 +3198,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3133 | 3198 | .func = .none, |
| 3134 | 3199 | .func_sym_index = undefined, |
| 3135 | 3200 | .func_high_reloc = undefined, |
| 3136 | | .inlined_funcs_high_reloc = undefined, |
| 3201 | .inlined_funcs = undefined, |
| 3137 | 3202 | .debug_info = .{}, |
| 3138 | 3203 | .debug_line = .{}, |
| 3139 | 3204 | .debug_loclists = .{}, |
| ... | ... | @@ -3142,14 +3207,14 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3142 | 3207 | defer wip_nav.deinit(); |
| 3143 | 3208 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 3144 | 3209 | const global_error_set_names = ip.global_error_set.getNamesFromMainThread(); |
| 3145 | | try uleb128(diw, @intFromEnum(@as(AbbrevCode, if (global_error_set_names.len > 0) .enum_type else .empty_enum_type))); |
| 3210 | try wip_nav.abbrevCode(if (global_error_set_names.len > 0) .enum_type else .empty_enum_type); |
| 3146 | 3211 | try wip_nav.strp("anyerror"); |
| 3147 | 3212 | try wip_nav.refType(Type.fromInterned(try pt.intern(.{ .int_type = .{ |
| 3148 | 3213 | .signedness = .unsigned, |
| 3149 | 3214 | .bits = pt.zcu.errorSetBits(), |
| 3150 | 3215 | } }))); |
| 3151 | 3216 | for (global_error_set_names, 1..) |name, value| { |
| 3152 | | try uleb128(diw, @intFromEnum(AbbrevCode.unsigned_enum_field)); |
| 3217 | try wip_nav.abbrevCode(.unsigned_enum_field); |
| 3153 | 3218 | try uleb128(diw, value); |
| 3154 | 3219 | try wip_nav.strp(name.toSlice(ip)); |
| 3155 | 3220 | } |
| ... | ... | @@ -3173,21 +3238,6 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3173 | 3238 | |
| 3174 | 3239 | var header = std.ArrayList(u8).init(dwarf.gpa); |
| 3175 | 3240 | defer header.deinit(); |
| 3176 | | if (dwarf.debug_abbrev.section.dirty) { |
| 3177 | | for (1.., &AbbrevCode.abbrevs) |code, *abbrev| { |
| 3178 | | try uleb128(header.writer(), code); |
| 3179 | | try uleb128(header.writer(), @intFromEnum(abbrev.tag)); |
| 3180 | | try header.append(if (abbrev.children) DW.CHILDREN.yes else DW.CHILDREN.no); |
| 3181 | | for (abbrev.attrs) |*attr| { |
| 3182 | | try uleb128(header.writer(), @intFromEnum(attr[0])); |
| 3183 | | try uleb128(header.writer(), @intFromEnum(attr[1])); |
| 3184 | | } |
| 3185 | | try header.appendSlice(&.{ 0, 0 }); |
| 3186 | | } |
| 3187 | | try header.append(@intFromEnum(AbbrevCode.null)); |
| 3188 | | try dwarf.debug_abbrev.section.replaceEntry(DebugAbbrev.unit, DebugAbbrev.entry, dwarf, header.items); |
| 3189 | | dwarf.debug_abbrev.section.dirty = false; |
| 3190 | | } |
| 3191 | 3241 | if (dwarf.debug_aranges.section.dirty) { |
| 3192 | 3242 | for (dwarf.debug_aranges.section.units.items, 0..) |*unit_ptr, unit_index| { |
| 3193 | 3243 | const unit: Unit.Index = @enumFromInt(unit_index); |
| ... | ... | @@ -3245,11 +3295,10 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3245 | 3295 | .source_off = @intCast(header.items.len), |
| 3246 | 3296 | .target_sec = .debug_abbrev, |
| 3247 | 3297 | .target_unit = DebugAbbrev.unit, |
| 3248 | | .target_entry = DebugAbbrev.entry.toOptional(), |
| 3249 | 3298 | }); |
| 3250 | 3299 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 3251 | 3300 | const compile_unit_off: u32 = @intCast(header.items.len); |
| 3252 | | uleb128(header.fixedWriter(), @intFromEnum(AbbrevCode.compile_unit)) catch unreachable; |
| 3301 | uleb128(header.fixedWriter(), try dwarf.refAbbrevCode(.compile_unit)) catch unreachable; |
| 3253 | 3302 | header.appendAssumeCapacity(DW.LANG.Zig); |
| 3254 | 3303 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 3255 | 3304 | .source_off = @intCast(header.items.len), |
| ... | ... | @@ -3292,7 +3341,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3292 | 3341 | }); |
| 3293 | 3342 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
| 3294 | 3343 | uleb128(header.fixedWriter(), 0) catch unreachable; |
| 3295 | | uleb128(header.fixedWriter(), @intFromEnum(AbbrevCode.module)) catch unreachable; |
| 3344 | uleb128(header.fixedWriter(), try dwarf.refAbbrevCode(.module)) catch unreachable; |
| 3296 | 3345 | unit_ptr.cross_section_relocs.appendAssumeCapacity(.{ |
| 3297 | 3346 | .source_off = @intCast(header.items.len), |
| 3298 | 3347 | .target_sec = .debug_str, |
| ... | ... | @@ -3306,6 +3355,11 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3306 | 3355 | } |
| 3307 | 3356 | dwarf.debug_info.section.dirty = false; |
| 3308 | 3357 | } |
| 3358 | if (dwarf.debug_abbrev.section.dirty) { |
| 3359 | assert(!dwarf.debug_info.section.dirty); |
| 3360 | try dwarf.debug_abbrev.section.getUnit(DebugAbbrev.unit).writeTrailer(&dwarf.debug_abbrev.section, dwarf); |
| 3361 | dwarf.debug_abbrev.section.dirty = false; |
| 3362 | } |
| 3309 | 3363 | if (dwarf.debug_str.section.dirty) { |
| 3310 | 3364 | const contents = dwarf.debug_str.contents.items; |
| 3311 | 3365 | try dwarf.debug_str.section.resize(dwarf, contents.len); |
| ... | ... | @@ -3313,8 +3367,11 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3313 | 3367 | dwarf.debug_str.section.dirty = false; |
| 3314 | 3368 | } |
| 3315 | 3369 | if (dwarf.debug_line.section.dirty) { |
| 3316 | | for (dwarf.mods.values(), dwarf.debug_line.section.units.items) |mod_info, *unit| |
| 3317 | | try unit.resizeHeader(&dwarf.debug_line.section, dwarf, DebugLine.headerBytes(dwarf, @intCast(mod_info.dirs.count()), @intCast(mod_info.files.count()))); |
| 3370 | for (dwarf.mods.values(), dwarf.debug_line.section.units.items) |mod_info, *unit| try unit.resizeHeader( |
| 3371 | &dwarf.debug_line.section, |
| 3372 | dwarf, |
| 3373 | DebugLine.headerBytes(dwarf, @intCast(mod_info.dirs.count()), @intCast(mod_info.files.count())), |
| 3374 | ); |
| 3318 | 3375 | for (dwarf.mods.values(), dwarf.debug_line.section.units.items) |mod_info, *unit| { |
| 3319 | 3376 | unit.clear(); |
| 3320 | 3377 | try unit.cross_section_relocs.ensureTotalCapacity(dwarf.gpa, 2 * (1 + mod_info.files.count())); |
| ... | ... | @@ -3333,14 +3390,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3333 | 3390 | } |
| 3334 | 3391 | std.mem.writeInt(u16, header.addManyAsArrayAssumeCapacity(@sizeOf(u16)), 5, dwarf.endian); |
| 3335 | 3392 | header.appendSliceAssumeCapacity(&.{ @intFromEnum(dwarf.address_size), 0 }); |
| 3336 | | switch (dwarf.format) { |
| 3337 | | inline .@"32", .@"64" => |format| std.mem.writeInt( |
| 3338 | | SectionOffset(format), |
| 3339 | | header.addManyAsArrayAssumeCapacity(@sizeOf(SectionOffset(format))), |
| 3340 | | @intCast(unit.header_len - header.items.len), |
| 3341 | | dwarf.endian, |
| 3342 | | ), |
| 3343 | | } |
| 3393 | dwarf.writeInt(header.addManyAsSliceAssumeCapacity(dwarf.sectionOffsetBytes()), unit.header_len - header.items.len); |
| 3344 | 3394 | const StandardOpcode = DeclValEnum(DW.LNS); |
| 3345 | 3395 | header.appendSliceAssumeCapacity(&[_]u8{ |
| 3346 | 3396 | dwarf.debug_line.header.minimum_instruction_length, |
| ... | ... | @@ -3422,6 +3472,9 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3422 | 3472 | try dwarf.getFile().?.pwriteAll(contents, dwarf.debug_line_str.section.off); |
| 3423 | 3473 | dwarf.debug_line_str.section.dirty = false; |
| 3424 | 3474 | } |
| 3475 | if (dwarf.debug_loclists.section.dirty) { |
| 3476 | dwarf.debug_loclists.section.dirty = false; |
| 3477 | } |
| 3425 | 3478 | if (dwarf.debug_rnglists.section.dirty) { |
| 3426 | 3479 | for (dwarf.debug_rnglists.section.units.items) |*unit| { |
| 3427 | 3480 | header.clearRetainingCapacity(); |
| ... | ... | @@ -3440,19 +3493,20 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3440 | 3493 | std.mem.writeInt(u16, header.addManyAsArrayAssumeCapacity(@sizeOf(u16)), 5, dwarf.endian); |
| 3441 | 3494 | header.appendSliceAssumeCapacity(&.{ @intFromEnum(dwarf.address_size), 0 }); |
| 3442 | 3495 | std.mem.writeInt(u32, header.addManyAsArrayAssumeCapacity(@sizeOf(u32)), 1, dwarf.endian); |
| 3443 | | switch (dwarf.format) { |
| 3444 | | inline .@"32", .@"64" => |format| std.mem.writeInt( |
| 3445 | | SectionOffset(format), |
| 3446 | | header.addManyAsArrayAssumeCapacity(@sizeOf(SectionOffset(format))), |
| 3447 | | @sizeOf(SectionOffset(format)), |
| 3448 | | dwarf.endian, |
| 3449 | | ), |
| 3450 | | } |
| 3496 | dwarf.writeInt(header.addManyAsSliceAssumeCapacity(dwarf.sectionOffsetBytes()), dwarf.sectionOffsetBytes() * 1); |
| 3451 | 3497 | try unit.replaceHeader(&dwarf.debug_rnglists.section, dwarf, header.items); |
| 3452 | 3498 | try unit.writeTrailer(&dwarf.debug_rnglists.section, dwarf); |
| 3453 | 3499 | } |
| 3454 | 3500 | dwarf.debug_rnglists.section.dirty = false; |
| 3455 | 3501 | } |
| 3502 | assert(!dwarf.debug_abbrev.section.dirty); |
| 3503 | assert(!dwarf.debug_aranges.section.dirty); |
| 3504 | assert(!dwarf.debug_info.section.dirty); |
| 3505 | assert(!dwarf.debug_line.section.dirty); |
| 3506 | assert(!dwarf.debug_line_str.section.dirty); |
| 3507 | assert(!dwarf.debug_loclists.section.dirty); |
| 3508 | assert(!dwarf.debug_rnglists.section.dirty); |
| 3509 | assert(!dwarf.debug_str.section.dirty); |
| 3456 | 3510 | } |
| 3457 | 3511 | |
| 3458 | 3512 | pub fn resolveRelocs(dwarf: *Dwarf) RelocError!void { |
| ... | ... | @@ -3491,7 +3545,7 @@ fn DeclValEnum(comptime T: type) type { |
| 3491 | 3545 | } }); |
| 3492 | 3546 | } |
| 3493 | 3547 | |
| 3494 | | const AbbrevCode = enum(u8) { |
| 3548 | const AbbrevCode = enum { |
| 3495 | 3549 | null, |
| 3496 | 3550 | // padding codes must be one byte uleb128 values to function |
| 3497 | 3551 | pad_1, |
| ... | ... | @@ -3499,15 +3553,16 @@ const AbbrevCode = enum(u8) { |
| 3499 | 3553 | // decl codes are assumed to all have the same uleb128 length |
| 3500 | 3554 | decl_alias, |
| 3501 | 3555 | decl_enum, |
| 3556 | decl_empty_enum, |
| 3502 | 3557 | decl_namespace_struct, |
| 3503 | 3558 | decl_struct, |
| 3504 | 3559 | decl_packed_struct, |
| 3505 | 3560 | decl_union, |
| 3506 | 3561 | decl_var, |
| 3507 | 3562 | decl_func, |
| 3508 | | decl_func_empty, |
| 3563 | decl_empty_func, |
| 3509 | 3564 | decl_func_generic, |
| 3510 | | decl_func_generic_empty, |
| 3565 | decl_empty_func_generic, |
| 3511 | 3566 | // the rest are unrestricted |
| 3512 | 3567 | compile_unit, |
| 3513 | 3568 | module, |
| ... | ... | @@ -3542,11 +3597,12 @@ const AbbrevCode = enum(u8) { |
| 3542 | 3597 | struct_type, |
| 3543 | 3598 | packed_struct_type, |
| 3544 | 3599 | union_type, |
| 3600 | empty_inlined_func, |
| 3545 | 3601 | inlined_func, |
| 3546 | 3602 | local_arg, |
| 3547 | 3603 | local_var, |
| 3548 | 3604 | |
| 3549 | | const decl_bytes = uleb128Bytes(@intFromEnum(AbbrevCode.decl_func_generic_empty)); |
| 3605 | const decl_bytes = uleb128Bytes(@intFromEnum(AbbrevCode.decl_empty_func_generic)); |
| 3550 | 3606 | |
| 3551 | 3607 | const Attr = struct { |
| 3552 | 3608 | DeclValEnum(DW.AT), |
| ... | ... | @@ -3586,6 +3642,12 @@ const AbbrevCode = enum(u8) { |
| 3586 | 3642 | .{ .type, .ref_addr }, |
| 3587 | 3643 | }, |
| 3588 | 3644 | }, |
| 3645 | .decl_empty_enum = .{ |
| 3646 | .tag = .enumeration_type, |
| 3647 | .attrs = decl_abbrev_common_attrs ++ .{ |
| 3648 | .{ .type, .ref_addr }, |
| 3649 | }, |
| 3650 | }, |
| 3589 | 3651 | .decl_namespace_struct = .{ |
| 3590 | 3652 | .tag = .structure_type, |
| 3591 | 3653 | .attrs = decl_abbrev_common_attrs ++ .{ |
| ... | ... | @@ -3638,7 +3700,7 @@ const AbbrevCode = enum(u8) { |
| 3638 | 3700 | .{ .noreturn, .flag }, |
| 3639 | 3701 | }, |
| 3640 | 3702 | }, |
| 3641 | | .decl_func_empty = .{ |
| 3703 | .decl_empty_func = .{ |
| 3642 | 3704 | .tag = .subprogram, |
| 3643 | 3705 | .attrs = decl_abbrev_common_attrs ++ .{ |
| 3644 | 3706 | .{ .linkage_name, .strp }, |
| ... | ... | @@ -3657,7 +3719,7 @@ const AbbrevCode = enum(u8) { |
| 3657 | 3719 | .{ .type, .ref_addr }, |
| 3658 | 3720 | }, |
| 3659 | 3721 | }, |
| 3660 | | .decl_func_generic_empty = .{ |
| 3722 | .decl_empty_func_generic = .{ |
| 3661 | 3723 | .tag = .subprogram, |
| 3662 | 3724 | .attrs = decl_abbrev_common_attrs ++ .{ |
| 3663 | 3725 | .{ .type, .ref_addr }, |
| ... | ... | @@ -3918,6 +3980,16 @@ const AbbrevCode = enum(u8) { |
| 3918 | 3980 | .{ .alignment, .udata }, |
| 3919 | 3981 | }, |
| 3920 | 3982 | }, |
| 3983 | .empty_inlined_func = .{ |
| 3984 | .tag = .inlined_subroutine, |
| 3985 | .attrs = &.{ |
| 3986 | .{ .abstract_origin, .ref_addr }, |
| 3987 | .{ .call_line, .udata }, |
| 3988 | .{ .call_column, .udata }, |
| 3989 | .{ .low_pc, .addr }, |
| 3990 | .{ .high_pc, .addr }, |
| 3991 | }, |
| 3992 | }, |
| 3921 | 3993 | .inlined_func = .{ |
| 3922 | 3994 | .tag = .inlined_subroutine, |
| 3923 | 3995 | .children = true, |
| ... | ... | @@ -3946,7 +4018,7 @@ const AbbrevCode = enum(u8) { |
| 3946 | 4018 | }, |
| 3947 | 4019 | }, |
| 3948 | 4020 | .null = undefined, |
| 3949 | | }).values[1..].*; |
| 4021 | }); |
| 3950 | 4022 | }; |
| 3951 | 4023 | |
| 3952 | 4024 | fn getFile(dwarf: *Dwarf) ?std.fs.File { |
| ... | ... | @@ -3955,11 +4027,11 @@ fn getFile(dwarf: *Dwarf) ?std.fs.File { |
| 3955 | 4027 | } |
| 3956 | 4028 | |
| 3957 | 4029 | fn addCommonEntry(dwarf: *Dwarf, unit: Unit.Index) UpdateError!Entry.Index { |
| 3958 | | const entry = try dwarf.debug_aranges.section.addEntry(unit, dwarf); |
| 3959 | | assert(try dwarf.debug_info.section.addEntry(unit, dwarf) == entry); |
| 3960 | | assert(try dwarf.debug_line.section.addEntry(unit, dwarf) == entry); |
| 3961 | | assert(try dwarf.debug_loclists.section.addEntry(unit, dwarf) == entry); |
| 3962 | | assert(try dwarf.debug_rnglists.section.addEntry(unit, dwarf) == entry); |
| 4030 | const entry = try dwarf.debug_aranges.section.getUnit(unit).addEntry(dwarf.gpa); |
| 4031 | assert(try dwarf.debug_info.section.getUnit(unit).addEntry(dwarf.gpa) == entry); |
| 4032 | assert(try dwarf.debug_line.section.getUnit(unit).addEntry(dwarf.gpa) == entry); |
| 4033 | assert(try dwarf.debug_loclists.section.getUnit(unit).addEntry(dwarf.gpa) == entry); |
| 4034 | assert(try dwarf.debug_rnglists.section.getUnit(unit).addEntry(dwarf.gpa) == entry); |
| 3963 | 4035 | return entry; |
| 3964 | 4036 | } |
| 3965 | 4037 | |
| ... | ... | @@ -3993,13 +4065,6 @@ fn sectionOffsetBytes(dwarf: *Dwarf) u32 { |
| 3993 | 4065 | }; |
| 3994 | 4066 | } |
| 3995 | 4067 | |
| 3996 | | fn SectionOffset(comptime format: DW.Format) type { |
| 3997 | | return switch (format) { |
| 3998 | | .@"32" => u32, |
| 3999 | | .@"64" => u64, |
| 4000 | | }; |
| 4001 | | } |
| 4002 | | |
| 4003 | 4068 | fn uleb128Bytes(value: anytype) u32 { |
| 4004 | 4069 | var cw = std.io.countingWriter(std.io.null_writer); |
| 4005 | 4070 | try uleb128(cw.writer(), value); |