LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
Variable.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_VARIABLE_H
16#define LIEF_DWARF_VARIABLE_H
17
18#include <memory>
19
20#include "LIEF/iterators.hpp"
21#include "LIEF/visibility.h"
23#include "LIEF/errors.hpp"
24#include "LIEF/debug_loc.hpp"
25#include "LIEF/DWARF/Type.hpp"
26
27namespace LIEF {
28namespace dwarf {
29class Scope;
30
31namespace details {
32class Variable;
33class VariableIt;
34}
35
39 public:
40 class Iterator final
41 : public iterator_facade_base<Iterator, std::bidirectional_iterator_tag,
42 Variable, std::ptrdiff_t, const Variable*,
43 const Variable&> {
44 public:
45 using implementation = details::VariableIt;
46 using iterator_facade_base::operator++;
47 using iterator_facade_base::operator--;
48
50
51 LIEF_API Iterator(std::unique_ptr<details::VariableIt> 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 Variable* operator->() const LIEF_LIFETIMEBOUND;
76
79 LIEF_API std::unique_ptr<Variable> yield();
80
81 private:
82 void load() const;
83
84 std::unique_ptr<details::VariableIt> impl_;
85 mutable std::unique_ptr<Variable> cached_;
86 };
87
88 Variable(std::unique_ptr<details::Variable> impl);
89
91 std::string name() const;
92
97 std::string linkage_name() const;
98
107 result<int64_t> address() const;
108
113 result<uint64_t> size() const;
114
116 bool is_constexpr() const;
117
119 bool is_stack_based() const;
120
123
125 std::unique_ptr<Type> type() const LIEF_LIFETIMEBOUND;
126
128 std::unique_ptr<Scope> scope() const LIEF_LIFETIMEBOUND;
129
131 std::string description() const;
132
134 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
135
137
138 private:
139 std::unique_ptr<details::Variable> impl_;
140};
141
142}
143}
144#endif
Configuration options for generated code from debug info.
Definition DebugDeclOpt.hpp:36
This class materializes a scope in which Function, Variable, Type, ... can be defined.
Definition Scope.hpp:33
This class represents a DWARF Type which includes:
Definition DWARF/Type.hpp:67
std::unique_ptr< Variable > yield()
Transfer ownership of the variable at the current position to the caller. Returns nullptr if the iter...
details::VariableIt implementation
Definition Variable.hpp:45
const Variable & operator*() const
Iterator(std::unique_ptr< details::VariableIt > impl)
Iterator(Iterator &&) noexcept
Iterator & operator=(const Iterator &)
std::string linkage_name() const
The name of the variable which is used for linking (DW_AT_linkage_name).
bool is_stack_based() const
Whether this variable is allocated on the stack.
Variable(std::unique_ptr< details::Variable > impl)
bool is_constexpr() const
Whether it's a constexpr variable.
std::unique_ptr< Type > type() const
Return the type of this variable.
debug_location_t debug_location() const
The original source location where the variable is defined.
std::string description() const
Description (DW_AT_description) of the variable or an empty string.
std::string to_decl(const DeclOpt &opt=DeclOpt()) const
Generates a C/C++ definition for this variable.
std::unique_ptr< Scope > scope() const
Return the scope in which this variable is defined.
std::string name() const
Name of the variable (usually demangled).
result< int64_t > address() const
Address of the variable.
result< uint64_t > size() const
Return the size of the variable (or a lief_errors if it can't be resolved).
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition iterators.hpp:729
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:78
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DWARF/CompilationUnit.hpp:32
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:30
LIEF namespace.
Definition Abstract/Binary.hpp:41
This structure holds a debug location (source filename & line).
Definition debug_loc.hpp:23
#define LIEF_API
Definition visibility.h:45