authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-02 12:22:17+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-02 12:22:17+01:00
log3ec0520bac74cf750482abae0c8ce09344299613
tree8581b608feb1ec517315a29b5f3e0a7f6cd4a1ca
parent8fea84f77ebc6805fe4558ae73064955dbfdcb64

dwarf: use common DI union object for arg and var gen


6 files changed, 83 insertions(+), 87 deletions(-)

src/arch/aarch64/CodeGen.zig+19-23
......@@ -185,28 +185,26 @@ const DbgInfoReloc = struct {
185185 const atom = function.getDbgInfoAtomPtr();
186186
187187 switch (function.debug_output) {
188 .dwarf => |dw| switch (reloc.mcv) {
189 .register => |reg| try dw.genArgDbgInfo(reloc.name, reloc.ty, atom, .{
190 .register = reg.dwarfLocOp(),
191 }),
192
193 .stack_offset,
194 .stack_argument_offset,
195 => |offset| {
196 const adjusted_offset = switch (reloc.mcv) {
197 .stack_offset => -@intCast(i32, offset),
198 .stack_argument_offset => @intCast(i32, function.saved_regs_stack_space + offset),
199 else => unreachable,
200 };
201 try dw.genArgDbgInfo(reloc.name, reloc.ty, atom, .{
202 .stack = .{
188 .dwarf => |dw| {
189 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (reloc.mcv) {
190 .register => |reg| .{ .register = reg.dwarfLocOp() },
191 .stack_offset,
192 .stack_argument_offset,
193 => |offset| blk: {
194 const adjusted_offset = switch (reloc.mcv) {
195 .stack_offset => -@intCast(i32, offset),
196 .stack_argument_offset => @intCast(i32, function.saved_regs_stack_space + offset),
197 else => unreachable,
198 };
199 break :blk .{ .stack = .{
203200 .fp_register = Register.x29.dwarfLocOpDeref(),
204201 .offset = adjusted_offset,
205 },
206 });
207 },
202 } };
203 },
204 else => unreachable, // not a possible argument
208205
209 else => unreachable, // not a possible argument
206 };
207 try dw.genArgDbgInfo(reloc.name, reloc.ty, atom, loc);
210208 },
211209 .plan9 => {},
212210 .none => {},
......@@ -223,10 +221,8 @@ const DbgInfoReloc = struct {
223221
224222 switch (function.debug_output) {
225223 .dwarf => |dw| {
226 const loc: link.File.Dwarf.DeclState.VarArgDbgInfoLoc = switch (reloc.mcv) {
227 .register => |reg| .{
228 .register = reg.dwarfLocOp(),
229 },
224 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (reloc.mcv) {
225 .register => |reg| .{ .register = reg.dwarfLocOp() },
230226 .ptr_stack_offset,
231227 .stack_offset,
232228 .stack_argument_offset,
src/arch/arm/CodeGen.zig+18-18
......@@ -4036,26 +4036,26 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMe
40364036 const atom = self.getDbgInfoAtom();
40374037
40384038 switch (self.debug_output) {
4039 .dwarf => |dw| switch (mcv) {
4040 .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{
4041 .register = reg.dwarfLocOp(),
4042 }),
4043 .stack_offset,
4044 .stack_argument_offset,
4045 => {
4046 const adjusted_stack_offset = switch (mcv) {
4047 .stack_offset => |offset| -@intCast(i32, offset),
4048 .stack_argument_offset => |offset| @intCast(i32, self.saved_regs_stack_space + offset),
4049 else => unreachable,
4050 };
4051 try dw.genArgDbgInfo(name, ty, atom, .{
4052 .stack = .{
4039 .dwarf => |dw| {
4040 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (mcv) {
4041 .register => |reg| .{ .register = reg.dwarfLocOp() },
4042 .stack_offset,
4043 .stack_argument_offset,
4044 => blk: {
4045 const adjusted_stack_offset = switch (mcv) {
4046 .stack_offset => |offset| -@intCast(i32, offset),
4047 .stack_argument_offset => |offset| @intCast(i32, self.saved_regs_stack_space + offset),
4048 else => unreachable,
4049 };
4050 break :blk .{ .stack = .{
40534051 .fp_register = DW.OP.breg11,
40544052 .offset = adjusted_stack_offset,
4055 },
4056 });
4057 },
4058 else => unreachable, // not a possible argument
4053 } };
4054 },
4055 else => unreachable, // not a possible argument
4056
4057 };
4058 try dw.genArgDbgInfo(name, ty, atom, loc);
40594059 },
40604060 .plan9 => {},
40614061 .none => {},
src/arch/riscv64/CodeGen.zig+13-9
......@@ -1602,17 +1602,10 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
16021602 return self.fail("TODO implement codegen airFieldParentPtr", .{});
16031603}
16041604
1605fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void {
1605fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void {
16061606 const ty = self.air.instructions.items(.data)[inst].ty;
16071607 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);
1608
1609 const mod = self.bin_file.options.module.?;
1610 const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl);
1611 const atom = switch (self.bin_file.tag) {
1612 .elf => &fn_owner_decl.link.elf.dbg_info_atom,
1613 .macho => &fn_owner_decl.link.macho.dbg_info_atom,
1614 else => unreachable,
1615 };
1608 const atom = self.getDbgIntoAtomPtr();
16161609
16171610 switch (self.debug_output) {
16181611 .dwarf => |dw| switch (mcv) {
......@@ -1627,6 +1620,17 @@ fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32
16271620 }
16281621}
16291622
1623fn getDbgIntoAtomPtr(self: Self) *link.File.Dwarf.Atom {
1624 const mod = self.bin_file.options.module.?;
1625 const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl);
1626 const atom = switch (self.bin_file.tag) {
1627 .elf => &fn_owner_decl.link.elf.dbg_info_atom,
1628 .macho => &fn_owner_decl.link.macho.dbg_info_atom,
1629 else => unreachable,
1630 };
1631 return atom;
1632}
1633
16301634fn airArg(self: *Self, inst: Air.Inst.Index) !void {
16311635 const arg_index = self.arg_index;
16321636 self.arg_index += 1;
src/arch/wasm/CodeGen.zig+1-1
......@@ -5327,7 +5327,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void {
53275327 log.debug(" var name = ({s})", .{name});
53285328
53295329 const atom = func.getDbgInfoAtom();
5330 const loc: link.File.Dwarf.DeclState.VarArgDbgInfoLoc = switch (operand) {
5330 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (operand) {
53315331 .local => |local| .{ .wasm_local = local.value },
53325332 else => blk: {
53335333 log.debug("TODO generate debug info for {}", .{operand});
src/arch/x86_64/CodeGen.zig+14-15
......@@ -3818,18 +3818,19 @@ fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void {
38183818 const atom = self.getDbgInfoAtomPtr();
38193819
38203820 switch (self.debug_output) {
3821 .dwarf => |dw| switch (mcv) {
3822 .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{
3823 .register = reg.dwarfLocOp(),
3824 }),
3825 .stack_offset => |off| try dw.genArgDbgInfo(name, ty, atom, .{
3826 .stack = .{
3827 .fp_register = Register.rbp.dwarfLocOpDeref(), // TODO handle -fomit-frame-pointer
3828 .offset = -off,
3821 .dwarf => |dw| {
3822 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (mcv) {
3823 .register => |reg| .{ .register = reg.dwarfLocOp() },
3824 .stack_offset => |off| .{
3825 .stack = .{
3826 // TODO handle -fomit-frame-pointer
3827 .fp_register = Register.rbp.dwarfLocOpDeref(),
3828 .offset = -off,
3829 },
38293830 },
3830 }),
3831
3832 else => unreachable, // not a valid function parameter
3831 else => unreachable, // not a valid function parameter
3832 };
3833 try dw.genArgDbgInfo(name, ty, atom, loc);
38333834 },
38343835 .plan9 => {},
38353836 .none => {},
......@@ -3852,10 +3853,8 @@ fn genVarDbgInfo(
38523853
38533854 switch (self.debug_output) {
38543855 .dwarf => |dw| {
3855 const loc: link.File.Dwarf.DeclState.VarArgDbgInfoLoc = switch (mcv) {
3856 .register => |reg| .{
3857 .register = reg.dwarfLocOp(),
3858 },
3856 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (mcv) {
3857 .register => |reg| .{ .register = reg.dwarfLocOp() },
38593858 .ptr_stack_offset,
38603859 .stack_offset,
38613860 => |off| .{ .stack = .{
src/link/Dwarf.zig+18-21
......@@ -562,16 +562,27 @@ pub const DeclState = struct {
562562 }
563563 }
564564
565 pub const DbgInfoLoc = union(enum) {
566 register: u8,
567 stack: struct {
568 fp_register: u8,
569 offset: i32,
570 },
571 wasm_local: u32,
572 memory: u64,
573 linker_load: LinkerLoad,
574 immediate: u64,
575 undef,
576 none,
577 nop,
578 };
579
565580 pub fn genArgDbgInfo(
566581 self: *DeclState,
567582 name: [:0]const u8,
568583 ty: Type,
569584 atom: *Atom,
570 loc: union(enum) {
571 register: u8,
572 stack: struct { fp_register: u8, offset: i32 },
573 wasm_local: u32,
574 },
585 loc: DbgInfoLoc,
575586 ) error{OutOfMemory}!void {
576587 const dbg_info = &self.dbg_info;
577588 const name_with_null = name.ptr[0 .. name.len + 1];
......@@ -612,6 +623,7 @@ pub const DeclState = struct {
612623 });
613624 leb128.writeULEB128(dbg_info.writer(), value) catch unreachable;
614625 },
626 else => unreachable,
615627 }
616628
617629 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
......@@ -621,28 +633,13 @@ pub const DeclState = struct {
621633 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
622634 }
623635
624 pub const VarArgDbgInfoLoc = union(enum) {
625 register: u8,
626 stack: struct {
627 fp_register: u8,
628 offset: i32,
629 },
630 wasm_local: u32,
631 memory: u64,
632 linker_load: LinkerLoad,
633 immediate: u64,
634 undef,
635 none,
636 nop,
637 };
638
639636 pub fn genVarDbgInfo(
640637 self: *DeclState,
641638 name: [:0]const u8,
642639 ty: Type,
643640 atom: *Atom,
644641 is_ptr: bool,
645 loc: VarArgDbgInfoLoc,
642 loc: DbgInfoLoc,
646643 ) error{OutOfMemory}!void {
647644 const dbg_info = &self.dbg_info;
648645 const name_with_null = name.ptr[0 .. name.len + 1];