1//===- DWARFDebugArangeSet.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_DWARFDEBUGARANGESET_H
10#define LLVM_DEBUGINFO_DWARF_DWARFDEBUGARANGESET_H
11
12#include "llvm/ADT/iterator_range.h"
13#include "llvm/BinaryFormat/Dwarf.h"
14#include "llvm/Support/Error.h"
15#include <cstdint>
16#include <vector>
17
18namespace llvm {
19
20class raw_ostream;
21class DWARFDataExtractor;
22
23class DWARFDebugArangeSet {
24public:
25  struct Header {
26    /// The total length of the entries for that set, not including the length
27    /// field itself.
28    uint64_t Length;
29    /// The DWARF format of the set.
30    dwarf::DwarfFormat Format;
31    /// The offset from the beginning of the .debug_info section of the
32    /// compilation unit entry referenced by the table.
33    uint64_t CuOffset;
34    /// The DWARF version number.
35    uint16_t Version;
36    /// The size in bytes of an address on the target architecture. For segmented
37    /// addressing, this is the size of the offset portion of the address.
38    uint8_t AddrSize;
39    /// The size in bytes of a segment descriptor on the target architecture.
40    /// If the target system uses a flat address space, this value is 0.
41    uint8_t SegSize;
42  };
43
44  struct Descriptor {
45    uint64_t Address;
46    uint64_t Length;
47
48    uint64_t getEndAddress() const { return Address + Length; }
49    void dump(raw_ostream &OS, uint32_t AddressSize) const;
50  };
51
52private:
53  using DescriptorColl = std::vector<Descriptor>;
54  using desc_iterator_range = iterator_range<DescriptorColl::const_iterator>;
55
56  uint64_t Offset;
57  Header HeaderData;
58  DescriptorColl ArangeDescriptors;
59
60public:
61  DWARFDebugArangeSet() { clear(); }
62
63  void clear();
64  Error extract(DWARFDataExtractor data, uint64_t *offset_ptr,
65                function_ref<void(Error)> WarningHandler);
66  void dump(raw_ostream &OS) const;
67
68  uint64_t getCompileUnitDIEOffset() const { return HeaderData.CuOffset; }
69
70  const Header &getHeader() const { return HeaderData; }
71
72  desc_iterator_range descriptors() const {
73    return desc_iterator_range(ArangeDescriptors.begin(),
74                               ArangeDescriptors.end());
75  }
76};
77
78} // end namespace llvm
79
80#endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGARANGESET_H
81