1 //===- DWARFDebugRnglists.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_DWARFDEBUGRNGLISTS_H
10 #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGRNGLISTS_H
11 
12 #include "llvm/ADT/Optional.h"
13 #include "llvm/ADT/STLFunctionalExtras.h"
14 #include "llvm/BinaryFormat/Dwarf.h"
15 #include "llvm/DebugInfo/DWARF/DWARFAddressRange.h"
16 #include "llvm/DebugInfo/DWARF/DWARFListTable.h"
17 #include <cstdint>
18 
19 namespace llvm {
20 
21 class Error;
22 class raw_ostream;
23 class DWARFUnit;
24 class DWARFDataExtractor;
25 struct DIDumpOptions;
26 namespace object {
27 struct SectionedAddress;
28 }
29 
30 /// A class representing a single range list entry.
31 struct RangeListEntry : public DWARFListEntryBase {
32   /// The values making up the range list entry. Most represent a range with
33   /// a start and end address or a start address and a length. Others are
34   /// single value base addresses or end-of-list with no values. The unneeded
35   /// values are semantically undefined, but initialized to 0.
36   uint64_t Value0;
37   uint64_t Value1;
38 
39   Error extract(DWARFDataExtractor Data, uint64_t *OffsetPtr);
40   void dump(raw_ostream &OS, uint8_t AddrSize, uint8_t MaxEncodingStringLength,
41             uint64_t &CurrentBase, DIDumpOptions DumpOpts,
42             llvm::function_ref<Optional<object::SectionedAddress>(uint32_t)>
43                 LookupPooledAddress) const;
44   bool isSentinel() const { return EntryKind == dwarf::DW_RLE_end_of_list; }
45 };
46 
47 /// A class representing a single rangelist.
48 class DWARFDebugRnglist : public DWARFListType<RangeListEntry> {
49 public:
50   /// Build a DWARFAddressRangesVector from a rangelist.
51   DWARFAddressRangesVector
52   getAbsoluteRanges(Optional<object::SectionedAddress> BaseAddr,
53                     uint8_t AddressByteSize,
54                     function_ref<Optional<object::SectionedAddress>(uint32_t)>
55                         LookupPooledAddress) const;
56 
57   /// Build a DWARFAddressRangesVector from a rangelist.
58   DWARFAddressRangesVector
59   getAbsoluteRanges(llvm::Optional<object::SectionedAddress> BaseAddr,
60                     DWARFUnit &U) const;
61 };
62 
63 class DWARFDebugRnglistTable : public DWARFListTableBase<DWARFDebugRnglist> {
64 public:
65   DWARFDebugRnglistTable()
66       : DWARFListTableBase(/* SectionName    = */ ".debug_rnglists",
67                            /* HeaderString   = */ "ranges:",
68                            /* ListTypeString = */ "range") {}
69 };
70 
71 } // end namespace llvm
72 
73 #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGRNGLISTS_H
74