LIEF: Library to Instrument Executable Formats Version 2.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 <string_view>
18#include <memory>
19#include <ostream>
20#include <string>
21#include <vector>
22
23#include "LIEF/DebugDeclOpt.hpp"
24#include "LIEF/PDB/Function.hpp"
25#include "LIEF/iterators.hpp"
26
27#include "LIEF/visibility.h"
28
29
30namespace LIEF::pdb {
31class BuildMetadata;
32
33namespace details {
34class CompilationUnit;
35class CompilationUnitIt;
36}
37
40 public:
41 class Iterator final
42 : public iterator_facade_base<Iterator, std::bidirectional_iterator_tag,
43 CompilationUnit, std::ptrdiff_t,
44 const CompilationUnit*, const CompilationUnit&> {
45 public:
46 using implementation = details::CompilationUnitIt;
47 using iterator_facade_base::operator++;
48 using iterator_facade_base::operator--;
49
51
52 LIEF_API Iterator(std::unique_ptr<details::CompilationUnitIt> impl);
53
56
58 LIEF_API Iterator& operator=(Iterator&&) noexcept;
59
61
62 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
63 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
64 return !(LHS == RHS);
65 }
66
67 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
69
70 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
72
74
75 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
76 LIEF_API const CompilationUnit* operator->() const LIEF_LIFETIMEBOUND;
77
80 LIEF_API std::unique_ptr<CompilationUnit> yield();
81
82 private:
83 void load() const;
84
85 std::unique_ptr<details::CompilationUnitIt> impl_;
86 mutable std::unique_ptr<CompilationUnit> cached_;
87 };
88
91 iterator_range<std::vector<std::string>::const_iterator>;
92
94
95 CompilationUnit(std::unique_ptr<details::CompilationUnit> impl);
97
101 std::string_view module_name() const LIEF_LIFETIMEBOUND;
102
106 std::string_view object_filename() const LIEF_LIFETIMEBOUND;
107
111
116
120
123 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
124
125 std::string to_string() const;
126
127 LIEF_API friend std::ostream& operator<<(std::ostream& os,
128 const CompilationUnit& CU) {
129 os << CU.to_string();
130 return os;
131 }
132
133 private:
134 std::unique_ptr<details::CompilationUnit> impl_;
135};
136
137}
138
139#endif
Configuration options for generated code from debug info.
Definition DebugDeclOpt.hpp:36
Definition iterators.hpp:595
This class wraps build metadata represented by the codeview symbols: S_COMPILE3, S_COMPILE2,...
Definition BuildMetadata.hpp:37
Definition PDB/CompilationUnit.hpp:44
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:46
Iterator(std::unique_ptr< details::CompilationUnitIt > impl)
Iterator & operator=(const Iterator &)
const CompilationUnit & operator*() const
std::string to_decl(const DeclOpt &opt=DeclOpt()) const
Generate a C/C++ definition for the functions defined in this compilation unit.
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:90
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:93
std::string_view 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...
function_iterator functions() const
Return an iterator over the function defined in this compilation unit. If the PDB does not contain or...
std::string_view module_name() const
Name (or path) to the COFF object (.obj) associated with this compilation unit (e....
Definition PDB/Function.hpp:36
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition BuildMetadata.hpp:31
Definition BuildMetadata.hpp:29
#define LIEF_API
Definition visibility.h:45