From 7d0af639d82bc22b204e20b11f5f6aee1ed1766e Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Thu, 1 Dec 2022 14:32:09 +0100 Subject: dwarf: update arm and riscv codegens to the new model --- src/arch/arm/CodeGen.zig | 103 ++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 73 deletions(-) (limited to 'src/arch/arm/CodeGen.zig') diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index 970b9376e5..c58147a71d 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -4029,86 +4029,43 @@ fn genInlineMemsetCode( // end: } -/// Adds a Type to the .debug_info at the current position. The bytes will be populated later, -/// after codegen for this symbol is done. -fn addDbgInfoTypeReloc(self: *Self, ty: Type) error{OutOfMemory}!void { - switch (self.debug_output) { - .dwarf => |dw| { - assert(ty.hasRuntimeBits()); - const dbg_info = &dw.dbg_info; - const index = dbg_info.items.len; - try dbg_info.resize(index + 4); // DW.AT.type, DW.FORM.ref4 - const mod = self.bin_file.options.module.?; - const atom = switch (self.bin_file.tag) { - .elf => &mod.declPtr(self.mod_fn.owner_decl).link.elf.dbg_info_atom, - .macho => unreachable, - else => unreachable, - }; - try dw.addTypeRelocGlobal(atom, ty, @intCast(u32, index)); - }, - .plan9 => {}, - .none => {}, - } -} - fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMemory}!void { const mcv = self.args[arg_index]; const ty = self.air.instructions.items(.data)[inst].ty; const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index); - const name_with_null = name.ptr[0 .. name.len + 1]; - switch (mcv) { - .register => |reg| { - switch (self.debug_output) { - .dwarf => |dw| { - const dbg_info = &dw.dbg_info; - try dbg_info.ensureUnusedCapacity(3); - dbg_info.appendAssumeCapacity(@enumToInt(link.File.Dwarf.AbbrevKind.parameter)); - dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc - 1, // ULEB128 dwarf expression length - reg.dwarfLocOp(), - }); - try dbg_info.ensureUnusedCapacity(5 + name_with_null.len); - try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4 - dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string - }, - .plan9 => {}, - .none => {}, - } - }, - .stack_offset, - .stack_argument_offset, - => { - switch (self.debug_output) { - .dwarf => |dw| { - const adjusted_stack_offset = switch (mcv) { - .stack_offset => |offset| -@intCast(i32, offset), - .stack_argument_offset => |offset| @intCast(i32, self.saved_regs_stack_space + offset), - else => unreachable, - }; - - const dbg_info = &dw.dbg_info; - try dbg_info.append(@enumToInt(link.File.Dwarf.AbbrevKind.parameter)); - - // Get length of the LEB128 stack offset - var counting_writer = std.io.countingWriter(std.io.null_writer); - leb128.writeILEB128(counting_writer.writer(), adjusted_stack_offset) catch unreachable; - - // DW.AT.location, DW.FORM.exprloc - // ULEB128 dwarf expression length - try leb128.writeULEB128(dbg_info.writer(), counting_writer.bytes_written + 1); - try dbg_info.append(DW.OP.breg11); - try leb128.writeILEB128(dbg_info.writer(), adjusted_stack_offset); + const mod = self.bin_file.options.module.?; + const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); + const atom = switch (self.bin_file.tag) { + .elf => &fn_owner_decl.link.elf.dbg_info_atom, + .macho => &fn_owner_decl.link.macho.dbg_info_atom, + else => unreachable, + }; - try dbg_info.ensureUnusedCapacity(5 + name_with_null.len); - try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4 - dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string - }, - .plan9 => {}, - .none => {}, - } + switch (self.debug_output) { + .dwarf => |dw| switch (mcv) { + .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{ + .register = reg.dwarfLocOp(), + }), + .stack_offset, + .stack_argument_offset, + => { + const adjusted_stack_offset = switch (mcv) { + .stack_offset => |offset| -@intCast(i32, offset), + .stack_argument_offset => |offset| @intCast(i32, self.saved_regs_stack_space + offset), + else => unreachable, + }; + try dw.genArgDbgInfo(name, ty, atom, .{ + .stack = .{ + .fp_register = DW.OP.breg11, + .offset = adjusted_stack_offset, + }, + }); + }, + else => unreachable, // not a possible argument }, - else => unreachable, // not a possible argument + .plan9 => {}, + .none => {}, } } -- cgit v1.2.3 From 17ab40f755a038bd9c06c7817354f9ce2eb4353f Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Thu, 1 Dec 2022 20:06:11 +0100 Subject: dwarf: refactor arm and riscv64 to the new scheme --- src/arch/arm/CodeGen.zig | 22 ++++++++------- src/arch/sparc64/CodeGen.zig | 64 +++++++++++++------------------------------- 2 files changed, 31 insertions(+), 55 deletions(-) (limited to 'src/arch/arm/CodeGen.zig') diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index c58147a71d..066a82e5a2 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -4029,18 +4029,11 @@ fn genInlineMemsetCode( // end: } -fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMemory}!void { +fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMemory}!void { const mcv = self.args[arg_index]; const ty = self.air.instructions.items(.data)[inst].ty; const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index); - - const mod = self.bin_file.options.module.?; - const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); - const atom = switch (self.bin_file.tag) { - .elf => &fn_owner_decl.link.elf.dbg_info_atom, - .macho => &fn_owner_decl.link.macho.dbg_info_atom, - else => unreachable, - }; + const atom = self.getDbgInfoAtom(); switch (self.debug_output) { .dwarf => |dw| switch (mcv) { @@ -4069,6 +4062,17 @@ fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfM } } +fn getDbgInfoAtom(self: Self) *link.File.Dwarf.Atom { + const mod = self.bin_file.options.module.?; + const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); + const atom = switch (self.bin_file.tag) { + .elf => &fn_owner_decl.link.elf.dbg_info_atom, + .macho => &fn_owner_decl.link.macho.dbg_info_atom, + else => unreachable, + }; + return atom; +} + fn airArg(self: *Self, inst: Air.Inst.Index) !void { const arg_index = self.arg_index; self.arg_index += 1; diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig index f22849c652..66d14f755b 100644 --- a/src/arch/sparc64/CodeGen.zig +++ b/src/arch/sparc64/CodeGen.zig @@ -2460,26 +2460,6 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void { // Common helper functions -/// Adds a Type to the .debug_info at the current position. The bytes will be populated later, -/// after codegen for this symbol is done. -fn addDbgInfoTypeReloc(self: *Self, ty: Type) !void { - switch (self.debug_output) { - .dwarf => |dw| { - assert(ty.hasRuntimeBits()); - const dbg_info = &dw.dbg_info; - const index = dbg_info.items.len; - try dbg_info.resize(index + 4); // DW.AT.type, DW.FORM.ref4 - const mod = self.bin_file.options.module.?; - const atom = switch (self.bin_file.tag) { - .elf => &mod.declPtr(self.mod_fn.owner_decl).link.elf.dbg_info_atom, - else => unreachable, - }; - try dw.addTypeRelocGlobal(atom, ty, @intCast(u32, index)); - }, - else => {}, - } -} - fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index { const gpa = self.gpa; try self.mir_instructions.ensureUnusedCapacity(gpa, 1); @@ -3272,40 +3252,32 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live self.finishAirBookkeeping(); } -fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void { +fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void { const ty = self.air.instructions.items(.data)[inst].ty; const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index); - const name_with_null = name.ptr[0 .. name.len + 1]; + const atom = self.getDbgInfoAtomPtr(); - switch (mcv) { - .register => |reg| { - switch (self.debug_output) { - .dwarf => |dw| { - const dbg_info = &dw.dbg_info; - try dbg_info.ensureUnusedCapacity(3); - dbg_info.appendAssumeCapacity(@enumToInt(link.File.Dwarf.AbbrevKind.parameter)); - dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc - 1, // ULEB128 dwarf expression length - reg.dwarfLocOp(), - }); - try dbg_info.ensureUnusedCapacity(5 + name_with_null.len); - try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4 - dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string - }, - else => {}, - } - }, - .stack_offset => |offset| { - _ = offset; - switch (self.debug_output) { - .dwarf => {}, - else => {}, - } + switch (self.debug_output) { + .dwarf => |dw| switch (mcv) { + .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{ + .register = reg.dwarfLocOp(), + }), + else => {}, }, else => {}, } } +fn getDbgInfoAtomPtr(self: Self) *link.File.Dwarf.Atom { + const mod = self.bin_file.options.module.?; + const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); + const atom = switch (self.bin_file.tag) { + .elf => &fn_owner_decl.link.elf.dbg_info_atom, + else => unreachable, + }; + return atom; +} + // TODO replace this to call to extern memcpy fn genInlineMemcpy( self: *Self, -- cgit v1.2.3 From 3ec0520bac74cf750482abae0c8ce09344299613 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 2 Dec 2022 12:22:17 +0100 Subject: dwarf: use common DI union object for arg and var gen --- src/arch/aarch64/CodeGen.zig | 42 +++++++++++++++++++----------------------- src/arch/arm/CodeGen.zig | 36 ++++++++++++++++++------------------ src/arch/riscv64/CodeGen.zig | 22 +++++++++++++--------- src/arch/wasm/CodeGen.zig | 2 +- src/arch/x86_64/CodeGen.zig | 29 ++++++++++++++--------------- src/link/Dwarf.zig | 39 ++++++++++++++++++--------------------- 6 files changed, 83 insertions(+), 87 deletions(-) (limited to 'src/arch/arm/CodeGen.zig') diff --git a/src/arch/aarch64/CodeGen.zig b/src/arch/aarch64/CodeGen.zig index ae24178a5a..7bf0f99a84 100644 --- a/src/arch/aarch64/CodeGen.zig +++ b/src/arch/aarch64/CodeGen.zig @@ -185,28 +185,26 @@ const DbgInfoReloc = struct { const atom = function.getDbgInfoAtomPtr(); switch (function.debug_output) { - .dwarf => |dw| switch (reloc.mcv) { - .register => |reg| try dw.genArgDbgInfo(reloc.name, reloc.ty, atom, .{ - .register = reg.dwarfLocOp(), - }), - - .stack_offset, - .stack_argument_offset, - => |offset| { - const adjusted_offset = switch (reloc.mcv) { - .stack_offset => -@intCast(i32, offset), - .stack_argument_offset => @intCast(i32, function.saved_regs_stack_space + offset), - else => unreachable, - }; - try dw.genArgDbgInfo(reloc.name, reloc.ty, atom, .{ - .stack = .{ + .dwarf => |dw| { + const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (reloc.mcv) { + .register => |reg| .{ .register = reg.dwarfLocOp() }, + .stack_offset, + .stack_argument_offset, + => |offset| blk: { + const adjusted_offset = switch (reloc.mcv) { + .stack_offset => -@intCast(i32, offset), + .stack_argument_offset => @intCast(i32, function.saved_regs_stack_space + offset), + else => unreachable, + }; + break :blk .{ .stack = .{ .fp_register = Register.x29.dwarfLocOpDeref(), .offset = adjusted_offset, - }, - }); - }, + } }; + }, + else => unreachable, // not a possible argument - else => unreachable, // not a possible argument + }; + try dw.genArgDbgInfo(reloc.name, reloc.ty, atom, loc); }, .plan9 => {}, .none => {}, @@ -223,10 +221,8 @@ const DbgInfoReloc = struct { switch (function.debug_output) { .dwarf => |dw| { - const loc: link.File.Dwarf.DeclState.VarArgDbgInfoLoc = switch (reloc.mcv) { - .register => |reg| .{ - .register = reg.dwarfLocOp(), - }, + const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (reloc.mcv) { + .register => |reg| .{ .register = reg.dwarfLocOp() }, .ptr_stack_offset, .stack_offset, .stack_argument_offset, diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index 066a82e5a2..0a19214e48 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -4036,26 +4036,26 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMe const atom = self.getDbgInfoAtom(); switch (self.debug_output) { - .dwarf => |dw| switch (mcv) { - .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{ - .register = reg.dwarfLocOp(), - }), - .stack_offset, - .stack_argument_offset, - => { - const adjusted_stack_offset = switch (mcv) { - .stack_offset => |offset| -@intCast(i32, offset), - .stack_argument_offset => |offset| @intCast(i32, self.saved_regs_stack_space + offset), - else => unreachable, - }; - try dw.genArgDbgInfo(name, ty, atom, .{ - .stack = .{ + .dwarf => |dw| { + const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (mcv) { + .register => |reg| .{ .register = reg.dwarfLocOp() }, + .stack_offset, + .stack_argument_offset, + => blk: { + const adjusted_stack_offset = switch (mcv) { + .stack_offset => |offset| -@intCast(i32, offset), + .stack_argument_offset => |offset| @intCast(i32, self.saved_regs_stack_space + offset), + else => unreachable, + }; + break :blk .{ .stack = .{ .fp_register = DW.OP.breg11, .offset = adjusted_stack_offset, - }, - }); - }, - else => unreachable, // not a possible argument + } }; + }, + else => unreachable, // not a possible argument + + }; + try dw.genArgDbgInfo(name, ty, atom, loc); }, .plan9 => {}, .none => {}, diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig index 368c0ba71f..b2c7ac293f 100644 --- a/src/arch/riscv64/CodeGen.zig +++ b/src/arch/riscv64/CodeGen.zig @@ -1602,17 +1602,10 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void { return self.fail("TODO implement codegen airFieldParentPtr", .{}); } -fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void { +fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void { const ty = self.air.instructions.items(.data)[inst].ty; const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index); - - const mod = self.bin_file.options.module.?; - const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); - const atom = switch (self.bin_file.tag) { - .elf => &fn_owner_decl.link.elf.dbg_info_atom, - .macho => &fn_owner_decl.link.macho.dbg_info_atom, - else => unreachable, - }; + const atom = self.getDbgIntoAtomPtr(); switch (self.debug_output) { .dwarf => |dw| switch (mcv) { @@ -1627,6 +1620,17 @@ fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32 } } +fn getDbgIntoAtomPtr(self: Self) *link.File.Dwarf.Atom { + const mod = self.bin_file.options.module.?; + const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); + const atom = switch (self.bin_file.tag) { + .elf => &fn_owner_decl.link.elf.dbg_info_atom, + .macho => &fn_owner_decl.link.macho.dbg_info_atom, + else => unreachable, + }; + return atom; +} + fn airArg(self: *Self, inst: Air.Inst.Index) !void { const arg_index = self.arg_index; self.arg_index += 1; diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index ddb1803998..6584ad2041 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -5327,7 +5327,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void { log.debug(" var name = ({s})", .{name}); const atom = func.getDbgInfoAtom(); - const loc: link.File.Dwarf.DeclState.VarArgDbgInfoLoc = switch (operand) { + const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (operand) { .local => |local| .{ .wasm_local = local.value }, else => blk: { log.debug("TODO generate debug info for {}", .{operand}); diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index 5d9e3ccb5e..b526743b2a 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -3818,18 +3818,19 @@ fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void { const atom = self.getDbgInfoAtomPtr(); switch (self.debug_output) { - .dwarf => |dw| switch (mcv) { - .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{ - .register = reg.dwarfLocOp(), - }), - .stack_offset => |off| try dw.genArgDbgInfo(name, ty, atom, .{ - .stack = .{ - .fp_register = Register.rbp.dwarfLocOpDeref(), // TODO handle -fomit-frame-pointer - .offset = -off, + .dwarf => |dw| { + const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (mcv) { + .register => |reg| .{ .register = reg.dwarfLocOp() }, + .stack_offset => |off| .{ + .stack = .{ + // TODO handle -fomit-frame-pointer + .fp_register = Register.rbp.dwarfLocOpDeref(), + .offset = -off, + }, }, - }), - - else => unreachable, // not a valid function parameter + else => unreachable, // not a valid function parameter + }; + try dw.genArgDbgInfo(name, ty, atom, loc); }, .plan9 => {}, .none => {}, @@ -3852,10 +3853,8 @@ fn genVarDbgInfo( switch (self.debug_output) { .dwarf => |dw| { - const loc: link.File.Dwarf.DeclState.VarArgDbgInfoLoc = switch (mcv) { - .register => |reg| .{ - .register = reg.dwarfLocOp(), - }, + const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (mcv) { + .register => |reg| .{ .register = reg.dwarfLocOp() }, .ptr_stack_offset, .stack_offset, => |off| .{ .stack = .{ diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index feb2857322..8540b8a542 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -562,16 +562,27 @@ pub const DeclState = struct { } } + pub const DbgInfoLoc = union(enum) { + register: u8, + stack: struct { + fp_register: u8, + offset: i32, + }, + wasm_local: u32, + memory: u64, + linker_load: LinkerLoad, + immediate: u64, + undef, + none, + nop, + }; + pub fn genArgDbgInfo( self: *DeclState, name: [:0]const u8, ty: Type, atom: *Atom, - loc: union(enum) { - register: u8, - stack: struct { fp_register: u8, offset: i32 }, - wasm_local: u32, - }, + loc: DbgInfoLoc, ) error{OutOfMemory}!void { const dbg_info = &self.dbg_info; const name_with_null = name.ptr[0 .. name.len + 1]; @@ -612,6 +623,7 @@ pub const DeclState = struct { }); leb128.writeULEB128(dbg_info.writer(), value) catch unreachable; }, + else => unreachable, } try dbg_info.ensureUnusedCapacity(5 + name_with_null.len); @@ -621,28 +633,13 @@ pub const DeclState = struct { dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string } - pub const VarArgDbgInfoLoc = union(enum) { - register: u8, - stack: struct { - fp_register: u8, - offset: i32, - }, - wasm_local: u32, - memory: u64, - linker_load: LinkerLoad, - immediate: u64, - undef, - none, - nop, - }; - pub fn genVarDbgInfo( self: *DeclState, name: [:0]const u8, ty: Type, atom: *Atom, is_ptr: bool, - loc: VarArgDbgInfoLoc, + loc: DbgInfoLoc, ) error{OutOfMemory}!void { const dbg_info = &self.dbg_info; const name_with_null = name.ptr[0 .. name.len + 1]; -- cgit v1.2.3 From bfd36cbf97bfa012e5c399c16578b8756782e1d8 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 2 Dec 2022 13:17:52 +0100 Subject: dwarf: pass linker Tag and owner Decl.Index instead of *Atom --- src/arch/aarch64/CodeGen.zig | 31 +++++++++++++++---------------- src/arch/arm/CodeGen.zig | 14 +------------- src/arch/riscv64/CodeGen.zig | 22 +++++++--------------- src/arch/sparc64/CodeGen.zig | 21 +++++++-------------- src/arch/wasm/CodeGen.zig | 12 ++---------- src/arch/x86_64/CodeGen.zig | 18 ++---------------- src/link/Dwarf.zig | 18 ++++++++++++++++-- 7 files changed, 50 insertions(+), 86 deletions(-) (limited to 'src/arch/arm/CodeGen.zig') diff --git a/src/arch/aarch64/CodeGen.zig b/src/arch/aarch64/CodeGen.zig index 7bf0f99a84..9975e08ea9 100644 --- a/src/arch/aarch64/CodeGen.zig +++ b/src/arch/aarch64/CodeGen.zig @@ -182,8 +182,6 @@ const DbgInfoReloc = struct { } } fn genArgDbgInfo(reloc: DbgInfoReloc, function: Self) error{OutOfMemory}!void { - const atom = function.getDbgInfoAtomPtr(); - switch (function.debug_output) { .dwarf => |dw| { const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (reloc.mcv) { @@ -204,7 +202,13 @@ const DbgInfoReloc = struct { else => unreachable, // not a possible argument }; - try dw.genArgDbgInfo(reloc.name, reloc.ty, atom, loc); + try dw.genArgDbgInfo( + reloc.name, + reloc.ty, + function.bin_file.tag, + function.mod_fn.owner_decl, + loc, + ); }, .plan9 => {}, .none => {}, @@ -217,7 +221,6 @@ const DbgInfoReloc = struct { .dbg_var_val => false, else => unreachable, }; - const atom = function.getDbgInfoAtomPtr(); switch (function.debug_output) { .dwarf => |dw| { @@ -251,7 +254,14 @@ const DbgInfoReloc = struct { break :blk .nop; }, }; - try dw.genVarDbgInfo(reloc.name, reloc.ty, atom, is_ptr, loc); + try dw.genVarDbgInfo( + reloc.name, + reloc.ty, + function.bin_file.tag, + function.mod_fn.owner_decl, + is_ptr, + loc, + ); }, .plan9 => {}, .none => {}, @@ -259,17 +269,6 @@ const DbgInfoReloc = struct { } }; -fn getDbgInfoAtomPtr(self: Self) *link.File.Dwarf.Atom { - const mod = self.bin_file.options.module.?; - const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); - const atom = switch (self.bin_file.tag) { - .elf => &fn_owner_decl.link.elf.dbg_info_atom, - .macho => &fn_owner_decl.link.macho.dbg_info_atom, - else => unreachable, - }; - return atom; -} - const Branch = struct { inst_table: std.AutoArrayHashMapUnmanaged(Air.Inst.Index, MCValue) = .{}, diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index 0a19214e48..7a9e00b83f 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -4033,7 +4033,6 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMe const mcv = self.args[arg_index]; const ty = self.air.instructions.items(.data)[inst].ty; const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index); - const atom = self.getDbgInfoAtom(); switch (self.debug_output) { .dwarf => |dw| { @@ -4055,24 +4054,13 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMe else => unreachable, // not a possible argument }; - try dw.genArgDbgInfo(name, ty, atom, loc); + try dw.genArgDbgInfo(name, ty, self.bin_file.tag, self.mod_fn.owner_decl, loc); }, .plan9 => {}, .none => {}, } } -fn getDbgInfoAtom(self: Self) *link.File.Dwarf.Atom { - const mod = self.bin_file.options.module.?; - const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); - const atom = switch (self.bin_file.tag) { - .elf => &fn_owner_decl.link.elf.dbg_info_atom, - .macho => &fn_owner_decl.link.macho.dbg_info_atom, - else => unreachable, - }; - return atom; -} - fn airArg(self: *Self, inst: Air.Inst.Index) !void { const arg_index = self.arg_index; self.arg_index += 1; diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig index b2c7ac293f..6a54ffeea2 100644 --- a/src/arch/riscv64/CodeGen.zig +++ b/src/arch/riscv64/CodeGen.zig @@ -1605,13 +1605,16 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void { fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void { const ty = self.air.instructions.items(.data)[inst].ty; const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index); - const atom = self.getDbgIntoAtomPtr(); switch (self.debug_output) { .dwarf => |dw| switch (mcv) { - .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{ - .register = reg.dwarfLocOp(), - }), + .register => |reg| try dw.genArgDbgInfo( + name, + ty, + self.bin_file.tag, + self.mod_fn.owner_decl, + .{ .register = reg.dwarfLocOp() }, + ), .stack_offset => {}, else => {}, }, @@ -1620,17 +1623,6 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) } } -fn getDbgIntoAtomPtr(self: Self) *link.File.Dwarf.Atom { - const mod = self.bin_file.options.module.?; - const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); - const atom = switch (self.bin_file.tag) { - .elf => &fn_owner_decl.link.elf.dbg_info_atom, - .macho => &fn_owner_decl.link.macho.dbg_info_atom, - else => unreachable, - }; - return atom; -} - fn airArg(self: *Self, inst: Air.Inst.Index) !void { const arg_index = self.arg_index; self.arg_index += 1; diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig index 66d14f755b..9f345767de 100644 --- a/src/arch/sparc64/CodeGen.zig +++ b/src/arch/sparc64/CodeGen.zig @@ -3255,29 +3255,22 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void { const ty = self.air.instructions.items(.data)[inst].ty; const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index); - const atom = self.getDbgInfoAtomPtr(); switch (self.debug_output) { .dwarf => |dw| switch (mcv) { - .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{ - .register = reg.dwarfLocOp(), - }), + .register => |reg| try dw.genArgDbgInfo( + name, + ty, + self.bin_file.tag, + self.mod_fn.owner_decl, + .{ .register = reg.dwarfLocOp() }, + ), else => {}, }, else => {}, } } -fn getDbgInfoAtomPtr(self: Self) *link.File.Dwarf.Atom { - const mod = self.bin_file.options.module.?; - const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); - const atom = switch (self.bin_file.tag) { - .elf => &fn_owner_decl.link.elf.dbg_info_atom, - else => unreachable, - }; - return atom; -} - // TODO replace this to call to extern memcpy fn genInlineMemcpy( self: *Self, diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 6584ad2041..c424c7b59d 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -2341,8 +2341,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { .dwarf => |dwarf| { // TODO: Get the original arg index rather than wasm arg index const name = func.mod_fn.getParamName(func.bin_file.base.options.module.?, arg_index); - const atom = func.getDbgInfoAtom(); - try dwarf.genArgDbgInfo(name, arg_ty, atom, .{ + try dwarf.genArgDbgInfo(name, arg_ty, .wasm, func.mod_fn.owner_decl, .{ .wasm_local = arg.local.value, }); }, @@ -2352,12 +2351,6 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { func.finishAir(inst, arg, &.{}); } -fn getDbgInfoAtom(func: CodeGen) *link.File.Dwarf.Atom { - const mod = func.bin_file.base.options.module.?; - const fn_owner_decl = mod.declPtr(func.mod_fn.owner_decl); - return &fn_owner_decl.link.wasm.dbg_info_atom; -} - fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void { const bin_op = func.air.instructions.items(.data)[inst].bin_op; if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs }); @@ -5326,7 +5319,6 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void { const name = func.air.nullTerminatedString(pl_op.payload); log.debug(" var name = ({s})", .{name}); - const atom = func.getDbgInfoAtom(); const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (operand) { .local => |local| .{ .wasm_local = local.value }, else => blk: { @@ -5334,7 +5326,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void { break :blk .nop; }, }; - try func.debug_output.dwarf.genVarDbgInfo(name, ty, atom, is_ptr, loc); + try func.debug_output.dwarf.genVarDbgInfo(name, ty, .wasm, func.mod_fn.owner_decl, is_ptr, loc); func.finishAir(inst, .none, &.{}); } diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index 8769b7ae61..ae7cbc762d 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -3815,8 +3815,6 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void { } fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void { - const atom = self.getDbgInfoAtomPtr(); - switch (self.debug_output) { .dwarf => |dw| { const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (mcv) { @@ -3830,7 +3828,7 @@ fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void { }, else => unreachable, // not a valid function parameter }; - try dw.genArgDbgInfo(name, ty, atom, loc); + try dw.genArgDbgInfo(name, ty, self.bin_file.tag, self.mod_fn.owner_decl, loc); }, .plan9 => {}, .none => {}, @@ -3849,7 +3847,6 @@ fn genVarDbgInfo( .dbg_var_val => false, else => unreachable, }; - const atom = self.getDbgInfoAtomPtr(); switch (self.debug_output) { .dwarf => |dw| { @@ -3871,24 +3868,13 @@ fn genVarDbgInfo( break :blk .nop; }, }; - try dw.genVarDbgInfo(name, ty, atom, is_ptr, loc); + try dw.genVarDbgInfo(name, ty, self.bin_file.tag, self.mod_fn.owner_decl, is_ptr, loc); }, .plan9 => {}, .none => {}, } } -fn getDbgInfoAtomPtr(self: Self) *link.File.Dwarf.Atom { - const mod = self.bin_file.options.module.?; - const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); - const atom = switch (self.bin_file.tag) { - .elf => &fn_owner_decl.link.elf.dbg_info_atom, - .macho => &fn_owner_decl.link.macho.dbg_info_atom, - else => unreachable, - }; - return atom; -} - fn airBreakpoint(self: *Self) !void { _ = try self.addInst(.{ .tag = .interrupt, diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index 8540b8a542..63ccb57e77 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -581,10 +581,12 @@ pub const DeclState = struct { self: *DeclState, name: [:0]const u8, ty: Type, - atom: *Atom, + tag: File.Tag, + owner_decl: Module.Decl.Index, loc: DbgInfoLoc, ) error{OutOfMemory}!void { const dbg_info = &self.dbg_info; + const atom = self.getDbgInfoAtom(tag, owner_decl); const name_with_null = name.ptr[0 .. name.len + 1]; switch (loc) { @@ -637,11 +639,13 @@ pub const DeclState = struct { self: *DeclState, name: [:0]const u8, ty: Type, - atom: *Atom, + tag: File.Tag, + owner_decl: Module.Decl.Index, is_ptr: bool, loc: DbgInfoLoc, ) error{OutOfMemory}!void { const dbg_info = &self.dbg_info; + const atom = self.getDbgInfoAtom(tag, owner_decl); const name_with_null = name.ptr[0 .. name.len + 1]; try dbg_info.append(@enumToInt(AbbrevKind.variable)); const target = self.mod.getTarget(); @@ -774,6 +778,16 @@ pub const DeclState = struct { try self.addTypeRelocGlobal(atom, child_ty, @intCast(u32, index)); dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string } + + fn getDbgInfoAtom(self: *DeclState, tag: File.Tag, decl_index: Module.Decl.Index) *Atom { + const decl = self.mod.declPtr(decl_index); + return switch (tag) { + .elf => &decl.link.elf.dbg_info_atom, + .macho => &decl.link.macho.dbg_info_atom, + .wasm => &decl.link.wasm.dbg_info_atom, + else => unreachable, + }; + } }; pub const AbbrevEntry = struct { -- cgit v1.2.3