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,...@@ -59,6 +59,7 @@ owner: Owner,
59inline_func: InternPool.Index,59inline_func: InternPool.Index,
60mod: *Package.Module,60mod: *Package.Module,
61err_msg: ?*ErrorMsg,61err_msg: ?*ErrorMsg,
62arg_index: u32,
62args: []MCValue,63args: []MCValue,
63va_info: union {64va_info: union {
64 sysv: struct {65 sysv: struct {
...@@ -71,7 +72,6 @@ va_info: union {...@@ -71,7 +72,6 @@ va_info: union {
71},72},
72ret_mcv: InstTracking,73ret_mcv: InstTracking,
73fn_type: Type,74fn_type: Type,
74arg_index: u32,
75src_loc: Zcu.LazySrcLoc,75src_loc: Zcu.LazySrcLoc,
7676
77eflags_inst: ?Air.Inst.Index = null,77eflags_inst: ?Air.Inst.Index = null,
...@@ -802,11 +802,11 @@ pub fn generate(...@@ -802,11 +802,11 @@ pub fn generate(
802 .owner = .{ .nav_index = func.owner_nav },802 .owner = .{ .nav_index = func.owner_nav },
803 .inline_func = func_index,803 .inline_func = func_index,
804 .err_msg = null,804 .err_msg = null,
805 .arg_index = undefined,
805 .args = undefined, // populated after `resolveCallingConventionValues`806 .args = undefined, // populated after `resolveCallingConventionValues`
806 .va_info = undefined, // populated after `resolveCallingConventionValues`807 .va_info = undefined, // populated after `resolveCallingConventionValues`
807 .ret_mcv = undefined, // populated after `resolveCallingConventionValues`808 .ret_mcv = undefined, // populated after `resolveCallingConventionValues`
808 .fn_type = fn_type,809 .fn_type = fn_type,
809 .arg_index = 0,
810 .src_loc = src_loc,810 .src_loc = src_loc,
811 .end_di_line = func.rbrace_line,811 .end_di_line = func.rbrace_line,
812 .end_di_column = func.rbrace_column,812 .end_di_column = func.rbrace_column,
...@@ -877,6 +877,7 @@ pub fn generate(...@@ -877,6 +877,7 @@ pub fn generate(
877 }),877 }),
878 );878 );
879 function.va_info = switch (cc) {879 function.va_info = switch (cc) {
880 else => undefined,
880 .SysV => .{ .sysv = .{881 .SysV => .{ .sysv = .{
881 .gp_count = call_info.gp_count,882 .gp_count = call_info.gp_count,
882 .fp_count = call_info.fp_count,883 .fp_count = call_info.fp_count,
...@@ -884,7 +885,6 @@ pub fn generate(...@@ -884,7 +885,6 @@ pub fn generate(
884 .reg_save_area = undefined,885 .reg_save_area = undefined,
885 } },886 } },
886 .Win64 => .{ .win64 = .{} },887 .Win64 => .{ .win64 = .{} },
887 else => undefined,
888 };888 };
889889
890 function.gen() catch |err| switch (err) {890 function.gen() catch |err| switch (err) {
...@@ -978,11 +978,11 @@ pub fn generateLazy(...@@ -978,11 +978,11 @@ pub fn generateLazy(
978 .owner = .{ .lazy_sym = lazy_sym },978 .owner = .{ .lazy_sym = lazy_sym },
979 .inline_func = undefined,979 .inline_func = undefined,
980 .err_msg = null,980 .err_msg = null,
981 .arg_index = undefined,
981 .args = undefined,982 .args = undefined,
982 .va_info = undefined,983 .va_info = undefined,
983 .ret_mcv = undefined,984 .ret_mcv = undefined,
984 .fn_type = undefined,985 .fn_type = undefined,
985 .arg_index = undefined,
986 .src_loc = src_loc,986 .src_loc = src_loc,
987 .end_di_line = undefined, // no debug info yet987 .end_di_line = undefined, // no debug info yet
988 .end_di_column = undefined, // no debug info yet988 .end_di_column = undefined, // no debug info yet
...@@ -1482,6 +1482,8 @@ fn asmOpOnly(self: *Self, tag: Mir.Inst.FixedTag) !void {...@@ -1482,6 +1482,8 @@ fn asmOpOnly(self: *Self, tag: Mir.Inst.FixedTag) !void {
1482}1482}
14831483
1484fn asmPseudo(self: *Self, ops: Mir.Inst.Ops) !void {1484fn 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"));
1485 _ = try self.addInst(.{1487 _ = try self.addInst(.{
1486 .tag = .pseudo,1488 .tag = .pseudo,
1487 .ops = ops,1489 .ops = ops,
...@@ -2101,6 +2103,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -2101,6 +2103,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
2101 const ip = &mod.intern_pool;2103 const ip = &mod.intern_pool;
2102 const air_tags = self.air.instructions.items(.tag);2104 const air_tags = self.air.instructions.items(.tag);
21032105
2106 self.arg_index = 0;
2104 for (body) |inst| {2107 for (body) |inst| {
2105 wip_mir_log.debug("{}", .{self.fmtAir(inst)});2108 wip_mir_log.debug("{}", .{self.fmtAir(inst)});
2106 verbose_tracking_log.debug("{}", .{self.fmtTracking()});2109 verbose_tracking_log.debug("{}", .{self.fmtTracking()});
...@@ -2114,6 +2117,8 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -2114,6 +2117,8 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
2114 self.checkInvariantsAfterAirInst(inst, old_air_bookkeeping);2117 self.checkInvariantsAfterAirInst(inst, old_air_bookkeeping);
2115 }2118 }
21162119
2120 if (self.arg_index == 0) try self.airDbgVarArgs();
2121 self.arg_index = 0;
2117 for (body) |inst| {2122 for (body) |inst| {
2118 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip)) continue;2123 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip)) continue;
2119 wip_mir_log.debug("{}", .{self.fmtAir(inst)});2124 wip_mir_log.debug("{}", .{self.fmtAir(inst)});
...@@ -12055,11 +12060,25 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {...@@ -12055,11 +12060,25 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
12055}12060}
1205612061
12057fn airDbgArg(self: *Self, inst: Air.Inst.Index) !void {12062fn airDbgArg(self: *Self, inst: Air.Inst.Index) !void {
12058 defer self.finishAirBookkeeping();12063 // skip zero-bit arguments as they don't have a corresponding arg instruction
12059 if (self.debug_output == .none) return;12064 var arg_index = self.arg_index;
12060 const name = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.name;12065 while (self.args[arg_index] == .none) arg_index += 1;
12061 if (name != .none) try self.genLocalDebugInfo(inst, self.getResolvedInstValue(inst).short);12066 self.arg_index = arg_index + 1;
12062 if (self.liveness.isUnused(inst)) try self.processDeath(inst);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);
12063}12082}
1206412083
12065fn genLocalDebugInfo(12084fn genLocalDebugInfo(
src/arch/x86_64/Emit.zig+7
...@@ -384,6 +384,13 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -384,6 +384,13 @@ pub fn emitMir(emit: *Emit) Error!void {
384 .none => {},384 .none => {},
385 }385 }
386 },386 },
387 .pseudo_dbg_var_args_none => {
388 switch (emit.debug_output) {
389 .dwarf => |dw| try dw.genVarArgsDebugInfo(),
390 .plan9 => {},
391 .none => {},
392 }
393 },
387 .pseudo_dead_none => {},394 .pseudo_dead_none => {},
388 },395 },
389 }396 }
src/arch/x86_64/Lower.zig+1
...@@ -279,6 +279,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct {...@@ -279,6 +279,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct {
279 .pseudo_dbg_local_aro,279 .pseudo_dbg_local_aro,
280 .pseudo_dbg_local_af,280 .pseudo_dbg_local_af,
281 .pseudo_dbg_local_am,281 .pseudo_dbg_local_am,
282 .pseudo_dbg_var_args_none,
282 .pseudo_dead_none,283 .pseudo_dead_none,
283 => {},284 => {},
284 else => unreachable,285 else => unreachable,
src/arch/x86_64/Mir.zig+2
...@@ -924,6 +924,8 @@ pub const Inst = struct {...@@ -924,6 +924,8 @@ pub const Inst = struct {
924 /// Local argument or variable.924 /// Local argument or variable.
925 /// Uses `ax` payload with extra data of type `Memory`.925 /// Uses `ax` payload with extra data of type `Memory`.
926 pseudo_dbg_local_am,926 pseudo_dbg_local_am,
927 /// Remaining arguments are varargs.
928 pseudo_dbg_var_args_none,
927929
928 /// Tombstone930 /// Tombstone
929 /// Emitter should skip this instruction.931 /// Emitter should skip this instruction.
src/link/Dwarf.zig+6
...@@ -1108,6 +1108,12 @@ pub const WipNav = struct {...@@ -1108,6 +1108,12 @@ pub const WipNav = struct {
1108 wip_nav.any_children = true;1108 wip_nav.any_children = true;
1109 }1109 }
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
1111 pub fn advancePCAndLine(1117 pub fn advancePCAndLine(
1112 wip_nav: *WipNav,1118 wip_nav: *WipNav,
1113 delta_line: i33,1119 delta_line: i33,