Commit Graph

1011 Commits

Author SHA1 Message Date
Kazu Hirata 7a47ee51a1 [llvm] Don't use Optional::getValue (NFC) 2022-06-20 22:45:45 -07:00
Kazu Hirata 064a08cd95 Don't use Optional::hasValue (NFC) 2022-06-20 20:05:16 -07:00
Kazu Hirata e0e687a615 [llvm] Don't use Optional::hasValue (NFC) 2022-06-20 10:38:12 -07:00
Kazu Hirata 129b531c9c [llvm] Use value_or instead of getValueOr (NFC) 2022-06-18 23:07:11 -07:00
Felipe de Azevedo Piovezan c20381b226 llvm-dwarf-dump: include type name for AT_containing_type
Type attributes are currently printed as:
  DW_AT_type    (<address> "<name>")
For example:
  DW_AT_type    (0x00000086 "double")

However, containing_type attributes omit the name, for example:
  DW_AT_containing_type    (0x00000086)

In order to make the dwarf dumps easier to read, and to have consistency
between the type-like attributes, this commit changes the way
DW_AT_containing_type is printed so that it includes the name of the
type it refers to:
  DW_AT_containing_type    (0x00000086 "double")

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D127078
2022-06-18 00:52:34 +00:00
David Blaikie 61fac2c370 Incomplete attempt to pull DWARFTypePrinter into its own file for reuse
from lldb
2022-06-16 22:28:28 +00:00
Florian Mayer a2695c3fe1 [DWARF] Support 'G' in dwarf parser
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D127171
2022-06-08 14:27:51 -07:00
Florian Mayer 0d54a874ee Revert "[DWARF] Support 'G' in dwarf parser"
This reverts commit 4c71c3386c.
2022-06-08 13:53:00 -07:00
Florian Mayer 4c71c3386c [DWARF] Support 'G' in dwarf parser
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D127171
2022-06-08 12:39:53 -07:00
Florian Mayer f60875254b [DWARF] Show which augmentation character was unrecognized.
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D127003
2022-06-03 15:35:33 -07:00
Krzysztof Parzyszek 23bb550eeb DWARFVerifier: Change vector of IntervalMap to vector of unique_ptrs
This is a workaround for compilation issue on FreeBSD. See comments in
https://reviews.llvm.org/rG0d8cb8b399ad for more information.

This fixes https://github.com/llvm/llvm-project/issues/55414.

Differential Revision: https://reviews.llvm.org/D125611
2022-05-25 10:59:46 -07:00
Hyoun Kyu Cho 6c12ae8163 Exposes interface to free up caching data structure in DWARFDebugLine and DWARFUnit for memory management
This is minimum changes extracted from https://reviews.llvm.org/D78950. The old patch tried to add LRU eviction of caching data structure. Due to multiple layers of interfaces that users could be using, it was not clear where to put the functionality. While we work out on where to put that functionality, it'll be great to add this minimum interface change so that the user could implement their own memory management. More specifically:

* Add a clearLineTable method for DWARFDebugLine which erases the given offset from the LineTableMap.
* DWARFDebugContext adds the clearLineTableForUnit method that leverages clearLineTable to remove the object corresponding to a given compile unit, for memory management purposes. When it is referred to again, the line table object will be repopulated.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D90006
2022-05-24 03:23:24 +00:00
Mitch Phillips cead4eceb0 [symbolizer] Parse DW_TAG_variable DIs to show line info for globals
Currently, llvm-symbolizer doesn't like to parse .debug_info in order to
show the line info for global variables. addr2line does this. In the
future, I'm looking to migrate AddressSanitizer off of internal metadata
over to using debuginfo, and this is predicated on being able to get the
line info for global variables.

This patch adds the requisite support for getting the line info from the
.debug_info section for symbolizing global variables. This only happens
when you ask for a global variable to be symbolized as data.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D123538
2022-05-23 13:30:22 -07:00
David Blaikie 0d8cb8b399 DWARFVerifier: Verify CU/TU index overlap issues
Discovered in a large object that would need a 64 bit index (but the
cu/tu index format doesn't include a 64 bit offset/length mode in
DWARF64 - a spec bug) but instead binutils dwp overflowed the offsets
causing overlapping regions.
2022-05-05 18:18:53 +00:00
Junfeng Dong a0fb387941 [DebugInfo] Give warning instead of error for premature terminator in .debug_aranges section.
llvm-profgen gives error message when the input binary contains premature terminator in .debug_aranges section. These zero length items point to some rodata with zero size type in embed Rust Library. Considering Zero-Sized Types are a valid feature in Rust. They are not real error. This change makes the "error:" message into a warning to avoid misleading.

Why do we still want a warning on such case? because it doesn't follow dwarf standard.  https://bugs.llvm.org/show_bug.cgi?id=46805 contains early discussion.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D124121
2022-05-04 15:21:58 -07:00
David Blaikie 727c590fe9 DebugInfo: Use hash-based unit lookup when available in dwp files
Fix a test case that had a bogus (probably I hand crafted it at some
point) index that didn't point to the right data in the process.
2022-04-27 21:18:14 +00:00
David Blaikie 6b306233f7 DebugInfo: Make the simplified template names prefix more unique 2022-04-06 18:25:46 +00:00
Argyrios Kyrtzidis 330268ba34 [Support/Hash functions] Change the `final()` and `result()` of the hashing functions to return an array of bytes
Returning `std::array<uint8_t, N>` is better ergonomics for the hashing functions usage, instead of a `StringRef`:

* When returning `StringRef`, client code is "jumping through hoops" to do string manipulations instead of dealing with fixed array of bytes directly, which is more natural
* Returning `std::array<uint8_t, N>` avoids the need for the hasher classes to keep a field just for the purpose of wrapping it and returning it as a `StringRef`

As part of this patch also:

* Introduce `TruncatedBLAKE3` which is useful for using BLAKE3 as the hasher type for `HashBuilder` with non-default hash sizes.
* Make `MD5Result` inherit from `std::array<uint8_t, 16>` which improves & simplifies its API.

Differential Revision: https://reviews.llvm.org/D123100
2022-04-05 21:38:06 -07:00
David Blaikie bb3980ae9f DebugInfo: Don't use enumerators in template names for debug info as they are not canonical
Since enumerators may not be available in every translation unit they
can't be reliably used to name entities. (this also makes simplified
template name roundtripping infeasible - since the expected name could
only be rebuilt if the enumeration definition could be found (or only if
it couldn't be found, depending on the context of the original name))
2022-04-05 17:16:42 +00:00
David Blaikie 4841dab4af llvm-dwarfdump: Including calling convention attribute in pretty printed type names 2022-03-22 19:19:54 +00:00
David Blaikie a3095a25d0 DebugInfo: Simplify const/volatile printing for function types 2022-03-22 19:19:54 +00:00
serge-sans-paille eb4c860811 Cleanup llvm/DebugInfo/PDB headers
accumulated preprocessed size:
before: 1065515095
after: 1065629059

Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup
Differential Revision: https://reviews.llvm.org/D120195
2022-02-23 10:31:34 +01:00
David Blaikie d7c4f7f147 DebugInfo: fix a couple of spurious spaces in simplified template name rebuilding 2022-02-16 11:33:41 -08:00
serge-sans-paille 290e482342 Cleanup LLVMDWARFDebugInfo
As usual with that header cleanup series, some implicit dependencies now need to
be explicit:

llvm/DebugInfo/DWARF/DWARFContext.h no longer includes:
- "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
- "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
- "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
- "llvm/DebugInfo/DWARF/DWARFDebugAranges.h"
- "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
- "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
- "llvm/DebugInfo/DWARF/DWARFDebugMacro.h"
- "llvm/DebugInfo/DWARF/DWARFGdbIndex.h"
- "llvm/DebugInfo/DWARF/DWARFSection.h"
- "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
- "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"

Plus llvm/Support/Errc.h not included by a bunch of llvm/DebugInfo/DWARF/DWARF*.h files

Preprocessed lines to build llvm on my setup:
after: 1065629059
before: 1066621848

Which is a great diff!

Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup
Differential Revision: https://reviews.llvm.org/D119723
2022-02-15 09:16:03 +01:00
serge-sans-paille e72c195fdc Cleanup LLVMObject headers
Most notably,

llvm/Object/Binary.h no longer includes llvm/Support/MemoryBuffer.h
llvm/Object/MachOUniversal*.h no longer include llvm/Object/Archive.h
llvm/Object/TapiUniversal.h no longer includes llvm/Object/TapiFile.h

llvm-project preprocessed size:
before: 1068185081
after:  1068324320

Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup
Differential Revision: https://reviews.llvm.org/D119457
2022-02-10 21:13:44 +01:00
Sylvestre Ledru f2c2e924e7 Fix a typo (occured => occurred)
Reported:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1005195
2022-02-08 21:35:26 +01:00
Alexey Lapshin 713c2b47a0 [DebugInfo][DWARF][NFC] Refactor DWARFTypePrinter usages. Create functions to print type dies.
This patch creates functions which might be used to dump types.
This functionality was already implemented by  DWARFTypePrinter.
Now it could be reused. It will help D96035, which uses DWARFTypePrinter.

Differential Revision: https://reviews.llvm.org/D117134
2022-01-14 16:19:08 +03:00
Kazu Hirata 2aed08131d [llvm] Use true/false instead of 1/0 (NFC)
Identified with modernize-use-bool-literals.
2022-01-07 00:39:14 -08:00
David Blaikie 811b60f0b9 llvm-dwarfdump: Speed up type unit lookup using the TUIndex or a cache
Use the TUIndex in a DWP file if present, otherwise (in .o, .dwo, and
non-split linked executables) cache a DenseMap for lookup of type units.
2022-01-05 20:41:07 -08:00
David Blaikie 33529ba0cb llvm-dwarfdump --summarize-types: skip compilation units
Important for DWARFv5 debug info which might contain type units in the
debug_info section, which made summarize-types fairly ineffective/lost
amongst the noise of CUs being dumped.
2022-01-05 20:36:04 -08: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
Luís Ferreira 34435fd105 [llvm] Add support for DW_TAG_immutable_type
Added documentation about DW_TAG_immutable_type too.

Reviewed By: probinson

Differential Revision: https://reviews.llvm.org/D113633
2022-01-05 19:17:08 +00:00
David Blaikie 9e45f2c308 Couple of post-commit tweaks on 4d58d1d5af based on maskray's feedback 2021-12-29 16:45:00 -08:00
David Blaikie 09f43c107f DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
David Blaikie 6edc38935a DWARFDie: don't try to compute a full template name for a template parameter packs
Otherwise these look a lot like actual templates (they have a name and
they have template parameters) but they don't participate in naming
(this doesn't come up in practice because a template parameter pack DIE
is never referenced from another DIE (so we don't do full name
rebuilding for it) or the subject of simplified template name rebuilding
(never has the _STN prefix)) - it could be tested with some hand crafted
DWARF but doesn't seem important/useful to do so.

This change is just for performance - to avoid trying to parse more
DIEs, etc, when it's not needed when computing the name in the DWARF
verifier.
2021-12-29 14:04:38 -08:00
David Blaikie 4d58d1d5af DWARFVerifier: Print the CU name and CU count to help visualize progress 2021-12-29 14:02:05 -08:00
David Blaikie f24dff357b DWARFVerifier: Delay loading nested types in type dumping to improve performance
Avoid trying to resolve nested types that may not be needed because the name is
already provided by the outer DIE.
2021-12-29 13:12:47 -08:00
Kazu Hirata 0542d15211 Remove redundant string initialization (NFC)
Identified with readability-redundant-string-init.
2021-12-26 09:39:26 -08:00
Kazu Hirata 2d303e6781 Remove redundant return and continue statements (NFC)
Identified with readability-redundant-control-flow.
2021-12-24 23:17:54 -08:00
Kazu Hirata 9c0a4227a9 Use Optional::getValueOr (NFC) 2021-12-24 20:57:40 -08:00
Simon Pilgrim 3b5572a18b Fix MSVC shadow variable warning. NFC. 2021-12-17 17:31:39 +00: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 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
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 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 71e5488a19 DebugInfo: Migrate callers from getAsCString to dwarf::toString
This makes a bunch of these call sites independent of a follow-up change
I'm making to have getAsCString return Expected<const char*> for more
descriptive error messages so that the failures there can be
communicated up to DWARFVerifier (or other callers who want to provide
more verbose diagnostics) so DWARFVerifier doesn't have to re-implement
the string lookup logic and error checking.
2021-12-14 14:50:43 -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
David Blaikie 3f3680dff3 DWARFVerifier: Simplify name lookups
No need to use the dynamic fallback query when the name type is known
statically at the call site.
2021-11-19 12:31:27 -08:00