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
79 return m_location_list;
80 }
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
93
94 bool LocationIsValidForAddress(const Address &address);
95
97
99
100 typedef size_t (*GetVariableCallback)(void *baton, const char *name,
101 VariableList &var_list);
102
104 llvm::StringRef variable_expr_path, ExecutionContextScope *scope,
105 GetVariableCallback callback, void *baton, VariableList &variable_list,
106 ValueObjectList &valobj_list);
107
108 static void AutoComplete(const ExecutionContext &exe_ctx,
109 CompletionRequest &request);
110
112
114
115protected:
116 /// The basename of the variable (no namespaces).
118 /// The mangled name of the variable.
120 /// The type pointer of the variable (int, struct, class, etc)
121 /// global, parameter, local.
124 /// The symbol file scope that this variable was defined in
126 /// The list of ranges inside the owner's scope where this variable
127 /// is valid.
129 /// Declaration location for this item.
131 /// The location of this variable that can be fed to
132 /// DWARFExpression::Evaluate().
134 /// Visible outside the containing compile unit?
135 unsigned m_external : 1;
136 /// Non-zero if the variable is not explicitly declared in source.
137 unsigned m_artificial : 1;
138 /// The m_location expression contains the constant variable value
139 /// data, not a DWARF location.
141 /// Non-zero if variable is static member of a class or struct.
142 unsigned m_static_member : 1;
143
144private:
145 Variable(const Variable &rhs) = delete;
146 Variable &operator=(const Variable &rhs) = delete;
147};
148
149} // namespace lldb_private
150
151#endif // LLDB_SYMBOL_VARIABLE_H
A section + offset based address class.
Definition: Address.h:62
Represents a generic declaration context in a program.
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28
"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:33
This base class provides an interface to stack frames.
Definition: StackFrame.h:44
An error handling class.
Definition: Status.h:115
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.
Definition: SymbolContext.h:34
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:142
bool IsInScope(StackFrame *frame)
Definition: Variable.cpp:275
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:137
unsigned m_external
Visible outside the containing compile unit?
Definition: Variable.h:135
bool LocationIsValidForAddress(const Address &address)
Definition: Variable.cpp:239
unsigned m_loc_is_const_data
The m_location expression contains the constant variable value data, not a DWARF location.
Definition: Variable.h:140
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:122
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:128
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:325
Mangled m_mangled
The mangled name of the variable.
Definition: Variable.h:119
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:123
SymbolContextScope * m_owner_scope
The symbol file scope that this variable was defined in.
Definition: Variable.h:125
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:117
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:130
void CalculateSymbolContext(SymbolContext *sc)
Definition: Variable.cpp:208
void SetLocationIsConstantValueData(bool b)
Definition: Variable.h:98
bool GetLocationIsConstantValueData() const
Definition: Variable.h:96
bool DumpLocations(Stream *s, const Address &address)
Definition: Variable.cpp:441
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:100
DWARFExpressionList m_location_list
The location of this variable that can be fed to DWARFExpression::Evaluate().
Definition: Variable.h:133
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
Definition: lldb-forward.h:441
uint64_t user_id_t
Definition: lldb-types.h:82
A mix in class that contains a generic user ID.
Definition: UserID.h:31