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 {...@@ -185,28 +185,26 @@ const DbgInfoReloc = struct {
185 const atom = function.getDbgInfoAtomPtr();185 const atom = function.getDbgInfoAtomPtr();
186186
187 switch (function.debug_output) {187 switch (function.debug_output) {
188 .dwarf => |dw| switch (reloc.mcv) {188 .dwarf => |dw| {
189 .register => |reg| try dw.genArgDbgInfo(reloc.name, reloc.ty, atom, .{189 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (reloc.mcv) {
190 .register = reg.dwarfLocOp(),190 .register => |reg| .{ .register = reg.dwarfLocOp() },
191 }),191 .stack_offset,
192192 .stack_argument_offset,
193 .stack_offset,193 => |offset| blk: {
194 .stack_argument_offset,194 const adjusted_offset = switch (reloc.mcv) {
195 => |offset| {195 .stack_offset => -@intCast(i32, offset),
196 const adjusted_offset = switch (reloc.mcv) {196 .stack_argument_offset => @intCast(i32, function.saved_regs_stack_space + offset),
197 .stack_offset => -@intCast(i32, offset),197 else => unreachable,
198 .stack_argument_offset => @intCast(i32, function.saved_regs_stack_space + offset),198 };
199 else => unreachable,199 break :blk .{ .stack = .{
200 };
201 try dw.genArgDbgInfo(reloc.name, reloc.ty, atom, .{
202 .stack = .{
203 .fp_register = Register.x29.dwarfLocOpDeref(),200 .fp_register = Register.x29.dwarfLocOpDeref(),
204 .offset = adjusted_offset,201 .offset = adjusted_offset,
205 },202 } };
206 });203 },
207 },204 else => unreachable, // not a possible argument
208205
209 else => unreachable, // not a possible argument206 };
207 try dw.genArgDbgInfo(reloc.name, reloc.ty, atom, loc);
210 },208 },
211 .plan9 => {},209 .plan9 => {},
212 .none => {},210 .none => {},
...@@ -223,10 +221,8 @@ const DbgInfoReloc = struct {...@@ -223,10 +221,8 @@ const DbgInfoReloc = struct {
223221
224 switch (function.debug_output) {222 switch (function.debug_output) {
225 .dwarf => |dw| {223 .dwarf => |dw| {
226 const loc: link.File.Dwarf.DeclState.VarArgDbgInfoLoc = switch (reloc.mcv) {224 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (reloc.mcv) {
227 .register => |reg| .{225 .register => |reg| .{ .register = reg.dwarfLocOp() },
228 .register = reg.dwarfLocOp(),
229 },
230 .ptr_stack_offset,226 .ptr_stack_offset,
231 .stack_offset,227 .stack_offset,
232 .stack_argument_offset,228 .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...@@ -4036,26 +4036,26 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMe
4036 const atom = self.getDbgInfoAtom();4036 const atom = self.getDbgInfoAtom();
40374037
4038 switch (self.debug_output) {4038 switch (self.debug_output) {
4039 .dwarf => |dw| switch (mcv) {4039 .dwarf => |dw| {
4040 .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{4040 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (mcv) {
4041 .register = reg.dwarfLocOp(),4041 .register => |reg| .{ .register = reg.dwarfLocOp() },
4042 }),4042 .stack_offset,
4043 .stack_offset,4043 .stack_argument_offset,
4044 .stack_argument_offset,4044 => blk: {
4045 => {4045 const adjusted_stack_offset = switch (mcv) {
4046 const adjusted_stack_offset = switch (mcv) {4046 .stack_offset => |offset| -@intCast(i32, offset),
4047 .stack_offset => |offset| -@intCast(i32, offset),4047 .stack_argument_offset => |offset| @intCast(i32, self.saved_regs_stack_space + offset),
4048 .stack_argument_offset => |offset| @intCast(i32, self.saved_regs_stack_space + offset),4048 else => unreachable,
4049 else => unreachable,4049 };
4050 };4050 break :blk .{ .stack = .{
4051 try dw.genArgDbgInfo(name, ty, atom, .{
4052 .stack = .{
4053 .fp_register = DW.OP.breg11,4051 .fp_register = DW.OP.breg11,
4054 .offset = adjusted_stack_offset,4052 .offset = adjusted_stack_offset,
4055 },4053 } };
4056 });4054 },
4057 },4055 else => unreachable, // not a possible argument
4058 else => unreachable, // not a possible argument4056
4057 };
4058 try dw.genArgDbgInfo(name, ty, atom, loc);
4059 },4059 },
4060 .plan9 => {},4060 .plan9 => {},
4061 .none => {},4061 .none => {},
src/arch/riscv64/CodeGen.zig+13-9
...@@ -1602,17 +1602,10 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1602,17 +1602,10 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
1602 return self.fail("TODO implement codegen airFieldParentPtr", .{});1602 return self.fail("TODO implement codegen airFieldParentPtr", .{});
1603}1603}
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 {
1606 const ty = self.air.instructions.items(.data)[inst].ty;1606 const ty = self.air.instructions.items(.data)[inst].ty;
1607 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);1607 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);
16081608 const atom = self.getDbgIntoAtomPtr();
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 };
16161609
1617 switch (self.debug_output) {1610 switch (self.debug_output) {
1618 .dwarf => |dw| switch (mcv) {1611 .dwarf => |dw| switch (mcv) {
...@@ -1627,6 +1620,17 @@ fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32...@@ -1627,6 +1620,17 @@ fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32
1627 }1620 }
1628}1621}
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
1630fn airArg(self: *Self, inst: Air.Inst.Index) !void {1634fn airArg(self: *Self, inst: Air.Inst.Index) !void {
1631 const arg_index = self.arg_index;1635 const arg_index = self.arg_index;
1632 self.arg_index += 1;1636 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 {...@@ -5327,7 +5327,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void {
5327 log.debug(" var name = ({s})", .{name});5327 log.debug(" var name = ({s})", .{name});
53285328
5329 const atom = func.getDbgInfoAtom();5329 const atom = func.getDbgInfoAtom();
5330 const loc: link.File.Dwarf.DeclState.VarArgDbgInfoLoc = switch (operand) {5330 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (operand) {
5331 .local => |local| .{ .wasm_local = local.value },5331 .local => |local| .{ .wasm_local = local.value },
5332 else => blk: {5332 else => blk: {
5333 log.debug("TODO generate debug info for {}", .{operand});5333 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 {...@@ -3818,18 +3818,19 @@ fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void {
3818 const atom = self.getDbgInfoAtomPtr();3818 const atom = self.getDbgInfoAtomPtr();
38193819
3820 switch (self.debug_output) {3820 switch (self.debug_output) {
3821 .dwarf => |dw| switch (mcv) {3821 .dwarf => |dw| {
3822 .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{3822 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (mcv) {
3823 .register = reg.dwarfLocOp(),3823 .register => |reg| .{ .register = reg.dwarfLocOp() },
3824 }),3824 .stack_offset => |off| .{
3825 .stack_offset => |off| try dw.genArgDbgInfo(name, ty, atom, .{3825 .stack = .{
3826 .stack = .{3826 // TODO handle -fomit-frame-pointer
3827 .fp_register = Register.rbp.dwarfLocOpDeref(), // TODO handle -fomit-frame-pointer3827 .fp_register = Register.rbp.dwarfLocOpDeref(),
3828 .offset = -off,3828 .offset = -off,
3829 },
3829 },3830 },
3830 }),3831 else => unreachable, // not a valid function parameter
38313832 };
3832 else => unreachable, // not a valid function parameter3833 try dw.genArgDbgInfo(name, ty, atom, loc);
3833 },3834 },
3834 .plan9 => {},3835 .plan9 => {},
3835 .none => {},3836 .none => {},
...@@ -3852,10 +3853,8 @@ fn genVarDbgInfo(...@@ -3852,10 +3853,8 @@ fn genVarDbgInfo(
38523853
3853 switch (self.debug_output) {3854 switch (self.debug_output) {
3854 .dwarf => |dw| {3855 .dwarf => |dw| {
3855 const loc: link.File.Dwarf.DeclState.VarArgDbgInfoLoc = switch (mcv) {3856 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (mcv) {
3856 .register => |reg| .{3857 .register => |reg| .{ .register = reg.dwarfLocOp() },
3857 .register = reg.dwarfLocOp(),
3858 },
3859 .ptr_stack_offset,3858 .ptr_stack_offset,
3860 .stack_offset,3859 .stack_offset,
3861 => |off| .{ .stack = .{3860 => |off| .{ .stack = .{
src/link/Dwarf.zig+18-21
...@@ -562,16 +562,27 @@ pub const DeclState = struct {...@@ -562,16 +562,27 @@ pub const DeclState = struct {
562 }562 }
563 }563 }
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
565 pub fn genArgDbgInfo(580 pub fn genArgDbgInfo(
566 self: *DeclState,581 self: *DeclState,
567 name: [:0]const u8,582 name: [:0]const u8,
568 ty: Type,583 ty: Type,
569 atom: *Atom,584 atom: *Atom,
570 loc: union(enum) {585 loc: DbgInfoLoc,
571 register: u8,
572 stack: struct { fp_register: u8, offset: i32 },
573 wasm_local: u32,
574 },
575 ) error{OutOfMemory}!void {586 ) error{OutOfMemory}!void {
576 const dbg_info = &self.dbg_info;587 const dbg_info = &self.dbg_info;
577 const name_with_null = name.ptr[0 .. name.len + 1];588 const name_with_null = name.ptr[0 .. name.len + 1];
...@@ -612,6 +623,7 @@ pub const DeclState = struct {...@@ -612,6 +623,7 @@ pub const DeclState = struct {
612 });623 });
613 leb128.writeULEB128(dbg_info.writer(), value) catch unreachable;624 leb128.writeULEB128(dbg_info.writer(), value) catch unreachable;
614 },625 },
626 else => unreachable,
615 }627 }
616628
617 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);629 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
...@@ -621,28 +633,13 @@ pub const DeclState = struct {...@@ -621,28 +633,13 @@ pub const DeclState = struct {
621 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string633 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
622 }634 }
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
639 pub fn genVarDbgInfo(636 pub fn genVarDbgInfo(
640 self: *DeclState,637 self: *DeclState,
641 name: [:0]const u8,638 name: [:0]const u8,
642 ty: Type,639 ty: Type,
643 atom: *Atom,640 atom: *Atom,
644 is_ptr: bool,641 is_ptr: bool,
645 loc: VarArgDbgInfoLoc,642 loc: DbgInfoLoc,
646 ) error{OutOfMemory}!void {643 ) error{OutOfMemory}!void {
647 const dbg_info = &self.dbg_info;644 const dbg_info = &self.dbg_info;
648 const name_with_null = name.ptr[0 .. name.len + 1];645 const name_with_null = name.ptr[0 .. name.len + 1];