| ... | @@ -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.ref4 | 589 | 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.string | 590 | dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string |
| 590 | | 591 | |
| ... | @@ -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.string | 607 | dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string |
| 606 | | 608 | |
| ... | @@ -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; |
| 640 | | 641 | |
| 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 | }, |
| 660 | | 661 | |
| 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.exprloc | 667 | 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 address | 669 | 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 | }, |
| 688 | | 698 | |
| 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.exprloc | 702 | 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.exprloc | 716 | // DW.AT.location, DW.FORM.exprloc |
| 707 | // uleb128(exprloc_len) | 717 | // uleb128(exprloc_len) |
| 708 | // DW.OP.implicit_value uleb128(len_of_bytes) bytes | 718 | // 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 { |
| 735 | | 745 | |
| 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.string | 750 | dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string |
| 740 | } | 751 | } |
| 741 | }; | 752 | }; |