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:
39 class Iterator final
40 : public iterator_facade_base<Iterator, std::bidirectional_iterator_tag,
41 CompilationUnit, std::ptrdiff_t,
42 const CompilationUnit*, const CompilationUnit&> {
43 public:
44 using implementation = details::CompilationUnitIt;
45 using iterator_facade_base::operator++;
46 using iterator_facade_base::operator--;
47
49
50 LIEF_API Iterator(std::unique_ptr<details::CompilationUnitIt> impl);
51
54
56 LIEF_API Iterator& operator=(Iterator&&) noexcept;
57
59
60 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
61 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
62 return !(LHS == RHS);
63 }
64
65 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
67
68 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
70
72
73 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
75
78 LIEF_API std::unique_ptr<CompilationUnit> yield();
79
80 private:
81 void load() const;
82
83 std::unique_ptr<details::CompilationUnitIt> impl_;
84 mutable std::unique_ptr<CompilationUnit> cached_;
85 };
86
90
92
93 CompilationUnit(std::unique_ptr<details::CompilationUnit> impl);
95
99 std::string module_name() const;
100
104 std::string object_filename() const;
105
109
114
117 std::unique_ptr<BuildMetadata> build_metadata() const;
118
119 std::string to_string() const;
120
121 LIEF_API friend std::ostream& operator<<(std::ostream& os,
122 const CompilationUnit& CU) {
123 os << CU.to_string();
124 return os;
125 }
126
127 private:
128 std::unique_ptr<details::CompilationUnit> impl_;
129};
130
131}
132}
133#endif
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition iterators.hpp:729
Definition iterators.hpp:601
This class wraps build metadata represented by the codeview symbols: S_COMPILE3, S_COMPILE2,...
Definition BuildMetadata.hpp:32
std::unique_ptr< CompilationUnit > yield()
Transfer ownership of the compilation unit at the current position to the caller. Returns nullptr if ...
details::CompilationUnitIt implementation
Definition PDB/CompilationUnit.hpp:44
const CompilationUnit * operator->() const
Iterator(std::unique_ptr< details::CompilationUnitIt > impl)
Iterator & operator=(const Iterator &)
const CompilationUnit & operator*() const
std::string to_string() const
iterator_range< std::vector< std::string >::const_iterator > sources_iterator
Iterator over the source files (std::string).
Definition PDB/CompilationUnit.hpp:88
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:91
friend std::ostream & operator<<(std::ostream &os, const CompilationUnit &CU)
Definition PDB/CompilationUnit.hpp:121
std::string object_filename() const
Name or 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:45