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 
12 #include "lldb/Core/Declaration.h"
13 #include "lldb/Core/Mangled.h"
16 #include "lldb/Utility/RangeMap.h"
17 #include "lldb/Utility/UserID.h"
18 #include "lldb/lldb-enumerations.h"
19 #include "lldb/lldb-private.h"
20 #include <memory>
21 #include <vector>
22 
23 namespace lldb_private {
24 
25 class Variable : public UserID, public std::enable_shared_from_this<Variable> {
26 public:
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 DWARFExpression &location, bool external,
36  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 
78  const DWARFExpression &LocationExpression() const { return m_location; }
79 
80  // When given invalid address, it dumps all locations. Otherwise it only dumps
81  // the location that contains this address.
82  bool DumpLocations(Stream *s, const Address &address);
83 
84  size_t MemorySize() const;
85 
87 
88  bool IsInScope(StackFrame *frame);
89 
91 
92  bool LocationIsValidForAddress(const Address &address);
93 
95 
97 
98  typedef size_t (*GetVariableCallback)(void *baton, const char *name,
99  VariableList &var_list);
100 
102  llvm::StringRef variable_expr_path, ExecutionContextScope *scope,
103  GetVariableCallback callback, void *baton, VariableList &variable_list,
104  ValueObjectList &valobj_list);
105 
106  static void AutoComplete(const ExecutionContext &exe_ctx,
107  CompletionRequest &request);
108 
110 
112 
113 protected:
114  /// The basename of the variable (no namespaces).
116  /// The mangled name of the variable.
117  Mangled m_mangled;
118  /// The type pointer of the variable (int, struct, class, etc)
119  /// global, parameter, local.
120  lldb::SymbolFileTypeSP m_symfile_type_sp;
122  /// The symbol file scope that this variable was defined in
124  /// The list of ranges inside the owner's scope where this variable
125  /// is valid.
127  /// Declaration location for this item.
129  /// The location of this variable that can be fed to
130  /// DWARFExpression::Evaluate().
132  /// Visible outside the containing compile unit?
133  unsigned m_external : 1;
134  /// Non-zero if the variable is not explicitly declared in source.
135  unsigned m_artificial : 1;
136  /// The m_location expression contains the constant variable value
137  /// data, not a DWARF location.
138  unsigned m_loc_is_const_data : 1;
139  /// Non-zero if variable is static member of a class or struct.
140  unsigned m_static_member : 1;
141 
142 private:
143  Variable(const Variable &rhs) = delete;
144  Variable &operator=(const Variable &rhs) = delete;
145 };
146 
147 } // namespace lldb_private
148 
149 #endif // LLDB_SYMBOL_VARIABLE_H
lldb_private::Variable::DumpDeclaration
bool DumpDeclaration(Stream *s, bool show_fullpaths, bool show_module)
Definition: Variable.cpp:168
lldb_private::Variable::m_owner_scope
SymbolContextScope * m_owner_scope
The symbol file scope that this variable was defined in.
Definition: Variable.h:123
lldb_private::Variable::GetScope
lldb::ValueType GetScope() const
Definition: Variable.h:66
lldb_private::ValueObjectList
A collection of ValueObject values that.
Definition: ValueObjectList.h:23
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
Mangled.h
lldb_private::RegularExpression
Definition: RegularExpression.h:18
lldb_private::Variable::m_scope
lldb::ValueType m_scope
Definition: Variable.h:121
lldb_private::Variable::GetVariableCallback
size_t(* GetVariableCallback)(void *baton, const char *name, VariableList &var_list)
Definition: Variable.h:98
lldb_private::UserID
Definition: UserID.h:31
lldb_private::Variable::m_symfile_type_sp
lldb::SymbolFileTypeSP m_symfile_type_sp
The type pointer of the variable (int, struct, class, etc) global, parameter, local.
Definition: Variable.h:120
lldb_private::Variable::LocationExpression
const DWARFExpression & LocationExpression() const
Definition: Variable.h:78
lldb_private::Variable::IsExternal
bool IsExternal() const
Definition: Variable.h:70
lldb_private::Variable::MemorySize
size_t MemorySize() const
Definition: Variable.cpp:192
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
lldb_private::CompilerDecl
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28
lldb_private::Variable::GetSymbolContextScope
SymbolContextScope * GetSymbolContextScope() const
Definition: Variable.h:51
lldb_private::Variable::DumpLocations
bool DumpLocations(Stream *s, const Address &address)
Definition: Variable.cpp:446
lldb_private::Stream
Definition: Stream.h:28
RangeMap.h
lldb_private::Variable::GetName
ConstString GetName() const
Definition: Variable.cpp:71
lldb_private::SymbolContext
Definition: SymbolContext.h:33
CompletionRequest.h
lldb_private::VariableList
Definition: VariableList.h:18
lldb_private::Variable::m_name
ConstString m_name
The basename of the variable (no namespaces).
Definition: Variable.h:115
lldb_private::Variable::IsArtificial
bool IsArtificial() const
Definition: Variable.h:72
lldb_private::Variable::IsInScope
bool IsInScope(StackFrame *frame)
Definition: Variable.cpp:278
lldb_private::ExecutionContextScope
Definition: ExecutionContextScope.h:32
lldb_private::Variable::GetDeclaration
const Declaration & GetDeclaration() const
Definition: Variable.h:45
Declaration.h
lldb_private::DWARFExpression
Definition: DWARFExpression.h:36
lldb_private::Variable::GetLanguage
lldb::LanguageType GetLanguage() const
Definition: Variable.cpp:54
lldb_private::Variable::RangeList
RangeVector< lldb::addr_t, lldb::addr_t > RangeList
Definition: Variable.h:27
lldb_private::ConstString
Definition: ConstString.h:40
lldb-enumerations.h
lldb_private::Variable::operator=
Variable & operator=(const Variable &rhs)=delete
lldb_private::Variable::GetValuesForVariableExpressionPath
static Status GetValuesForVariableExpressionPath(llvm::StringRef variable_expr_path, ExecutionContextScope *scope, GetVariableCallback callback, void *baton, VariableList &variable_list, ValueObjectList &valobj_list)
Definition: Variable.cpp:328
lldb_private::Variable::m_external
unsigned m_external
Visible outside the containing compile unit?
Definition: Variable.h:133
lldb_private::Variable::m_scope_range
RangeList m_scope_range
The list of ranges inside the owner's scope where this variable is valid.
Definition: Variable.h:126
lldb_private::Variable::m_loc_is_const_data
unsigned m_loc_is_const_data
The m_location expression contains the constant variable value data, not a DWARF location.
Definition: Variable.h:138
lldb_private::Variable::NameMatches
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:80
lldb_private::RangeVector< lldb::addr_t, lldb::addr_t >
lldb_private::Variable::GetDeclContext
CompilerDeclContext GetDeclContext()
Definition: Variable.cpp:194
UserID.h
lldb_private::CompilerDeclContext
Represents a generic declaration context in a program.
Definition: CompilerDeclContext.h:30
lldb_private::SymbolContextScope
Definition: SymbolContextScope.h:64
lldb_private::Variable::AutoComplete
static void AutoComplete(const ExecutionContext &exe_ctx, CompletionRequest &request)
Definition: Variable.cpp:720
lldb-private.h
lldb_private::Variable::GetDecl
CompilerDecl GetDecl()
Definition: Variable.cpp:201
lldb_private::Status
Definition: Status.h:44
lldb::ValueType
ValueType
Definition: lldb-enumerations.h:315
lldb_private::Variable::GetScopeRange
const RangeList & GetScopeRange() const
Definition: Variable.h:68
lldb_private::Address
Definition: Address.h:59
lldb_private::Type
Definition: Type.h:66
lldb_private::Variable::IsStaticMember
bool IsStaticMember() const
Definition: Variable.h:74
lldb_private::Variable::LocationIsValidForAddress
bool LocationIsValidForAddress(const Address &address)
Definition: Variable.cpp:242
lldb_private::Variable::m_location
DWARFExpression m_location
The location of this variable that can be fed to DWARFExpression::Evaluate().
Definition: Variable.h:131
lldb_private::Variable::~Variable
virtual ~Variable()
lldb_private::Variable::CalculateSymbolContext
void CalculateSymbolContext(SymbolContext *sc)
Definition: Variable.cpp:206
lldb_private::Variable::LocationExpression
DWARFExpression & LocationExpression()
Definition: Variable.h:76
DWARFExpression.h
lldb_private::Variable::m_mangled
Mangled m_mangled
The mangled name of the variable.
Definition: Variable.h:117
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::Variable::SetLocationIsConstantValueData
void SetLocationIsConstantValueData(bool b)
Definition: Variable.h:96
lldb_private::Variable::GetLocationIsConstantValueData
bool GetLocationIsConstantValueData() const
Definition: Variable.h:94
lldb_private::Variable::GetType
Type * GetType()
Definition: Variable.cpp:96
lldb_private::Variable
Definition: Variable.h:25
lldb_private::Variable::LocationIsValidForFrame
bool LocationIsValidForFrame(StackFrame *frame)
Definition: Variable.cpp:214
lldb_private::Variable::m_static_member
unsigned m_static_member
Non-zero if variable is static member of a class or struct.
Definition: Variable.h:140
lldb_private::Declaration
Definition: Declaration.h:24
lldb_private::StackFrame
Definition: StackFrame.h:40
lldb_private::Variable::GetUnqualifiedName
ConstString GetUnqualifiedName() const
Definition: Variable.cpp:78
lldb_private::Variable::m_artificial
unsigned m_artificial
Non-zero if the variable is not explicitly declared in source.
Definition: Variable.h:135
lldb_private::Variable::m_declaration
Declaration m_declaration
Declaration location for this item.
Definition: Variable.h:128
lldb_private::CompletionRequest
Definition: CompletionRequest.h:100
lldb_private::Variable::Dump
void Dump(Stream *s, bool show_context) const
Definition: Variable.cpp:102
lldb_private::Variable::Variable
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 DWARFExpression &location, bool external, bool artificial, bool location_is_constant_data, bool static_member=false)
Constructors and Destructors.
Definition: Variable.cpp:38