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