]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Expression/ExpressionVariable.h
MFV r337586: lua: Update to 5.3.5
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Expression / ExpressionVariable.h
1 //===-- ExpressionVariable.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_ExpressionVariable_h_
11 #define liblldb_ExpressionVariable_h_
12
13 // C Includes
14 // C++ Includes
15 #include <memory>
16 #include <vector>
17
18 // Other libraries and framework includes
19 #include "llvm/ADT/DenseMap.h"
20
21 // Project includes
22 #include "lldb/Core/ValueObject.h"
23 #include "lldb/Utility/ConstString.h"
24 #include "lldb/lldb-public.h"
25
26 namespace lldb_private {
27
28 class ClangExpressionVariable;
29
30 class ExpressionVariable
31     : public std::enable_shared_from_this<ExpressionVariable> {
32 public:
33   //----------------------------------------------------------------------
34   // See TypeSystem.h for how to add subclasses to this.
35   //----------------------------------------------------------------------
36   enum LLVMCastKind { eKindClang, eKindSwift, eKindGo, kNumKinds };
37
38   LLVMCastKind getKind() const { return m_kind; }
39
40   ExpressionVariable(LLVMCastKind kind) : m_flags(0), m_kind(kind) {}
41
42   virtual ~ExpressionVariable();
43
44   size_t GetByteSize() { return m_frozen_sp->GetByteSize(); }
45
46   const ConstString &GetName() { return m_frozen_sp->GetName(); }
47
48   lldb::ValueObjectSP GetValueObject() { return m_frozen_sp; }
49
50   uint8_t *GetValueBytes();
51
52   void ValueUpdated() { m_frozen_sp->ValueUpdated(); }
53
54   RegisterInfo *GetRegisterInfo() {
55     return m_frozen_sp->GetValue().GetRegisterInfo();
56   }
57
58   void SetRegisterInfo(const RegisterInfo *reg_info) {
59     return m_frozen_sp->GetValue().SetContext(
60         Value::eContextTypeRegisterInfo, const_cast<RegisterInfo *>(reg_info));
61   }
62
63   CompilerType GetCompilerType() { return m_frozen_sp->GetCompilerType(); }
64
65   void SetCompilerType(const CompilerType &compiler_type) {
66     m_frozen_sp->GetValue().SetCompilerType(compiler_type);
67   }
68
69   void SetName(const ConstString &name) { m_frozen_sp->SetName(name); }
70
71   // this function is used to copy the address-of m_live_sp into m_frozen_sp
72   // this is necessary because the results of certain cast and
73   // pointer-arithmetic
74   // operations (such as those described in bugzilla issues 11588 and 11618)
75   // generate
76   // frozen objects that do not have a valid address-of, which can be
77   // troublesome when
78   // using synthetic children providers. Transferring the address-of the live
79   // object
80   // solves these issues and provides the expected user-level behavior
81   void TransferAddress(bool force = false) {
82     if (m_live_sp.get() == nullptr)
83       return;
84
85     if (m_frozen_sp.get() == nullptr)
86       return;
87
88     if (force || (m_frozen_sp->GetLiveAddress() == LLDB_INVALID_ADDRESS))
89       m_frozen_sp->SetLiveAddress(m_live_sp->GetLiveAddress());
90   }
91
92   enum Flags {
93     EVNone = 0,
94     EVIsLLDBAllocated = 1 << 0, ///< This variable is resident in a location
95                                 ///specifically allocated for it by LLDB in the
96                                 ///target process
97     EVIsProgramReference = 1 << 1, ///< This variable is a reference to a
98                                    ///(possibly invalid) area managed by the
99                                    ///target program
100     EVNeedsAllocation = 1 << 2,    ///< Space for this variable has yet to be
101                                    ///allocated in the target process
102     EVIsFreezeDried = 1 << 3, ///< This variable's authoritative version is in
103                               ///m_frozen_sp (for example, for
104                               ///statically-computed results)
105     EVNeedsFreezeDry =
106         1 << 4, ///< Copy from m_live_sp to m_frozen_sp during dematerialization
107     EVKeepInTarget = 1 << 5, ///< Keep the allocation after the expression is
108                              ///complete rather than freeze drying its contents
109                              ///and freeing it
110     EVTypeIsReference = 1 << 6, ///< The original type of this variable is a
111                                 ///reference, so materialize the value rather
112                                 ///than the location
113     EVUnknownType = 1 << 7, ///< This is a symbol of unknown type, and the type
114                             ///must be resolved after parsing is complete
115     EVBareRegister = 1 << 8 ///< This variable is a direct reference to $pc or
116                             ///some other entity.
117   };
118
119   typedef uint16_t FlagType;
120
121   FlagType m_flags; // takes elements of Flags
122
123   // these should be private
124   lldb::ValueObjectSP m_frozen_sp;
125   lldb::ValueObjectSP m_live_sp;
126   LLVMCastKind m_kind;
127 };
128
129 //----------------------------------------------------------------------
130 /// @class ExpressionVariableList ExpressionVariable.h
131 /// "lldb/Expression/ExpressionVariable.h"
132 /// @brief A list of variable references.
133 ///
134 /// This class stores variables internally, acting as the permanent store.
135 //----------------------------------------------------------------------
136 class ExpressionVariableList {
137 public:
138   //----------------------------------------------------------------------
139   /// Implementation of methods in ExpressionVariableListBase
140   //----------------------------------------------------------------------
141   size_t GetSize() { return m_variables.size(); }
142
143   lldb::ExpressionVariableSP GetVariableAtIndex(size_t index) {
144     lldb::ExpressionVariableSP var_sp;
145     if (index < m_variables.size())
146       var_sp = m_variables[index];
147     return var_sp;
148   }
149
150   size_t AddVariable(const lldb::ExpressionVariableSP &var_sp) {
151     m_variables.push_back(var_sp);
152     return m_variables.size() - 1;
153   }
154
155   lldb::ExpressionVariableSP
156   AddNewlyConstructedVariable(ExpressionVariable *var) {
157     lldb::ExpressionVariableSP var_sp(var);
158     m_variables.push_back(var_sp);
159     return m_variables.back();
160   }
161
162   bool ContainsVariable(const lldb::ExpressionVariableSP &var_sp) {
163     const size_t size = m_variables.size();
164     for (size_t index = 0; index < size; ++index) {
165       if (m_variables[index].get() == var_sp.get())
166         return true;
167     }
168     return false;
169   }
170
171   //----------------------------------------------------------------------
172   /// Finds a variable by name in the list.
173   ///
174   /// @param[in] name
175   ///     The name of the requested variable.
176   ///
177   /// @return
178   ///     The variable requested, or nullptr if that variable is not in the
179   ///     list.
180   //----------------------------------------------------------------------
181   lldb::ExpressionVariableSP GetVariable(const ConstString &name) {
182     lldb::ExpressionVariableSP var_sp;
183     for (size_t index = 0, size = GetSize(); index < size; ++index) {
184       var_sp = GetVariableAtIndex(index);
185       if (var_sp->GetName() == name)
186         return var_sp;
187     }
188     var_sp.reset();
189     return var_sp;
190   }
191
192   lldb::ExpressionVariableSP GetVariable(llvm::StringRef name) {
193     if (name.empty())
194       return nullptr;
195
196     for (size_t index = 0, size = GetSize(); index < size; ++index) {
197       auto var_sp = GetVariableAtIndex(index);
198       llvm::StringRef var_name_str = var_sp->GetName().GetStringRef();
199       if (var_name_str == name)
200         return var_sp;
201     }
202     return nullptr;
203   }
204
205   void RemoveVariable(lldb::ExpressionVariableSP var_sp) {
206     for (std::vector<lldb::ExpressionVariableSP>::iterator
207              vi = m_variables.begin(),
208              ve = m_variables.end();
209          vi != ve; ++vi) {
210       if (vi->get() == var_sp.get()) {
211         m_variables.erase(vi);
212         return;
213       }
214     }
215   }
216
217   void Clear() { m_variables.clear(); }
218
219 private:
220   std::vector<lldb::ExpressionVariableSP> m_variables;
221 };
222
223 class PersistentExpressionState : public ExpressionVariableList {
224 public:
225   //----------------------------------------------------------------------
226   // See TypeSystem.h for how to add subclasses to this.
227   //----------------------------------------------------------------------
228   enum LLVMCastKind { eKindClang, eKindSwift, eKindGo, kNumKinds };
229
230   LLVMCastKind getKind() const { return m_kind; }
231
232   PersistentExpressionState(LLVMCastKind kind) : m_kind(kind) {}
233
234   virtual ~PersistentExpressionState();
235
236   virtual lldb::ExpressionVariableSP
237   CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) = 0;
238
239   virtual lldb::ExpressionVariableSP
240   CreatePersistentVariable(ExecutionContextScope *exe_scope,
241                            const ConstString &name, const CompilerType &type,
242                            lldb::ByteOrder byte_order,
243                            uint32_t addr_byte_size) = 0;
244
245   virtual ConstString GetNextPersistentVariableName() = 0;
246
247   virtual void
248   RemovePersistentVariable(lldb::ExpressionVariableSP variable) = 0;
249
250   virtual lldb::addr_t LookupSymbol(const ConstString &name);
251
252   void RegisterExecutionUnit(lldb::IRExecutionUnitSP &execution_unit_sp);
253
254 private:
255   LLVMCastKind m_kind;
256
257   typedef std::set<lldb::IRExecutionUnitSP> ExecutionUnitSet;
258   ExecutionUnitSet
259       m_execution_units; ///< The execution units that contain valuable symbols.
260
261   typedef llvm::DenseMap<const char *, lldb::addr_t> SymbolMap;
262   SymbolMap
263       m_symbol_map; ///< The addresses of the symbols in m_execution_units.
264 };
265
266 } // namespace lldb_private
267
268 #endif // liblldb_ExpressionVariable_h_