Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:41

0001 //===- DWARFDebugAddr.h -------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGADDR_H
0010 #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGADDR_H
0011 
0012 #include "llvm/BinaryFormat/Dwarf.h"
0013 #include "llvm/DebugInfo/DIContext.h"
0014 #include "llvm/Support/Error.h"
0015 #include <cstdint>
0016 #include <vector>
0017 
0018 namespace llvm {
0019 
0020 class raw_ostream;
0021 class DWARFDataExtractor;
0022 
0023 /// A class representing an address table as specified in DWARF v5.
0024 /// The table consists of a header followed by an array of address values from
0025 /// .debug_addr section.
0026 class DWARFDebugAddrTable {
0027   dwarf::DwarfFormat Format;
0028   uint64_t Offset;
0029   /// The total length of the entries for this table, not including the length
0030   /// field itself.
0031   uint64_t Length = 0;
0032   /// The DWARF version number.
0033   uint16_t Version;
0034   /// The size in bytes of an address on the target architecture. For
0035   /// segmented addressing, this is the size of the offset portion of the
0036   /// address.
0037   uint8_t AddrSize;
0038   /// The size in bytes of a segment selector on the target architecture.
0039   /// If the target system uses a flat address space, this value is 0.
0040   uint8_t SegSize;
0041   std::vector<uint64_t> Addrs;
0042 
0043   /// Invalidate Length field to stop further processing.
0044   void invalidateLength() { Length = 0; }
0045 
0046   Error extractAddresses(const DWARFDataExtractor &Data, uint64_t *OffsetPtr,
0047                          uint64_t EndOffset);
0048 
0049 public:
0050 
0051   /// Extract the entire table, including all addresses.
0052   Error extract(const DWARFDataExtractor &Data, uint64_t *OffsetPtr,
0053                 uint16_t CUVersion, uint8_t CUAddrSize,
0054                 std::function<void(Error)> WarnCallback);
0055 
0056   /// Extract a DWARFv5 address table.
0057   Error extractV5(const DWARFDataExtractor &Data, uint64_t *OffsetPtr,
0058                   uint8_t CUAddrSize, std::function<void(Error)> WarnCallback);
0059 
0060   /// Extract a pre-DWARFv5 address table. Such tables do not have a header
0061   /// and consist only of a series of addresses.
0062   /// See https://gcc.gnu.org/wiki/DebugFission for details.
0063   Error extractPreStandard(const DWARFDataExtractor &Data, uint64_t *OffsetPtr,
0064                            uint16_t CUVersion, uint8_t CUAddrSize);
0065 
0066   void dump(raw_ostream &OS, DIDumpOptions DumpOpts = {}) const;
0067 
0068   /// Return the address based on a given index.
0069   Expected<uint64_t> getAddrEntry(uint32_t Index) const;
0070 
0071   /// Return the full length of this table, including the length field.
0072   /// Return std::nullopt if the length cannot be identified reliably.
0073   std::optional<uint64_t> getFullLength() const;
0074 
0075   /// Return the DWARF format of this table.
0076   dwarf::DwarfFormat getFormat() const { return Format; }
0077 
0078   /// Return the length of this table.
0079   uint64_t getLength() const { return Length; }
0080 
0081   /// Return the version of this table.
0082   uint16_t getVersion() const { return Version; }
0083 
0084   /// Return the address size of this table.
0085   uint8_t getAddressSize() const { return AddrSize; }
0086 
0087   /// Return the segment selector size of this table.
0088   uint8_t getSegmentSelectorSize() const { return SegSize; }
0089 
0090   /// Return the parsed addresses of this table.
0091   ArrayRef<uint64_t> getAddressEntries() const { return Addrs; }
0092 };
0093 
0094 } // end namespace llvm
0095 
0096 #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGADDR_H