authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-04-21 20:17:41+07:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-05-05 19:34:05+02:00
logc73eb00727e70e6d5224b371b5d0dc4ac6af4dd3
treedc08f6dbd0e4d02bb905b6e0e9413cc858f3e91f
parente76d52c74dbb7566af75baf7184b04f131d26d5f

stage2: sparcv9: Add debug info generation for args


1 files changed, 56 insertions(+), 0 deletions(-)

src/arch/sparcv9/CodeGen.zig+56
......@@ -780,6 +780,8 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
780780 // TODO Copy registers to the stack
781781 const mcv = result;
782782
783 try self.genArgDbgInfo(inst, mcv, @intCast(u32, arg_index));
784
783785 if (self.liveness.isUnused(inst))
784786 return self.finishAirBookkeeping();
785787
......@@ -1038,6 +1040,26 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
10381040
10391041// Common helper functions
10401042
1043/// Adds a Type to the .debug_info at the current position. The bytes will be populated later,
1044/// after codegen for this symbol is done.
1045fn addDbgInfoTypeReloc(self: *Self, ty: Type) !void {
1046 switch (self.debug_output) {
1047 .dwarf => |dw| {
1048 assert(ty.hasRuntimeBits());
1049 const dbg_info = &dw.dbg_info;
1050 const index = dbg_info.items.len;
1051 try dbg_info.resize(index + 4); // DW.AT.type, DW.FORM.ref4
1052 const mod = self.bin_file.options.module.?;
1053 const atom = switch (self.bin_file.tag) {
1054 .elf => &mod.declPtr(self.mod_fn.owner_decl).link.elf.dbg_info_atom,
1055 else => unreachable,
1056 };
1057 try dw.addTypeReloc(atom, ty, @intCast(u32, index), null);
1058 },
1059 else => {},
1060 }
1061}
1062
10411063fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
10421064 const gpa = self.gpa;
10431065 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);
......@@ -1166,6 +1188,40 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live
11661188 self.finishAirBookkeeping();
11671189}
11681190
1191fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void {
1192 const ty = self.air.instructions.items(.data)[inst].ty;
1193 const name = self.mod_fn.getParamName(arg_index);
1194 const name_with_null = name.ptr[0 .. name.len + 1];
1195
1196 switch (mcv) {
1197 .register => |reg| {
1198 switch (self.debug_output) {
1199 .dwarf => |dw| {
1200 const dbg_info = &dw.dbg_info;
1201 try dbg_info.ensureUnusedCapacity(3);
1202 dbg_info.appendAssumeCapacity(@enumToInt(link.File.Dwarf.AbbrevKind.parameter));
1203 dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc
1204 1, // ULEB128 dwarf expression length
1205 reg.dwarfLocOp(),
1206 });
1207 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
1208 try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4
1209 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
1210 },
1211 else => {},
1212 }
1213 },
1214 .stack_offset => |offset| {
1215 _ = offset;
1216 switch (self.debug_output) {
1217 .dwarf => {},
1218 else => {},
1219 }
1220 },
1221 else => {},
1222 }
1223}
1224
11691225fn genLoad(self: *Self, value_reg: Register, addr_reg: Register, comptime off_type: type, off: off_type, abi_size: u64) !void {
11701226 assert(off_type == Register or off_type == i13);
11711227