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/DebugDeclOpt.hpp"
24#include "LIEF/PDB/Function.hpp"
25
26#include "LIEF/visibility.h"
27
28namespace LIEF {
29namespace pdb {
30class BuildMetadata;
31
32namespace details {
33class CompilationUnit;
34class CompilationUnitIt;
35}
36
39 public:
40 class Iterator final
41 : public iterator_facade_base<Iterator, std::bidirectional_iterator_tag,
42 CompilationUnit, std::ptrdiff_t,
43 const CompilationUnit*, const CompilationUnit&> {
44 public:
45 using implementation = details::CompilationUnitIt;
46 using iterator_facade_base::operator++;
47 using iterator_facade_base::operator--;
48
50
51 LIEF_API Iterator(std::unique_ptr<details::CompilationUnitIt> impl);
52
55
57 LIEF_API Iterator& operator=(Iterator&&) noexcept;
58
60
61 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
62 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
63 return !(LHS == RHS);
64 }
65
66 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
68
69 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
71
73
74 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
75 LIEF_API const CompilationUnit* operator->() const LIEF_LIFETIMEBOUND;
76
79 LIEF_API std::unique_ptr<CompilationUnit> yield();
80
81 private:
82 void load() const;
83
84 std::unique_ptr<details::CompilationUnitIt> impl_;
85 mutable std::unique_ptr<CompilationUnit> cached_;
86 };
87
90 iterator_range<std::vector<std::string>::const_iterator>;
91
93
94 CompilationUnit(std::unique_ptr<details::CompilationUnit> impl);
96
100 std::string module_name() const;
101
105 std::string object_filename() const;
106
110
115
119
122 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
123
124 std::string to_string() const;
125
126 LIEF_API friend std::ostream& operator<<(std::ostream& os,
127 const CompilationUnit& CU) {
128 os << CU.to_string();
129 return os;
130 }
131
132 private:
133 std::unique_ptr<details::CompilationUnit> impl_;
134};
135
136}
137}
138#endif
Configuration options for generated code from debug info.
Definition DebugDeclOpt.hpp:36
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:33
Definition PDB/CompilationUnit.hpp:43
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:45
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:89
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:92
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 PDB/Function.hpp:35
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition BuildMetadata.hpp:27
Definition BuildMetadata.hpp:25
LIEF namespace.
Definition Abstract/Binary.hpp:41
#define LIEF_API
Definition visibility.h:45