authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-02 13:17:52+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-02 13:17:52+01:00
logbfd36cbf97bfa012e5c399c16578b8756782e1d8
treed6655a05c089ab0c316d3e36049b67768f774be8
parent05962a4aa28eca701bb22c4b17d2f9ea236583f5

dwarf: pass linker Tag and owner Decl.Index instead of *Atom


7 files changed, 50 insertions(+), 86 deletions(-)

src/arch/aarch64/CodeGen.zig+15-16
......@@ -182,8 +182,6 @@ const DbgInfoReloc = struct {
182182 }
183183 }
184184 fn genArgDbgInfo(reloc: DbgInfoReloc, function: Self) error{OutOfMemory}!void {
185 const atom = function.getDbgInfoAtomPtr();
186
187185 switch (function.debug_output) {
188186 .dwarf => |dw| {
189187 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (reloc.mcv) {
......@@ -204,7 +202,13 @@ const DbgInfoReloc = struct {
204202 else => unreachable, // not a possible argument
205203
206204 };
207 try dw.genArgDbgInfo(reloc.name, reloc.ty, atom, loc);
205 try dw.genArgDbgInfo(
206 reloc.name,
207 reloc.ty,
208 function.bin_file.tag,
209 function.mod_fn.owner_decl,
210 loc,
211 );
208212 },
209213 .plan9 => {},
210214 .none => {},
......@@ -217,7 +221,6 @@ const DbgInfoReloc = struct {
217221 .dbg_var_val => false,
218222 else => unreachable,
219223 };
220 const atom = function.getDbgInfoAtomPtr();
221224
222225 switch (function.debug_output) {
223226 .dwarf => |dw| {
......@@ -251,7 +254,14 @@ const DbgInfoReloc = struct {
251254 break :blk .nop;
252255 },
253256 };
254 try dw.genVarDbgInfo(reloc.name, reloc.ty, atom, is_ptr, loc);
257 try dw.genVarDbgInfo(
258 reloc.name,
259 reloc.ty,
260 function.bin_file.tag,
261 function.mod_fn.owner_decl,
262 is_ptr,
263 loc,
264 );
255265 },
256266 .plan9 => {},
257267 .none => {},
......@@ -259,17 +269,6 @@ const DbgInfoReloc = struct {
259269 }
260270};
261271
262fn getDbgInfoAtomPtr(self: Self) *link.File.Dwarf.Atom {
263 const mod = self.bin_file.options.module.?;
264 const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl);
265 const atom = switch (self.bin_file.tag) {
266 .elf => &fn_owner_decl.link.elf.dbg_info_atom,
267 .macho => &fn_owner_decl.link.macho.dbg_info_atom,
268 else => unreachable,
269 };
270 return atom;
271}
272
273272const Branch = struct {
274273 inst_table: std.AutoArrayHashMapUnmanaged(Air.Inst.Index, MCValue) = .{},
275274
src/arch/arm/CodeGen.zig+1-13
......@@ -4033,7 +4033,6 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMe
40334033 const mcv = self.args[arg_index];
40344034 const ty = self.air.instructions.items(.data)[inst].ty;
40354035 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);
4036 const atom = self.getDbgInfoAtom();
40374036
40384037 switch (self.debug_output) {
40394038 .dwarf => |dw| {
......@@ -4055,24 +4054,13 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMe
40554054 else => unreachable, // not a possible argument
40564055
40574056 };
4058 try dw.genArgDbgInfo(name, ty, atom, loc);
4057 try dw.genArgDbgInfo(name, ty, self.bin_file.tag, self.mod_fn.owner_decl, loc);
40594058 },
40604059 .plan9 => {},
40614060 .none => {},
40624061 }
40634062}
40644063
4065fn getDbgInfoAtom(self: Self) *link.File.Dwarf.Atom {
4066 const mod = self.bin_file.options.module.?;
4067 const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl);
4068 const atom = switch (self.bin_file.tag) {
4069 .elf => &fn_owner_decl.link.elf.dbg_info_atom,
4070 .macho => &fn_owner_decl.link.macho.dbg_info_atom,
4071 else => unreachable,
4072 };
4073 return atom;
4074}
4075
40764064fn airArg(self: *Self, inst: Air.Inst.Index) !void {
40774065 const arg_index = self.arg_index;
40784066 self.arg_index += 1;
src/arch/riscv64/CodeGen.zig+7-15
......@@ -1605,13 +1605,16 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
16051605fn 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 const atom = self.getDbgIntoAtomPtr();
16091608
16101609 switch (self.debug_output) {
16111610 .dwarf => |dw| switch (mcv) {
1612 .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{
1613 .register = reg.dwarfLocOp(),
1614 }),
1611 .register => |reg| try dw.genArgDbgInfo(
1612 name,
1613 ty,
1614 self.bin_file.tag,
1615 self.mod_fn.owner_decl,
1616 .{ .register = reg.dwarfLocOp() },
1617 ),
16151618 .stack_offset => {},
16161619 else => {},
16171620 },
......@@ -1620,17 +1623,6 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32)
16201623 }
16211624}
16221625
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
16341626fn airArg(self: *Self, inst: Air.Inst.Index) !void {
16351627 const arg_index = self.arg_index;
16361628 self.arg_index += 1;
src/arch/sparc64/CodeGen.zig+7-14
......@@ -3255,29 +3255,22 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live
32553255fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void {
32563256 const ty = self.air.instructions.items(.data)[inst].ty;
32573257 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);
3258 const atom = self.getDbgInfoAtomPtr();
32593258
32603259 switch (self.debug_output) {
32613260 .dwarf => |dw| switch (mcv) {
3262 .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{
3263 .register = reg.dwarfLocOp(),
3264 }),
3261 .register => |reg| try dw.genArgDbgInfo(
3262 name,
3263 ty,
3264 self.bin_file.tag,
3265 self.mod_fn.owner_decl,
3266 .{ .register = reg.dwarfLocOp() },
3267 ),
32653268 else => {},
32663269 },
32673270 else => {},
32683271 }
32693272}
32703273
3271fn getDbgInfoAtomPtr(self: Self) *link.File.Dwarf.Atom {
3272 const mod = self.bin_file.options.module.?;
3273 const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl);
3274 const atom = switch (self.bin_file.tag) {
3275 .elf => &fn_owner_decl.link.elf.dbg_info_atom,
3276 else => unreachable,
3277 };
3278 return atom;
3279}
3280
32813274// TODO replace this to call to extern memcpy
32823275fn genInlineMemcpy(
32833276 self: *Self,
src/arch/wasm/CodeGen.zig+2-10
......@@ -2341,8 +2341,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
23412341 .dwarf => |dwarf| {
23422342 // TODO: Get the original arg index rather than wasm arg index
23432343 const name = func.mod_fn.getParamName(func.bin_file.base.options.module.?, arg_index);
2344 const atom = func.getDbgInfoAtom();
2345 try dwarf.genArgDbgInfo(name, arg_ty, atom, .{
2344 try dwarf.genArgDbgInfo(name, arg_ty, .wasm, func.mod_fn.owner_decl, .{
23462345 .wasm_local = arg.local.value,
23472346 });
23482347 },
......@@ -2352,12 +2351,6 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
23522351 func.finishAir(inst, arg, &.{});
23532352}
23542353
2355fn getDbgInfoAtom(func: CodeGen) *link.File.Dwarf.Atom {
2356 const mod = func.bin_file.base.options.module.?;
2357 const fn_owner_decl = mod.declPtr(func.mod_fn.owner_decl);
2358 return &fn_owner_decl.link.wasm.dbg_info_atom;
2359}
2360
23612354fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
23622355 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
23632356 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 {
53265319 const name = func.air.nullTerminatedString(pl_op.payload);
53275320 log.debug(" var name = ({s})", .{name});
53285321
5329 const atom = func.getDbgInfoAtom();
53305322 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (operand) {
53315323 .local => |local| .{ .wasm_local = local.value },
53325324 else => blk: {
......@@ -5334,7 +5326,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void {
53345326 break :blk .nop;
53355327 },
53365328 };
5337 try func.debug_output.dwarf.genVarDbgInfo(name, ty, atom, is_ptr, loc);
5329 try func.debug_output.dwarf.genVarDbgInfo(name, ty, .wasm, func.mod_fn.owner_decl, is_ptr, loc);
53385330
53395331 func.finishAir(inst, .none, &.{});
53405332}
src/arch/x86_64/CodeGen.zig+2-16
......@@ -3815,8 +3815,6 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
38153815}
38163816
38173817fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void {
3818 const atom = self.getDbgInfoAtomPtr();
3819
38203818 switch (self.debug_output) {
38213819 .dwarf => |dw| {
38223820 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 {
38303828 },
38313829 else => unreachable, // not a valid function parameter
38323830 };
3833 try dw.genArgDbgInfo(name, ty, atom, loc);
3831 try dw.genArgDbgInfo(name, ty, self.bin_file.tag, self.mod_fn.owner_decl, loc);
38343832 },
38353833 .plan9 => {},
38363834 .none => {},
......@@ -3849,7 +3847,6 @@ fn genVarDbgInfo(
38493847 .dbg_var_val => false,
38503848 else => unreachable,
38513849 };
3852 const atom = self.getDbgInfoAtomPtr();
38533850
38543851 switch (self.debug_output) {
38553852 .dwarf => |dw| {
......@@ -3871,24 +3868,13 @@ fn genVarDbgInfo(
38713868 break :blk .nop;
38723869 },
38733870 };
3874 try dw.genVarDbgInfo(name, ty, atom, is_ptr, loc);
3871 try dw.genVarDbgInfo(name, ty, self.bin_file.tag, self.mod_fn.owner_decl, is_ptr, loc);
38753872 },
38763873 .plan9 => {},
38773874 .none => {},
38783875 }
38793876}
38803877
3881fn getDbgInfoAtomPtr(self: Self) *link.File.Dwarf.Atom {
3882 const mod = self.bin_file.options.module.?;
3883 const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl);
3884 const atom = switch (self.bin_file.tag) {
3885 .elf => &fn_owner_decl.link.elf.dbg_info_atom,
3886 .macho => &fn_owner_decl.link.macho.dbg_info_atom,
3887 else => unreachable,
3888 };
3889 return atom;
3890}
3891
38923878fn airBreakpoint(self: *Self) !void {
38933879 _ = try self.addInst(.{
38943880 .tag = .interrupt,
src/link/Dwarf.zig+16-2
......@@ -581,10 +581,12 @@ pub const DeclState = struct {
581581 self: *DeclState,
582582 name: [:0]const u8,
583583 ty: Type,
584 atom: *Atom,
584 tag: File.Tag,
585 owner_decl: Module.Decl.Index,
585586 loc: DbgInfoLoc,
586587 ) error{OutOfMemory}!void {
587588 const dbg_info = &self.dbg_info;
589 const atom = self.getDbgInfoAtom(tag, owner_decl);
588590 const name_with_null = name.ptr[0 .. name.len + 1];
589591
590592 switch (loc) {
......@@ -637,11 +639,13 @@ pub const DeclState = struct {
637639 self: *DeclState,
638640 name: [:0]const u8,
639641 ty: Type,
640 atom: *Atom,
642 tag: File.Tag,
643 owner_decl: Module.Decl.Index,
641644 is_ptr: bool,
642645 loc: DbgInfoLoc,
643646 ) error{OutOfMemory}!void {
644647 const dbg_info = &self.dbg_info;
648 const atom = self.getDbgInfoAtom(tag, owner_decl);
645649 const name_with_null = name.ptr[0 .. name.len + 1];
646650 try dbg_info.append(@enumToInt(AbbrevKind.variable));
647651 const target = self.mod.getTarget();
......@@ -774,6 +778,16 @@ pub const DeclState = struct {
774778 try self.addTypeRelocGlobal(atom, child_ty, @intCast(u32, index));
775779 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
776780 }
781
782 fn getDbgInfoAtom(self: *DeclState, tag: File.Tag, decl_index: Module.Decl.Index) *Atom {
783 const decl = self.mod.declPtr(decl_index);
784 return switch (tag) {
785 .elf => &decl.link.elf.dbg_info_atom,
786 .macho => &decl.link.macho.dbg_info_atom,
787 .wasm => &decl.link.wasm.dbg_info_atom,
788 else => unreachable,
789 };
790 }
777791};
778792
779793pub const AbbrevEntry = struct {