LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
DWARF/Type.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2026 R. Thomas
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_DWARF_TYPE_H
16#define LIEF_DWARF_TYPE_H
17
18#include <string_view>
19#include <memory>
20
21#include "LIEF/DebugDeclOpt.hpp"
22#include "LIEF/canbe_unique.hpp"
24#include "LIEF/debug_loc.hpp"
25#include "LIEF/errors.hpp"
26#include "LIEF/iterators.hpp"
27#include "LIEF/visibility.h"
28
29
30namespace LIEF::dwarf {
31class Scope;
32
33namespace details {
34class Type;
35class TypeIt;
36}
37
69 public:
70 class Iterator final
71 : public iterator_facade_base<Iterator, std::bidirectional_iterator_tag, Type,
72 std::ptrdiff_t, const Type*, const Type&> {
73 public:
74 using implementation = details::TypeIt;
75 using iterator_facade_base::operator++;
76 using iterator_facade_base::operator--;
77
79
80 LIEF_API Iterator(std::unique_ptr<details::TypeIt> impl);
81
84
86 LIEF_API Iterator& operator=(Iterator&&) noexcept;
87
89
90 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
91 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
92 return !(LHS == RHS);
93 }
94
95 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
97
98 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
100
102
103 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
104 LIEF_API const Type* operator->() const LIEF_LIFETIMEBOUND;
105
108 LIEF_API std::unique_ptr<Type> yield();
109
110 private:
111 void load() const;
112
113 std::unique_ptr<details::TypeIt> impl_;
114 mutable std::unique_ptr<Type> cached_;
115 };
116
117 LIEF_LOCAL Type(std::unique_ptr<details::Type> impl);
119
120 Type(const Type&) = delete;
121 Type& operator=(const Type&) = delete;
122
123 Type(Type&&) noexcept;
124 Type& operator=(Type&&) noexcept;
125
126 virtual ~Type();
127
128 enum class KIND {
129 UNKNOWN = 0,
130 UNSPECIFIED,
131 BASE,
132 CONST_KIND,
133 CLASS,
134 ARRAY,
135 POINTER,
136 STRUCT,
137 UNION,
138 TYPEDEF,
139 REF,
140 SET_TYPE,
141 STRING,
142 SUBROUTINE,
143 POINTER_MEMBER,
144 PACKED,
145 FILE,
146 THROWN,
147 VOLATILE,
148 RESTRICT,
149 INTERFACE,
150 SHARED,
151 RVALREF,
152 TEMPLATE_ALIAS,
153 COARRAY,
154 DYNAMIC,
155 ATOMIC,
156 IMMUTABLE,
157 ENUM,
158 };
159
160 KIND kind() const;
161
163 bool is_unspecified() const {
164 return kind() == KIND::UNSPECIFIED;
165 }
166
170
174 result<uint64_t> size() const;
175
178
180 std::unique_ptr<Scope> scope() const LIEF_LIFETIMEBOUND;
181
183 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
184
185 template<class T>
186 const T* as() const LIEF_LIFETIMEBOUND {
187 if (T::classof(this)) {
188 return static_cast<const T*>(this);
189 }
190 return nullptr;
191 }
192
193 static std::unique_ptr<Type>
194 create(std::unique_ptr<details::Type> impl LIEF_LIFETIMEBOUND);
195
196 protected:
198};
199
200}
201
202#endif
Configuration options for generated code from debug info.
Definition DebugDeclOpt.hpp:37
Definition canbe_unique.hpp:22
This class materializes a scope in which Function, Variable, Type, ... can be defined.
Definition Scope.hpp:35
Iterator(std::unique_ptr< details::TypeIt > impl)
Iterator(const Iterator &)
Iterator(Iterator &&) noexcept
std::unique_ptr< Type > yield()
Transfer ownership of the type at the current position to the caller. Returns nullptr if the iterator...
Iterator & operator=(const Iterator &)
const Type & operator*() const
details::TypeIt implementation
Definition DWARF/Type.hpp:74
const T * as() const
Definition DWARF/Type.hpp:186
bool is_unspecified() const
Whether this type is a DW_TAG_unspecified_type.
Definition DWARF/Type.hpp:163
KIND kind() const
KIND
Definition DWARF/Type.hpp:128
@ UNSPECIFIED
Definition DWARF/Type.hpp:130
Type(std::unique_ptr< details::Type > impl)
result< std::string_view > name() const
Return the type's name using either DW_AT_name or DW_AT_picture_string (if any).
result< uint64_t > size() const
Return the size of the type or an error if it can't be computed.
std::string to_decl(const DeclOpt &opt=DeclOpt()) const
Generates a C/C++ definition for this type.
debug_location_t location() const
Return the debug location where this type is defined.
static std::unique_ptr< Type > create(std::unique_ptr< details::Type > impl)
std::unique_ptr< Scope > scope() const
Return the scope in which this type is defined.
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:79
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DWARF/CompilationUnit.hpp:33
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:31
This structure holds a debug location (source filename & line).
Definition debug_loc.hpp:23
#define LIEF_API
Definition visibility.h:45
#define LIEF_LOCAL
Definition visibility.h:46