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