xref: /NextBSD/contrib/llvm/tools/lldb/include/lldb/Symbol/Variable.h (revision 84d351007654069f9643c8e4b4802a7f5f08ee42)
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 <vector>
14 
15 #include "lldb/lldb-private.h"
16 #include "lldb/lldb-enumerations.h"
17 #include "lldb/Core/Mangled.h"
18 #include "lldb/Core/UserID.h"
19 #include "lldb/Expression/DWARFExpression.h"
20 #include "lldb/Symbol/Declaration.h"
21 
22 namespace lldb_private {
23 
24 class Variable : public UserID
25 {
26 public:
27     //------------------------------------------------------------------
28     // Constructors and Destructors
29     //------------------------------------------------------------------
30     Variable (lldb::user_id_t uid,
31               const char *name,
32               const char *mangled,  // The mangled or fully qualified name of the variable.
33               const lldb::SymbolFileTypeSP &symfile_type_sp,
34               lldb::ValueType scope,
35               SymbolContextScope *owner_scope,
36               Declaration* decl,
37               const DWARFExpression& location,
38               bool external,
39               bool artificial);
40 
41     virtual
42     ~Variable();
43 
44     void
45     Dump(Stream *s, bool show_context) const;
46 
47     bool
48     DumpDeclaration (Stream *s,
49                      bool show_fullpaths,
50                      bool show_module);
51 
52     const Declaration&
GetDeclaration()53     GetDeclaration() const
54     {
55         return m_declaration;
56     }
57 
58     ConstString
59     GetName() const;
60 
61     SymbolContextScope *
GetSymbolContextScope()62     GetSymbolContextScope() const
63     {
64         return m_owner_scope;
65     }
66 
67     // Since a variable can have a basename "i" and also a mangled
68     // named "_ZN12_GLOBAL__N_11iE" and a demangled mangled name
69     // "(anonymous namespace)::i", this function will allow a generic match
70     // function that can be called by commands and expression parsers to make
71     // sure we match anything we come across.
72     bool
73     NameMatches (const ConstString &name) const;
74 
75     bool
76     NameMatches (const RegularExpression& regex) const;
77 
78     Type *
79     GetType();
80 
81     lldb::LanguageType
82     GetLanguage () const;
83 
84     lldb::ValueType
GetScope()85     GetScope() const
86     {
87         return m_scope;
88     }
89 
90     bool
IsExternal()91     IsExternal() const
92     {
93         return m_external;
94     }
95 
96     bool
IsArtificial()97     IsArtificial() const
98     {
99         return m_artificial;
100     }
101 
102     DWARFExpression &
LocationExpression()103     LocationExpression()
104     {
105         return m_location;
106     }
107 
108     const DWARFExpression &
LocationExpression()109     LocationExpression() const
110     {
111         return m_location;
112     }
113 
114     bool
115     DumpLocationForAddress (Stream *s,
116                             const Address &address);
117 
118     size_t
119     MemorySize() const;
120 
121     void
122     CalculateSymbolContext (SymbolContext *sc);
123 
124     bool
125     IsInScope (StackFrame *frame);
126 
127     bool
128     LocationIsValidForFrame (StackFrame *frame);
129 
130     bool
131     LocationIsValidForAddress (const Address &address);
132 
133     bool
GetLocationIsConstantValueData()134     GetLocationIsConstantValueData () const
135     {
136         return m_loc_is_const_data;
137     }
138 
139     void
SetLocationIsConstantValueData(bool b)140     SetLocationIsConstantValueData (bool b)
141     {
142         m_loc_is_const_data = b;
143     }
144 
145     typedef size_t (*GetVariableCallback) (void *baton,
146                                            const char *name,
147                                            VariableList &var_list);
148 
149 
150     static Error
151     GetValuesForVariableExpressionPath (const char *variable_expr_path,
152                                         ExecutionContextScope *scope,
153                                         GetVariableCallback callback,
154                                         void *baton,
155                                         VariableList &variable_list,
156                                         ValueObjectList &valobj_list);
157 
158     static size_t
159     AutoComplete (const ExecutionContext &exe_ctx,
160                   const char *name,
161                   StringList &matches,
162                   bool &word_complete);
163 
164 protected:
165     ConstString m_name;                 // The basename of the variable (no namespaces)
166     Mangled m_mangled;                  // The mangled name of the variable
167     lldb::SymbolFileTypeSP m_symfile_type_sp;   // The type pointer of the variable (int, struct, class, etc)
168     lldb::ValueType m_scope;            // global, parameter, local
169     SymbolContextScope *m_owner_scope;  // The symbol file scope that this variable was defined in
170     Declaration m_declaration;          // Declaration location for this item.
171     DWARFExpression m_location;         // The location of this variable that can be fed to DWARFExpression::Evaluate()
172     uint8_t m_external:1,               // Visible outside the containing compile unit?
173             m_artificial:1,             // Non-zero if the variable is not explicitly declared in source
174             m_loc_is_const_data:1;      // The m_location expression contains the constant variable value data, not a DWARF location
175 private:
176     Variable(const Variable& rhs);
177     Variable& operator=(const Variable& rhs);
178 };
179 
180 } // namespace lldb_private
181 
182 #endif  // liblldb_Variable_h_
183