blob: 387e171e3526a1ddfde5fa663635c5c29e03e69c [file] [log] [blame]
Greg Clayton1d3afba2010-10-05 00:00:42 +00001//===-- ValueObjectConstResult.cpp ------------------------------*- 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#include "lldb/Core/ValueObjectConstResult.h"
11
Enrico Granata9128ee22011-09-06 19:20:51 +000012#include "lldb/Core/ValueObjectChild.h"
13#include "lldb/Core/ValueObjectConstResultChild.h"
Greg Clayton1d3afba2010-10-05 00:00:42 +000014#include "lldb/Core/DataExtractor.h"
15#include "lldb/Core/Module.h"
Greg Clayton94073022012-07-07 01:22:45 +000016#include "lldb/Core/ValueObjectDynamicValue.h"
Greg Clayton1d3afba2010-10-05 00:00:42 +000017#include "lldb/Core/ValueObjectList.h"
18
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"
24
25#include "lldb/Target/ExecutionContext.h"
26#include "lldb/Target/Process.h"
27#include "lldb/Target/Target.h"
28
29using namespace lldb;
30using namespace lldb_private;
31
Jim Ingham58b59f92011-04-22 23:53:53 +000032ValueObjectSP
Greg Clayton57ee3062013-07-11 22:46:58 +000033ValueObjectConstResult::Create (ExecutionContextScope *exe_scope,
34 ByteOrder byte_order,
35 uint32_t addr_byte_size,
36 lldb::addr_t address)
Jim Ingham58b59f92011-04-22 23:53:53 +000037{
38 return (new ValueObjectConstResult (exe_scope,
39 byte_order,
Enrico Granata9128ee22011-09-06 19:20:51 +000040 addr_byte_size,
41 address))->GetSP();
Jim Ingham58b59f92011-04-22 23:53:53 +000042}
43
Greg Clayton57ee3062013-07-11 22:46:58 +000044ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
45 ByteOrder byte_order,
46 uint32_t addr_byte_size,
47 lldb::addr_t address) :
Jim Ingham6035b672011-03-31 00:19:25 +000048 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000049 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +000050 m_byte_size (0),
51 m_impl(this, address)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000052{
53 SetIsConstant ();
54 SetValueIsValid(true);
55 m_data.SetByteOrder(byte_order);
56 m_data.SetAddressByteSize(addr_byte_size);
Enrico Granata9128ee22011-09-06 19:20:51 +000057 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000058}
59
Jim Ingham58b59f92011-04-22 23:53:53 +000060ValueObjectSP
61ValueObjectConstResult::Create
62(
63 ExecutionContextScope *exe_scope,
Greg Clayton57ee3062013-07-11 22:46:58 +000064 const ClangASTType &clang_type,
Jim Ingham58b59f92011-04-22 23:53:53 +000065 const ConstString &name,
Enrico Granata9128ee22011-09-06 19:20:51 +000066 const DataExtractor &data,
67 lldb::addr_t address
Jim Ingham58b59f92011-04-22 23:53:53 +000068)
69{
70 return (new ValueObjectConstResult (exe_scope,
Jim Ingham58b59f92011-04-22 23:53:53 +000071 clang_type,
72 name,
Enrico Granata9128ee22011-09-06 19:20:51 +000073 data,
74 address))->GetSP();
Jim Ingham58b59f92011-04-22 23:53:53 +000075}
76
Greg Clayton57ee3062013-07-11 22:46:58 +000077ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
78 const ClangASTType &clang_type,
79 const ConstString &name,
80 const DataExtractor &data,
81 lldb::addr_t address) :
Jim Ingham6035b672011-03-31 00:19:25 +000082 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000083 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +000084 m_byte_size (0),
85 m_impl(this, address)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000086{
87 m_data = data;
Sean Callanan31a8d052012-01-05 01:11:09 +000088
89 if (!m_data.GetSharedDataBuffer())
90 {
91 DataBufferSP shared_data_buffer(new DataBufferHeap(data.GetDataStart(), data.GetByteSize()));
92 m_data.SetData(shared_data_buffer);
93 }
94
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000095 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
96 m_value.SetValueType(Value::eValueTypeHostAddress);
Greg Clayton57ee3062013-07-11 22:46:58 +000097 m_value.SetClangType(clang_type);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000098 m_name = name;
99 SetIsConstant ();
100 SetValueIsValid(true);
Enrico Granata9128ee22011-09-06 19:20:51 +0000101 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000102}
103
Jim Ingham58b59f92011-04-22 23:53:53 +0000104ValueObjectSP
Greg Clayton57ee3062013-07-11 22:46:58 +0000105ValueObjectConstResult::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)
Jim Ingham58b59f92011-04-22 23:53:53 +0000112{
113 return (new ValueObjectConstResult (exe_scope,
Jim Ingham58b59f92011-04-22 23:53:53 +0000114 clang_type,
115 name,
116 data_sp,
117 data_byte_order,
Enrico Granata9128ee22011-09-06 19:20:51 +0000118 data_addr_size,
119 address))->GetSP();
Jim Ingham58b59f92011-04-22 23:53:53 +0000120}
121
Jim Ingham73ca05a2011-12-17 01:35:57 +0000122ValueObjectSP
123ValueObjectConstResult::Create (ExecutionContextScope *exe_scope,
Greg Clayton57ee3062013-07-11 22:46:58 +0000124 Value &value,
125 const ConstString &name)
Jim Ingham73ca05a2011-12-17 01:35:57 +0000126{
Greg Clayton57ee3062013-07-11 22:46:58 +0000127 return (new ValueObjectConstResult (exe_scope, value, name))->GetSP();
Jim Ingham73ca05a2011-12-17 01:35:57 +0000128}
129
Greg Clayton57ee3062013-07-11 22:46:58 +0000130ValueObjectConstResult::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) :
Jim Ingham6035b672011-03-31 00:19:25 +0000137 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000138 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +0000139 m_byte_size (0),
140 m_impl(this, address)
Greg Clayton1d3afba2010-10-05 00:00:42 +0000141{
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);
Greg Clayton57ee3062013-07-11 22:46:58 +0000147 //m_value.SetContext(Value::eContextTypeClangType, clang_type);
148 m_value.SetClangType (clang_type);
Greg Clayton1d3afba2010-10-05 00:00:42 +0000149 m_name = name;
Greg Claytonb71f3842010-10-05 03:13:51 +0000150 SetIsConstant ();
Jim Inghame2f88412010-10-15 22:47:36 +0000151 SetValueIsValid(true);
Enrico Granata9128ee22011-09-06 19:20:51 +0000152 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000153}
154
Jim Ingham58b59f92011-04-22 23:53:53 +0000155ValueObjectSP
Greg Clayton57ee3062013-07-11 22:46:58 +0000156ValueObjectConstResult::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)
Jim Ingham58b59f92011-04-22 23:53:53 +0000162{
163 return (new ValueObjectConstResult (exe_scope,
Jim Ingham58b59f92011-04-22 23:53:53 +0000164 clang_type,
165 name,
166 address,
167 address_type,
168 addr_byte_size))->GetSP();
169}
170
Greg Clayton57ee3062013-07-11 22:46:58 +0000171ValueObjectConstResult::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) :
Jim Ingham6035b672011-03-31 00:19:25 +0000177 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000178 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +0000179 m_byte_size (0),
180 m_impl(this, address)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000181{
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)
187 {
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000188 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;
192 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000193// m_value.SetContext(Value::eContextTypeClangType, clang_type);
194 m_value.SetClangType (clang_type);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000195 m_name = name;
196 SetIsConstant ();
197 SetValueIsValid(true);
Enrico Granata9128ee22011-09-06 19:20:51 +0000198 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Claytonb71f3842010-10-05 03:13:51 +0000199}
200
Jim Ingham58b59f92011-04-22 23:53:53 +0000201ValueObjectSP
202ValueObjectConstResult::Create
203(
204 ExecutionContextScope *exe_scope,
205 const Error& error
206)
207{
208 return (new ValueObjectConstResult (exe_scope,
209 error))->GetSP();
210}
211
Greg Clayton57ee3062013-07-11 22:46:58 +0000212ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
213 const Error& error) :
Jim Ingham6035b672011-03-31 00:19:25 +0000214 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000215 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +0000216 m_byte_size (0),
217 m_impl(this)
Greg Claytonb71f3842010-10-05 03:13:51 +0000218{
219 m_error = error;
220 SetIsConstant ();
Greg Clayton1d3afba2010-10-05 00:00:42 +0000221}
222
Greg Clayton57ee3062013-07-11 22:46:58 +0000223ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
224 const Value &value,
225 const ConstString &name) :
Jim Ingham73ca05a2011-12-17 01:35:57 +0000226 ValueObject (exe_scope),
227 m_type_name (),
228 m_byte_size (0),
Jim Ingham73ca05a2011-12-17 01:35:57 +0000229 m_impl(this)
230{
231 m_value = value;
232 m_value.GetData(m_data);
233}
234
Greg Clayton1d3afba2010-10-05 00:00:42 +0000235ValueObjectConstResult::~ValueObjectConstResult()
236{
237}
238
Greg Clayton57ee3062013-07-11 22:46:58 +0000239ClangASTType
Sean Callanan72772842012-02-22 23:57:45 +0000240ValueObjectConstResult::GetClangTypeImpl()
Greg Clayton1d3afba2010-10-05 00:00:42 +0000241{
242 return m_value.GetClangType();
243}
244
245lldb::ValueType
246ValueObjectConstResult::GetValueType() const
247{
248 return eValueTypeConstResult;
249}
250
Greg Claytonfaac1112013-03-14 18:31:44 +0000251uint64_t
Greg Clayton1d3afba2010-10-05 00:00:42 +0000252ValueObjectConstResult::GetByteSize()
253{
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000254 if (m_byte_size == 0)
Greg Clayton57ee3062013-07-11 22:46:58 +0000255 m_byte_size = GetClangType().GetByteSize();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000256 return m_byte_size;
257}
258
259void
260ValueObjectConstResult::SetByteSize (size_t size)
261{
262 m_byte_size = size;
Greg Clayton1d3afba2010-10-05 00:00:42 +0000263}
264
Greg Claytonc7bece562013-01-25 18:06:21 +0000265size_t
Greg Clayton1d3afba2010-10-05 00:00:42 +0000266ValueObjectConstResult::CalculateNumChildren()
267{
Greg Clayton57ee3062013-07-11 22:46:58 +0000268 return GetClangType().GetNumChildren (true);
Greg Clayton1d3afba2010-10-05 00:00:42 +0000269}
270
271ConstString
272ValueObjectConstResult::GetTypeName()
273{
274 if (m_type_name.IsEmpty())
Greg Clayton57ee3062013-07-11 22:46:58 +0000275 m_type_name = GetClangType().GetConstTypeName ();
Greg Clayton1d3afba2010-10-05 00:00:42 +0000276 return m_type_name;
277}
278
Enrico Granatae8daa2f2014-05-17 19:14:17 +0000279ConstString
280ValueObjectConstResult::GetDisplayTypeName()
281{
282 return GetClangType().GetDisplayTypeName();
283}
284
Jim Ingham6035b672011-03-31 00:19:25 +0000285bool
286ValueObjectConstResult::UpdateValue ()
Greg Clayton1d3afba2010-10-05 00:00:42 +0000287{
Greg Clayton1d3afba2010-10-05 00:00:42 +0000288 // Const value is always valid
289 SetValueIsValid (true);
Jim Ingham6035b672011-03-31 00:19:25 +0000290 return true;
Greg Clayton1d3afba2010-10-05 00:00:42 +0000291}
292
293
294bool
Jim Ingham6035b672011-03-31 00:19:25 +0000295ValueObjectConstResult::IsInScope ()
Greg Clayton1d3afba2010-10-05 00:00:42 +0000296{
297 // A const result value is always in scope since it serializes all
298 // information needed to contain the constant value.
299 return true;
300}
Enrico Granata9128ee22011-09-06 19:20:51 +0000301
302lldb::ValueObjectSP
303ValueObjectConstResult::Dereference (Error &error)
304{
305 return m_impl.Dereference(error);
306}
307
308lldb::ValueObjectSP
309ValueObjectConstResult::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
310{
311 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create);
312}
313
314lldb::ValueObjectSP
315ValueObjectConstResult::AddressOf (Error &error)
316{
317 return m_impl.AddressOf(error);
318}
319
Johnny Chenb456b792011-12-16 23:04:52 +0000320lldb::addr_t
321ValueObjectConstResult::GetAddressOf (bool scalar_is_load_address,
322 AddressType *address_type)
323{
324 return m_impl.GetAddressOf(scalar_is_load_address, address_type);
325}
326
Enrico Granata9128ee22011-09-06 19:20:51 +0000327ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000328ValueObjectConstResult::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Enrico Granata9128ee22011-09-06 19:20:51 +0000329{
330 return m_impl.CreateChildAtIndex(idx, synthetic_array_member, synthetic_index);
331}
332
333size_t
334ValueObjectConstResult::GetPointeeData (DataExtractor& data,
335 uint32_t item_idx,
336 uint32_t item_count)
337{
338 return m_impl.GetPointeeData(data, item_idx, item_count);
339}
Greg Clayton94073022012-07-07 01:22:45 +0000340
341lldb::ValueObjectSP
342ValueObjectConstResult::GetDynamicValue (lldb::DynamicValueType use_dynamic)
343{
344 // Always recalculate dynamic values for const results as the memory that
345 // they might point to might have changed at any time.
346 if (use_dynamic != eNoDynamicValues)
347 {
348 if (!IsDynamic())
349 {
350 ExecutionContext exe_ctx (GetExecutionContextRef());
351 Process *process = exe_ctx.GetProcessPtr();
352 if (process && process->IsPossibleDynamicValue(*this))
353 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
354 }
355 if (m_dynamic_value)
356 return m_dynamic_value->GetSP();
357 }
358 return ValueObjectSP();
359}
360