| ... | ... | @@ -585,6 +585,7 @@ pub const DeclState = struct { |
| 585 | 585 | }); |
| 586 | 586 | try dbg_info.ensureUnusedCapacity(5 + name_with_null.len); |
| 587 | 587 | const index = dbg_info.items.len; |
| 588 | try dbg_info.resize(index + 4); // dw.at.type, dw.form.ref4 |
| 588 | 589 | try self.addTypeRelocGlobal(atom, ty, @intCast(u32, index)); // DW.AT.type, DW.FORM.ref4 |
| 589 | 590 | dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string |
| 590 | 591 | |
| ... | ... | @@ -601,6 +602,7 @@ pub const DeclState = struct { |
| 601 | 602 | dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2); |
| 602 | 603 | try dbg_info.ensureUnusedCapacity(5 + name_with_null.len); |
| 603 | 604 | const index = dbg_info.items.len; |
| 605 | try dbg_info.resize(index + 4); // dw.at.type, dw.form.ref4 |
| 604 | 606 | try self.addTypeRelocGlobal(atom, ty, @intCast(u32, index)); |
| 605 | 607 | dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string |
| 606 | 608 | |
| ... | ... | @@ -614,11 +616,8 @@ pub const DeclState = struct { |
| 614 | 616 | fp_register: u8, |
| 615 | 617 | offset: i32, |
| 616 | 618 | }, |
| 617 | | memory: struct { |
| 618 | | address: u64, |
| 619 | | is_ptr: bool, |
| 620 | | linker_load: ?LinkerLoad = null, |
| 621 | | }, |
| 619 | memory: u64, |
| 620 | linker_load: LinkerLoad, |
| 622 | 621 | immediate: u64, |
| 623 | 622 | undef, |
| 624 | 623 | none, |
| ... | ... | @@ -630,6 +629,7 @@ pub const DeclState = struct { |
| 630 | 629 | name: [:0]const u8, |
| 631 | 630 | ty: Type, |
| 632 | 631 | atom: *Atom, |
| 632 | is_ptr: bool, |
| 633 | 633 | loc: VarArgDbgInfoLoc, |
| 634 | 634 | ) error{OutOfMemory}!void { |
| 635 | 635 | const dbg_info = &self.dbg_info; |
| ... | ... | @@ -637,6 +637,7 @@ pub const DeclState = struct { |
| 637 | 637 | try dbg_info.append(@enumToInt(AbbrevKind.variable)); |
| 638 | 638 | const target = self.mod.getTarget(); |
| 639 | 639 | const endian = target.cpu.arch.endian(); |
| 640 | const child_ty = if (is_ptr) ty.childType() else ty; |
| 640 | 641 | |
| 641 | 642 | switch (loc) { |
| 642 | 643 | .register => |reg| { |
| ... | ... | @@ -658,32 +659,41 @@ pub const DeclState = struct { |
| 658 | 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 | 665 | const ptr_width = @intCast(u8, @divExact(target.cpu.arch.ptrBitWidth(), 8)); |
| 663 | 666 | try dbg_info.ensureUnusedCapacity(2 + ptr_width); |
| 664 | 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 | 669 | DW.OP.addr, // literal address |
| 667 | 670 | }); |
| 668 | 671 | const offset = @intCast(u32, dbg_info.items.len); |
| 672 | const addr = switch (loc) { |
| 673 | .memory => |x| x, |
| 674 | else => 0, |
| 675 | }; |
| 669 | 676 | switch (ptr_width) { |
| 670 | 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 | 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 | 683 | else => unreachable, |
| 677 | 684 | } |
| 678 | | if (info.is_ptr) { |
| 685 | if (is_ptr) { |
| 679 | 686 | // We need deref the address as we point to the value via GOT entry. |
| 680 | 687 | try dbg_info.append(DW.OP.deref); |
| 681 | 688 | } |
| 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 | } |
| 687 | 697 | }, |
| 688 | 698 | |
| 689 | 699 | .immediate => |x| { |
| ... | ... | @@ -691,9 +701,9 @@ pub const DeclState = struct { |
| 691 | 701 | const fixup = dbg_info.items.len; |
| 692 | 702 | dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc |
| 693 | 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 | 707 | try leb128.writeILEB128(dbg_info.writer(), @bitCast(i64, x)); |
| 698 | 708 | } else { |
| 699 | 709 | try leb128.writeULEB128(dbg_info.writer(), x); |
| ... | ... | @@ -706,7 +716,7 @@ pub const DeclState = struct { |
| 706 | 716 | // DW.AT.location, DW.FORM.exprloc |
| 707 | 717 | // uleb128(exprloc_len) |
| 708 | 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 | 720 | var implicit_value_len = std.ArrayList(u8).init(self.gpa); |
| 711 | 721 | defer implicit_value_len.deinit(); |
| 712 | 722 | try leb128.writeULEB128(implicit_value_len.writer(), abi_size); |
| ... | ... | @@ -735,7 +745,8 @@ pub const DeclState = struct { |
| 735 | 745 | |
| 736 | 746 | try dbg_info.ensureUnusedCapacity(5 + name_with_null.len); |
| 737 | 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 | 750 | dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string |
| 740 | 751 | } |
| 741 | 752 | }; |