1243789Sdim//===-- DWARFDebugRangeList.h -----------------------------------*- C++ -*-===//
2243789Sdim//
3243789Sdim//                     The LLVM Compiler Infrastructure
4243789Sdim//
5243789Sdim// This file is distributed under the University of Illinois Open Source
6243789Sdim// License. See LICENSE.TXT for details.
7243789Sdim//
8243789Sdim//===----------------------------------------------------------------------===//
9243789Sdim
10243789Sdim#ifndef LLVM_DEBUGINFO_DWARFDEBUGRANGELIST_H
11243789Sdim#define LLVM_DEBUGINFO_DWARFDEBUGRANGELIST_H
12243789Sdim
13243789Sdim#include "llvm/Support/DataExtractor.h"
14243789Sdim#include <vector>
15243789Sdim
16243789Sdimnamespace llvm {
17243789Sdim
18243789Sdimclass raw_ostream;
19243789Sdim
20243789Sdimclass DWARFDebugRangeList {
21243789Sdimpublic:
22243789Sdim  struct RangeListEntry {
23243789Sdim    // A beginning address offset. This address offset has the size of an
24243789Sdim    // address and is relative to the applicable base address of the
25243789Sdim    // compilation unit referencing this range list. It marks the beginning
26243789Sdim    // of an address range.
27243789Sdim    uint64_t StartAddress;
28243789Sdim    // An ending address offset. This address offset again has the size of
29243789Sdim    // an address and is relative to the applicable base address of the
30243789Sdim    // compilation unit referencing this range list. It marks the first
31243789Sdim    // address past the end of the address range. The ending address must
32243789Sdim    // be greater than or equal to the beginning address.
33243789Sdim    uint64_t EndAddress;
34243789Sdim    // The end of any given range list is marked by an end of list entry,
35243789Sdim    // which consists of a 0 for the beginning address offset
36243789Sdim    // and a 0 for the ending address offset.
37243789Sdim    bool isEndOfListEntry() const {
38243789Sdim      return (StartAddress == 0) && (EndAddress == 0);
39243789Sdim    }
40243789Sdim    // A base address selection entry consists of:
41243789Sdim    // 1. The value of the largest representable address offset
42243789Sdim    // (for example, 0xffffffff when the size of an address is 32 bits).
43243789Sdim    // 2. An address, which defines the appropriate base address for
44243789Sdim    // use in interpreting the beginning and ending address offsets of
45243789Sdim    // subsequent entries of the location list.
46243789Sdim    bool isBaseAddressSelectionEntry(uint8_t AddressSize) const {
47243789Sdim      assert(AddressSize == 4 || AddressSize == 8);
48243789Sdim      if (AddressSize == 4)
49243789Sdim        return StartAddress == -1U;
50243789Sdim      else
51243789Sdim        return StartAddress == -1ULL;
52243789Sdim    }
53243789Sdim    bool containsAddress(uint64_t BaseAddress, uint64_t Address) const {
54243789Sdim      return (BaseAddress + StartAddress <= Address) &&
55243789Sdim             (Address < BaseAddress + EndAddress);
56243789Sdim    }
57243789Sdim  };
58243789Sdim
59243789Sdimprivate:
60243789Sdim  // Offset in .debug_ranges section.
61243789Sdim  uint32_t Offset;
62243789Sdim  uint8_t AddressSize;
63243789Sdim  std::vector<RangeListEntry> Entries;
64243789Sdim
65243789Sdimpublic:
66243789Sdim  DWARFDebugRangeList() { clear(); }
67243789Sdim  void clear();
68243789Sdim  void dump(raw_ostream &OS) const;
69243789Sdim  bool extract(DataExtractor data, uint32_t *offset_ptr);
70243789Sdim  /// containsAddress - Returns true if range list contains the given
71243789Sdim  /// address. Has to be passed base address of the compile unit that
72243789Sdim  /// references this range list.
73243789Sdim  bool containsAddress(uint64_t BaseAddress, uint64_t Address) const;
74243789Sdim};
75243789Sdim
76243789Sdim}  // namespace llvm
77243789Sdim
78243789Sdim#endif  // LLVM_DEBUGINFO_DWARFDEBUGRANGELIST_H
79