93 Commits

Author SHA1 Message Date
Kazu Hirata
36c78ec3c8
[DebugInfo] Use llvm::remove_if (NFC) (#149543)
We can pass a range to llvm::remove_if.
2025-07-18 13:32:49 -07:00
Kazu Hirata
c101415820
[DebugInfo] Remove an unnecessary cast (NFC) (#146217) 2025-06-28 13:03:38 -07:00
Sterling-Augustine
23f1ba3ee4
Reapply "[NFC][DebugInfo][DWARF] Create new low-level dwarf library (#… (#145959) (#146112)
Reapply "[NFC][DebugInfo][DWARF] Create new low-level dwarf library (#…
(#145959)
    
This reapplies cbf781f0bdf2f680abbe784faedeefd6f84c246e, with fixes for
the shared-library build and the unconventional sanitizer-runtime build.

Original Description:

This is the culmination of a series of changes described in [1].
    
Although somewhat large by line count, it is almost entirely mechanical,
creating a new library in DebugInfo/DWARF/LowLevel. This new library has
very minimal dependencies, allowing it to be used from more places than
the normal DebugInfo/DWARF library--in particular from MC.
    
1.
https://discourse.llvm.org/t/rfc-debuginfo-dwarf-refactor-into-to-lower-and-higher-level-libraries/86665/2
2025-06-27 11:05:49 -07:00
Sterling-Augustine
5d03e7a204
Revert "[NFC][DebugInfo][DWARF] Create new low-level dwarf library (#… (#145959)
…145081)"

This reverts commit cbf781f0bdf2f680abbe784faedeefd6f84c246e.

Breaks a couple of buildbots.
2025-06-26 13:09:20 -07:00
Sterling-Augustine
cbf781f0bd
[NFC][DebugInfo][DWARF] Create new low-level dwarf library (#145081)
This is the culmination of a series of changes described in [1].
    
Although somewhat large by line count, it is almost entirely mechanical,
creating a new library in DebugInfo/DWARF/LowLevel. This new library has
very minimal dependencies, allowing it to be used from more places than
the normal DebugInfo/DWARF library--in particular from MC.
    
I am happy to put it in another location, or to structure it differently
if that makes sense. Some have suggested in BinaryFormat, but it is not
a great fit there. But if that makes more sense to the reviewers, I can
do that.
 
Another possibility would be to use pass-through headers to allow
clients who don't care to depend only on DebugInfo/DWARF. This would be
a much less invasive change, and perhaps easier for clients. But also a
system that hides details.

Either way, I'm open.

1.
https://discourse.llvm.org/t/rfc-debuginfo-dwarf-refactor-into-to-lower-and-higher-level-libraries/86665/2
2025-06-26 11:23:46 -07:00
Carlos Alberto Enciso
8b7fc6487d
[llvm-debuginfo-analyzer] Fix crash with WebAssembly dead code (#141616)
https://github.com/llvm/llvm-project/issues/136772
Incorrect handling of 'tombstone' value for WebAssembly.

llvm-debuginfo-analyzer already uses the tombstone approach
to identify dead code. Currently, the tombstone value is
evaluated as std::numeric_limits<uint64_t>::max(). Which is
wrong as it does not take into account the 'Address Byte Size'
from the Compile Unit header.
2025-06-26 05:37:32 +01:00
Javier Lopez-Gomez
383b326879
[llvm-debuginfo-analyzer] Fix ODR violation in llvm::logicalview::LVObject (#140265)
Some data members are only part of a class definition in a Debug build,
e.g. `LVObject::ID`. If `debuginfologicalview` is used as a library,
`NDEBUG` cannot be used for this purpose, as this PP macro may have a
different definition in a downstream project, which in turn triggers an
ODR violation. Fix it by
- Making `LVObject::ID` an unconditional data member.
- Making `LVObject::dump()` non-virtual. Rationale: `virtual` is not
needed (and it calls `print()`, which is virtual anyway).

Fixes #139098.
2025-06-16 10:47:00 +02:00
Sterling-Augustine
474db6a852
[NFC] Separate high-level-dependent portions of DWARFExpression (revised) (#143170)
(Revised version of a previous, unreviewed, PR.)

Move all expression verification into its only client: DWARFVerifier.
Move all printing code (which was a mix of static and member functions)
into a separate class.

This is one in a series of refactoring PRs to separate dwarf
functionality into lower-level pieces usable without object files and
sections at build time. The code is already written this way via various
"if (section == nullptr)" and similar conditionals. So the functionality
itself is needed and exists, but only as a runtime feature. The goal of
these refactors is to remove the build-time dependencies, which will
allow the existing functionality to be used from lower-level parts of
the compiler. Particularly from lib/MC/.... More information at:


https://discourse.llvm.org/t/rfc-debuginfo-dwarf-refactor-into-to-lower-and-higher-level-libraries/86665
2025-06-09 16:32:40 -07:00
Javier Lopez-Gomez
0f38c54c6f
[llvm-debuginfo-analyzer] Add support for parsing DWARF / CodeView SourceLanguage (#137223)
This pull request adds support for parsing the source language in both
DWARF and CodeView. Specifically,

- The `LVSourceLanguage` class is introduced to represent any supported
language by any of the debug info representations.

- Update `LVDWARFReader.cpp` and `LVCodeViewVisitor.cpp` to parse the
source language where it applies. Added a new `=Language` attribute;
`getAttributeLanguage()` is internally used to control whether this
information is being printed.
2025-06-06 15:03:07 +01:00
Carlos Alberto Enciso
fef5096a8a
[llvm-debuginfo-analyzer][NFC] Move some functionality to LVReader. (#142740)
Hoist out from LVDWARFReader and LVBinaryReader some generic
code, so it can be available to other readers that do not share the
binary format.
2025-06-04 14:35:48 +01:00
Kazu Hirata
d77c995f14
[DebugInfo] Avoid creating a temporary instance of std::string (NFC) (#142523)
lookupTarget accepts StringRef.  We don't need to create a temporary
instance of std::string only to be converted back to StringRef.
2025-06-02 23:27:35 -07:00
Javier Lopez-Gomez
9cac4bf485
[llvm-debuginfo-analyzer] Add support for DWARF DW_AT_byte_size (#139110)
This PR was split from https://github.com/llvm/llvm-project/pull/137228
(which introduced support for `DW_TAG_module` and `DW_AT_byte_size`).

This PR improves `LVDWARFReader` by introducing handling of
`DW_AT_byte_size`. Most DWARF emitters include this attribute for types
to specify the size of an entity of the given type.
2025-05-22 14:20:40 +01:00
Javier Lopez-Gomez
cb575785b9
[llvm-debuginfo-analyzer] Support DW_TAG_module (#137228)
- Adds support for `DW_TAG_module` DIEs and recurse over their children.
Prior to this patch, entities hanging below `DW_TAG_module` were just
not visible. This DIE kind is commonly generated by Objective-C modules.

This patch will represent such entities, which will print as
```
[001]    {CompileUnit} '/llvm/tools/clang/test/modules/<stdin>'
[002]      {Producer} 'LLVM version 3.7.0'
           {Directory} '/llvm/tools/clang/test/modules'
           {File} '<stdin>'
[002]      {Module} 'DebugModule'
```
The minimal test case included is just the result of
```
$ llc llvm/test/DebugInfo/X86/DIModule.ll
      -accel-tables=Dwarf
      -o llvm/unittests/DebugInfo/LogicalView/Inputs/test-dwarf-clang-module.o
      -filetype=obj
```
2025-05-21 15:05:10 +01:00
Javier Lopez-Gomez
211ee04a61
[llvm-debuginfo-analyzer] Fix a couple of unhandled DWARF situations leading to a crash (#137221)
This pull request fixes a couple of unhandled situations in DWARF input
leading to a crash. Specifically,

- If the DWARF input contains a declaration of a C variadic function
(where `...` translates to `DW_TAG_unspecified_parameters`), which is
then followed by a definition, `llvm_unreachable()` is hit in
`LVScope::addMissingElements()`. This is only visible in Debug builds.

- Parsing of instructions in `LVBinaryReader::createInstructions()` does
not check whether `Offset` lies within the `Bytes` ArrayRef. A specially
crafted DWARF input can lead to this condition.
2025-05-21 05:29:41 +01:00
Kazu Hirata
ff78648b09
[llvm] Use llvm::find_if (NFC) (#140412) 2025-05-17 17:02:04 -07:00
Kazu Hirata
18ecff4f65
[llvm] Use llvm::stable_sort (NFC) (#140067) 2025-05-15 12:18:18 -07:00
Kazu Hirata
2422b1795f
[DebugInfo] Simplify a string comparison (NFC) (#139918)
Note that the lambda function we are in returns bool, so
FileZero.compare(FileOne) is equivalent to FileZero != FileOne in this
context.
2025-05-14 09:52:48 -07:00
Kazu Hirata
52fcb076c0
[llvm] Use llvm::transform (NFC) (#137532) 2025-04-27 12:32:12 -07:00
Kazu Hirata
8210cdd764
[llvm] Use llvm::replace (NFC) (#137481) 2025-04-26 18:18:09 -07:00
Kazu Hirata
c4e9901b5b
[llvm] Use llvm::append_range (NFC) (#135931) 2025-04-16 12:28:47 -07:00
Kazu Hirata
6257621f41
[llvm] Use llvm::append_range (NFC) (#133658) 2025-03-30 18:43:02 -07:00
Kazu Hirata
e49c8d5d3d
[DebugInfo] Avoid repeated map lookups (NFC) (#128826) 2025-02-26 00:56:03 -08:00
Kazu Hirata
38f8ca1d18
[DebugInfo] Avoid repeated hash lookups (NFC) (#128632) 2025-02-25 09:02:52 -08:00
Kazu Hirata
6ad55f1517
[DebugInfo] Avoid repeated hash lookups (NFC) (#128459) 2025-02-24 00:59:49 -08:00
Kazu Hirata
b0d1c51a17
[DebugInfo] Avoid repeated hash lookups (NFC) (#128395) 2025-02-23 01:03:22 -08:00
Kazu Hirata
94b810661a
[DebugInfo] Avoid repeated hash lookups (NFC) (#128301) 2025-02-22 02:13:02 -08:00
Kazu Hirata
f964377df7
[DebugInfo] Avoid repeated hash lookups (NFC) (#128127) 2025-02-21 11:07:51 -08:00
Kazu Hirata
fb14638817
[DebugInfo] Avoid repeated hash lookups (NFC) (#127446) 2025-02-17 01:32:25 -08:00
aurelien35
37e48e4a73
Fix crash due to un-checked error in LVReaderHandler::handleArchive method (#118951)
[llvm-debuginfo-analyzer] Fix crash due to un-checked error in LVReaderHandler::handleArchive
method.

- Added README describing how to generated the binary files used for the test.
- A follow up patch to add extra ASSERT_NE

Committed on behalf of @aurelien35
2024-12-17 11:19:48 +00:00
Carlos Alberto Enciso
c4fbb6500a
[llvm-debuginfo-analyzer] Add support for DW_AT_GNU_template_name. (#115724)
For the given C++ code:
```
  template <typename T> class Foo { T Member; };

  template <template <typename T> class TemplateType>
  class Bar {
    TemplateType<int> Int;
  };

  template <template <template <typename> class> class TemplateTemplateType>
  class Baz {
    TemplateTemplateType<Foo> Foo;
  };

  typedef Baz<Bar> Example;
  Example TT;
```
The '--attribute=encoded' option, will produce the logical view:
```
  {Class} 'Foo<int>'
    {Encoded} <int>
  {Class} 'Bar<Foo>'
    {Encoded} <>                 <-- Missing the template argument info (Foo)
  {Class} 'Baz<Bar>'
    {Encoded} <>                 <-- Missing the template argument info (Bar)
```
When the template argument is another template it is not included in the
{Encoded} field. The correct output should be:
```
  {Class} 'Foo<int>'
    {Encoded} <int>
  {Class} 'Bar<Foo>'
    {Encoded} <Foo>
  {Class} 'Baz<Bar>'
    {Encoded} <Bar>
```
2024-11-28 14:47:21 +00:00
Carlos Alberto Enciso
fb3765959f
[llvm-debuginfo-analyzer] Common handling of unsigned attribute values. (#116027)
- In the DWARF reader, for those attributes that can have an unsigned
value, allow for the following cases:
  * Is an implicit constant
  * Is an optional value
- The testing is done by creating a file with generated DWARF, using
`DwarfGenerator` (generate DWARF debug info for unit tests).
2024-11-28 05:21:47 +00:00
Kazu Hirata
0060c54e0d
[DebugInfo] Remove unused includes (NFC) (#116551)
Identified with misc-include-cleaner.
2024-11-17 10:37:33 -08:00
Carlos Alberto Enciso
5e7662efec
[llvm-debuginfo-analyzer] Incorrect DW_AT_call_line/DW_AT_call_file. (#115701)
The code dealing with DW_AT_call_line/DW_AT_call_file is in the wrong
place. The correct functions were call, but with incorrect values:
  DW_AT_call_line <-- Filename Index
  DW_AT_call_file <-- Line number
2024-11-11 13:00:24 +00:00
Carlos Alberto Enciso
a912c81f65
[llvm-debuginfo-analyzer] Fix crash with thread local storage. (#113904)
The DW_OP_GNU_push_tls_address, DW_OP_form_tls_address DWARF
location forms generated for thread local storage variables, caused a
crash in the DWARFReader, due to incorrect number of operands.
2024-11-11 05:31:59 +00:00
Kazu Hirata
5c9c281c25
[DebugInfo] Use heterogenous lookups with std::map (NFC) (#113118) 2024-10-21 06:50:03 -07:00
Kazu Hirata
8b6764fdc0
[DebugInfo] Simplify code with std::unordered_map::operator[] (NFC) (#112658) 2024-10-17 07:47:06 -07:00
Kazu Hirata
8a53dc69c2
[DebugInfo] Avoid repeated map lookups (NFC) (#111936) 2024-10-11 08:59:01 -07:00
Kazu Hirata
f01d45cf97
[DebugInfo] Avoid repeated hash lookups (NFC) (#110620) 2024-10-01 07:48:09 -07:00
Craig Topper
f2b71491d1
[MC] Make MCRegisterInfo::getLLVMRegNum return std::optional<MCRegister>. NFC (#107776) 2024-09-08 21:21:51 -07:00
Pavel Labath
d0d61a7e4c
Split DWARFFormValue::getReference into four functions (#98905)
The result of the function cannot be correctly interpreted without
knowing the precise form type (a type signature needs to be looked up
very differently from a supplementary debug info reference). The
function sort of worked because the two reference types (unit-relative
and section-relative) that can be handled uniformly are also the most
common types of references, but this setup made it easy to write code
which does not support other kinds of reference (and if one tried to
support them, the result didn't look pretty --
https://github.com/llvm/llvm-project/pull/97423/files#r1676217081).

The split is based on the reference type classification from DWARFv5
(Section 7.5.5 Classes and Forms), and it should enable uniform (if
slightly more verbose) hadling. Note that this only affects users which
want more control of how (or if) the references are resolved. Users
which just want to access the referenced DIE can use the higher level
API (DWARFDie::GetAttributeValueAsReferencedDie) which returns (or will
return after #97423 is merged) the correct die for all reference types
(except for supplementary references, which we don't support right now).
2024-07-16 12:55:38 +02:00
Kazu Hirata
026a29e8b3
[Analysis, CodeGen, DebugInfo] Use StringRef::operator== instead of StringRef::equals (NFC) (#91304)
I'm planning to remove StringRef::equals in favor of
StringRef::operator==.

- StringRef::operator==/!= outnumber StringRef::equals by a factor of
  53 under llvm/ in terms of their usage.

- The elimination of StringRef::equals brings StringRef closer to
  std::string_view, which has operator== but not equals.

- S == "foo" is more readable than S.equals("foo"), especially for
  !Long.Expression.equals("str") vs Long.Expression != "str".
2024-05-07 10:20:10 -07:00
Carlos Alberto Enciso
9c0c98ed37
[llvm-debuginfo-analyzer][DOC] Convert 'README.txt' to markdown. (#86394)
As part of the WebAssembly support work
https://github.com/llvm/llvm-project/pull/85566

The README.txt is a bit odd since it only lists issues and problems
without talking about what works. It’s also hard to read on the GitHub
web view.

- Convert to Markdown and linking to the command docs
https://llvm.org/docs/CommandGuide/llvm-debuginfo-analyzer
- Rename some left 'elf reader' to 'DWARF reader'.
2024-03-27 05:27:44 +00:00
Carlos Alberto Enciso
c1ccf0781b
[llvm-debuginfo-analyzer][NFC] Rename LVElfReader.cpp[h] (#85530)
As part of the WebAssembly support work review
  https://github.com/llvm/llvm-project/pull/82588

It was decided to rename:

  Files: LVElfReader.cpp[h] -> LVDWARFReader.cpp[h]
         ELFReaderTest.cpp  -> DWARFReaderTest.cpp

  Class: LVELFReader        -> LVDWARFReader

The name LVDWARFReader would match the another reader LVCodeViewReader
as they will reflect the type of
debug information format that they are parsing.
2024-03-18 05:08:42 +00:00
Carlos Alberto Enciso
b19cfb9175
[llvm-debuginfo-analyzer] Add support for WebAssembly binary format. (#82588)
Add support for the WebAssembly binary format and be able to generate
logical views.

https://github.com/llvm/llvm-project/issues/69181

The README.txt includes information about how to build the test cases.
2024-03-14 10:03:18 +00:00
Kazu Hirata
c6cfd5350e [llvm] Use StringRef::contains (NFC) 2024-01-19 00:19:36 -08:00
Simon Pilgrim
1950190b61 [DebugInfo] Use StringRef::starts_with/ends_with instead of startswith/endswith. NFC.
startswith/endswith wrap starts_with/ends_with and will eventually go away (to more closely match string_view)
2023-11-06 15:20:20 +00:00
Kazu Hirata
f9306f6de3
[ADT] Rename llvm::erase_value to llvm::erase (NFC) (#70156)
C++20 comes with std::erase to erase a value from std::vector.  This
patch renames llvm::erase_value to llvm::erase for consistency with
C++20.

We could make llvm::erase more similar to std::erase by having it
return the number of elements removed, but I'm not doing that for now
because nobody seems to care about that in our code base.

Since there are only 50 occurrences of erase_value in our code base,
this patch replaces all of them with llvm::erase and deprecates
llvm::erase_value.
2023-10-24 23:03:13 -07:00
Kazu Hirata
6e18003a23 [llvm] Use llvm::any_of (NFC) 2023-10-22 10:42:18 -07:00
Kazu Hirata
e5ef5b9e32 [DebugInfo] Use llvm::erase_value (NFC) 2023-10-20 23:45:15 -07:00
Kazu Hirata
dc271b59e9 [DebugInfo] Use llvm::erase_if (NFC) 2023-10-20 00:15:00 -07:00