1 //===-- ExpressionVariable.h ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ExpressionVariable_h_
11 #define liblldb_ExpressionVariable_h_
18 // Other libraries and framework includes
19 #include "llvm/ADT/DenseMap.h"
22 #include "lldb/Core/ValueObject.h"
23 #include "lldb/Utility/ConstString.h"
24 #include "lldb/lldb-public.h"
26 namespace lldb_private {
28 class ClangExpressionVariable;
30 class ExpressionVariable
31 : public std::enable_shared_from_this<ExpressionVariable> {
33 //----------------------------------------------------------------------
34 // See TypeSystem.h for how to add subclasses to this.
35 //----------------------------------------------------------------------
36 enum LLVMCastKind { eKindClang, eKindSwift, eKindGo, kNumKinds };
38 LLVMCastKind getKind() const { return m_kind; }
40 ExpressionVariable(LLVMCastKind kind) : m_flags(0), m_kind(kind) {}
42 virtual ~ExpressionVariable();
44 size_t GetByteSize() { return m_frozen_sp->GetByteSize(); }
46 const ConstString &GetName() { return m_frozen_sp->GetName(); }
48 lldb::ValueObjectSP GetValueObject() { return m_frozen_sp; }
50 uint8_t *GetValueBytes();
52 void ValueUpdated() { m_frozen_sp->ValueUpdated(); }
54 RegisterInfo *GetRegisterInfo() {
55 return m_frozen_sp->GetValue().GetRegisterInfo();
58 void SetRegisterInfo(const RegisterInfo *reg_info) {
59 return m_frozen_sp->GetValue().SetContext(
60 Value::eContextTypeRegisterInfo, const_cast<RegisterInfo *>(reg_info));
63 CompilerType GetCompilerType() { return m_frozen_sp->GetCompilerType(); }
65 void SetCompilerType(const CompilerType &compiler_type) {
66 m_frozen_sp->GetValue().SetCompilerType(compiler_type);
69 void SetName(const ConstString &name) { m_frozen_sp->SetName(name); }
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
74 // operations (such as those described in bugzilla issues 11588 and 11618)
76 // frozen objects that do not have a valid address-of, which can be
78 // using synthetic children providers. Transferring the address-of the live
80 // solves these issues and provides the expected user-level behavior
81 void TransferAddress(bool force = false) {
82 if (m_live_sp.get() == nullptr)
85 if (m_frozen_sp.get() == nullptr)
88 if (force || (m_frozen_sp->GetLiveAddress() == LLDB_INVALID_ADDRESS))
89 m_frozen_sp->SetLiveAddress(m_live_sp->GetLiveAddress());
94 EVIsLLDBAllocated = 1 << 0, ///< This variable is resident in a location
95 ///specifically allocated for it by LLDB in the
97 EVIsProgramReference = 1 << 1, ///< This variable is a reference to a
98 ///(possibly invalid) area managed by the
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)
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
110 EVTypeIsReference = 1 << 6, ///< The original type of this variable is a
111 ///reference, so materialize the value rather
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.
119 typedef uint16_t FlagType;
121 FlagType m_flags; // takes elements of Flags
123 // these should be private
124 lldb::ValueObjectSP m_frozen_sp;
125 lldb::ValueObjectSP m_live_sp;
129 //----------------------------------------------------------------------
130 /// @class ExpressionVariableList ExpressionVariable.h
131 /// "lldb/Expression/ExpressionVariable.h"
132 /// @brief A list of variable references.
134 /// This class stores variables internally, acting as the permanent store.
135 //----------------------------------------------------------------------
136 class ExpressionVariableList {
138 //----------------------------------------------------------------------
139 /// Implementation of methods in ExpressionVariableListBase
140 //----------------------------------------------------------------------
141 size_t GetSize() { return m_variables.size(); }
143 lldb::ExpressionVariableSP GetVariableAtIndex(size_t index) {
144 lldb::ExpressionVariableSP var_sp;
145 if (index < m_variables.size())
146 var_sp = m_variables[index];
150 size_t AddVariable(const lldb::ExpressionVariableSP &var_sp) {
151 m_variables.push_back(var_sp);
152 return m_variables.size() - 1;
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();
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())
171 //----------------------------------------------------------------------
172 /// Finds a variable by name in the list.
175 /// The name of the requested variable.
178 /// The variable requested, or nullptr if that variable is not in the
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)
192 lldb::ExpressionVariableSP GetVariable(llvm::StringRef name) {
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)
205 void RemoveVariable(lldb::ExpressionVariableSP var_sp) {
206 for (std::vector<lldb::ExpressionVariableSP>::iterator
207 vi = m_variables.begin(),
208 ve = m_variables.end();
210 if (vi->get() == var_sp.get()) {
211 m_variables.erase(vi);
217 void Clear() { m_variables.clear(); }
220 std::vector<lldb::ExpressionVariableSP> m_variables;
223 class PersistentExpressionState : public ExpressionVariableList {
225 //----------------------------------------------------------------------
226 // See TypeSystem.h for how to add subclasses to this.
227 //----------------------------------------------------------------------
228 enum LLVMCastKind { eKindClang, eKindSwift, eKindGo, kNumKinds };
230 LLVMCastKind getKind() const { return m_kind; }
232 PersistentExpressionState(LLVMCastKind kind) : m_kind(kind) {}
234 virtual ~PersistentExpressionState();
236 virtual lldb::ExpressionVariableSP
237 CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) = 0;
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;
245 virtual ConstString GetNextPersistentVariableName() = 0;
248 RemovePersistentVariable(lldb::ExpressionVariableSP variable) = 0;
250 virtual lldb::addr_t LookupSymbol(const ConstString &name);
252 void RegisterExecutionUnit(lldb::IRExecutionUnitSP &execution_unit_sp);
257 typedef std::set<lldb::IRExecutionUnitSP> ExecutionUnitSet;
259 m_execution_units; ///< The execution units that contain valuable symbols.
261 typedef llvm::DenseMap<const char *, lldb::addr_t> SymbolMap;
263 m_symbol_map; ///< The addresses of the symbols in m_execution_units.
266 } // namespace lldb_private
268 #endif // liblldb_ExpressionVariable_h_