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 {...@@ -182,8 +182,6 @@ const DbgInfoReloc = struct {
182 }182 }
183 }183 }
184 fn genArgDbgInfo(reloc: DbgInfoReloc, function: Self) error{OutOfMemory}!void {184 fn genArgDbgInfo(reloc: DbgInfoReloc, function: Self) error{OutOfMemory}!void {
185 const atom = function.getDbgInfoAtomPtr();
186
187 switch (function.debug_output) {185 switch (function.debug_output) {
188 .dwarf => |dw| {186 .dwarf => |dw| {
189 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (reloc.mcv) {187 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (reloc.mcv) {
...@@ -204,7 +202,13 @@ const DbgInfoReloc = struct {...@@ -204,7 +202,13 @@ const DbgInfoReloc = struct {
204 else => unreachable, // not a possible argument202 else => unreachable, // not a possible argument
205203
206 };204 };
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 );
208 },212 },
209 .plan9 => {},213 .plan9 => {},
210 .none => {},214 .none => {},
...@@ -217,7 +221,6 @@ const DbgInfoReloc = struct {...@@ -217,7 +221,6 @@ const DbgInfoReloc = struct {
217 .dbg_var_val => false,221 .dbg_var_val => false,
218 else => unreachable,222 else => unreachable,
219 };223 };
220 const atom = function.getDbgInfoAtomPtr();
221224
222 switch (function.debug_output) {225 switch (function.debug_output) {
223 .dwarf => |dw| {226 .dwarf => |dw| {
...@@ -251,7 +254,14 @@ const DbgInfoReloc = struct {...@@ -251,7 +254,14 @@ const DbgInfoReloc = struct {
251 break :blk .nop;254 break :blk .nop;
252 },255 },
253 };256 };
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 );
255 },265 },
256 .plan9 => {},266 .plan9 => {},
257 .none => {},267 .none => {},
...@@ -259,17 +269,6 @@ const DbgInfoReloc = struct {...@@ -259,17 +269,6 @@ const DbgInfoReloc = struct {
259 }269 }
260};270};
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
273const Branch = struct {272const Branch = struct {
274 inst_table: std.AutoArrayHashMapUnmanaged(Air.Inst.Index, MCValue) = .{},273 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...@@ -4033,7 +4033,6 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMe
4033 const mcv = self.args[arg_index];4033 const mcv = self.args[arg_index];
4034 const ty = self.air.instructions.items(.data)[inst].ty;4034 const ty = self.air.instructions.items(.data)[inst].ty;
4035 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);4035 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);
4036 const atom = self.getDbgInfoAtom();
40374036
4038 switch (self.debug_output) {4037 switch (self.debug_output) {
4039 .dwarf => |dw| {4038 .dwarf => |dw| {
...@@ -4055,24 +4054,13 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMe...@@ -4055,24 +4054,13 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMe
4055 else => unreachable, // not a possible argument4054 else => unreachable, // not a possible argument
40564055
4057 };4056 };
4058 try dw.genArgDbgInfo(name, ty, atom, loc);4057 try dw.genArgDbgInfo(name, ty, self.bin_file.tag, self.mod_fn.owner_decl, loc);
4059 },4058 },
4060 .plan9 => {},4059 .plan9 => {},
4061 .none => {},4060 .none => {},
4062 }4061 }
4063}4062}
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
4076fn airArg(self: *Self, inst: Air.Inst.Index) !void {4064fn airArg(self: *Self, inst: Air.Inst.Index) !void {
4077 const arg_index = self.arg_index;4065 const arg_index = self.arg_index;
4078 self.arg_index += 1;4066 self.arg_index += 1;
src/arch/riscv64/CodeGen.zig+7-15
...@@ -1605,13 +1605,16 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1605,13 +1605,16 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
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);
1608 const atom = self.getDbgIntoAtomPtr();
16091608
1610 switch (self.debug_output) {1609 switch (self.debug_output) {
1611 .dwarf => |dw| switch (mcv) {1610 .dwarf => |dw| switch (mcv) {
1612 .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{1611 .register => |reg| try dw.genArgDbgInfo(
1613 .register = reg.dwarfLocOp(),1612 name,
1614 }),1613 ty,
1614 self.bin_file.tag,
1615 self.mod_fn.owner_decl,
1616 .{ .register = reg.dwarfLocOp() },
1617 ),
1615 .stack_offset => {},1618 .stack_offset => {},
1616 else => {},1619 else => {},
1617 },1620 },
...@@ -1620,17 +1623,6 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32)...@@ -1620,17 +1623,6 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32)
1620 }1623 }
1621}1624}
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
1634fn airArg(self: *Self, inst: Air.Inst.Index) !void {1626fn airArg(self: *Self, inst: Air.Inst.Index) !void {
1635 const arg_index = self.arg_index;1627 const arg_index = self.arg_index;
1636 self.arg_index += 1;1628 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...@@ -3255,29 +3255,22 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live
3255fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void {3255fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void {
3256 const ty = self.air.instructions.items(.data)[inst].ty;3256 const ty = self.air.instructions.items(.data)[inst].ty;
3257 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);3257 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);
3258 const atom = self.getDbgInfoAtomPtr();
32593258
3260 switch (self.debug_output) {3259 switch (self.debug_output) {
3261 .dwarf => |dw| switch (mcv) {3260 .dwarf => |dw| switch (mcv) {
3262 .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{3261 .register => |reg| try dw.genArgDbgInfo(
3263 .register = reg.dwarfLocOp(),3262 name,
3264 }),3263 ty,
3264 self.bin_file.tag,
3265 self.mod_fn.owner_decl,
3266 .{ .register = reg.dwarfLocOp() },
3267 ),
3265 else => {},3268 else => {},
3266 },3269 },
3267 else => {},3270 else => {},
3268 }3271 }
3269}3272}
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
3281// TODO replace this to call to extern memcpy3274// TODO replace this to call to extern memcpy
3282fn genInlineMemcpy(3275fn genInlineMemcpy(
3283 self: *Self,3276 self: *Self,
src/arch/wasm/CodeGen.zig+2-10
...@@ -2341,8 +2341,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2341,8 +2341,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2341 .dwarf => |dwarf| {2341 .dwarf => |dwarf| {
2342 // TODO: Get the original arg index rather than wasm arg index2342 // TODO: Get the original arg index rather than wasm arg index
2343 const name = func.mod_fn.getParamName(func.bin_file.base.options.module.?, arg_index);2343 const name = func.mod_fn.getParamName(func.bin_file.base.options.module.?, arg_index);
2344 const atom = func.getDbgInfoAtom();2344 try dwarf.genArgDbgInfo(name, arg_ty, .wasm, func.mod_fn.owner_decl, .{
2345 try dwarf.genArgDbgInfo(name, arg_ty, atom, .{
2346 .wasm_local = arg.local.value,2345 .wasm_local = arg.local.value,
2347 });2346 });
2348 },2347 },
...@@ -2352,12 +2351,6 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2352,12 +2351,6 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2352 func.finishAir(inst, arg, &.{});2351 func.finishAir(inst, arg, &.{});
2353}2352}
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
2361fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {2354fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
2362 const bin_op = func.air.instructions.items(.data)[inst].bin_op;2355 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
2363 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });2356 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 {...@@ -5326,7 +5319,6 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void {
5326 const name = func.air.nullTerminatedString(pl_op.payload);5319 const name = func.air.nullTerminatedString(pl_op.payload);
5327 log.debug(" var name = ({s})", .{name});5320 log.debug(" var name = ({s})", .{name});
53285321
5329 const atom = func.getDbgInfoAtom();
5330 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (operand) {5322 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (operand) {
5331 .local => |local| .{ .wasm_local = local.value },5323 .local => |local| .{ .wasm_local = local.value },
5332 else => blk: {5324 else => blk: {
...@@ -5334,7 +5326,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void {...@@ -5334,7 +5326,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void {
5334 break :blk .nop;5326 break :blk .nop;
5335 },5327 },
5336 };5328 };
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
5339 func.finishAir(inst, .none, &.{});5331 func.finishAir(inst, .none, &.{});
5340}5332}
src/arch/x86_64/CodeGen.zig+2-16
...@@ -3815,8 +3815,6 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {...@@ -3815,8 +3815,6 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
3815}3815}
38163816
3817fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void {3817fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void {
3818 const atom = self.getDbgInfoAtomPtr();
3819
3820 switch (self.debug_output) {3818 switch (self.debug_output) {
3821 .dwarf => |dw| {3819 .dwarf => |dw| {
3822 const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (mcv) {3820 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 {...@@ -3830,7 +3828,7 @@ fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void {
3830 },3828 },
3831 else => unreachable, // not a valid function parameter3829 else => unreachable, // not a valid function parameter
3832 };3830 };
3833 try dw.genArgDbgInfo(name, ty, atom, loc);3831 try dw.genArgDbgInfo(name, ty, self.bin_file.tag, self.mod_fn.owner_decl, loc);
3834 },3832 },
3835 .plan9 => {},3833 .plan9 => {},
3836 .none => {},3834 .none => {},
...@@ -3849,7 +3847,6 @@ fn genVarDbgInfo(...@@ -3849,7 +3847,6 @@ fn genVarDbgInfo(
3849 .dbg_var_val => false,3847 .dbg_var_val => false,
3850 else => unreachable,3848 else => unreachable,
3851 };3849 };
3852 const atom = self.getDbgInfoAtomPtr();
38533850
3854 switch (self.debug_output) {3851 switch (self.debug_output) {
3855 .dwarf => |dw| {3852 .dwarf => |dw| {
...@@ -3871,24 +3868,13 @@ fn genVarDbgInfo(...@@ -3871,24 +3868,13 @@ fn genVarDbgInfo(
3871 break :blk .nop;3868 break :blk .nop;
3872 },3869 },
3873 };3870 };
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);
3875 },3872 },
3876 .plan9 => {},3873 .plan9 => {},
3877 .none => {},3874 .none => {},
3878 }3875 }
3879}3876}
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
3892fn airBreakpoint(self: *Self) !void {3878fn airBreakpoint(self: *Self) !void {
3893 _ = try self.addInst(.{3879 _ = try self.addInst(.{
3894 .tag = .interrupt,3880 .tag = .interrupt,
src/link/Dwarf.zig+16-2
...@@ -581,10 +581,12 @@ pub const DeclState = struct {...@@ -581,10 +581,12 @@ pub const DeclState = struct {
581 self: *DeclState,581 self: *DeclState,
582 name: [:0]const u8,582 name: [:0]const u8,
583 ty: Type,583 ty: Type,
584 atom: *Atom,584 tag: File.Tag,
585 owner_decl: Module.Decl.Index,
585 loc: DbgInfoLoc,586 loc: DbgInfoLoc,
586 ) error{OutOfMemory}!void {587 ) error{OutOfMemory}!void {
587 const dbg_info = &self.dbg_info;588 const dbg_info = &self.dbg_info;
589 const atom = self.getDbgInfoAtom(tag, owner_decl);
588 const name_with_null = name.ptr[0 .. name.len + 1];590 const name_with_null = name.ptr[0 .. name.len + 1];
589591
590 switch (loc) {592 switch (loc) {
...@@ -637,11 +639,13 @@ pub const DeclState = struct {...@@ -637,11 +639,13 @@ pub const DeclState = struct {
637 self: *DeclState,639 self: *DeclState,
638 name: [:0]const u8,640 name: [:0]const u8,
639 ty: Type,641 ty: Type,
640 atom: *Atom,642 tag: File.Tag,
643 owner_decl: Module.Decl.Index,
641 is_ptr: bool,644 is_ptr: bool,
642 loc: DbgInfoLoc,645 loc: DbgInfoLoc,
643 ) error{OutOfMemory}!void {646 ) error{OutOfMemory}!void {
644 const dbg_info = &self.dbg_info;647 const dbg_info = &self.dbg_info;
648 const atom = self.getDbgInfoAtom(tag, owner_decl);
645 const name_with_null = name.ptr[0 .. name.len + 1];649 const name_with_null = name.ptr[0 .. name.len + 1];
646 try dbg_info.append(@enumToInt(AbbrevKind.variable));650 try dbg_info.append(@enumToInt(AbbrevKind.variable));
647 const target = self.mod.getTarget();651 const target = self.mod.getTarget();
...@@ -774,6 +778,16 @@ pub const DeclState = struct {...@@ -774,6 +778,16 @@ pub const DeclState = struct {
774 try self.addTypeRelocGlobal(atom, child_ty, @intCast(u32, index));778 try self.addTypeRelocGlobal(atom, child_ty, @intCast(u32, index));
775 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string779 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
776 }780 }
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 }
777};791};
778792
779pub const AbbrevEntry = struct {793pub const AbbrevEntry = struct {