summaryrefslogtreecommitdiff
path: root/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
AgeCommit message (Collapse)Author
2025-05-07[NFC][Support] Add llvm::uninitialized_copy (#138174)Rahul Joshi
Add `llvm::uninitialized_copy` that accepts a range instead of start/end iterator for the source of the copy.
2025-04-09Revert "Reland "Symbolize line zero as if no source info is available ↵Zequan Wu
(#124846)" (#133798)" This reverts commit 348374028970c956f2e49ab7553b495d7408ccd9 because #128619 doesn't handle the case when we have an empty frame from `getInliningInfoForAddress` because line num is 0 which makes it non-differentiable from missing debug info. So, we end up using the base filename from symtab again. Reverting for now until that issus is solved.
2025-03-31Reland "Symbolize line zero as if no source info is available (#124846)" ↵Zequan Wu
(#133798) This land commits 23aca2f88dd5d2447e69496c89c3ed42a56f9c31 and 1b15a89a23c631a8e2d096dad4afe456970572c0. https://github.com/llvm/llvm-project/pull/128619 makes symbolizer to always use debug info when available so we can reland this chagnge.
2025-02-24Revert "Symbolize line zero as if no source info is available (#124846)"Zequan Wu
This commit creates an inconsistency on `__sanitizer_symbolize_pc` API. Before this change, this API always uses the filename from debug info when the line number is 0. After this change, the filename becomes invalid when line number is 0. The sanitizer might fall back to use base filename from symbol table. So, this API may return either `??:0` or `{filename from symbol table}:0` depending on if the symbol table has the filename for it. Make sure this inconsistency is resolved before relanding the commit.
2025-02-07Use a stable sort to handle overlapping/duplicate line sequencesDavid Blaikie
This can occur due to linker ICF and stable sort will ensure the results are stable. No explicit/new test coverage, because nondeterminism is non-testable. It should already be covered by the DWARFDebugLineTest that was failing some internal testing on an ARM machine which might've been what changed the sort order. But `llvm::sort` also deliberately randomizes the contents (under EXPENSIVE_CHECKS) so I'd have expected failures to show up in any EXPENSIVE_CHECKS Build...
2025-02-06[DebugInfo][DWARF] Utilize DW_AT_LLVM_stmt_sequence attr in line table ↵alx32
lookups (#123391) **Summary** Add support for filtering line table entries based on `DW_AT_LLVM_stmt_sequence` attribute when looking up address ranges. This ensures that line entries are correctly attributed to their corresponding functions, even when multiple functions share the same address range due to optimizations. **Background** In https://github.com/llvm/llvm-project/pull/110192 we added support to clang to generate the `DW_AT_LLVM_stmt_sequence` attribute for `DW_TAG_subprogram`'s. Corresponding RFC: [New DWARF Attribute for Symbolication of Merged Functions](https://discourse.llvm.org/t/rfc-new-dwarf-attribute-for-symbolication-of-merged-functions/79434) The `DW_AT_LLVM_stmt_sequence` attribute allows accurate attribution of line number information to their corresponding functions, even in scenarios where functions are merged or share the same address space due to optimizations like Identical Code Folding (ICF) in the linker. **Implementation Details** The patch modifies `DWARFDebugLine::lookupAddressRange` to accept an optional DWARFDie parameter. When provided, the function checks if the `DIE` has a `DW_AT_LLVM_stmt_sequence` attribute. This attribute contains an offset into the line table that marks where the line entries for this DIE's function begin. If the attribute is present, the function filters the results to only include line entries from the sequence that starts at the specified offset. This ensures that even when multiple functions share the same address range, we return only the line entries that actually belong to the function represented by the DIE. The implementation: - Adds an optional DWARFDie parameter to lookupAddressRange - Extracts the `DW_AT_LLVM_stmt_sequence` offset if present - Modifies the address range lookup logic to filter sequences based on their offset - Returns only line entries from the matching sequence
2025-02-06Symbolize line zero as if no source info is available (#124846)David Blaikie
Since line zero means "no line information", when symbolizing a location (an address or an inline frame associated with the address) that has a line zero location, we shouldn't include other irrelevant data (like filename) in the result.
2024-08-07Fix gcc Wparentheses warning. NFC.Simon Pilgrim
2024-08-05[Symbolizer] Support for Missing Line Numbers. (#82240)Amit Kumar Pandey
LLVM Symbolizer attempt to symbolize addresses of optimized binaries reports missing line numbers for some cases. It maybe due to compiler which sometimes cannot map an instruction to line number due to optimizations. Symbolizer should handle those cases gracefully. Adding an option '--skip-line-zero' to symbolizer so as to report the nearest non-zero line number. --------- Co-authored-by: Amit Pandey <amit.pandey@amd.com>
2024-02-22[lldb][llvm] Return an error instead of crashing when parsing a line table ↵Greg Clayton
prologue. (#80769) We recently ran into some bad DWARF where the `DW_AT_stmt_list` of many compile units was randomly set to invalid values and was causing LLDB to crash due to an assertion about address sizes not matching. Instead of asserting, we should return an appropriate recoverable `llvm::Error`.
2024-01-19[llvm] Use SmallString::operator std::string (NFC)Kazu Hirata
2023-11-30Allow for mixing source/no-source DIFiles in one CUAdrian Prantl
The DWARF proposal that the DW_LNCT_LLVM_source extension is based on (https://dwarfstd.org/issues/180201.1.html) allows to mix source and non-source files in the same CU by storing an empty string as a sentinel value. This patch implements this feature. Review in https://github.com/llvm/llvm-project/pull/73877
2023-07-12[DWARF] Allow op-index in line number programsDavid Stenberg
This extends DWARFDebugLine to properly parse line number programs with maximum_operations_per_instruction > 1 for VLIW targets. No functions that use that parsed output to retrieve line information have been extended to support multiple op-indexes. This means that when retrieving information for an address with multiple op-indexes, e.g. when using llvm-addr2line, the penultimate row for that address will be used, which in most cases is the row for the second largest op-index. This will be addressed in further changes, but this patch at least allows us to correctly parse such line number programs, with a warning saying that the line number information may be incorrect (incomplete). Reviewed By: StephenTozer Differential Revision: https://reviews.llvm.org/D152536
2023-07-12[DWARF] Add printout for op-indexDavid Stenberg
This is a preparatory patch for extending DWARFDebugLine to properly parse line number programs with maximum_operations_per_instruction > 1 for VLIW targets. Add some scaffolding for handling op-index in line number programs, and add printouts for that in the table. As this affects a lot of tests, this is done in a separate commit to get a cleaner review for the actual op-index implementation. Verbose printouts are not present in many tests, and adding op-index to those will require a bit more code changes, so that is done in the actual implementation patch. Reviewed By: StephenTozer Differential Revision: https://reviews.llvm.org/D152535
2023-03-22[DebugInfo] Allow parsing line tables aligned to 4 or 8-byte boundariesBenjamin Maxwell
This allows the DWARFDebugLine::SectionParser to try parsing line tables at 4 or 8-byte boundaries if the unaligned offset appears invalid. If aligning the offset does not reduce errors the offset is used unchanged. This is needed for llvm-dwarfdump to be able to extract the line tables (with --debug-lines) from binaries produced by certain compilers that like to align each line table in the .debug_line section. Note that this alignment does not seem to be invalid since the units do point to the correct line table offsets via the DW_AT_stmt_list attribute. Differential Revision: https://reviews.llvm.org/D143513
2022-12-16std::optional::value => operator*/operator->Fangrui Song
value() has undesired exception checking semantics and calls __throw_bad_optional_access in libc++. Moreover, the API is unavailable without _LIBCPP_NO_EXCEPTIONS on older Mach-O platforms (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). This commit fixes LLVMAnalysis and its dependencies.
2022-12-06[llvm] Don't include Optional.h (NFC)Kazu Hirata
These source files no longer use Optional<T>, so they do not need to include Optional.h. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-04[llvm] Use std::nullopt instead of None in comments (NFC)Kazu Hirata
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-05[DebugInfo] llvm::Optional => std::optionalFangrui Song
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-02[DebugInfo] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-10-27[llvm-debuginfo-analyzer] (08/09) - ELF ReaderCarlos Alberto Enciso
llvm-debuginfo-analyzer is a command line tool that processes debug info contained in a binary file and produces a debug information format agnostic “Logical View”, which is a high-level semantic representation of the debug info, independent of the low-level format. The code has been divided into the following patches: 1) Interval tree 2) Driver and documentation 3) Logical elements 4) Locations and ranges 5) Select elements 6) Warning and internal options 7) Compare elements 8) ELF Reader 9) CodeView Reader Full details: https://discourse.llvm.org/t/llvm-dev-rfc-llvm-dva-debug-information-visual-analyzer/62570 This patch: This is a high level summary of the changes in this patch. ELF Reader - Support for ELF/DWARF. LVBinaryReader, LVELFReader Reviewed By: psamolysov, probinson Differential Revision: https://reviews.llvm.org/D125783
2022-08-12[DebugInfo] Don't join DW_AT_comp_dir and directories[0] for DWARF v5 line ↵Fangrui Song
tables DWARF v5 6.2.4 The Line Number Program Header says: > The first entry is the current directory of the compilation. Each additional > path entry is either a full path name or is relative to the current directory of > the compilation. When forming a path, relative DW_AT_comp_dir and directories[0] are not supposed to be joined together. Fix getFileNameByIndex to special case DWARF v5 DirIdx == 0. Reviewed By: #debug-info, dblaikie Differential Revision: https://reviews.llvm.org/D131804
2022-07-17Remove unused forward declarations (NFC)Kazu Hirata
2022-07-13[llvm] Use value instead of getValue (NFC)Kazu Hirata
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata
2022-05-24Exposes interface to free up caching data structure in DWARFDebugLine and ↵Hyoun Kyu Cho
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-04-05[Support/Hash functions] Change the `final()` and `result()` of the hashing ↵Argyrios Kyrtzidis
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-02-15Cleanup LLVMDWARFDebugInfoserge-sans-paille
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
2021-12-14DebugInfo: Migrate callers from getAsCString to dwarf::toStringDavid Blaikie
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.
2020-10-04llvm-dwarfdump: Print addresses in debug_line to the parsed address sizeDavid Blaikie
2020-10-04llvm-dwarfdump: Skip tombstoned address rangesDavid Blaikie
Make the dumper & API a bit more informative by using the new tombstone addresses to filter out or otherwise render more explicitly dead code ranges.
2020-09-18DebugInfo: Simplify line table parsing to take all the units together, ↵David Blaikie
rather than CUs and TUs separately
2020-09-15Revert "[DebugInfo] Remove dots from getFilenameByIndex return value"Petr Hosek
This is failing on Windows bots due to path separator normalization. This reverts commit 042c23506869b4ae9a49d2c4bc5ea6e6baeabe78.
2020-09-14[DebugInfo] Remove dots from getFilenameByIndex return valuePetr Hosek
When concatenating directory with filename in getFilenameByIndex, we might end up with a path that contains extra dots. For example, if the input is /path and ./example, we would return /path/./example. Run sys::path::remove_dots on the output to eliminate unnecessary dots. Differential Revision: https://reviews.llvm.org/D87657
2020-08-05Add verification for DW_AT_decl_file and DW_AT_call_file.Greg Clayton
LTO builds have been creating invalid DWARF and one of the errors was a file index that was out of bounds. "llvm-dwarfdump --verify" will check all file indexes for line tables already, but there are no checks for the validity of file indexes in attributes. The verification will verify if there is a DW_AT_decl_file/DW_AT_call_file that: - there is a line table for the compile unit - the file index is valid - the encoding is appropriate Tests are added that test all of the above conditions. Differential Revision: https://reviews.llvm.org/D84817
2020-07-03[DebugInfo] Use Cursor to detect errors in debug line prologue parserJames Henderson
Previously, the debug line parser would keep attempting to read data even if it had run out of data to read. This meant errors in parsing would often end up being reported as something else, such as an unknown version or malformed directory/filename table. This patch fixes the issues by using the Cursor API to capture errors. Reviewed by: labath Differential Revision: https://reviews.llvm.org/D83043
2020-06-23[DebugInfo] Print line table extended opcode bytes if parsing failsJames Henderson
Previously, if there was an error whilst parsing the operands of an extended opcode, the operands would be treated as zero and printed. This could potentially be slightly confusing. This patch changes the behaviour to print the raw bytes instead. Reviewed by: ikudrin Differential Revision: https://reviews.llvm.org/D81570
2020-06-17[DebugInfo] Unify Cursor usage for all debug line opcodesJames Henderson
This is a natural extension of the previous changes to use the Cursor class independently in the standard and extended opcode paths, and in turn allows delaying error handling until the entire line has been printed in verbose mode, removing interleaved output in some cases. Reviewed by: MaskRay, JDevlieghere Differential Revision: https://reviews.llvm.org/D81562
2020-06-15[DebugInfo] Report errors for truncated debug line standard opcodeJames Henderson
Standard opcodes usually have ULEB128 arguments, so it is generally not possible to recover from such errors. This patch causes the parser to stop parsing the table in such situations. Also don't emit the operands or add data to the table if there is an error reading these opcodes. Reviewed by: JDevlieghere Differential Revision: https://reviews.llvm.org/D81470
2020-06-11[llvm/DWARFDebugLine] Remove spurious full stop from warning messagesPavel Labath
Other warnings messages don't have a trailing full stop.
2020-06-11[llvm/DWARFDebugLine] Fix a typo in one warning messagePavel Labath
2020-06-10[DWARFDebugLine] Use truncating data extractors for prologue parsingPavel Labath
Summary: This makes the code easier to reason about, as it will behave the same way regardless of whether there is any more data coming after the presumed end of the prologue. Reviewers: jhenderson, dblaikie, probinson, ikudrin Subscribers: hiraditya, MaskRay, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77557
2020-06-09[DebugInfo] Drop unneeded format() calls (fix -Wformat-security) after ↵Fangrui Song
3b7ec64d59748765990ed99716034ab8d5533673
2020-06-09[DebugInfo] Fix printing of unrecognised standard opcodesJames Henderson
The verbose printing of unrecognised standard opcodes was broken in multiple ways (additional blank lines, a closing parenthesis without opening parenthesis and so on). This patch fixes it, and makes the output more consistent with other opcodes.
2020-06-09[DebugInfo] Improve new line printing in debug line verbose outputJames Henderson
The new line printing for debug line verbose output was inconsistent. For new rows in the matrix, a blank line followed, whilst the DW_LNS_copy opcode actually resulted in two blank lines. There was also potential inconsistency in the blank lines at the end of the table. This patch mostly resolves these issues - no blank lines appear in the output except for a single line after the prologue and at table end to separate it from any subsquent table, plus some instances after error messages. Also add a unit test for verbose output to test the fine details of new line placement and other aspects of verbose output. Reviewed by: dblaikie Differential Revision: https://reviews.llvm.org/D81102
2020-06-09[DebugInfo] Print non-verbose output at some point as verbose outputJames Henderson
Verbose and non-verbose parsing of .debug_line produced their output at different points in the program. The most obvious impact of this was that error messages were produced at different times, but it also potentially reduced what clients could do by customising the stream or warning/error handlers. This change makes the two variants consistent by printing non-verbose output inline, the same as verbose output. Testing of the error messages has been modified to check the messages always appear in the same location to illustrate the behaviour. Reviewed by: JDevlieghere, dblaikie, MaskRay, labath Differential Revision: https://reviews.llvm.org/D80989
2020-06-09[DebugInfo] Check for errors when reading data for extended opcodeJames Henderson
Previously, if an extended opcode was truncated, it would manifest as an "unexpected line op length error" which wasn't quite accurate. This change checks for errors any time data is read whilst parsing an extended opcode, and reports any errors detected. Reviewed by: MaskRay, labath, aprantl Differential Revision: https://reviews.llvm.org/D80797
2020-06-04[llvm-dwarfdump] Add a table header for -debug-line -verbose outputFangrui Song
Like non-verbose output, so that it is easy to recognize the `Line,Column,File,ISA,Discriminator` column values. Reviewed By: JDevlieghere, jhenderson Differential Revision: https://reviews.llvm.org/D80874
2020-06-02[DebugInfo] Report the format of line tables [7/10]Igor Kudrin
Differential Revision: https://reviews.llvm.org/D80523