| ... | ... | @@ -101,22 +101,22 @@ fn mirDbgLine(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | | fn mirDebugPrologueEnd(self: *Emit) !void { |
| 105 | | switch (self.debug_output) { |
| 104 | fn mirDebugPrologueEnd(emit: *Emit) !void { |
| 105 | switch (emit.debug_output) { |
| 106 | 106 | .dwarf => |dbg_out| { |
| 107 | 107 | try dbg_out.dbg_line.append(DW.LNS.set_prologue_end); |
| 108 | | try self.dbgAdvancePCAndLine(self.prev_di_line, self.prev_di_column); |
| 108 | try emit.dbgAdvancePCAndLine(emit.prev_di_line, emit.prev_di_column); |
| 109 | 109 | }, |
| 110 | 110 | .plan9 => {}, |
| 111 | 111 | .none => {}, |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | | fn mirDebugEpilogueBegin(self: *Emit) !void { |
| 116 | | switch (self.debug_output) { |
| 115 | fn mirDebugEpilogueBegin(emit: *Emit) !void { |
| 116 | switch (emit.debug_output) { |
| 117 | 117 | .dwarf => |dbg_out| { |
| 118 | 118 | try dbg_out.dbg_line.append(DW.LNS.set_epilogue_begin); |
| 119 | | try self.dbgAdvancePCAndLine(self.prev_di_line, self.prev_di_column); |
| 119 | try emit.dbgAdvancePCAndLine(emit.prev_di_line, emit.prev_di_column); |
| 120 | 120 | }, |
| 121 | 121 | .plan9 => {}, |
| 122 | 122 | .none => {}, |
| ... | ... | @@ -232,10 +232,10 @@ fn mirTrap(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 232 | 232 | |
| 233 | 233 | // Common helper functions |
| 234 | 234 | |
| 235 | | fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void { |
| 236 | | const delta_line = @intCast(i32, line) - @intCast(i32, self.prev_di_line); |
| 237 | | const delta_pc: usize = self.code.items.len - self.prev_di_pc; |
| 238 | | switch (self.debug_output) { |
| 235 | fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) !void { |
| 236 | const delta_line = @intCast(i32, line) - @intCast(i32, emit.prev_di_line); |
| 237 | const delta_pc: usize = emit.code.items.len - emit.prev_di_pc; |
| 238 | switch (emit.debug_output) { |
| 239 | 239 | .dwarf => |dbg_out| { |
| 240 | 240 | // TODO Look into using the DWARF special opcodes to compress this data. |
| 241 | 241 | // It lets you emit single-byte opcodes that add different numbers to |
| ... | ... | @@ -248,38 +248,12 @@ fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void { |
| 248 | 248 | leb128.writeILEB128(dbg_out.dbg_line.writer(), delta_line) catch unreachable; |
| 249 | 249 | } |
| 250 | 250 | dbg_out.dbg_line.appendAssumeCapacity(DW.LNS.copy); |
| 251 | | self.prev_di_pc = self.code.items.len; |
| 252 | | self.prev_di_line = line; |
| 253 | | self.prev_di_column = column; |
| 254 | | self.prev_di_pc = self.code.items.len; |
| 251 | emit.prev_di_pc = emit.code.items.len; |
| 252 | emit.prev_di_line = line; |
| 253 | emit.prev_di_column = column; |
| 254 | emit.prev_di_pc = emit.code.items.len; |
| 255 | 255 | }, |
| 256 | | .plan9 => |dbg_out| { |
| 257 | | if (delta_pc <= 0) return; // only do this when the pc changes |
| 258 | | // we have already checked the target in the linker to make sure it is compatable |
| 259 | | const quant = @import("../../link/Plan9/aout.zig").getPCQuant(self.target.cpu.arch) catch unreachable; |
| 260 | | |
| 261 | | // increasing the line number |
| 262 | | try @import("../../link/Plan9.zig").changeLine(dbg_out.dbg_line, delta_line); |
| 263 | | // increasing the pc |
| 264 | | const d_pc_p9 = @intCast(i64, delta_pc) - quant; |
| 265 | | if (d_pc_p9 > 0) { |
| 266 | | // minus one because if its the last one, we want to leave space to change the line which is one quanta |
| 267 | | try dbg_out.dbg_line.append(@intCast(u8, @divExact(d_pc_p9, quant) + 128) - quant); |
| 268 | | if (dbg_out.pcop_change_index.*) |pci| |
| 269 | | dbg_out.dbg_line.items[pci] += 1; |
| 270 | | dbg_out.pcop_change_index.* = @intCast(u32, dbg_out.dbg_line.items.len - 1); |
| 271 | | } else if (d_pc_p9 == 0) { |
| 272 | | // we don't need to do anything, because adding the quant does it for us |
| 273 | | } else unreachable; |
| 274 | | if (dbg_out.start_line.* == null) |
| 275 | | dbg_out.start_line.* = self.prev_di_line; |
| 276 | | dbg_out.end_line.* = line; |
| 277 | | // only do this if the pc changed |
| 278 | | self.prev_di_line = line; |
| 279 | | self.prev_di_column = column; |
| 280 | | self.prev_di_pc = self.code.items.len; |
| 281 | | }, |
| 282 | | .none => {}, |
| 256 | else => {}, |
| 283 | 257 | } |
| 284 | 258 | } |
| 285 | 259 | |