| ... | ... | @@ -9,6 +9,7 @@ const ErrorMsg = Module.ErrorMsg; |
| 9 | 9 | const Liveness = @import("../../Liveness.zig"); |
| 10 | 10 | const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput; |
| 11 | 11 | const DW = std.dwarf; |
| 12 | const leb128 = std.leb; |
| 12 | 13 | |
| 13 | 14 | const Emit = @This(); |
| 14 | 15 | const Mir = @import("Mir.zig"); |
| ... | ... | @@ -60,11 +61,54 @@ pub fn deinit(emit: *Emit) void { |
| 60 | 61 | } |
| 61 | 62 | |
| 62 | 63 | fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void { |
| 63 | | _ = self; |
| 64 | | _ = line; |
| 65 | | _ = column; |
| 66 | | |
| 67 | | @panic("TODO implement dbgAdvancePCAndLine"); |
| 64 | const delta_line = @intCast(i32, line) - @intCast(i32, self.prev_di_line); |
| 65 | const delta_pc: usize = self.code.items.len - self.prev_di_pc; |
| 66 | switch (self.debug_output) { |
| 67 | .dwarf => |dbg_out| { |
| 68 | // TODO Look into using the DWARF special opcodes to compress this data. |
| 69 | // It lets you emit single-byte opcodes that add different numbers to |
| 70 | // both the PC and the line number at the same time. |
| 71 | try dbg_out.dbg_line.ensureUnusedCapacity(11); |
| 72 | dbg_out.dbg_line.appendAssumeCapacity(DW.LNS.advance_pc); |
| 73 | leb128.writeULEB128(dbg_out.dbg_line.writer(), delta_pc) catch unreachable; |
| 74 | if (delta_line != 0) { |
| 75 | dbg_out.dbg_line.appendAssumeCapacity(DW.LNS.advance_line); |
| 76 | leb128.writeILEB128(dbg_out.dbg_line.writer(), delta_line) catch unreachable; |
| 77 | } |
| 78 | dbg_out.dbg_line.appendAssumeCapacity(DW.LNS.copy); |
| 79 | self.prev_di_pc = self.code.items.len; |
| 80 | self.prev_di_line = line; |
| 81 | self.prev_di_column = column; |
| 82 | self.prev_di_pc = self.code.items.len; |
| 83 | }, |
| 84 | .plan9 => |dbg_out| { |
| 85 | if (delta_pc <= 0) return; // only do this when the pc changes |
| 86 | // we have already checked the target in the linker to make sure it is compatable |
| 87 | const quant = @import("../../link/Plan9/aout.zig").getPCQuant(self.target.cpu.arch) catch unreachable; |
| 88 | |
| 89 | // increasing the line number |
| 90 | try @import("../../link/Plan9.zig").changeLine(dbg_out.dbg_line, delta_line); |
| 91 | // increasing the pc |
| 92 | const d_pc_p9 = @intCast(i64, delta_pc) - quant; |
| 93 | if (d_pc_p9 > 0) { |
| 94 | // minus one because if its the last one, we want to leave space to change the line which is one quanta |
| 95 | try dbg_out.dbg_line.append(@intCast(u8, @divExact(d_pc_p9, quant) + 128) - quant); |
| 96 | if (dbg_out.pcop_change_index.*) |pci| |
| 97 | dbg_out.dbg_line.items[pci] += 1; |
| 98 | dbg_out.pcop_change_index.* = @intCast(u32, dbg_out.dbg_line.items.len - 1); |
| 99 | } else if (d_pc_p9 == 0) { |
| 100 | // we don't need to do anything, because adding the quant does it for us |
| 101 | } else unreachable; |
| 102 | if (dbg_out.start_line.* == null) |
| 103 | dbg_out.start_line.* = self.prev_di_line; |
| 104 | dbg_out.end_line.* = line; |
| 105 | // only do this if the pc changed |
| 106 | self.prev_di_line = line; |
| 107 | self.prev_di_column = column; |
| 108 | self.prev_di_pc = self.code.items.len; |
| 109 | }, |
| 110 | .none => {}, |
| 111 | } |
| 68 | 112 | } |
| 69 | 113 | |
| 70 | 114 | fn mirDbgLine(emit: *Emit, inst: Mir.Inst.Index) !void { |