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
39 virtual ~Variable();
40
41 void Dump(Stream *s, bool show_context) const;
42
43 bool DumpDeclaration(Stream *s, bool show_fullpaths, bool show_module);
44
45 const Declaration &GetDeclaration() const { return m_declaration; }
46
47 ConstString GetName() const;
48
50
52
53 /// Since a variable can have a basename "i" and also a mangled named
54 /// "_ZN12_GLOBAL__N_11iE" and a demangled mangled name "(anonymous
55 /// namespace)::i", this function will allow a generic match function that can
56 /// be called by commands and expression parsers to make sure we match
57 /// anything we come across.
58 bool NameMatches(ConstString name) const;
59
60 bool NameMatches(const RegularExpression &regex) const;
61
62 Type *GetType();
63
65
66 lldb::ValueType GetScope() const { return m_scope; }
67
68 const RangeList &GetScopeRange() const { return m_scope_range; }
69
70 bool IsExternal() const { return m_external; }
71
72 bool IsArtificial() const { return m_artificial; }
73
74 bool IsStaticMember() const { return m_static_member; }
75
77
81
82 // When given invalid address, it dumps all locations. Otherwise it only dumps
83 // the location that contains this address.
84 bool DumpLocations(Stream *s, const Address &address);
85
86 size_t MemorySize() const;
87
89
90 bool IsInScope(StackFrame *frame);
91
92 /// Returns true if this variable is in scope at `addr` inside `block`.
93 bool IsInScope(const Block &block, const Address &addr);
94
96
97 bool LocationIsValidForAddress(const Address &address);
98
100
102
103 typedef size_t (*GetVariableCallback)(void *baton, const char *name,
104 VariableList &var_list);
105
107 llvm::StringRef variable_expr_path, ExecutionContextScope *scope,
108 GetVariableCallback callback, void *baton, VariableList &variable_list,
109 ValueObjectList &valobj_list);
110
111 static void AutoComplete(const ExecutionContext &exe_ctx,
112 CompletionRequest &request);
113
115
117
118protected:
119 /// The basename of the variable (no namespaces).
121 /// The mangled name of the variable.
123 /// The type pointer of the variable (int, struct, class, etc)
124 /// global, parameter, local.
127 /// The symbol file scope that this variable was defined in
129 /// The list of ranges inside the owner's scope where this variable
130 /// is valid.
132 /// Declaration location for this item.
134 /// The location of this variable that can be fed to
135 /// DWARFExpression::Evaluate().
137 /// Visible outside the containing compile unit?
138 unsigned m_external : 1;
139 /// Non-zero if the variable is not explicitly declared in source.
140 unsigned m_artificial : 1;
141 /// The m_location expression contains the constant variable value
142 /// data, not a DWARF location.
144 /// Non-zero if variable is static member of a class or struct.
145 unsigned m_static_member : 1;
146
147private:
148 Variable(const Variable &rhs) = delete;
149 Variable &operator=(const Variable &rhs) = delete;
150};
151
152} // namespace lldb_private
153
154#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:170
const RangeList & GetScopeRange() const
Definition Variable.h:68
DWARFExpressionList & LocationExpressionList()
Definition Variable.h:76
unsigned m_static_member
Non-zero if variable is static member of a class or struct.
Definition Variable.h:145
bool IsInScope(StackFrame *frame)
Definition Variable.cpp:274
SymbolContextScope * GetSymbolContextScope() const
Definition Variable.h:51
static void AutoComplete(const ExecutionContext &exe_ctx, CompletionRequest &request)
Definition Variable.cpp:720
CompilerDeclContext GetDeclContext()
Definition Variable.cpp:196
unsigned m_artificial
Non-zero if the variable is not explicitly declared in source.
Definition Variable.h:140
unsigned m_external
Visible outside the containing compile unit?
Definition Variable.h:138
bool LocationIsValidForAddress(const Address &address)
Definition Variable.cpp:238
unsigned m_loc_is_const_data
The m_location expression contains the constant variable value data, not a DWARF location.
Definition Variable.h:143
const Declaration & GetDeclaration() const
Definition Variable.h:45
lldb::SymbolFileTypeSP m_symfile_type_sp
The type pointer of the variable (int, struct, class, etc) global, parameter, local.
Definition Variable.h:125
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:131
ConstString GetUnqualifiedName() const
Definition Variable.cpp:80
static Status GetValuesForVariableExpressionPath(llvm::StringRef variable_expr_path, ExecutionContextScope *scope, GetVariableCallback callback, void *baton, VariableList &variable_list, ValueObjectList &valobj_list)
Definition Variable.cpp:326
Mangled m_mangled
The mangled name of the variable.
Definition Variable.h:122
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:82
void Dump(Stream *s, bool show_context) const
Definition Variable.cpp:104
lldb::ValueType m_scope
Definition Variable.h:126
SymbolContextScope * m_owner_scope
The symbol file scope that this variable was defined in.
Definition Variable.h:128
ConstString GetName() const
Definition Variable.cpp:73
CompilerDecl GetDecl()
Definition Variable.cpp:203
ConstString m_name
The basename of the variable (no namespaces).
Definition Variable.h:120
RangeVector< lldb::addr_t, lldb::addr_t > RangeList
Definition Variable.h:27
const DWARFExpressionList & LocationExpressionList() const
Definition Variable.h:78
Declaration m_declaration
Declaration location for this item.
Definition Variable.h:133
void CalculateSymbolContext(SymbolContext *sc)
Definition Variable.cpp:208
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)
Constructors and Destructors.
Definition Variable.cpp:40
void SetLocationIsConstantValueData(bool b)
Definition Variable.h:101
bool GetLocationIsConstantValueData() const
Definition Variable.h:99
bool DumpLocations(Stream *s, const Address &address)
Definition Variable.cpp:442
bool IsExternal() const
Definition Variable.h:70
Variable & operator=(const Variable &rhs)=delete
lldb::LanguageType GetLanguage() const
Definition Variable.cpp:56
size_t MemorySize() const
Definition Variable.cpp:194
bool IsStaticMember() const
Definition Variable.h:74
bool IsArtificial() const
Definition Variable.h:72
bool LocationIsValidForFrame(StackFrame *frame)
Definition Variable.cpp:216
size_t(* GetVariableCallback)(void *baton, const char *name, VariableList &var_list)
Definition Variable.h:103
DWARFExpressionList m_location_list
The location of this variable that can be fed to DWARFExpression::Evaluate().
Definition Variable.h:136
lldb::ValueType GetScope() const
Definition Variable.h:66
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