Commit Graph

401 Commits

Author SHA1 Message Date
David Blaikie d7c4f7f147 DebugInfo: fix a couple of spurious spaces in simplified template name rebuilding 2022-02-16 11:33:41 -08:00
Jay Foad 013116cd70 Use {LITERAL} instead of regex escaping in some lit tests. NFC. 2022-01-14 10:55:00 +00:00
David Blaikie 06c154602e DebugInfo: Rebuild varargs function types correctly
Improves llvm-dwarfdump output and for simplified template names roundtripping.
2022-01-05 20:29:29 -08:00
David Blaikie 09f43c107f DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
David Blaikie 4f60a42878 DWARFVerifier: Skip resolution failures for locations in dwo files
When reading location lists in dwo files the addresses cannot be
resolved, but that's not a problem.

Long term this probably should be fixed with a different API that
exposes location expressions without the need to resolve the address
ranges, since that's all the verifier (in its current state) requires.
(though the verifier should probably also eventually verify the address
ranges in location lists are a subset of the enclosing scope's address
range)
2021-12-16 22:24:32 -08:00
David Blaikie e5c3b97116 DWARFVerifier: Test failures to parse DW_AT_locations 2021-12-16 22:24:32 -08:00
David Blaikie 2444e305c5 DWARFVerifier: Cleanup a test, remove redundant abbreviation 2021-12-16 20:34:52 -08:00
David Blaikie 8f6d52c8db DWARFVerifier: Don't error on missing ranges in Split DWARF
When verifying dwo files address ranges won't be able to be resolved due
to missing debug_addr (or missing debug_ranges in the case of DWARFv4
Split DWARF).
2021-12-16 20:34:44 -08:00
David Blaikie ae6961d407 DWARFVerifier: Don't try to resolve decl_file in split CUs
Since they refer to the debug_line in the skeleton unit, they can't be
resolved from the dwo CU.

But they can be resolved for split TUs, since those refer to
.debug_line.dwo, which is available in the dwo file.
2021-12-16 18:12:52 -08:00
Ellis Hoag ea5ba47407 [dSYM][NFC] Add error test case for llvm-dwarfdump
Add a test to `llvm-dwarfdump` to simply test that the error messages
make sense when passing bad `.dSYM`s.

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D115889
2021-12-16 15:23:18 -08:00
David Blaikie eb12e61384 DebugInfoVerifier: Verify dwo units
Initial pass - follow-up patches to address various limitations (debug
ranges, location lists... )
2021-12-16 14:47:22 -08:00
David Blaikie 51776ecaff DebugInfo: Fix test to match comment
This produced a few verifier warnings that came up while I was
investigating something else here. Change the assembly to match the
comment so it's warning free. Doesn't seem necessary to change the
CHECKs for the test since it's just a bug in the test, not in the code
under test.
2021-12-14 16:03:34 -08:00
David Blaikie 92f2d02b4a DebugInfo: Sink string form validation down from verifier to form parsing
Avoid duplicating the string decoding - improve the error messages down
in form parsing (& produce an Expected<const char*> instead of
Optional<const char*> to communicate the extra error details)
2021-12-14 15:41:53 -08:00
David Blaikie 892742907f DWARFVerifier: Verbosely dump DIEs in verifier reports
Seems helpful when you're dealing with invalid/problematic DWARF. Some
diagnostic messages are probably redundant with the verbose dumping and
could be simplified with this.
2021-12-13 19:00:38 -08:00
Kristina Bessonova 0bf2c87785 [llvm-dwarfdump] Do not print preceding :: for local types
Reviewed By: dblaikie, jhenderson

Differential Revision: https://reviews.llvm.org/D114892
2021-12-03 12:27:29 +02:00
David Blaikie cd93ab8947 DWARFVerifier: Don't parse all units twice
Introduced/discussed in https://reviews.llvm.org/D38719

The header validation logic was also explicitly building the DWARFUnits
to validate. But then other calls, like "Units.getUnitForOffset" creates
the DWARFUnits again in the DWARFContext proper - so, let's avoid
creating the DWARFUnits twice by walking the DWARFContext's units rather
than building a new list explicitly.

This does reduce some verifier power - it means that any unit with a
header parsing failure won't get further validation, whereas the
verifier-created units were getting some further validation despite
invalid headers. I don't think this is a great loss/seems "right" in
some ways to me that if the header's invalid we should stop there.

Exposing the raw DWARFUnitVectors from DWARFContext feels a bit
sub-optimal, but gave simple access to the getUnitForOffset to keep the
rest of the code fairly similar.
2021-11-24 14:03:56 -08:00
Djordje Todorovic e3d8ebe158 [llvm-dwarfdump][Statistics] Handle LTO cases with cross CU referencing
With link-time optimizations enabled, resulting DWARF mayend up containing
cross CU references (through the DW_AT_abstract_origin attribute).
Consider the following example:

// sum.c
__attribute__((always_inline)) int sum(int a, int b)
{
     return a + b;
}
// main.c
extern int sum(int, int);
int main()
{
     int a = 5, b = 10, c = sum(a, b);
     return 0;
}

Compiled as follows:

$ clang -g -flto -fuse-ld=lld main.c sum.c -o main

Results in the following DWARF:

-- sum.c CU: abstract instance tree
...
0x000000b0:   DW_TAG_subprogram
                DW_AT_name	("sum")
                DW_AT_decl_file	("sum.c")
                DW_AT_decl_line	(1)
                DW_AT_prototyped	(true)
                DW_AT_type	(0x000000d3 "int")
                DW_AT_external	(true)
                DW_AT_inline	(DW_INL_inlined)

0x000000bc:     DW_TAG_formal_parameter
                  DW_AT_name	("a")
                  DW_AT_decl_file	("sum.c")
                  DW_AT_decl_line	(1)
                  DW_AT_type	(0x000000d3 "int")

0x000000c7:     DW_TAG_formal_parameter
                  DW_AT_name	("b")
                  DW_AT_decl_file	("sum.c")
                  DW_AT_decl_line	(1)
                  DW_AT_type	(0x000000d3 "int")
...
-- main.c CU: concrete inlined instance tree
...
0x0000006d:     DW_TAG_inlined_subroutine
                  DW_AT_abstract_origin	(0x00000000000000b0 "sum")
                  DW_AT_low_pc	(0x00000000002016ef)
                  DW_AT_high_pc	(0x00000000002016f1)
                  DW_AT_call_file	("main.c")
                  DW_AT_call_line	(5)
                  DW_AT_call_column	(0x19)

0x00000081:       DW_TAG_formal_parameter
                    DW_AT_location	(DW_OP_reg0 RAX)
                    DW_AT_abstract_origin	(0x00000000000000bc "a")

0x00000088:       DW_TAG_formal_parameter
                    DW_AT_location	(DW_OP_reg2 RCX)
                    DW_AT_abstract_origin	(0x00000000000000c7 "b")
...

Note that each entry within the concrete inlined instance tree in
the main.c CU has a DW_AT_abstract_origin attribute which
refers to a corresponding entry within the abstract instance
tree in the sum.c CU.
llvm-dwarfdump --statistics did not properly report
DW_TAG_formal_parameters/DW_TAG_variables from concrete inlined
instance trees which had 0% location coverage and which
referred to a different CU, mainly because information about abstract
instance trees and their parameters/variables was stored
locally - just for the currently processed CU,
rather than globally - for all CUs.
In particular, if the concrete inlined instance tree from
the example above was to look like this
(i.e. parameter b has 0% location coverage, hence why it's missing):

0x0000006d:     DW_TAG_inlined_subroutine
                  DW_AT_abstract_origin	(0x00000000000000b0 "sum")
                  DW_AT_low_pc	(0x00000000002016ef)
                  DW_AT_high_pc	(0x00000000002016f1)
                  DW_AT_call_file	("main.c")
                  DW_AT_call_line	(5)
                  DW_AT_call_column	(0x19)

0x00000081:       DW_TAG_formal_parameter
                    DW_AT_location	(DW_OP_reg0 RAX)
                    DW_AT_abstract_origin	(0x00000000000000bc "a")

llvm-dwarfdump --statistics would have not reported b as such.

Patch by Dimitrije Milosevic.

Differential revision: https://reviews.llvm.org/D113465
2021-11-24 13:50:47 +01:00
David Blaikie 3cbc4c487a llvm-dwarfdump: Rebuild type names in dwo type units 2021-11-18 14:12:48 -08:00
David Blaikie 58b1b6414b llvm-dwarfdump: Lookup type units when prettyprinting types
This handles DWARFv4 and DWARFv5 type units, but not Split DWARF type
units. That'll come in a follow-up patch.
2021-11-09 16:58:22 -08:00
Alexey Lapshin c8ae08987d [llvm-dwarfdump] dump link to the immediate parent.
It is often useful to know which die is the parent of the current die.
This patch adds information about parent offset into the dump:

0x0000000b: DW_TAG_compile_unit
              DW_AT_producer    ("by_hand")

0x00000014:   DW_TAG_base_type (0x0000000b)  <<<<<<<<<<<<<<
                DW_AT_name      ("int")

Now it is easy to see which die is the parent of the current die.
This patch makes that behaviour to be default.
We can make it to be opt-in if neccessary.

This functionality differs from already existed "--show-parents"
in that sence that parent information is shown for all dies and
only link to the immediate parent is shown.

Differential Revision: https://reviews.llvm.org/D113406
2021-11-09 14:14:06 +03:00
David Blaikie 0a5c26f2ef DebugInfo: Simplified Template Names: drop unneeded space in arrays
Matching a recent clang change I've made, now 'int[3]' is formatted
without the space between the type and array bound. This commit updates
libDebugInfoDWARF/llvm-dwarfdump to match that formatting.
2021-11-05 22:50:57 -07:00
David Blaikie f57d0e2726 DWARF Simplified Template Names: Narrow down the handling for operator overloads
Actually we can, for now, remove the explicit "operator" handling
entirely - since clang currently won't try to flag any of these as
rebuildable. That seems like a reasonable state for now, but it could be
narrowed down to only apply to conversion operators, most likely - but
would need more nuance for op> and op>> since they would be incorrectly
flagged as already having their template arguments (due to the trailing
'>').
2021-11-05 15:41:56 -07:00
David Blaikie b65f24a74c llvm-dwarfdump --verify: Don't diagnose functions in different sections as overlapping
Functions in different sections (common in object files - inline
functions, -ffunction-sections, etc) can't overlap, so factor in the
section when diagnosing overlapping address ranges.

This removes a major false-positive when running llvm-dwarfdump on
unlinked code.
2021-10-28 17:13:57 -07:00
Djordje Todorovic 40c2bdf6d1 [llvm-locstats] Move the test from D110621 into test/llvm-locstats/ dir 2021-10-27 17:36:19 +02:00
djtodoro 30a3652b6a [llvm-locstats] Report a warning if overflow was detected by llvm-dwarfdump
Catch that llvm-dwarfdump detected an overflow in statistics.

Differential Revision: https://reviews.llvm.org/D110621
2021-10-27 14:35:29 +02:00
David Blaikie 3ac709b6ce llvm-dwarfdump --verify: Exit non-zero on simplified template name rebuilding failures 2021-10-26 15:57:16 -07:00
Jack Anderson d7733f8422 [DebugInfo] Expand ability to load 2-byte addresses in dwarf sections
Some dwarf loaders in LLVM are hard-coded to only accept 4-byte and 8-byte address sizes. This patch generalizes acceptance into `DWARFContext::isAddressSizeSupported` and provides a common way to generate rejection errors.

The MSP430 target has been given new tests to cover dwarf loading cases that previously failed due to 2-byte addresses.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D111953
2021-10-21 17:31:00 -07:00
djtodoro c450e47a8c [llvm-dwarfdump] Fix unsigned overflow when calculating stats
This fixes https://bugs.llvm.org/show_bug.cgi?id=51652.

The idea is to bump all the stat fields to 64-bit wide
unsigned integers. I've confirmed this resolves
the use case for chromium.

Differential Revision: https://reviews.llvm.org/D109217
2021-10-15 12:15:58 +02:00
David Blaikie 9911af4b91 WIP: Verify -gsimple-template-names=mangled values
Clang will encode names that should be able to be simplified as
"_STNname|<template, args>" (eg: "_STNt1|<int>") - this verification
mode will detect these names, decode them, create the original name
("t1<int>") and the simple name ("t1") - letting the simple name run
through the usual rebuilding logic - then compare the two sources of the
full name - the rebuilt and the _STN encoding.

This helps ensure that -gsimple-template-names is lossless.
2021-09-24 14:28:18 -07:00
David Blaikie 49c519a848 DebugInfo: Rebuild decltype(nullptr) as 'std::nullptr_t'
Now that Clang's been changed to render nullptr types/template
parameters as 'std::nullptr_t' do the same thing down here.

(Clang commit: 131e878664 )
2021-09-21 11:37:30 -07:00
Paul Robinson fa822a2ee5 [DebugInfo] Add test for dumping DW_AT_defaulted 2021-09-20 16:43:53 -04:00
David Blaikie cb42bb3550 llvm-dwarfdump: pretty type printing: print fully qualified names in function type parameter types 2021-09-19 18:49:15 -07:00
David Blaikie 606ea0dd2a llvm-dwarfdump: support for type printing "decltype(nullptr)" as "nullptr_t"
This should probably be rendered as "std::nullptr_t" but for now clang
uses the unqualified name (which is ambiguous with possible user defined
name in the global namespace), so match that here.
2021-09-19 17:33:56 -07:00
David Blaikie 11e0b79b05 llvm-dwarfdump: Don't print even an empty string when a type is unprintable 2021-09-19 17:03:10 -07:00
David Blaikie 5bfe5207ef llvm-dwarfdump: Pretty print names qualified/with scopes 2021-09-19 16:36:01 -07:00
David Blaikie 372e2c24b6 llvm-dwarfdump: Pretty printing types including a space between const and parenthesized references/pointers to arrays 2021-09-19 13:32:53 -07:00
David Blaikie f09ca5c646 DWARFDie: Improve type printing for function and array types - with qualifiers (cv/reference) and pointers to them 2021-09-19 12:59:31 -07:00
David Blaikie 2ca637c976 llvm-dwarfdump: Refactor type pretty printing tests
Move most type tests to a pre-generated assembly file to make it easier
to add more weird cases without having to hand craft more DWARF.

Move the novel array types that aren't reachable via clang-generated
DWARF to a separate file for easy maintenance.
2021-09-19 09:30:38 -07:00
Richard Smith 02fe58d628 DebugInfo: additional fix missed in bc066e2. 2021-09-03 15:28:00 -07:00
David Blaikie bc066e26c9 DebugInfo: Fix a few bot failures for type dumping fixes 2021-09-03 14:08:58 -07:00
David Blaikie 40f1593558 DebugInfo: Correct/improve type formatting (pointers to function types especially)
This does add some extra superfluous whitespace (eg: "int *") intended
to make the Simplified Template Names work easier - this makes the
DIE-based names match more exactly the clang-generated names, so it's
easier to identify cases that don't generate matching names.

(arguably we could change clang to skip that whitespace or add some
fuzzy matching to accommodate differences in certain whitespace - but
this seemed easier and fairly low-impact)
2021-09-03 12:22:28 -07:00
Alexey Lapshin 07d44cc0b1 [DWARF][Verifier] Do not add child DieRangeInfo with empty address range to the parent.
verifyDieRanges function checks for the intersected address ranges.
It adds child DieRangeInfo into parent DieRangeInfo to check
whether children have overlapping address ranges. It is safe to not add
DieRangeInfo with empty address range into parent's children list.
This decreases the number of children which should be navigated and as a result
decreases execution time(parents having a lot of children with empty ranges
spend much time navigating them). For this command: "llvm-dwarfdump --verify clang-repl"
execution time decreased from 220 sec till 75 sec.

Differential Revision: https://reviews.llvm.org/D107554
2021-08-22 19:39:21 +03:00
David Blaikie 44d0a99a12 Add missing triple for test 2021-08-15 12:32:12 -07:00
David Blaikie 62a4c2c10e DWARFVerifier: Check section-relative references at the end of the section
This ensures that debug_types references aren't looked for in
debug_info section.

Behavior is still going to be questionable in an unlinked object file -
since cross-cu references could refer to symbols in another .debug_info
(or, in theory, .debug_types) chunk - but if a producer only uses
ref_addr to refer to things within the same .debug_info chunk in an
object file (eg: whole program optimization/LTO - producing two CUs into
a single .debug_info section in an object file - the ref_addrs there
could be resolved relative to that .debug_info chunk, not needing to
consider comdat  (DWARFv5 type units or other creatures) chunks of
.debug_info, etc)
2021-08-15 11:40:24 -07:00
David Blaikie 2af4db7d5c Migrate DWARFVerifier tests to lit-based yaml instead of gtest with embedded yaml
Improves maintainability (edit/modify the tests without recompiling) and
error messages (previously the failure would be a gtest failure
mentioning nothing of the input or desired text) and the option to
improve tests with more checks.

(maybe these tests shouldn't all be in separate files - we could
probably have DWARF yaml that contains multiple errors while still being
fairly maintainable - the various invalid offsets (ref_addr, rnglists,
ranges, etc) could probably be all in one test, but for the simple sake
of the migration I just did the mechanical thing here)
2021-08-13 19:09:41 -07:00
Esme-Yi 14f6cfcf3c [Debug-Info][llvm-dwarfdump] Don't try to dump location
list for attributes that don't have the loclist class.

Summary: The overflow error occurs when we try to dump
location list for those attributes that do not have the
loclist class, like DW_AT_count and DW_AT_byte_size.
After re-reviewed the entire list, I sorted those
attributes into two parts, one for dumping location list
and one for dumping the location expression.

Reviewed By: probinson

Differential Revision: https://reviews.llvm.org/D105613
2021-07-27 07:28:59 +00:00
Fangrui Song c0da287c30 [yaml2obj][MachO] Rename PayloadString to Content
The new name is conciser and matches yaml2obj ELF & DWARF.

Reviewed By: #lld-macho, thakis

Differential Revision: https://reviews.llvm.org/D106759
2021-07-26 09:04:51 -07:00
David Blaikie ac8cedead8 Fix test - mistaken hardcoded path from my local machine. 2021-07-12 18:39:41 -07:00
David Blaikie ea91749f01 DebugInfo: Use debug_rnglists.dwo for ranges in debug_info.dwo when parsing DWARFv5
This call would incorrectly overwrite (with the .debug_rnglists.dwo from
the executable, if there was one) the rnglists section instead of the
correct value (from the .debug_rnglists.dwo in the .dwo file) that's
applied in DWARFUnit::tryExtractDIEsIfNeeded
2021-07-12 18:15:09 -07:00
Jan Kratochvil c19a28919f llvm-dwarfdump: Print warnings on invalid DWARF
llvm-dwarfdump was silent even when the format of DWARF was invalid
and/or llvm-dwarfdump did not understand/support some of the constructs.
This can be pretty confusing as llvm-dwarfdump is a tool for DWARF
producers+consumers development.

Review comments also by @dblaikie.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D104271
2021-06-27 11:38:35 +02:00