301 Commits

Author SHA1 Message Date
Greg Clayton
44810bc17f Fix buildbots.
MSVC doesn't correctly capture constexpr in lambdas, and other builds warn if you do, others will error out if you do. Avoid lambdas.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372179 91177308-0d34-0410-b5e6-96231b3b80d8
2019-09-17 20:31:01 +00:00
Greg Clayton
c7e2fdea40 GSYM: Add the llvm::gsym::Header header class with tests
This patch adds the llvm::gsym::Header class which appears at the start of a stand alone GSYM file, or in the first bytes of the GSYM data in a GSYM section within a file. Added encode and decode methods with full error handling and full tests.

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372149 91177308-0d34-0410-b5e6-96231b3b80d8
2019-09-17 17:46:13 +00:00
Simon Pilgrim
7583a6bc10 Fix MSVC lambda capture warnings. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372144 91177308-0d34-0410-b5e6-96231b3b80d8
2019-09-17 17:24:55 +00:00
Greg Clayton
d4f9d51f7e GSYM: add encoding and decoding to FunctionInfo
This patch adds encoding and decoding of the FunctionInfo objects along with full error handling and tests. Full details of the FunctionInfo encoding format appear in the FunctionInfo.h header file.

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372135 91177308-0d34-0410-b5e6-96231b3b80d8
2019-09-17 16:15:49 +00:00
David Blaikie
9294c897b2 Add some missing changes to GSYM that was addressing a gcc compilation error due to a type and variable with the same name
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@371681 91177308-0d34-0410-b5e6-96231b3b80d8
2019-09-11 22:24:45 +00:00
Greg Clayton
5447f442c7 Add a LineTable class to GSYM and test it.
This patch adds the ability to create a gsym::LineTable object, populate it, encode and decode it and test all functionality.

The full format of the LineTable encoding is specified in the header file LineTable.h.

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@371657 91177308-0d34-0410-b5e6-96231b3b80d8
2019-09-11 20:51:03 +00:00
Igor Kudrin
9387344a36 Reland [DWARF] Add a unit test for DWARFUnit::getLength().
This is a follow-up of rL369529, where the return value of
DWARFUnit::getLength() was changed from uint32_t to uint64_t.
The test checks that a unit header with Length > 4G can be successfully
parsed and the value of the Length field is not truncated.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@371510 91177308-0d34-0410-b5e6-96231b3b80d8
2019-09-10 11:54:32 +00:00
Igor Kudrin
5caea93ebd Revert "[DWARF] Add a unit test for DWARFUnit::getLength()" because it broke ASAN bot.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@371505 91177308-0d34-0410-b5e6-96231b3b80d8
2019-09-10 10:17:48 +00:00
Igor Kudrin
591903131e [DWARF] Add a unit test for DWARFUnit::getLength().
This is a follow-up of rL369529, where the return value of
DWARFUnit::getLength() was changed from uint32_t to uint64_t.
The test checks that a unit header with Length > 4G can be successfully
parsed and the value of the Length field is not truncated.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@371499 91177308-0d34-0410-b5e6-96231b3b80d8
2019-09-10 09:03:24 +00:00
Greg Clayton
d9ad3be1c9 Add encode and decode methods to InlineInfo and document encoding format to the GSYM file format.
This patch adds the ability to encode and decode InlineInfo objects and adds test coverage. Error handling is introduced in the encoding and decoding which will be used from here on out for remaining patches.

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




git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@370936 91177308-0d34-0410-b5e6-96231b3b80d8
2019-09-04 17:32:51 +00:00
Greg Clayton
a8e86b955e Add FileWriter to GSYM and encode/decode functions to AddressRange and AddressRanges
The full GSYM patch started with: https://reviews.llvm.org/D53379

This patch add the ability to encode data using the new llvm::gsym::FileWriter class.

FileWriter is a simplified binary data writer class that doesn't require targets, target definitions, architectures, or require any other optional compile time libraries to be enabled via the build process. This class needs the ability to seek to different spots in the binary data that it produces to fix up offsets and sizes in GSYM data. It currently uses std::ostream over llvm::raw_ostream because llvm::raw_ostream doesn't support seeking which is required when encoding and decoding GSYM data.

AddressRange objects are encoded and decoded to be relative to a base address. This will be the FunctionInfo's start address if the AddressRange is directly contained in a FunctionInfo, or a base address of the containing parent AddressRange or AddressRanges. This allows address ranges to be efficiently encoded using ULEB128 encodings as we encode the offset and size of each range instead of full addresses. This also makes encoded addresses easy to relocate as we just need to relocate one base address.

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369587 91177308-0d34-0410-b5e6-96231b3b80d8
2019-08-21 21:48:11 +00:00
Jonas Devlieghere
114087caa6 [llvm] Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances across the monorepo.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369013 91177308-0d34-0410-b5e6-96231b3b80d8
2019-08-15 15:54:37 +00:00
David Blaikie
948e657594 DebugInfo/DWARF: Normalize DWARFObject members on the DWARF spec section names
Some of these names were abbreviated, some were not, some pluralised,
some not. Made the API difficult to use - since it's an exact 1:1
mapping to the DWARF sections - use those names (changing underscore
separation for camel casing).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368189 91177308-0d34-0410-b5e6-96231b3b80d8
2019-08-07 17:18:11 +00:00
Igor Kudrin
36ec6cc9c1 Support 64-bit offsets in utility classes (1/5)
Using 64-bit offsets is required to fully implement 64-bit DWARF.
As these classes are used in many different libraries they should
temporarily support both 32- and 64-bit offsets.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368013 91177308-0d34-0410-b5e6-96231b3b80d8
2019-08-06 10:47:20 +00:00
Fangrui Song
2ffd08308b Rename F_{None,Text,Append} to OF_{None,Text,Append}. NFC
F_{None,Text,Append} are kept for compatibility since r334221.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367800 91177308-0d34-0410-b5e6-96231b3b80d8
2019-08-05 05:43:48 +00:00
Paul Robinson
aad23eb933 Silence a conversion warning after r366887. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366906 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-24 14:15:02 +00:00
Igor Kudrin
ae40b57421 [DWARF][NFC] Add constants for reserved values of an initial length field.
Differential Revision: https://reviews.llvm.org/D65039


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366887 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-24 11:34:29 +00:00
Jonas Devlieghere
bee5bcd674 [DWARF] Add more error handling to debug line parser.
This patch exnteds the error handling in the debug line parser to get
rid of the existing MD5 assertion. I want to reuse the debug line parser
from LLVM in LLDB where we cannot crash on invalid input.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366762 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-22 23:23:34 +00:00
Igor Kudrin
f6f2d32c53 [DWARF] Fix the reserved values for unit length in DWARFDebugLine.
The DWARF3 documentation had inconsistency concerning the reserved range
for unit length values. The issue was fixed in DWARF4.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366190 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-16 07:01:08 +00:00
Nico Weber
177247fd3b PDB HashTable: Move TraitsT from class parameter to the methods that need it
The traits object is only used by a few methods. Deserializing a hash
table and walking it is possible without the traits object, so it
shouldn't be required to build a dummy object for that use case.

The TraitsT object used to be a function template parameter before
r327647, this restores it to that state.

This makes it clear that the traits object isn't needed at all in 1 of
the current 3 uses of HashTable (and I am going to add another use that
doesn't need it), and that the default PdbHashTraits isn't used outside
of tests.

While here, also re-enable 3 checks in the test that were commented out
(which requires making HashTableInternals templated and giving FooBar
an operator==).

No intended behavior change.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365974 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-12 23:30:55 +00:00
Fangrui Song
9cd08b6cee [DebugInfo] Simplify GSYM::AddressRange and GSYM::AddressRanges
Delete unnecessary getters of AddressRange.
Simplify AddressRange::size(): Start <= End check should be checked in an upper layer.
Delete isContiguousWith() that doesn't make sense.
Simplify AddressRanges::insert. Delete commented code. Fix it when more than 1 ranges are to be deleted.
Delete trailing newline.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364637 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-28 10:06:11 +00:00
Fangrui Song
144fab93ff [DebugInfo] GSYM cleanups after D63104/r364427
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364634 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-28 08:58:05 +00:00
Greg Clayton
4871614dcf Add GSYM utility files along with unit tests.
The full GSYM patch started with: https://reviews.llvm.org/D53379

In that patch we wanted to split up getting GSYM into the LLVM code base so we are not committing too much code at once.

This is a first in a series of patches where I only add the foundation classes along with complete unit tests. They provide the foundation for encoding and decoding a GSYM file.

File entries are defined in llvm::gsym::FileEntry. This class splits the file up into a directory and filename represented by uniqued string table offsets. This allows all files that are referred to in a GSYM file to be encoded as 1 based indexes into a global file table in the GSYM file.

Function information in stored in llvm::gsym::FunctionInfo. This object represents a contiguous address range that has a name and range with an optional line table and inline call stack information.

Line table entries are defined in llvm::gsym::LineEntry. They store only address, file and line information to keep the line tables simple and allows the information to be efficiently encoded in a subsequent patch.

Inline information is defined in llvm::gsym::InlineInfo. These structs store the name of the inline function, along with one or more address ranges, and the file and line that called this function. They also contain any child inline information.

There are also utility classes for address ranges in llvm::gsym::AddressRange, and string table support in llvm::gsym::StringTable which are simple classes.

The unit tests test all the APIs on these simple classes so they will be ready for the next patches where we will create GSYM files and parse GSYM files.

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




git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364427 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-26 14:09:09 +00:00
Jason Liu
15479d535a Fix DWARF DebugInfo unit test errors when cross-compiling
Summary:
When building with a Default Target set we can experience issues
in the DWARF DebugInfo unit tests because:

They assume we can generate object files for the host platform.
Some tests assume the endianess of the target we are generating
DWARF for and the host match.

This patch correct these issues by ensuring the tests which
generate objects in memory are run with respect to
LVM_DEFAULT_TARGET_TRIPLE and it's endianess.

We also make sure we don't use the hosts address size for line test
and split the triple util function in DwarfUtils into a version
that takes an address size and one that doesn't.

See also for discussion:
http://lists.llvm.org/pipermail/llvm-dev/2019-March/131212.html

Patch by: daltenty

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362454 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-03 22:22:03 +00:00
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 466ce67d6ec444962e5cc0136243c16a453190c0.

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 b5c7e2f9a4dbb34e3667c4bb4972735eadd3247a.

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