LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
PDB/CompilationUnit.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_PDB_COMPILATION_UNIT_H
16#define LIEF_PDB_COMPILATION_UNIT_H
17#include <memory>
18#include <string>
19#include <vector>
20
21#include "LIEF/iterators.hpp"
22#include "LIEF/PDB/Function.hpp"
23
24#include "LIEF/visibility.h"
25
26namespace LIEF {
27namespace pdb {
28
29namespace details {
30class CompilationUnit;
31class CompilationUnitIt;
32}
36 public:
37 class LIEF_API Iterator {
38 public:
39 using iterator_category = std::bidirectional_iterator_tag;
40 using value_type = std::unique_ptr<CompilationUnit>;
41 using difference_type = std::ptrdiff_t;
42 using pointer = CompilationUnit*;
43 using reference = CompilationUnit&;
44 using implementation = details::CompilationUnitIt;
45
46 class PointerProxy {
47 // Inspired from LLVM's iterator_facade_base
48 friend class Iterator;
49 public:
50 pointer operator->() const { return R.get(); }
51
52 private:
53 value_type R;
54
55 template <typename RefT>
56 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
57 };
58
59 Iterator(const Iterator&);
60 Iterator(Iterator&&);
61 Iterator(std::unique_ptr<details::CompilationUnitIt> impl);
63
64 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
65 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
66 return !(LHS == RHS);
67 }
68
69 Iterator& operator++();
70 Iterator& operator--();
71
72 Iterator operator--(int) {
73 Iterator tmp = *static_cast<Iterator*>(this);
74 --*static_cast<Iterator *>(this);
75 return tmp;
76 }
77
78 Iterator operator++(int) {
79 Iterator tmp = *static_cast<Iterator*>(this);
80 ++*static_cast<Iterator *>(this);
81 return tmp;
82 }
83
84 std::unique_ptr<CompilationUnit> operator*() const;
85
86 PointerProxy operator->() const {
87 return static_cast<const Iterator*>(this)->operator*();
88 }
89
90 private:
91 std::unique_ptr<details::CompilationUnitIt> impl_;
92 };
93 using sources_iterator = iterator_range<std::vector<std::string>::const_iterator>;
96
97 using function_iterator = iterator_range<Function::Iterator>;
98
99 CompilationUnit(std::unique_ptr<details::CompilationUnit> impl);
101 std::string module_name() const;
105 std::string object_filename() const;
110 sources_iterator sources() const;
114 function_iterator functions() const;
119
120 private:
121 std::unique_ptr<details::CompilationUnit> impl_;
122};
123
124}
125}
126#endif
127
pointer operator->() const
Definition PDB/CompilationUnit.hpp:50
Iterator operator--(int)
Definition PDB/CompilationUnit.hpp:72
Iterator operator++(int)
Definition PDB/CompilationUnit.hpp:78
PointerProxy operator->() const
Definition PDB/CompilationUnit.hpp:86
friend bool operator==(const Iterator &LHS, const Iterator &RHS)
Iterator(std::unique_ptr< details::CompilationUnitIt > impl)
std::unique_ptr< CompilationUnit > operator*() const
friend bool operator!=(const Iterator &LHS, const Iterator &RHS)
Definition PDB/CompilationUnit.hpp:65
This class represents a CompilationUnit (or Module) in a PDB file.
Definition PDB/CompilationUnit.hpp:35
sources_iterator sources() const
Iterator over the sources files that compose this compilation unit. These files also include headers ...
CompilationUnit(std::unique_ptr< details::CompilationUnit > impl)
std::string object_filename() const
Name of path to the original binary object (COFF, Archive) in which the compilation unit was located ...
std::string module_name() const
Name (or path) to the COFF object (.obj) associated with this compilation unit (e....
function_iterator functions() const
Return an iterator over the function defined in this compilation unit. If the PDB does not contain or...
Definition PDB/CompilationUnit.hpp:29
Definition PDB/CompilationUnit.hpp:27
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41