Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 1 | //===- DWARFDebugAddr.h -------------------------------------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 6 | // |
| 7 | //===------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_DEBUGINFO_DWARFDEBUGADDR_H |
| 10 | #define LLVM_DEBUGINFO_DWARFDEBUGADDR_H |
| 11 | |
| 12 | #include "llvm/BinaryFormat/Dwarf.h" |
| 13 | #include "llvm/DebugInfo/DIContext.h" |
| 14 | #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h" |
| 15 | #include "llvm/Support/Errc.h" |
| 16 | #include "llvm/Support/Error.h" |
| 17 | #include <cstdint> |
| 18 | #include <map> |
| 19 | #include <vector> |
| 20 | |
| 21 | namespace llvm { |
| 22 | |
| 23 | class Error; |
| 24 | class raw_ostream; |
| 25 | |
| 26 | /// A class representing an address table as specified in DWARF v5. |
| 27 | /// The table consists of a header followed by an array of address values from |
| 28 | /// .debug_addr section. |
| 29 | class DWARFDebugAddrTable { |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 30 | dwarf::DwarfFormat Format; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 31 | uint64_t Offset; |
| 32 | /// The total length of the entries for this table, not including the length |
| 33 | /// field itself. |
| 34 | uint64_t Length = 0; |
| 35 | /// The DWARF version number. |
| 36 | uint16_t Version; |
| 37 | /// The size in bytes of an address on the target architecture. For |
| 38 | /// segmented addressing, this is the size of the offset portion of the |
| 39 | /// address. |
| 40 | uint8_t AddrSize; |
| 41 | /// The size in bytes of a segment selector on the target architecture. |
| 42 | /// If the target system uses a flat address space, this value is 0. |
| 43 | uint8_t SegSize; |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 44 | std::vector<uint64_t> Addrs; |
| 45 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 46 | /// Invalidate Length field to stop further processing. |
| 47 | void invalidateLength() { Length = 0; } |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 48 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 49 | Error extractAddresses(const DWARFDataExtractor &Data, uint64_t *OffsetPtr, |
| 50 | uint64_t EndOffset); |
| 51 | |
| 52 | public: |
| 53 | |
| 54 | /// Extract the entire table, including all addresses. |
| 55 | Error extract(const DWARFDataExtractor &Data, uint64_t *OffsetPtr, |
| 56 | uint16_t CUVersion, uint8_t CUAddrSize, |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 57 | std::function<void(Error)> WarnCallback); |
| 58 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 59 | /// Extract a DWARFv5 address table. |
| 60 | Error extractV5(const DWARFDataExtractor &Data, uint64_t *OffsetPtr, |
| 61 | uint8_t CUAddrSize, std::function<void(Error)> WarnCallback); |
| 62 | |
| 63 | /// Extract a pre-DWARFv5 address table. Such tables do not have a header |
| 64 | /// and consist only of a series of addresses. |
| 65 | /// See https://gcc.gnu.org/wiki/DebugFission for details. |
| 66 | Error extractPreStandard(const DWARFDataExtractor &Data, uint64_t *OffsetPtr, |
| 67 | uint16_t CUVersion, uint8_t CUAddrSize); |
| 68 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 69 | void dump(raw_ostream &OS, DIDumpOptions DumpOpts = {}) const; |
| 70 | |
| 71 | /// Return the address based on a given index. |
| 72 | Expected<uint64_t> getAddrEntry(uint32_t Index) const; |
| 73 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 74 | /// Return the full length of this table, including the length field. |
| 75 | /// Return None if the length cannot be identified reliably. |
| 76 | Optional<uint64_t> getFullLength() const; |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 77 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 78 | /// Return the DWARF format of this table. |
| 79 | dwarf::DwarfFormat getFormat() const { return Format; } |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 80 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 81 | /// Return the length of this table. |
| 82 | uint64_t getLength() const { return Length; } |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 83 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 84 | /// Return the version of this table. |
| 85 | uint16_t getVersion() const { return Version; } |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 86 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 87 | /// Return the address size of this table. |
| 88 | uint8_t getAddressSize() const { return AddrSize; } |
| 89 | |
| 90 | /// Return the segment selector size of this table. |
| 91 | uint8_t getSegmentSelectorSize() const { return SegSize; } |
| 92 | |
| 93 | /// Return the parsed addresses of this table. |
| 94 | ArrayRef<uint64_t> getAddressEntries() const { return Addrs; } |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | } // end namespace llvm |
| 98 | |
| 99 | #endif // LLVM_DEBUGINFO_DWARFDEBUGADDR_H |