| author | |
| committer | |
| log | 5ee99f862a1b3a4d1f5ca304623e7394603136a6 |
| tree | d7de8e23ad0104b44e693e8126da66ad7032cda9 |
| parent | fc3142aa9a54f014c07aac6ac2aab75f57c5a75f |
3 files changed, 77 insertions(+), 51 deletions(-)
src/arch/aarch64/CodeGen.zig+14-23| ... | ... | @@ -186,22 +186,21 @@ const DbgInfoReloc = struct { |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | fn genArgDbgInfo(reloc: DbgInfoReloc, function: Self) error{OutOfMemory}!void { |
| 189 | const name_with_null = reloc.name.ptr[0 .. reloc.name.len + 1]; | |
| 189 | const mod = function.bin_file.options.module.?; | |
| 190 | const fn_owner_decl = mod.declPtr(function.mod_fn.owner_decl); | |
| 191 | const atom = switch (function.bin_file.tag) { | |
| 192 | .elf => &fn_owner_decl.link.elf.dbg_info_atom, | |
| 193 | .macho => &fn_owner_decl.link.macho.dbg_info_atom, | |
| 194 | else => unreachable, | |
| 195 | }; | |
| 190 | 196 | |
| 191 | 197 | switch (function.debug_output) { |
| 192 | 198 | .dwarf => |dw| { |
| 193 | const dbg_info = &dw.dbg_info; | |
| 194 | 199 | switch (reloc.mcv) { |
| 195 | 200 | .register => |reg| { |
| 196 | try dbg_info.ensureUnusedCapacity(3); | |
| 197 | dbg_info.appendAssumeCapacity(@enumToInt(link.File.Dwarf.AbbrevKind.parameter)); | |
| 198 | dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc | |
| 199 | 1, // ULEB128 dwarf expression length | |
| 200 | reg.dwarfLocOp(), | |
| 201 | try dw.genArgDbgInfo(reloc.name, reloc.ty, atom, .{ | |
| 202 | .register = reg.dwarfLocOp(), | |
| 201 | 203 | }); |
| 202 | try dbg_info.ensureUnusedCapacity(5 + name_with_null.len); | |
| 203 | try function.addDbgInfoTypeReloc(reloc.ty); // DW.AT.type, DW.FORM.ref4 | |
| 204 | dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string | |
| 205 | 204 | }, |
| 206 | 205 | |
| 207 | 206 | .stack_offset, |
| ... | ... | @@ -212,20 +211,12 @@ const DbgInfoReloc = struct { |
| 212 | 211 | .stack_argument_offset => @intCast(i32, function.saved_regs_stack_space + offset), |
| 213 | 212 | else => unreachable, |
| 214 | 213 | }; |
| 215 | ||
| 216 | try dbg_info.ensureUnusedCapacity(8); | |
| 217 | dbg_info.appendAssumeCapacity(@enumToInt(link.File.Dwarf.AbbrevKind.parameter)); | |
| 218 | const fixup = dbg_info.items.len; | |
| 219 | dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc | |
| 220 | 1, // we will backpatch it after we encode the displacement in LEB128 | |
| 221 | Register.x29.dwarfLocOpDeref(), // frame pointer | |
| 214 | try dw.genArgDbgInfo(reloc.name, reloc.ty, atom, .{ | |
| 215 | .stack = .{ | |
| 216 | .fp_register = Register.x29.dwarfLocOpDeref(), | |
| 217 | .offset = adjusted_offset, | |
| 218 | }, | |
| 222 | 219 | }); |
| 223 | leb128.writeILEB128(dbg_info.writer(), adjusted_offset) catch unreachable; | |
| 224 | dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2); | |
| 225 | try dbg_info.ensureUnusedCapacity(5 + name_with_null.len); | |
| 226 | try function.addDbgInfoTypeReloc(reloc.ty); // DW.AT.type, DW.FORM.ref4 | |
| 227 | dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string | |
| 228 | ||
| 229 | 220 | }, |
| 230 | 221 | |
| 231 | 222 | else => unreachable, // not a possible argument |
src/arch/x86_64/CodeGen.zig+17-28| ... | ... | @@ -3818,38 +3818,27 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void { |
| 3818 | 3818 | } |
| 3819 | 3819 | |
| 3820 | 3820 | fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void { |
| 3821 | const name_with_null = name.ptr[0 .. name.len + 1]; | |
| 3821 | const mod = self.bin_file.options.module.?; | |
| 3822 | const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); | |
| 3823 | const atom = switch (self.bin_file.tag) { | |
| 3824 | .elf => &fn_owner_decl.link.elf.dbg_info_atom, | |
| 3825 | .macho => &fn_owner_decl.link.macho.dbg_info_atom, | |
| 3826 | else => unreachable, | |
| 3827 | }; | |
| 3828 | ||
| 3822 | 3829 | switch (self.debug_output) { |
| 3823 | 3830 | .dwarf => |dw| { |
| 3824 | const dbg_info = &dw.dbg_info; | |
| 3825 | 3831 | switch (mcv) { |
| 3826 | .register => |reg| { | |
| 3827 | try dbg_info.ensureUnusedCapacity(3); | |
| 3828 | dbg_info.appendAssumeCapacity(@enumToInt(link.File.Dwarf.AbbrevKind.parameter)); | |
| 3829 | dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc | |
| 3830 | 1, // ULEB128 dwarf expression length | |
| 3831 | reg.dwarfLocOp(), | |
| 3832 | }); | |
| 3833 | try dbg_info.ensureUnusedCapacity(5 + name_with_null.len); | |
| 3834 | try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4 | |
| 3835 | dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string | |
| 3836 | }, | |
| 3837 | ||
| 3838 | .stack_offset => |off| { | |
| 3839 | try dbg_info.ensureUnusedCapacity(8); | |
| 3840 | dbg_info.appendAssumeCapacity(@enumToInt(link.File.Dwarf.AbbrevKind.parameter)); | |
| 3841 | const fixup = dbg_info.items.len; | |
| 3842 | dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc | |
| 3843 | 1, // we will backpatch it after we encode the displacement in LEB128 | |
| 3844 | Register.rbp.dwarfLocOpDeref(), // TODO handle -fomit-frame-pointer | |
| 3845 | }); | |
| 3846 | leb128.writeILEB128(dbg_info.writer(), -off) catch unreachable; | |
| 3847 | dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2); | |
| 3848 | try dbg_info.ensureUnusedCapacity(5 + name_with_null.len); | |
| 3849 | try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4 | |
| 3850 | dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string | |
| 3832 | .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{ | |
| 3833 | .register = reg.dwarfLocOp(), | |
| 3834 | }), | |
| 3851 | 3835 | |
| 3852 | }, | |
| 3836 | .stack_offset => |off| try dw.genArgDbgInfo(name, ty, atom, .{ | |
| 3837 | .stack = .{ | |
| 3838 | .fp_register = Register.rbp.dwarfLocOpDeref(), // TODO handle -fomit-frame-pointer | |
| 3839 | .offset = -off, | |
| 3840 | }, | |
| 3841 | }), | |
| 3853 | 3842 | |
| 3854 | 3843 | else => unreachable, // not a valid function parameter |
| 3855 | 3844 | } |
src/link/Dwarf.zig+46| ... | ... | @@ -560,6 +560,52 @@ pub const DeclState = struct { |
| 560 | 560 | }, |
| 561 | 561 | } |
| 562 | 562 | } |
| 563 | ||
| 564 | pub fn genArgDbgInfo( | |
| 565 | self: *DeclState, | |
| 566 | name: [:0]const u8, | |
| 567 | ty: Type, | |
| 568 | atom: *Atom, | |
| 569 | loc: union(enum) { | |
| 570 | register: u8, | |
| 571 | stack: struct { fp_register: u8, offset: i32 }, | |
| 572 | }, | |
| 573 | ) error{OutOfMemory}!void { | |
| 574 | const dbg_info = &self.dbg_info; | |
| 575 | const name_with_null = name.ptr[0 .. name.len + 1]; | |
| 576 | ||
| 577 | switch (loc) { | |
| 578 | .register => |reg| { | |
| 579 | try dbg_info.ensureUnusedCapacity(3); | |
| 580 | dbg_info.appendAssumeCapacity(@enumToInt(AbbrevKind.parameter)); | |
| 581 | dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc | |
| 582 | 1, // ULEB128 dwarf expression length | |
| 583 | reg, | |
| 584 | }); | |
| 585 | try dbg_info.ensureUnusedCapacity(5 + name_with_null.len); | |
| 586 | const index = dbg_info.items.len; | |
| 587 | try self.addTypeRelocGlobal(atom, ty, @intCast(u32, index)); // DW.AT.type, DW.FORM.ref4 | |
| 588 | dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string | |
| 589 | ||
| 590 | }, | |
| 591 | .stack => |info| { | |
| 592 | try dbg_info.ensureUnusedCapacity(8); | |
| 593 | dbg_info.appendAssumeCapacity(@enumToInt(AbbrevKind.parameter)); | |
| 594 | const fixup = dbg_info.items.len; | |
| 595 | dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc | |
| 596 | 1, // we will backpatch it after we encode the displacement in LEB128 | |
| 597 | info.fp_register, // frame pointer | |
| 598 | }); | |
| 599 | leb128.writeILEB128(dbg_info.writer(), info.offset) catch unreachable; | |
| 600 | dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2); | |
| 601 | try dbg_info.ensureUnusedCapacity(5 + name_with_null.len); | |
| 602 | const index = dbg_info.items.len; | |
| 603 | try self.addTypeRelocGlobal(atom, ty, @intCast(u32, index)); | |
| 604 | dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string | |
| 605 | ||
| 606 | }, | |
| 607 | } | |
| 608 | } | |
| 563 | 609 | }; |
| 564 | 610 | |
| 565 | 611 | pub const AbbrevEntry = struct { |