hanchenye-llvm-project/llvm/tools
James Henderson a3acf99e59 [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
2018-05-10 10:51:33 +00:00
..
bugpoint Remove @brief commands from doxygen comments, too. 2018-05-01 16:10:38 +00:00
bugpoint-passes
dsymutil [DWARF] Rework debug line parsing to use llvm::Error and callbacks 2018-05-10 10:51:33 +00:00
gold [LTO] Add stats-file option to LTO/Config.h. 2018-04-20 10:18:36 +00:00
llc Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
lli IWYU for llvm-config.h in llvm, additions. 2018-04-30 14:59:11 +00:00
llvm-ar Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-as Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-as-fuzzer
llvm-bcanalyzer [bcanalyzer] Recognize more stream types 2018-04-21 23:52:04 +00:00
llvm-c-test [LLVM-C] Eliminate an unused variable in a test. 2018-04-29 02:01:34 +00:00
llvm-cat
llvm-cfi-verify Make llvm-cfi-verify CMakeLists.txt formatting more consistent with the rest of LLVM. 2018-05-09 01:07:02 +00:00
llvm-config Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00
llvm-cov Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00
llvm-cvtres [llvm-cvtres] Allow parameters preceded by '-' in addition to '/' 2018-05-02 21:15:13 +00:00
llvm-cxxdump Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-cxxfilt Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-demangle-fuzzer
llvm-diff Let llvm-diff correctly deal with Undef/ConstantAggregateZero/ConstantVector/IndirectBr 2018-04-12 21:28:04 +00:00
llvm-dis [tools] Use WithColor for printing errors. 2018-04-21 21:11:59 +00:00
llvm-dwarfdump [DebugInfo] Accept `S` in augmentation strings in CIE. 2018-05-08 06:21:12 +00:00
llvm-dwp [llvm-dwp] Define InitLLVM. 2018-05-06 23:08:29 +00:00
llvm-exegesis Re-land r331622 "[llvm-exegesis] Add a library to cluster benchmark results." 2018-05-07 09:09:48 +00:00
llvm-extract Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-go
llvm-isel-fuzzer Rename *CommandFlags.def to *CommandFlags.inc 2018-04-11 18:49:37 +00:00
llvm-jitlistener Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-link [llvm-link] Use WithColor for printing errors 2018-04-18 14:41:47 +00:00
llvm-lto Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00
llvm-lto2 [LTO] Allow pass remarks with hotness to be set when emitting to stderr 2018-05-04 23:59:34 +00:00
llvm-mc [MC] Change AsmParser to leverage Assembler during evaluation 2018-04-30 19:22:40 +00:00
llvm-mc-assemble-fuzzer [llvm-mc-assemble-fuzzer] Catch up with API changes. 2018-05-04 23:41:25 +00:00
llvm-mc-disassemble-fuzzer
llvm-mca llvm-mca: Add missing includes 2018-05-09 17:28:10 +00:00
llvm-modextract
llvm-mt Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-nm Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-objcopy [llvm-objcopy] Add --strip-symbol (-N) option 2018-05-09 21:36:54 +00:00
llvm-objdump Remove @brief commands from doxygen comments, too. 2018-05-01 16:10:38 +00:00
llvm-opt-fuzzer Link to AggressiveInstCombine in a few places. Unbreaks build for me. 2018-04-24 08:40:37 +00:00
llvm-opt-report Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00
llvm-pdbutil llvm-pdbutil: Fix an off-by-one error. 2018-04-17 21:44:17 +00:00
llvm-profdata [llvm-profdata] Use WithColor for printing errors 2018-04-18 14:42:33 +00:00
llvm-rc [llvm-rc] Handle C preprocessor output 2018-05-09 18:21:03 +00:00
llvm-readobj [WebAssembly] llvm-readobj: display symbols names in relocations 2018-05-01 16:35:16 +00:00
llvm-rtdyld Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-shlib Rename llvm library from libLLVM-X.Y to libLLVM-X 2018-03-29 09:44:09 +00:00
llvm-size Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-special-case-list-fuzzer
llvm-split
llvm-stress
llvm-strings Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-symbolizer Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-xray Inline contents of LLVM_XRAY_TOOLS variable into its only use. 2018-05-09 00:42:17 +00:00
lto s/LLVM_ON_WIN32/_WIN32/, llvm 2018-04-29 00:45:03 +00:00
msbuild
obj2yaml obj2yaml: Correctly round-trip default alignment. 2018-05-04 16:28:41 +00:00
opt Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00
opt-viewer [opt-viewer] Kill parser processes before moving onto rendering 2018-02-26 21:15:51 +00:00
sancov Rename sancov.cc to sancov.cpp 2018-04-25 18:06:23 +00:00
sanstats
verify-uselistorder Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00
xcode-toolchain
yaml2obj Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00
CMakeLists.txt
LLVMBuild.txt Re-land r329156 "Add llvm-exegesis tool." 2018-04-04 11:37:06 +00:00