authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-08-22 13:10:10-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-08-22 19:53:04-04:00
logcbaff43b2a3697a168fcf9d5c022f2193d1fc9a0
tree27e394e639109d4be45a2101895036adc20398e3
parentc262061129f0c19a276779e4102da99eca58536a

Dwarf: add missing var args info on function decls


5 files changed, 44 insertions(+), 9 deletions(-)

src/arch/x86_64/CodeGen.zig+28-9
......@@ -59,6 +59,7 @@ owner: Owner,
5959inline_func: InternPool.Index,
6060mod: *Package.Module,
6161err_msg: ?*ErrorMsg,
62arg_index: u32,
6263args: []MCValue,
6364va_info: union {
6465 sysv: struct {
......@@ -71,7 +72,6 @@ va_info: union {
7172},
7273ret_mcv: InstTracking,
7374fn_type: Type,
74arg_index: u32,
7575src_loc: Zcu.LazySrcLoc,
7676
7777eflags_inst: ?Air.Inst.Index = null,
......@@ -802,11 +802,11 @@ pub fn generate(
802802 .owner = .{ .nav_index = func.owner_nav },
803803 .inline_func = func_index,
804804 .err_msg = null,
805 .arg_index = undefined,
805806 .args = undefined, // populated after `resolveCallingConventionValues`
806807 .va_info = undefined, // populated after `resolveCallingConventionValues`
807808 .ret_mcv = undefined, // populated after `resolveCallingConventionValues`
808809 .fn_type = fn_type,
809 .arg_index = 0,
810810 .src_loc = src_loc,
811811 .end_di_line = func.rbrace_line,
812812 .end_di_column = func.rbrace_column,
......@@ -877,6 +877,7 @@ pub fn generate(
877877 }),
878878 );
879879 function.va_info = switch (cc) {
880 else => undefined,
880881 .SysV => .{ .sysv = .{
881882 .gp_count = call_info.gp_count,
882883 .fp_count = call_info.fp_count,
......@@ -884,7 +885,6 @@ pub fn generate(
884885 .reg_save_area = undefined,
885886 } },
886887 .Win64 => .{ .win64 = .{} },
887 else => undefined,
888888 };
889889
890890 function.gen() catch |err| switch (err) {
......@@ -978,11 +978,11 @@ pub fn generateLazy(
978978 .owner = .{ .lazy_sym = lazy_sym },
979979 .inline_func = undefined,
980980 .err_msg = null,
981 .arg_index = undefined,
981982 .args = undefined,
982983 .va_info = undefined,
983984 .ret_mcv = undefined,
984985 .fn_type = undefined,
985 .arg_index = undefined,
986986 .src_loc = src_loc,
987987 .end_di_line = undefined, // no debug info yet
988988 .end_di_column = undefined, // no debug info yet
......@@ -1482,6 +1482,8 @@ fn asmOpOnly(self: *Self, tag: Mir.Inst.FixedTag) !void {
14821482}
14831483
14841484fn asmPseudo(self: *Self, ops: Mir.Inst.Ops) !void {
1485 assert(std.mem.startsWith(u8, @tagName(ops), "pseudo_") and
1486 std.mem.endsWith(u8, @tagName(ops), "_none"));
14851487 _ = try self.addInst(.{
14861488 .tag = .pseudo,
14871489 .ops = ops,
......@@ -2101,6 +2103,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
21012103 const ip = &mod.intern_pool;
21022104 const air_tags = self.air.instructions.items(.tag);
21032105
2106 self.arg_index = 0;
21042107 for (body) |inst| {
21052108 wip_mir_log.debug("{}", .{self.fmtAir(inst)});
21062109 verbose_tracking_log.debug("{}", .{self.fmtTracking()});
......@@ -2114,6 +2117,8 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
21142117 self.checkInvariantsAfterAirInst(inst, old_air_bookkeeping);
21152118 }
21162119
2120 if (self.arg_index == 0) try self.airDbgVarArgs();
2121 self.arg_index = 0;
21172122 for (body) |inst| {
21182123 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip)) continue;
21192124 wip_mir_log.debug("{}", .{self.fmtAir(inst)});
......@@ -12055,11 +12060,25 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
1205512060}
1205612061
1205712062fn airDbgArg(self: *Self, inst: Air.Inst.Index) !void {
12058 defer self.finishAirBookkeeping();
12059 if (self.debug_output == .none) return;
12060 const name = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.name;
12061 if (name != .none) try self.genLocalDebugInfo(inst, self.getResolvedInstValue(inst).short);
12062 if (self.liveness.isUnused(inst)) try self.processDeath(inst);
12063 // skip zero-bit arguments as they don't have a corresponding arg instruction
12064 var arg_index = self.arg_index;
12065 while (self.args[arg_index] == .none) arg_index += 1;
12066 self.arg_index = arg_index + 1;
12067
12068 if (self.debug_output != .none) {
12069 const name = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.name;
12070 if (name != .none) try self.genLocalDebugInfo(inst, self.getResolvedInstValue(inst).short);
12071 if (self.liveness.isUnused(inst)) try self.processDeath(inst);
12072 }
12073 for (self.args[self.arg_index..]) |arg| {
12074 if (arg != .none) break;
12075 } else try self.airDbgVarArgs();
12076 self.finishAirBookkeeping();
12077}
12078
12079fn airDbgVarArgs(self: *Self) !void {
12080 if (self.pt.zcu.typeToFunc(self.fn_type).?.is_var_args)
12081 try self.asmPseudo(.pseudo_dbg_var_args_none);
1206312082}
1206412083
1206512084fn genLocalDebugInfo(
src/arch/x86_64/Emit.zig+7
......@@ -384,6 +384,13 @@ pub fn emitMir(emit: *Emit) Error!void {
384384 .none => {},
385385 }
386386 },
387 .pseudo_dbg_var_args_none => {
388 switch (emit.debug_output) {
389 .dwarf => |dw| try dw.genVarArgsDebugInfo(),
390 .plan9 => {},
391 .none => {},
392 }
393 },
387394 .pseudo_dead_none => {},
388395 },
389396 }
src/arch/x86_64/Lower.zig+1
......@@ -279,6 +279,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct {
279279 .pseudo_dbg_local_aro,
280280 .pseudo_dbg_local_af,
281281 .pseudo_dbg_local_am,
282 .pseudo_dbg_var_args_none,
282283 .pseudo_dead_none,
283284 => {},
284285 else => unreachable,
src/arch/x86_64/Mir.zig+2
......@@ -924,6 +924,8 @@ pub const Inst = struct {
924924 /// Local argument or variable.
925925 /// Uses `ax` payload with extra data of type `Memory`.
926926 pseudo_dbg_local_am,
927 /// Remaining arguments are varargs.
928 pseudo_dbg_var_args_none,
927929
928930 /// Tombstone
929931 /// Emitter should skip this instruction.
src/link/Dwarf.zig+6
......@@ -1108,6 +1108,12 @@ pub const WipNav = struct {
11081108 wip_nav.any_children = true;
11091109 }
11101110
1111 pub fn genVarArgsDebugInfo(wip_nav: *WipNav) UpdateError!void {
1112 assert(wip_nav.func != .none);
1113 try wip_nav.abbrevCode(.is_var_args);
1114 wip_nav.any_children = true;
1115 }
1116
11111117 pub fn advancePCAndLine(
11121118 wip_nav: *WipNav,
11131119 delta_line: i33,