authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-07 22:42:48-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-07 22:43:00-04:00
log2622cb368f0a3aa6b3efe625d2abc967ddf82f23
tree9d7dbb27ab4ec883164966f2944f319b0b9011e5
parenta059c9a5e57164338bf4b99728905882b0d6323c

Dwarf2: finish function debug info


2 files changed, 193 insertions(+), 129 deletions(-)

src/link/Dwarf2.zig+191-121
......@@ -717,16 +717,23 @@ pub const WipFunc = struct {
717717 pub const Debug = struct {
718718 wip_func: WipFunc,
719719 pt: Zcu.PerThread,
720 empty: bool,
720 is_empty: bool,
721 empty_abbrev_code: AbbrevCode,
721722 blocks: std.ArrayList(struct {
722 abbrev_code: u32,
723 low_pc_off: usize,
724 high_pc: u32,
723 abbrev_code_offset: usize,
724 low_pc: usize,
725 high_pc_offset: usize,
725726 }),
726727 info_writer: link.MappedFile.Node.Writer,
727728 info_func_length_offset: usize,
728729 line_writer: link.MappedFile.Node.Writer,
729730
731 pub fn init(debug: *Debug, pt: Zcu.PerThread) void {
732 debug.pt = pt;
733 debug.is_empty = true;
734 debug.blocks = .empty;
735 }
736
730737 pub fn deinit(debug: *Debug) void {
731738 const gpa = debug.pt.zcu.gpa;
732739 debug.line_writer.deinit();
......@@ -760,15 +767,24 @@ pub const WipFunc = struct {
760767 const decl = zf.zir.?.getDeclaration(inst_info.inst);
761768 const di_nw = &debug.info_writer;
762769 const di_w = &di_nw.interface;
763 try dwarf.abbrevCode(di_nw, .decl_func);
764 try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(switch (func.generic_owner) {
765 .none => nav,
770 const parent_ty: Type = .fromInterned(ip.namespacePtr(switch (func.generic_owner) {
766771 else => |generic_owner| ip.getNav(zcu.funcInfo(generic_owner).owner_nav),
767 }.analysis.?.namespace).owner_type));
768 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
769 try di_w.writeUleb128(decl.src_column + 1);
770 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
771 try dwarf.strx(di_nw, nav.name.toSlice(ip));
772 .none => nav,
773 }.analysis.?.namespace).owner_type);
774 if (func.generic_owner != .none or parent_ty.getCaptures(zcu).len > 0) {
775 debug.empty_abbrev_code = .decl_instance_empty_func;
776 try dwarf.abbrevCode(di_nw, .decl_instance_func);
777 try dwarf.refType(pt, di_nw, parent_ty);
778 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, debug.wip_func.func), 0);
779 } else {
780 debug.empty_abbrev_code = .decl_empty_func;
781 try dwarf.abbrevCode(di_nw, .decl_func);
782 try dwarf.refType(pt, di_nw, parent_ty);
783 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
784 try di_w.writeUleb128(decl.src_column + 1);
785 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
786 try dwarf.strx(di_nw, nav.name.toSlice(ip));
787 }
772788 try dwarf.strx(di_nw, switch (decl.linkage) {
773789 .normal => nav.fqn,
774790 .@"extern", .@"export" => nav.name,
......@@ -850,10 +866,10 @@ pub const WipFunc = struct {
850866 @intCast(func_length),
851867 dwarf.endian,
852868 );
853 if (debug.empty) std.leb.writeUnsignedFixed(
869 if (debug.is_empty) std.leb.writeUnsignedFixed(
854870 AbbrevCode.decl_size,
855871 di_w.buffered()[0..AbbrevCode.decl_size],
856 @intCast(try dwarf.refAbbrevCode(di_nw.mf, .decl_empty_func)),
872 @intCast(try dwarf.refAbbrevCode(di_nw.mf, debug.empty_abbrev_code)),
857873 ) else try di_w.writeUleb128(@backingInt(AbbrevCode.null));
858874 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
859875 }
......@@ -891,7 +907,7 @@ pub const WipFunc = struct {
891907 if (opt_name) |name| try dwarf.strx(di_nw, name);
892908 try dwarf.refType(debug.pt, di_nw, ty);
893909 try dwarf.exprLoc(di_nw, loc);
894 debug.empty = false;
910 debug.is_empty = false;
895911 }
896912
897913 pub const LocalConstTag = enum { comptime_arg, local_const };
......@@ -944,7 +960,7 @@ pub const WipFunc = struct {
944960 try dwarf.refType(pt, di_nw, ty);
945961 if (ty_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, val);
946962 if (ty_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, val);
947 debug.empty = false;
963 debug.is_empty = false;
948964 }
949965
950966 pub fn genVarArgsDebugInfo(debug: *Debug) link.Error!void {
......@@ -955,7 +971,7 @@ pub const WipFunc = struct {
955971 }
956972 fn genVarArgsDebugInfoInner(debug: *Debug) link.EmitError!void {
957973 try debug.wip_func.dwarf.abbrevCode(&debug.info_writer, .is_var_args);
958 debug.empty = false;
974 debug.is_empty = false;
959975 }
960976
961977 pub fn advanceLineAndPc(
......@@ -1056,62 +1072,67 @@ pub const WipFunc = struct {
10561072 try debug.line_writer.interface.writeByte(DW.LNS.set_epilogue_begin);
10571073 }
10581074
1059 pub fn enterBlock(debug: *Debug, code_off: usize) link.Error!void {
1060 return debug.enterBlockInner(code_off) catch |err| switch (err) {
1075 pub fn enterBlock(debug: *Debug, code_offset: usize) link.Error!void {
1076 return debug.enterBlockInner(code_offset) catch |err| switch (err) {
10611077 else => |e| e,
10621078 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
10631079 };
10641080 }
1065 fn enterBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {
1081 fn enterBlockInner(debug: *Debug, code_offset: usize) link.EmitError!void {
10661082 const dwarf = debug.wip_func.dwarf;
10671083 const block = try debug.blocks.addOne(dwarf.lf.comp.gpa);
10681084
10691085 const di_nw = &debug.info_writer;
10701086 const di_w = &di_nw.interface;
1071 block.abbrev_code = @intCast(di_w.end);
1087 block.abbrev_code_offset = di_w.end;
10721088 try dwarf.abbrevCode(di_nw, .block);
1073 block.low_pc_off = code_off;
1074 try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_off);
1075 block.high_pc = @intCast(di_w.end);
1089 block.low_pc = code_offset;
1090 try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_offset);
1091 block.high_pc_offset = di_w.end;
10761092 try di_w.writeInt(u32, 0, dwarf.endian);
1077 debug.empty = true;
1093 debug.is_empty = true;
10781094 }
10791095
1080 pub fn leaveBlock(debug: *Debug, code_off: usize) link.Error!void {
1081 return debug.leaveBlockInner(code_off) catch |err| switch (err) {
1096 pub fn leaveBlock(debug: *Debug, code_offset: usize) link.Error!void {
1097 return debug.leaveBlockInner(code_offset) catch |err| switch (err) {
10821098 else => |e| e,
10831099 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
10841100 };
10851101 }
1086 fn leaveBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {
1102 fn leaveBlockInner(debug: *Debug, code_offset: usize) link.EmitError!void {
10871103 const dwarf = debug.wip_func.dwarf;
10881104 const block = debug.blocks.pop().?;
10891105
10901106 const di_nw = &debug.info_writer;
10911107 const di_w = &di_nw.interface;
10921108 const block_size = comptime uleb128Size(@backingInt(AbbrevCode.block));
1093 if (debug.empty) std.leb.writeUnsignedFixed(
1109 if (debug.is_empty) std.leb.writeUnsignedFixed(
10941110 block_size,
1095 di_w.buffered()[block.abbrev_code..][0..block_size],
1111 di_w.buffered()[block.abbrev_code_offset..][0..block_size],
10961112 @intCast(try dwarf.refAbbrevCode(di_nw.mf, .empty_block)),
10971113 ) else try di_w.writeUleb128(@backingInt(AbbrevCode.null));
10981114 std.mem.writeInt(
10991115 u32,
1100 di_nw.interface.buffered()[block.high_pc..][0..4],
1101 @intCast(code_off - block.low_pc_off),
1116 di_nw.interface.buffered()[block.high_pc_offset..][0..4],
1117 @intCast(code_offset - block.low_pc),
11021118 dwarf.endian,
11031119 );
1104 debug.empty = false;
1120 debug.is_empty = false;
11051121 }
11061122
11071123 pub fn enterInlineFunc(
11081124 debug: *Debug,
11091125 func: InternPool.Index,
1110 code_off: usize,
1126 code_offset: usize,
11111127 line: u32,
11121128 column: u32,
11131129 ) link.Error!void {
1114 return debug.enterInlineFuncInner(func, code_off, line, column) catch |err| switch (err) {
1130 return debug.enterInlineFuncInner(
1131 func,
1132 code_offset,
1133 line,
1134 column,
1135 ) catch |err| switch (err) {
11151136 else => |e| e,
11161137 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
11171138 };
......@@ -1119,7 +1140,7 @@ pub const WipFunc = struct {
11191140 fn enterInlineFuncInner(
11201141 debug: *Debug,
11211142 func: InternPool.Index,
1122 code_off: usize,
1143 code_offset: usize,
11231144 line: u32,
11241145 column: u32,
11251146 ) link.EmitError!void {
......@@ -1130,7 +1151,7 @@ pub const WipFunc = struct {
11301151
11311152 const di_nw = &debug.info_writer;
11321153 const di_w = &di_nw.interface;
1133 block.abbrev_code = @intCast(di_w.end);
1154 block.abbrev_code_offset = di_w.end;
11341155 try dwarf.abbrevCode(di_nw, .inlined_func);
11351156 try dwarf.refConst(pt, di_nw, .fromInterned(func));
11361157 try di_w.writeUleb128((if (zcu.comp.config.incremental)
......@@ -1138,16 +1159,20 @@ pub const WipFunc = struct {
11381159 else
11391160 zcu.navSrcLine(zcu.funcInfo(debug.wip_func.func).owner_nav) + 1) + line);
11401161 try di_w.writeUleb128(column + 1);
1141 block.low_pc_off = code_off;
1142 try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_off);
1143 block.high_pc = @intCast(di_w.end);
1162 block.low_pc = code_offset;
1163 try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_offset);
1164 block.high_pc_offset = di_w.end;
11441165 try di_w.writeInt(u32, 0, dwarf.endian);
11451166 try debug.setInlineFunc(func);
1146 debug.empty = true;
1167 debug.is_empty = true;
11471168 }
11481169
1149 pub fn leaveInlineFunc(debug: *Debug, func: InternPool.Index, code_off: usize) link.Error!void {
1150 return debug.leaveInlineFuncInner(func, code_off) catch |err| switch (err) {
1170 pub fn leaveInlineFunc(
1171 debug: *Debug,
1172 func: InternPool.Index,
1173 code_offset: usize,
1174 ) link.Error!void {
1175 return debug.leaveInlineFuncInner(func, code_offset) catch |err| switch (err) {
11511176 else => |e| e,
11521177 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
11531178 };
......@@ -1155,7 +1180,7 @@ pub const WipFunc = struct {
11551180 fn leaveInlineFuncInner(
11561181 debug: *Debug,
11571182 func: InternPool.Index,
1158 code_off: usize,
1183 code_offset: usize,
11591184 ) link.EmitError!void {
11601185 const dwarf = debug.wip_func.dwarf;
11611186 const block = debug.blocks.pop().?;
......@@ -1163,19 +1188,19 @@ pub const WipFunc = struct {
11631188 const di_nw = &debug.info_writer;
11641189 const di_w = &di_nw.interface;
11651190 const inlined_func_size = comptime uleb128Size(@backingInt(AbbrevCode.inlined_func));
1166 if (debug.empty) std.leb.writeUnsignedFixed(
1191 if (debug.is_empty) std.leb.writeUnsignedFixed(
11671192 inlined_func_size,
1168 di_w.buffered()[block.abbrev_code..][0..inlined_func_size],
1193 di_w.buffered()[block.abbrev_code_offset..][0..inlined_func_size],
11691194 @intCast(try dwarf.refAbbrevCode(di_nw.mf, .empty_inlined_func)),
11701195 ) else try di_w.writeUleb128(@backingInt(AbbrevCode.null));
11711196 std.mem.writeInt(
11721197 u32,
1173 di_w.buffered()[block.high_pc..][0..4],
1174 @intCast(code_off - block.low_pc_off),
1198 di_w.buffered()[block.high_pc_offset..][0..4],
1199 @intCast(code_offset - block.low_pc),
11751200 dwarf.endian,
11761201 );
11771202 try debug.setInlineFunc(func);
1178 debug.empty = false;
1203 debug.is_empty = false;
11791204 }
11801205
11811206 pub fn setInlineFunc(debug: *Debug, func: InternPool.Index) link.Error!void {
......@@ -1539,47 +1564,59 @@ pub fn getFuncIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Func.Index {
15391564 return @fromBackingInt(@intCast(dwarf.funcs.getIndex(nav) orelse return null));
15401565}
15411566
1542fn getConstDeclInst(dwarf: *Dwarf, val: InternPool.Index) ?InternPool.TrackedInst.Index {
1543 const ip = &dwarf.lf.comp.zcu.?.intern_pool;
1544 switch (ip.indexToKey(val)) {
1567fn getConstDeclInst(dwarf: *Dwarf, @"const": InternPool.Index) union(enum) {
1568 @"const": InternPool.Index,
1569 src_inst: InternPool.TrackedInst.Index,
1570} {
1571 const zcu = dwarf.lf.comp.zcu.?;
1572 const ip = &zcu.intern_pool;
1573 switch (ip.indexToKey(@"const")) {
15451574 else => unreachable,
15461575 .struct_type, .union_type, .enum_type, .opaque_type => |container, tag| switch (container) {
15471576 .declared => |declared| switch (declared.captures.owned.len) {
1548 0 => return null,
1549 else => switch (tag) {
1577 0 => return .{ .@"const" = @"const" },
1578 else => return .{ .src_inst = src_inst: switch (tag) {
15501579 else => unreachable,
15511580 .struct_type => {
1552 const loaded_struct = ip.loadStructType(val);
1553 return ip.getNav(loaded_struct.name_nav.unwrap() orelse
1554 return loaded_struct.zir_index).srcInst(ip);
1581 const loaded_struct = ip.loadStructType(@"const");
1582 break :src_inst ip.getNav(loaded_struct.name_nav.unwrap() orelse
1583 break :src_inst loaded_struct.zir_index).srcInst(ip);
15551584 },
15561585 .union_type => {
1557 const loaded_union = ip.loadUnionType(val);
1558 return ip.getNav(loaded_union.name_nav.unwrap() orelse
1559 return loaded_union.zir_index).srcInst(ip);
1586 const loaded_union = ip.loadUnionType(@"const");
1587 break :src_inst ip.getNav(loaded_union.name_nav.unwrap() orelse
1588 break :src_inst loaded_union.zir_index).srcInst(ip);
15601589 },
15611590 .enum_type => {
1562 const loaded_enum = ip.loadEnumType(val);
1563 return ip.getNav(loaded_enum.name_nav.unwrap() orelse
1564 return loaded_enum.zir_index.unwrap().?).srcInst(ip);
1591 const loaded_enum = ip.loadEnumType(@"const");
1592 break :src_inst ip.getNav(loaded_enum.name_nav.unwrap() orelse
1593 break :src_inst loaded_enum.zir_index.unwrap().?).srcInst(ip);
15651594 },
15661595 .opaque_type => {
1567 const loaded_opaque = ip.loadOpaqueType(val);
1568 return ip.getNav(loaded_opaque.name_nav.unwrap() orelse
1569 return loaded_opaque.zir_index).srcInst(ip);
1596 const loaded_opaque = ip.loadOpaqueType(@"const");
1597 break :src_inst ip.getNav(loaded_opaque.name_nav.unwrap() orelse
1598 break :src_inst loaded_opaque.zir_index).srcInst(ip);
15701599 },
1571 },
1600 } },
15721601 },
15731602 .reified => |reified| {
15741603 assert(reified.zir_index.resolve(ip).? != .main_struct_inst);
1575 return reified.zir_index;
1604 return .{ .src_inst = reified.zir_index };
15761605 },
15771606 .generated_union_tag => unreachable,
15781607 },
1579 .func => |func| return ip.getNav(switch (func.generic_owner) {
1580 .none => func.owner_nav,
1581 else => |generic_owner| ip.indexToKey(generic_owner).func.owner_nav,
1582 }).srcInst(ip),
1608 .func => |func| switch (func.generic_owner) {
1609 else => |generic_owner| return .{ .@"const" = generic_owner },
1610 .none => {
1611 const owner_nav = ip.getNav(func.owner_nav);
1612 return switch (Type.fromInterned(
1613 ip.namespacePtr(owner_nav.analysis.?.namespace).owner_type,
1614 ).getCaptures(zcu).len) {
1615 0 => .{ .@"const" = @"const" },
1616 else => .{ .src_inst = owner_nav.srcInst(ip) },
1617 };
1618 },
1619 },
15831620 }
15841621}
15851622pub fn getConstDecl(
......@@ -1587,10 +1624,13 @@ pub fn getConstDecl(
15871624 pt: Zcu.PerThread,
15881625 instance_const: InternPool.Index,
15891626) link.Error!link.MappedFile.Node.Index {
1590 return dwarf.getDecl(pt, dwarf.getConstDeclInst(instance_const) orelse {
1591 const cpi = try dwarf.getConst(pt, .fromInterned(instance_const));
1592 return Const.get(cpi, dwarf).debug_info_ni.unwrap().?;
1593 }, .{ .@"const" = instance_const });
1627 switch (dwarf.getConstDeclInst(instance_const)) {
1628 .@"const" => |@"const"| {
1629 const cpi = try dwarf.getConst(pt, .fromInterned(@"const"));
1630 return Const.get(cpi, dwarf).debug_info_ni.unwrap().?;
1631 },
1632 .src_inst => |src_inst| return dwarf.getDecl(pt, src_inst, .{ .@"const" = instance_const }),
1633 }
15941634}
15951635pub fn getGlobalDecl(
15961636 dwarf: *Dwarf,
......@@ -2259,7 +2299,7 @@ pub fn updateComptimeGlobal(
22592299 const zcu = pt.zcu;
22602300 const ip = &zcu.intern_pool;
22612301 const nav = ip.getNav(global);
2262 log.debug("updateComptimeNav({f})", .{nav.fqn.fmt(ip)});
2302 log.debug("updateComptimeGlobal({f})", .{nav.fqn.fmt(ip)});
22632303 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
22642304 const nav_val: Value = .fromInterned(nav.resolved.?.value);
22652305 const decl = zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst);
......@@ -2298,32 +2338,32 @@ pub fn updateComptimeGlobal(
22982338 => try dwarf.genComptimeGlobal(pt, global, &decl),
22992339 .struct_type => {
23002340 const loaded_struct = ip.loadStructType(nav_val.toIntern());
2301 if (global.toOptional() == loaded_struct.name_nav) {
2341 if (loaded_struct.name_nav == global.toOptional()) {
23022342 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
23032343 } else try dwarf.genComptimeGlobal(pt, global, &decl);
23042344 },
23052345 .enum_type => {
23062346 const loaded_enum = ip.loadEnumType(nav_val.toIntern());
2307 if (global.toOptional() == loaded_enum.name_nav) {
2347 if (loaded_enum.name_nav == global.toOptional()) {
23082348 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
23092349 } else try dwarf.genComptimeGlobal(pt, global, &decl);
23102350 },
23112351 .union_type => {
23122352 const loaded_union = ip.loadUnionType(nav_val.toIntern());
2313 if (global.toOptional() == loaded_union.name_nav) {
2353 if (loaded_union.name_nav == global.toOptional()) {
23142354 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
23152355 } else try dwarf.genComptimeGlobal(pt, global, &decl);
23162356 },
23172357 .opaque_type => {
23182358 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());
2319 if (global.toOptional() == loaded_opaque.name_nav) {
2359 if (loaded_opaque.name_nav == global.toOptional()) {
23202360 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
23212361 } else try dwarf.genComptimeGlobal(pt, global, &decl);
23222362 },
23232363 .@"extern" => unreachable,
2324 .func => |func| if (func.owner_nav == global and func.generic_owner == .none) {
2364 .func => |func| if (func.owner_nav == global) {
23252365 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
2326 } else return,
2366 } else try dwarf.genComptimeGlobal(pt, global, &decl),
23272367 .memoized_call => unreachable, // not a value
23282368 }
23292369}
......@@ -2490,14 +2530,14 @@ fn updateConstInner(
24902530 dwarf: *Dwarf,
24912531 pt: Zcu.PerThread,
24922532 di_nw: *link.MappedFile.Node.Writer,
2493 val: InternPool.Index,
2533 @"const": InternPool.Index,
24942534) link.EmitError!void {
24952535 const zcu = pt.zcu;
24962536 const ip = &zcu.intern_pool;
24972537 const di_w = &di_nw.interface;
2498 switch (ip.indexToKey(val)) {
2538 switch (ip.indexToKey(@"const")) {
24992539 .int_type => |int_type| {
2500 const ty: Type = .fromInterned(val);
2540 const ty: Type = .fromInterned(@"const");
25012541 try dwarf.abbrevCode(di_nw, .numeric_type);
25022542 var name_buf: [std.fmt.count("i{d}", .{std.math.maxInt(u16)})]u8 = undefined;
25032543 try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{
......@@ -2513,7 +2553,7 @@ fn updateConstInner(
25132553 },
25142554 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
25152555 .one, .many, .c => {
2516 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
2556 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
25172557 defer zcu.gpa.free(name);
25182558 try dwarf.abbrevCode(di_nw, switch (ptr_type.sentinel) {
25192559 .none => .ptr_type,
......@@ -2547,7 +2587,7 @@ fn updateConstInner(
25472587 try dwarf.refType(pt, di_nw, .fromInterned(ptr_type.child));
25482588 },
25492589 .slice => {
2550 const ty: Type = .fromInterned(val);
2590 const ty: Type = .fromInterned(@"const");
25512591 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
25522592 defer zcu.gpa.free(name);
25532593 try dwarf.abbrevCode(di_nw, .generated_struct_type);
......@@ -2568,7 +2608,7 @@ fn updateConstInner(
25682608 },
25692609 },
25702610 .array_type => |array_type| {
2571 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
2611 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
25722612 defer zcu.gpa.free(name);
25732613 try dwarf.abbrevCode(
25742614 di_nw,
......@@ -2584,7 +2624,7 @@ fn updateConstInner(
25842624 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
25852625 },
25862626 .vector_type => |vector_type| {
2587 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
2627 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
25882628 defer zcu.gpa.free(name);
25892629 try dwarf.abbrevCode(di_nw, .vector_type);
25902630 try dwarf.strx(di_nw, name);
......@@ -2595,7 +2635,7 @@ fn updateConstInner(
25952635 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
25962636 },
25972637 .opt_type => |opt_child_type_index| {
2598 const opt_ty: Type = .fromInterned(val);
2638 const opt_ty: Type = .fromInterned(@"const");
25992639 const opt_child_ty: Type = .fromInterned(opt_child_type_index);
26002640 const opt_repr = optRepr(opt_child_ty, zcu);
26012641 const name = try zcu.gpa.print("{f}", .{opt_ty.fmt(pt)});
......@@ -2668,7 +2708,7 @@ fn updateConstInner(
26682708 },
26692709 .anyframe_type => unreachable,
26702710 .error_union_type => |error_union_type| {
2671 const eu_ty: Type = .fromInterned(val);
2711 const eu_ty: Type = .fromInterned(@"const");
26722712 const eu_error_set_ty: Type = .fromInterned(error_union_type.error_set_type);
26732713 const eu_payload_ty: Type = .fromInterned(error_union_type.payload_type);
26742714 const eu_error_set_offset, const eu_payload_offset = switch (error_union_type.payload_type) {
......@@ -2747,10 +2787,10 @@ fn updateConstInner(
27472787 .c_longdouble,
27482788 .bool,
27492789 => {
2750 const ty: Type = .fromInterned(val);
2790 const ty: Type = .fromInterned(@"const");
27512791 try dwarf.abbrevCode(di_nw, .numeric_type);
27522792 try dwarf.strx(di_nw, @tagName(simple_type));
2753 try di_w.writeByte(if (val == .bool_type)
2793 try di_w.writeByte(if (@"const" == .bool_type)
27542794 DW.ATE.boolean
27552795 else if (ty.isRuntimeFloat())
27562796 DW.ATE.float
......@@ -2778,7 +2818,7 @@ fn updateConstInner(
27782818 .undefined,
27792819 .enum_literal,
27802820 => {
2781 const ty: Type = .fromInterned(val);
2821 const ty: Type = .fromInterned(@"const");
27822822 try dwarf.abbrevCode(di_nw, .void_type);
27832823 var name_buf: ["@TypeOf(undefined)".len]u8 = undefined;
27842824 try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{
......@@ -2793,18 +2833,18 @@ fn updateConstInner(
27932833 .generated_empty_enum_type);
27942834 try dwarf.strx(di_nw, "anyerror");
27952835 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
2796 for (global_error_set_names, 1..) |name, value| {
2836 for (global_error_set_names, 1..) |err_name, err_value| {
27972837 try dwarf.abbrevCode(di_nw, .enum_field);
27982838 try di_w.writeUleb128(DW.FORM.udata);
2799 try di_w.writeUleb128(value);
2800 try dwarf.strx(di_nw, name.toSlice(ip));
2839 try di_w.writeUleb128(err_value);
2840 try dwarf.strx(di_nw, err_name.toSlice(ip));
28012841 }
28022842 if (global_error_set_names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
28032843 },
28042844 .adhoc_inferred_error_set => unreachable,
28052845 },
28062846 .tuple_type => |tuple_type| {
2807 const ty: Type = .fromInterned(val);
2847 const ty: Type = .fromInterned(@"const");
28082848 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
28092849 defer zcu.gpa.free(name);
28102850 if (tuple_type.types.len == 0) {
......@@ -2854,7 +2894,7 @@ fn updateConstInner(
28542894 }
28552895 },
28562896 .struct_type => {
2857 const loaded_struct = ip.loadStructType(val);
2897 const loaded_struct = ip.loadStructType(@"const");
28582898 const src_inst = loaded_struct.zir_index.resolveFull(ip).?;
28592899 const zf = zcu.fileByIndex(src_inst.file);
28602900 if (src_inst.inst == .main_struct_inst) {
......@@ -2879,7 +2919,7 @@ fn updateConstInner(
28792919 try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(
28802920 ip.namespacePtr(loaded_struct.namespace).parent.unwrap().?,
28812921 ).owner_type));
2882 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0);
2922 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, @"const"), 0);
28832923 } else if (loaded_struct.name_nav.unwrap()) |name_ni| {
28842924 const name_nav = ip.getNav(name_ni);
28852925 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
......@@ -2921,7 +2961,7 @@ fn updateConstInner(
29212961 }
29222962 switch (loaded_struct.layout) {
29232963 .auto, .@"extern" => {
2924 const ty: Type = .fromInterned(val);
2964 const ty: Type = .fromInterned(@"const");
29252965 try di_w.writeUleb128(ty.abiSize(zcu));
29262966 try di_w.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
29272967 try dwarf.genCaptures(pt, di_nw, loaded_struct.captures);
......@@ -2997,7 +3037,7 @@ fn updateConstInner(
29973037 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
29983038 },
29993039 .union_type => {
3000 const loaded_union = ip.loadUnionType(val);
3040 const loaded_union = ip.loadUnionType(@"const");
30013041 const loaded_tag = ip.loadEnumType(loaded_union.enum_tag_type);
30023042 const zfi = loaded_union.zir_index.resolveFile(ip);
30033043 const zf = zcu.fileByIndex(zfi);
......@@ -3013,7 +3053,7 @@ fn updateConstInner(
30133053 try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(
30143054 ip.namespacePtr(loaded_union.namespace).parent.unwrap().?,
30153055 ).owner_type));
3016 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0);
3056 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, @"const"), 0);
30173057 } else if (loaded_union.name_nav.unwrap()) |name_ni| {
30183058 const name_nav = ip.getNav(name_ni);
30193059 const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
......@@ -3133,7 +3173,7 @@ fn updateConstInner(
31333173 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
31343174 },
31353175 .enum_type => {
3136 const loaded_enum = ip.loadEnumType(val);
3176 const loaded_enum = ip.loadEnumType(@"const");
31373177 switch (loaded_enum.owner_union) {
31383178 .none => {
31393179 const zfi = loaded_enum.zir_index.unwrap().?.resolveFile(ip);
......@@ -3148,7 +3188,7 @@ fn updateConstInner(
31483188 try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(
31493189 ip.namespacePtr(loaded_enum.namespace).parent.unwrap().?,
31503190 ).owner_type));
3151 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0);
3191 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, @"const"), 0);
31523192 } else if (loaded_enum.name_nav.unwrap()) |name_ni| {
31533193 const name_nav = ip.getNav(name_ni);
31543194 const decl = zir.getDeclaration(name_nav.srcInst(ip).resolve(ip).?);
......@@ -3198,11 +3238,11 @@ fn updateConstInner(
31983238 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
31993239 },
32003240 // no defined size, so lowered the same as incomplete struct types
3201 .opaque_type => return dwarf.updateConstIncompleteInner(pt, di_nw, val),
3241 .opaque_type => return dwarf.updateConstIncompleteInner(pt, di_nw, @"const"),
32023242 .spirv_type => unreachable,
32033243 .func_type => |func_type| {
32043244 const is_empty = func_type.param_types.len == 0 and !func_type.is_var_args;
3205 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
3245 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
32063246 defer zcu.gpa.free(name);
32073247 try dwarf.abbrevCode(di_nw, if (is_empty) .empty_func_type else .func_type);
32083248 try dwarf.strx(di_nw, name);
......@@ -3287,7 +3327,7 @@ fn updateConstInner(
32873327 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
32883328 },
32893329 .error_set_type => |error_set_type| {
3290 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
3330 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
32913331 defer zcu.gpa.free(name);
32923332 try dwarf.abbrevCode(
32933333 di_nw,
......@@ -3305,7 +3345,7 @@ fn updateConstInner(
33053345 if (error_set_type.names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
33063346 },
33073347 .inferred_error_set_type => |func| {
3308 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
3348 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
33093349 defer zcu.gpa.free(name);
33103350 try dwarf.abbrevCode(di_nw, .inferred_error_set_type);
33113351 try dwarf.strx(di_nw, name);
......@@ -3343,14 +3383,26 @@ fn updateConstInner(
33433383 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
33443384 const zir = &zcu.fileByIndex(inst_info.file).zir.?;
33453385 const decl = zir.getDeclaration(inst_info.inst);
3346 const empty = func_type.param_types.len == 0 and !func_type.is_var_args;
3386 const is_empty = func_type.param_types.len == 0 and !func_type.is_var_args;
33473387 const parent_ty: Type = .fromInterned(ip.namespacePtr(nav.analysis.?.namespace).owner_type);
3348 try dwarf.abbrevCode(di_nw, if (empty) .decl_empty_func_generic else .decl_func_generic);
3349 try dwarf.refType(pt, di_nw, parent_ty);
3350 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
3351 try di_w.writeUleb128(decl.src_column + 1);
3352 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
3353 try dwarf.strx(di_nw, nav.name.toSlice(ip));
3388 if (func.generic_owner != .none or parent_ty.getCaptures(zcu).len > 0) {
3389 try dwarf.abbrevCode(
3390 di_nw,
3391 if (is_empty) .decl_instance_empty_func_generic else .decl_instance_func_generic,
3392 );
3393 try dwarf.refType(pt, di_nw, parent_ty);
3394 try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, @"const"), 0);
3395 } else {
3396 try dwarf.abbrevCode(
3397 di_nw,
3398 if (is_empty) .decl_empty_func_generic else .decl_func_generic,
3399 );
3400 try dwarf.refType(pt, di_nw, parent_ty);
3401 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
3402 try di_w.writeUleb128(decl.src_column + 1);
3403 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
3404 try dwarf.strx(di_nw, nav.name.toSlice(ip));
3405 }
33543406 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));
33553407 for (
33563408 zir.getParamBody(func.zir_body_inst.resolve(ip).?)[0..func_type.param_types.len],
......@@ -3366,7 +3418,7 @@ fn updateConstInner(
33663418 try dwarf.refType(pt, di_nw, .fromInterned(param_ty));
33673419 }
33683420 if (func_type.is_var_args) try dwarf.abbrevCode(di_nw, .is_var_args);
3369 if (!empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
3421 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
33703422 },
33713423 .int => |int| {
33723424 var big_int_space: Value.BigIntSpace = undefined;
......@@ -3375,7 +3427,7 @@ fn updateConstInner(
33753427 try dwarf.bigIntConstValue(
33763428 di_w,
33773429 .fromInterned(int.ty),
3378 Value.fromInterned(val).toBigInt(&big_int_space, zcu),
3430 Value.fromInterned(@"const").toBigInt(&big_int_space, zcu),
33793431 );
33803432 },
33813433 .bitpack => |bitpack| {
......@@ -3461,7 +3513,7 @@ fn updateConstInner(
34613513 try dwarf.bigIntConstValue(
34623514 di_w,
34633515 .fromInterned(int.ty),
3464 Value.fromInterned(val).toBigInt(&big_int_space, zcu),
3516 Value.fromInterned(@"const").toBigInt(&big_int_space, zcu),
34653517 );
34663518 },
34673519 .float => |float| {
......@@ -3638,7 +3690,7 @@ fn updateConstInner(
36383690 switch (optRepr(opt_child_ty, zcu)) {
36393691 .opv_null => try di_w.writeUleb128(0),
36403692 .unpacked => try dwarf.blockConst(pt, di_nw, .makeBool(opt.val != .none)),
3641 .error_set, .pointer => try dwarf.blockConst(pt, di_nw, .fromInterned(val)),
3693 .error_set, .pointer => try dwarf.blockConst(pt, di_nw, .fromInterned(@"const")),
36423694 }
36433695 }
36443696 if (opt.val != .none) child_field: {
......@@ -4249,6 +4301,24 @@ fn genDeclInner(
42494301 loaded_opaque.namespace,
42504302 };
42514303 },
4304 .func => |func| {
4305 const owner_nav = ip.getNav(switch (func.generic_owner) {
4306 else => |generic_owner| zcu.funcInfo(generic_owner).owner_nav,
4307 .none => func.owner_nav,
4308 });
4309 const inst_info = owner_nav.srcInst(ip).resolveFull(ip).?;
4310 const decl = zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst);
4311 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
4312 owner_nav.analysis.?.namespace,
4313 ).owner_type);
4314 try dwarf.abbrevCode(di_nw, .decl_specification_func);
4315 try dwarf.secOffset(di_nw, parent_ni, 0);
4316 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
4317 try di_w.writeUleb128(decl.src_column + 1);
4318 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
4319 try dwarf.strx(di_nw, owner_nav.name.toSlice(ip));
4320 break :done;
4321 },
42524322 };
42534323 const zir = &zf.zir.?;
42544324 if (maybe_name_nav.unwrap()) |name_ni| {
src/link/Elf2.zig+2-8
......@@ -8982,8 +8982,7 @@ fn updateFuncInner(
89828982 const debug_output: link.File.DebugInfoOutput, const dwarf_func = debug_output: {
89838983 if (elf.ehdrMachine() != .X86_64) break :debug_output .{ .none, undefined };
89848984 const dwarf = &elf.dwarf;
8985 const src_inst = nav.srcInst(ip);
8986 const mod = zcu.fileByIndex(src_inst.resolveFile(ip)).mod.?;
8985 const mod = zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?;
89878986 if (mod.strip and mod.unwind_tables == .none) break :debug_output .{ .none, undefined };
89888987
89898988 try elf.nodes.ensureUnusedCapacity(gpa, 4);
......@@ -9063,15 +9062,10 @@ fn updateFuncInner(
90639062 if (mod.strip) break :debug_output .{ .{ .eh_frame = wip_func }, dwarf_func };
90649063
90659064 const debug = &debug_output_buf;
9066 debug.pt = pt;
9067 debug.empty = true;
9068 debug.blocks = .empty;
9065 debug.init(pt);
90699066 dwarf_func.state = .resolved;
90709067
90719068 const debug_info_ni = dwarf_func.debug_info_ni.unwrap().?;
9072 try dwarf.decls.put(zcu.comp.gpa, src_inst, .{
9073 .debug_info_ni = debug_info_ni.toOptional(),
9074 });
90759069 try debug_info_ni.moved(gpa, &elf.mf);
90769070 debug_info_ni.writer(gpa, &elf.mf, &debug.info_writer);
90779071