LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
PDB/CompilationUnit.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_PDB_COMPILATION_UNIT_H
16#define LIEF_PDB_COMPILATION_UNIT_H
17#include <memory>
18#include <string>
19#include <vector>
20#include <ostream>
21
22#include "LIEF/iterators.hpp"
23#include "LIEF/PDB/Function.hpp"
24
25#include "LIEF/visibility.h"
26
27namespace LIEF {
28namespace pdb {
29class BuildMetadata;
30
31namespace details {
32class CompilationUnit;
33class CompilationUnitIt;
34}
35
38 public:
40 public:
41 using iterator_category = std::bidirectional_iterator_tag;
42 using value_type = std::unique_ptr<CompilationUnit>;
43 using difference_type = std::ptrdiff_t;
46 using implementation = details::CompilationUnitIt;
47
48 class PointerProxy {
49 // Inspired from LLVM's iterator_facade_base
50 friend class Iterator;
51
52 public:
54 return R.get();
55 }
56
57 private:
58 value_type R;
59
60 template<typename RefT>
61 PointerProxy(RefT&& R) :
62 R(std::forward<RefT>(R)) {
63 } // NOLINT(bugprone-forwarding-reference-overload)
64 };
65
68 Iterator(std::unique_ptr<details::CompilationUnitIt> impl);
70
71 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
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<CompilationUnit> operator*() const;
92
94 return static_cast<const Iterator*>(this)->operator*();
95 }
96
97 private:
98 std::unique_ptr<details::CompilationUnitIt> impl_;
99 };
100
104
106
107 CompilationUnit(std::unique_ptr<details::CompilationUnit> impl);
109
113 std::string module_name() const;
114
118 std::string object_filename() const;
119
123
128
131 std::unique_ptr<BuildMetadata> build_metadata() const;
132
133 std::string to_string() const;
134
135 LIEF_API friend std::ostream& operator<<(std::ostream& os,
136 const CompilationUnit& CU) {
137 os << CU.to_string();
138 return os;
139 }
140
141 private:
142 std::unique_ptr<details::CompilationUnit> impl_;
143};
144
145}
146}
147#endif
Definition iterators.hpp:510
This class wraps build metadata represented by the codeview symbols: S_COMPILE3, S_COMPILE2,...
Definition BuildMetadata.hpp:32
Definition PDB/CompilationUnit.hpp:48
pointer operator->() const
Definition PDB/CompilationUnit.hpp:53
friend class Iterator
Definition PDB/CompilationUnit.hpp:50
Iterator operator--(int)
Definition PDB/CompilationUnit.hpp:79
std::unique_ptr< CompilationUnit > value_type
Definition PDB/CompilationUnit.hpp:42
Iterator operator++(int)
Definition PDB/CompilationUnit.hpp:85
PointerProxy operator->() const
Definition PDB/CompilationUnit.hpp:93
friend bool operator==(const Iterator &LHS, const Iterator &RHS)
details::CompilationUnitIt implementation
Definition PDB/CompilationUnit.hpp:46
CompilationUnit & reference
Definition PDB/CompilationUnit.hpp:45
std::bidirectional_iterator_tag iterator_category
Definition PDB/CompilationUnit.hpp:41
Iterator(std::unique_ptr< details::CompilationUnitIt > impl)
std::ptrdiff_t difference_type
Definition PDB/CompilationUnit.hpp:43
CompilationUnit * pointer
Definition PDB/CompilationUnit.hpp:44
std::unique_ptr< CompilationUnit > operator*() const
friend bool operator!=(const Iterator &LHS, const Iterator &RHS)
Definition PDB/CompilationUnit.hpp:72
std::string to_string() const
iterator_range< std::vector< std::string >::const_iterator > sources_iterator
Iterator over the sources file (std::string).
Definition PDB/CompilationUnit.hpp:102
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)
iterator_range< Function::Iterator > function_iterator
Definition PDB/CompilationUnit.hpp:105
friend std::ostream & operator<<(std::ostream &os, const CompilationUnit &CU)
Definition PDB/CompilationUnit.hpp:135
std::string object_filename() const
Name of path to the original binary object (COFF, Archive) in which the compilation unit was located ...
std::unique_ptr< BuildMetadata > build_metadata() const
Return build metadata such as the version of the compiler or the original source language of this com...
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 BuildMetadata.hpp:26
Definition BuildMetadata.hpp:24
LIEF namespace.
Definition Abstract/Binary.hpp:40
#define LIEF_API
Definition visibility.h:43