LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
PDB/CompilationUnit.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_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}
38 public:
39 class LIEF_API Iterator {
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;
44 using pointer = CompilationUnit*;
45 using reference = CompilationUnit&;
46 using implementation = details::CompilationUnitIt;
47
48 class PointerProxy {
49 // Inspired from LLVM's iterator_facade_base
50 friend class Iterator;
51 public:
52 pointer operator->() const { return R.get(); }
53
54 private:
55 value_type R;
56
57 template <typename RefT>
58 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
59 };
60
61 Iterator(const Iterator&);
62 Iterator(Iterator&&);
63 Iterator(std::unique_ptr<details::CompilationUnitIt> impl);
65
66 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
67 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
68 return !(LHS == RHS);
69 }
70
71 Iterator& operator++();
72 Iterator& operator--();
73
74 Iterator operator--(int) {
75 Iterator tmp = *static_cast<Iterator*>(this);
76 --*static_cast<Iterator *>(this);
77 return tmp;
78 }
79
80 Iterator operator++(int) {
81 Iterator tmp = *static_cast<Iterator*>(this);
82 ++*static_cast<Iterator *>(this);
83 return tmp;
84 }
85
86 std::unique_ptr<CompilationUnit> operator*() const;
87
88 PointerProxy operator->() const {
89 return static_cast<const Iterator*>(this)->operator*();
90 }
91
92 private:
93 std::unique_ptr<details::CompilationUnitIt> impl_;
94 };
95 using sources_iterator = iterator_range<std::vector<std::string>::const_iterator>;
98
99 using function_iterator = iterator_range<Function::Iterator>;
100
101 CompilationUnit(std::unique_ptr<details::CompilationUnit> impl);
103 std::string module_name() const;
107 std::string object_filename() const;
112 sources_iterator sources() const;
116 function_iterator functions() const;
121 std::unique_ptr<BuildMetadata> build_metadata() const;
125
126 std::string to_string() const;
127
128 LIEF_API friend
129 std::ostream& operator<<(std::ostream& os, const CompilationUnit& CU)
130 {
131 os << CU.to_string();
132 return os;
133 }
134
135 private:
136 std::unique_ptr<details::CompilationUnit> impl_;
137};
138
139}
140}
141#endif
142
This class wraps build metadata represented by the codeview symbols: S_COMPILE3, S_COMPILE2,...
Definition BuildMetadata.hpp:32
pointer operator->() const
Definition PDB/CompilationUnit.hpp:52
Iterator operator--(int)
Definition PDB/CompilationUnit.hpp:74
Iterator operator++(int)
Definition PDB/CompilationUnit.hpp:80
PointerProxy operator->() const
Definition PDB/CompilationUnit.hpp:88
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:67
This class represents a CompilationUnit (or Module) in a PDB file.
Definition PDB/CompilationUnit.hpp:37
std::string to_string() const
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)
friend std::ostream & operator<<(std::ostream &os, const CompilationUnit &CU)
Definition PDB/CompilationUnit.hpp:129
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:36
#define LIEF_API
Definition visibility.h:41