authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-13 14:31:04+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-13 14:31:04+02:00
log4c50a27d682d3241ec73c7130d69d1d2f2553b86
tree6d6bc54566cc7b2cb2c99f1e2ac9b9a932df7c1d
parentbaeff1762b90fc9a4cd4b1d6a7db6ba43fd35356

stage2,x64: generate debug info for local vars at hardcoded mem addr


1 files changed, 37 insertions(+), 29 deletions(-)

src/arch/x86_64/CodeGen.zig+37-29
...@@ -3926,31 +3926,21 @@ fn genVarDbgInfo(...@@ -3926,31 +3926,21 @@ fn genVarDbgInfo(
3926 name: [:0]const u8,3926 name: [:0]const u8,
3927) !void {3927) !void {
3928 const name_with_null = name.ptr[0 .. name.len + 1];3928 const name_with_null = name.ptr[0 .. name.len + 1];
3929 switch (mcv) {3929 switch (self.debug_output) {
3930 .register => |reg| {3930 .dwarf => |dw| {
3931 switch (self.debug_output) {3931 const dbg_info = &dw.dbg_info;
3932 .dwarf => |dw| {3932 try dbg_info.append(@enumToInt(link.File.Dwarf.AbbrevKind.variable));
3933 const dbg_info = &dw.dbg_info;3933
3934 try dbg_info.ensureUnusedCapacity(3);3934 switch (mcv) {
3935 dbg_info.appendAssumeCapacity(@enumToInt(link.File.Dwarf.AbbrevKind.variable));3935 .register => |reg| {
3936 try dbg_info.ensureUnusedCapacity(2);
3936 dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc3937 dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc
3937 1, // ULEB128 dwarf expression length3938 1, // ULEB128 dwarf expression length
3938 reg.dwarfLocOp(),3939 reg.dwarfLocOp(),
3939 });3940 });
3940 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
3941 try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4
3942 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
3943 },3941 },
3944 .plan9 => {},3942 .ptr_stack_offset, .stack_offset => |off| {
3945 .none => {},3943 try dbg_info.ensureUnusedCapacity(7);
3946 }
3947 },
3948 .ptr_stack_offset, .stack_offset => |off| {
3949 switch (self.debug_output) {
3950 .dwarf => |dw| {
3951 const dbg_info = &dw.dbg_info;
3952 try dbg_info.ensureUnusedCapacity(8);
3953 dbg_info.appendAssumeCapacity(@enumToInt(link.File.Dwarf.AbbrevKind.variable));
3954 const fixup = dbg_info.items.len;3944 const fixup = dbg_info.items.len;
3955 dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc3945 dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc
3956 1, // we will backpatch it after we encode the displacement in LEB1283946 1, // we will backpatch it after we encode the displacement in LEB128
...@@ -3958,18 +3948,36 @@ fn genVarDbgInfo(...@@ -3958,18 +3948,36 @@ fn genVarDbgInfo(
3958 });3948 });
3959 leb128.writeILEB128(dbg_info.writer(), -off) catch unreachable;3949 leb128.writeILEB128(dbg_info.writer(), -off) catch unreachable;
3960 dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2);3950 dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2);
3961 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
3962 try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4
3963 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
3964
3965 },3951 },
3966 .plan9 => {},3952 .memory => |addr| {
3967 .none => {},3953 const endian = self.target.cpu.arch.endian();
3954 const ptr_width = @intCast(u8, @divExact(self.target.cpu.arch.ptrBitWidth(), 8));
3955 try dbg_info.ensureUnusedCapacity(2 + ptr_width);
3956 dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc
3957 1 + ptr_width,
3958 DW.OP.addr, // literal address
3959 });
3960 switch (ptr_width) {
3961 0...4 => {
3962 try dbg_info.writer().writeInt(u32, @intCast(u32, addr), endian);
3963 },
3964 5...8 => {
3965 try dbg_info.writer().writeInt(u64, addr, endian);
3966 },
3967 else => unreachable,
3968 }
3969 },
3970 else => {
3971 log.debug("TODO generate debug info for {}", .{mcv});
3972 },
3968 }3973 }
3974
3975 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
3976 try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4
3977 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
3969 },3978 },
3970 else => {3979 .plan9 => {},
3971 log.debug("TODO generate debug info for {}", .{mcv});3980 .none => {},
3972 },
3973 }3981 }
3974}3982}
39753983