LIEF: Library to Instrument Executable Formats Version 2.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 <string_view>
19#include <memory>
20#include <vector>
21
23#include "LIEF/DWARF/Type.hpp"
25#include "LIEF/debug_loc.hpp"
26#include "LIEF/errors.hpp"
27#include "LIEF/iterators.hpp"
28#include "LIEF/visibility.h"
29
30
31namespace LIEF::dwarf {
32class Scope;
33
34namespace details {
35class Variable;
36class VariableIt;
37}
38
42 public:
43 class Iterator final
44 : public iterator_facade_base<Iterator, std::bidirectional_iterator_tag,
45 Variable, std::ptrdiff_t, const Variable*,
46 const Variable&> {
47 public:
48 using implementation = details::VariableIt;
49 using iterator_facade_base::operator++;
50 using iterator_facade_base::operator--;
51
53
54 LIEF_API Iterator(std::unique_ptr<details::VariableIt> impl);
55
58
60 LIEF_API Iterator& operator=(Iterator&&) noexcept;
61
63
64 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
65 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
66 return !(LHS == RHS);
67 }
68
69 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
71
72 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
74
76
77 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
78 LIEF_API const Variable* operator->() const LIEF_LIFETIMEBOUND;
79
82 LIEF_API std::unique_ptr<Variable> yield();
83
84 private:
85 void load() const;
86
87 std::unique_ptr<details::VariableIt> impl_;
88 mutable std::unique_ptr<Variable> cached_;
89 };
90
91 Variable(std::unique_ptr<details::Variable> impl);
92
94 std::string_view name() const LIEF_LIFETIMEBOUND;
95
100 std::string_view linkage_name() const LIEF_LIFETIMEBOUND;
101
110 result<int64_t> address() const;
111
116 result<uint64_t> size() const;
117
119 bool is_constexpr() const;
120
122 bool is_stack_based() const;
123
125 std::unique_ptr<Location> location() const;
126
128 std::unique_ptr<Location> location(uint64_t pc) const;
129
131 std::vector<LocationEntry> locations() const;
132
135
137 std::unique_ptr<Type> type() const LIEF_LIFETIMEBOUND;
138
140 std::unique_ptr<Scope> scope() const LIEF_LIFETIMEBOUND;
141
143 std::string_view description() const LIEF_LIFETIMEBOUND;
144
146 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
147
149
150 private:
151 std::unique_ptr<details::Variable> impl_;
152};
153
154}
155
156#endif
Configuration options for generated code from debug info.
Definition DebugDeclOpt.hpp:37
This class represents where the value of a variable or a parameter lives. It interfaces the DWARF loc...
Definition Location.hpp:33
This class materializes a scope in which Function, Variable, Type, ... can be defined.
Definition Scope.hpp:35
This class represents a DWARF Type which includes:
Definition DWARF/Type.hpp:68
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:48
const Variable & operator*() const
Iterator(std::unique_ptr< details::VariableIt > impl)
Iterator(Iterator &&) noexcept
Iterator & operator=(const Iterator &)
bool is_stack_based() const
Whether this variable is allocated on the stack.
Variable(std::unique_ptr< details::Variable > impl)
std::vector< LocationEntry > locations() const
All the location entries of this variable.
bool is_constexpr() const
Whether it's a constexpr variable.
std::unique_ptr< Location > location() const
Location of this 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_view 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_view linkage_name() const
The name of the variable which is used for linking (DW_AT_linkage_name).
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).
std::string_view name() const
Name of the variable (usually demangled).
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:79
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DWARF/CompilationUnit.hpp:33
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:31
This structure holds a debug location (source filename & line).
Definition debug_loc.hpp:23
Location associated with the range of addresses where it is valid.
Definition Location.hpp:250
#define LIEF_API
Definition visibility.h:45