1 //===-- Variable.h -----------------------------------------------*- C++-*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef liblldb_Variable_h_
11 #define liblldb_Variable_h_
12 
13 #include <memory>
14 #include <vector>
15 
16 #include "lldb/Core/Mangled.h"
17 #include "lldb/Core/RangeMap.h"
18 #include "lldb/Expression/DWARFExpression.h"
19 #include "lldb/Symbol/Declaration.h"
20 #include "lldb/Utility/CompletionRequest.h"
21 #include "lldb/Utility/UserID.h"
22 #include "lldb/lldb-enumerations.h"
23 #include "lldb/lldb-private.h"
24 
25 namespace lldb_private {
26 
27 class Variable : public UserID, public std::enable_shared_from_this<Variable> {
28 public:
29   typedef RangeVector<lldb::addr_t, lldb::addr_t> RangeList;
30 
31   //------------------------------------------------------------------
32   // Constructors and Destructors
33   //------------------------------------------------------------------
34   Variable(lldb::user_id_t uid, const char *name,
35            const char
36                *mangled, // The mangled or fully qualified name of the variable.
37            const lldb::SymbolFileTypeSP &symfile_type_sp,
38            lldb::ValueType scope, SymbolContextScope *owner_scope,
39            const RangeList &scope_range, Declaration *decl,
40            const DWARFExpression &location, bool external, bool artificial,
41            bool static_member = false);
42 
43   virtual ~Variable();
44 
45   void Dump(Stream *s, bool show_context) const;
46 
47   bool DumpDeclaration(Stream *s, bool show_fullpaths, bool show_module);
48 
GetDeclaration()49   const Declaration &GetDeclaration() const { return m_declaration; }
50 
51   ConstString GetName() const;
52 
53   ConstString GetUnqualifiedName() const;
54 
GetSymbolContextScope()55   SymbolContextScope *GetSymbolContextScope() const { return m_owner_scope; }
56 
57   // Since a variable can have a basename "i" and also a mangled named
58   // "_ZN12_GLOBAL__N_11iE" and a demangled mangled name "(anonymous
59   // namespace)::i", this function will allow a generic match function that can
60   // be called by commands and expression parsers to make sure we match
61   // anything we come across.
62   bool NameMatches(const ConstString &name) const;
63 
64   bool NameMatches(const RegularExpression &regex) const;
65 
66   Type *GetType();
67 
68   lldb::LanguageType GetLanguage() const;
69 
GetScope()70   lldb::ValueType GetScope() const { return m_scope; }
71 
IsExternal()72   bool IsExternal() const { return m_external; }
73 
IsArtificial()74   bool IsArtificial() const { return m_artificial; }
75 
IsStaticMember()76   bool IsStaticMember() const { return m_static_member; }
77 
LocationExpression()78   DWARFExpression &LocationExpression() { return m_location; }
79 
LocationExpression()80   const DWARFExpression &LocationExpression() const { return m_location; }
81 
82   bool DumpLocationForAddress(Stream *s, const Address &address);
83 
84   size_t MemorySize() const;
85 
86   void CalculateSymbolContext(SymbolContext *sc);
87 
88   bool IsInScope(StackFrame *frame);
89 
90   bool LocationIsValidForFrame(StackFrame *frame);
91 
92   bool LocationIsValidForAddress(const Address &address);
93 
GetLocationIsConstantValueData()94   bool GetLocationIsConstantValueData() const { return m_loc_is_const_data; }
95 
SetLocationIsConstantValueData(bool b)96   void SetLocationIsConstantValueData(bool b) { m_loc_is_const_data = b; }
97 
98   typedef size_t (*GetVariableCallback)(void *baton, const char *name,
99                                         VariableList &var_list);
100 
101   static Status GetValuesForVariableExpressionPath(
102       llvm::StringRef variable_expr_path, ExecutionContextScope *scope,
103       GetVariableCallback callback, void *baton, VariableList &variable_list,
104       ValueObjectList &valobj_list);
105 
106   static size_t AutoComplete(const ExecutionContext &exe_ctx,
107                              CompletionRequest &request);
108 
109   CompilerDeclContext GetDeclContext();
110 
111   CompilerDecl GetDecl();
112 
113 protected:
114   ConstString m_name; // The basename of the variable (no namespaces)
115   Mangled m_mangled;  // The mangled name of the variable
116   lldb::SymbolFileTypeSP m_symfile_type_sp; // The type pointer of the variable
117                                             // (int, struct, class, etc)
118   lldb::ValueType m_scope;                  // global, parameter, local
119   SymbolContextScope
120       *m_owner_scope; // The symbol file scope that this variable was defined in
121   RangeList m_scope_range; // The list of ranges inside the owner's scope where
122                            // this variable is valid
123   Declaration m_declaration;  // Declaration location for this item.
124   DWARFExpression m_location; // The location of this variable that can be fed
125                               // to DWARFExpression::Evaluate()
126   uint8_t m_external : 1,     // Visible outside the containing compile unit?
127       m_artificial : 1, // Non-zero if the variable is not explicitly declared
128                         // in source
129       m_loc_is_const_data : 1, // The m_location expression contains the
130                                // constant variable value data, not a DWARF
131                                // location
132       m_static_member : 1; // Non-zero if variable is static member of a class
133                            // or struct.
134 private:
135   Variable(const Variable &rhs);
136   Variable &operator=(const Variable &rhs);
137 };
138 
139 } // namespace lldb_private
140 
141 #endif // liblldb_Variable_h_
142