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"
14#include <cassert>
15#include <optional>
16
17/// Identifies a DWARF debug info entry within a given Module. It contains three
18/// "coordinates":
19/// - file_index: identifies the separate stand alone debug info file
20/// that is referred to by the main debug info file. This will be the
21/// index of a DWO file for fission, or the .o file on mac when not
22/// using a dSYM file. If this field is not set, then this references
23/// a DIE inside the original object file.
24/// - section: identifies the section of the debug info entry in the given file:
25/// debug_info or debug_types.
26/// - die_offset: The offset of the debug info entry as an absolute offset from
27/// the beginning of the section specified in the section field.
28class DIERef {
29public:
30 enum Section : uint8_t { DebugInfo, DebugTypes };
31 DIERef(std::optional<uint32_t> file_index, Section section,
35 assert(this->file_index() == file_index && "File Index is out of range?");
36 }
37
38 explicit DIERef(lldb::user_id_t uid) {
43 : 0;
44 m_section =
46 }
47
50 return LLDB_INVALID_UID;
51
52 return lldb::user_id_t(file_index().value_or(0)) << k_die_offset_bit_size |
55 }
56
57 std::optional<uint32_t> file_index() const {
59 return m_file_index;
60 return std::nullopt;
61 }
62
63 Section section() const { return static_cast<Section>(m_section); }
64
66
67 bool operator<(DIERef other) const {
71 return m_file_index < other.m_file_index;
72 if (m_section != other.m_section)
73 return m_section < other.m_section;
74 return m_die_offset < other.m_die_offset;
75 }
76
77 bool operator==(const DIERef &rhs) const {
78 return file_index() == rhs.file_index() && m_section == rhs.m_section &&
80 }
81
82 bool operator!=(const DIERef &rhs) const { return !(*this == rhs); }
83
84 /// Decode a serialized version of this object from data.
85 ///
86 /// \param data
87 /// The decoder object that references the serialized data.
88 ///
89 /// \param offset_ptr
90 /// A pointer that contains the offset from which the data will be decoded
91 /// from that gets updated as data gets decoded.
92 ///
93 /// \return
94 /// Returns a valid DIERef if decoding succeeded, std::nullopt if there was
95 /// unsufficient or invalid values that were decoded.
96 static std::optional<DIERef> Decode(const lldb_private::DataExtractor &data,
97 lldb::offset_t *offset_ptr);
98
99 /// Encode this object into a data encoder object.
100 ///
101 /// This allows this object to be serialized to disk.
102 ///
103 /// \param encoder
104 /// A data encoder object that serialized bytes will be encoded into.
105 ///
106 void Encode(lldb_private::DataEncoder &encoder) const;
107
109 static constexpr uint64_t k_file_index_bit_size =
110 64 - DW_DIE_OFFSET_MAX_BITSIZE - /* size of control bits */ 2;
111
112 static constexpr uint64_t k_file_index_valid_bit =
114 static constexpr uint64_t k_section_bit =
116 static constexpr uint64_t
117 k_file_index_mask = (~0ull) >> (64 - k_file_index_bit_size); // 0x3fffff;
118 static constexpr uint64_t k_die_offset_mask = (~0ull) >>
120
121private:
122 // Allow 2TB of .debug_info/.debug_types offset
124 // Used for DWO index or for .o file index on mac
126 // Set to 1 if m_file_index is a DWO number
128 // Set to 0 for .debug_info 1 for .debug_types,
130};
131static_assert(sizeof(DIERef) == 8);
132
133typedef std::vector<DIERef> DIEArray;
134
135namespace llvm {
136template<> struct format_provider<DIERef> {
137 static void format(const DIERef &ref, raw_ostream &OS, StringRef Style);
138};
139} // namespace llvm
140
141#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DIEREF_H
std::vector< DIERef > DIEArray
Definition: DIERef.h:133
Identifies a DWARF debug info entry within a given Module.
Definition: DIERef.h:28
static constexpr uint64_t k_file_index_bit_size
Definition: DIERef.h:109
DIERef(lldb::user_id_t uid)
Definition: DIERef.h:38
static constexpr uint64_t k_file_index_valid_bit
Definition: DIERef.h:112
dw_offset_t m_file_index_valid
Definition: DIERef.h:127
static constexpr uint64_t k_file_index_mask
Definition: DIERef.h:117
bool operator==(const DIERef &rhs) const
Definition: DIERef.h:77
std::optional< uint32_t > file_index() const
Definition: DIERef.h:57
Section
Definition: DIERef.h:30
@ DebugInfo
Definition: DIERef.h:30
@ DebugTypes
Definition: DIERef.h:30
bool operator<(DIERef other) const
Definition: DIERef.h:67
dw_offset_t m_die_offset
Definition: DIERef.h:123
lldb::user_id_t get_id() const
Definition: DIERef.h:48
static std::optional< DIERef > Decode(const lldb_private::DataExtractor &data, lldb::offset_t *offset_ptr)
Decode a serialized version of this object from data.
Definition: DIERef.cpp:26
dw_offset_t m_file_index
Definition: DIERef.h:125
void Encode(lldb_private::DataEncoder &encoder) const
Encode this object into a data encoder object.
Definition: DIERef.cpp:38
DIERef(std::optional< uint32_t > file_index, Section section, dw_offset_t die_offset)
Definition: DIERef.h:31
bool operator!=(const DIERef &rhs) const
Definition: DIERef.h:82
static constexpr uint64_t k_die_offset_bit_size
Definition: DIERef.h:108
dw_offset_t die_offset() const
Definition: DIERef.h:65
Section section() const
Definition: DIERef.h:63
dw_offset_t m_section
Definition: DIERef.h:129
static constexpr uint64_t k_die_offset_mask
Definition: DIERef.h:118
static constexpr uint64_t k_section_bit
Definition: DIERef.h:114
An binary data encoding class.
Definition: DataEncoder.h:42
An data extractor class.
Definition: DataExtractor.h:48
uint64_t dw_offset_t
Definition: dwarf.h:31
#define DW_DIE_OFFSET_MAX_BITSIZE
Definition: dwarf.h:35
#define LLDB_INVALID_UID
Definition: lldb-defines.h:82
uint64_t offset_t
Definition: lldb-types.h:83
uint64_t user_id_t
Definition: lldb-types.h:80
Definition: Debugger.h:53