blob: 64ee3304e58ae3fc2bbaf18936c32f06991291f3 [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);
Enrico Granata5510a572014-10-15 21:38:32 +0000233 m_name = name;
Jim Ingham73ca05a2011-12-17 01:35:57 +0000234}
235
Greg Clayton1d3afba2010-10-05 00:00:42 +0000236ValueObjectConstResult::~ValueObjectConstResult()
237{
238}
239
Greg Clayton57ee3062013-07-11 22:46:58 +0000240ClangASTType
Sean Callanan72772842012-02-22 23:57:45 +0000241ValueObjectConstResult::GetClangTypeImpl()
Greg Clayton1d3afba2010-10-05 00:00:42 +0000242{
243 return m_value.GetClangType();
244}
245
246lldb::ValueType
247ValueObjectConstResult::GetValueType() const
248{
249 return eValueTypeConstResult;
250}
251
Greg Claytonfaac1112013-03-14 18:31:44 +0000252uint64_t
Greg Clayton1d3afba2010-10-05 00:00:42 +0000253ValueObjectConstResult::GetByteSize()
254{
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000255 if (m_byte_size == 0)
Greg Clayton57ee3062013-07-11 22:46:58 +0000256 m_byte_size = GetClangType().GetByteSize();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000257 return m_byte_size;
258}
259
260void
261ValueObjectConstResult::SetByteSize (size_t size)
262{
263 m_byte_size = size;
Greg Clayton1d3afba2010-10-05 00:00:42 +0000264}
265
Greg Claytonc7bece562013-01-25 18:06:21 +0000266size_t
Greg Clayton1d3afba2010-10-05 00:00:42 +0000267ValueObjectConstResult::CalculateNumChildren()
268{
Greg Clayton57ee3062013-07-11 22:46:58 +0000269 return GetClangType().GetNumChildren (true);
Greg Clayton1d3afba2010-10-05 00:00:42 +0000270}
271
272ConstString
273ValueObjectConstResult::GetTypeName()
274{
275 if (m_type_name.IsEmpty())
Greg Clayton57ee3062013-07-11 22:46:58 +0000276 m_type_name = GetClangType().GetConstTypeName ();
Greg Clayton1d3afba2010-10-05 00:00:42 +0000277 return m_type_name;
278}
279
Enrico Granatae8daa2f2014-05-17 19:14:17 +0000280ConstString
281ValueObjectConstResult::GetDisplayTypeName()
282{
283 return GetClangType().GetDisplayTypeName();
284}
285
Jim Ingham6035b672011-03-31 00:19:25 +0000286bool
287ValueObjectConstResult::UpdateValue ()
Greg Clayton1d3afba2010-10-05 00:00:42 +0000288{
Greg Clayton1d3afba2010-10-05 00:00:42 +0000289 // Const value is always valid
290 SetValueIsValid (true);
Jim Ingham6035b672011-03-31 00:19:25 +0000291 return true;
Greg Clayton1d3afba2010-10-05 00:00:42 +0000292}
293
294
295bool
Jim Ingham6035b672011-03-31 00:19:25 +0000296ValueObjectConstResult::IsInScope ()
Greg Clayton1d3afba2010-10-05 00:00:42 +0000297{
298 // A const result value is always in scope since it serializes all
299 // information needed to contain the constant value.
300 return true;
301}
Enrico Granata9128ee22011-09-06 19:20:51 +0000302
303lldb::ValueObjectSP
304ValueObjectConstResult::Dereference (Error &error)
305{
306 return m_impl.Dereference(error);
307}
308
309lldb::ValueObjectSP
310ValueObjectConstResult::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
311{
312 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create);
313}
314
315lldb::ValueObjectSP
316ValueObjectConstResult::AddressOf (Error &error)
317{
318 return m_impl.AddressOf(error);
319}
320
Johnny Chenb456b792011-12-16 23:04:52 +0000321lldb::addr_t
322ValueObjectConstResult::GetAddressOf (bool scalar_is_load_address,
323 AddressType *address_type)
324{
325 return m_impl.GetAddressOf(scalar_is_load_address, address_type);
326}
327
Enrico Granata9128ee22011-09-06 19:20:51 +0000328ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000329ValueObjectConstResult::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Enrico Granata9128ee22011-09-06 19:20:51 +0000330{
331 return m_impl.CreateChildAtIndex(idx, synthetic_array_member, synthetic_index);
332}
333
334size_t
335ValueObjectConstResult::GetPointeeData (DataExtractor& data,
336 uint32_t item_idx,
337 uint32_t item_count)
338{
339 return m_impl.GetPointeeData(data, item_idx, item_count);
340}
Greg Clayton94073022012-07-07 01:22:45 +0000341
342lldb::ValueObjectSP
343ValueObjectConstResult::GetDynamicValue (lldb::DynamicValueType use_dynamic)
344{
345 // Always recalculate dynamic values for const results as the memory that
346 // they might point to might have changed at any time.
347 if (use_dynamic != eNoDynamicValues)
348 {
349 if (!IsDynamic())
350 {
351 ExecutionContext exe_ctx (GetExecutionContextRef());
352 Process *process = exe_ctx.GetProcessPtr();
353 if (process && process->IsPossibleDynamicValue(*this))
354 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
355 }
356 if (m_dynamic_value)
357 return m_dynamic_value->GetSP();
358 }
359 return ValueObjectSP();
360}
361