LIEF: Library to Instrument Executable Formats Version 1.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 <memory>
19#include <string>
20
21#include "LIEF/visibility.h"
22#include "LIEF/errors.hpp"
23#include "LIEF/iterators.hpp"
25
26#include "LIEF/range.hpp"
28#include "LIEF/DWARF/Type.hpp"
31
32namespace LIEF {
33namespace dwarf {
34
35class Scope;
36class Parameter;
37
38namespace details {
39class Function;
40class FunctionIt;
41}
42
46 public:
47 class Iterator final
48 : public iterator_facade_base<Iterator, std::bidirectional_iterator_tag,
49 Function, std::ptrdiff_t, const Function*,
50 const Function&> {
51 public:
52 using implementation = details::FunctionIt;
53 using iterator_facade_base::operator++;
54 using iterator_facade_base::operator--;
55
57
58 LIEF_API Iterator(std::unique_ptr<details::FunctionIt> impl);
59
62
64 LIEF_API Iterator& operator=(Iterator&&) noexcept;
65
67
68 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
69
70 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
71 return !(LHS == RHS);
72 }
73
74 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
76
77 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
79
81
82 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
83 LIEF_API const Function* operator->() const LIEF_LIFETIMEBOUND;
84
87 LIEF_API std::unique_ptr<Function> yield();
88
89 private:
90 void load() const;
91
92 std::unique_ptr<details::FunctionIt> impl_;
93 mutable std::unique_ptr<Function> cached_;
94 };
95
98 using parameters_t = std::vector<std::unique_ptr<Parameter>>;
99 using thrown_types_t = std::vector<std::unique_ptr<Type>>;
100
102
104
105 Function(std::unique_ptr<details::Function> impl);
106
108 std::string name() const;
109
114 std::string linkage_name() const;
115
117 result<uint64_t> address() const;
118
123
126 bool is_artificial() const;
127
130 bool is_external() const;
131
133 uint64_t size() const;
134
136 std::vector<range_t> ranges() const;
137
140
143 std::unique_ptr<Type> type() const LIEF_LIFETIMEBOUND;
144
147
161
163 std::unique_ptr<Scope> scope() const LIEF_LIFETIMEBOUND;
164
168
171
173 std::string description() const;
174
176 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
177
179
180 private:
181 std::unique_ptr<details::Function> impl_;
182};
183
184}
185}
186#endif
Configuration options for generated code from debug info.
Definition DebugDeclOpt.hpp:36
Definition DWARF/Function.hpp:50
details::FunctionIt implementation
Definition DWARF/Function.hpp:52
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:103
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:98
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 name() const
The name of the function (DW_AT_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:99
iterator_range< Variable::Iterator > vars_it
Iterator over the variables defined in the scope of this function.
Definition DWARF/Function.hpp:97
iterator_range< LexicalBlock::Iterator > lexical_blocks_it
Definition DWARF/Function.hpp:101
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).
uint64_t size() const
Return the size taken by this function in the binary.
std::string linkage_name() const
The name of the function which is used for linking (DW_AT_linkage_name).
std::string description() const
Description (DW_AT_description) of this function or an empty string.
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:38
This class materializes a scope in which Function, Variable, Type, ... can be defined.
Definition Scope.hpp:33
This class represents a DWARF Type which includes:
Definition DWARF/Type.hpp:67
This class represents a DWARF variable which can be owned by a dwarf::Function or a dwarf::Compilatio...
Definition Variable.hpp:38
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition iterators.hpp:729
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
Namespace related to assembly/disassembly support.
Definition Abstract/Binary.hpp:48
Definition DWARF/CompilationUnit.hpp:32
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:30
LIEF namespace.
Definition Abstract/Binary.hpp:41
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