Variable.h revision 360660
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"
13#include "lldb/Expression/DWARFExpression.h"
14#include "lldb/Symbol/Declaration.h"
15#include "lldb/Utility/CompletionRequest.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
23namespace lldb_private {
24
25class Variable : public UserID, public std::enable_shared_from_this<Variable> {
26public:
27  typedef RangeVector<lldb::addr_t, lldb::addr_t> RangeList;
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
49  ConstString GetUnqualifiedName() const;
50
51  SymbolContextScope *GetSymbolContextScope() const { return m_owner_scope; }
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
64  lldb::LanguageType GetLanguage() const;
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
74  DWARFExpression &LocationExpression() { return m_location; }
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
82  void CalculateSymbolContext(SymbolContext *sc);
83
84  bool IsInScope(StackFrame *frame);
85
86  bool LocationIsValidForFrame(StackFrame *frame);
87
88  bool LocationIsValidForAddress(const Address &address);
89
90  bool GetLocationIsConstantValueData() const { return m_loc_is_const_data; }
91
92  void SetLocationIsConstantValueData(bool b) { m_loc_is_const_data = b; }
93
94  typedef size_t (*GetVariableCallback)(void *baton, const char *name,
95                                        VariableList &var_list);
96
97  static Status GetValuesForVariableExpressionPath(
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
105  CompilerDeclContext GetDeclContext();
106
107  CompilerDecl GetDecl();
108
109protected:
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
115  SymbolContextScope
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.
130private:
131  Variable(const Variable &rhs) = delete;
132  Variable &operator=(const Variable &rhs) = delete;
133};
134
135} // namespace lldb_private
136
137#endif // liblldb_Variable_h_
138