Index: lib/DebugInfo/DWARF/DWARFDebugLine.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -305,6 +305,14 @@ PrologueOffset, EndPrologueOffset, (uint64_t)*OffsetPtr); return false; } + + if (LineRange == 0) { + fprintf(stderr, "warning: parsing line table prologue at 0x%8.8" PRIx64 + " found a line_range of value 0\n", + PrologueOffset); + return false; + } + return true; } Index: test/tools/llvm-dwarfdump/X86/bad_line_ranges.s =================================================================== --- test/tools/llvm-dwarfdump/X86/bad_line_ranges.s +++ test/tools/llvm-dwarfdump/X86/bad_line_ranges.s @@ -0,0 +1,58 @@ +# RUN: llvm-mc %s -filetype obj -triple x86_64-pc-linux -o %t.o +# RUN: llvm-dwarfdump -debug-line %t.o | FileCheck %s -check-prefixes=CHECK +# RUN: FileCheck %s -check-prefix=WARN -input-file=%t.err +# RUN: not llvm-dwarfdump -debug-line -verify %t.o 2> %t2.err | FileCheck %s -check-prefix=ERR +# RUN: FileCheck %s -check-prefix=WARN -input-file=%t2.err + +# CHECK-NOT: error: +# CHECK-NOT: warning: +# CHECK: line_range: 0 +# CHECK-NOT: error: +# CHECK-NOT: warning: + +# WARN: warning: parsing line table prologue at 0x00000000 found a line_range of value 0 +# ERR: error: .debug_line[0x00000000] was not able to be parsed for CU: + +.section .debug_line,"",@progbits + +.Lline_table_start0: +.long .Ldebug_line_end0 - .Ldebug_line_start0 # unit_length +.Ldebug_line_start0: +.short 4 # version +.long .Lheader_end - .Lheader_start # header_length +.Lheader_start: +.byte 1 # minimum_instruction_length +.byte 1 # maximum_operations_per_instruction +.byte 1 # default_is_stmt +.byte -5 # line_base +.byte 0 # line_range +.byte 13 # opcode_base +.byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # standard_opcode_lengths +.byte 0 # include directories +.byte 0 # file_names +.Lheader_end: +.byte 25 # special opcode. In order to calculate its meaning, a division by line_range is required. +.Ldebug_line_end0: + +.section .debug_info,"",@progbits +.Lsection_info: +.long .Lunit_end - .Lunit_start # Length of Unit +.Lunit_start: +.short 4 # DWARF version number +.long .Lsection_abbrev # Offset Into Abbrev. Section +.byte 8 # Address Size (in bytes) +.byte 1 # Abbrev [1] 0xb:0x59 DW_TAG_compile_unit +.long .Lline_table_start0 # DW_AT_stmt_list +.byte 0 # End Of Children Mark +.Lunit_end: + +.section .debug_abbrev,"",@progbits +.Lsection_abbrev: +.byte 1 # Abbreviation Code +.byte 17 # DW_TAG_compile_unit +.byte 0 # DW_CHILDREN_no +.byte 16 # DW_AT_stmt_list +.byte 23 # DW_FORM_sec_offset +.byte 0 # EOM(1) +.byte 0 # EOM(2) +.byte 0 # EOM(3)