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/CompilerType.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 CompilerType &compiler_type,
65 const ConstString &name,
66 const DataExtractor &data,
70 return (new ValueObjectConstResult (exe_scope,
77 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
78 const CompilerType &compiler_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.SetCompilerType(compiler_type);
100 SetValueIsValid(true);
101 SetAddressTypeOfChildren(eAddressTypeLoad);
105 ValueObjectConstResult::Create (ExecutionContextScope *exe_scope,
106 const CompilerType &compiler_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,
128 return (new ValueObjectConstResult (exe_scope, value, name, module))->GetSP();
131 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
132 const CompilerType &compiler_type,
133 const ConstString &name,
134 const lldb::DataBufferSP &data_sp,
135 lldb::ByteOrder data_byte_order,
136 uint32_t data_addr_size,
137 lldb::addr_t address) :
138 ValueObject (exe_scope),
141 m_impl(this, address)
143 m_data.SetByteOrder(data_byte_order);
144 m_data.SetAddressByteSize(data_addr_size);
145 m_data.SetData(data_sp);
146 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
147 m_value.SetValueType(Value::eValueTypeHostAddress);
148 //m_value.SetContext(Value::eContextTypeClangType, compiler_type);
149 m_value.SetCompilerType (compiler_type);
152 SetValueIsValid(true);
153 SetAddressTypeOfChildren(eAddressTypeLoad);
157 ValueObjectConstResult::Create (ExecutionContextScope *exe_scope,
158 const CompilerType &compiler_type,
159 const ConstString &name,
160 lldb::addr_t address,
161 AddressType address_type,
162 uint32_t addr_byte_size)
164 return (new ValueObjectConstResult (exe_scope,
169 addr_byte_size))->GetSP();
172 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
173 const CompilerType &compiler_type,
174 const ConstString &name,
175 lldb::addr_t address,
176 AddressType address_type,
177 uint32_t addr_byte_size) :
178 ValueObject (exe_scope),
181 m_impl(this, address)
183 m_value.GetScalar() = address;
184 m_data.SetAddressByteSize(addr_byte_size);
185 m_value.GetScalar().GetData (m_data, addr_byte_size);
186 //m_value.SetValueType(Value::eValueTypeHostAddress);
187 switch (address_type)
189 case eAddressTypeInvalid: m_value.SetValueType(Value::eValueTypeScalar); break;
190 case eAddressTypeFile: m_value.SetValueType(Value::eValueTypeFileAddress); break;
191 case eAddressTypeLoad: m_value.SetValueType(Value::eValueTypeLoadAddress); break;
192 case eAddressTypeHost: m_value.SetValueType(Value::eValueTypeHostAddress); break;
194 // m_value.SetContext(Value::eContextTypeClangType, compiler_type);
195 m_value.SetCompilerType (compiler_type);
198 SetValueIsValid(true);
199 SetAddressTypeOfChildren(eAddressTypeLoad);
203 ValueObjectConstResult::Create
205 ExecutionContextScope *exe_scope,
209 return (new ValueObjectConstResult (exe_scope,
213 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
214 const Error& error) :
215 ValueObject (exe_scope),
224 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
226 const ConstString &name,
228 ValueObject (exe_scope),
235 ExecutionContext exe_ctx;
236 exe_scope->CalculateExecutionContext(exe_ctx);
237 m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, module);
240 ValueObjectConstResult::~ValueObjectConstResult()
245 ValueObjectConstResult::GetCompilerTypeImpl()
247 return m_value.GetCompilerType();
251 ValueObjectConstResult::GetValueType() const
253 return eValueTypeConstResult;
257 ValueObjectConstResult::GetByteSize()
259 ExecutionContext exe_ctx(GetExecutionContextRef());
261 if (m_byte_size == 0)
262 SetByteSize(GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope()));
267 ValueObjectConstResult::SetByteSize (size_t size)
273 ValueObjectConstResult::CalculateNumChildren(uint32_t max)
275 auto children_count = GetCompilerType().GetNumChildren (true);
276 return children_count <= max ? children_count : max;
280 ValueObjectConstResult::GetTypeName()
282 if (m_type_name.IsEmpty())
283 m_type_name = GetCompilerType().GetConstTypeName ();
288 ValueObjectConstResult::GetDisplayTypeName()
290 return GetCompilerType().GetDisplayTypeName();
294 ValueObjectConstResult::UpdateValue ()
296 // Const value is always valid
297 SetValueIsValid (true);
303 ValueObjectConstResult::IsInScope ()
305 // A const result value is always in scope since it serializes all
306 // information needed to contain the constant value.
311 ValueObjectConstResult::Dereference (Error &error)
313 return m_impl.Dereference(error);
317 ValueObjectConstResult::GetSyntheticChildAtOffset(uint32_t offset,
318 const CompilerType& type,
320 ConstString name_const_str)
322 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create, name_const_str);
326 ValueObjectConstResult::AddressOf (Error &error)
328 return m_impl.AddressOf(error);
332 ValueObjectConstResult::GetAddressOf (bool scalar_is_load_address,
333 AddressType *address_type)
335 return m_impl.GetAddressOf(scalar_is_load_address, address_type);
339 ValueObjectConstResult::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
341 return m_impl.CreateChildAtIndex(idx, synthetic_array_member, synthetic_index);
345 ValueObjectConstResult::GetPointeeData (DataExtractor& data,
349 return m_impl.GetPointeeData(data, item_idx, item_count);
353 ValueObjectConstResult::GetDynamicValue (lldb::DynamicValueType use_dynamic)
355 // Always recalculate dynamic values for const results as the memory that
356 // they might point to might have changed at any time.
357 if (use_dynamic != eNoDynamicValues)
361 ExecutionContext exe_ctx (GetExecutionContextRef());
362 Process *process = exe_ctx.GetProcessPtr();
363 if (process && process->IsPossibleDynamicValue(*this))
364 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
367 return m_dynamic_value->GetSP();
369 return ValueObjectSP();
373 ValueObjectConstResult::Cast (const CompilerType &compiler_type)
375 return m_impl.Cast(compiler_type);
379 ValueObjectConstResult::GetPreferredDisplayLanguage ()
381 if (m_preferred_display_language != lldb::eLanguageTypeUnknown)
382 return m_preferred_display_language;
383 return GetCompilerTypeImpl().GetMinimumLanguage();