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
92 lines
4.9 KiB
Plaintext
92 lines
4.9 KiB
Plaintext
# 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:
|