LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
DWARF/Function.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2024 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"
27
28namespace LIEF {
29namespace dwarf {
30
31class Scope;
32
33namespace details {
34class Function;
35class Parameter;
36class FunctionIt;
37}
38
42 public:
44 public:
45 using iterator_category = std::bidirectional_iterator_tag;
46 using value_type = std::unique_ptr<Function>;
47 using difference_type = std::ptrdiff_t;
48 using pointer = Function*;
49 using reference = std::unique_ptr<Function>&;
50 using implementation = details::FunctionIt;
51
53 // Inspired from LLVM's iterator_facade_base
54 friend class Iterator;
55 public:
56 pointer operator->() const { return R.get(); }
57
58 private:
59 value_type R;
60
61 template <typename RefT>
62 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
63 };
64
66 Iterator(Iterator&&) noexcept;
67 Iterator(std::unique_ptr<details::FunctionIt> impl);
69
70 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
71
72 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
73 return !(LHS == RHS);
74 }
75
78
80 Iterator tmp = *static_cast<Iterator*>(this);
81 --*static_cast<Iterator *>(this);
82 return tmp;
83 }
84
86 Iterator tmp = *static_cast<Iterator*>(this);
87 ++*static_cast<Iterator *>(this);
88 return tmp;
89 }
90
91 std::unique_ptr<Function> operator*() const;
92
94 return static_cast<const Iterator*>(this)->operator*();
95 }
96
97 private:
98 std::unique_ptr<details::FunctionIt> impl_;
99 };
100
102 class Parameter {
103 public:
104 Parameter(std::unique_ptr<details::Parameter> impl);
105 Parameter(Parameter&& other) noexcept;
106 Parameter& operator=(Parameter&& other) noexcept;
107
109 std::string name() const;
110
112 std::unique_ptr<Type> type() const;
113
115 private:
116 std::unique_ptr<details::Parameter> impl_;
117 };
118
120
121 Function(std::unique_ptr<details::Function> impl);
122
124 std::string name() const;
125
130 std::string linkage_name() const;
131
134
139
142 bool is_artificial() 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
158 std::vector<Parameter> parameters() const;
159
161 std::unique_ptr<Scope> scope() const;
162
164 private:
165 std::unique_ptr<details::Function> impl_;
166};
167
168}
169}
170#endif
Definition DWARF/Function.hpp:52
pointer operator->() const
Definition DWARF/Function.hpp:56
Definition DWARF/Function.hpp:43
Iterator operator++(int)
Definition DWARF/Function.hpp:85
details::FunctionIt implementation
Definition DWARF/Function.hpp:50
std::unique_ptr< Function > & reference
Definition DWARF/Function.hpp:49
std::unique_ptr< Function > operator*() const
Iterator(Iterator &&) noexcept
std::unique_ptr< Function > value_type
Definition DWARF/Function.hpp:46
std::ptrdiff_t difference_type
Definition DWARF/Function.hpp:47
Iterator operator--(int)
Definition DWARF/Function.hpp:79
std::bidirectional_iterator_tag iterator_category
Definition DWARF/Function.hpp:45
PointerProxy operator->() const
Definition DWARF/Function.hpp:93
This class wraps a DWARF function's parameter.
Definition DWARF/Function.hpp:102
std::unique_ptr< Type > type() const
Type of the parameter.
Parameter(Parameter &&other) noexcept
std::string name() const
Name of the parameter.
Parameter & operator=(Parameter &&other) noexcept
Parameter(std::unique_ptr< details::Parameter > impl)
This class represents a DWARF function which can be associated with either: DW_TAG_subprogram or DW_T...
Definition DWARF/Function.hpp:41
vars_it variables() const
Return an iterator of variables (DW_TAG_variable) defined within the scope of this function....
std::vector< Parameter > parameters() const
Return the function's parameters.
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)
result< uint64_t > address() const
Return the address of the function (DW_AT_entry_pc or DW_AT_low_pc).
debug_location_t debug_location() const
Original source code location.
std::vector< range_t > ranges() const
Ranges of virtual addresses owned by this function.
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).
bool is_artificial() const
Whether this function is created by the compiler and not present in the original source code.
Definition iterators.hpp:485
LIEF namespace.
Definition Abstract/Binary.hpp:32
tl::expected< T, lief_errors > result
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:74
This structure holds a debug location (source filename & line)
Definition debug_loc.hpp:23
#define LIEF_API
Definition visibility.h:41