1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00
Commit Graph

362 Commits

Author SHA1 Message Date
Oliver Stannard
864164dbfc [llvm-objdump] Add simple memory expressions to variable display
Add the DW_OP_breg0..DW_OP_breg31 and DW_OP_bregx opcodes to the DWARF
expression printer.

Differential revision: https://reviews.llvm.org/D74841
2020-03-16 10:54:41 +00:00
Oliver Stannard
52f5dcd954 [DebugInfo] Add unit test for compact expression printer
Add a unit test for the compact DWARF expression printer which will be
used by the llvm-objdump --debug-vars option.

Differential revision: https://reviews.llvm.org/D75250
2020-03-16 10:54:41 +00:00
James Henderson
cd41ba8d27 [DebugInfo] Add check for .debug_line minimum_instruction_length of 0
If the minimum_instruction_length of a debug line program is 0, no
address advancing via special opcodes, DW_LNS_const_add_pc, and
DW_LNS_advance_pc can occur, since the minimum_instruction_length is
used in a multiplication. This patch adds a warning reporting when this
issue occurs.

Reviewed by: probinson

Differential Revision: https://reviews.llvm.org/D75189
2020-03-09 12:59:44 +00:00
James Henderson
eff38d6af0 [DebugInfo] Prevent crash when .debug_line line_range is zero
The line_range value of a debug line program header is used in divisions
related to special opcodes and DW_LNS_const_add_pc opcodes. As such, a
value of 0 cannot be used. This change introduces a new warning, if such
a situation is identified, and does not perform the relevant
calculations.

Reviewed by: probinson, aprantl

Differential Revision: https://reviews.llvm.org/D43470
2020-03-09 12:59:43 +00:00
James Henderson
14ae577b3f [DebugInfo] Report unsupported maximum_operations_per_instruction values
This patch adds a check which reports an unsupported value of the
maximum_operations_per_instruction field in a debug line table header.
This is reported once per line table, at most, and only if the tablet
would otherwise need to use it (i.e. never for tables with version 3 or
less, or for tables which don't use DW_LNS_const_add_pc or special
opcodes). Unsupported values are currently any apart from 1.

Reviewed by: probinson, MaskRay

Differential Revision: https://reviews.llvm.org/D74819
2020-03-09 12:59:43 +00:00
Igor Kudrin
a4fab2c27b [DebugInfo] Do not truncate 64-bit values when dumping CIEs and FDEs.
This fixes printing long values that might reside in CIE and FDE,
including offsets, lengths, and addresses.

Differential Revision: https://reviews.llvm.org/D73887
2020-03-05 17:37:28 +07:00
Pavel Labath
9ccd43f14c Use DWARFDataExtractor::getInitialLength in debug_aranges
Summary:
getInitialLength is a *DWARF*DataExtractor method so I had to "upgrade"
some DataExtractors to be able to make use of it.

Reviewers: ikudrin, jhenderson, probinson

Subscribers: aprantl, hiraditya, llvm-commits, dblaikie

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D75535
2020-03-04 13:01:07 +01:00
Pavel Labath
b424382a42 [DWARF] Use DWARFDataExtractor::getInitialLength to parse debug_names
Summary:
In this patch I've done a slightly bigger rewrite to also remove the
hardcoded header lengths.

Reviewers: jhenderson, dblaikie, ikudrin

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D75119
2020-03-02 11:21:23 +01:00
Pavel Labath
b7a812f072 [DWARFDebugLine] Use new DWARFDataExtractor::getInitialLength
Summary:
The error messages change somewhat, but I believe the overall
informational value remains unchanged.

Reviewers: jhenderson, dblaikie, ikudrin

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D75116
2020-03-02 11:14:29 +01:00
Pavel Labath
7d8c00606f [DataExtractor] Improve error message when we run off the end of the buffer
Summary: Include the offset at which this happened.

Reviewers: dblaikie, jhenderson

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D75265
2020-02-28 09:02:33 +01:00
Alexey Lapshin
35d0c4caae [Debuginfo][NFC] Unify error reporting routines inside DebugInfoDWARF.
Summary:
Error reporting in DebugInfoDWARF library currently done in three ways :

1. Direct calls to WithColor::error()/WithColor::warning()
2. ErrorPolicy defaultErrorHandler(Error E);
3. void dumpWarning(Error Warning);

additionally, other locations could have more variations:

lld/ELF/SyntheticSection.cpp
    if (Error e = cu->tryExtractDIEsIfNeeded(false)) {
      error(toString(sec) + ": " + toString(std::move(e)));

DebugInfo/DWARF/DWARFUnit.cpp
  if (Error e = tryExtractDIEsIfNeeded(CUDieOnly))
    WithColor::error() << toString(std::move(e));

Thus error reporting could look inconsistent. To have a consistent error
messages it is necessary to have a possibility to redefine error
reporting functions. This patch creates two handlers and allows to
redefine them. It also patches all places inside DebugInfoDWARF
to use these handlers.

The intention is always to use following handlers for error reporting
purposes inside DebugInfoDWARF:

DebugInfo/DWARF/DWARFContext.h

std::function<void(Error E)> RecoverableErrorHandler = WithColor::defaultErrorHandler;
std::function<void(Error E)> WarningHandler = WithColor::defaultWarningHandler;

This is last patch from series of patches: D74481, D74635, D75118.

Reviewers: jhenderson, dblaikie, probinson, aprantl, JDevlieghere

Reviewed By: jhenderson

Subscribers: grimar, hiraditya, llvm-commits

Tags: #llvm, #debug-info

Differential Revision: https://reviews.llvm.org/D74308
2020-02-27 18:32:40 +03:00
Alexey Lapshin
7caf79acd9 [DebugInfo][NFC] Remove handler with ErrorPolicy from DWARFContext.
Summary:
Current LLVM code base does not use error handler with ErrorPolicy.
This patch removes ErrorPolicy from DWARFContext.

This patch is extracted from the D74308.

Reviewers: jhenderson, dblaikie, grimar, aprantl, JDevlieghere

Reviewed By: grimar

Subscribers: hiraditya, llvm-commits

Tags: #llvm, #debug-info

Differential Revision: https://reviews.llvm.org/D75118
2020-02-27 00:42:37 +03:00
Pavel Labath
2993a0fb59 Introduce DWARFDataExtractor::getInitialLength
Summary:
This patch introduces a function to house the code needed to do the
DWARF64 detection dance. The function decodes the initial length field
and returns it as a pair containing the actual length, and the DWARF
encoding.

This patch does _not_ attempt to handle the problem of detecting lengths
which extend past the size of the section, or cases when reads of a
single contribution accidentally escape beyond its specified length, but
I think it's useful in its own right.

Reviewers: dblaikie, jhenderson, ikudrin

Subscribers: hiraditya, probinson, aprantl, JDevlieghere, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74560
2020-02-26 17:07:58 +01:00
Pavel Labath
f744a9cab7 Use new FailedWithMessage matcher in DWARFDebugLineTest.cpp
Summary:
This should produce slightly better error messages in case of failures.
Only slightly, because this code was pretty careful about that to begin
with -- I've seen code which does much worse.

Reviewers: jhenderson, dblaikie

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74899
2020-02-24 10:27:00 +01:00
Greg Clayton
76f7457508 Add an Offset field to the SourceLocation for LookupResult objects.
Summary:
The Offset provides the offset within the function in a SourceLocation struct. This allows us to show the byte offset within a function. We also track offsets within inline functions as well. Updated the lookup tests to verify the offset for functions and inline functions.

0x1000: main + 32 @ /tmp/main.cpp:45

Reviewers: labath, aadsm, serhiy.redko, jankratochvil, xiaobai, wallace, aprantl, JDevlieghere

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74680
2020-02-19 16:12:32 -08:00
Greg Clayton
0f9e8cbf13 [NFC] Move ValidTextRanges out of DwarfTransformer and into GsymCreator and unify address is not in GSYM errors so all strings match. 2020-02-15 16:48:23 -08:00
Fangrui Song
13339a0dea [MCStreamer] De-capitalize EmitValue EmitIntValue{,InHex} 2020-02-14 23:08:40 -08:00
Fangrui Song
e6d3f76ab0 [MC] De-capitalize another set of MCStreamer::Emit* functions
Emit{ValueTo,Code}Alignment Emit{DTP,TP,GP}* EmitSymbolValue etc
2020-02-14 19:26:52 -08:00
Fangrui Song
343c2a2b44 [MC] De-capitalize some MCStreamer::Emit* functions 2020-02-14 19:11:53 -08:00
James Henderson
87baadc8bc [test][DebugInfo] Fix signed/unsigned comparison problem in test
This caused build bot failures:
http://lab.llvm.org:8011/builders/ppc64le-lld-multistage-test/builds/8568/
2020-02-14 13:40:44 +00:00
James Henderson
a0c4d6a1cc [DebugInfo] Error if unsupported address size detected in line table
Prior to this patch, if a DW_LNE_set_address opcode was parsed with an
address size (i.e. with a length after the opcode) of anything other 1,
2, 4, or 8, an llvm_unreachable would be hit, as the data extractor does
not support other values. This patch introduces a new error check that
verifies the address size is one of the supported sizes, in common with
other places within the DWARF parsing.

This patch also fixes calculation of a generated line table's size in
unit tests. One of the tests in this patch highlighted a bug introduced
in 1271cde4745, when non-byte operands were used as arguments for
extended or standard opcodes.

Reviewed by: dblaikie

Differential Revision: https://reviews.llvm.org/D73962
2020-02-14 11:08:12 +00:00
Fangrui Song
216ba73a16 [AsmPrinter] De-capitalize some AsmPrinter::Emit* functions
Similar to rL328848.
2020-02-13 13:38:33 -08:00
Greg Clayton
ccea019faf Add a DWARF transformer class that converts DWARF to GSYM.
Summary:
The DWARF transformer is added as a class so it can be unit tested fully.

The DWARF is converted to GSYM format and handles many special cases for functions:
- omit functions in compile units with 4 byte addresses whose address is UINT32_MAX (dead stripped)
- omit functions in compile units with 8 byte addresses whose address is UINT64_MAX (dead stripped)
- omit any functions whose high PC is <= low PC (dead stripped)
- StringTable builder doesn't copy strings, so we need to make backing copies of strings but only when needed. Many strings come from sections in object files and won't need to have backing copies, but some do.
- When a function doesn't have a mangled name, store the fully qualified name by creating a string by traversing the parent decl context DIEs and then. If we don't do this, we end up having cases where some function might appear in the GSYM as "erase" instead of "std::vector<int>::erase".
- omit any functions whose address isn't in the optional TextRanges member variable of DwarfTransformer. This allows object file to register address ranges that are known valid code ranges and can help omit functions that should have been dead stripped, but just had their low PC values set to zero. In this case we have many functions that all appear at address zero and can omit these functions by making sure they fall into good address ranges on the object file. Many compilers do this when the DWARF has a DW_AT_low_pc with a DW_FORM_addr, and a DW_AT_high_pc with a DW_FORM_data4 as the offset from the low PC. In this case the linker can't write the same address to both the high and low PC since there is only a relocation for the DW_AT_low_pc, so many linkers tend to just zero it out.

Reviewers: aprantl, dblaikie, probinson

Subscribers: mgorny, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74450
2020-02-13 10:48:37 -08:00
James Henderson
28d5339ea7 [DebugInfo] Add checks for v2 directory and file name table terminators
The DWARFv2-4 specification for the line table header states that the
include directories and file name tables both end with a single null
byte. Prior to this change, the parser did not detect if this byte was
missing, because it also stopped reading the tables once it reached the
prologue end, as claimed by the header_length field. This change adds a
check that the terminator has been seen at the end of each table.

Reviewed by: dblaikie, MaskRay

Differential Revision: https://reviews.llvm.org/D74413
2020-02-12 14:49:22 +00:00
James Henderson
dff704a989 [DebugInfo] Print version in error message in decimal
Also remove some test duplication and add a test case that shows the
maximum version is rejected (this also shows that the value in the error
message is actually in decimal, and not just missing an 0x prefix).

Reviewed by: dblaikie

Differential Revision: https://reviews.llvm.org/D74403
2020-02-12 14:49:22 +00:00
Sterling Augustine
0b336f6ee0 Update test for windows. 2020-02-11 12:35:46 -08:00
Sterling Augustine
ad25ac2e9f Allow retrieving source files relative to the compilation directory.
Summary:
Dwarf stores source-file names the three parts:
<compilation_directory><include_directory><filename>

Prior to this change, the code only allowed retrieving either all
three as the absolute path, or just the filename.  But many
compile-command lines--especially those in hermetic build systems
don't specify an absolute path, nor just the filename, but rather the
path relative to the compilation directory. This features allows
retrieving them in that style.

Add tests for path printing styles.

Modify createBasicPrologue to handle include directories.

Subscribers: aprantl, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73383
2020-02-11 11:46:20 -08:00
Sterling Augustine
ddc0ec1309 [DebugInfo] Support file-level include directories when generating DWARFv5 LineTable prologues.
Differential Revision: https://reviews.llvm.org/D74249
2020-02-10 12:24:46 -08:00
James Henderson
a1baba7432 [DebugInfo][test] Fix host endian test issue
The test previously assumed that the host was little endian, which broke
the big endian build bots.
2020-02-10 16:23:30 +00:00
James Henderson
cb74c8eb16 [DebugInfo][test] Fix(?) build bots due to incorrect type usage 2020-02-10 15:11:49 +00:00
James Henderson
f0566b59e2 [DebugInfo] Reject line tables of version > 5
If a debug line section with version of greater than 5 is encountered,
prior to this change the parser would accept it and treat it as version
5. This might work to some extent, but then it might not at all, as it
really depends on the format of the unspecified future version, which
will be different (otherwise there would be no point in changing the
version number). Any information we could provide has a good chance of
being invalid, so we should just refuse to parse such tables.

Reviewed by: dblaikie, MaskRay

Differential Revision: https://reviews.llvm.org/D74204
2020-02-10 14:43:10 +00:00
James Henderson
34f3b069d4 [NFC] Fix line endings 2020-02-10 14:41:46 +00:00
James Henderson
72ca7e6d2b [DebugInfo][test] Replace pre-canned binary test
The DebugInfo/dwarfdump-invalid-line-table test used a pre-canned binary
generated by a fuzzer to demonstrate a bug fix. Unfortunately, the
binary is rigid and requires hand-editing if we change behaviour, such
as rejecting certain properties within it (as I plan on doing in another
change).

Rather than hand-edit the binary, I have replaced it with two tests. The
first tests the high-level code path from the debug line parser that
produces the same error as this test previously did, and the second is a
set of unit test cases that comprehensively cover the
FormValue::skipValue method, which in turn covers the area that the
original bug fix touched.

Reviewed by: MaskRay, dblaikie

Differential Revision: https://reviews.llvm.org/D74202
2020-02-10 13:54:40 +00:00
James Henderson
46d04a31b6 [DebugInfo][test] Adjust line table unit length to account for contents
Previously, if a debug line Prologue was created via
createBasicPrologue, its TotalLength field did not account for any
contents in the table itself. This change fixes this issue.

Reviewed by: probinson

Differential Revision: https://reviews.llvm.org/D73772
2020-02-03 12:16:36 +00:00
Igor Kudrin
2e7956d059 [DWARF] Add support for 64-bit DWARF in .debug_names.
Differential Revision: https://reviews.llvm.org/D72900
2020-01-31 16:12:35 +07:00
James Henderson
076adf9c49 [DebugInfo] Fix DebugLine::Prologue::getLength
The function a) returned 32-bits when in DWARF64, the PrologueLength
field is 64-bits in size, and b) didn't work for DWARF version 5.

Also deleted some related dead code. With this deletion, getLength is
itself dead, but another change is about to make use of it.

Reviewed by: probinson

Differential Revision: https://reviews.llvm.org/D73626
2020-01-30 09:35:50 +00:00
James Henderson
0edcf38c7a [DebugInfo] Make most debug line prologue errors non-fatal to parsing
Many of the debug line prologue errors are not inherently fatal. In most
cases, we can make reasonable assumptions and carry on. This patch does
exactly that. In the case of length problems, the approach of "assume
stated length is correct" is taken which means the offset might need
adjusting.

This is a relanding of b94191fe, fixing an LLD test and the LLDB build.

Reviewed by: dblaikie, labath

Differential Revision: https://reviews.llvm.org/D72158
2020-01-29 10:23:41 +00:00
Benjamin Kramer
87d13166c7 Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with
std::string_view. There should be no functional change here.

This is mostly mechanical from a custom clang-tidy check, with a lot of
manual fixups. It uncovers a lot of minor inefficiencies.

This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-28 23:25:25 +01:00
James Henderson
b93b2eeaa3 Revert "[DebugInfo] Make most debug line prologue errors non-fatal to parsing"
This reverts commit b94191fecdbadc18b342a27df1109754edcb8c4b.

The change broke both an LLD test and the LLDB build.
2020-01-28 11:49:30 +00:00
James Henderson
89524e5f12 [DebugInfo] Make most debug line prologue errors non-fatal to parsing
Many of the debug line prologue errors are not inherently fatal. In most
cases, we can make reasonable assumptions and carry on. This patch does
exactly that. In the case of length problems, the approach of "the
claimed length is correct" is taken to be consistent with other
instances such as the SectionParser, which ignores the read length.

Reviewed by: dblaikie

Differential Revision: https://reviews.llvm.org/D72158
2020-01-28 11:29:50 +00:00
James Henderson
a050bdcc58 [DebugInfo] Make incorrect debug line extended opcode length non-fatal
It is possible to try to keep parsing a debug line program even when the
length of an extended opcode does not match what is expected for that
opcode. This patch changes what was previously a fatal error to be
non-fatal. The parser now continues by assuming the the claimed length
is correct, even if it means moving the offset backwards.

Reviewed by: dblaikie

Differential Revision: https://reviews.llvm.org/D72155
2020-01-27 15:32:41 +00:00
Reid Kleckner
c822eded13 [codeview] Prune SimpleTypeSerializer.h headers, NFC
These are left over from when the class was more complicated. Add a
header comment banner to the .cpp file, which was missing.
2020-01-24 16:07:36 -08:00
Igor Kudrin
d2a354ad70 [DWARF] Better detect errors in Address Range Tables.
The patch tries to cover most remaining cases of wrong data.

Differential Revision: https://reviews.llvm.org/D71932
2020-01-23 12:41:05 +07:00
Igor Kudrin
2a9879d3d3 [DWARF] Support DWARF64 in DWARFDebugArangeSet.
This allows parsing Address Range Tables in the 64-bit DWARF format.

Differential Revision: https://reviews.llvm.org/D71876
2020-01-23 12:41:05 +07:00
Igor Kudrin
25f6cfa0aa [DWARF] Return Error from DWARFDebugArangeSet::extract().
This helps to detect and report parsing errors better.
The patch follows the ideas of LLDB's patches D59370 and D59381.

It adds tests for valid and some invalid cases. More checks and
tests to come. Note that the patch fixes validation of the Length
field because the value does not include the field itself.

The existing users are updated to show the error messages.

Differential Revision: https://reviews.llvm.org/D71875
2020-01-23 12:41:05 +07:00
James Henderson
69703dcf78 [DebugInfo] Make debug line address size mismatch non-fatal to parsing
Reasonable assumptions can be made when a parsed address length does not
match the expected length, so there's no need for this to be fatal.

Reviewed by: ikudrin

Differential Revision: https://reviews.llvm.org/D72154
2020-01-13 16:27:05 +00:00
James Henderson
57d8688d36 [DebugInfo] Improve error message text
Unlike most of our errors in the debug line parser, the "no end of
sequence" message was missing any reference to which line table it
refererred to. This change adds the offset to this message.

Reviewed by: dblaikie

Differential Revision: https://reviews.llvm.org/D72443
2020-01-10 14:59:58 +00:00
James Henderson
9361ef9442 [DebugInfo] Fix infinite loop caused by reading past debug_line end
If the claimed unit length of a debug line program is such that the line
table would finish past the end of the .debug_line section, an infinite
loop occurs because the data extractor will continue to "read" zeroes
without changing the offset. This previously didn't hit an error because
the line table program handles a series of zeroes as a bad extended
opcode.

This patch fixes the inifinite loop and adds a warning if the program
doesn't fit in the available data.

Reviewed by: JDevlieghere

Differential Revision: https://reviews.llvm.org/D72279
2020-01-07 10:22:35 +00:00
James Henderson
5e309984b7 [test][DebugInfo][NFC] Rename method for clarity
The checkGetOrParseLineTableEmitsError function could end up generating
both recoverable and unrecoverable errors, but it is only intended for
handling the latter.

Reviewed by: dblaikie

Differential Revision: https://reviews.llvm.org/D72156
2020-01-06 11:30:26 +00:00
James Henderson
e971a824fd [DebugInfo] Fix printing of DW_LNS_set_isa
The Isa register is a uint8_t, but at least on Windows this is
internally an unsigned char, which meant that prior to this patch it got
formatted as an ASCII character, rather than a decimal number. This
patch fixes this by casting it to a uint64_t before printing. I did it
this way instead of using a uint8_t formatter because a) it is simpler,
and b) it allows us to change the internal type of Isa in the future
without this code breaking.

I also took the opportunity to test the printing of the other standard
opcodes.

Reviewed by: probinson

Differential Revision: https://reviews.llvm.org/D71274
2019-12-11 13:38:41 +00:00