authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-01 17:23:28+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-01 17:23:28+01:00
log41203325770e87920e797a7113da626ce2cf1b06
treef15d44f3ef68bce17ca6750a765edd79dae362f3
parent5bffc17c42bb6eacd0cc09a61954e98ccf912fa4

dwarf: fix typos after refactoring dbi gen


3 files changed, 36 insertions(+), 39 deletions(-)

src/arch/aarch64/CodeGen.zig+3-10
......@@ -245,15 +245,8 @@ const DbgInfoReloc = struct {
245245 },
246246 };
247247 },
248 .memory => |address| .{ .memory = .{
249 .address = address,
250 .is_ptr = is_ptr,
251 } },
252 .linker_load => |linker_load| .{ .memory = .{
253 .address = 0,
254 .is_ptr = is_ptr,
255 .linker_load = linker_load,
256 } },
248 .memory => |address| .{ .memory = address },
249 .linker_load => |linker_load| .{ .linker_load = linker_load },
257250 .immediate => |x| .{ .immediate = x },
258251 .undef => .undef,
259252 .none => .none,
......@@ -262,7 +255,7 @@ const DbgInfoReloc = struct {
262255 break :blk .nop;
263256 },
264257 };
265 try dw.genVarDbgInfo(reloc.name, reloc.ty, atom, loc);
258 try dw.genVarDbgInfo(reloc.name, reloc.ty, atom, is_ptr, loc);
266259 },
267260 .plan9 => {},
268261 .none => {},
src/arch/x86_64/CodeGen.zig+3-10
......@@ -3862,15 +3862,8 @@ fn genVarDbgInfo(
38623862 .fp_register = Register.rbp.dwarfLocOpDeref(),
38633863 .offset = -off,
38643864 } },
3865 .memory => |address| .{ .memory = .{
3866 .address = address,
3867 .is_ptr = is_ptr,
3868 } },
3869 .linker_load => |linker_load| .{ .memory = .{
3870 .address = 0,
3871 .is_ptr = is_ptr,
3872 .linker_load = linker_load,
3873 } },
3865 .memory => |address| .{ .memory = address },
3866 .linker_load => |linker_load| .{ .linker_load = linker_load },
38743867 .immediate => |x| .{ .immediate = x },
38753868 .undef => .undef,
38763869 .none => .none,
......@@ -3879,7 +3872,7 @@ fn genVarDbgInfo(
38793872 break :blk .nop;
38803873 },
38813874 };
3882 try dw.genVarDbgInfo(name, ty, atom, loc);
3875 try dw.genVarDbgInfo(name, ty, atom, is_ptr, loc);
38833876 },
38843877 .plan9 => {},
38853878 .none => {},
src/link/Dwarf.zig+30-19
......@@ -585,6 +585,7 @@ pub const DeclState = struct {
585585 });
586586 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
587587 const index = dbg_info.items.len;
588 try dbg_info.resize(index + 4); // dw.at.type, dw.form.ref4
588589 try self.addTypeRelocGlobal(atom, ty, @intCast(u32, index)); // DW.AT.type, DW.FORM.ref4
589590 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
590591
......@@ -601,6 +602,7 @@ pub const DeclState = struct {
601602 dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2);
602603 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
603604 const index = dbg_info.items.len;
605 try dbg_info.resize(index + 4); // dw.at.type, dw.form.ref4
604606 try self.addTypeRelocGlobal(atom, ty, @intCast(u32, index));
605607 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
606608
......@@ -614,11 +616,8 @@ pub const DeclState = struct {
614616 fp_register: u8,
615617 offset: i32,
616618 },
617 memory: struct {
618 address: u64,
619 is_ptr: bool,
620 linker_load: ?LinkerLoad = null,
621 },
619 memory: u64,
620 linker_load: LinkerLoad,
622621 immediate: u64,
623622 undef,
624623 none,
......@@ -630,6 +629,7 @@ pub const DeclState = struct {
630629 name: [:0]const u8,
631630 ty: Type,
632631 atom: *Atom,
632 is_ptr: bool,
633633 loc: VarArgDbgInfoLoc,
634634 ) error{OutOfMemory}!void {
635635 const dbg_info = &self.dbg_info;
......@@ -637,6 +637,7 @@ pub const DeclState = struct {
637637 try dbg_info.append(@enumToInt(AbbrevKind.variable));
638638 const target = self.mod.getTarget();
639639 const endian = target.cpu.arch.endian();
640 const child_ty = if (is_ptr) ty.childType() else ty;
640641
641642 switch (loc) {
642643 .register => |reg| {
......@@ -658,32 +659,41 @@ pub const DeclState = struct {
658659 dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2);
659660 },
660661
661 .memory => |info| {
662 .memory,
663 .linker_load,
664 => {
662665 const ptr_width = @intCast(u8, @divExact(target.cpu.arch.ptrBitWidth(), 8));
663666 try dbg_info.ensureUnusedCapacity(2 + ptr_width);
664667 dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc
665 1 + ptr_width + @boolToInt(info.is_ptr),
668 1 + ptr_width + @boolToInt(is_ptr),
666669 DW.OP.addr, // literal address
667670 });
668671 const offset = @intCast(u32, dbg_info.items.len);
672 const addr = switch (loc) {
673 .memory => |x| x,
674 else => 0,
675 };
669676 switch (ptr_width) {
670677 0...4 => {
671 try dbg_info.writer().writeInt(u32, @intCast(u32, info.address), endian);
678 try dbg_info.writer().writeInt(u32, @intCast(u32, addr), endian);
672679 },
673680 5...8 => {
674 try dbg_info.writer().writeInt(u64, info.address, endian);
681 try dbg_info.writer().writeInt(u64, addr, endian);
675682 },
676683 else => unreachable,
677684 }
678 if (info.is_ptr) {
685 if (is_ptr) {
679686 // We need deref the address as we point to the value via GOT entry.
680687 try dbg_info.append(DW.OP.deref);
681688 }
682 if (info.linker_load) |load_struct| try self.addExprlocReloc(
683 load_struct.sym_index,
684 offset,
685 info.is_ptr,
686 );
689 switch (loc) {
690 .linker_load => |load_struct| try self.addExprlocReloc(
691 load_struct.sym_index,
692 offset,
693 is_ptr,
694 ),
695 else => {},
696 }
687697 },
688698
689699 .immediate => |x| {
......@@ -691,9 +701,9 @@ pub const DeclState = struct {
691701 const fixup = dbg_info.items.len;
692702 dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc
693703 1,
694 if (ty.isSignedInt()) DW.OP.consts else DW.OP.constu,
704 if (child_ty.isSignedInt()) DW.OP.consts else DW.OP.constu,
695705 });
696 if (ty.isSignedInt()) {
706 if (child_ty.isSignedInt()) {
697707 try leb128.writeILEB128(dbg_info.writer(), @bitCast(i64, x));
698708 } else {
699709 try leb128.writeULEB128(dbg_info.writer(), x);
......@@ -706,7 +716,7 @@ pub const DeclState = struct {
706716 // DW.AT.location, DW.FORM.exprloc
707717 // uleb128(exprloc_len)
708718 // DW.OP.implicit_value uleb128(len_of_bytes) bytes
709 const abi_size = @intCast(u32, ty.abiSize(target));
719 const abi_size = @intCast(u32, child_ty.abiSize(target));
710720 var implicit_value_len = std.ArrayList(u8).init(self.gpa);
711721 defer implicit_value_len.deinit();
712722 try leb128.writeULEB128(implicit_value_len.writer(), abi_size);
......@@ -735,7 +745,8 @@ pub const DeclState = struct {
735745
736746 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
737747 const index = dbg_info.items.len;
738 try self.addTypeRelocGlobal(atom, ty, @intCast(u32, index));
748 try dbg_info.resize(index + 4); // dw.at.type, dw.form.ref4
749 try self.addTypeRelocGlobal(atom, child_ty, @intCast(u32, index));
739750 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
740751 }
741752};