134 Commits

Author SHA1 Message Date
Pavel Labath
de99770375 Fix "Optional" is ambiguous error on some bots
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334580 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-13 08:29:19 +00:00
Pavel Labath
c271b02f29 [DWARF/AccelTable] Remove getDIESectionOffset for DWARF v5 entries
Summary:
This method was not correct for entries in DWO files as it assumed it
could just add up the CU and DIE offsets to get the absolute DIE offset.
This is not correct for the DWO files, as here the CU offset will
reference the skeleton unit, whereas the DIE offset will be the offset
in the full unit in the DWO file.

Unfortunately, this means that we are not able to determine the absolute
DIE offset using the information in the .debug_names section alone,
which means we have to offload some of this work to the users of this
class.

To demonstrate how this can be done, I've added/fixed the ability to
lookup entries using accelerator tables in DWO files in llvm-dwarfdump.
To make this happen, I've needed to make two extra changes in other
classes:
- made the DWARFContext method to lookup a CU based on the section
  offset public. I've needed this functionality to lookup a CU, and this
  seems like a useful thing in general.
- made DWARFUnit::getDWOId call extractDIEsIfNeeded. Before this, the
  DWOId was filled in only if the root DIE happened to be parsed
  before we called the accessor. Since the lazy parsing is supposed to
  happen under the hood, calling extractDIEsIfNeeded seems appropriate.

Reviewers: JDevlieghere, aprantl, dblaikie

Subscribers: mgrang, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334578 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-13 08:14:27 +00:00
Pavel Labath
2299c2e836 DWARFAcceleratorTable: fix equal_range iterators
Summary:
Both (Apple and DWARF5) implementations of the iterators had bugs which
resulted in crashes if one attempted to iterate through the accelerator
tables all the way.

For the Apple tables, the issue was that we did not clear the DataOffset
field when we reached the end, which made our iterator compare unequal
to the "end" iterator. For the Dwarf5 tables, the problem was that we
incremented the CurrentIndex pointer and then used the incremented
(possibly invalid) pointer to check whether we have reached the end of
the index list.

The reason these bugs went undetected is because their only user
(dwarfdump) only ever searched for the first match. Besides allowing us
to test this fix, changing llvm-dwarfdump --find to display all matches
seems like a good improvement (it makes the behavior consistent with the
--name option), so I change llvm-dwarfdump to do that.

The existing tests would be sufficient to test this fix with the new
llvm-dwarfdump behavior, but I add a special test that demonstrates that
the tool indeed displays multiple results. The find.test test needed to
be tweaked a bit as the tool now does not print the ".debug_info
contents" header (also consistent with how --name works).

Reviewers: JDevlieghere, aprantl, dblaikie

Subscribers: mgrang, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333635 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-31 08:47:00 +00:00
Jonas Devlieghere
2071b7a8b2 [Support] Add color cl category.
This commit adds a color category so tools can document this option and
enables it for dwarfdump and dsymuttil.

rdar://problem/40498996

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333176 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-24 11:36:57 +00:00
Fangrui Song
ea4e592233 [DebugInfo] Accept S in augmentation strings in CIE.
glibc libc.a(sigaction.o) compiled from sysdeps/unix/sysv/linux/x86_64/sigaction.c uses "zRS".

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331738 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-08 06:21:12 +00:00
Rui Ueyama
0b9d56a30e Define InitLLVM to do common initialization all at once.
We have a few functions that virtually all command wants to run on
process startup/shutdown. This patch adds InitLLVM class to do that
all at once, so that we don't need to copy-n-paste boilerplate code
to each llvm command's main() function.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330046 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-13 18:26:06 +00:00
Pavel Labath
2cf5f8ca1d [DebugInfo/AccelTable] Fix inconsistency in getDIEOffset implementations
Summary:
Even though the getDIEOffset offset function was common for the two
accelerator table implementations, it was doing two different things:
for the Apple tables, it was returning the die offset relative to the
start of the section, whereas for DWARF v5 tables, it was relative to
the start of the CU.

I resolve this by renaming the function to getDIESectionOffset to make
it obvious what the function returns, and change the DWARF
implementation to return the section offset. I also keep the CU-relative
accessor, but only in the DWARF implementation (there is no way to get
this information for the Apple tables). This was not caught by existing
tests because the hand-written inputs also erroneously used section
offsets instead of CU-relative ones.

While looking at this, I noticed that the Apple implementation was not
fully correct either -- the header contains a DIEOffsetBase field, which
should be added to offsets encoded with the DW_FORM_ref*** family, but
this was not being used. This went unnoticed because all current writers
set this field to zero anyway. I fix this as well and add a hand-written
test which demonstrates the issue.

Reviewers: JDevlieghere, dblaikie

Subscribers: aprantl, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327116 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-09 11:58:59 +00:00
Pavel Labath
39821cc14f Fix build breakage from r326003
- an ambiguous reference to Optional<T> in llvm-dwarfdump.cpp (fixed
  with an explicit prefix).
- a missing base class initialization in Entry copy constructor (fixed
  by using the implicitly default constructor, which is possible after
  some changes which were done during review).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326006 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-24 00:54:31 +00:00
Pavel Labath
0999c7ce09 Implement equal_range for the DWARF v5 accelerator table
Summary:
This patch implements the name lookup functionality of the .debug_names
accelerator table and hooks it up to "llvm-dwarfdump -find". To make the
interface of the two kinds of accelerator tables more consistent, I've
created an abstract "DWARFAcceleratorTable::Entry" class, which provides
a consistent interface to access the common functionality of the table
entries (such as getting the die offset, die tag, etc.). I've also
modified the apple table to vend entries conforming to this interface.

Reviewers: JDevlieghere, aprantl, probinson, dblaikie

Subscribers: vleschuk, clayborg, echristo, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326003 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-24 00:35:21 +00:00
Jonas Devlieghere
f1567ab48d [dwarfdump] Normalize input path.
Before this patch, llvm-dwarfdump would reject `bundel.dSYM/` as input,
while `bundel.dSYM` was accepted. The reason is that `path::extension()`
returns an empty string for the former, leading to the argument not
being recognized as a dSYM bundle.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324621 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-08 16:31:01 +00:00
Pavel Labath
0757989b8c [DebugInfo] Basic .debug_names dumping support
Summary:
This commit renames DWARFAcceleratorTable to AppleAcceleratorTable to free up
the first name as an interface for the different accelerator tables.
Then I add a DWARFDebugNames class for the dwarf5 table.

Presently, the only common functionality of the two classes is the dump()
method, because this is the only method that was necessary to implement
dwarfdump -debug-names; and because the rest of the
AppleAcceleratorTable interface does not directly transfer to the dwarf5
tables (the main reason for that is that the present interface assumes
the tables are homogeneous, but the dwarf5 tables can have different
keys associated with each entry).

I expect to make the common interface richer as I add more functionality
to the new class (and invent a way to represent it in generic way).

In terms of sharing the implementation, I found the format of the two
tables sufficiently different to frustrate any attempts to have common
parsing or dumping code, so presently the implementations share just low
level code for formatting dwarf constants.

Reviewers: vleschuk, JDevlieghere, clayborg, aprantl, probinson, echristo, dblaikie

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323638 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-29 11:08:32 +00:00
Pavel Labath
efadeb465e Rename DwarfAcceleratorTable to AppleAcceleratorTable. NFC
This frees up the first name to be used as an base class for the
apple table and the dwarf5 .debug_names accel table. The rename  was
split off from D42297 (adding of debug_names support), which is still
under review.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323113 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-22 13:17:23 +00:00
Jonas Devlieghere
d900f82d61 [dwarfdump] Lookup needs to be an unsigned long long parameter.
Before this patch, dwarfdump's lookup parameter only accepts unsigned.
Given that for many current platforms the load address already exceeds
unsigned (e.g. arm64 w/ 0x100000000), dwarfdump needs an unsigned long
long parameter.

Patch by: Dr. Michael 'Mickey' Lauer <mickey@vanille-media.de>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321064 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-19 09:45:26 +00:00
Michael Zolotukhin
d770752b5c Remove redundant includes from tools.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320631 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-13 21:31:10 +00:00
Adrian Prantl
b5b768dede dwarfdump: Add support for the --diff option.
--diff      Emit the output in a diff-friendly way by omitting offsets and
            addresses.

<rdar://problem/34502625>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320214 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-08 23:32:47 +00:00
Adrian Prantl
c97df2361b llvm-dwarfdump: honor the --show-children option when dumping a specific DIE.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319271 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29 01:12:22 +00:00
Jonas Devlieghere
c2c04200c8 Re-land "[dwarfdump] Add -lookup option"
Add the option to lookup an address in the debug information and print
out the file, function, block and line table details.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316619 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-25 21:56:41 +00:00
Adrian Prantl
e14de92ad4 Unify spelling.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315102 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-06 20:24:35 +00:00
Adrian Prantl
eadc313c6a llvm-dwarfdump: Add an option to collect debug info quality metrics.
At the last LLVM dev meeting we had a debug info for optimized code
BoF session. In that session I presented some graphs that showed how
the quality of the debug info produced by LLVM changed over the last
couple of years. This is a cleaned up version of the patch I used to
collect the this data. It is implemented as an extension of
llvm-dwarfdump, adding a new --statistics option. The intended
use-case is to automatically run this on the debug info produced by,
e.g., our bots, to identify eyebrow-raising changes or regressions
introduced by new transformations that we could act on.

In the current form, two kinds of data are being collected:

- The number of variables that have a debug location versus the number
  of variables in total (this takes into account inlined instances of
  the same function, so if a variable is completely missing form only
  one instance it will be found).

- The PC range covered by variable location descriptions versus the PC
  range of all variables' containing lexical scopes.

The output format is versioned and extensible, so I'm looking forward
to both bug fixes and ideas for other data that would be interesting
to track.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315101 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-06 20:24:34 +00:00
Adrian Prantl
ffbb88fc8a llvm-dwarfdump: implement the --regex option in combination with --name.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314855 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-03 22:08:22 +00:00
Hans Wennborg
f8a9b3953b Revert r314817 "[dwarfdump] Add -lookup option"
The test fails on Linux; see follow-up email on the llvm-commits list.

> Add the option to lookup an address in the debug information and print
> out the file, function, block and line table details.
>
> Differential revision: https://reviews.llvm.org/D38409

This also reverts the follow-up r314818:

> [test] Fix llvm-dwarfdump/cmdline.test
>
> Fixes test/tools/llvm-dwarfdump/cmdline.test

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314825 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-03 18:39:13 +00:00
Jonas Devlieghere
05dde13ff8 [dwarfdump] Add -lookup option
Add the option to lookup an address in the debug information and print
out the file, function, block and line table details.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314817 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-03 17:10:21 +00:00
Adrian Prantl
706e8dc44c llvm-dwarfdump: support the --ignore-case option.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314723 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-02 21:21:09 +00:00
Jonas Devlieghere
5295aa52c1 [dwarfdump] Add -show-form
This enables printing of DWARF form types after the DWARF attribute
types.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314685 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-02 16:02:04 +00:00
Adrian Prantl
9721275d8d typos
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314577 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-30 00:31:15 +00:00
Adrian Prantl
7de891a778 llvm-dwarfdump: implement the --name lookup option.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314576 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-30 00:22:25 +00:00
Adrian Prantl
9fda176b0e Add comments
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314574 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-30 00:22:21 +00:00
Adrian Prantl
547ff0af11 llvm-dwarfdump: support .apple-namespaces in --find
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314481 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-29 00:52:33 +00:00
Adrian Prantl
4d5765b0a5 llvm-dwarfdump: add support for .apple_types in --find
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314479 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-29 00:33:22 +00:00
Adrian Prantl
2f5de20dc0 try and appease gcc
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314442 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-28 18:27:00 +00:00
Adrian Prantl
81f2386de4 llvm-dwarfdump: implement --find for .apple_names
This patch implements the dwarfdump option --find=<name>.  This option
looks for a DIE in the accelerator tables and dumps it if found.  This
initial patch only adds support for .apple_names to keep the review
small, adding the other sections and pubnames support should be
trivial though.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314439 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-28 18:10:52 +00:00
Reid Kleckner
1fe9675efd Commit missing fixes for tool_file_rename
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314051 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-23 01:04:42 +00:00
Jonas Devlieghere
fe5f8bde97 [dwarfdump] Fix ambiguous call to make_unique
Fix buildbot failures:
 - http://lab.llvm.org:8011/builders/lldb-x86-windows-msvc2015/builds/13153
 - http://lab.llvm.org:8011/builders/lld-x86_64-win7/builds/13566

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313971 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-22 09:38:52 +00:00
Jonas Devlieghere
7080e068b5 [dwarfdump] Add support for redirecting output to a file
This patch adds the -o and --out-file options for compatibility with
Darwin's dwarfdump.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313969 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-22 09:20:57 +00:00
Adrian Prantl
ab669421b2 llvm-dwarfdump: Add support for the --arch command line option.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313888 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-21 16:26:18 +00:00
Adrian Prantl
ff00c9c5ca llvm-dwarfdump: move -eh-frame into the right section in the help output.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313836 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-20 23:29:31 +00:00
Adrian Prantl
ae599aa1b4 llvm-dwarfdump: implement --recurse-depth=<N>
This patch implements the Darwin dwarfdump option --recurse-depth=<N>,
which limits the recursion depth when selectively printing DIEs at an
offset.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313778 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-20 17:44:00 +00:00
Adrian Prantl
fd65d0d80e llvm-dwarfdump: un-hide more command line options
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313673 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-19 20:58:57 +00:00
Adrian Prantl
47842dcdbe Replace for_each with a range-based for. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313578 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-18 22:11:33 +00:00
Adrian Prantl
8233b30822 llvm-dwarfdump: add a --show-parents options when selectively dumping DIEs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313567 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-18 21:27:44 +00:00
Jonas Devlieghere
6ad4356f4d [dwarfdump] Make .eh_frame an alias for .debug_frame
This patch makes the `.eh_frame` extension an alias for `.debug_frame`.
Up till now it was only possible to dump the section using objdump, but
not with dwarfdump. Since the two are essentially interchangeable, we
dump whichever of the two is present.

As a workaround, this patch also adds parsing for 3 currently
unimplemented CFA instructions: `DW_CFA_def_cfa_expression`,
`DW_CFA_expression`, and `DW_CFA_val_expression`. Because I lack the
required knowledge, I just parse the fields without actually creating
the instructions.

Finally, this also fixes the typo in the `.debug_frame` section name
which incorrectly contained a trailing `s`.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313530 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-18 14:15:57 +00:00
Adrian Prantl
d4e3753582 llvm-dwarfdump: support a --show-children option
This will print all children of a DIE when selectively printing only
one DIE at a given offset.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313464 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-16 17:28:00 +00:00
Adrian Prantl
b311e92f13 llvm-dwarfdump: Add support for -debug-info=<offset>.
This is the first of many commits that enable selectively dumping just
one record from the debug info.

This reapplies r313412 with some extra qualification to appease GCC and MSVC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313419 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-15 23:04:04 +00:00
Adrian Prantl
ba583516b4 Revert "llvm-dwarfdump: Add support for -debug-info=<offset>."
This reverts commit r313412 because of a g++ incompatibility.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313413 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-15 22:47:16 +00:00
Adrian Prantl
e11a1f2d13 llvm-dwarfdump: Add support for -debug-info=<offset>.
This is the first of many commits that enable selectively dumping just
one record from the debug info.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313412 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-15 22:37:56 +00:00
Adrian Prantl
7c649ac2c9 llvm-dwarfdump: support dumping static archives.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313272 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-14 17:01:53 +00:00
Adrian Prantl
1c29e7f5eb Use MemoryBufferRef. (NFC)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313212 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-13 23:16:13 +00:00
Adrian Prantl
d368c61fa5 Factor out duplicate code from llvm-dwarfdump (NFC)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313211 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-13 23:07:24 +00:00
Adrian Prantl
494372f27e llvm-dwarfdump: automatically dump both regular and .dwo variant of sections
Since users typically don't really care about the .dwo / non.dwo
distinction, this patch makes it so dwarfdump --debug-<info,...> dumps
.debug_info and (if available) also .debug_info.dwo. This simplifies
the command line interface (I've removed all dwo-specific dump
options) and makes the tool friendlier to use.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313207 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-13 22:09:01 +00:00
Adrian Prantl
7ff141c202 llvm-dwarfdump: support dumping UUIDs of Mach-O binaries.
This is a feature supported by Darwin dwarfdump. UUIDs are used to
associate executables with their .dSYM bundles.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313165 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-13 18:22:59 +00:00