LLDB mainline
Variable.h
Go to the documentation of this file.
1//===-- Variable.h -----------------------------------------------*- C++-*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SYMBOL_VARIABLE_H
10#define LLDB_SYMBOL_VARIABLE_H
11
13#include "lldb/Core/Mangled.h"
17#include "lldb/Utility/UserID.h"
19#include "lldb/lldb-private.h"
20#include <memory>
21#include <vector>
22
23namespace lldb_private {
24
25class Variable : public UserID, public std::enable_shared_from_this<Variable> {
26public:
28
29 /// Constructors and Destructors.
30 ///
31 /// \param mangled The mangled or fully qualified name of the variable.
32 Variable(lldb::user_id_t uid, const char *name, const char *mangled,
33 const lldb::SymbolFileTypeSP &symfile_type_sp, lldb::ValueType scope,
34 SymbolContextScope *owner_scope, const RangeList &scope_range,
35 Declaration *decl, const DWARFExpressionList &location,
36 bool external, bool artificial, bool location_is_constant_data,
37 bool static_member = false,
38 std::optional<uint64_t> tag_offset = std::nullopt);
39
40 virtual ~Variable();
41
42 void Dump(Stream *s, bool show_context) const;
43
44 bool DumpDeclaration(Stream *s, bool show_fullpaths, bool show_module);
45
46 const Declaration &GetDeclaration() const { return m_declaration; }
47
48 ConstString GetName() const;
49
51
53
54 /// Since a variable can have a basename "i" and also a mangled named
55 /// "_ZN12_GLOBAL__N_11iE" and a demangled mangled name "(anonymous
56 /// namespace)::i", this function will allow a generic match function that can
57 /// be called by commands and expression parsers to make sure we match
58 /// anything we come across.
59 bool NameMatches(ConstString name) const;
60
61 bool NameMatches(const RegularExpression &regex) const;
62
63 Type *GetType();
64
66
67 lldb::ValueType GetScope() const { return m_scope; }
68
69 const RangeList &GetScopeRange() const { return m_scope_range; }
70
71 bool IsExternal() const { return m_external; }
72
73 bool IsArtificial() const { return m_artificial; }
74
75 bool IsStaticMember() const { return m_static_member; }
76
78
82
83 uint64_t GetTagOffset() const { return m_tag_offset.value(); }
84
85 bool HasTagOffset() const { return m_tag_offset.has_value(); }
86
87 // When given invalid address, it dumps all locations. Otherwise it only dumps
88 // the location that contains this address.
89 bool DumpLocations(Stream *s, const Address &address);
90
91 size_t MemorySize() const;
92
94
95 bool IsInScope(StackFrame *frame);
96
97 /// Returns true if this variable is in scope at `addr` inside `block`.
98 bool IsInScope(const Block &block, const Address &addr);
99
101
102 bool LocationIsValidForAddress(const Address &address);
103
105
107
108 typedef size_t (*GetVariableCallback)(void *baton, const char *name,
109 VariableList &var_list);
110
112 llvm::StringRef variable_expr_path, ExecutionContextScope *scope,
113 GetVariableCallback callback, void *baton, VariableList &variable_list,
114 ValueObjectList &valobj_list);
115
116 static void AutoComplete(const ExecutionContext &exe_ctx,
117 CompletionRequest &request);
118
120
122
123protected:
124 /// The basename of the variable (no namespaces).
126 /// The mangled name of the variable.
128 /// The type pointer of the variable (int, struct, class, etc)
129 /// global, parameter, local.
132 /// The symbol file scope that this variable was defined in
134 /// The list of ranges inside the owner's scope where this variable
135 /// is valid.
137 /// Declaration location for this item.
139 /// The location of this variable that can be fed to
140 /// DWARFExpression::Evaluate().
142 /// Visible outside the containing compile unit?
143 unsigned m_external : 1;
144 /// Non-zero if the variable is not explicitly declared in source.
145 unsigned m_artificial : 1;
146 /// The m_location expression contains the constant variable value
147 /// data, not a DWARF location.
149 /// Non-zero if variable is static member of a class or struct.
150 unsigned m_static_member : 1;
151 /// The value of DW_AT_LLVM_tag_offset if present.
152 std::optional<uint64_t> m_tag_offset;
153
154private:
155 Variable(const Variable &rhs) = delete;
156 Variable &operator=(const Variable &rhs) = delete;
157};
158
159} // namespace lldb_private
160
161#endif // LLDB_SYMBOL_VARIABLE_H
A section + offset based address class.
Definition Address.h:62
A class that describes a single lexical block.
Definition Block.h:41
Represents a generic declaration context in a program.
Represents a generic declaration such as a function declaration.
"lldb/Utility/ArgCompletionRequest.h"
A uniqued constant string class.
Definition ConstString.h:40
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
A class that describes the declaration location of a lldb object.
Definition Declaration.h:24
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A class that handles mangled names.
Definition Mangled.h:34
This base class provides an interface to stack frames.
Definition StackFrame.h:44
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
Defines a symbol context baton that can be handed other debug core functions.
A collection of ValueObject values that.
bool DumpDeclaration(Stream *s, bool show_fullpaths, bool show_module)
Definition Variable.cpp:178
const RangeList & GetScopeRange() const
Definition Variable.h:69
DWARFExpressionList & LocationExpressionList()
Definition Variable.h:77
uint64_t GetTagOffset() const
Definition Variable.h:83
unsigned m_static_member
Non-zero if variable is static member of a class or struct.
Definition Variable.h:150
bool IsInScope(StackFrame *frame)
Definition Variable.cpp:282
SymbolContextScope * GetSymbolContextScope() const
Definition Variable.h:52
static void AutoComplete(const ExecutionContext &exe_ctx, CompletionRequest &request)
Definition Variable.cpp:728
CompilerDeclContext GetDeclContext()
Definition Variable.cpp:204
unsigned m_artificial
Non-zero if the variable is not explicitly declared in source.
Definition Variable.h:145
unsigned m_external
Visible outside the containing compile unit?
Definition Variable.h:143
bool LocationIsValidForAddress(const Address &address)
Definition Variable.cpp:246
unsigned m_loc_is_const_data
The m_location expression contains the constant variable value data, not a DWARF location.
Definition Variable.h:148
const Declaration & GetDeclaration() const
Definition Variable.h:46
lldb::SymbolFileTypeSP m_symfile_type_sp
The type pointer of the variable (int, struct, class, etc) global, parameter, local.
Definition Variable.h:130
Variable(const Variable &rhs)=delete
RangeList m_scope_range
The list of ranges inside the owner's scope where this variable is valid.
Definition Variable.h:136
ConstString GetUnqualifiedName() const
Definition Variable.cpp:88
static Status GetValuesForVariableExpressionPath(llvm::StringRef variable_expr_path, ExecutionContextScope *scope, GetVariableCallback callback, void *baton, VariableList &variable_list, ValueObjectList &valobj_list)
Definition Variable.cpp:334
Mangled m_mangled
The mangled name of the variable.
Definition Variable.h:127
bool NameMatches(ConstString name) const
Since a variable can have a basename "i" and also a mangled named "_ZN12_GLOBAL__N_11iE" and a demang...
Definition Variable.cpp:90
void Dump(Stream *s, bool show_context) const
Definition Variable.cpp:112
std::optional< uint64_t > m_tag_offset
The value of DW_AT_LLVM_tag_offset if present.
Definition Variable.h:152
lldb::ValueType m_scope
Definition Variable.h:131
SymbolContextScope * m_owner_scope
The symbol file scope that this variable was defined in.
Definition Variable.h:133
ConstString GetName() const
Definition Variable.cpp:81
CompilerDecl GetDecl()
Definition Variable.cpp:211
ConstString m_name
The basename of the variable (no namespaces).
Definition Variable.h:125
RangeVector< lldb::addr_t, lldb::addr_t > RangeList
Definition Variable.h:27
const DWARFExpressionList & LocationExpressionList() const
Definition Variable.h:79
Declaration m_declaration
Declaration location for this item.
Definition Variable.h:138
void CalculateSymbolContext(SymbolContext *sc)
Definition Variable.cpp:216
bool HasTagOffset() const
Definition Variable.h:85
void SetLocationIsConstantValueData(bool b)
Definition Variable.h:106
bool GetLocationIsConstantValueData() const
Definition Variable.h:104
bool DumpLocations(Stream *s, const Address &address)
Definition Variable.cpp:450
bool IsExternal() const
Definition Variable.h:71
Variable & operator=(const Variable &rhs)=delete
lldb::LanguageType GetLanguage() const
Definition Variable.cpp:64
size_t MemorySize() const
Definition Variable.cpp:202
bool IsStaticMember() const
Definition Variable.h:75
bool IsArtificial() const
Definition Variable.h:73
bool LocationIsValidForFrame(StackFrame *frame)
Definition Variable.cpp:224
Variable(lldb::user_id_t uid, const char *name, const char *mangled, const lldb::SymbolFileTypeSP &symfile_type_sp, lldb::ValueType scope, SymbolContextScope *owner_scope, const RangeList &scope_range, Declaration *decl, const DWARFExpressionList &location, bool external, bool artificial, bool location_is_constant_data, bool static_member=false, std::optional< uint64_t > tag_offset=std::nullopt)
Constructors and Destructors.
Definition Variable.cpp:41
size_t(* GetVariableCallback)(void *baton, const char *name, VariableList &var_list)
Definition Variable.h:108
DWARFExpressionList m_location_list
The location of this variable that can be fed to DWARFExpression::Evaluate().
Definition Variable.h:141
lldb::ValueType GetScope() const
Definition Variable.h:67
A class that represents a running process on the host machine.
LanguageType
Programming language type.
std::shared_ptr< lldb_private::SymbolFileType > SymbolFileTypeSP
uint64_t user_id_t
Definition lldb-types.h:82
UserID(lldb::user_id_t uid=LLDB_INVALID_UID)
Construct with optional user ID.
Definition UserID.h:33