summaryrefslogtreecommitdiff
path: root/llvm/lib/DebugInfo/DWARF/DWARFDataExtractor.cpp
AgeCommit message (Collapse)Author
2025-06-06[NFC] Split portions of DWARFDataExtractor into new class (#140096)Sterling-Augustine
Currently, DWARFDataExtractor can extract data without performing relocations, (eg, by checking if the section pointer is null) but is coded such that it still depends on all the relocation machinery, like DWARFSections and similar. All at build time. Extract most functionality into a new class, DWARFDataExtractorBase, and have DWARFDataExtractor add the relocation dependent pieces via CRTP. Add a new class, DWARFDataExtractorSimple, which does no relocation at all. This will allow moving DWARFDataExtractorSimple into a new lower-level, lighter-weight library with fewer external build-time dependencies. This is another in a series of refactoring changes to create a new better-layered, low-level Dwarf library that can be called from lower-level code without circular dependencies.
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-11-27[lld] Change Optional to std::optionalFangrui Song
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
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
2020-11-20[lib/Object] - Generalize the RelocationResolver API.Georgii Rymar
This allows to reuse the RelocationResolver from the code that doesn't want to deal with `RelocationRef` class. I am going to use it in llvm-readobj. See the description of D91530 for more details. Differential revision: https://reviews.llvm.org/D91533
2020-07-18[DebugInfo] Respect relocations when decoding DW_EH_PE_sdata4 & ↵Fangrui Song
DW_EH_PE_sdata8 and support R_ARM_REL32 The addresses in llvm-dwarfdump --eh-frame output for object files are closer to readelf -wf output now.
2020-04-15Fix DWARFDataExtractor::getRelocatedValue near EOFPavel Labath
Summary: If we have an (invalid) relocation which relocates bytes which partially lie outside the range of the relocated section, the getRelocatedValue would return confusing results. It would first read zero (because that's what the underlying DataExtractor api does for out-of-bounds reads), and then relocate that zero anyway. A more appropriate behavior is to return zero straight away. This is what this patch does. Reviewers: dblaikie, jhenderson Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78113
2020-02-26Introduce DWARFDataExtractor::getInitialLengthPavel Labath
Summary: This patch introduces a function to house the code needed to do the DWARF64 detection dance. The function decodes the initial length field and returns it as a pair containing the actual length, and the DWARF encoding. This patch does _not_ attempt to handle the problem of detecting lengths which extend past the size of the section, or cases when reads of a single contribution accidentally escape beyond its specified length, but I think it's useful in its own right. Reviewers: dblaikie, jhenderson, ikudrin Subscribers: hiraditya, probinson, aprantl, JDevlieghere, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D74560
2019-08-27Add error handling to the DataExtractor classPavel Labath
Summary: This is motivated by D63591, where we realized that there isn't a really good way of telling whether a DataExtractor is reading actual data, or is it just returning default values because it reached the end of the buffer. This patch resolves that by providing a new "Cursor" class. A Cursor object encapsulates two things: - the current position/offset in the DataExtractor - an error object Storing the error object inside the Cursor enables one to use the same pattern as the std::{io}stream API, where one can blindly perform a sequence of reads and only check for errors once at the end of the operation. Similarly to the stream API, as soon as we encounter one error, all of the subsequent operations are skipped (return default values) too, even if the would suceed with clear error state. Unlike the std::stream API (but in line with other llvm APIs), we force the error state to be checked through usage of llvm::Error. Reviewers: probinson, dblaikie, JDevlieghere, aprantl, echristo Subscribers: kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63713 llvm-svn: 370042
2019-08-16Remove the temporary code. NFC.Igor Kudrin
That should have been done in rL368156 but somehow was missed. llvm-svn: 369082
2019-08-06Support 64-bit offsets in utility classes (1/5)Igor Kudrin
Using 64-bit offsets is required to fully implement 64-bit DWARF. As these classes are used in many different libraries they should temporarily support both 32- and 64-bit offsets. Differential Revision: https://reviews.llvm.org/D64006 llvm-svn: 368013
2019-07-18[DWARF][RISCV] Add support for RISC-V relocations needed for debug infoAlex Bradbury
When code relaxation is enabled many RISC-V fixups are not resolved but instead relocations are emitted. This happens even for DWARF debug sections. Therefore, to properly support the parsing of DWARF debug info we need to be able to resolve RISC-V relocations. This patch adds: * Support for RISC-V relocations in RelocationResolver * DWARF support for two relocations per object file offset * DWARF changes to support relocations in more DIE fields The two relocations per offset change is needed because some RISC-V relocations (used for label differences) come in pairs. Relocations can also be emitted for DWARF fields where relocations were not yet evaluated. Adding relocation support for some of these fields is essencial. On the other hand, LLVM currently emits RISC-V relocations for fixups that could be safely evaluated, since they can never be affected by code relaxations. This patch also adds relocation support for the fields affected by those extraneous relocations (the DWARF unit entry Length, and the DWARF debug line entry TotalLength and PrologueLength), for testing purposes. Differential Revision: https://reviews.llvm.org/D62062 Patch by Luís Marques. llvm-svn: 366402
2019-03-22[DWARF] Refactor RelocVisitor and fix computation of SHT_RELA-typed ↵Fangrui Song
relocation entries Summary: getRelocatedValue may compute incorrect value for SHT_RELA-typed relocation entries. // DWARFDataExtractor.cpp uint64_t DWARFDataExtractor::getRelocatedValue(uint32_t Size, uint32_t *Off, ... // This formula is correct for REL, but may be incorrect for RELA if the value // stored in the location (getUnsigned(Off, Size)) is not zero. return getUnsigned(Off, Size) + Rel->Value; In this patch, we * refactor these visit* functions to include a new parameter `uint64_t A`. Since these visit* functions are no longer used as visitors, rename them to resolve*. + REL: A is used as the addend. A is the value stored in the location where the relocation applies: getUnsigned(Off, Size) + RELA: The addend encoded in RelocationRef is used, e.g. getELFAddend(R) * and add another set of supports* functions to check if a given relocation type is handled. DWARFObjInMemory uses them to fail early. Reviewers: echristo, dblaikie Reviewed By: echristo Subscribers: mgorny, aprantl, aheejin, fedor.sergeev, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D57939 llvm-svn: 356729
2019-02-27[DebugInfo] add SectionedAddress to DebugInfo interfaces.Alexey Lapshin
That patch is the fix for https://bugs.llvm.org/show_bug.cgi?id=40703 "wrong line number info for obj file compiled with -ffunction-sections" bug. The problem happened with only .o files. If object file contains several .text sections then line number information showed incorrectly. The reason for this is that DwarfLineTable could not detect section which corresponds to specified address(because address is the local to the section). And as the result it could not select proper sequence in the line table. The fix is to pass SectionIndex with the address. So that it would be possible to differentiate addresses from various sections. With this fix llvm-objdump shows correct line numbers for disassembled code. Differential review: https://reviews.llvm.org/D58194 llvm-svn: 354972
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-03-08Reland "[DebugInfo] Support DWARF expressions in eh_frame"Rafael Auler
Summary: Original change was D43313 (r326932) and reverted by r326953 because it broke an LLD test and a windows build. The LLD test was already fixed in lld commit r326944 (thanks maskray). This is the original change with the windows build fixed. llvm-svn: 326970
2018-03-07Revert r326932: [DebugInfo] Support DWARF expressions in eh_frameRui Ueyama
This reverts commit rr326932 because it broke lld/test/ELF/eh-frame-hdr-augmentation.s. llvm-svn: 326953
2018-03-07[DebugInfo] Support DWARF expressions in eh_frameRafael Auler
This patch enhances DWARFDebugFrame with the capability of parsing and printing DWARF expressions in CFI instructions. It also makes FDEs and CIEs accessible to lib users, so they can process them in client tools that rely on LLVM. To make it self-contained with a test case, it teaches llvm-readobj to be able to dump EH frames and checks they are correct in a unit test. The llvm-readobj code is Maksim Panchenko's work (maksfb). Reviewers: JDevlieghere, espindola Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D43313 llvm-svn: 326932
2017-09-04[DebugInfo] - Fix for lld DWARF parsing of base address selection entries in ↵George Rimar
range lists. It solves issue of wrong section index evaluating for ranges when base address is used. Based on David Blaikie's patch D36097. Differential revision: https://reviews.llvm.org/D37214 llvm-svn: 312477
2017-07-19Use delegation instead of inheritance.Rafael Espindola
This changes DwarfContext to delegate to DwarfObject instead of having pure virtual methods. With this DwarfContextInMemory is replaced with an implementation of DwarfObject that is local to a .cpp file. llvm-svn: 308543
2017-06-29[DWARF] NFC: DWARFDataExtractor combines relocs with DataExtractor.Paul Robinson
Requires callers to directly associate relocations with a DataExtractor used to read data from a DWARF section, which helps a callee not make assumptions about which section it is reading. This is the next step in reducing DWARFFormValue's dependence on DWARFUnit. Differential Revision: https://reviews.llvm.org/D34704 llvm-svn: 306699