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"
19#include "LIEF/DWARF/Type.hpp"
21
22namespace LIEF {
23namespace dwarf {
24namespace types {
25
26namespace details {
27class Member;
28}
29
32class LIEF_API ClassLike : public Type {
33 public:
34 template<typename... Args,
35 typename = typename std::
36 enable_if<std::is_constructible<Type, Args&&...>::value>::type>
37 ClassLike(Args&&... args) :
38 Type(std::forward<Args>(args)...) {}
39
42 public:
43 Member(std::unique_ptr<details::Member> impl);
44 Member(Member&& other) noexcept;
45 Member& operator=(Member&& other) noexcept;
46
47 Member(const Member&) = delete;
48 Member& operator=(const Member&) = delete;
49
51 std::string name() const;
52
57
74
78
80 std::unique_ptr<Type> type() const;
81
82 bool is_external() const;
83
84 bool is_declaration() const;
85
87
88 private:
89 std::unique_ptr<details::Member> impl_;
90 };
91
92 ClassLike(const ClassLike&) = delete;
93 ClassLike& operator=(const ClassLike&) = delete;
94
95 ClassLike(ClassLike&&) noexcept = default;
96 ClassLike& operator=(ClassLike&&) noexcept = default;
97
99
100 static bool classof(const Type* type) {
101 const auto kind = type->kind();
104 }
105
107 std::vector<Member> members() const;
108
110 std::unique_ptr<Member> find_member(uint64_t offset) const;
111
114
115 ~ClassLike() override;
116};
117
120 public:
121 template<typename... Args,
122 typename = typename std::
123 enable_if<std::is_constructible<ClassLike, Args&&...>::value>::type>
124 Structure(Args&&... args) :
125 ClassLike(std::forward<Args>(args)...) {}
126
127 Structure(const Structure&) = delete;
128 Structure& operator=(const Structure&) = delete;
129
130 Structure(Structure&&) noexcept = default;
131 Structure& operator=(Structure&&) noexcept = default;
132
133 static bool classof(const Type* type) {
134 return type->kind() == Type::KIND::STRUCT;
135 }
136
137 ~Structure() override;
138};
139
141class LIEF_API Class : public ClassLike {
142 public:
143 template<typename... Args,
144 typename = typename std::
145 enable_if<std::is_constructible<ClassLike, Args&&...>::value>::type>
146 Class(Args&&... args) :
147 ClassLike(std::forward<Args>(args)...) {}
148
149 Class(const Class&) = delete;
150 Class& operator=(const Class&) = delete;
151
152 Class(Class&&) noexcept = default;
153 Class& operator=(Class&&) noexcept = default;
154
155 static bool classof(const Type* type) {
156 return type->kind() == Type::KIND::CLASS;
157 }
158
159 ~Class() override;
160};
161
163class LIEF_API Union : public ClassLike {
164 public:
165 template<typename... Args,
166 typename = typename std::
167 enable_if<std::is_constructible<ClassLike, Args&&...>::value>::type>
168 Union(Args&&... args) :
169 ClassLike(std::forward<Args>(args)...) {}
170
171 Union(const Union&) = delete;
172 Union& operator=(const Union&) = delete;
173
174 Union(Union&&) noexcept = default;
175 Union& operator=(Union&&) noexcept = default;
176
177 static bool classof(const Type* type) {
178 return type->kind() == Type::KIND::UNION;
179 }
180
181 ~Union() override;
182};
183
185class LIEF_API Packed : public ClassLike {
186 public:
187 template<typename... Args,
188 typename = typename std::
189 enable_if<std::is_constructible<ClassLike, Args&&...>::value>::type>
190 Packed(Args&&... args) :
191 ClassLike(std::forward<Args>(args)...) {}
192
193 Packed(const Packed&) = delete;
194 Packed& operator=(const Packed&) = delete;
195
196 Packed(Packed&&) noexcept = default;
197 Packed& operator=(Packed&&) noexcept = default;
198
199 static bool classof(const Type* type) {
200 return type->kind() == Type::KIND::PACKED;
201 }
202
203 ~Packed() override;
204};
205
206}
207}
208}
209#endif
This class represents a DWARF function which can be associated with either: DW_TAG_subprogram or DW_T...
Definition DWARF/Function.hpp:43
Definition DWARF/Type.hpp:70
KIND kind() const
@ PACKED
Definition DWARF/Type.hpp:142
@ STRUCT
Definition DWARF/Type.hpp:134
@ CLASS
Definition DWARF/Type.hpp:131
@ UNION
Definition DWARF/Type.hpp:135
Type(std::unique_ptr< details::Type > impl)
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:98
functions_it functions() const
Iterator over the functions defined by the class-like.
ClassLike(const ClassLike &)=delete
ClassLike(ClassLike &&) noexcept=default
ClassLike & operator=(const ClassLike &)=delete
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:37
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:100
Class(Args &&... args)
Definition DWARF/types/ClassLike.hpp:146
Class & operator=(const Class &)=delete
Class(Class &&) noexcept=default
Class(const Class &)=delete
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:155
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:199
Packed & operator=(const Packed &)=delete
Packed(Packed &&) noexcept=default
Packed(Args &&... args)
Definition DWARF/types/ClassLike.hpp:190
Packed(const Packed &)=delete
Structure(Args &&... args)
Definition DWARF/types/ClassLike.hpp:124
Structure(Structure &&) noexcept=default
Structure(const Structure &)=delete
Structure & operator=(const Structure &)=delete
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:133
Union(Union &&) noexcept=default
Union(const Union &)=delete
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:177
Union & operator=(const Union &)=delete
Union(Args &&... args)
Definition DWARF/types/ClassLike.hpp:168
Definition iterators.hpp:601
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:77
Definition DWARF/types/ClassLike.hpp:26
Definition DWARF/types/Array.hpp:23
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:28
LIEF namespace.
Definition Abstract/Binary.hpp:40
#define LIEF_API
Definition visibility.h:45