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