Commit Graph

277 Commits

Author SHA1 Message Date
Nico Weber
033bb22f79 [PDB] Fix hash function used to write /src/headerblock
lld-link used to write PDB files that DIA couldn't recover natvis
files from if:

- The global strings table was > 64kiB
- There were at least 3 natvis files

The cause was that the hash function for the /src/headerblock stream
was incorrect: It needs to be truncated to 16 bit.

If the global strings table was <= 64kiB, truncating to 16 bit is a
no-op, so this wasn't needed for small programs.

If there are only 1 or 2 natvis files, then the growth strategy in
HashTable::grow() would mean the hash table would have 2 buckets (for 1
natvis file) or 4 buckets (for 4 natvis files), and since the hash
function is used modulo number of buckets, and since 2 and 4 divide
0x10000, the missing `% 0x10000` is a no-op there too. For 3 natvis
files, the hash table grows to 6 buckets, which has a factor that's not
common with 0x10000 and the difference starts to matter.

Fixes PR41626.

Differential Revision: https://reviews.llvm.org/D61277

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359515 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-29 23:09:35 +00:00
Fangrui Song
b0014722fd [DWARF] Fix DWARFVerifier::DieRangeInfo::contains
It didn't handle empty LHS correctly. If two ranges of LHS were
contiguous and jointly contained one range of RHS, it could also be incorrect.

DWARFAddressRange::contains can be removed and its tests can be merged into DWARFVerifier::DieRangeInfo::contains

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358387 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-15 10:02:36 +00:00
Fangrui Song
1d49a21976 [DWARF] Fix DWARFVerifier::DieRangeInfo::intersects
It was incorrect if RHS had more than 1 ranges and one of the ranges interacted with *this

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358376 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-15 08:30:10 +00:00
Reid Kleckner
27775cd11b [codeview] Remove Type member from CVRecord
Summary:
Now CVType and CVSymbol are effectively type-safe wrappers around
ArrayRef<uint8_t>. Make the kind() accessor load it from the
RecordPrefix, which is the same for types and symbols.

Reviewers: zturner, aganea

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D60018

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357658 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-04 00:28:48 +00:00
Jonas Devlieghere
6187547968 [DWARFFormValue] Cleanup DWARFFormValue interface. (NFC)
DWARFFormValues can be created from a data extractor or by passing its
value directly. Until now this was done by member functions that
modified an existing object's internal state. This patch replaces a
subset of these methods with static method that return a new
DWARFFormValue.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354941 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-27 00:58:09 +00:00
Chandler Carruth
6b547686c5 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-19 08:50:56 +00:00
Jonas Devlieghere
92ddcaeadd [DebugInfo] Define base function on DWARFDie reverse iterators
This defines member function base on the specialization of
std::reverse_iterator for DWARFDie::iterator as required by C++
[reverse.iter.conv].

This fixes unit test DWARFDebugInfoTest.cpp under EXPENSIVE_CHECKS which
currently can't be built due to GNU C++ Library calling this member
function in debug mode.

This fixes https://llvm.org/PR38785

Patch by: Eugene Sharygin

Differential revision: https://reviews.llvm.org/D53792

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345621 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-30 18:25:28 +00:00
Aleksandr Urakov
7fc581a267 Revert "Revert "[PDB] Extend IPDBSession's interface to retrieve frame data""
This reverts commit 466ce67d6e.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345010 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-23 08:14:53 +00:00
Aleksandr Urakov
466ce67d6e Revert "[PDB] Extend IPDBSession's interface to retrieve frame data"
This reverts commit b5c7e2f9a4.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344909 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-22 15:30:48 +00:00
Aleksandr Urakov
b5c7e2f9a4 [PDB] Extend IPDBSession's interface to retrieve frame data
Summary:
This patch just extends the `IPDBSession` interface to allow retrieving
of frame data through it, and adds an implementation over DIA. It is needed
for an implementation (for now with DIA) of the conversion from FPO programs
to DWARF expressions mentioned in D53086.

Reviewers: zturner, asmith, rnk

Reviewed By: asmith

Subscribers: mgorny, aprantl, JDevlieghere, llvm-commits

Differential Revision: https://reviews.llvm.org/D53324

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344886 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-22 07:18:08 +00:00
Zachary Turner
e105a22a72 Fix function signature to actually be an override.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342496 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-18 16:58:17 +00:00
Nico Weber
8c4c37e724 Introduce explicit add_unittest_with_input_files target for tests that use llvm::getInputFileDirectory()
Using llvm::getInputFileDirectory() in unit tests is discouraged, so require an explicit opt-in.
This way, cmake also writes ~60 fewer unused files to disk.

Differential Revision: https://reviews.llvm.org/D52095


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342248 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-14 17:34:46 +00:00
Zachary Turner
279c17e658 [PDB] Change uint32_t to SymIndex wherever it makes sense.
Although it's just a typedef, it helps for readability.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341863 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-10 21:30:59 +00:00
Fangrui Song
f22832842f Quick fix for -DBUILD_SHARED_LIBS=on build after rL341502
libLLVMTestingSupport.so references a symbol in utils/unittest/UnitTestMain/TestMain.cpp (a layering issue) and will cause a link error because of -Wl,-z,defs (cmake/modules/HandleLLVMOptions.cmake)

Waiting zturner for a better fix.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341580 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-06 19:51:20 +00:00
Zachary Turner
94bb0ad1a1 Fix a warning.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341561 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-06 16:34:56 +00:00
Zachary Turner
af026c1760 [PDB] Refactor the PDB symbol classes to fix a reuse bug.
The way DIA SDK works is that when you request a symbol, it
gets assigned an internal identifier that is unique for the
life of the session.  You can then use this identifier to
get back the same symbol, with all of the same internal state
that it had before, even if you "destroyed" the original
copy of the object you had.

This didn't work properly in our native implementation, and
if you destroyed an object for a particular symbol, then
requested the same symbol again, it would get assigned a new
ID and you'd get a fresh copy of the object.  In order to fix
this some refactoring had to happen to properly reuse cached
objects.  Some unittests are added to verify that symbol
reuse is taking place, making use of the new unittest input
feature.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341503 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-05 23:30:38 +00:00
Reid Kleckner
9d1f82a2cc [codeview] Use push_macro to avoid conflicts instead of a prefix
Summary:
This prefix was added in r333421, and it changed our dumper output to
say things like "CVRegEAX" instead of just "EAX". That's a functional
change that I'd rather avoid.

I tested GCC, Clang, and MSVC, and all of them support #pragma
push_macro. They don't issue warnings whem the macro is not defined
either.

I don't have a Mac so I can't test the real termios.h header, but I
looked at the termios.h sources online and looked for other conflicts.
I saw only the CR* macros, so those are the ones we work around.

Reviewers: zturner, JDevlieghere

Subscribers: hiraditya, llvm-commits

Differential Revision: https://reviews.llvm.org/D50851

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339907 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-16 17:34:31 +00:00
Pavel Labath
23332c50c1 [DebugInfo] Reduce debug_str_offsets section size
Summary:
The accelerator tables use the debug_str section to store their strings.
However, they do not support the indirect method of access that is
available for the debug_info section (DW_FORM_strx et al.).

Currently our code is assuming that all strings can/will be referenced
indirectly, and puts all of them into the debug_str_offsets section.
This is generally true for regular (unsplit) dwarf, but in the DWO case,
most of the strings in the debug_str section will only be used from the
accelerator tables. Therefore the contents of the debug_str_offsets
section will be largely unused and bloating the main executable.

This patch rectifies this by teaching the DwarfStringPool to
differentiate between strings accessed directly and indirectly. When a
user inserts a string into the pool it has to declare whether that
string will be referenced directly or not. If at least one user requsts
indirect access, that string will be assigned an index ID and put into
debug_str_offsets table. Otherwise, the offset table is skipped.

This approach reduces the overall binary size (when compiled with
-gdwarf-5 -gsplit-dwarf) in my tests by about 2% (debug_str_offsets is
shrunk by 99%).

Reviewers: probinson, dblaikie, JDevlieghere

Subscribers: aprantl, mgrang, llvm-commits

Differential Revision: https://reviews.llvm.org/D49493

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339122 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-07 09:54:52 +00:00
Paul Robinson
2b9857ed4f [DebugInfo/DWARF] [2/4] Type units no longer in a std::deque. NFC
This is patch 2 of 4 NFC refactorings to handle type units and compile
units more consistently and with less concern about the object-file
section that they came from.

Patch 2 takes the existing std::deque<DWARFUnitSection> for type units
and makes it a simple DWARFUnitSection, simplifying the handling of
type units and making it more consistent with compile units.

Differential Revision: https://reviews.llvm.org/D49742

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338629 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-01 20:46:46 +00:00
Paul Robinson
55a0ed21cd [DebugInfo/DWARF] [1/4] De-templatize DWARFUnitSection. NFC
This is patch 1 of 4 NFC refactorings to handle type units and compile
units more consistently and with less concern about the object-file
section that they came from.

Patch 1 replaces the templated DWARFUnitSection with a non-templated
version. That is, instead of being a SmallVector of pointers to a
specific unit kind, it is not a SmallVector of pointers to the base
class for both type and compile units.  Virtual methods are magic.

Differential Revision: https://reviews.llvm.org/D49741

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338628 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-01 20:43:47 +00:00
Jonas Devlieghere
86e18055e6 [DebugInfo] Have custom std::reverse_iterator<DWARFDie>
The DWARFDie is a lightweight utility wrapper that stores a pointer to a
compile unit and a debug info entry. Currently, its iterator (used for
walking over its children) stores a DWARFDie and returns a const
reference when dereferencing it.

When the iterator is modified (by incrementing or decrementing it), this
reference becomes invalid. This was happening when calling reverse on
it, because the std::reverse_iterator is keeping a temporary copy of the
iterator (see
https://en.cppreference.com/w/cpp/iterator/reverse_iterator for a good
illustration).

The relevant code in libcxx:

  reference operator*() const {_Iter __tmp = current; return *--__tmp;}

When dereferencing the reverse iterator, we decrement and return a
reference to a DWARFDie stored in the stack frame of this function,
resulting in UB at runtime.

This patch specifies the std::reverse_iterator for DWARFDie to do the
right thing.

Differential revision: https://reviews.llvm.org/D49679

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338506 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-01 10:24:17 +00:00
Alexandre Ganea
a7336f2922 [CodeView] Minimal support for S_UNAMESPACE records
Differential Revision: https://reviews.llvm.org/D50007


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338417 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-31 19:15:50 +00:00
Pavel Labath
bffd929d5b dwarfgen: Add support for generating the debug_str_offsets section, take 3
Previous version of this patch failed on darwin targets because of
different handling of cross-debug-section relocations. This fixes the
tests to emit the DW_AT_str_offsets_base attribute correctly in both
cases. Since doing this is a non-trivial amount of code, and I'm going
to need it in more than one test, I've added a helper function to the
dwarfgen DIE class to do it.

Original commit message follows:

The motivation for this is D49493, where we'd like to test details of
debug_str_offsets behavior which is difficult to trigger from a
traditional test.

This adds the plubming necessary for dwarfgen to generate this section.
The more interesting changes are:
- I've moved emitStringOffsetsTableHeader function from DwarfFile to
  DwarfStringPool, so I can generate the section header more easily from
  the unit test.
- added a new addAttribute overload taking an MCExpr*. This is used to
  generate the DW_AT_str_offsets_base, which links a compile unit to the
  offset table.

I've also added a basic test for reading and writing DW_form_strx forms.

Reviewers: dblaikie, JDevlieghere, probinson

Subscribers: llvm-commits, aprantl

Differential Revision: https://reviews.llvm.org/D49670

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338031 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-26 14:36:07 +00:00
Pavel Labath
99cfb5c8a7 dwarfgen: Don't create an AsmPrinter with an invalid ObjFile lowering
The AsmPrinter created in the tests contained an uninitialized
TargetLoweringObjectFile. Things mostly worked regardless, because we
used a separate instance of that class to specify sections to emit.

This rearanges the object construction order so that we can avoid
creating two lowering objects. Instead, we properly initialize the
object in the AsmPrinter, and have the DWARF generator store a pointer
to it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338026 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-26 13:16:06 +00:00
Pavel Labath
a70431e931 Revert "dwarfgen: Add support for generating the debug_str_offsets section, take 2"
This reverts commit r337933. The build error is fixed but the test now
fails on the darwin buildbots. Investigating...

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337935 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-25 16:34:43 +00:00
Pavel Labath
030afdf934 dwarfgen: Add support for generating the debug_str_offsets section, take 2
This recommits r337910 after fixing an "ambiguous call to addAttribute"
error with some compilers (gcc circa 4.9 and MSVC). It seems that these
compilers will consider a "false -> pointer" conversion during overload
resolution. This creates ambiguity because one I added an overload which
takes a MCExpr * as an argument.

I fix this by making the new overload take MCExpr&, which avoids the
conversion. It also documents the fact that we expect a valid MCExpr
object.

Original commit message follows:

The motivation for this is D49493, where we'd like to test details of
debug_str_offsets behavior which is difficult to trigger from a
traditional test.

This adds the plubming necessary for dwarfgen to generate this section.
The more interesting changes are:
- I've moved emitStringOffsetsTableHeader function from DwarfFile to
  DwarfStringPool, so I can generate the section header more easily from
  the unit test.
- added a new addAttribute overload taking an MCExpr*. This is used to
  generate the DW_AT_str_offsets_base, which links a compile unit to the
  offset table.

I've also added a basic test for reading and writing DW_form_strx forms.

Reviewers: dblaikie, JDevlieghere, probinson

Subscribers: llvm-commits, aprantl

Differential Revision: https://reviews.llvm.org/D49670

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337933 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-25 15:33:32 +00:00
Pavel Labath
a47b5f6ca0 Revert "dwarfgen: Add support for generating the debug_str_offsets section"
This reverts commit r337910 as it's generating "ambiguous call to
addAttribute" errors on some bots.

Will resubmit once I get a chance to look into the problem.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337924 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-25 12:52:30 +00:00
Pavel Labath
b1674d0d93 dwarfgen: Add support for generating the debug_str_offsets section
Summary:
The motivation for this is D49493, where we'd like to test details of
debug_str_offsets behavior which is difficult to trigger from a
traditional test.

This adds the plubming necessary for dwarfgen to generate this section.
The more interesting changes are:
- I've moved emitStringOffsetsTableHeader function from DwarfFile to
  DwarfStringPool, so I can generate the section header more easily from
  the unit test.
- added a new addAttribute overload taking an MCExpr*. This is used to
  generate the DW_AT_str_offsets_base, which links a compile unit to the
  offset table.

I've also added a basic test for reading and writing DW_form_strx forms.

Reviewers: dblaikie, JDevlieghere, probinson

Subscribers: llvm-commits, aprantl

Differential Revision: https://reviews.llvm.org/D49670

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337910 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-25 11:55:59 +00:00
Jonas Devlieghere
f8497881d6 [DebugInfo] Make children iterator bidirectional
Make the DIE iterator bidirectional so we can move to the previous
sibling of a DIE.

Differential revision: https://reviews.llvm.org/D49173

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336823 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-11 17:11:11 +00:00
Zachary Turner
6a89efb6b2 Move some code from PDBFileBuilder to MSFBuilder.
The code to emit the pieces of the MSF file were actually in
PDBFileBuilder.  Move this to MSFBuilder so that we can
theoretically emit an MSF without having a PDB file.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335789 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-27 21:18:15 +00:00
Jonas Devlieghere
5f28b9c36c [CodeView] Add prefix to CodeView registers.
Adds CVReg to CodeView register names to prevent a duplicate symbol with
CR3 defined in termios.h, as suggested by Zachary on the mailing list.

http://lists.llvm.org/pipermail/llvm-dev/2018-May/123372.html

Differential revision: https://reviews.llvm.org/D47478

rdar://39863705

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333421 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-29 14:35:34 +00:00
James Henderson
8b03f4d6d2 [DWARF] Refactor callback usage for .debug_line error handling
Change the "recoverable" error callback to take an Error instaed of a
string.

Reviewed by: JDevlieghere

Differential Revision: https://reviews.llvm.org/D46831



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332845 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-21 15:30:54 +00:00
Peter Collingbourne
17a98146db MC: Change the streamer ctors to take an object writer instead of a stream. NFCI.
The idea is that a client that wants split dwarf would create a
specific kind of object writer that creates two files, and use it to
create the streamer.

Part of PR37466.

Differential Revision: https://reviews.llvm.org/D47050

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332749 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-18 18:26:45 +00:00
Nico Weber
3220080533 Inline a few CMake variables into their only uses.
No behavior change. Makes unittests CMakeLists.txt files more self-consistent.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332280 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-14 19:23:31 +00:00
Simon Pilgrim
fc2b453631 Fix Wdocumentation warnings. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332239 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-14 12:22:30 +00:00
James Henderson
6340f7f814 [DWARF] Remove unused member and fix(?) the unit-tests on big endian hosts
I can't verified the fix on a big endian host, so I'm not 100% certain it
will work.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331986 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-10 14:36:24 +00:00
Roman Lebedev
f1d346e4c5 [DWARF] DwarfGenerator.h LineTable: explicitly mark DG as unused
Just want to unbreak the build.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331984 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-10 14:16:45 +00:00
Roman Lebedev
1886be969a [DWARF] dwarfgen::LineTable::writeData(): pacify -Wcovered-switch-default
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331983 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-10 14:16:41 +00:00
Roman Lebedev
b50edb96e4 [DWARF] DWARFDebugLineTest: fix a few more signed/unsigned mismatch warnings
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331982 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-10 14:16:37 +00:00
James Henderson
290ef8aa41 Fix signed/unsigned comparison warning and print format
The print format was causing at least 2 unit-test failures from r331971.

The signed/unsigned comparison warnings only appeared to affect two lines but
it was unclear whether it might just pop up on other lines, so I have been
explicit in all the literals in the tests.

There were other bot unit-test failures that I am still investigating.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331978 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-10 12:15:43 +00:00
James Henderson
b82663119e [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.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331971 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-10 10:51:33 +00:00
Nico Weber
05cdaca17f IWYU for llvm-config.h, removals. Also see r331184.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331190 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-30 15:26:01 +00:00
Nico Weber
0f38c60baf IWYU for llvm-config.h in llvm, additions.
See r331124 for how I made a list of files missing the include.
I then ran this Python script:

    for f in open('filelist.txt'):
        f = f.strip()
        fl = open(f).readlines()

        found = False
        for i in xrange(len(fl)):
            p = '#include "llvm/'
            if not fl[i].startswith(p):
                continue
            if fl[i][len(p):] > 'Config':
                fl.insert(i, '#include "llvm/Config/llvm-config.h"\n')
                found = True
                break
        if not found:
            print 'not found', f
        else:
            open(f, 'w').write(''.join(fl))

and then looked through everything with `svn diff | diffstat -l | xargs -n 1000 gvim -p`
and tried to fix include ordering and whatnot.

No intended behavior change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331184 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-30 14:59:11 +00:00
Jonas Devlieghere
f6415de6bf [ObjectYAML] Add ability for DWARFYAML to calculate DIE lengths
This patch adds the ability for the ObjectYAML DWARFEmitter to calculate
the lengths of DIEs. This is accomplished by creating a DIEFixupVisitor
class which traverses the DWARF DIEs to calculate and fix up the lengths
in the Compile Unit header.

The DIEFixupVisitor can be extended in the future to enable more complex
fix ups which will enable simplified YAML string representations.

This is also very useful when using the YAML format in unit tests
because you no longer need to know the length of the compile unit when
writing the YAML string.

Differential commandeered from Chris Bieneman (beanz)

Differential revision: https://reviews.llvm.org/D30666

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330421 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-20 12:33:49 +00:00
David Blaikie
461bf527e5 Rename *CommandFlags.def to *CommandFlags.inc
These aren't the .def style files used in LLVM that require a macro
defined before their inclusion - they're just basic non-modular includes
to stamp out command line flag variables.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329840 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-11 18:49:37 +00:00
Aaron Smith
9970be8176 [DebugInfoPDB] Add missing test for findSymbolByRVA and findSymbolByAddr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329733 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-10 18:12:49 +00:00
Alexandre Ganea
789d4d24fe [DebugInfo][COFF] Fix reading variable-length encoded records
While reading Codeview records which contain variable-length encoded integers,
such as LF_BCLASS, LF_ENUMERATE, LF_MEMBER, LF_VBCLASS or LF_IVBCLASS,
the record's size would be improperly calculated in cases where the value was
indeed of a variable length (>= LF_NUMERIC). This caused a bad alignement on
the next record, which would/might crash later on.

Differential Revision: https://reviews.llvm.org/D45104

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329659 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-10 01:58:45 +00:00
Alexandre Ganea
bc755e2a9c Fix line endings (CR/LF -> LF) introduced by rL329613
reviewer: zturner


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329646 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-10 00:09:15 +00:00
Alexandre Ganea
2031cf6be1 [Debuginfo][COFF] Minimal serialization support for precompiled types records
This change adds support for the LF_PRECOMP and LF_ENDPRECOMP records required
to read/write Microsoft precompiled types .objs.
See https://en.wikipedia.org/wiki/Precompiled_header#Microsoft_Visual_C_and_C++

This also adds handling for the .debug$P section, which is actually a .debug$T
section in disguise, found only in precompiled .objs.

Differential Revision: https://reviews.llvm.org/D45283

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329613 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-09 20:17:56 +00:00
Rafael Espindola
9f3889b501 Style update. NFC.
Rename 3 functions to start with lowercase letters. Don't repeat the
name in the comments.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328848 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-29 23:32:54 +00:00