LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
DWARF/types/ClassLike.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_STRUCTURE_H
16#define LIEF_DWARF_TYPE_STRUCTURE_H
17
18#include "LIEF/visibility.h"
20#include "LIEF/DWARF/Type.hpp"
22
23namespace LIEF {
24namespace dwarf {
25namespace types {
26
27namespace details {
28class Member;
29}
30
33class LIEF_API ClassLike : public Type {
34 public:
35 template<typename... Args,
36 typename = typename std::
37 enable_if<std::is_constructible<Type, Args&&...>::value>::type>
38 ClassLike(Args&&... args) :
39 Type(std::forward<Args>(args)...) {}
40
43 public:
44 Member(std::unique_ptr<details::Member> impl);
45 Member(Member&& other) noexcept;
46 Member& operator=(Member&& other) noexcept;
47
48 Member(const Member&) = delete;
49 Member& operator=(const Member&) = delete;
50
52 std::string name() const;
53
58
75
79
81 std::unique_ptr<Type> type() const LIEF_LIFETIMEBOUND;
82
83 bool is_external() const;
84
85 bool is_declaration() const;
86
88
89 private:
90 std::unique_ptr<details::Member> impl_;
91 };
92
93 ClassLike(const ClassLike&) = delete;
94 ClassLike& operator=(const ClassLike&) = delete;
95
96 ClassLike(ClassLike&&) noexcept = default;
97 ClassLike& operator=(ClassLike&&) noexcept = default;
98
100
101 static bool classof(const Type* type) {
102 const auto kind = type->kind();
105 }
106
108 std::vector<Member> members() const LIEF_LIFETIMEBOUND;
109
111 std::unique_ptr<Member> find_member(uint64_t offset) const LIEF_LIFETIMEBOUND;
112
115
116 ~ClassLike() override;
117};
118
121 public:
122 template<typename... Args,
123 typename = typename std::
124 enable_if<std::is_constructible<ClassLike, Args&&...>::value>::type>
125 Structure(Args&&... args) :
126 ClassLike(std::forward<Args>(args)...) {}
127
128 Structure(const Structure&) = delete;
129 Structure& operator=(const Structure&) = delete;
130
131 Structure(Structure&&) noexcept = default;
132 Structure& operator=(Structure&&) noexcept = default;
133
134 static bool classof(const Type* type) {
135 return type->kind() == Type::KIND::STRUCT;
136 }
137
138 ~Structure() override;
139};
140
142class LIEF_API Class : public ClassLike {
143 public:
144 template<typename... Args,
145 typename = typename std::
146 enable_if<std::is_constructible<ClassLike, Args&&...>::value>::type>
147 Class(Args&&... args) :
148 ClassLike(std::forward<Args>(args)...) {}
149
150 Class(const Class&) = delete;
151 Class& operator=(const Class&) = delete;
152
153 Class(Class&&) noexcept = default;
154 Class& operator=(Class&&) noexcept = default;
155
156 static bool classof(const Type* type) {
157 return type->kind() == Type::KIND::CLASS;
158 }
159
160 ~Class() override;
161};
162
164class LIEF_API Union : public ClassLike {
165 public:
166 template<typename... Args,
167 typename = typename std::
168 enable_if<std::is_constructible<ClassLike, Args&&...>::value>::type>
169 Union(Args&&... args) :
170 ClassLike(std::forward<Args>(args)...) {}
171
172 Union(const Union&) = delete;
173 Union& operator=(const Union&) = delete;
174
175 Union(Union&&) noexcept = default;
176 Union& operator=(Union&&) noexcept = default;
177
178 static bool classof(const Type* type) {
179 return type->kind() == Type::KIND::UNION;
180 }
181
182 ~Union() override;
183};
184
186class LIEF_API Packed : public ClassLike {
187 public:
188 template<typename... Args,
189 typename = typename std::
190 enable_if<std::is_constructible<ClassLike, Args&&...>::value>::type>
191 Packed(Args&&... args) :
192 ClassLike(std::forward<Args>(args)...) {}
193
194 Packed(const Packed&) = delete;
195 Packed& operator=(const Packed&) = delete;
196
197 Packed(Packed&&) noexcept = default;
198 Packed& operator=(Packed&&) noexcept = default;
199
200 static bool classof(const Type* type) {
201 return type->kind() == Type::KIND::PACKED;
202 }
203
204 ~Packed() override;
205};
206
207}
208}
209}
210#endif
This class represents a DWARF function which can be associated with either: DW_TAG_subprogram or DW_T...
Definition DWARF/Function.hpp:45
Definition DWARF/Type.hpp:71
KIND kind() const
@ PACKED
Definition DWARF/Type.hpp:143
@ STRUCT
Definition DWARF/Type.hpp:135
@ CLASS
Definition DWARF/Type.hpp:132
@ UNION
Definition DWARF/Type.hpp:136
Type(std::unique_ptr< details::Type > impl)
This represents a class/struct/union attribute.
Definition DWARF/types/ClassLike.hpp:42
result< uint64_t > bit_size() const
If the current member is a bit-field, this function returns its size in bits.
Member(std::unique_ptr< details::Member > impl)
std::unique_ptr< Type > type() const
Type of the current member.
Member & operator=(Member &&other) noexcept
Member(Member &&other) noexcept
std::string name() const
Name of the member.
result< uint64_t > offset() const
Offset of the current member in the struct/union/class.
result< uint64_t > bit_offset() const
Offset of the current member in bits in the struct/union/class.
Member & operator=(const Member &)=delete
iterator_range< Function::Iterator > functions_it
Definition DWARF/types/ClassLike.hpp:99
functions_it functions() const
Iterator over the functions defined by the class-like.
std::vector< Member > members() const
Return the list of all the attributes defined in this class-like type.
std::unique_ptr< Member > find_member(uint64_t offset) const
Try to find the attribute at the given offset.
ClassLike(Args &&... args)
Definition DWARF/types/ClassLike.hpp:38
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:101
Class(Args &&... args)
Definition DWARF/types/ClassLike.hpp:147
Class & operator=(const Class &)=delete
Class(Class &&) noexcept=default
Class(const Class &)=delete
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:156
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:200
Packed & operator=(const Packed &)=delete
Packed(Packed &&) noexcept=default
Packed(Args &&... args)
Definition DWARF/types/ClassLike.hpp:191
Packed(const Packed &)=delete
Structure(Args &&... args)
Definition DWARF/types/ClassLike.hpp:125
Structure(Structure &&) noexcept=default
Structure(const Structure &)=delete
Structure & operator=(const Structure &)=delete
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:134
Union(Union &&) noexcept=default
Union(const Union &)=delete
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:178
Union & operator=(const Union &)=delete
Union(Args &&... args)
Definition DWARF/types/ClassLike.hpp:169
Definition iterators.hpp:601
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:78
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DWARF/types/ClassLike.hpp:27
Definition DWARF/types/Array.hpp:24
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:30
LIEF namespace.
Definition Abstract/Binary.hpp:41
#define LIEF_API
Definition visibility.h:45