authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-06 11:52:49-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-07 16:11:00-04:00
log804b044235954830e66a27b2365e1b26db51478a
tree32d0f61bd6a97ba94738971f3d8ed3aad4a2be39
parentf6d272651274897c10a75f12a2f146ad27f08628

Dwarf2: implement runtime globals


5 files changed, 454 insertions(+), 266 deletions(-)

src/codegen/x86_64/Mir.zig+1-1
......@@ -2009,7 +2009,7 @@ pub fn emit(
20092009 .column = func.lbrace_column,
20102010 .is_stmt = switch (debug_output) {
20112011 .dwarf => |dwarf| dwarf.dwarf.debug_line.header.default_is_stmt,
2012 .dwarf2 => |dwarf| dwarf.wip_nav.dwarf.debug_line.header.default_is_stmt,
2012 .dwarf2 => |dwarf| dwarf.wip_func.dwarf.debug_line.header.default_is_stmt,
20132013 .eh_frame, .none => undefined,
20142014 },
20152015 },
src/link.zig+2-2
......@@ -755,8 +755,8 @@ pub const File = struct {
755755
756756 pub const DebugInfoOutput = union(enum) {
757757 dwarf: *Dwarf.WipNav,
758 eh_frame: *Dwarf2.WipNav,
759 dwarf2: *Dwarf2.WipNav.Debug,
758 eh_frame: *Dwarf2.WipFunc,
759 dwarf2: *Dwarf2.WipFunc.Debug,
760760 none,
761761 };
762762 pub const UpdateDebugInfoError = Dwarf.UpdateError;
src/link/Dwarf2.zig+358-207
......@@ -497,33 +497,33 @@ pub const Cfa = union(enum) {
497497 const RegOff = struct { reg: u32, off: i64 };
498498 const RegExpr = struct { reg: u32, expr: Loc };
499499
500 fn write(cfa: Cfa, wip_nav: *WipNav) link.EmitError!void {
501 const df_nw = &wip_nav.fde_writer;
500 fn write(cfa: Cfa, wip_func: *WipFunc) link.EmitError!void {
501 const df_nw = &wip_func.fde_writer;
502502 const df_w = &df_nw.interface;
503503 switch (cfa) {
504504 .nop => try df_w.writeByte(DW.CFA.nop),
505505 .advance_loc => |loc| {
506506 const delta =
507 @divExact(loc - wip_nav.cfi.loc, wip_nav.dwarf.frame.header.code_alignment_factor);
507 @divExact(loc - wip_func.cfi.loc, wip_func.dwarf.frame.header.code_alignment_factor);
508508 if (delta == 0) {} else if (std.math.cast(u6, delta)) |small_delta|
509509 try df_w.writeByte(@as(u8, DW.CFA.advance_loc) + small_delta)
510510 else if (std.math.cast(u8, delta)) |ubyte_delta|
511511 try df_w.writeAll(&.{ DW.CFA.advance_loc1, ubyte_delta })
512512 else if (std.math.cast(u16, delta)) |uhalf_delta| {
513513 try df_w.writeByte(DW.CFA.advance_loc2);
514 try df_w.writeInt(u16, uhalf_delta, wip_nav.dwarf.endian);
514 try df_w.writeInt(u16, uhalf_delta, wip_func.dwarf.endian);
515515 } else if (std.math.cast(u32, delta)) |uword_delta| {
516516 try df_w.writeByte(DW.CFA.advance_loc4);
517 try df_w.writeInt(u32, uword_delta, wip_nav.dwarf.endian);
517 try df_w.writeInt(u32, uword_delta, wip_func.dwarf.endian);
518518 }
519 wip_nav.cfi.loc = loc;
519 wip_func.cfi.loc = loc;
520520 },
521521 .offset, .rel_offset => |reg_off| {
522522 const factored_off = @divExact(reg_off.off - switch (cfa) {
523523 else => unreachable,
524524 .offset => 0,
525 .rel_offset => wip_nav.cfi.cfa.off,
526 }, wip_nav.dwarf.frame.header.data_alignment_factor);
525 .rel_offset => wip_func.cfi.cfa.off,
526 }, wip_func.dwarf.frame.header.data_alignment_factor);
527527 if (std.math.cast(u63, factored_off)) |unsigned_off| {
528528 if (std.math.cast(u6, reg_off.reg)) |small_reg| {
529529 try df_w.writeByte(@as(u8, DW.CFA.offset) + small_reg);
......@@ -565,21 +565,21 @@ pub const Cfa = union(enum) {
565565 const reg_off: RegOff = switch (cfa) {
566566 else => unreachable,
567567 .def_cfa => |reg_off| reg_off,
568 .def_cfa_register => |reg| .{ .reg = reg, .off = wip_nav.cfi.cfa.off },
569 .def_cfa_offset => |off| .{ .reg = wip_nav.cfi.cfa.reg, .off = off },
568 .def_cfa_register => |reg| .{ .reg = reg, .off = wip_func.cfi.cfa.off },
569 .def_cfa_offset => |off| .{ .reg = wip_func.cfi.cfa.reg, .off = off },
570570 .adjust_cfa_offset => |off| .{
571 .reg = wip_nav.cfi.cfa.reg,
572 .off = wip_nav.cfi.cfa.off + off,
571 .reg = wip_func.cfi.cfa.reg,
572 .off = wip_func.cfi.cfa.off + off,
573573 },
574574 };
575 const changed_reg = reg_off.reg != wip_nav.cfi.cfa.reg;
575 const changed_reg = reg_off.reg != wip_func.cfi.cfa.reg;
576576 const unsigned_off = std.math.cast(u63, reg_off.off);
577 if (reg_off.off == wip_nav.cfi.cfa.off) {
577 if (reg_off.off == wip_func.cfi.cfa.off) {
578578 if (changed_reg) {
579579 try df_w.writeByte(DW.CFA.def_cfa_register);
580580 try df_w.writeUleb128(reg_off.reg);
581581 }
582 } else if (switch (wip_nav.dwarf.frame.header.data_alignment_factor) {
582 } else if (switch (wip_func.dwarf.frame.header.data_alignment_factor) {
583583 0 => unreachable,
584584 1 => unsigned_off != null,
585585 else => |data_alignment_factor| @rem(reg_off.off, data_alignment_factor) != 0,
......@@ -591,23 +591,23 @@ pub const Cfa = union(enum) {
591591 try df_w.writeByte(if (changed_reg) DW.CFA.def_cfa_sf else DW.CFA.def_cfa_offset_sf);
592592 if (changed_reg) try df_w.writeUleb128(reg_off.reg);
593593 try df_w.writeSleb128(
594 @divExact(reg_off.off, wip_nav.dwarf.frame.header.data_alignment_factor),
594 @divExact(reg_off.off, wip_func.dwarf.frame.header.data_alignment_factor),
595595 );
596596 }
597 wip_nav.cfi.cfa = reg_off;
597 wip_func.cfi.cfa = reg_off;
598598 },
599599 .def_cfa_expression => |expr| {
600600 try df_w.writeByte(DW.CFA.def_cfa_expression);
601 try wip_nav.dwarf.exprLoc(df_nw, expr);
601 try wip_func.dwarf.exprLoc(df_nw, expr);
602602 },
603603 .expression => |reg_expr| {
604604 try df_w.writeByte(DW.CFA.expression);
605605 try df_w.writeUleb128(reg_expr.reg);
606 try wip_nav.dwarf.exprLoc(df_nw, reg_expr.expr);
606 try wip_func.dwarf.exprLoc(df_nw, reg_expr.expr);
607607 },
608608 .val_offset => |reg_off| {
609609 const factored_off =
610 @divExact(reg_off.off, wip_nav.dwarf.frame.header.data_alignment_factor);
610 @divExact(reg_off.off, wip_func.dwarf.frame.header.data_alignment_factor);
611611 if (std.math.cast(u63, factored_off)) |unsigned_off| {
612612 try df_w.writeByte(DW.CFA.val_offset);
613613 try df_w.writeUleb128(reg_off.reg);
......@@ -621,14 +621,14 @@ pub const Cfa = union(enum) {
621621 .val_expression => |reg_expr| {
622622 try df_w.writeByte(DW.CFA.val_expression);
623623 try df_w.writeUleb128(reg_expr.reg);
624 try wip_nav.dwarf.exprLoc(df_nw, reg_expr.expr);
624 try wip_func.dwarf.exprLoc(df_nw, reg_expr.expr);
625625 },
626626 .escape => |bytes| try df_w.writeAll(bytes),
627627 }
628628 }
629629};
630630
631pub const WipNav = struct {
631pub const WipFunc = struct {
632632 dwarf: *Dwarf,
633633 unit: Unit.Index,
634634 func: InternPool.Index,
......@@ -642,7 +642,7 @@ pub const WipNav = struct {
642642 frame_func_length: struct { offset: usize, size: AddressSize },
643643
644644 pub const Debug = struct {
645 wip_nav: WipNav,
645 wip_func: WipFunc,
646646 pt: Zcu.PerThread,
647647 empty: bool,
648648 blocks: std.ArrayList(struct {
......@@ -659,27 +659,26 @@ pub const WipNav = struct {
659659 debug.line_writer.deinit();
660660 debug.info_writer.deinit();
661661 debug.blocks.deinit(gpa);
662 debug.wip_nav.deinit();
662 debug.wip_func.deinit();
663663 debug.* = undefined;
664664 }
665665
666666 pub fn genDebugFrame(debug: *Debug, loc: u32, cfa: Cfa) link.Error!void {
667 return debug.wip_nav.genDebugFrame(loc, cfa);
667 return debug.wip_func.genDebugFrame(loc, cfa);
668668 }
669669
670 pub fn startFuncDebugInfo(debug: *Debug) link.Error!void {
671 assert(debug.wip_nav.func != .none);
672 debug.startFuncDebugInfoInner() catch |err| switch (err) {
673 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
670 pub fn startDebugInfo(debug: *Debug) link.Error!void {
671 debug.startDebugInfoInner() catch |err| switch (err) {
674672 else => |e| return e,
673 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
675674 };
676675 }
677 fn startFuncDebugInfoInner(debug: *Debug) link.EmitError!void {
678 const dwarf = debug.wip_nav.dwarf;
676 fn startDebugInfoInner(debug: *Debug) link.EmitError!void {
677 const dwarf = debug.wip_func.dwarf;
679678 const pt = debug.pt;
680679 const zcu = pt.zcu;
681680 const ip = &zcu.intern_pool;
682 const func = zcu.funcInfo(debug.wip_nav.func);
681 const func = zcu.funcInfo(debug.wip_func.func);
683682 const nav = ip.getNav(func.owner_nav);
684683 const func_type = ip.indexToKey(func.ty).func_type;
685684 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
......@@ -702,7 +701,7 @@ pub const WipNav = struct {
702701 .@"extern", .@"export" => nav.name,
703702 }.toSlice(ip));
704703 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));
705 try dwarf.addrSym(di_nw, debug.wip_nav.func_si, 0);
704 try dwarf.addrSym(di_nw, debug.wip_func.func_si, 0);
706705 debug.info_func_length_offset = di_w.end;
707706 try di_w.writeInt(u32, undefined, dwarf.endian);
708707 try di_w.writeUleb128(
......@@ -713,17 +712,16 @@ pub const WipNav = struct {
713712 }
714713
715714 pub fn startDebugLine(debug: *Debug) link.Error!void {
716 assert(debug.wip_nav.func != .none);
717715 debug.startDebugLineInner() catch |err| switch (err) {
718 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),
719716 else => |e| return e,
717 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
720718 };
721719 }
722720 fn startDebugLineInner(debug: *Debug) link.EmitError!void {
723 const dwarf = debug.wip_nav.dwarf;
721 const dwarf = debug.wip_func.dwarf;
724722 const zcu = debug.pt.zcu;
725723 const ip = &zcu.intern_pool;
726 const func = zcu.funcInfo(debug.wip_nav.func);
724 const func = zcu.funcInfo(debug.wip_func.func);
727725 const inst_info = ip.getNav(func.owner_nav).srcInst(ip).resolveFull(ip).?;
728726 const zf = zcu.fileByIndex(inst_info.file);
729727 const decl = zf.zir.?.getDeclaration(inst_info.inst);
......@@ -742,7 +740,7 @@ pub const WipNav = struct {
742740 } else {
743741 try dl_w.writeUleb128(1 + @backingInt(dwarf.address_size));
744742 try dl_w.writeByte(DW.LNE.set_address);
745 try dwarf.addrSym(dl_nw, debug.wip_nav.func_si, 0);
743 try dwarf.addrSym(dl_nw, debug.wip_func.func_si, 0);
746744
747745 const ui = dwarf.getUnit(zf.mod.?);
748746 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, inst_info.file);
......@@ -756,20 +754,19 @@ pub const WipNav = struct {
756754 }
757755 }
758756
759 pub fn finishFunc(debug: *Debug, func_length: u64) link.Error!void {
760 assert(debug.wip_nav.func != .none);
757 pub fn finish(debug: *Debug, func_length: u64) link.Error!void {
761758 const di_nw = &debug.info_writer;
762759 debug.finishDebugInfo(func_length) catch |err| switch (err) {
763 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(di_nw),
764760 else => |e| return e,
761 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(di_nw),
765762 };
766763 debug.finishDebugLine() catch |err| switch (err) {
767 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(di_nw),
768764 else => |e| return e,
765 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(di_nw),
769766 };
770767 }
771768 fn finishDebugInfo(debug: *Debug, func_length: u64) link.EmitError!void {
772 const dwarf = debug.wip_nav.dwarf;
769 const dwarf = debug.wip_func.dwarf;
773770 const di_nw = &debug.info_writer;
774771 const di_w = &di_nw.interface;
775772 std.mem.writeInt(
......@@ -799,8 +796,8 @@ pub const WipNav = struct {
799796 loc: Loc,
800797 ) link.Error!void {
801798 return debug.genLocalVarDebugInfoInner(tag, opt_name, ty, loc) catch |err| switch (err) {
802 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
803799 else => |e| e,
800 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
804801 };
805802 }
806803 fn genLocalVarDebugInfoInner(
......@@ -810,8 +807,7 @@ pub const WipNav = struct {
810807 ty: Type,
811808 loc: Loc,
812809 ) link.EmitError!void {
813 assert(debug.wip_nav.func != .none);
814 const dwarf = debug.wip_nav.dwarf;
810 const dwarf = debug.wip_func.dwarf;
815811 const di_nw = &debug.info_writer;
816812 try dwarf.abbrevCode(di_nw, switch (tag) {
817813 .arg => if (opt_name) |_| .arg else .unnamed_arg,
......@@ -831,8 +827,8 @@ pub const WipNav = struct {
831827 val: Value,
832828 ) link.Error!void {
833829 return debug.genLocalConstDebugInfoInner(tag, opt_name, val) catch |err| switch (err) {
834 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
835830 else => |e| e,
831 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
836832 };
837833 }
838834 fn genLocalConstDebugInfoInner(
......@@ -841,8 +837,7 @@ pub const WipNav = struct {
841837 opt_name: ?[]const u8,
842838 val: Value,
843839 ) link.EmitError!void {
844 assert(debug.wip_nav.func != .none);
845 const dwarf = debug.wip_nav.dwarf;
840 const dwarf = debug.wip_func.dwarf;
846841 const pt = debug.pt;
847842 const zcu = debug.pt.zcu;
848843 const ty = val.typeOf(zcu);
......@@ -879,13 +874,12 @@ pub const WipNav = struct {
879874
880875 pub fn genVarArgsDebugInfo(debug: *Debug) link.Error!void {
881876 return debug.genVarArgsDebugInfoInner() catch |err| switch (err) {
882 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
883877 else => |e| e,
878 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
884879 };
885880 }
886881 fn genVarArgsDebugInfoInner(debug: *Debug) link.EmitError!void {
887 assert(debug.wip_nav.func != .none);
888 try debug.wip_nav.dwarf.abbrevCode(&debug.info_writer, .is_var_args);
882 try debug.wip_func.dwarf.abbrevCode(&debug.info_writer, .is_var_args);
889883 debug.empty = false;
890884 }
891885
......@@ -896,7 +890,7 @@ pub const WipNav = struct {
896890 end: bool,
897891 ) link.Error!void {
898892 return debug.advanceLineAndPcInner(delta_line, delta_pc, end) catch |err| switch (err) {
899 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),
893 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
900894 };
901895 }
902896 fn advanceLineAndPcInner(
......@@ -907,7 +901,7 @@ pub const WipNav = struct {
907901 ) std.Io.Writer.Error!void {
908902 const dl_w = &debug.line_writer.interface;
909903
910 const header = debug.wip_nav.dwarf.debug_line.header;
904 const header = debug.wip_func.dwarf.debug_line.header;
911905 assert(header.maximum_operations_per_instruction == 1);
912906 const delta_op: u64 = 0;
913907
......@@ -951,7 +945,7 @@ pub const WipNav = struct {
951945
952946 pub fn setColumn(debug: *Debug, column: u32) link.Error!void {
953947 return debug.setColumnInner(column) catch |err| switch (err) {
954 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),
948 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
955949 };
956950 }
957951 fn setColumnInner(debug: *Debug, column: u32) std.Io.Writer.Error!void {
......@@ -962,7 +956,7 @@ pub const WipNav = struct {
962956
963957 pub fn negateStmt(debug: *Debug) link.Error!void {
964958 return debug.negateStmtInner() catch |err| switch (err) {
965 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),
959 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
966960 };
967961 }
968962 fn negateStmtInner(debug: *Debug) std.Io.Writer.Error!void {
......@@ -971,7 +965,7 @@ pub const WipNav = struct {
971965
972966 pub fn setPrologueEnd(debug: *Debug) link.Error!void {
973967 return debug.setPrologueEndInner() catch |err| switch (err) {
974 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),
968 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
975969 };
976970 }
977971 fn setPrologueEndInner(debug: *Debug) std.Io.Writer.Error!void {
......@@ -980,7 +974,7 @@ pub const WipNav = struct {
980974
981975 pub fn setEpilogueBegin(debug: *Debug) link.Error!void {
982976 return debug.setEpilogueBeginInner() catch |err| switch (err) {
983 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),
977 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
984978 };
985979 }
986980 fn setEpilogueBeginInner(debug: *Debug) std.Io.Writer.Error!void {
......@@ -989,12 +983,12 @@ pub const WipNav = struct {
989983
990984 pub fn enterBlock(debug: *Debug, code_off: usize) link.Error!void {
991985 return debug.enterBlockInner(code_off) catch |err| switch (err) {
992 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
993986 else => |e| e,
987 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
994988 };
995989 }
996990 fn enterBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {
997 const dwarf = debug.wip_nav.dwarf;
991 const dwarf = debug.wip_func.dwarf;
998992 const block = try debug.blocks.addOne(dwarf.lf.comp.gpa);
999993
1000994 const di_nw = &debug.info_writer;
......@@ -1002,7 +996,7 @@ pub const WipNav = struct {
1002996 block.abbrev_code = @intCast(di_w.end);
1003997 try dwarf.abbrevCode(di_nw, .block);
1004998 block.low_pc_off = code_off;
1005 try dwarf.addrSym(di_nw, debug.wip_nav.func_si, code_off);
999 try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_off);
10061000 block.high_pc = @intCast(di_w.end);
10071001 try di_w.writeInt(u32, 0, dwarf.endian);
10081002 debug.empty = true;
......@@ -1010,12 +1004,12 @@ pub const WipNav = struct {
10101004
10111005 pub fn leaveBlock(debug: *Debug, code_off: usize) link.Error!void {
10121006 return debug.leaveBlockInner(code_off) catch |err| switch (err) {
1013 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
10141007 else => |e| e,
1008 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
10151009 };
10161010 }
10171011 fn leaveBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {
1018 const dwarf = debug.wip_nav.dwarf;
1012 const dwarf = debug.wip_func.dwarf;
10191013 const block = debug.blocks.pop().?;
10201014
10211015 const di_nw = &debug.info_writer;
......@@ -1043,8 +1037,8 @@ pub const WipNav = struct {
10431037 column: u32,
10441038 ) link.Error!void {
10451039 return debug.enterInlineFuncInner(func, code_off, line, column) catch |err| switch (err) {
1046 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
10471040 else => |e| e,
1041 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
10481042 };
10491043 }
10501044 fn enterInlineFuncInner(
......@@ -1054,22 +1048,23 @@ pub const WipNav = struct {
10541048 line: u32,
10551049 column: u32,
10561050 ) link.EmitError!void {
1057 const dwarf = debug.wip_nav.dwarf;
1058 const zcu = debug.pt.zcu;
1051 const dwarf = debug.wip_func.dwarf;
1052 const pt = debug.pt;
1053 const zcu = pt.zcu;
10591054 const block = try debug.blocks.addOne(zcu.gpa);
10601055
10611056 const di_nw = &debug.info_writer;
10621057 const di_w = &di_nw.interface;
10631058 block.abbrev_code = @intCast(di_w.end);
10641059 try dwarf.abbrevCode(di_nw, .inlined_func);
1065 try debug.refFunc(func);
1060 try dwarf.refConst(pt, di_nw, .fromInterned(func));
10661061 try di_w.writeUleb128((if (zcu.comp.config.incremental)
10671062 0
10681063 else
1069 zcu.navSrcLine(zcu.funcInfo(debug.wip_nav.func).owner_nav) + 1) + line);
1064 zcu.navSrcLine(zcu.funcInfo(debug.wip_func.func).owner_nav) + 1) + line);
10701065 try di_w.writeUleb128(column + 1);
10711066 block.low_pc_off = code_off;
1072 try dwarf.addrSym(di_nw, debug.wip_nav.func_si, code_off);
1067 try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_off);
10731068 block.high_pc = @intCast(di_w.end);
10741069 try di_w.writeInt(u32, 0, dwarf.endian);
10751070 try debug.setInlineFunc(func);
......@@ -1078,8 +1073,8 @@ pub const WipNav = struct {
10781073
10791074 pub fn leaveInlineFunc(debug: *Debug, func: InternPool.Index, code_off: usize) link.Error!void {
10801075 return debug.leaveInlineFuncInner(func, code_off) catch |err| switch (err) {
1081 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
10821076 else => |e| e,
1077 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
10831078 };
10841079 }
10851080 fn leaveInlineFuncInner(
......@@ -1087,7 +1082,7 @@ pub const WipNav = struct {
10871082 func: InternPool.Index,
10881083 code_off: usize,
10891084 ) link.EmitError!void {
1090 const dwarf = debug.wip_nav.dwarf;
1085 const dwarf = debug.wip_func.dwarf;
10911086 const block = debug.blocks.pop().?;
10921087
10931088 const di_nw = &debug.info_writer;
......@@ -1110,15 +1105,15 @@ pub const WipNav = struct {
11101105
11111106 pub fn setInlineFunc(debug: *Debug, func: InternPool.Index) link.Error!void {
11121107 return debug.setInlineFuncInner(func) catch |err| switch (err) {
1113 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),
11141108 else => |e| e,
1109 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
11151110 };
11161111 }
11171112 fn setInlineFuncInner(debug: *Debug, func: InternPool.Index) link.EmitError!void {
11181113 const zcu = debug.pt.zcu;
11191114 const ip = &zcu.intern_pool;
1120 const dwarf = debug.wip_nav.dwarf;
1121 if (debug.wip_nav.func == func) return;
1115 const dwarf = debug.wip_func.dwarf;
1116 if (debug.wip_func.func == func) return;
11221117
11231118 const dl_nw = &debug.line_writer;
11241119 const dl_w = &dl_nw.interface;
......@@ -1132,7 +1127,7 @@ pub const WipNav = struct {
11321127 return;
11331128 }
11341129
1135 const old_owner_nav = zcu.funcInfo(debug.wip_nav.func).owner_nav;
1130 const old_owner_nav = zcu.funcInfo(debug.wip_func.func).owner_nav;
11361131 const old_inst_info = ip.getNav(old_owner_nav).srcInst(ip).resolveFull(ip).?;
11371132 const old_zf = zcu.fileByIndex(old_inst_info.file);
11381133 const new_inst_info = ip.getNav(new_owner_nav).srcInst(ip).resolveFull(ip).?;
......@@ -1140,7 +1135,7 @@ pub const WipNav = struct {
11401135 if (old_inst_info.file != new_inst_info.file) {
11411136 const new_ui = dwarf.getUnit(new_zf.mod.?);
11421137 _, const new_fi =
1143 try debug.wip_nav.unit.get(dwarf).getFile(zcu.gpa, new_ui, new_inst_info.file);
1138 try debug.wip_func.unit.get(dwarf).getFile(zcu.gpa, new_ui, new_inst_info.file);
11441139
11451140 try dl_w.writeByte(DW.LNS.set_file);
11461141 try dl_w.writeUleb128(@backingInt(new_fi));
......@@ -1153,38 +1148,27 @@ pub const WipNav = struct {
11531148 try dl_w.writeSleb128(new_src_line - old_src_line);
11541149 }
11551150
1156 debug.wip_nav.func = func;
1157 }
1158
1159 fn refFunc(debug: *Debug, func: InternPool.Index) link.EmitError!void {
1160 const dwarf = debug.wip_nav.dwarf;
1161 const fi = try dwarf.getFunc(debug.pt.zcu.funcInfo(func).owner_nav);
1162 try debug.wip_nav.dwarf.secOffset(
1163 &debug.info_writer,
1164 fi.get(dwarf).debug_info_ni.unwrap().?,
1165 0,
1166 );
1151 debug.wip_func.func = func;
11671152 }
11681153 };
11691154
1170 pub fn deinit(wip_nav: *WipNav) void {
1171 wip_nav.fde_writer.deinit();
1172 wip_nav.* = undefined;
1155 pub fn deinit(wip_func: *WipFunc) void {
1156 wip_func.fde_writer.deinit();
1157 wip_func.* = undefined;
11731158 }
11741159
1175 pub fn genDebugFrameHeader(wip_nav: *WipNav) link.Error!void {
1176 wip_nav.genDebugFrameHeaderInner() catch |err| switch (err) {
1177 error.WriteFailed => return wip_nav.dwarf.reportWriteError(&wip_nav.fde_writer),
1160 pub fn genDebugFrameHeader(wip_func: *WipFunc) link.Error!void {
1161 wip_func.genDebugFrameHeaderInner() catch |err| switch (err) {
11781162 else => |e| return e,
1163 error.WriteFailed => return wip_func.dwarf.reportWriteError(&wip_func.fde_writer),
11791164 };
11801165 }
1181 fn genDebugFrameHeaderInner(wip_nav: *WipNav) link.EmitError!void {
1182 assert(wip_nav.func != .none);
1183 const dwarf = wip_nav.dwarf;
1184 const df_nw = &wip_nav.fde_writer;
1166 fn genDebugFrameHeaderInner(wip_func: *WipFunc) link.EmitError!void {
1167 const dwarf = wip_func.dwarf;
1168 const df_nw = &wip_func.fde_writer;
11851169 const df_w = &df_nw.interface;
11861170 try dwarf.genUnitLength(df_w);
1187 switch (wip_nav.frame_format) {
1171 switch (wip_func.frame_format) {
11881172 .eh_frame => {
11891173 try df_w.writeInt(u32, undefined, dwarf.endian);
11901174 {
......@@ -1193,51 +1177,50 @@ pub const WipNav = struct {
11931177 if (dwarf.lf.cast(.elf2)) |elf| try elf.addReloc(
11941178 @bitCast(df_nw.ni),
11951179 offset,
1196 wip_nav.func_si,
1180 wip_func.func_si,
11971181 0,
11981182 .rel32(elf),
11991183 ) else unreachable;
12001184 }
1201 wip_nav.frame_func_length = .{ .offset = df_w.end, .size = .@"32" };
1185 wip_func.frame_func_length = .{ .offset = df_w.end, .size = .@"32" };
12021186 try df_w.writeInt(u32, undefined, dwarf.endian);
12031187 try df_w.writeUleb128(0);
12041188 },
12051189 .debug_frame => {
1206 try dwarf.secOffset(df_nw, wip_nav.unit.get(dwarf).cie_ni.unwrap().?, 0);
1207 try dwarf.addrSym(df_nw, wip_nav.func_si, 0);
1208 wip_nav.frame_func_length = .{ .offset = df_w.end, .size = dwarf.address_size };
1190 try dwarf.secOffset(df_nw, wip_func.unit.get(dwarf).cie_ni.unwrap().?, 0);
1191 try dwarf.addrSym(df_nw, wip_func.func_si, 0);
1192 wip_func.frame_func_length = .{ .offset = df_w.end, .size = dwarf.address_size };
12091193 try dwarf.addrPlaceholder(df_w);
12101194 },
12111195 }
12121196 }
12131197
1214 pub fn genDebugFrame(wip_nav: *WipNav, loc: u32, cfa: Cfa) link.Error!void {
1215 return wip_nav.genDebugFrameInner(loc, cfa) catch |err| switch (err) {
1216 error.WriteFailed => return wip_nav.dwarf.reportWriteError(&wip_nav.fde_writer),
1198 pub fn genDebugFrame(wip_func: *WipFunc, loc: u32, cfa: Cfa) link.Error!void {
1199 return wip_func.genDebugFrameInner(loc, cfa) catch |err| switch (err) {
12171200 else => |e| return e,
1201 error.WriteFailed => return wip_func.dwarf.reportWriteError(&wip_func.fde_writer),
12181202 };
12191203 }
1220 fn genDebugFrameInner(wip_nav: *WipNav, loc: u32, cfa: Cfa) link.EmitError!void {
1221 assert(wip_nav.func != .none);
1204 fn genDebugFrameInner(wip_func: *WipFunc, loc: u32, cfa: Cfa) link.EmitError!void {
12221205 const loc_cfa: Cfa = .{ .advance_loc = loc };
1223 try loc_cfa.write(wip_nav);
1224 try cfa.write(wip_nav);
1206 try loc_cfa.write(wip_func);
1207 try cfa.write(wip_func);
12251208 }
12261209
1227 pub fn finishDebugFrameFde(wip_nav: *WipNav, func_length: u64) void {
1228 const dwarf = wip_nav.dwarf;
1229 const df_w = &wip_nav.fde_writer.interface;
1230 switch (wip_nav.frame_func_length.size) {
1210 pub fn finishDebugFrameFde(wip_func: *WipFunc, func_length: u64) void {
1211 const dwarf = wip_func.dwarf;
1212 const df_w = &wip_func.fde_writer.interface;
1213 switch (wip_func.frame_func_length.size) {
12311214 _ => unreachable,
12321215 .@"32" => std.mem.writeInt(
12331216 u32,
1234 df_w.buffered()[wip_nav.frame_func_length.offset..][0..4],
1217 df_w.buffered()[wip_func.frame_func_length.offset..][0..4],
12351218 @intCast(func_length),
12361219 dwarf.endian,
12371220 ),
12381221 .@"64" => std.mem.writeInt(
12391222 u64,
1240 df_w.buffered()[wip_nav.frame_func_length.offset..][0..8],
1223 df_w.buffered()[wip_func.frame_func_length.offset..][0..8],
12411224 func_length,
12421225 dwarf.endian,
12431226 ),
......@@ -1966,6 +1949,197 @@ pub fn genDebugRnglists(
19661949 try dr_w.writeByte(DW.RLE.end_of_list);
19671950}
19681951
1952pub fn updateExtern(
1953 dwarf: *Dwarf,
1954 pt: Zcu.PerThread,
1955 di_nw: *link.MappedFile.Node.Writer,
1956 arch: std.Target.Cpu.Arch,
1957 si: link.File.SymbolId,
1958 global: InternPool.Nav.Index,
1959) link.Error!void {
1960 dwarf.updateExternInner(pt, di_nw, arch, si, global) catch |err| switch (err) {
1961 else => |e| return e,
1962 error.WriteFailed => return dwarf.reportWriteError(di_nw),
1963 };
1964}
1965fn updateExternInner(
1966 dwarf: *Dwarf,
1967 pt: Zcu.PerThread,
1968 di_nw: *link.MappedFile.Node.Writer,
1969 arch: std.Target.Cpu.Arch,
1970 si: link.File.SymbolId,
1971 global: InternPool.Nav.Index,
1972) link.EmitError!void {
1973 const zcu = pt.zcu;
1974 const ip = &zcu.intern_pool;
1975 const nav = ip.getNav(global);
1976 log.debug("updateExtern({f})", .{nav.fqn.fmt(ip)});
1977 const nav_align, const nav_const, const nav_threadlocal, const nav_extern = nav_resolved: {
1978 const nav_resolved = nav.resolved.?;
1979 break :nav_resolved .{
1980 nav_resolved.@"align",
1981 nav_resolved.@"const",
1982 nav_resolved.@"threadlocal",
1983 ip.indexToKey(nav_resolved.value).@"extern",
1984 };
1985 };
1986 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
1987 const decl = switch (nav_extern.source) {
1988 .builtin => undefined,
1989 .syntax => zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst),
1990 };
1991 const maybe_func_type = switch (ip.indexToKey(nav_extern.ty)) {
1992 .func_type => |func_type| func_type,
1993 else => null,
1994 };
1995 const is_empty = if (maybe_func_type) |func_type| func_type.param_types.len == 0 and
1996 !func_type.is_var_args else undefined;
1997 const di_w = &di_nw.interface;
1998 switch (nav_extern.source) {
1999 .builtin => {
2000 try dwarf.abbrevCode(di_nw, if (maybe_func_type) |_|
2001 if (is_empty) .builtin_extern_empty_func else .builtin_extern_func
2002 else
2003 .builtin_extern_var);
2004 try dwarf.refType(pt, di_nw, .fromInterned(zcu.fileRootType(inst_info.file)));
2005 },
2006 .syntax => if (maybe_func_type) |_| {
2007 try dwarf.abbrevCode(
2008 di_nw,
2009 if (is_empty) .decl_extern_empty_func else .decl_extern_func,
2010 );
2011 try dwarf.refType(pt, di_nw, .fromInterned(zcu.fileRootType(inst_info.file)));
2012 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2013 try di_w.writeUleb128(decl.src_column + 1);
2014 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2015 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
2016 } else {
2017 try dwarf.abbrevCode(di_nw, .decl_var);
2018 try dwarf.refType(pt, di_nw, .fromInterned(zcu.fileRootType(inst_info.file)));
2019 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2020 try di_w.writeUleb128(decl.src_column + 1);
2021 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2022 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
2023 },
2024 }
2025 try dwarf.strp(&dwarf.debug_str, di_nw, nav_extern.name.toSlice(ip));
2026 if (maybe_func_type) |func_type| {
2027 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));
2028 try dwarf.addrSym(di_nw, si, 0);
2029 try di_w.writeByte(@intFromBool(Type.fromInterned(func_type.return_type).isNoReturn(zcu)));
2030 for (func_type.param_types.get(ip)) |param_type| {
2031 try dwarf.abbrevCode(di_nw, .extern_param);
2032 try dwarf.refType(pt, di_nw, .fromInterned(param_type));
2033 }
2034 if (func_type.is_var_args) try dwarf.abbrevCode(di_nw, .is_var_args);
2035 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2036 } else {
2037 const addr: Loc = .{ .addr_reloc = si };
2038 const loc: Loc = if (nav_threadlocal) switch (arch) {
2039 .x86_64 => .{ .form_tls_address = &addr },
2040 else => unreachable,
2041 } else addr;
2042 const type_offset = di_w.end;
2043 if (nav_const)
2044 try dwarf.secOffsetPlaceholder(di_w)
2045 else
2046 try dwarf.refType(pt, di_nw, .fromInterned(nav_extern.ty));
2047 try dwarf.exprLoc(di_nw, loc);
2048 try di_w.writeUleb128(nav_align.toByteUnits() orelse
2049 Type.fromInterned(nav_extern.ty).abiAlignment(zcu).toByteUnits().?);
2050 switch (nav_extern.source) {
2051 .builtin => {},
2052 .syntax => try di_w.writeByte(@intFromBool(decl.linkage != .normal)),
2053 }
2054 if (nav_const) {
2055 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2056 try dwarf.abbrevCode(di_nw, .is_const);
2057 try dwarf.refType(pt, di_nw, .fromInterned(nav_extern.ty));
2058 }
2059 }
2060 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
2061}
2062
2063pub fn updateGlobal(
2064 dwarf: *Dwarf,
2065 pt: Zcu.PerThread,
2066 di_nw: *link.MappedFile.Node.Writer,
2067 arch: std.Target.Cpu.Arch,
2068 si: link.File.SymbolId,
2069 global: InternPool.Nav.Index,
2070) link.Error!void {
2071 const ip = &pt.zcu.intern_pool;
2072 log.debug("updateGlobal({f})", .{ip.getNav(global).fqn.fmt(ip)});
2073 dwarf.updateGlobalInner(pt, di_nw, arch, si, global) catch |err| switch (err) {
2074 else => |e| return e,
2075 error.WriteFailed => return dwarf.reportWriteError(di_nw),
2076 };
2077}
2078fn updateGlobalInner(
2079 dwarf: *Dwarf,
2080 pt: Zcu.PerThread,
2081 di_nw: *link.MappedFile.Node.Writer,
2082 arch: std.Target.Cpu.Arch,
2083 si: link.File.SymbolId,
2084 global: InternPool.Nav.Index,
2085) link.EmitError!void {
2086 const zcu = pt.zcu;
2087 const ip = &zcu.intern_pool;
2088 const nav = ip.getNav(global);
2089 const nav_ty: Type, const nav_align, const nav_const, const nav_threadlocal = nav_resolved: {
2090 const nav_resolved = nav.resolved.?;
2091 break :nav_resolved .{
2092 .fromInterned(nav_resolved.type),
2093 nav_resolved.@"align",
2094 nav_resolved.@"const",
2095 nav_resolved.@"threadlocal",
2096 };
2097 };
2098 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
2099 const decl = zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst);
2100 switch (decl.kind) {
2101 .unnamed_test, .@"test", .decltest, .@"comptime" => unreachable,
2102 .@"const" => assert(nav_const),
2103 .@"var" => assert(!nav_const),
2104 }
2105 const parent_ty: Type = .fromInterned(ip.namespacePtr(nav.analysis.?.namespace).owner_type);
2106 const di_w = &di_nw.interface;
2107 if (parent_ty.getCaptures(zcu).len > 0) {
2108 try dwarf.abbrevCode(di_nw, .decl_instance_var);
2109 try dwarf.refType(pt, di_nw, parent_ty);
2110 try dwarf.secOffset(di_nw, try dwarf.getGlobalDecl(pt, global), 0);
2111 } else {
2112 const parent_ni = try dwarf.getConstDecl(pt, parent_ty.toIntern());
2113 try dwarf.abbrevCode(di_nw, .decl_var);
2114 try dwarf.secOffset(di_nw, parent_ni, 0);
2115 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2116 try di_w.writeUleb128(decl.src_column + 1);
2117 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2118 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
2119 }
2120 try dwarf.strp(&dwarf.debug_str, di_nw, switch (decl.linkage) {
2121 .normal => nav.fqn,
2122 .@"extern" => unreachable,
2123 .@"export" => nav.name,
2124 }.toSlice(ip));
2125 const addr: Loc = .{ .addr_reloc = si };
2126 const loc: Loc = if (nav_threadlocal) switch (arch) {
2127 .x86_64 => .{ .form_tls_address = &addr },
2128 else => unreachable,
2129 } else addr;
2130 const type_offset = di_w.end;
2131 if (nav_const) try dwarf.secOffsetPlaceholder(di_w) else try dwarf.refType(pt, di_nw, nav_ty);
2132 try dwarf.exprLoc(di_nw, loc);
2133 try di_w.writeUleb128(nav_align.toByteUnits() orelse nav_ty.abiAlignment(zcu).toByteUnits().?);
2134 try di_w.writeByte(@intFromBool(decl.linkage != .normal));
2135 if (nav_const) {
2136 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2137 try dwarf.abbrevCode(di_nw, .is_const);
2138 try dwarf.refType(pt, di_nw, nav_ty);
2139 }
2140 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
2141}
2142
19692143pub fn updateComptimeGlobal(
19702144 dwarf: *Dwarf,
19712145 pt: Zcu.PerThread,
......@@ -2010,30 +2184,30 @@ pub fn updateComptimeGlobal(
20102184 .aggregate,
20112185 .un,
20122186 .bitpack,
2013 => try dwarf.genGlobal(pt, global, &decl),
2187 => try dwarf.genComptimeGlobal(pt, global, &decl),
20142188 .struct_type => {
20152189 const loaded_struct = ip.loadStructType(nav_val.toIntern());
20162190 if (global.toOptional() == loaded_struct.name_nav) {
20172191 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
2018 } else try dwarf.genGlobal(pt, global, &decl);
2192 } else try dwarf.genComptimeGlobal(pt, global, &decl);
20192193 },
20202194 .enum_type => {
20212195 const loaded_enum = ip.loadEnumType(nav_val.toIntern());
20222196 if (global.toOptional() == loaded_enum.name_nav) {
20232197 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
2024 } else try dwarf.genGlobal(pt, global, &decl);
2198 } else try dwarf.genComptimeGlobal(pt, global, &decl);
20252199 },
20262200 .union_type => {
20272201 const loaded_union = ip.loadUnionType(nav_val.toIntern());
20282202 if (global.toOptional() == loaded_union.name_nav) {
20292203 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
2030 } else try dwarf.genGlobal(pt, global, &decl);
2204 } else try dwarf.genComptimeGlobal(pt, global, &decl);
20312205 },
20322206 .opaque_type => {
20332207 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());
20342208 if (global.toOptional() == loaded_opaque.name_nav) {
20352209 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
2036 } else try dwarf.genGlobal(pt, global, &decl);
2210 } else try dwarf.genComptimeGlobal(pt, global, &decl);
20372211 },
20382212 .@"extern" => unreachable,
20392213 .func => |func| if (func.owner_nav == global and func.generic_owner == .none) {
......@@ -2042,26 +2216,28 @@ pub fn updateComptimeGlobal(
20422216 .memoized_call => unreachable, // not a value
20432217 }
20442218}
2045fn genGlobal(
2219fn genComptimeGlobal(
20462220 dwarf: *Dwarf,
20472221 pt: Zcu.PerThread,
20482222 global: InternPool.Nav.Index,
20492223 decl: *const std.zig.Zir.Inst.Declaration.Unwrapped,
20502224) link.Error!void {
2225 const gpa = pt.zcu.gpa;
20512226 const gi = try dwarf.getGlobal(global);
20522227 const debug_info_ni = gi.get(dwarf).debug_info_ni.unwrap().?;
20532228 var di_nw: link.MappedFile.Node.Writer = undefined;
20542229 if (dwarf.lf.cast(.elf2)) |elf| {
2055 debug_info_ni.writer(pt.zcu.gpa, &elf.mf, &di_nw);
2230 try debug_info_ni.moved(gpa, &elf.mf);
2231 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
20562232 elf.resetNodeRelocs(debug_info_ni);
20572233 } else unreachable;
20582234 defer di_nw.deinit();
2059 dwarf.genGlobalInner(pt, &di_nw, global, decl) catch |err| switch (err) {
2060 error.WriteFailed => return dwarf.reportWriteError(&di_nw),
2235 dwarf.genComptimeGlobalInner(pt, &di_nw, global, decl) catch |err| switch (err) {
20612236 else => |e| return e,
2237 error.WriteFailed => return dwarf.reportWriteError(&di_nw),
20622238 };
20632239}
2064fn genGlobalInner(
2240fn genComptimeGlobalInner(
20652241 dwarf: *Dwarf,
20662242 pt: Zcu.PerThread,
20672243 di_nw: *link.MappedFile.Node.Writer,
......@@ -2071,40 +2247,40 @@ fn genGlobalInner(
20712247 const zcu = pt.zcu;
20722248 const ip = &zcu.intern_pool;
20732249 const nav = ip.getNav(global);
2074 const nav_const, const nav_ty: Type, const nav_align, const nav_val: Value = nav_resolved: {
2250 const nav_ty: Type, const nav_align, const nav_const, const nav_val: Value = nav_resolved: {
20752251 const nav_resolved = nav.resolved.?;
20762252 break :nav_resolved .{
2077 nav_resolved.@"const",
20782253 .fromInterned(nav_resolved.type),
20792254 nav_resolved.@"align",
2255 nav_resolved.@"const",
20802256 .fromInterned(nav_resolved.value),
20812257 };
20822258 };
20832259 const nav_class = nav_ty.classify(zcu);
2084 const parent_ty = ip.namespacePtr(nav.analysis.?.namespace).owner_type;
2260 const parent_ty: Type = .fromInterned(ip.namespacePtr(nav.analysis.?.namespace).owner_type);
20852261 const di_w = &di_nw.interface;
2086 if (Type.fromInterned(parent_ty).getCaptures(zcu).len > 0) {
2262 if (parent_ty.getCaptures(zcu).len > 0) {
20872263 try dwarf.abbrevCode(di_nw, switch (nav_ty.toIntern()) {
20882264 .type_type => .decl_instance_type,
2089 else => if (nav_const) switch (nav_class) {
2265 else => switch (nav_class) {
20902266 .no_possible_value, .one_possible_value => .decl_instance_const,
20912267 .runtime => .decl_instance_const_fully_runtime,
20922268 .partially_comptime => .decl_instance_const_partially_comptime,
20932269 .fully_comptime => .decl_instance_const_fully_comptime,
2094 } else .decl_instance_var,
2270 },
20952271 });
2096 try dwarf.refType(pt, di_nw, .fromInterned(parent_ty));
2272 try dwarf.refType(pt, di_nw, parent_ty);
20972273 try dwarf.secOffset(di_nw, try dwarf.getGlobalDecl(pt, global), 0);
20982274 } else {
2099 const parent_ni = try dwarf.getConstDecl(pt, parent_ty);
2275 const parent_ni = try dwarf.getConstDecl(pt, parent_ty.toIntern());
21002276 try dwarf.abbrevCode(di_nw, switch (nav_ty.toIntern()) {
21012277 .type_type => .decl_type,
2102 else => if (nav_const) switch (nav_class) {
2278 else => switch (nav_class) {
21032279 .no_possible_value, .one_possible_value => .decl_const,
21042280 .runtime => .decl_const_fully_runtime,
21052281 .partially_comptime => .decl_const_partially_comptime,
21062282 .fully_comptime => .decl_const_fully_comptime,
2107 } else .decl_var,
2283 },
21082284 });
21092285 try dwarf.secOffset(di_nw, parent_ni, 0);
21102286 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
......@@ -2120,16 +2296,16 @@ fn genGlobalInner(
21202296 .@"extern", .@"export" => nav.name,
21212297 }.toSlice(ip));
21222298 const type_offset = di_w.end;
2123 if (nav_const) try dwarf.secOffsetPlaceholder(di_w) else {
2299 if (nav_const)
2300 try dwarf.secOffsetPlaceholder(di_w)
2301 else
21242302 try dwarf.refType(pt, di_nw, nav_ty);
2125 try dwarf.blockConst(pt, di_nw, nav_val);
2126 }
21272303 try di_w.writeUleb128(nav_align.toByteUnits() orelse
21282304 nav_ty.abiAlignment(zcu).toByteUnits().?);
21292305 try di_w.writeByte(@intFromBool(decl.linkage != .normal));
2306 if (nav_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, nav_val);
2307 if (nav_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, nav_val);
21302308 if (nav_const) {
2131 if (nav_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, nav_val);
2132 if (nav_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, nav_val);
21332309 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
21342310 try dwarf.abbrevCode(di_nw, .is_const);
21352311 try dwarf.refType(pt, di_nw, nav_ty);
......@@ -2229,36 +2405,34 @@ fn updateConstInner(
22292405 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
22302406 defer zcu.gpa.free(name);
22312407 try dwarf.abbrevCode(di_nw, switch (ptr_type.sentinel) {
2232 .none => switch (ptr_type.flags.alignment) {
2233 .none => .ptr_type,
2234 else => .ptr_aligned_type,
2235 },
2236 else => switch (ptr_type.flags.alignment) {
2237 .none => .ptr_sentinel_type,
2238 else => .ptr_aligned_sentinel_type,
2239 },
2408 .none => .ptr_type,
2409 else => .ptr_sentinel_type,
22402410 });
22412411 try dwarf.strp(&dwarf.debug_str, di_nw, name);
22422412 switch (ptr_type.sentinel) {
22432413 .none => {},
22442414 else => |sentinel| try dwarf.blockConst(pt, di_nw, .fromInterned(sentinel)),
22452415 }
2246 if (ptr_type.flags.alignment.toByteUnits()) |a| try di_w.writeUleb128(a);
22472416 try di_w.writeByte(@backingInt(ptr_type.flags.address_space));
2248 if (ptr_type.flags.is_const or ptr_type.flags.is_volatile) try dwarf.secOffset(
2249 di_nw,
2250 di_nw.ni,
2251 di_w.end + dwarf.secOffsetSize(),
2252 );
2417 if (ptr_type.flags.alignment.toByteUnits()) |a| {
2418 const type_offset = di_w.end;
2419 try dwarf.secOffsetPlaceholder(di_w);
2420 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2421 try dwarf.abbrevCode(di_nw, .is_aligned);
2422 try di_w.writeUleb128(a);
2423 }
22532424 if (ptr_type.flags.is_const) {
2425 const type_offset = di_w.end;
2426 try dwarf.secOffsetPlaceholder(di_w);
2427 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
22542428 try dwarf.abbrevCode(di_nw, .is_const);
2255 if (ptr_type.flags.is_volatile) try dwarf.secOffset(
2256 di_nw,
2257 di_nw.ni,
2258 di_w.end + dwarf.secOffsetSize(),
2259 );
22602429 }
2261 if (ptr_type.flags.is_volatile) try dwarf.abbrevCode(di_nw, .is_volatile);
2430 if (ptr_type.flags.is_volatile) {
2431 const type_offset = di_w.end;
2432 try dwarf.secOffsetPlaceholder(di_w);
2433 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2434 try dwarf.abbrevCode(di_nw, .is_volatile);
2435 }
22622436 try dwarf.refType(pt, di_nw, .fromInterned(ptr_type.child));
22632437 },
22642438 .slice => {
......@@ -2328,8 +2502,10 @@ fn updateConstInner(
23282502 },
23292503 .unpacked, .error_set, .pointer => {
23302504 try dwarf.abbrevCode(di_nw, .tagged_union);
2331 try dwarf.secOffset(di_nw, di_nw.ni, di_w.end + dwarf.secOffsetSize());
2505 const discr_offset = di_w.end;
2506 try dwarf.secOffsetPlaceholder(di_w);
23322507 {
2508 try dwarf.secOffsetFinish(di_nw, discr_offset, di_nw.ni, di_w.end);
23332509 try dwarf.abbrevCode(di_nw, .generated_field);
23342510 try dwarf.strp(&dwarf.debug_str, di_nw, "has_value");
23352511 switch (opt_repr) {
......@@ -2342,7 +2518,10 @@ fn updateConstInner(
23422518 0);
23432519 },
23442520 .error_set => {
2345 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
2521 try dwarf.refType(pt, di_nw, try pt.intType(
2522 .unsigned,
2523 zcu.errorSetBits(),
2524 ));
23462525 try di_w.writeUleb128(0);
23472526 },
23482527 .pointer => {
......@@ -2404,8 +2583,10 @@ fn updateConstInner(
24042583 }
24052584 {
24062585 try dwarf.abbrevCode(di_nw, .tagged_union);
2407 try dwarf.secOffset(di_nw, di_nw.ni, di_w.end + dwarf.secOffsetSize());
2586 const discr_offset = di_w.end;
2587 try dwarf.secOffsetPlaceholder(di_w);
24082588 {
2589 try dwarf.secOffsetFinish(di_nw, discr_offset, di_nw.ni, di_w.end);
24092590 try dwarf.abbrevCode(di_nw, .generated_field);
24102591 try dwarf.strp(&dwarf.debug_str, di_nw, "is_error");
24112592 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
......@@ -2771,8 +2952,10 @@ fn updateConstInner(
27712952 try dwarf.genCaptures(pt, di_nw, loaded_union.captures);
27722953 if (loaded_union.has_runtime_tag) {
27732954 try dwarf.abbrevCode(di_nw, .tagged_union);
2774 try dwarf.secOffset(di_nw, di_nw.ni, di_w.end + dwarf.secOffsetSize());
2955 const discr_offset = di_w.end;
2956 try dwarf.secOffsetPlaceholder(di_w);
27752957 {
2958 try dwarf.secOffsetFinish(di_nw, discr_offset, di_nw.ni, di_w.end);
27762959 try dwarf.abbrevCode(di_nw, .generated_field);
27772960 try dwarf.strp(&dwarf.debug_str, di_nw, "tag");
27782961 try dwarf.refType(pt, di_nw, .fromInterned(loaded_union.enum_tag_type));
......@@ -4084,8 +4267,11 @@ fn refAbbrevCode(
40844267 @branchHint(.likely);
40854268 return backing_int;
40864269 }
4270 const gpa = dwarf.lf.comp.gpa;
4271 const debug_abbrev_ni = dwarf.debug_abbrev.ni.unwrap().?;
4272 try debug_abbrev_ni.moved(gpa, mf);
40874273 var da_nw: link.MappedFile.Node.Writer = undefined;
4088 dwarf.debug_abbrev.ni.unwrap().?.writer(dwarf.lf.comp.gpa, mf, &da_nw);
4274 debug_abbrev_ni.writer(gpa, mf, &da_nw);
40894275 defer da_nw.deinit();
40904276 dwarf.genDebugAbbrev(&da_nw, abbrev_code) catch |err| switch (err) {
40914277 else => |e| return e,
......@@ -4294,10 +4480,10 @@ fn exprLoc(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, loc: Loc) link.EmitE
42944480fn strp(dwarf: *Dwarf, s: *Str, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
42954481 const comp = dwarf.lf.comp;
42964482 try dwarf.secOffset(nw, s.ni.unwrap().?, s.get(comp.gpa, nw.mf, str) catch |err| switch (err) {
4483 else => |e| return e,
42974484 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
42984485 nw.mf.io_err.?,
42994486 }),
4300 else => |e| return e,
43014487 });
43024488}
43034489
......@@ -4433,8 +4619,6 @@ pub const AbbrevCode = enum {
44334619 decl_instance_func,
44344620 decl_instance_empty_func_generic,
44354621 decl_instance_func_generic,
4436 decl_instance_extern_empty_func,
4437 decl_instance_extern_func,
44384622 // the rest are unrestricted other than empty variants must not be longer
44394623 // than the non-empty variant, and so should appear first
44404624 compile_unit,
......@@ -4462,8 +4646,7 @@ pub const AbbrevCode = enum {
44624646 inferred_error_set_type,
44634647 ptr_type,
44644648 ptr_sentinel_type,
4465 ptr_aligned_type,
4466 ptr_aligned_sentinel_type,
4649 is_aligned,
44674650 is_const,
44684651 is_volatile,
44694652 array_type,
......@@ -4522,7 +4705,7 @@ pub const AbbrevCode = enum {
45224705 comptime_value_elem_runtime,
45234706 comptime_value_elem_comptime,
45244707
4525 const decl_size = uleb128Size(@backingInt(AbbrevCode.decl_instance_extern_func));
4708 const decl_size = uleb128Size(@backingInt(AbbrevCode.decl_func_generic));
45264709 comptime {
45274710 assert(uleb128Size(@backingInt(AbbrevCode.pad_1)) == 1);
45284711 assert(uleb128Size(@backingInt(AbbrevCode.pad_n)) == 1);
......@@ -5142,27 +5325,6 @@ pub const AbbrevCode = enum {
51425325 .{ .type, .ref_addr },
51435326 },
51445327 },
5145 .decl_instance_extern_empty_func = .{
5146 .tag = .subprogram,
5147 .attrs = decl_instance_attrs ++ .{
5148 .{ .linkage_name, .strp },
5149 .{ .type, .ref_addr },
5150 .{ .low_pc, .addr },
5151 .{ .external, .flag_present },
5152 .{ .noreturn, .flag },
5153 },
5154 },
5155 .decl_instance_extern_func = .{
5156 .tag = .subprogram,
5157 .children = true,
5158 .attrs = decl_instance_attrs ++ .{
5159 .{ .linkage_name, .strp },
5160 .{ .type, .ref_addr },
5161 .{ .low_pc, .addr },
5162 .{ .external, .flag_present },
5163 .{ .noreturn, .flag },
5164 },
5165 },
51665328 .compile_unit = .{
51675329 .tag = .compile_unit,
51685330 .children = true,
......@@ -5375,22 +5537,10 @@ pub const AbbrevCode = enum {
53755537 .{ .type, .ref_addr },
53765538 },
53775539 },
5378 .ptr_aligned_type = .{
5379 .tag = .pointer_type,
5380 .attrs = &.{
5381 .{ .name, .strp },
5382 .{ .alignment, .udata },
5383 .{ .address_class, .data1 },
5384 .{ .type, .ref_addr },
5385 },
5386 },
5387 .ptr_aligned_sentinel_type = .{
5388 .tag = .pointer_type,
5540 .is_aligned = .{
5541 .tag = .typedef,
53895542 .attrs = &.{
5390 .{ .name, .strp },
5391 .{ .ZIG_sentinel, .block },
53925543 .{ .alignment, .udata },
5393 .{ .address_class, .data1 },
53945544 .{ .type, .ref_addr },
53955545 },
53965546 },
......@@ -5594,6 +5744,7 @@ pub const AbbrevCode = enum {
55945744 .{ .linkage_name, .strp },
55955745 .{ .type, .ref_addr },
55965746 .{ .location, .exprloc },
5747 .{ .alignment, .udata },
55975748 .{ .external, .flag_present },
55985749 },
55995750 },
src/link/Elf2.zig+92-55
......@@ -5856,10 +5856,11 @@ fn dynsymPtr(elf: *Elf, index: u32) SymPtr {
58565856}
58575857
58585858fn navType(elf: *const Elf, nav_resolved: InternPool.Nav.Resolved) std.elf.STT {
5859 const any_non_single_threaded = elf.base.comp.config.any_non_single_threaded;
5859 const comp = elf.base.comp;
5860 const any_non_single_threaded = comp.config.any_non_single_threaded;
58605861 return if (any_non_single_threaded and nav_resolved.@"threadlocal")
58615862 .TLS
5862 else if (elf.base.comp.zcu.?.intern_pool.isFunctionType(nav_resolved.type))
5863 else if (comp.zcu.?.intern_pool.isFunctionType(nav_resolved.type))
58635864 .FUNC
58645865 else
58655866 .OBJECT;
......@@ -7406,7 +7407,6 @@ fn flushFiles(elf: *Elf) Error!void {
74067407 const debug_line_header_ni = unit.debug_line_header_ni.unwrap().?;
74077408 try debug_line_header_ni.parent(&elf.mf).unwrap().?.nextMoved(gpa, &elf.mf);
74087409 try debug_line_header_ni.moved(gpa, &elf.mf);
7409 try debug_line_header_ni.nextMoved(gpa, &elf.mf);
74107410 var dlh_nw: MappedFile.Node.Writer = undefined;
74117411 debug_line_header_ni.writer(gpa, &elf.mf, &dlh_nw);
74127412 defer dlh_nw.deinit();
......@@ -8632,38 +8632,77 @@ fn updateNavInner(elf: *Elf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index)
86328632 const ip = &zcu.intern_pool;
86338633
86348634 const nav = ip.getNav(nav_index);
8635 if (ip.indexToKey(nav.resolved.?.value) == .@"extern") return;
8636 if (Type.fromInterned(nav.resolved.?.type).hasRuntimeBits(zcu)) {
8637 const nmi = try elf.navMapIndex(zcu, nav_index);
8638 const ni = nmi.symbol(elf).index().ptr(elf).node.unwrap().?;
8635 const mod = zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?;
8636 switch (ip.indexToKey(nav.resolved.?.value)) {
8637 .@"extern" => |@"extern"| {
8638 if (mod.strip or elf.ehdrMachine() != .X86_64) return;
8639 const si = try elf.externSymbol(.{
8640 .name = @"extern".name.toSlice(ip),
8641 .lib_name = @"extern".lib_name.toSlice(ip),
8642 .type = elf.navType(nav.resolved.?),
8643 .linkage = @"extern".linkage,
8644 .visibility = @"extern".visibility,
8645 });
8646 const dwarf_gi = try elf.dwarf.getGlobal(nav_index);
8647 const dwarf_global = dwarf_gi.get(&elf.dwarf);
8648 const debug_info_ni = dwarf_global.debug_info_ni.unwrap().?;
8649 try debug_info_ni.moved(gpa, &elf.mf);
8650 var di_nw: MappedFile.Node.Writer = undefined;
8651 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
8652 defer di_nw.deinit();
8653 elf.resetNodeRelocs(debug_info_ni);
8654 try elf.dwarf.updateExtern(pt, &di_nw, switch (elf.ehdrMachine()) {
8655 else => unreachable,
8656 .X86_64 => .x86_64,
8657 }, si, nav_index);
8658 },
8659 else => if (Type.fromInterned(nav.resolved.?.type).hasRuntimeBits(zcu)) {
8660 const nmi = try elf.navMapIndex(zcu, nav_index);
8661 const lsi = nmi.symbol(elf);
8662 const ni = lsi.index().ptr(elf).node.unwrap().?;
86398663
8640 // Ensure the NAV is marked as moved so that once we're done, `flushMoved` will eventually be
8641 // called to apply the NAV's new relocations.
8642 try ni.moved(gpa, &elf.mf);
8664 // Ensure the NAV is marked as moved so that once we're done, `flushMoved`
8665 // will eventually be called to apply the NAV's new relocations.
8666 try ni.moved(gpa, &elf.mf);
86438667
8644 {
8645 var nw: MappedFile.Node.Writer = undefined;
8646 ni.writer(gpa, &elf.mf, &nw);
8647 defer nw.deinit();
8648 elf.resetNodeRelocs(ni);
8649 codegen.generateSymbol(
8650 &elf.base,
8651 pt,
8652 .fromInterned(nav.resolved.?.value),
8653 &nw.interface,
8654 .{ .atom_index = Node.toAtom(ni) },
8655 ) catch |err| switch (err) {
8656 else => |e| return e,
8657 error.WriteFailed => return nw.err.?,
8658 };
8659 switch (elf.symPtr(nmi.symbol(elf).index())) {
8660 inline else => |sym| elf.targetStore(&sym.size, @intCast(nw.interface.end)),
8668 {
8669 var nw: MappedFile.Node.Writer = undefined;
8670 ni.writer(gpa, &elf.mf, &nw);
8671 defer nw.deinit();
8672 elf.resetNodeRelocs(ni);
8673 codegen.generateSymbol(
8674 &elf.base,
8675 pt,
8676 .fromInterned(nav.resolved.?.value),
8677 &nw.interface,
8678 .{ .atom_index = Node.toAtom(ni) },
8679 ) catch |err| switch (err) {
8680 else => |e| return e,
8681 error.WriteFailed => return nw.err.?,
8682 };
8683 switch (elf.symPtr(nmi.symbol(elf).index())) {
8684 inline else => |sym| elf.targetStore(&sym.size, @intCast(nw.interface.end)),
8685 }
86618686 }
8662 }
8663 } else {
8664 if (elf.ehdrMachine() != .X86_64) return;
8665 const mod = zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?;
8666 if (!mod.strip) try elf.dwarf.updateComptimeGlobal(pt, nav_index);
8687
8688 if (!mod.strip and elf.ehdrMachine() == .X86_64) {
8689 const dwarf_gi = try elf.dwarf.getGlobal(nav_index);
8690 const dwarf_global = dwarf_gi.get(&elf.dwarf);
8691 const debug_info_ni = dwarf_global.debug_info_ni.unwrap().?;
8692 try debug_info_ni.moved(gpa, &elf.mf);
8693 var di_nw: MappedFile.Node.Writer = undefined;
8694 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
8695 defer di_nw.deinit();
8696 elf.resetNodeRelocs(debug_info_ni);
8697 try elf.dwarf.updateGlobal(pt, &di_nw, switch (elf.ehdrMachine()) {
8698 else => unreachable,
8699 .X86_64 => .x86_64,
8700 }, Symbol.Id.local(lsi).toTypeErased(), nav_index);
8701 }
8702 } else {
8703 if (mod.strip or elf.ehdrMachine() != .X86_64) return;
8704 try elf.dwarf.updateComptimeGlobal(pt, nav_index);
8705 },
86678706 }
86688707
86698708 // The NAV's node is done---now generate any UAVs or lazy code/data which the NAV needs.
......@@ -8851,7 +8890,7 @@ fn updateFuncInner(
88518890 var nw: MappedFile.Node.Writer = undefined;
88528891 ni.writer(gpa, &elf.mf, &nw);
88538892 defer nw.deinit();
8854 var debug_output_buf: Dwarf.WipNav.Debug = undefined;
8893 var debug_output_buf: Dwarf.WipFunc.Debug = undefined;
88558894 const debug_output: link.File.DebugInfoOutput, const dwarf_func = debug_output: {
88568895 if (elf.ehdrMachine() != .X86_64) break :debug_output .{ .none, undefined };
88578896 const dwarf = &elf.dwarf;
......@@ -8862,8 +8901,8 @@ fn updateFuncInner(
88628901 try elf.nodes.ensureUnusedCapacity(gpa, 4);
88638902 const dwarf_fi = try dwarf.getFunc(func.owner_nav);
88648903
8865 const wip_nav = &debug_output_buf.wip_nav;
8866 wip_nav.* = .{
8904 const wip_func = &debug_output_buf.wip_func;
8905 wip_func.* = .{
88678906 .dwarf = dwarf,
88688907 .unit = dwarf.getUnit(mod),
88698908 .func = func_index,
......@@ -8879,7 +8918,7 @@ fn updateFuncInner(
88798918 .fde_writer = undefined,
88808919 .frame_func_length = undefined,
88818920 };
8882 const unit = wip_nav.unit.get(dwarf);
8921 const unit = wip_func.unit.get(dwarf);
88838922
88848923 const frame_align: Alignment = switch (elf.identClass()) {
88858924 .NONE, _ => unreachable,
......@@ -8887,13 +8926,13 @@ fn updateFuncInner(
88878926 .@"64" => .@"8",
88888927 };
88898928 const frame_ni = unit.frame_ni.unwrap() orelse frame_ni: {
8890 const frame_ni = elf.addNodeAssumeCapacity(try switch (wip_nav.frame_format) {
8929 const frame_ni = elf.addNodeAssumeCapacity(try switch (wip_func.frame_format) {
88918930 .debug_frame => elf.shndx.debug_frame,
88928931 .eh_frame => elf.shndx.eh_frame,
88938932 }.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{
88948933 .alignment = frame_align.max(elf.mf.flags.block_size),
88958934 .enable_next_moved = true,
8896 }), .{ .unit_frame = wip_nav.unit });
8935 }), .{ .unit_frame = wip_func.unit });
88978936 unit.frame_ni = .wrap(frame_ni);
88988937 break :frame_ni frame_ni;
88998938 };
......@@ -8904,7 +8943,7 @@ fn updateFuncInner(
89048943 .next_moved = true,
89058944 .enable_next_moved = true,
89068945 }),
8907 .{ .unit_frame_cie = wip_nav.unit },
8946 .{ .unit_frame_cie = wip_func.unit },
89088947 );
89098948 unit.cie_ni = .wrap(cie_ni);
89108949 var cie_nw: MappedFile.Node.Writer = undefined;
......@@ -8913,14 +8952,13 @@ fn updateFuncInner(
89138952 dwarf.genDebugFrameCie(&cie_nw.interface, switch (elf.ehdrMachine()) {
89148953 else => unreachable,
89158954 .X86_64 => .x86_64,
8916 }, wip_nav.frame_format) catch |err| switch (err) {
8955 }, wip_func.frame_format) catch |err| switch (err) {
89178956 error.WriteFailed => return cie_nw.err.?,
89188957 };
89198958 }
89208959 const dwarf_func = dwarf_fi.get(dwarf);
89218960 const fde_ni = if (dwarf_func.fde_ni.unwrap()) |fde_ni| fde_ni: {
89228961 try fde_ni.moved(gpa, &elf.mf);
8923 try fde_ni.nextMoved(gpa, &elf.mf);
89248962 break :fde_ni fde_ni;
89258963 } else fde_ni: {
89268964 const fde_ni = elf.addNodeAssumeCapacity(try frame_ni.addFloatingChild(gpa, &elf.mf, .{
......@@ -8932,9 +8970,9 @@ fn updateFuncInner(
89328970 dwarf_func.fde_ni = .wrap(fde_ni);
89338971 break :fde_ni fde_ni;
89348972 };
8935 fde_ni.writer(gpa, &elf.mf, &wip_nav.fde_writer);
8973 fde_ni.writer(gpa, &elf.mf, &wip_func.fde_writer);
89368974
8937 if (mod.strip) break :debug_output .{ .{ .eh_frame = wip_nav }, dwarf_func };
8975 if (mod.strip) break :debug_output .{ .{ .eh_frame = wip_func }, dwarf_func };
89388976
89398977 const debug = &debug_output_buf;
89408978 debug.pt = pt;
......@@ -8947,7 +8985,6 @@ fn updateFuncInner(
89478985 .debug_info_ni = debug_info_ni.toOptional(),
89488986 });
89498987 try debug_info_ni.moved(gpa, &elf.mf);
8950 try debug_info_ni.nextMoved(gpa, &elf.mf);
89518988 debug_info_ni.writer(gpa, &elf.mf, &debug.info_writer);
89528989
89538990 const debug_line_ni = dwarf_func.debug_line_ni.unwrap() orelse debug_line_ni: {
......@@ -8973,17 +9010,17 @@ fn updateFuncInner(
89739010 };
89749011 switch (debug_output) {
89759012 .dwarf => unreachable,
8976 .eh_frame => |wip_nav| {
9013 .eh_frame => |wip_func| {
89779014 elf.resetNodeRelocs(dwarf_func.fde_ni.unwrap().?);
8978 try wip_nav.genDebugFrameHeader();
9015 try wip_func.genDebugFrameHeader();
89799016 },
89809017 .dwarf2 => |debug| {
89819018 elf.resetNodeRelocs(dwarf_func.fde_ni.unwrap().?);
8982 try debug.wip_nav.genDebugFrameHeader();
9019 try debug.wip_func.genDebugFrameHeader();
89839020 elf.resetNodeRelocs(dwarf_func.debug_line_ni.unwrap().?);
89849021 try debug.startDebugLine();
89859022 elf.resetNodeRelocs(dwarf_func.debug_info_ni.unwrap().?);
8986 try debug.startFuncDebugInfo();
9023 try debug.startDebugInfo();
89879024 },
89889025 .none => {},
89899026 }
......@@ -9006,25 +9043,25 @@ fn updateFuncInner(
90069043 }
90079044 switch (debug_output) {
90089045 .dwarf => unreachable,
9009 .eh_frame => |wip_nav| wip_nav.finishDebugFrameFde(func_length),
9046 .eh_frame => |wip_func| wip_func.finishDebugFrameFde(func_length),
90109047 .dwarf2 => |debug| {
9011 try debug.finishFunc(func_length);
9012 const unit = debug.wip_nav.unit.get(debug.wip_nav.dwarf);
9048 try debug.finish(func_length);
9049 const unit = debug.wip_func.unit.get(debug.wip_func.dwarf);
90139050 {
90149051 var dr_nw: MappedFile.Node.Writer = undefined;
90159052 unit.debug_rnglists_ni.unwrap().?.writer(gpa, &elf.mf, &dr_nw);
90169053 defer dr_nw.deinit();
90179054 const first_symbol_reloc = elf.symbol_relocs.items.len;
9018 debug.wip_nav.dwarf.genDebugRnglists(
9055 debug.wip_func.dwarf.genDebugRnglists(
90199056 unit,
90209057 &dr_nw,
9021 debug.wip_nav.func_si,
9058 debug.wip_func.func_si,
90229059 func_length,
90239060 ) catch |err| switch (err) {
90249061 else => |e| return e,
90259062 error.WriteFailed => return dr_nw.err.?,
90269063 };
9027 const symbol_relocs = &elf.dwarf_units[@backingInt(debug.wip_nav.unit)]
9064 const symbol_relocs = &elf.dwarf_units[@backingInt(debug.wip_func.unit)]
90289065 .debug_rnglists_symbol_relocs;
90299066 try symbol_relocs.ensureUnusedCapacity(gpa, elf.symbol_relocs.items.len -
90309067 first_symbol_reloc);
......@@ -9034,7 +9071,7 @@ fn updateFuncInner(
90349071 {},
90359072 );
90369073 }
9037 debug.wip_nav.finishDebugFrameFde(func_length);
9074 debug.wip_func.finishDebugFrameFde(func_length);
90389075 if (func.analysisUnordered(ip).inferred_error_set) {
90399076 const ies = ip.getIfExists(.{ .inferred_error_set_type = func_index }).?;
90409077 if (elf.dwarf.const_pool.getIfExists(ies)) |cpi|
test/src/Debugger.zig+1-1
......@@ -868,7 +868,7 @@ pub fn addTests(db: *Debugger) void {
868868 \\(lldb) breakpoint delete --force 1
869869 \\1 breakpoints deleted; 0 breakpoint locations disabled.
870870 },
871 .{ .skip_new_linker = true },
871 .{},
872872 );
873873 db.addLldbTest(
874874 "if_blocks",