| ... | ... | @@ -48,6 +48,21 @@ pub const DebugInfoOutput = union(enum) { |
| 48 | 48 | dbg_info: *std.ArrayList(u8), |
| 49 | 49 | dbg_info_type_relocs: *link.File.DbgInfoTypeRelocsTable, |
| 50 | 50 | }, |
| 51 | /// the plan9 debuginfo output is a bytecode with 4 opcodes |
| 52 | /// assume all numbers/variables are bytes |
| 53 | /// 0 w x y z -> interpret w x y z as a big-endian i32, and add it to the line offset |
| 54 | /// x when x < 65 -> add x to line offset |
| 55 | /// x when x < 129 -> subtract 64 from x and add it to the line offset |
| 56 | /// x -> subtract 129 from x, multiply it by the quanta of the instruction size |
| 57 | /// (1 on x86_64), and add it to the pc |
| 58 | /// after every opcode, add the quanta of the instruction size to the pc |
| 59 | plan9: struct { |
| 60 | /// the actual opcodes |
| 61 | dbg_line: *std.ArrayList(u8), |
| 62 | /// what the line count ends on after codegen |
| 63 | /// this helps because the linker might have to insert some opcodes to make sure that the line count starts at the right amount for the next decl |
| 64 | end_line: *u32, |
| 65 | }, |
| 51 | 66 | none, |
| 52 | 67 | }; |
| 53 | 68 | |
| ... | ... | @@ -913,6 +928,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 913 | 928 | try dbg_out.dbg_line.append(DW.LNS.set_prologue_end); |
| 914 | 929 | try self.dbgAdvancePCAndLine(self.prev_di_line, self.prev_di_column); |
| 915 | 930 | }, |
| 931 | .plan9 => {}, |
| 916 | 932 | .none => {}, |
| 917 | 933 | } |
| 918 | 934 | } |
| ... | ... | @@ -923,15 +939,16 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 923 | 939 | try dbg_out.dbg_line.append(DW.LNS.set_epilogue_begin); |
| 924 | 940 | try self.dbgAdvancePCAndLine(self.prev_di_line, self.prev_di_column); |
| 925 | 941 | }, |
| 942 | .plan9 => {}, |
| 926 | 943 | .none => {}, |
| 927 | 944 | } |
| 928 | 945 | } |
| 929 | 946 | |
| 930 | 947 | fn dbgAdvancePCAndLine(self: *Self, line: u32, column: u32) InnerError!void { |
| 948 | const delta_line = @intCast(i32, line) - @intCast(i32, self.prev_di_line); |
| 949 | const delta_pc = self.code.items.len - self.prev_di_pc; |
| 931 | 950 | switch (self.debug_output) { |
| 932 | 951 | .dwarf => |dbg_out| { |
| 933 | | const delta_line = @intCast(i32, line) - @intCast(i32, self.prev_di_line); |
| 934 | | const delta_pc = self.code.items.len - self.prev_di_pc; |
| 935 | 952 | // TODO Look into using the DWARF special opcodes to compress this data. |
| 936 | 953 | // It lets you emit single-byte opcodes that add different numbers to |
| 937 | 954 | // both the PC and the line number at the same time. |
| ... | ... | @@ -944,6 +961,24 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 944 | 961 | } |
| 945 | 962 | dbg_out.dbg_line.appendAssumeCapacity(DW.LNS.copy); |
| 946 | 963 | }, |
| 964 | .plan9 => |dbg_out| { |
| 965 | // we have already checked the target in the linker to make sure it is compatable |
| 966 | const quant = @import("link/Plan9/aout.zig").getPCQuant(self.target.cpu.arch) catch unreachable; |
| 967 | |
| 968 | // increasing the line number |
| 969 | if (delta_line > 0 and delta_line < 65) { |
| 970 | try dbg_out.dbg_line.append(@intCast(u8, delta_line)); |
| 971 | } else if (delta_line < 0 and delta_line > -65) { |
| 972 | try dbg_out.dbg_line.append(@intCast(u8, -delta_line + 64)); |
| 973 | } else if (delta_line != 0) { |
| 974 | try dbg_out.dbg_line.writer().writeIntBig(i32, delta_line); |
| 975 | } |
| 976 | // increasing the pc |
| 977 | if (delta_pc - quant != 0) { |
| 978 | try dbg_out.dbg_line.append(@intCast(u8, delta_pc - quant + 129)); |
| 979 | } |
| 980 | dbg_out.end_line.* = line; |
| 981 | }, |
| 947 | 982 | .none => {}, |
| 948 | 983 | } |
| 949 | 984 | self.prev_di_line = line; |
| ... | ... | @@ -1032,6 +1067,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 1032 | 1067 | } |
| 1033 | 1068 | try gop.value_ptr.relocs.append(self.gpa, @intCast(u32, index)); |
| 1034 | 1069 | }, |
| 1070 | .plan9 => {}, |
| 1035 | 1071 | .none => {}, |
| 1036 | 1072 | } |
| 1037 | 1073 | } |
| ... | ... | @@ -2457,6 +2493,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2457 | 2493 | try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4 |
| 2458 | 2494 | dbg_out.dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string |
| 2459 | 2495 | }, |
| 2496 | .plan9 => {}, |
| 2460 | 2497 | .none => {}, |
| 2461 | 2498 | } |
| 2462 | 2499 | }, |
| ... | ... | @@ -2491,6 +2528,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2491 | 2528 | else => {}, |
| 2492 | 2529 | } |
| 2493 | 2530 | }, |
| 2531 | .plan9 => {}, |
| 2494 | 2532 | .none => {}, |
| 2495 | 2533 | } |
| 2496 | 2534 | }, |