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 {...@@ -245,15 +245,8 @@ const DbgInfoReloc = struct {
245 },245 },
246 };246 };
247 },247 },
248 .memory => |address| .{ .memory = .{248 .memory => |address| .{ .memory = address },
249 .address = address,249 .linker_load => |linker_load| .{ .linker_load = linker_load },
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 } },
257 .immediate => |x| .{ .immediate = x },250 .immediate => |x| .{ .immediate = x },
258 .undef => .undef,251 .undef => .undef,
259 .none => .none,252 .none => .none,
...@@ -262,7 +255,7 @@ const DbgInfoReloc = struct {...@@ -262,7 +255,7 @@ const DbgInfoReloc = struct {
262 break :blk .nop;255 break :blk .nop;
263 },256 },
264 };257 };
265 try dw.genVarDbgInfo(reloc.name, reloc.ty, atom, loc);258 try dw.genVarDbgInfo(reloc.name, reloc.ty, atom, is_ptr, loc);
266 },259 },
267 .plan9 => {},260 .plan9 => {},
268 .none => {},261 .none => {},
src/arch/x86_64/CodeGen.zig+3-10
...@@ -3862,15 +3862,8 @@ fn genVarDbgInfo(...@@ -3862,15 +3862,8 @@ fn genVarDbgInfo(
3862 .fp_register = Register.rbp.dwarfLocOpDeref(),3862 .fp_register = Register.rbp.dwarfLocOpDeref(),
3863 .offset = -off,3863 .offset = -off,
3864 } },3864 } },
3865 .memory => |address| .{ .memory = .{3865 .memory => |address| .{ .memory = address },
3866 .address = address,3866 .linker_load => |linker_load| .{ .linker_load = linker_load },
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 } },
3874 .immediate => |x| .{ .immediate = x },3867 .immediate => |x| .{ .immediate = x },
3875 .undef => .undef,3868 .undef => .undef,
3876 .none => .none,3869 .none => .none,
...@@ -3879,7 +3872,7 @@ fn genVarDbgInfo(...@@ -3879,7 +3872,7 @@ fn genVarDbgInfo(
3879 break :blk .nop;3872 break :blk .nop;
3880 },3873 },
3881 };3874 };
3882 try dw.genVarDbgInfo(name, ty, atom, loc);3875 try dw.genVarDbgInfo(name, ty, atom, is_ptr, loc);
3883 },3876 },
3884 .plan9 => {},3877 .plan9 => {},
3885 .none => {},3878 .none => {},
src/link/Dwarf.zig+30-19
...@@ -585,6 +585,7 @@ pub const DeclState = struct {...@@ -585,6 +585,7 @@ pub const DeclState = struct {
585 });585 });
586 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);586 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
587 const index = dbg_info.items.len;587 const index = dbg_info.items.len;
588 try dbg_info.resize(index + 4); // dw.at.type, dw.form.ref4
588 try self.addTypeRelocGlobal(atom, ty, @intCast(u32, index)); // DW.AT.type, DW.FORM.ref4589 try self.addTypeRelocGlobal(atom, ty, @intCast(u32, index)); // DW.AT.type, DW.FORM.ref4
589 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string590 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
590591
...@@ -601,6 +602,7 @@ pub const DeclState = struct {...@@ -601,6 +602,7 @@ pub const DeclState = struct {
601 dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2);602 dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2);
602 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);603 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
603 const index = dbg_info.items.len;604 const index = dbg_info.items.len;
605 try dbg_info.resize(index + 4); // dw.at.type, dw.form.ref4
604 try self.addTypeRelocGlobal(atom, ty, @intCast(u32, index));606 try self.addTypeRelocGlobal(atom, ty, @intCast(u32, index));
605 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string607 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
606608
...@@ -614,11 +616,8 @@ pub const DeclState = struct {...@@ -614,11 +616,8 @@ pub const DeclState = struct {
614 fp_register: u8,616 fp_register: u8,
615 offset: i32,617 offset: i32,
616 },618 },
617 memory: struct {619 memory: u64,
618 address: u64,620 linker_load: LinkerLoad,
619 is_ptr: bool,
620 linker_load: ?LinkerLoad = null,
621 },
622 immediate: u64,621 immediate: u64,
623 undef,622 undef,
624 none,623 none,
...@@ -630,6 +629,7 @@ pub const DeclState = struct {...@@ -630,6 +629,7 @@ pub const DeclState = struct {
630 name: [:0]const u8,629 name: [:0]const u8,
631 ty: Type,630 ty: Type,
632 atom: *Atom,631 atom: *Atom,
632 is_ptr: bool,
633 loc: VarArgDbgInfoLoc,633 loc: VarArgDbgInfoLoc,
634 ) error{OutOfMemory}!void {634 ) error{OutOfMemory}!void {
635 const dbg_info = &self.dbg_info;635 const dbg_info = &self.dbg_info;
...@@ -637,6 +637,7 @@ pub const DeclState = struct {...@@ -637,6 +637,7 @@ pub const DeclState = struct {
637 try dbg_info.append(@enumToInt(AbbrevKind.variable));637 try dbg_info.append(@enumToInt(AbbrevKind.variable));
638 const target = self.mod.getTarget();638 const target = self.mod.getTarget();
639 const endian = target.cpu.arch.endian();639 const endian = target.cpu.arch.endian();
640 const child_ty = if (is_ptr) ty.childType() else ty;
640641
641 switch (loc) {642 switch (loc) {
642 .register => |reg| {643 .register => |reg| {
...@@ -658,32 +659,41 @@ pub const DeclState = struct {...@@ -658,32 +659,41 @@ pub const DeclState = struct {
658 dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2);659 dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2);
659 },660 },
660661
661 .memory => |info| {662 .memory,
663 .linker_load,
664 => {
662 const ptr_width = @intCast(u8, @divExact(target.cpu.arch.ptrBitWidth(), 8));665 const ptr_width = @intCast(u8, @divExact(target.cpu.arch.ptrBitWidth(), 8));
663 try dbg_info.ensureUnusedCapacity(2 + ptr_width);666 try dbg_info.ensureUnusedCapacity(2 + ptr_width);
664 dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc667 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),
666 DW.OP.addr, // literal address669 DW.OP.addr, // literal address
667 });670 });
668 const offset = @intCast(u32, dbg_info.items.len);671 const offset = @intCast(u32, dbg_info.items.len);
672 const addr = switch (loc) {
673 .memory => |x| x,
674 else => 0,
675 };
669 switch (ptr_width) {676 switch (ptr_width) {
670 0...4 => {677 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);
672 },679 },
673 5...8 => {680 5...8 => {
674 try dbg_info.writer().writeInt(u64, info.address, endian);681 try dbg_info.writer().writeInt(u64, addr, endian);
675 },682 },
676 else => unreachable,683 else => unreachable,
677 }684 }
678 if (info.is_ptr) {685 if (is_ptr) {
679 // We need deref the address as we point to the value via GOT entry.686 // We need deref the address as we point to the value via GOT entry.
680 try dbg_info.append(DW.OP.deref);687 try dbg_info.append(DW.OP.deref);
681 }688 }
682 if (info.linker_load) |load_struct| try self.addExprlocReloc(689 switch (loc) {
683 load_struct.sym_index,690 .linker_load => |load_struct| try self.addExprlocReloc(
684 offset,691 load_struct.sym_index,
685 info.is_ptr,692 offset,
686 );693 is_ptr,
694 ),
695 else => {},
696 }
687 },697 },
688698
689 .immediate => |x| {699 .immediate => |x| {
...@@ -691,9 +701,9 @@ pub const DeclState = struct {...@@ -691,9 +701,9 @@ pub const DeclState = struct {
691 const fixup = dbg_info.items.len;701 const fixup = dbg_info.items.len;
692 dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc702 dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc
693 1,703 1,
694 if (ty.isSignedInt()) DW.OP.consts else DW.OP.constu,704 if (child_ty.isSignedInt()) DW.OP.consts else DW.OP.constu,
695 });705 });
696 if (ty.isSignedInt()) {706 if (child_ty.isSignedInt()) {
697 try leb128.writeILEB128(dbg_info.writer(), @bitCast(i64, x));707 try leb128.writeILEB128(dbg_info.writer(), @bitCast(i64, x));
698 } else {708 } else {
699 try leb128.writeULEB128(dbg_info.writer(), x);709 try leb128.writeULEB128(dbg_info.writer(), x);
...@@ -706,7 +716,7 @@ pub const DeclState = struct {...@@ -706,7 +716,7 @@ pub const DeclState = struct {
706 // DW.AT.location, DW.FORM.exprloc716 // DW.AT.location, DW.FORM.exprloc
707 // uleb128(exprloc_len)717 // uleb128(exprloc_len)
708 // DW.OP.implicit_value uleb128(len_of_bytes) bytes718 // 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));
710 var implicit_value_len = std.ArrayList(u8).init(self.gpa);720 var implicit_value_len = std.ArrayList(u8).init(self.gpa);
711 defer implicit_value_len.deinit();721 defer implicit_value_len.deinit();
712 try leb128.writeULEB128(implicit_value_len.writer(), abi_size);722 try leb128.writeULEB128(implicit_value_len.writer(), abi_size);
...@@ -735,7 +745,8 @@ pub const DeclState = struct {...@@ -735,7 +745,8 @@ pub const DeclState = struct {
735745
736 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);746 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
737 const index = dbg_info.items.len;747 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));
739 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string750 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
740 }751 }
741};752};