Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAddr.h
Line
Count
Source (jump to first uncovered line)
1
//===- DWARFDebugAddr.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_DWARFDEBUGADDR_H
10
#define LLVM_DEBUGINFO_DWARFDEBUGADDR_H
11
12
#include "llvm/BinaryFormat/Dwarf.h"
13
#include "llvm/DebugInfo/DIContext.h"
14
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
15
#include "llvm/Support/Errc.h"
16
#include "llvm/Support/Error.h"
17
#include <cstdint>
18
#include <map>
19
#include <vector>
20
21
namespace llvm {
22
23
class Error;
24
class raw_ostream;
25
26
/// A class representing an address table as specified in DWARF v5.
27
/// The table consists of a header followed by an array of address values from
28
/// .debug_addr section.
29
class DWARFDebugAddrTable {
30
public:
31
  struct Header {
32
    /// The total length of the entries for this table, not including the length
33
    /// field itself.
34
    uint32_t Length = 0;
35
    /// The DWARF version number.
36
    uint16_t Version = 5;
37
    /// The size in bytes of an address on the target architecture. For
38
    /// segmented addressing, this is the size of the offset portion of the
39
    /// address.
40
    uint8_t AddrSize;
41
    /// The size in bytes of a segment selector on the target architecture.
42
    /// If the target system uses a flat address space, this value is 0.
43
    uint8_t SegSize = 0;
44
  };
45
46
private:
47
  dwarf::DwarfFormat Format;
48
  uint32_t HeaderOffset;
49
  Header HeaderData;
50
  uint32_t DataSize = 0;
51
  std::vector<uint64_t> Addrs;
52
53
public:
54
  void clear();
55
56
  /// Extract an entire table, including all addresses.
57
  Error extract(DWARFDataExtractor Data, uint32_t *OffsetPtr,
58
                uint16_t Version, uint8_t AddrSize,
59
                std::function<void(Error)> WarnCallback);
60
61
0
  uint32_t getHeaderOffset() const { return HeaderOffset; }
62
0
  uint8_t getAddrSize() const { return HeaderData.AddrSize; }
63
  void dump(raw_ostream &OS, DIDumpOptions DumpOpts = {}) const;
64
65
  /// Return the address based on a given index.
66
  Expected<uint64_t> getAddrEntry(uint32_t Index) const;
67
68
  /// Return the size of the table header including the length
69
  /// but not including the addresses.
70
28
  uint8_t getHeaderSize() const {
71
28
    switch (Format) {
72
28
    case dwarf::DwarfFormat::DWARF32:
73
28
      return 8; // 4 + 2 + 1 + 1
74
28
    case dwarf::DwarfFormat::DWARF64:
75
0
      return 16; // 12 + 2 + 1 + 1
76
0
    }
77
0
    llvm_unreachable("Invalid DWARF format (expected DWARF32 or DWARF64)");
78
0
  }
79
80
  /// Returns the length of this table, including the length field, or 0 if the
81
  /// length has not been determined (e.g. because the table has not yet been
82
  /// parsed, or there was a problem in parsing).
83
  uint32_t getLength() const;
84
85
  /// Verify that the given length is valid for this table.
86
10
  bool hasValidLength() const { return getLength() != 0; }
87
88
  /// Invalidate Length field to stop further processing.
89
46
  void invalidateLength() { HeaderData.Length = 0; }
90
91
  /// Returns the length of the array of addresses.
92
  uint32_t getDataSize() const;
93
};
94
95
} // end namespace llvm
96
97
#endif // LLVM_DEBUGINFO_DWARFDEBUGADDR_H