Skip to content

Commit 048f77e

Browse files
ysbaddadenbcardiff
authored andcommittedJan 10, 2018
Fix: decode DWARF line sequences with single program entry (#5565)
Debug::DWARF::LineNumbers would skip the program statement when it contained a single entry, because of a wrong assumption of the sequence unit_length entry, which doesn't account for the unit length space in the standard, and was overlooked in checking whether the sequence had any program statement, or not.
1 parent 972f2b3 commit 048f77e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed
 

Diff for: ‎src/debug/dwarf/line_numbers.cr

+8-3
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ module Debug
154154
@file_names = [{"", 0, 0, 0}]
155155
@standard_opcode_lengths = [0_u8]
156156
end
157+
158+
# Returns the unit length, adding the size of the `unit_length`.
159+
def total_length
160+
unit_length + sizeof(typeof(unit_length))
161+
end
157162
end
158163

159164
# Matrix of decompressed `Row` to search line number informations from the
@@ -230,14 +235,14 @@ module Debug
230235
read_directory_table(sequence)
231236
read_filename_table(sequence)
232237

233-
if @io.tell - @offset < sequence.offset + sequence.unit_length
238+
if @io.tell - @offset < sequence.offset + sequence.total_length
234239
read_statement_program(sequence)
235240
end
236241
end
237242
end
238243

239244
private def read_opcodes(sequence)
240-
1.upto(sequence.opcode_base - 1) do |i|
245+
1.upto(sequence.opcode_base - 1) do
241246
sequence.standard_opcode_lengths << @io.read_byte.not_nil!
242247
end
243248
end
@@ -296,7 +301,7 @@ module Debug
296301
when LNE::EndSequence
297302
registers.end_sequence = true
298303
register_to_matrix(sequence, registers)
299-
if (@io.tell - @offset - sequence.offset) < sequence.unit_length
304+
if (@io.tell - @offset - sequence.offset) < sequence.total_length
300305
registers = Register.new(sequence.default_is_stmt)
301306
else
302307
break

0 commit comments

Comments
 (0)
Please sign in to comment.