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
92
93 bool IsInScope(StackFrame *frame);
94
95 /// Returns true if this variable is in scope at `addr` inside `block`.
96 bool IsInScope(const Block &block, const Address &addr);
97
99
100 bool LocationIsValidForAddress(const Address &address);
101
103
105
106 typedef size_t (*GetVariableCallback)(void *baton, const char *name,
107 VariableList &var_list);
108
110 llvm::StringRef variable_expr_path, ExecutionContextScope *scope,
111 GetVariableCallback callback, void *baton, VariableList &variable_list,
112 ValueObjectList &valobj_list);
113
114 static void AutoComplete(const ExecutionContext &exe_ctx,
115 CompletionRequest &request);
116
118
120
121protected:
122 /// The basename of the variable (no namespaces).
124 /// The mangled name of the variable.
126 /// The type pointer of the variable (int, struct, class, etc)
127 /// global, parameter, local.
130 /// The symbol file scope that this variable was defined in
132 /// The list of ranges inside the owner's scope where this variable
133 /// is valid.
135 /// Declaration location for this item.
137 /// The location of this variable that can be fed to
138 /// DWARFExpression::Evaluate().
140 /// Visible outside the containing compile unit?
141 unsigned m_external : 1;
142 /// Non-zero if the variable is not explicitly declared in source.
143 unsigned m_artificial : 1;
144 /// The m_location expression contains the constant variable value
145 /// data, not a DWARF location.
147 /// Non-zero if variable is static member of a class or struct.
148 unsigned m_static_member : 1;
149 /// The value of DW_AT_LLVM_tag_offset if present.
150 std::optional<uint64_t> m_tag_offset;
151
152private:
153 Variable(const Variable &rhs) = delete;
154 Variable &operator=(const Variable &rhs) = delete;
155};
156
157} // namespace lldb_private
158
159#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:179
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:148
bool IsInScope(StackFrame *frame)
Definition Variable.cpp:281
SymbolContextScope * GetSymbolContextScope() const
Definition Variable.h:52
static void AutoComplete(const ExecutionContext &exe_ctx, CompletionRequest &request)
Definition Variable.cpp:765
CompilerDeclContext GetDeclContext()
Definition Variable.cpp:203
unsigned m_artificial
Non-zero if the variable is not explicitly declared in source.
Definition Variable.h:143
unsigned m_external
Visible outside the containing compile unit?
Definition Variable.h:141
bool LocationIsValidForAddress(const Address &address)
Definition Variable.cpp:245
unsigned m_loc_is_const_data
The m_location expression contains the constant variable value data, not a DWARF location.
Definition Variable.h:146
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:128
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:134
ConstString GetUnqualifiedName() const
Definition Variable.cpp:89
static Status GetValuesForVariableExpressionPath(llvm::StringRef variable_expr_path, ExecutionContextScope *scope, GetVariableCallback callback, void *baton, VariableList &variable_list, ValueObjectList &valobj_list)
Definition Variable.cpp:333
Mangled m_mangled
The mangled name of the variable.
Definition Variable.h:125
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:91
void Dump(Stream *s, bool show_context) const
Definition Variable.cpp:113
std::optional< uint64_t > m_tag_offset
The value of DW_AT_LLVM_tag_offset if present.
Definition Variable.h:150
lldb::ValueType m_scope
Definition Variable.h:129
SymbolContextScope * m_owner_scope
The symbol file scope that this variable was defined in.
Definition Variable.h:131
ConstString GetName() const
Definition Variable.cpp:82
CompilerDecl GetDecl()
Definition Variable.cpp:210
ConstString m_name
The basename of the variable (no namespaces).
Definition Variable.h:123
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:136
void CalculateSymbolContext(SymbolContext *sc)
Definition Variable.cpp:215
bool HasTagOffset() const
Definition Variable.h:85
void SetLocationIsConstantValueData(bool b)
Definition Variable.h:104
bool GetLocationIsConstantValueData() const
Definition Variable.h:102
bool DumpLocations(Stream *s, const Address &address)
Definition Variable.cpp:449
bool IsExternal() const
Definition Variable.h:71
Variable & operator=(const Variable &rhs)=delete
lldb::LanguageType GetLanguage() const
Definition Variable.cpp:65
bool IsStaticMember() const
Definition Variable.h:75
bool IsArtificial() const
Definition Variable.h:73
bool LocationIsValidForFrame(StackFrame *frame)
Definition Variable.cpp:223
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:42
size_t(* GetVariableCallback)(void *baton, const char *name, VariableList &var_list)
Definition Variable.h:106
DWARFExpressionList m_location_list
The location of this variable that can be fed to DWARFExpression::Evaluate().
Definition Variable.h:139
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