@@ -52,16 +52,23 @@ pub const DebugInfoOutput = union(enum) {
52
52
/// assume all numbers/variables are bytes
53
53
/// 0 w x y z -> interpret w x y z as a big-endian i32, and add it to the line offset
54
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
55
+ /// x when x < 129 -> subtract 64 from x and subtract it from the line offset
56
56
/// x -> subtract 129 from x, multiply it by the quanta of the instruction size
57
57
/// (1 on x86_64), and add it to the pc
58
58
/// after every opcode, add the quanta of the instruction size to the pc
59
59
plan9 : struct {
60
60
/// the actual opcodes
61
61
dbg_line : * std .ArrayList (u8 ),
62
+ /// what line the debuginfo starts on
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
+ start_line : * ? u32 ,
62
65
/// what the line count ends on after codegen
63
66
/// 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
67
end_line : * u32 ,
68
+ /// the last pc change op
69
+ /// This is very useful for adding quanta
70
+ /// to it if its not actually the last one.
71
+ pcop_change_index : * ? u32 ,
65
72
},
66
73
none ,
67
74
};
@@ -946,7 +953,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
946
953
947
954
fn dbgAdvancePCAndLine (self : * Self , line : u32 , column : u32 ) InnerError ! void {
948
955
const delta_line = @intCast (i32 , line ) - @intCast (i32 , self .prev_di_line );
949
- const delta_pc = self .code .items .len - self .prev_di_pc ;
956
+ const delta_pc : usize = self .code .items .len - self .prev_di_pc ;
950
957
switch (self .debug_output ) {
951
958
.dwarf = > | dbg_out | {
952
959
// TODO Look into using the DWARF special opcodes to compress this data.
@@ -960,30 +967,39 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
960
967
leb128 .writeILEB128 (dbg_out .dbg_line .writer (), delta_line ) catch unreachable ;
961
968
}
962
969
dbg_out .dbg_line .appendAssumeCapacity (DW .LNS .copy );
970
+ self .prev_di_pc = self .code .items .len ;
971
+ self .prev_di_line = line ;
972
+ self .prev_di_column = column ;
973
+ self .prev_di_pc = self .code .items .len ;
963
974
},
964
975
.plan9 = > | dbg_out | {
976
+ if (delta_pc <= 0 ) return ; // only do this when the pc changes
965
977
// we have already checked the target in the linker to make sure it is compatable
966
978
const quant = @import ("link/Plan9/aout.zig" ).getPCQuant (self .target .cpu .arch ) catch unreachable ;
967
979
968
980
// 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
- }
981
+ try @import ("link/Plan9.zig" ).changeLine (dbg_out .dbg_line , delta_line );
976
982
// increasing the pc
977
- if (delta_pc - quant != 0 ) {
978
- try dbg_out .dbg_line .append (@intCast (u8 , delta_pc - quant + 129 ));
979
- }
983
+ const d_pc_p9 = @intCast (i64 , delta_pc ) - quant ;
984
+ if (d_pc_p9 > 0 ) {
985
+ // minus one becaue if its the last one, we want to leave space to change the line which is one quanta
986
+ try dbg_out .dbg_line .append (@intCast (u8 , @divExact (d_pc_p9 , quant ) + 128 ) - quant );
987
+ if (dbg_out .pcop_change_index .* ) | pci |
988
+ dbg_out .dbg_line .items [pci ] += 1 ;
989
+ dbg_out .pcop_change_index .* = @intCast (u32 , dbg_out .dbg_line .items .len - 1 );
990
+ } else if (d_pc_p9 == 0 ) {
991
+ // we don't need to do anything, because adding the quant does it for us
992
+ } else unreachable ;
993
+ if (dbg_out .start_line .* == null )
994
+ dbg_out .start_line .* = self .prev_di_line ;
980
995
dbg_out .end_line .* = line ;
996
+ // only do this if the pc changed
997
+ self .prev_di_line = line ;
998
+ self .prev_di_column = column ;
999
+ self .prev_di_pc = self .code .items .len ;
981
1000
},
982
1001
.none = > {},
983
1002
}
984
- self .prev_di_line = line ;
985
- self .prev_di_column = column ;
986
- self .prev_di_pc = self .code .items .len ;
987
1003
}
988
1004
989
1005
/// Asserts there is already capacity to insert into top branch inst_table.
0 commit comments