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