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:
45 class Iterator final
46 : public iterator_facade_base<Iterator, std::bidirectional_iterator_tag,
47 Function, std::ptrdiff_t, const Function*,
48 const Function&> {
49 public:
50 using implementation = details::FunctionIt;
51 using iterator_facade_base::operator++;
52 using iterator_facade_base::operator--;
53
55
56 LIEF_API Iterator(std::unique_ptr<details::FunctionIt> impl);
57
60
62 LIEF_API Iterator& operator=(Iterator&&) noexcept;
63
65
66 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
67
68 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
69 return !(LHS == RHS);
70 }
71
72 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
74
75 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
77
78 LIEF_API const Function& operator*() const;
79
80 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
82
85 LIEF_API std::unique_ptr<Function> yield();
86
87 private:
88 void load() const;
89
90 std::unique_ptr<details::FunctionIt> impl_;
91 mutable std::unique_ptr<Function> cached_;
92 };
93
96 using parameters_t = std::vector<std::unique_ptr<Parameter>>;
97 using thrown_types_t = std::vector<std::unique_ptr<Type>>;
98
100
102
103 Function(std::unique_ptr<details::Function> impl);
104
106 std::string name() const;
107
112 std::string linkage_name() const;
113
116
121
124 bool is_artificial() const;
125
128 bool is_external() const;
129
131 uint64_t size() const;
132
134 std::vector<range_t> ranges() const;
135
138
141 std::unique_ptr<Type> type() const;
142
145
159
161 std::unique_ptr<Scope> scope() const;
162
166
169
171 std::string description() const;
172
174 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
175
177
178 private:
179 std::unique_ptr<details::Function> impl_;
180};
181
182}
183}
184#endif
details::FunctionIt implementation
Definition DWARF/Function.hpp:50
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...
const Function * operator->() const
Iterator & operator=(const Iterator &)
Iterator(std::unique_ptr< details::FunctionIt > impl)
iterator_range< assembly::Instruction::Iterator > instructions_it
Definition DWARF/Function.hpp:101
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:96
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:97
iterator_range< Variable::Iterator > vars_it
Iterator over the variables defined in the scope of this function.
Definition DWARF/Function.hpp:95
iterator_range< LexicalBlock::Iterator > lexical_blocks_it
Definition DWARF/Function.hpp:99
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
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:77
Definition DWARF/CompilationUnit.hpp:30
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:28
LIEF namespace.
Definition Abstract/Binary.hpp:40
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:45