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 liblldb_Variable_h_
10 #define liblldb_Variable_h_
11 
12 #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  Variable(lldb::user_id_t uid, const char *name,
31  const char
32  *mangled, // The mangled or fully qualified name of the variable.
33  const lldb::SymbolFileTypeSP &symfile_type_sp,
34  lldb::ValueType scope, SymbolContextScope *owner_scope,
35  const RangeList &scope_range, Declaration *decl,
36  const DWARFExpression &location, bool external, bool artificial,
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  bool IsExternal() const { return m_external; }
69 
70  bool IsArtificial() const { return m_artificial; }
71 
72  bool IsStaticMember() const { return m_static_member; }
73 
75 
76  const DWARFExpression &LocationExpression() const { return m_location; }
77 
78  bool DumpLocationForAddress(Stream *s, const Address &address);
79 
80  size_t MemorySize() const;
81 
83 
84  bool IsInScope(StackFrame *frame);
85 
87 
88  bool LocationIsValidForAddress(const Address &address);
89 
91 
93 
94  typedef size_t (*GetVariableCallback)(void *baton, const char *name,
95  VariableList &var_list);
96 
98  llvm::StringRef variable_expr_path, ExecutionContextScope *scope,
99  GetVariableCallback callback, void *baton, VariableList &variable_list,
100  ValueObjectList &valobj_list);
101 
102  static size_t AutoComplete(const ExecutionContext &exe_ctx,
103  CompletionRequest &request);
104 
106 
108 
109 protected:
110  ConstString m_name; // The basename of the variable (no namespaces)
111  Mangled m_mangled; // The mangled name of the variable
112  lldb::SymbolFileTypeSP m_symfile_type_sp; // The type pointer of the variable
113  // (int, struct, class, etc)
114  lldb::ValueType m_scope; // global, parameter, local
116  *m_owner_scope; // The symbol file scope that this variable was defined in
117  RangeList m_scope_range; // The list of ranges inside the owner's scope where
118  // this variable is valid
119  Declaration m_declaration; // Declaration location for this item.
120  DWARFExpression m_location; // The location of this variable that can be fed
121  // to DWARFExpression::Evaluate()
122  uint8_t m_external : 1, // Visible outside the containing compile unit?
123  m_artificial : 1, // Non-zero if the variable is not explicitly declared
124  // in source
125  m_loc_is_const_data : 1, // The m_location expression contains the
126  // constant variable value data, not a DWARF
127  // location
128  m_static_member : 1; // Non-zero if variable is static member of a class
129  // or struct.
130 private:
131  Variable(const Variable &rhs);
132  Variable &operator=(const Variable &rhs);
133 };
134 
135 } // namespace lldb_private
136 
137 #endif // liblldb_Variable_h_
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 static_member=false)
Definition: Variable.cpp:39
lldb::ValueType m_scope
Definition: Variable.h:114
RangeList m_scope_range
Definition: Variable.h:117
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
ConstString m_name
Definition: Variable.h:110
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
bool IsInScope(StackFrame *frame)
Definition: Variable.cpp:276
lldb::LanguageType GetLanguage() const
Definition: Variable.cpp:56
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
static Status GetValuesForVariableExpressionPath(llvm::StringRef variable_expr_path, ExecutionContextScope *scope, GetVariableCallback callback, void *baton, VariableList &variable_list, ValueObjectList &valobj_list)
Definition: Variable.cpp:326
"lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location expression and interprets it...
uint8_t m_loc_is_const_data
Definition: Variable.h:122
size_t(* GetVariableCallback)(void *baton, const char *name, VariableList &var_list)
Definition: Variable.h:94
A mix in class that contains a generic user ID.
Definition: UserID.h:33
SymbolContextScope * GetSymbolContextScope() const
Definition: Variable.h:51
"lldb/Utility/RegularExpression.h" A C++ wrapper class for regex.
const Declaration & GetDeclaration() const
Definition: Variable.h:45
static size_t AutoComplete(const ExecutionContext &exe_ctx, CompletionRequest &request)
Definition: Variable.cpp:756
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool GetLocationIsConstantValueData() const
Definition: Variable.h:90
void Dump(Stream *s, bool show_context) const
Definition: Variable.cpp:98
CompilerDecl GetDecl()
Definition: Variable.cpp:207
const DWARFExpression & LocationExpression() const
Definition: Variable.h:76
"lldb/Utility/ArgCompletionRequest.h"
bool LocationIsValidForFrame(StackFrame *frame)
Definition: Variable.cpp:220
DWARFExpression & LocationExpression()
Definition: Variable.h:74
ConstString GetName() const
Definition: Variable.cpp:64
Declaration m_declaration
Definition: Variable.h:119
bool IsExternal() const
Definition: Variable.h:68
uint64_t user_id_t
Definition: lldb-types.h:84
LanguageType
Programming language type.
bool LocationIsValidForAddress(const Address &address)
Definition: Variable.cpp:248
bool NameMatches(ConstString name) const
Definition: Variable.cpp:73
bool DumpLocationForAddress(Stream *s, const Address &address)
Definition: Variable.cpp:450
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
DWARFExpression m_location
Definition: Variable.h:120
void CalculateSymbolContext(SymbolContext *sc)
Definition: Variable.cpp:212
lldb::ValueType GetScope() const
Definition: Variable.h:66
A section + offset based address class.
Definition: Address.h:80
ConstString GetUnqualifiedName() const
Definition: Variable.cpp:71
bool IsStaticMember() const
Definition: Variable.h:72
size_t MemorySize() const
Definition: Variable.cpp:198
CompilerDeclContext GetDeclContext()
Definition: Variable.cpp:200
A uniqued constant string class.
Definition: ConstString.h:38
bool IsArtificial() const
Definition: Variable.h:70
bool DumpDeclaration(Stream *s, bool show_fullpaths, bool show_module)
Definition: Variable.cpp:174
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
lldb::SymbolFileTypeSP m_symfile_type_sp
Definition: Variable.h:112
void SetLocationIsConstantValueData(bool b)
Definition: Variable.h:92
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
SymbolContextScope * m_owner_scope
Definition: Variable.h:116
This base class provides an interface to stack frames.
Definition: StackFrame.h:40
RangeVector< lldb::addr_t, lldb::addr_t > RangeList
Definition: Variable.h:27
An error handling class.
Definition: Status.h:44