aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2022-04-13 14:31:04 +0200
committerJakub Konka <kubkon@jakubkonka.com>2022-04-13 14:31:04 +0200
commit4c50a27d682d3241ec73c7130d69d1d2f2553b86 (patch)
tree6d6bc54566cc7b2cb2c99f1e2ac9b9a932df7c1d /src
parentbaeff1762b90fc9a4cd4b1d6a7db6ba43fd35356 (diff)
downloadzig-4c50a27d682d3241ec73c7130d69d1d2f2553b86.tar.gz
zig-4c50a27d682d3241ec73c7130d69d1d2f2553b86.zip
stage2,x64: generate debug info for local vars at hardcoded mem addr
Diffstat (limited to 'src')
-rw-r--r--src/arch/x86_64/CodeGen.zig66
1 files changed, 37 insertions, 29 deletions
diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig
index 71074edc2d..a06f7941b4 100644
--- a/src/arch/x86_64/CodeGen.zig
+++ b/src/arch/x86_64/CodeGen.zig
@@ -3926,31 +3926,21 @@ fn genVarDbgInfo(
name: [:0]const u8,
) !void {
const name_with_null = name.ptr[0 .. name.len + 1];
- switch (mcv) {
- .register => |reg| {
- switch (self.debug_output) {
- .dwarf => |dw| {
- const dbg_info = &dw.dbg_info;
- try dbg_info.ensureUnusedCapacity(3);
- dbg_info.appendAssumeCapacity(@enumToInt(link.File.Dwarf.AbbrevKind.variable));
+ switch (self.debug_output) {
+ .dwarf => |dw| {
+ const dbg_info = &dw.dbg_info;
+ try dbg_info.append(@enumToInt(link.File.Dwarf.AbbrevKind.variable));
+
+ switch (mcv) {
+ .register => |reg| {
+ try dbg_info.ensureUnusedCapacity(2);
dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc
1, // ULEB128 dwarf expression length
reg.dwarfLocOp(),
});
- try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
- try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4
- dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
},
- .plan9 => {},
- .none => {},
- }
- },
- .ptr_stack_offset, .stack_offset => |off| {
- switch (self.debug_output) {
- .dwarf => |dw| {
- const dbg_info = &dw.dbg_info;
- try dbg_info.ensureUnusedCapacity(8);
- dbg_info.appendAssumeCapacity(@enumToInt(link.File.Dwarf.AbbrevKind.variable));
+ .ptr_stack_offset, .stack_offset => |off| {
+ try dbg_info.ensureUnusedCapacity(7);
const fixup = dbg_info.items.len;
dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc
1, // we will backpatch it after we encode the displacement in LEB128
@@ -3958,18 +3948,36 @@ fn genVarDbgInfo(
});
leb128.writeILEB128(dbg_info.writer(), -off) catch unreachable;
dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2);
- try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
- try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4
- dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
-
},
- .plan9 => {},
- .none => {},
+ .memory => |addr| {
+ const endian = self.target.cpu.arch.endian();
+ const ptr_width = @intCast(u8, @divExact(self.target.cpu.arch.ptrBitWidth(), 8));
+ try dbg_info.ensureUnusedCapacity(2 + ptr_width);
+ dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc
+ 1 + ptr_width,
+ DW.OP.addr, // literal address
+ });
+ switch (ptr_width) {
+ 0...4 => {
+ try dbg_info.writer().writeInt(u32, @intCast(u32, addr), endian);
+ },
+ 5...8 => {
+ try dbg_info.writer().writeInt(u64, addr, endian);
+ },
+ else => unreachable,
+ }
+ },
+ else => {
+ log.debug("TODO generate debug info for {}", .{mcv});
+ },
}
+
+ try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
+ try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4
+ dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
},
- else => {
- log.debug("TODO generate debug info for {}", .{mcv});
- },
+ .plan9 => {},
+ .none => {},
}
}