Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h
Line
Count
Source (jump to first uncovered line)
1
//===-- DIERef.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 LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DIEREF_H
10
#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DIEREF_H
11
12
#include "lldb/Core/dwarf.h"
13
#include "llvm/ADT/Optional.h"
14
#include "llvm/Support/FormatProviders.h"
15
#include <cassert>
16
#include <vector>
17
18
/// Identifies a DWARF debug info entry within a given Module. It contains three
19
/// "coordinates":
20
/// - dwo_num: identifies the dwo file in the Module. If this field is not set,
21
///   the DIERef references the main file.
22
/// - section: identifies the section of the debug info entry in the given file:
23
///   debug_info or debug_types.
24
/// - die_offset: The offset of the debug info entry as an absolute offset from
25
///   the beginning of the section specified in the section field.
26
class DIERef {
27
public:
28
  enum Section : uint8_t { DebugInfo, DebugTypes };
29
30
  DIERef(llvm::Optional<uint32_t> dwo_num, Section section,
31
         dw_offset_t die_offset)
32
      : m_dwo_num(dwo_num.getValueOr(0)), m_dwo_num_valid(bool(dwo_num)),
33
1.72M
        m_section(section), m_die_offset(die_offset) {
34
1.72M
    assert(this->dwo_num() == dwo_num && "Dwo number out of range?");
35
1.72M
  }
36
37
2.52M
  llvm::Optional<uint32_t> dwo_num() const {
38
2.52M
    if (m_dwo_num_valid)
39
628
      return m_dwo_num;
40
2.51M
    return llvm::None;
41
2.52M
  }
42
43
1.10M
  Section section() const { return static_cast<Section>(m_section); }
44
45
2.33M
  dw_offset_t die_offset() const { return m_die_offset; }
46
47
90.3k
  bool operator<(DIERef other) const {
48
90.3k
    if (m_dwo_num_valid != other.m_dwo_num_valid)
49
0
      return m_dwo_num_valid < other.m_dwo_num_valid;
50
90.3k
    if (m_dwo_num_valid && 
(m_dwo_num != other.m_dwo_num)0
)
51
0
      return m_dwo_num < other.m_dwo_num;
52
90.3k
    if (m_section != other.m_section)
53
0
      return m_section < other.m_section;
54
90.3k
    return m_die_offset < other.m_die_offset;
55
90.3k
  }
56
57
44
  bool operator==(const DIERef &rhs) const {
58
44
    return dwo_num() == rhs.dwo_num() && m_section == rhs.m_section &&
59
44
           m_die_offset == rhs.m_die_offset;
60
44
  }
61
62
36
  bool operator!=(const DIERef &rhs) const { return !(*this == rhs); }
63
64
  /// Decode a serialized version of this object from data.
65
  ///
66
  /// \param data
67
  ///   The decoder object that references the serialized data.
68
  ///
69
  /// \param offset_ptr
70
  ///   A pointer that contains the offset from which the data will be decoded
71
  ///   from that gets updated as data gets decoded.
72
  ///
73
  /// \return
74
  ///   Returns a valid DIERef if decoding succeeded, llvm::None if there was
75
  ///   unsufficient or invalid values that were decoded.
76
  static llvm::Optional<DIERef> Decode(const lldb_private::DataExtractor &data,
77
                                       lldb::offset_t *offset_ptr);
78
79
  /// Encode this object into a data encoder object.
80
  ///
81
  /// This allows this object to be serialized to disk.
82
  ///
83
  /// \param encoder
84
  ///   A data encoder object that serialized bytes will be encoded into.
85
  ///
86
  void Encode(lldb_private::DataEncoder &encoder) const;
87
88
private:
89
  uint32_t m_dwo_num : 30;
90
  uint32_t m_dwo_num_valid : 1;
91
  uint32_t m_section : 1;
92
  dw_offset_t m_die_offset;
93
};
94
static_assert(sizeof(DIERef) == 8, "");
95
96
typedef std::vector<DIERef> DIEArray;
97
98
namespace llvm {
99
template<> struct format_provider<DIERef> {
100
  static void format(const DIERef &ref, raw_ostream &OS, StringRef Style);
101
};
102
} // namespace llvm
103
104
#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DIEREF_H