LLDB  mainline
DIERef.h
Go to the documentation of this file.
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,
32  : m_dwo_num(dwo_num.getValueOr(0)), m_dwo_num_valid(bool(dwo_num)),
34  assert(this->dwo_num() == dwo_num && "Dwo number out of range?");
35  }
36 
37  llvm::Optional<uint32_t> dwo_num() const {
38  if (m_dwo_num_valid)
39  return m_dwo_num;
40  return llvm::None;
41  }
42 
43  Section section() const { return static_cast<Section>(m_section); }
44 
45  dw_offset_t die_offset() const { return m_die_offset; }
46 
47  bool operator<(DIERef other) const {
48  if (m_dwo_num_valid != other.m_dwo_num_valid)
49  return m_dwo_num_valid < other.m_dwo_num_valid;
50  if (m_dwo_num_valid && (m_dwo_num != other.m_dwo_num))
51  return m_dwo_num < other.m_dwo_num;
52  if (m_section != other.m_section)
53  return m_section < other.m_section;
54  return m_die_offset < other.m_die_offset;
55  }
56 
57 private:
62 };
63 static_assert(sizeof(DIERef) == 8, "");
64 
65 typedef std::vector<DIERef> DIEArray;
66 
67 namespace llvm {
68 template<> struct format_provider<DIERef> {
69  static void format(const DIERef &ref, raw_ostream &OS, StringRef Style);
70 };
71 } // namespace llvm
72 
73 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DIEREF_H
DIERef
Identifies a DWARF debug info entry within a given Module.
Definition: DIERef.h:26
llvm
Definition: Debugger.h:49
DIERef::m_section
uint32_t m_section
Definition: DIERef.h:60
DIERef::DebugTypes
@ DebugTypes
Definition: DIERef.h:28
DIERef::die_offset
dw_offset_t die_offset() const
Definition: DIERef.h:45
DIEArray
std::vector< DIERef > DIEArray
Definition: DIERef.h:63
DIERef::m_die_offset
dw_offset_t m_die_offset
Definition: DIERef.h:61
DIERef::DebugInfo
@ DebugInfo
Definition: DIERef.h:28
DIERef::operator<
bool operator<(DIERef other) const
Definition: DIERef.h:47
dwarf.h
uint32_t
DIERef::section
Section section() const
Definition: DIERef.h:43
DIERef::m_dwo_num
uint32_t m_dwo_num
Definition: DIERef.h:58
DIERef::dwo_num
llvm::Optional< uint32_t > dwo_num() const
Definition: DIERef.h:37
DIERef::DIERef
DIERef(llvm::Optional< uint32_t > dwo_num, Section section, dw_offset_t die_offset)
Definition: DIERef.h:30
DIERef::Section
Section
Definition: DIERef.h:28
DIERef::m_dwo_num_valid
uint32_t m_dwo_num_valid
Definition: DIERef.h:59