LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
DWARF/CompilationUnit.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2024 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:
39 public:
40 using iterator_category = std::bidirectional_iterator_tag;
41 using value_type = std::unique_ptr<CompilationUnit>;
42 using difference_type = std::ptrdiff_t;
44 using reference = std::unique_ptr<CompilationUnit>&;
45 using implementation = details::CompilationUnitIt;
46
48 // Inspired from LLVM's iterator_facade_base
49 friend class Iterator;
50 public:
51 pointer operator->() const { return R.get(); }
52
53 private:
54 value_type R;
55
56 template <typename RefT>
57 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
58 };
59
61 Iterator(Iterator&&) noexcept;
62 Iterator(std::unique_ptr<details::CompilationUnitIt> impl);
64
65 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
66 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
67 return !(LHS == RHS);
68 }
69
72
74 Iterator tmp = *static_cast<Iterator*>(this);
75 --*static_cast<Iterator *>(this);
76 return tmp;
77 }
78
80 Iterator tmp = *static_cast<Iterator*>(this);
81 ++*static_cast<Iterator *>(this);
82 return tmp;
83 }
84
85 std::unique_ptr<CompilationUnit> operator*() const;
86
88 return static_cast<const Iterator*>(this)->operator*();
89 }
90
91 private:
92 std::unique_ptr<details::CompilationUnitIt> impl_;
93 };
94
97
100
103
109 class Language {
110 public:
111 enum LANG : uint32_t {
112 UNKNOWN = 0,
117 };
118
120 LANG lang = UNKNOWN;
121
123 uint32_t version = 0;
124
125 Language() = default;
126 Language(LANG lang, uint32_t version) :
127 lang(lang), version(version)
128 {}
130 Language(lang, 0)
131 {}
132
133 Language(const Language&) = default;
134 Language& operator=(const Language&) = default;
135 Language(Language&&) = default;
137 ~Language() = default;
138 };
139 CompilationUnit(std::unique_ptr<details::CompilationUnit> impl);
141
146 std::string name() const;
147
155 std::string producer() const;
156
164 std::string compilation_dir() const;
165
170
172 uint64_t low_address() const;
173
175 uint64_t high_address() const;
176
185 uint64_t size() const;
186
191 std::vector<range_t> ranges() const;
192
196 std::unique_ptr<Function> find_function(const std::string& name) const;
197
199 std::unique_ptr<Function> find_function(uint64_t addr) const;
200
202 std::unique_ptr<Variable> find_variable(uint64_t addr) const;
203
205 std::unique_ptr<Variable> find_variable(const std::string& name) const;
206
230
234
235
249
250 private:
251 std::unique_ptr<details::CompilationUnit> impl_;
252};
253
254}
255}
256#endif
257
Definition DWARF/CompilationUnit.hpp:47
pointer operator->() const
Definition DWARF/CompilationUnit.hpp:51
Definition DWARF/CompilationUnit.hpp:38
std::unique_ptr< CompilationUnit > value_type
Definition DWARF/CompilationUnit.hpp:41
Iterator operator--(int)
Definition DWARF/CompilationUnit.hpp:73
std::unique_ptr< CompilationUnit > operator*() const
Iterator operator++(int)
Definition DWARF/CompilationUnit.hpp:79
std::unique_ptr< CompilationUnit > & reference
Definition DWARF/CompilationUnit.hpp:44
std::bidirectional_iterator_tag iterator_category
Definition DWARF/CompilationUnit.hpp:40
std::ptrdiff_t difference_type
Definition DWARF/CompilationUnit.hpp:42
details::CompilationUnitIt implementation
Definition DWARF/CompilationUnit.hpp:45
PointerProxy operator->() const
Definition DWARF/CompilationUnit.hpp:87
Languages supported by the DWARF (v5) format. See: https://dwarfstd.org/languages....
Definition DWARF/CompilationUnit.hpp:109
Language(LANG lang)
Definition DWARF/CompilationUnit.hpp:129
Language(LANG lang, uint32_t version)
Definition DWARF/CompilationUnit.hpp:126
Language & operator=(Language &&)=default
LANG
Definition DWARF/CompilationUnit.hpp:111
@ DART
Definition DWARF/CompilationUnit.hpp:116
@ RUST
Definition DWARF/CompilationUnit.hpp:115
@ C
Definition DWARF/CompilationUnit.hpp:113
@ CPP
Definition DWARF/CompilationUnit.hpp:114
Language(const Language &)=default
Language & operator=(const Language &)=default
This class represents a DWARF compilation unit.
Definition DWARF/CompilationUnit.hpp:36
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 the 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)
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.
uint64_t low_address() const
Return the lowest virtual address owned by this compilation unit.
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.
Definition iterators.hpp:486
LIEF namespace.
Definition Abstract/Binary.hpp:32
#define LIEF_API
Definition visibility.h:41