LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
PDB/Function.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2025 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_PDB_FUNCTION_H
16#define LIEF_PDB_FUNCTION_H
17#include <memory>
18#include <string>
19#include <ostream>
20
21#include "LIEF/visibility.h"
22#include "LIEF/debug_loc.hpp"
23
24namespace LIEF {
25namespace pdb {
26
27namespace details {
28class Function;
29class FunctionIt;
30}
31
33 public:
34 class LIEF_API Iterator {
35 public:
36 using iterator_category = std::forward_iterator_tag;
37 using value_type = std::unique_ptr<Function>;
38 using difference_type = std::ptrdiff_t;
39 using pointer = Function*;
40 using reference = Function&;
41 using implementation = details::FunctionIt;
42
43 class LIEF_API PointerProxy {
44 // Inspired from LLVM's iterator_facade_base
45 friend class Iterator;
46 public:
47 pointer operator->() const { return R.get(); }
48
49 private:
50 value_type R;
51
52 template <typename RefT>
53 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
54 };
55
56 Iterator(const Iterator&);
57 Iterator(Iterator&&);
58 Iterator(std::unique_ptr<details::FunctionIt> impl);
60
61 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
62 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
63 return !(LHS == RHS);
64 }
65
66 Iterator& operator++();
67
68 Iterator operator++(int) {
69 Iterator tmp = *static_cast<Iterator*>(this);
70 ++*static_cast<Iterator *>(this);
71 return tmp;
72 }
73
74 std::unique_ptr<Function> operator*() const;
75
76 PointerProxy operator->() const {
77 return static_cast<const Iterator*>(this)->operator*();
78 }
79
80 private:
81 std::unique_ptr<details::FunctionIt> impl_;
82 };
83 Function(std::unique_ptr<details::Function> impl);
85 std::string name() const;
88 uint32_t RVA() const;
91 uint32_t code_size() const;
94 std::string section_name() const;
97 debug_location_t debug_location() const;
100
101 std::string to_string() const;
102
103 LIEF_API friend
104 std::ostream& operator<<(std::ostream& os, const Function& F)
105 {
106 os << F.to_string();
107 return os;
108 }
109
110 private:
111 std::unique_ptr<details::Function> impl_;
112};
113
114}
115}
116#endif
117
pointer operator->() const
Definition PDB/Function.hpp:47
Iterator operator++(int)
Definition PDB/Function.hpp:68
friend bool operator==(const Iterator &LHS, const Iterator &RHS)
Iterator(const Iterator &)
std::unique_ptr< Function > operator*() const
PointerProxy operator->() const
Definition PDB/Function.hpp:76
friend bool operator!=(const Iterator &LHS, const Iterator &RHS)
Definition PDB/Function.hpp:62
Iterator(std::unique_ptr< details::FunctionIt > impl)
Definition PDB/Function.hpp:32
std::string section_name() const
The name of the section in which this function is defined.
friend std::ostream & operator<<(std::ostream &os, const Function &F)
Definition PDB/Function.hpp:104
uint32_t code_size() const
The size of the function.
Function(std::unique_ptr< details::Function > impl)
std::string name() const
The name of the function (this name is usually demangled)
debug_location_t debug_location() const
Original source code location.
uint32_t RVA() const
The Relative Virtual Address of the function.
std::string to_string() const
Definition BuildMetadata.hpp:26
Definition BuildMetadata.hpp:24
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41