Home | History | Annotate | Line # | Download | only in DWARF
      1 //===- DWARFDebugAddr.h -------------------------------------*- C++ -*-===//
      2 //
      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
      6 //
      7 //===------------------------------------------------------------------===//
      8 
      9 #ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGADDR_H
     10 #define LLVM_DEBUGINFO_DWARF_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 {
     30   dwarf::DwarfFormat Format;
     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;
     44   std::vector<uint64_t> Addrs;
     45 
     46   /// Invalidate Length field to stop further processing.
     47   void invalidateLength() { Length = 0; }
     48 
     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,
     57                 std::function<void(Error)> WarnCallback);
     58 
     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 
     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 
     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;
     77 
     78   /// Return the DWARF format of this table.
     79   dwarf::DwarfFormat getFormat() const { return Format; }
     80 
     81   /// Return the length of this table.
     82   uint64_t getLength() const { return Length; }
     83 
     84   /// Return the version of this table.
     85   uint16_t getVersion() const { return Version; }
     86 
     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; }
     95 };
     96 
     97 } // end namespace llvm
     98 
     99 #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGADDR_H
    100