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"
24#include "LIEF/range.hpp"
26#include "LIEF/DWARF/Type.hpp"
29
30namespace LIEF {
31namespace dwarf {
32
33class Scope;
34class Parameter;
35
36namespace details {
37class Function;
38class FunctionIt;
39}
40
44 public:
46 public:
47 using iterator_category = std::bidirectional_iterator_tag;
48 using value_type = std::unique_ptr<Function>;
49 using difference_type = std::ptrdiff_t;
50 using pointer = Function*;
51 using reference = std::unique_ptr<Function>&;
52 using implementation = details::FunctionIt;
53
54 class LIEF_API PointerProxy {
55 // Inspired from LLVM's iterator_facade_base
56 friend class Iterator;
57
58 public:
60 return R.get();
61 }
62
63 private:
64 value_type R;
65
66 template<typename RefT>
67 PointerProxy(RefT&& R) :
68 R(std::forward<RefT>(R)) {
69 } // NOLINT(bugprone-forwarding-reference-overload)
70 };
71
73 Iterator(Iterator&&) noexcept;
74 Iterator(std::unique_ptr<details::FunctionIt> impl);
76
77 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
78
79 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
80 return !(LHS == RHS);
81 }
82
85
87 Iterator tmp = *static_cast<Iterator*>(this);
88 --*static_cast<Iterator*>(this);
89 return tmp;
90 }
91
93 Iterator tmp = *static_cast<Iterator*>(this);
94 ++*static_cast<Iterator*>(this);
95 return tmp;
96 }
97
98 std::unique_ptr<Function> operator*() const;
99
101 return static_cast<const Iterator*>(this)->operator*();
102 }
103
104 private:
105 std::unique_ptr<details::FunctionIt> impl_;
106 };
107
110 using parameters_t = std::vector<std::unique_ptr<Parameter>>;
111 using thrown_types_t = std::vector<std::unique_ptr<Type>>;
112
114
116
117 Function(std::unique_ptr<details::Function> impl);
118
120 std::string name() const;
121
126 std::string linkage_name() const;
127
130
135
138 bool is_artificial() const;
139
142 bool is_external() const;
143
145 uint64_t size() const;
146
148 std::vector<range_t> ranges() const;
149
152
155 std::unique_ptr<Type> type() const;
156
159
173
175 std::unique_ptr<Scope> scope() const;
176
180
183
185 std::string description() const;
186
188 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
189
191
192 private:
193 std::unique_ptr<details::Function> impl_;
194};
195
196}
197}
198#endif
Definition DWARF/Function.hpp:54
friend class Iterator
Definition DWARF/Function.hpp:56
pointer operator->() const
Definition DWARF/Function.hpp:59
Iterator operator++(int)
Definition DWARF/Function.hpp:92
details::FunctionIt implementation
Definition DWARF/Function.hpp:52
std::unique_ptr< Function > & reference
Definition DWARF/Function.hpp:51
std::unique_ptr< Function > operator*() const
Iterator(Iterator &&) noexcept
Function * pointer
Definition DWARF/Function.hpp:50
std::unique_ptr< Function > value_type
Definition DWARF/Function.hpp:48
std::ptrdiff_t difference_type
Definition DWARF/Function.hpp:49
Iterator operator--(int)
Definition DWARF/Function.hpp:86
std::bidirectional_iterator_tag iterator_category
Definition DWARF/Function.hpp:47
PointerProxy operator->() const
Definition DWARF/Function.hpp:100
iterator_range< assembly::Instruction::Iterator > instructions_it
Definition DWARF/Function.hpp:115
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:110
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:111
iterator_range< Variable::Iterator > vars_it
Iterator over the variables defined in the scope of this function.
Definition DWARF/Function.hpp:109
iterator_range< LexicalBlock::Iterator > lexical_blocks_it
Definition DWARF/Function.hpp:113
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 parameter which can be either:
Definition Parameter.hpp:37
This class materializes a scope in which Function, Variable, Type, ... can be defined.
Definition Scope.hpp:33
Definition iterators.hpp:567
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:77
Definition DWARF/CompilationUnit.hpp:30
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:28
LIEF namespace.
Definition Abstract/Binary.hpp:40
Definition string.h:155
Configuration options for generated code from debug info.
Definition DebugDeclOpt.hpp:25
This structure holds a debug location (source filename & line).
Definition debug_loc.hpp:23
#define LIEF_API
Definition visibility.h:43