| ... | @@ -438,39 +438,50 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { | ... | @@ -438,39 +438,50 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { |
| 438 | return error.EmitFail; | 438 | return error.EmitFail; |
| 439 | } | 439 | } |
| 440 | | 440 | |
| 441 | fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void { | 441 | fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) InnerError!void { |
| 442 | const delta_line = @as(i32, @intCast(line)) - @as(i32, @intCast(self.prev_di_line)); | 442 | const delta_line = @as(i33, line) - @as(i33, emit.prev_di_line); |
| 443 | const delta_pc: usize = self.code.items.len - self.prev_di_pc; | 443 | const delta_pc: usize = emit.code.items.len - emit.prev_di_pc; |
| 444 | switch (self.debug_output) { | 444 | log.debug(" (advance pc={d} and line={d})", .{ delta_pc, delta_line }); |
| | 445 | switch (emit.debug_output) { |
| 445 | .dwarf => |dw| { | 446 | .dwarf => |dw| { |
| | 447 | if (column != emit.prev_di_column) try dw.setColumn(column); |
| 446 | try dw.advancePCAndLine(delta_line, delta_pc); | 448 | try dw.advancePCAndLine(delta_line, delta_pc); |
| 447 | self.prev_di_line = line; | 449 | emit.prev_di_line = line; |
| 448 | self.prev_di_column = column; | 450 | emit.prev_di_column = column; |
| 449 | self.prev_di_pc = self.code.items.len; | 451 | emit.prev_di_pc = emit.code.items.len; |
| 450 | }, | 452 | }, |
| 451 | .plan9 => |dbg_out| { | 453 | .plan9 => |dbg_out| { |
| 452 | if (delta_pc <= 0) return; // only do this when the pc changes | 454 | if (delta_pc <= 0) return; // only do this when the pc changes |
| 453 | | 455 | |
| 454 | // increasing the line number | 456 | // increasing the line number |
| 455 | try link.File.Plan9.changeLine(&dbg_out.dbg_line, delta_line); | 457 | try link.File.Plan9.changeLine(&dbg_out.dbg_line, @intCast(delta_line)); |
| 456 | // increasing the pc | 458 | // increasing the pc |
| 457 | const d_pc_p9 = @as(i64, @intCast(delta_pc)) - dbg_out.pc_quanta; | 459 | const d_pc_p9 = @as(i64, @intCast(delta_pc)) - dbg_out.pc_quanta; |
| 458 | if (d_pc_p9 > 0) { | 460 | if (d_pc_p9 > 0) { |
| 459 | // minus one because if its the last one, we want to leave space to change the line which is one pc quanta | 461 | // minus one because if its the last one, we want to leave space to change the line which is one pc quanta |
| 460 | try dbg_out.dbg_line.append(@as(u8, @intCast(@divExact(d_pc_p9, dbg_out.pc_quanta) + 128)) - dbg_out.pc_quanta); | 462 | var diff = @divExact(d_pc_p9, dbg_out.pc_quanta) - dbg_out.pc_quanta; |
| | 463 | while (diff > 0) { |
| | 464 | if (diff < 64) { |
| | 465 | try dbg_out.dbg_line.append(@intCast(diff + 128)); |
| | 466 | diff = 0; |
| | 467 | } else { |
| | 468 | try dbg_out.dbg_line.append(@intCast(64 + 128)); |
| | 469 | diff -= 64; |
| | 470 | } |
| | 471 | } |
| 461 | if (dbg_out.pcop_change_index) |pci| | 472 | if (dbg_out.pcop_change_index) |pci| |
| 462 | dbg_out.dbg_line.items[pci] += 1; | 473 | dbg_out.dbg_line.items[pci] += 1; |
| 463 | dbg_out.pcop_change_index = @as(u32, @intCast(dbg_out.dbg_line.items.len - 1)); | 474 | dbg_out.pcop_change_index = @intCast(dbg_out.dbg_line.items.len - 1); |
| 464 | } else if (d_pc_p9 == 0) { | 475 | } else if (d_pc_p9 == 0) { |
| 465 | // we don't need to do anything, because adding the pc quanta does it for us | 476 | // we don't need to do anything, because adding the pc quanta does it for us |
| 466 | } else unreachable; | 477 | } else unreachable; |
| 467 | if (dbg_out.start_line == null) | 478 | if (dbg_out.start_line == null) |
| 468 | dbg_out.start_line = self.prev_di_line; | 479 | dbg_out.start_line = emit.prev_di_line; |
| 469 | dbg_out.end_line = line; | 480 | dbg_out.end_line = line; |
| 470 | // only do this if the pc changed | 481 | // only do this if the pc changed |
| 471 | self.prev_di_line = line; | 482 | emit.prev_di_line = line; |
| 472 | self.prev_di_column = column; | 483 | emit.prev_di_column = column; |
| 473 | self.prev_di_pc = self.code.items.len; | 484 | emit.prev_di_pc = emit.code.items.len; |
| 474 | }, | 485 | }, |
| 475 | .none => {}, | 486 | .none => {}, |
| 476 | } | 487 | } |
| ... | @@ -638,22 +649,25 @@ fn mirDbgLine(emit: *Emit, inst: Mir.Inst.Index) !void { | ... | @@ -638,22 +649,25 @@ fn mirDbgLine(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 638 | } | 649 | } |
| 639 | } | 650 | } |
| 640 | | 651 | |
| 641 | fn mirDebugPrologueEnd(self: *Emit) !void { | 652 | fn mirDebugPrologueEnd(emit: *Emit) !void { |
| 642 | switch (self.debug_output) { | 653 | switch (emit.debug_output) { |
| 643 | .dwarf => |dw| { | 654 | .dwarf => |dw| { |
| 644 | try dw.setPrologueEnd(); | 655 | try dw.setPrologueEnd(); |
| 645 | try self.dbgAdvancePCAndLine(self.prev_di_line, self.prev_di_column); | 656 | log.debug("mirDbgPrologueEnd (line={d}, col={d})", .{ |
| | 657 | emit.prev_di_line, emit.prev_di_column, |
| | 658 | }); |
| | 659 | try emit.dbgAdvancePCAndLine(emit.prev_di_line, emit.prev_di_column); |
| 646 | }, | 660 | }, |
| 647 | .plan9 => {}, | 661 | .plan9 => {}, |
| 648 | .none => {}, | 662 | .none => {}, |
| 649 | } | 663 | } |
| 650 | } | 664 | } |
| 651 | | 665 | |
| 652 | fn mirDebugEpilogueBegin(self: *Emit) !void { | 666 | fn mirDebugEpilogueBegin(emit: *Emit) !void { |
| 653 | switch (self.debug_output) { | 667 | switch (emit.debug_output) { |
| 654 | .dwarf => |dw| { | 668 | .dwarf => |dw| { |
| 655 | try dw.setEpilogueBegin(); | 669 | try dw.setEpilogueBegin(); |
| 656 | try self.dbgAdvancePCAndLine(self.prev_di_line, self.prev_di_column); | 670 | try emit.dbgAdvancePCAndLine(emit.prev_di_line, emit.prev_di_column); |
| 657 | }, | 671 | }, |
| 658 | .plan9 => {}, | 672 | .plan9 => {}, |
| 659 | .none => {}, | 673 | .none => {}, |