LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
DWARF/Function.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_FUNCTION_H
16#define LIEF_DWARF_FUNCTION_H
17
18#include <string_view>
19#include <memory>
20#include <string>
21
23#include "LIEF/errors.hpp"
24#include "LIEF/iterators.hpp"
25#include "LIEF/visibility.h"
26
28#include "LIEF/DWARF/Type.hpp"
31#include "LIEF/range.hpp"
32
33
34namespace LIEF::dwarf {
35
36class Scope;
37class Parameter;
38
39namespace details {
40class Function;
41class FunctionIt;
42}
43
47 public:
48 class Iterator final
49 : public iterator_facade_base<Iterator, std::bidirectional_iterator_tag,
50 Function, std::ptrdiff_t, const Function*,
51 const Function&> {
52 public:
53 using implementation = details::FunctionIt;
54 using iterator_facade_base::operator++;
55 using iterator_facade_base::operator--;
56
58
59 LIEF_API Iterator(std::unique_ptr<details::FunctionIt> impl);
60
63
65 LIEF_API Iterator& operator=(Iterator&&) noexcept;
66
68
69 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
70
71 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
72 return !(LHS == RHS);
73 }
74
75 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
77
78 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
80
82
83 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
84 LIEF_API const Function* operator->() const LIEF_LIFETIMEBOUND;
85
88 LIEF_API std::unique_ptr<Function> yield();
89
90 private:
91 void load() const;
92
93 std::unique_ptr<details::FunctionIt> impl_;
94 mutable std::unique_ptr<Function> cached_;
95 };
96
99 using parameters_t = std::vector<std::unique_ptr<Parameter>>;
100 using thrown_types_t = std::vector<std::unique_ptr<Type>>;
101
103
105
106 Function(std::unique_ptr<details::Function> impl);
107
109 std::string_view name() const LIEF_LIFETIMEBOUND;
110
115 std::string_view linkage_name() const LIEF_LIFETIMEBOUND;
116
118 result<uint64_t> address() const;
119
124
127 bool is_artificial() const;
128
131 bool is_external() const;
132
134 uint64_t size() const;
135
137 std::vector<range_t> ranges() const;
138
141
144 std::unique_ptr<Type> type() const LIEF_LIFETIMEBOUND;
145
148
162
164 std::unique_ptr<Scope> scope() const LIEF_LIFETIMEBOUND;
165
169
172
174 std::string_view description() const LIEF_LIFETIMEBOUND;
175
177 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
178
180
181 private:
182 std::unique_ptr<details::Function> impl_;
183};
184
185}
186
187#endif
Configuration options for generated code from debug info.
Definition DebugDeclOpt.hpp:37
Definition DWARF/Function.hpp:51
details::FunctionIt implementation
Definition DWARF/Function.hpp:53
Iterator(Iterator &&) noexcept
const Function & operator*() const
std::unique_ptr< Function > yield()
Transfer ownership of the function at the current position to the caller. Returns nullptr if the iter...
Iterator & operator=(const Iterator &)
Iterator(std::unique_ptr< details::FunctionIt > impl)
iterator_range< assembly::Instruction::Iterator > instructions_it
Definition DWARF/Function.hpp:104
std::string_view description() const
Description (DW_AT_description) of this function or an empty string.
instructions_it instructions() const
Disassemble the current function by returning an iterator over the assembly::Instruction.
std::vector< std::unique_ptr< Parameter > > parameters_t
Definition DWARF/Function.hpp:99
vars_it variables() const
Return an iterator of variables (DW_TAG_variable) defined within the scope of this function....
lexical_blocks_it lexical_blocks() const
Iterator over the LexicalBlock owned by this function.
thrown_types_t thrown_types() const
List of exceptions (types) that can be thrown by the function.
std::unique_ptr< Type > type() const
Return the dwarf::Type associated with the return type of this function.
std::unique_ptr< Scope > scope() const
Return the scope in which this function is defined.
Function(std::unique_ptr< details::Function > impl)
std::string_view linkage_name() const
The name of the function which is used for linking (DW_AT_linkage_name).
bool is_external() const
Whether the function is defined outside the current compilation unit (DW_AT_external).
result< uint64_t > address() const
Return the address of the function (DW_AT_entry_pc or DW_AT_low_pc).
std::vector< std::unique_ptr< Type > > thrown_types_t
Definition DWARF/Function.hpp:100
iterator_range< Variable::Iterator > vars_it
Iterator over the variables defined in the scope of this function.
Definition DWARF/Function.hpp:98
iterator_range< LexicalBlock::Iterator > lexical_blocks_it
Definition DWARF/Function.hpp:102
std::string to_decl(const DeclOpt &opt=DeclOpt()) const
Generates a C/C++ definition for this function.
debug_location_t debug_location() const
Original source code location.
std::vector< range_t > ranges() const
Ranges of virtual addresses owned by this function.
parameters_t parameters() const
Return the function's parameters (including any template parameter).
std::string_view name() const
The name of the function (DW_AT_name).
uint64_t size() const
Return the size taken by this function in the binary.
bool is_artificial() const
Whether this function is created by the compiler and not present in the original source code.
This class represents a DWARF lexical block (DW_TAG_lexical_block).
Definition LexicalBlock.hpp:37
This class represents a DWARF parameter which can be either:
Definition Parameter.hpp:40
This class materializes a scope in which Function, Variable, Type, ... can be defined.
Definition Scope.hpp:35
This class represents a DWARF Type which includes:
Definition DWARF/Type.hpp:68
This class represents a DWARF variable which can be owned by a dwarf::Function or a dwarf::Compilatio...
Definition Variable.hpp:41
Definition iterators.hpp:595
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:79
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Namespace related to assembly/disassembly support.
Definition Abstract/Binary.hpp:49
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
Definition range.hpp:23
#define LIEF_API
Definition visibility.h:45