diff options
author | James Henderson <jh7370@my.bristol.ac.uk> | 2018-05-10 10:51:33 +0000 |
---|---|---|
committer | James Henderson <jh7370@my.bristol.ac.uk> | 2018-05-10 10:51:33 +0000 |
commit | a3acf99e5929409401e94f6beaf48ba5d9f0bb7f (patch) | |
tree | e436b9890e3bfe0bf880be6dc2df73096ecfe0d0 /llvm/test | |
parent | 19dd1a0ea6fed11b40cb9f83adbce17c04d569f3 (diff) | |
download | bcm5719-llvm-a3acf99e5929409401e94f6beaf48ba5d9f0bb7f.tar.gz bcm5719-llvm-a3acf99e5929409401e94f6beaf48ba5d9f0bb7f.zip |
[DWARF] Rework debug line parsing to use llvm::Error and callbacks
Reviewed by: dblaikie, JDevlieghere, espindola
Differential Revision: https://reviews.llvm.org/D44560
Summary:
The .debug_line parser previously reported errors by printing to stderr and
return false. This is not particularly helpful for clients of the library code,
as it prevents them from handling the errors in a manner based on the calling
context. This change switches to using llvm::Error and callbacks to indicate
what problems were detected during parsing, and has updated clients to handle
the errors in a location-specific manner. In general, this means that they
continue to do the same thing to external users. Below, I have outlined what
the known behaviour changes are, relating to this change.
There are two levels of "errors" in the new error mechanism, to broadly
distinguish between different fail states of the parser, since not every
failure will prevent parsing of the unit, or of subsequent unit. Malformed
table errors that prevent reading the remainder of the table (reported by
returning them) and other minor issues representing problems with parsing that
do not prevent attempting to continue reading the table (reported by calling a
specified callback funciton). The only example of this currently is when the
last sequence of a unit is unterminated. However, I think it would be good to
change the handling of unrecognised opcodes to report as minor issues as well,
rather than just printing to the stream if --verbose is used (this would be a
subsequent change however).
I have substantially extended the DwarfGenerator to be able to handle
custom-crafted .debug_line sections, allowing for comprehensive unit-testing
of the parser code. For now, I am just adding unit tests to cover the basic
error reporting, and positive cases, and do not currently intend to test every
part of the parser, although the framework should be sufficient to do so at a
later point.
Known behaviour changes:
- The dump function in DWARFContext now does not attempt to read subsequent
tables when searching for a specific offset, if the unit length field of a
table before the specified offset is a reserved value.
- getOrParseLineTable now returns a useful Error if an invalid offset is
encountered, rather than simply a nullptr.
- The parse functions no longer use `WithColor::warning` directly to report
errors, allowing LLD to call its own warning function.
- The existing parse error messages have been updated to not specifically
include "warning" in their message, allowing consumers to determine what
severity the problem is.
- If the line table version field appears to have a value less than 2, an
informative error is returned, instead of just false.
- If the line table unit length field uses a reserved value, an informative
error is returned, instead of just false.
- Dumping of .debug_line.dwo sections is now implemented the same as regular
.debug_line sections.
- Verbose dumping of .debug_line[.dwo] sections now prints the prologue, if
there is a prologue error, just like non-verbose dumping.
As a helper for the generator code, I have re-added emitInt64 to the
AsmPrinter code. This previously existed, but was removed way back in r100296,
presumably because it was dead at the time.
This change also requires a change to LLD, which will be committed separately.
llvm-svn: 331971
Diffstat (limited to 'llvm/test')
4 files changed, 338 insertions, 97 deletions
diff --git a/llvm/test/DebugInfo/X86/dwarfdump-bogus-LNE.s b/llvm/test/DebugInfo/X86/dwarfdump-bogus-LNE.s index aa2a416df7a..ec1f1b7fbb8 100644 --- a/llvm/test/DebugInfo/X86/dwarfdump-bogus-LNE.s +++ b/llvm/test/DebugInfo/X86/dwarfdump-bogus-LNE.s @@ -150,100 +150,3 @@ LT2_end: # ERR: warning: unexpected line op length at offset 0x0000005e # ERR-SAME: expected 0x02 found 0x01 - -# The above parsing errors still let us move to the next unit. -# If the prologue is bogus, we need to bail out because we can't -# even find the next unit. - -# DWARF v4 line-table header #3. -LT3_start: - .long LT3_end-LT3_version # Length of Unit (DWARF-32 format) -LT3_version: - .short 4 # DWARF version number - .long LT3_header_end-LT3_params # Length of Prologue -LT3_params: - .byte 1 # Minimum Instruction Length - .byte 1 # Maximum Operations per Instruction - .byte 1 # Default is_stmt - .byte -5 # Line Base - .byte 14 # Line Range - .byte 13 # Opcode Base - .byte 0 # Standard Opcode Lengths - .byte 1 - .byte 1 - .byte 1 - .byte 1 - .byte 0 - .byte 0 - .byte 0 - .byte 1 - .byte 0 - .byte 0 - .byte 1 - # No directories. - .byte 0 - # No files. - .byte 0 - # Extra junk at the end of the prologue, so the length isn't right. - .long 0 -LT3_header_end: - # Real opcode and operand. - .byte 0 - .byte 9 - .byte 2 # DW_LNE_set_address - .quad .text - # Real opcode with incorrect length. - .byte 0 - .byte 2 # Wrong length, should be 1. - .byte 1 # DW_LNE_end_sequence -LT3_end: - -# We should have bailed out above, so never see this in the dump. -# DWARF v4 line-table header #4. -LT4_start: - .long LT4_end-LT4_version # Length of Unit (DWARF-32 format) -LT4_version: - .short 4 # DWARF version number - .long LT4_header_end-LT4_params # Length of Prologue -LT4_params: - .byte 1 # Minimum Instruction Length - .byte 1 # Maximum Operations per Instruction - .byte 1 # Default is_stmt - .byte -5 # Line Base - .byte 14 # Line Range - .byte 13 # Opcode Base - .byte 0 # Standard Opcode Lengths - .byte 1 - .byte 1 - .byte 1 - .byte 1 - .byte 0 - .byte 0 - .byte 0 - .byte 1 - .byte 0 - .byte 0 - .byte 1 - # No directories. - .byte 0 - # No files. - .byte 0 -LT4_header_end: - # Real opcode and operand. - .byte 0 - .byte 9 - .byte 2 # DW_LNE_set_address - .quad .text - # Real opcode with correct length. - .byte 0 - .byte 1 - .byte 1 # DW_LNE_end_sequence -LT4_end: - -# Look for the dump of unit 3, and don't want unit 4. -# CHECK: Line table prologue: -# CHECK-NOT: Line table prologue: - -# And look for the error message. -# ERR: warning: parsing line table prologue at 0x0000005f should have -# ERR-SAME: ended at 0x00000081 but it ended at 0x0000007d diff --git a/llvm/test/tools/llvm-dwarfdump/X86/Inputs/debug_line_malformed.s b/llvm/test/tools/llvm-dwarfdump/X86/Inputs/debug_line_malformed.s new file mode 100644 index 00000000000..3fca64f3ead --- /dev/null +++ b/llvm/test/tools/llvm-dwarfdump/X86/Inputs/debug_line_malformed.s @@ -0,0 +1,190 @@ +.section .debug_line,"",@progbits +# Leading good section +.long .Lunit1_end - .Lunit1_start # Length of Unit (DWARF-32 format) +.Lunit1_start: +.short 4 # DWARF version number +.long .Lprologue1_end-.Lprologue1_start # Length of Prologue +.Lprologue1_start: +.byte 1 # Minimum Instruction Length +.byte 1 # Maximum Operations per Instruction +.byte 1 # Default is_stmt +.byte -5 # Line Base +.byte 14 # Line Range +.byte 13 # Opcode Base +.byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # Standard Opcode Lengths +.asciz "dir1" # Include table +.asciz "dir2" +.byte 0 +.asciz "file1" # File table +.byte 0, 0, 0 +.asciz "file2" +.byte 1, 0, 0 +.byte 0 +.Lprologue1_end: +.byte 0, 9, 2 # DW_LNE_set_address +.quad 0x0badbeef +.byte 0, 1, 1 # DW_LNE_end_sequence +.Lunit1_end: + +# version 0 +.long .Lunit_v0_end - .Lunit_v0_start # unit length +.Lunit_v0_start: +.short 0 # version +.Lunit_v0_end: + +# version 1 +.long .Lunit_v1_end - .Lunit_v1_start # unit length +.Lunit_v1_start: +.short 1 # version +.Lunit_v1_end: + +# version 5 malformed line/include table +.long .Lunit_v5_end - .Lunit_v5_start # unit length +.Lunit_v5_start: +.short 5 # version +.byte 8 # address size +.byte 8 # segment selector +.long .Lprologue_v5_end-.Lprologue_v5_start # Length of Prologue +.Lprologue_v5_start: +.byte 1 # Minimum Instruction Length +.byte 1 # Maximum Operations per Instruction +.byte 1 # Default is_stmt +.byte -5 # Line Base +.byte 14 # Line Range +.byte 13 # Opcode Base +.byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # Standard Opcode Lengths +.byte 0 # directory table (invalid) +.Lprologue_v5_end: +.Lunit_v5_end: + +# Short prologue +.long .Lunit_short_prologue_end - .Lunit_short_prologue_start # unit length +.Lunit_short_prologue_start: +.short 4 # version +.long .Lprologue_short_prologue_end-.Lprologue_short_prologue_start - 2 # Length of Prologue +.Lprologue_short_prologue_start: +.byte 1 # Minimum Instruction Length +.byte 1 # Maximum Operations per Instruction +.byte 1 # Default is_stmt +.byte -5 # Line Base +.byte 14 # Line Range +.byte 13 # Opcode Base +.byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # Standard Opcode Lengths +.asciz "dir1" # Include table +.asciz "dir2" +.byte 0 +.asciz "file1" # File table +.byte 0, 0, 0 +.asciz "file2" +.byte 1, 0, 0 +.byte 0 +.Lprologue_short_prologue_end: +.Lunit_short_prologue_end: + +# Over-long prologue +.long .Lunit_long_prologue_end - .Lunit_long_prologue_start # unit length +.Lunit_long_prologue_start: +.short 4 # version +.long .Lprologue_long_prologue_end-.Lprologue_long_prologue_start + 1 # Length of Prologue +.Lprologue_long_prologue_start: +.byte 1 # Minimum Instruction Length +.byte 1 # Maximum Operations per Instruction +.byte 1 # Default is_stmt +.byte -5 # Line Base +.byte 14 # Line Range +.byte 13 # Opcode Base +.byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # Standard Opcode Lengths +.asciz "dir1" # Include table +.asciz "dir2" +.byte 0 +.asciz "file1" # File table +.byte 0, 0, 0 +.asciz "file2" +.byte 1, 0, 0 +.byte 0 +.Lprologue_long_prologue_end: +.Lunit_long_prologue_end: + +# Over-long extended opcode +.long .Lunit_long_opcode_end - .Lunit_long_opcode_start # unit length +.Lunit_long_opcode_start: +.short 4 # version +.long .Lprologue_long_opcode_end-.Lprologue_long_opcode_start # Length of Prologue +.Lprologue_long_opcode_start: +.byte 1 # Minimum Instruction Length +.byte 1 # Maximum Operations per Instruction +.byte 1 # Default is_stmt +.byte -5 # Line Base +.byte 14 # Line Range +.byte 13 # Opcode Base +.byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # Standard Opcode Lengths +.asciz "dir1" # Include table +.asciz "dir2" +.byte 0 +.asciz "file1" # File table +.byte 0, 0, 0 +.asciz "file2" +.byte 1, 0, 0 +.byte 0 +.Lprologue_long_opcode_end: +.byte 0, 9, 2 # DW_LNE_set_address +.quad 0xabbadaba +.byte 0, 2, 1 # DW_LNE_end_sequence (wrong length) +.byte 0, 9, 2 # DW_LNE_set_address +.quad 0xbabb1e45 +.byte 0, 1, 1 # DW_LNE_end_sequence (wrong length) +.Lunit_long_opcode_end: + +# No end of sequence +.long .Lunit_no_eos_end - .Lunit_no_eos_start # unit length +.Lunit_no_eos_start: +.short 4 # version +.long .Lprologue_no_eos_end-.Lprologue_no_eos_start # Length of Prologue +.Lprologue_no_eos_start: +.byte 1 # Minimum Instruction Length +.byte 1 # Maximum Operations per Instruction +.byte 1 # Default is_stmt +.byte -5 # Line Base +.byte 14 # Line Range +.byte 13 # Opcode Base +.byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # Standard Opcode Lengths +.asciz "dir1" # Include table +.asciz "dir2" +.byte 0 +.asciz "file1" # File table +.byte 0, 0, 0 +.asciz "file2" +.byte 1, 0, 0 +.byte 0 +.Lprologue_no_eos_end: +.byte 0, 9, 2 # DW_LNE_set_address +.quad 0xdeadfade +.byte 1 # DW_LNS_copy +.Lunit_no_eos_end: + +# Trailing good section +.long .Lunit_good_end - .Lunit_good_start # Length of Unit (DWARF-32 format) +.Lunit_good_start: +.short 4 # DWARF version number +.long .Lprologue_good_end-.Lprologue_good_start # Length of Prologue +.Lprologue_good_start: +.byte 1 # Minimum Instruction Length +.byte 1 # Maximum Operations per Instruction +.byte 1 # Default is_stmt +.byte -5 # Line Base +.byte 14 # Line Range +.byte 13 # Opcode Base +.byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # Standard Opcode Lengths +.asciz "dir1" # Include table +.asciz "dir2" +.byte 0 +.asciz "file1" # File table +.byte 0, 0, 0 +.asciz "file2" +.byte 1, 0, 0 +.byte 0 +.Lprologue_good_end: +.byte 0, 9, 2 # DW_LNE_set_address +.quad 0xcafebabe +.byte 0, 1, 1 # DW_LNE_end_sequence +.Lunit_good_end: diff --git a/llvm/test/tools/llvm-dwarfdump/X86/Inputs/debug_line_reserved_length.s b/llvm/test/tools/llvm-dwarfdump/X86/Inputs/debug_line_reserved_length.s new file mode 100644 index 00000000000..f21d411ed9f --- /dev/null +++ b/llvm/test/tools/llvm-dwarfdump/X86/Inputs/debug_line_reserved_length.s @@ -0,0 +1,57 @@ +.section .debug_line,"",@progbits +# Leading good section +.long .Lunit1_end - .Lunit1_start # Length of Unit (DWARF-32 format) +.Lunit1_start: +.short 4 # DWARF version number +.long .Lprologue1_end-.Lprologue1_start # Length of Prologue +.Lprologue1_start: +.byte 1 # Minimum Instruction Length +.byte 1 # Maximum Operations per Instruction +.byte 1 # Default is_stmt +.byte -5 # Line Base +.byte 14 # Line Range +.byte 13 # Opcode Base +.byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # Standard Opcode Lengths +.asciz "dir1" # Include table +.asciz "dir2" +.byte 0 +.asciz "file1" # File table +.byte 0, 0, 0 +.asciz "file2" +.byte 1, 0, 0 +.byte 0 +.Lprologue1_end: +.byte 0, 9, 2 # DW_LNE_set_address +.quad 0x0badbeef +.byte 0, 1, 1 # DW_LNE_end_sequence +.Lunit1_end: + +# Malformed section +.long 0xfffffffe # reserved unit length + +# Trailing good section +.long .Lunit3_end - .Lunit3_start # Length of Unit (DWARF-32 format) +.Lunit3_start: +.short 4 # DWARF version number +.long .Lprologue3_end-.Lprologue3_start # Length of Prologue +.Lprologue3_start: +.byte 1 # Minimum Instruction Length +.byte 1 # Maximum Operations per Instruction +.byte 1 # Default is_stmt +.byte -5 # Line Base +.byte 14 # Line Range +.byte 13 # Opcode Base +.byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # Standard Opcode Lengths +.asciz "dir1" # Include table +.asciz "dir2" +.byte 0 +.asciz "file1" # File table +.byte 0, 0, 0 +.asciz "file2" +.byte 1, 0, 0 +.byte 0 +.Lprologue3_end: +.byte 0, 9, 2 # DW_LNE_set_address +.quad 0xcafebabe +.byte 0, 1, 1 # DW_LNE_end_sequence +.Lunit3_end: diff --git a/llvm/test/tools/llvm-dwarfdump/X86/debug_line_invalid.test b/llvm/test/tools/llvm-dwarfdump/X86/debug_line_invalid.test new file mode 100644 index 00000000000..29ee24a3f23 --- /dev/null +++ b/llvm/test/tools/llvm-dwarfdump/X86/debug_line_invalid.test @@ -0,0 +1,91 @@ +# Test the different error cases in the debug line parsing and how they prevent +# or don't prevent further dumping of section contents. + +# RUN: llvm-mc -triple x86_64-pc-linux %S/Inputs/debug_line_reserved_length.s -filetype=obj -o %t-reserved.o +# RUN: llvm-dwarfdump -debug-line %t-reserved.o 2> %t-reserved.err | FileCheck %s --check-prefixes=FIRST,FATAL +# RUN: FileCheck %s --input-file=%t-reserved.err --check-prefix=RESERVED +# RUN: llvm-dwarfdump -debug-line %t-reserved.o -verbose 2> %t-reserved-verbose.err | FileCheck %s --check-prefixes=FIRST,FATAL +# RUN: FileCheck %s --input-file=%t-reserved-verbose.err --check-prefix=RESERVED + +# We should still produce warnings for malformed tables after the specified unit. +# RUN: llvm-dwarfdump -debug-line=0 %t-reserved.o 2> %t-reserved-off-first.err | FileCheck %s --check-prefixes=FIRST,NOLATER +# RUN: FileCheck %s --input-file=%t-reserved-off-first.err --check-prefix=RESERVED + +# Stop looking for the specified unit, if a fatally-bad prologue is detected. +# RUN: llvm-dwarfdump -debug-line=0x4b %t-reserved.o 2> %t-reserved-off-last.err | FileCheck %s --check-prefixes=NOFIRST,NOLATER +# RUN: FileCheck %s --input-file=%t-reserved-off-last.err --check-prefix=RESERVED + +# RUN: llvm-mc -triple x86_64-pc-linux %S/Inputs/debug_line_malformed.s -filetype=obj -o %t-malformed.o +# RUN: llvm-dwarfdump -debug-line %t-malformed.o 2> %t-malformed.err | FileCheck %s --check-prefixes=FIRST,NONFATAL +# RUN: FileCheck %s --input-file=%t-malformed.err --check-prefixes=ALL,OTHER +# RUN: llvm-dwarfdump -debug-line %t-malformed.o -verbose 2> %t-malformed-verbose.err | FileCheck %s --check-prefixes=FIRST,NONFATAL +# RUN: FileCheck %s --input-file=%t-malformed-verbose.err --check-prefixes=ALL,OTHER + +# RUN: llvm-dwarfdump -debug-line=0 %t-malformed.o 2> %t-malformed-off-first.err | FileCheck %s --check-prefixes=FIRST,NOLATER +# RUN: FileCheck %s --input-file=%t-malformed-off-first.err --check-prefix=ALL + +# Don't stop looking for the later unit if non-fatal issues are found. +# RUN: llvm-dwarfdump -debug-line=0x183 %t-malformed.o 2> %t-malformed-off-last.err | FileCheck %s --check-prefixes=LASTONLY +# RUN: FileCheck %s --input-file=%t-malformed-off-last.err --check-prefix=ALL + +# FIRST: debug_line[0x00000000] +# FIRST: 0x000000000badbeef {{.*}} end_sequence +# NOFIRST-NOT: debug_line[0x00000000] +# NOFIRST-NOT: 0x000000000badbeef {{.*}} end_sequence +# NOLATER-NOT: debug_line[{{.*}}] +# NOLATER-NOT: end_sequence + +# For fatal issues, the following table(s) should not be dumped. +# FATAL: debug_line[0x00000048] +# FATAL-NEXT: Line table prologue +# FATAL-NEXT: total_length: 0xfffffffe +# FATAL-NOT: debug_line + +# For non-fatal prologue issues, the table prologue should be dumped, and any subsequent tables should also be. +# NONFATAL: debug_line[0x00000048] +# NONFATAL-NEXT: Line table prologue +# NONFATAL-NOT: Address +# NONFATAL: debug_line[0x0000004e] +# NONFATAL-NEXT: Line table prologue +# NONFATAL-NOT: Address +# NONFATAL: debug_line[0x00000054] +# NONFATAL-NEXT: Line table prologue +# NONFATAL-NOT: Address +# NONFATAL: debug_line[0x00000073] +# NONFATAL-NEXT: Line table prologue +# NONFATAL-NOT: Address +# NONFATAL: debug_line[0x000000ad] +# NONFATAL-NEXT: Line table prologue +# NONFATAL-NOT: Address +# NONFATAL: debug_line[0x000000e7] +# Dumping prints the line table prologue and any valid operations up to the point causing the problem. +# NONFATAL-NEXT: Line table prologue +# NONFATAL: 0x00000000abbadaba {{.*}} end_sequence +# NONFATAL-NOT: is_stmt + +# For minor issues, we can dump the table. +# NONFATAL: debug_line[0x0000013d] +# NONFATAL-NEXT: Line table prologue +# NONFATAL-NOT: debug_line[{{.*}}] +# NONFATAL: 0x00000000deadfade {{.*}} +# NONFATAL: debug_line[0x00000183] +# NONFATAL-NOT: debug_line[{{.*}}] +# NONFATAL: 0x00000000cafebabe {{.*}} end_sequence +# NONFATAL-NOT: debug_line[{{.*}}] + +# LASTONLY-NOT: debug_line[{{.*}}] +# LASTONLY: debug_line[0x00000183] +# LASTONLY: 0x00000000cafebabe {{.*}} end_sequence + +# RESERVED: warning: parsing line table prologue at offset 0x00000048 unsupported reserved unit length found of value 0xfffffffe + +# ALL-NOT: warning: +# ALL: warning: parsing line table prologue at offset 0x00000048 found unsupported version 0x00 +# ALL-NEXT: warning: parsing line table prologue at offset 0x0000004e found unsupported version 0x01 +# ALL-NEXT: warning: parsing line table prologue at 0x00000054 found an invalid directory or file table description at 0x00000073 +# FIXME - The latter offset in the next line should be 0xad. The filename parsing code does not notice a missing terminating byte. +# ALL-NEXT: warning: parsing line table prologue at 0x00000073 should have ended at 0x000000ab but it ended at 0x000000ac +# ALL-NEXT: warning: parsing line table prologue at 0x000000ad should have ended at 0x000000e8 but it ended at 0x000000e7 +# OTHER-NEXT: warning: unexpected line op length at offset 0x0000012e expected 0x02 found 0x01 +# OTHER-NEXT: warning: last sequence in debug line table is not terminated! +# ALL-NOT: warning: |