LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
DWARF/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_DWARF_COMPILATION_UNIT_H
16#define LIEF_DWARF_COMPILATION_UNIT_H
17#include <memory>
18#include <string>
19#include <vector>
20
21#include "LIEF/visibility.h"
22#include "LIEF/range.hpp"
23#include "LIEF/iterators.hpp"
25#include "LIEF/DWARF/Type.hpp"
26
27namespace LIEF {
28namespace dwarf {
29
30namespace details {
31class CompilationUnit;
32class CompilationUnitIt;
33}
34
37 public:
38 class Iterator final
39 : public iterator_facade_base<Iterator, std::bidirectional_iterator_tag,
40 CompilationUnit, std::ptrdiff_t,
41 const CompilationUnit*, const CompilationUnit&> {
42 public:
43 using implementation = details::CompilationUnitIt;
44 using iterator_facade_base::operator++;
45 using iterator_facade_base::operator--;
46
48
49 LIEF_API Iterator(std::unique_ptr<details::CompilationUnitIt> impl);
50
53
55 LIEF_API Iterator& operator=(Iterator&&) noexcept;
56
58
59 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
60 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
61 return !(LHS == RHS);
62 }
63
64 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
66
67 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
69
71
72 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
74
77 LIEF_API std::unique_ptr<CompilationUnit> yield();
78
79 private:
80 void load() const;
81
82 std::unique_ptr<details::CompilationUnitIt> impl_;
83 mutable std::unique_ptr<CompilationUnit> cached_;
84 };
85
88
91
94
100 class Language {
101 public:
115
118
120 uint32_t version = 0;
121
122 Language() = default;
124 lang(lang),
125 version(version) {}
128
129 Language(const Language&) = default;
130 Language& operator=(const Language&) = default;
131 Language(Language&&) = default;
133 ~Language() = default;
134 };
135 CompilationUnit(std::unique_ptr<details::CompilationUnit> impl);
137
142 std::string name() const;
143
151 std::string producer() const;
152
160 std::string compilation_dir() const;
161
166
168 uint64_t low_address() const;
169
171 uint64_t high_address() const;
172
181 uint64_t size() const;
182
187 std::vector<range_t> ranges() const;
188
192 std::unique_ptr<Function> find_function(const std::string& name) const;
193
195 std::unique_ptr<Function> find_function(uint64_t addr) const;
196
198 std::unique_ptr<Variable> find_variable(uint64_t addr) const;
199
201 std::unique_ptr<Variable> find_variable(const std::string& name) const;
202
226
245
249
250
264
265 private:
266 std::unique_ptr<details::CompilationUnit> impl_;
267};
268
269}
270}
271#endif
const CompilationUnit & operator*() const
Iterator(std::unique_ptr< details::CompilationUnitIt > impl)
details::CompilationUnitIt implementation
Definition DWARF/CompilationUnit.hpp:43
std::unique_ptr< CompilationUnit > yield()
Transfer ownership of the compilation unit at the current position to the caller. Returns nullptr if ...
const CompilationUnit * operator->() const
Iterator & operator=(const Iterator &)
Languages supported by the DWARF (v5) format. See: https://dwarfstd.org/languages....
Definition DWARF/CompilationUnit.hpp:100
Language(LANG lang)
Definition DWARF/CompilationUnit.hpp:126
Language(LANG lang, uint32_t version)
Definition DWARF/CompilationUnit.hpp:123
Language & operator=(Language &&)=default
LANG lang
The language itself.
Definition DWARF/CompilationUnit.hpp:117
uint32_t version
Version of the language (e.g. 17 for C++17).
Definition DWARF/CompilationUnit.hpp:120
LANG
Definition DWARF/CompilationUnit.hpp:102
@ D
Definition DWARF/CompilationUnit.hpp:111
@ DART
Definition DWARF/CompilationUnit.hpp:107
@ RUST
Definition DWARF/CompilationUnit.hpp:106
@ C
Definition DWARF/CompilationUnit.hpp:104
@ COBOL
Definition DWARF/CompilationUnit.hpp:113
@ SWIFT
Definition DWARF/CompilationUnit.hpp:110
@ UNKNOWN
Definition DWARF/CompilationUnit.hpp:103
@ CPP
Definition DWARF/CompilationUnit.hpp:105
@ FORTRAN
Definition DWARF/CompilationUnit.hpp:109
@ JAVA
Definition DWARF/CompilationUnit.hpp:112
@ MODULA
Definition DWARF/CompilationUnit.hpp:108
Language(const Language &)=default
Language & operator=(const Language &)=default
This class represents a DWARF compilation unit.
Definition DWARF/CompilationUnit.hpp:36
iterator_range< Variable::Iterator > vars_it
Iterator over the CompilationUnit's variables.
Definition DWARF/CompilationUnit.hpp:93
uint64_t high_address() const
Return the highest virtual address owned by this compilation unit.
vars_it variables() const
Return an iterator over all the variables defined in this compilation unit:
types_it types() const
Return an iterator over the different types defined in this compilation unit.
Language language() const
Original language of this compilation unit.
std::unique_ptr< Variable > find_variable(const std::string &name) const
Try to find the Variable with the given name.
CompilationUnit(std::unique_ptr< details::CompilationUnit > impl)
iterator_range< Function::Iterator > functions_it
Iterator over the dwarf::Function.
Definition DWARF/CompilationUnit.hpp:87
std::unique_ptr< Function > find_function(uint64_t addr) const
Try to find the function at the given address.
uint64_t size() const
Return the size of the compilation unit according to its range of address.
functions_it imported_functions() const
Return an iterator over the functions imported in this compilation unit but not implemented.
uint64_t low_address() const
Return the lowest virtual address owned by this compilation unit.
iterator_range< Type::Iterator > types_it
Iterator over the dwarf::Type.
Definition DWARF/CompilationUnit.hpp:90
std::string name() const
Name of the file associated with this compilation unit (e.g. test.cpp) Return an empty string if the ...
std::string compilation_dir() const
Return the path to the directory in which the compilation took place for compiling this compilation u...
functions_it functions() const
Return an iterator over the functions implemented in this compilation unit.
std::unique_ptr< Function > find_function(const std::string &name) const
Try to find the function whose name is given in parameter.
std::unique_ptr< Variable > find_variable(uint64_t addr) const
Try to find the Variable at the given address.
std::string producer() const
Information about the program (or library) that generated this compilation unit. For instance,...
std::vector< range_t > ranges() const
Return a list of address ranges owned by this compilation unit.
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
Definition DWARF/CompilationUnit.hpp:30
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:28
LIEF namespace.
Definition Abstract/Binary.hpp:40
#define LIEF_API
Definition visibility.h:45