1 //===-- ValueObjectConstResult.cpp ------------------------------*- 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 #include "lldb/Core/ValueObjectConstResult.h"
12 #include "lldb/Core/ValueObjectChild.h"
13 #include "lldb/Core/ValueObjectConstResultChild.h"
14 #include "lldb/Core/DataExtractor.h"
15 #include "lldb/Core/Module.h"
16 #include "lldb/Core/ValueObjectDynamicValue.h"
17 #include "lldb/Core/ValueObjectList.h"
19 #include "lldb/Symbol/ClangASTType.h"
20 #include "lldb/Symbol/ObjectFile.h"
21 #include "lldb/Symbol/SymbolContext.h"
22 #include "lldb/Symbol/Type.h"
23 #include "lldb/Symbol/Variable.h"
25 #include "lldb/Target/ExecutionContext.h"
26 #include "lldb/Target/Process.h"
27 #include "lldb/Target/Target.h"
30 using namespace lldb_private;
33 ValueObjectConstResult::Create (ExecutionContextScope *exe_scope,
35 uint32_t addr_byte_size,
38 return (new ValueObjectConstResult (exe_scope,
44 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
46 uint32_t addr_byte_size,
47 lldb::addr_t address) :
48 ValueObject (exe_scope),
54 SetValueIsValid(true);
55 m_data.SetByteOrder(byte_order);
56 m_data.SetAddressByteSize(addr_byte_size);
57 SetAddressTypeOfChildren(eAddressTypeLoad);
61 ValueObjectConstResult::Create
63 ExecutionContextScope *exe_scope,
64 const ClangASTType &clang_type,
65 const ConstString &name,
66 const DataExtractor &data,
70 return (new ValueObjectConstResult (exe_scope,
77 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
78 const ClangASTType &clang_type,
79 const ConstString &name,
80 const DataExtractor &data,
81 lldb::addr_t address) :
82 ValueObject (exe_scope),
89 if (!m_data.GetSharedDataBuffer())
91 DataBufferSP shared_data_buffer(new DataBufferHeap(data.GetDataStart(), data.GetByteSize()));
92 m_data.SetData(shared_data_buffer);
95 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
96 m_value.SetValueType(Value::eValueTypeHostAddress);
97 m_value.SetClangType(clang_type);
100 SetValueIsValid(true);
101 SetAddressTypeOfChildren(eAddressTypeLoad);
105 ValueObjectConstResult::Create (ExecutionContextScope *exe_scope,
106 const ClangASTType &clang_type,
107 const ConstString &name,
108 const lldb::DataBufferSP &data_sp,
109 lldb::ByteOrder data_byte_order,
110 uint32_t data_addr_size,
111 lldb::addr_t address)
113 return (new ValueObjectConstResult (exe_scope,
123 ValueObjectConstResult::Create (ExecutionContextScope *exe_scope,
125 const ConstString &name)
127 return (new ValueObjectConstResult (exe_scope, value, name))->GetSP();
130 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
131 const ClangASTType &clang_type,
132 const ConstString &name,
133 const lldb::DataBufferSP &data_sp,
134 lldb::ByteOrder data_byte_order,
135 uint32_t data_addr_size,
136 lldb::addr_t address) :
137 ValueObject (exe_scope),
140 m_impl(this, address)
142 m_data.SetByteOrder(data_byte_order);
143 m_data.SetAddressByteSize(data_addr_size);
144 m_data.SetData(data_sp);
145 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
146 m_value.SetValueType(Value::eValueTypeHostAddress);
147 //m_value.SetContext(Value::eContextTypeClangType, clang_type);
148 m_value.SetClangType (clang_type);
151 SetValueIsValid(true);
152 SetAddressTypeOfChildren(eAddressTypeLoad);
156 ValueObjectConstResult::Create (ExecutionContextScope *exe_scope,
157 const ClangASTType &clang_type,
158 const ConstString &name,
159 lldb::addr_t address,
160 AddressType address_type,
161 uint32_t addr_byte_size)
163 return (new ValueObjectConstResult (exe_scope,
168 addr_byte_size))->GetSP();
171 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
172 const ClangASTType &clang_type,
173 const ConstString &name,
174 lldb::addr_t address,
175 AddressType address_type,
176 uint32_t addr_byte_size) :
177 ValueObject (exe_scope),
180 m_impl(this, address)
182 m_value.GetScalar() = address;
183 m_data.SetAddressByteSize(addr_byte_size);
184 m_value.GetScalar().GetData (m_data, addr_byte_size);
185 //m_value.SetValueType(Value::eValueTypeHostAddress);
186 switch (address_type)
188 case eAddressTypeInvalid: m_value.SetValueType(Value::eValueTypeScalar); break;
189 case eAddressTypeFile: m_value.SetValueType(Value::eValueTypeFileAddress); break;
190 case eAddressTypeLoad: m_value.SetValueType(Value::eValueTypeLoadAddress); break;
191 case eAddressTypeHost: m_value.SetValueType(Value::eValueTypeHostAddress); break;
193 // m_value.SetContext(Value::eContextTypeClangType, clang_type);
194 m_value.SetClangType (clang_type);
197 SetValueIsValid(true);
198 SetAddressTypeOfChildren(eAddressTypeLoad);
202 ValueObjectConstResult::Create
204 ExecutionContextScope *exe_scope,
208 return (new ValueObjectConstResult (exe_scope,
212 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
213 const Error& error) :
214 ValueObject (exe_scope),
223 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
225 const ConstString &name) :
226 ValueObject (exe_scope),
232 m_value.GetData(m_data);
235 ValueObjectConstResult::~ValueObjectConstResult()
240 ValueObjectConstResult::GetClangTypeImpl()
242 return m_value.GetClangType();
246 ValueObjectConstResult::GetValueType() const
248 return eValueTypeConstResult;
252 ValueObjectConstResult::GetByteSize()
254 if (m_byte_size == 0)
255 m_byte_size = GetClangType().GetByteSize();
260 ValueObjectConstResult::SetByteSize (size_t size)
266 ValueObjectConstResult::CalculateNumChildren()
268 return GetClangType().GetNumChildren (true);
272 ValueObjectConstResult::GetTypeName()
274 if (m_type_name.IsEmpty())
275 m_type_name = GetClangType().GetConstTypeName ();
280 ValueObjectConstResult::UpdateValue ()
282 // Const value is always valid
283 SetValueIsValid (true);
289 ValueObjectConstResult::IsInScope ()
291 // A const result value is always in scope since it serializes all
292 // information needed to contain the constant value.
297 ValueObjectConstResult::Dereference (Error &error)
299 return m_impl.Dereference(error);
303 ValueObjectConstResult::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
305 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create);
309 ValueObjectConstResult::AddressOf (Error &error)
311 return m_impl.AddressOf(error);
315 ValueObjectConstResult::GetAddressOf (bool scalar_is_load_address,
316 AddressType *address_type)
318 return m_impl.GetAddressOf(scalar_is_load_address, address_type);
322 ValueObjectConstResult::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
324 return m_impl.CreateChildAtIndex(idx, synthetic_array_member, synthetic_index);
328 ValueObjectConstResult::GetPointeeData (DataExtractor& data,
332 return m_impl.GetPointeeData(data, item_idx, item_count);
336 ValueObjectConstResult::GetDynamicValue (lldb::DynamicValueType use_dynamic)
338 // Always recalculate dynamic values for const results as the memory that
339 // they might point to might have changed at any time.
340 if (use_dynamic != eNoDynamicValues)
344 ExecutionContext exe_ctx (GetExecutionContextRef());
345 Process *process = exe_ctx.GetProcessPtr();
346 if (process && process->IsPossibleDynamicValue(*this))
347 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
350 return m_dynamic_value->GetSP();
352 return ValueObjectSP();