blob: 6154829b240ef0259dc9eb2c0912bb66f3775d91 [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
Greg Claytona1e5dc82015-08-11 22:53:00 +000019#include "lldb/Symbol/CompilerType.h"
Greg Clayton1d3afba2010-10-05 00:00:42 +000020#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,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +000064 const CompilerType &compiler_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,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +000071 compiler_type,
Jim Ingham58b59f92011-04-22 23:53:53 +000072 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,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +000078 const CompilerType &compiler_type,
Greg Clayton57ee3062013-07-11 22:46:58 +000079 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);
Bruce Mitchener3ad353f2015-09-24 03:54:50 +000097 m_value.SetCompilerType(compiler_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,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000106 const CompilerType &compiler_type,
Greg Clayton57ee3062013-07-11 22:46:58 +0000107 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,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000114 compiler_type,
Jim Ingham58b59f92011-04-22 23:53:53 +0000115 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,
Enrico Granata0c10a852014-12-08 23:13:56 +0000125 const ConstString &name,
126 Module *module)
Jim Ingham73ca05a2011-12-17 01:35:57 +0000127{
Enrico Granata0c10a852014-12-08 23:13:56 +0000128 return (new ValueObjectConstResult (exe_scope, value, name, module))->GetSP();
Jim Ingham73ca05a2011-12-17 01:35:57 +0000129}
130
Greg Clayton57ee3062013-07-11 22:46:58 +0000131ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000132 const CompilerType &compiler_type,
Greg Clayton57ee3062013-07-11 22:46:58 +0000133 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) :
Jim Ingham6035b672011-03-31 00:19:25 +0000138 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000139 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +0000140 m_byte_size (0),
141 m_impl(this, address)
Greg Clayton1d3afba2010-10-05 00:00:42 +0000142{
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);
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000148 //m_value.SetContext(Value::eContextTypeClangType, compiler_type);
149 m_value.SetCompilerType (compiler_type);
Greg Clayton1d3afba2010-10-05 00:00:42 +0000150 m_name = name;
Greg Claytonb71f3842010-10-05 03:13:51 +0000151 SetIsConstant ();
Jim Inghame2f88412010-10-15 22:47:36 +0000152 SetValueIsValid(true);
Enrico Granata9128ee22011-09-06 19:20:51 +0000153 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000154}
155
Jim Ingham58b59f92011-04-22 23:53:53 +0000156ValueObjectSP
Greg Clayton57ee3062013-07-11 22:46:58 +0000157ValueObjectConstResult::Create (ExecutionContextScope *exe_scope,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000158 const CompilerType &compiler_type,
Greg Clayton57ee3062013-07-11 22:46:58 +0000159 const ConstString &name,
160 lldb::addr_t address,
161 AddressType address_type,
162 uint32_t addr_byte_size)
Jim Ingham58b59f92011-04-22 23:53:53 +0000163{
164 return (new ValueObjectConstResult (exe_scope,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000165 compiler_type,
Jim Ingham58b59f92011-04-22 23:53:53 +0000166 name,
167 address,
168 address_type,
169 addr_byte_size))->GetSP();
170}
171
Greg Clayton57ee3062013-07-11 22:46:58 +0000172ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000173 const CompilerType &compiler_type,
Greg Clayton57ee3062013-07-11 22:46:58 +0000174 const ConstString &name,
175 lldb::addr_t address,
176 AddressType address_type,
177 uint32_t addr_byte_size) :
Jim Ingham6035b672011-03-31 00:19:25 +0000178 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000179 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +0000180 m_byte_size (0),
181 m_impl(this, address)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000182{
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)
188 {
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000189 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;
193 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000194// m_value.SetContext(Value::eContextTypeClangType, compiler_type);
195 m_value.SetCompilerType (compiler_type);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000196 m_name = name;
197 SetIsConstant ();
198 SetValueIsValid(true);
Enrico Granata9128ee22011-09-06 19:20:51 +0000199 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Claytonb71f3842010-10-05 03:13:51 +0000200}
201
Jim Ingham58b59f92011-04-22 23:53:53 +0000202ValueObjectSP
203ValueObjectConstResult::Create
204(
205 ExecutionContextScope *exe_scope,
206 const Error& error
207)
208{
209 return (new ValueObjectConstResult (exe_scope,
210 error))->GetSP();
211}
212
Greg Clayton57ee3062013-07-11 22:46:58 +0000213ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
214 const Error& error) :
Jim Ingham6035b672011-03-31 00:19:25 +0000215 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000216 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +0000217 m_byte_size (0),
218 m_impl(this)
Greg Claytonb71f3842010-10-05 03:13:51 +0000219{
220 m_error = error;
221 SetIsConstant ();
Greg Clayton1d3afba2010-10-05 00:00:42 +0000222}
223
Greg Clayton57ee3062013-07-11 22:46:58 +0000224ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope,
225 const Value &value,
Enrico Granata0c10a852014-12-08 23:13:56 +0000226 const ConstString &name,
227 Module *module) :
Jim Ingham73ca05a2011-12-17 01:35:57 +0000228 ValueObject (exe_scope),
229 m_type_name (),
230 m_byte_size (0),
Jim Ingham73ca05a2011-12-17 01:35:57 +0000231 m_impl(this)
232{
233 m_value = value;
Enrico Granata5510a572014-10-15 21:38:32 +0000234 m_name = name;
Enrico Granata0c10a852014-12-08 23:13:56 +0000235 ExecutionContext exe_ctx;
236 exe_scope->CalculateExecutionContext(exe_ctx);
237 m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, module);
Jim Ingham73ca05a2011-12-17 01:35:57 +0000238}
239
Greg Clayton1d3afba2010-10-05 00:00:42 +0000240ValueObjectConstResult::~ValueObjectConstResult()
241{
242}
243
Greg Claytona1e5dc82015-08-11 22:53:00 +0000244CompilerType
Greg Clayton99558cc42015-08-24 23:46:31 +0000245ValueObjectConstResult::GetCompilerTypeImpl()
Greg Clayton1d3afba2010-10-05 00:00:42 +0000246{
Greg Clayton99558cc42015-08-24 23:46:31 +0000247 return m_value.GetCompilerType();
Greg Clayton1d3afba2010-10-05 00:00:42 +0000248}
249
250lldb::ValueType
251ValueObjectConstResult::GetValueType() const
252{
253 return eValueTypeConstResult;
254}
255
Greg Claytonfaac1112013-03-14 18:31:44 +0000256uint64_t
Greg Clayton1d3afba2010-10-05 00:00:42 +0000257ValueObjectConstResult::GetByteSize()
258{
Enrico Granata951bdd52015-01-28 01:09:45 +0000259 ExecutionContext exe_ctx(GetExecutionContextRef());
260
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000261 if (m_byte_size == 0)
Greg Clayton99558cc42015-08-24 23:46:31 +0000262 SetByteSize(GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope()));
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000263 return m_byte_size;
264}
265
266void
267ValueObjectConstResult::SetByteSize (size_t size)
268{
269 m_byte_size = size;
Greg Clayton1d3afba2010-10-05 00:00:42 +0000270}
271
Greg Claytonc7bece562013-01-25 18:06:21 +0000272size_t
Greg Clayton1d3afba2010-10-05 00:00:42 +0000273ValueObjectConstResult::CalculateNumChildren()
274{
Greg Clayton99558cc42015-08-24 23:46:31 +0000275 return GetCompilerType().GetNumChildren (true);
Greg Clayton1d3afba2010-10-05 00:00:42 +0000276}
277
278ConstString
279ValueObjectConstResult::GetTypeName()
280{
281 if (m_type_name.IsEmpty())
Greg Clayton99558cc42015-08-24 23:46:31 +0000282 m_type_name = GetCompilerType().GetConstTypeName ();
Greg Clayton1d3afba2010-10-05 00:00:42 +0000283 return m_type_name;
284}
285
Enrico Granatae8daa2f2014-05-17 19:14:17 +0000286ConstString
287ValueObjectConstResult::GetDisplayTypeName()
288{
Greg Clayton99558cc42015-08-24 23:46:31 +0000289 return GetCompilerType().GetDisplayTypeName();
Enrico Granatae8daa2f2014-05-17 19:14:17 +0000290}
291
Jim Ingham6035b672011-03-31 00:19:25 +0000292bool
293ValueObjectConstResult::UpdateValue ()
Greg Clayton1d3afba2010-10-05 00:00:42 +0000294{
Greg Clayton1d3afba2010-10-05 00:00:42 +0000295 // Const value is always valid
296 SetValueIsValid (true);
Jim Ingham6035b672011-03-31 00:19:25 +0000297 return true;
Greg Clayton1d3afba2010-10-05 00:00:42 +0000298}
299
300
301bool
Jim Ingham6035b672011-03-31 00:19:25 +0000302ValueObjectConstResult::IsInScope ()
Greg Clayton1d3afba2010-10-05 00:00:42 +0000303{
304 // A const result value is always in scope since it serializes all
305 // information needed to contain the constant value.
306 return true;
307}
Enrico Granata9128ee22011-09-06 19:20:51 +0000308
309lldb::ValueObjectSP
310ValueObjectConstResult::Dereference (Error &error)
311{
312 return m_impl.Dereference(error);
313}
314
315lldb::ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +0000316ValueObjectConstResult::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata9128ee22011-09-06 19:20:51 +0000317{
318 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create);
319}
320
321lldb::ValueObjectSP
322ValueObjectConstResult::AddressOf (Error &error)
323{
324 return m_impl.AddressOf(error);
325}
326
Johnny Chenb456b792011-12-16 23:04:52 +0000327lldb::addr_t
328ValueObjectConstResult::GetAddressOf (bool scalar_is_load_address,
329 AddressType *address_type)
330{
331 return m_impl.GetAddressOf(scalar_is_load_address, address_type);
332}
333
Enrico Granata9128ee22011-09-06 19:20:51 +0000334ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000335ValueObjectConstResult::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Enrico Granata9128ee22011-09-06 19:20:51 +0000336{
337 return m_impl.CreateChildAtIndex(idx, synthetic_array_member, synthetic_index);
338}
339
340size_t
341ValueObjectConstResult::GetPointeeData (DataExtractor& data,
342 uint32_t item_idx,
343 uint32_t item_count)
344{
345 return m_impl.GetPointeeData(data, item_idx, item_count);
346}
Greg Clayton94073022012-07-07 01:22:45 +0000347
348lldb::ValueObjectSP
349ValueObjectConstResult::GetDynamicValue (lldb::DynamicValueType use_dynamic)
350{
351 // Always recalculate dynamic values for const results as the memory that
352 // they might point to might have changed at any time.
353 if (use_dynamic != eNoDynamicValues)
354 {
355 if (!IsDynamic())
356 {
357 ExecutionContext exe_ctx (GetExecutionContextRef());
358 Process *process = exe_ctx.GetProcessPtr();
359 if (process && process->IsPossibleDynamicValue(*this))
360 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
361 }
362 if (m_dynamic_value)
363 return m_dynamic_value->GetSP();
364 }
365 return ValueObjectSP();
366}
367
Siva Chandraf8877ef2015-07-16 01:47:12 +0000368lldb::ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000369ValueObjectConstResult::Cast (const CompilerType &compiler_type)
Siva Chandraf8877ef2015-07-16 01:47:12 +0000370{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000371 return m_impl.Cast(compiler_type);
Siva Chandraf8877ef2015-07-16 01:47:12 +0000372}
373
Enrico Granatac1247f52014-11-06 21:23:20 +0000374lldb::LanguageType
375ValueObjectConstResult::GetPreferredDisplayLanguage ()
376{
Enrico Granata73e8c4d2015-10-07 02:36:35 +0000377 if (m_preferred_display_language != lldb::eLanguageTypeUnknown)
378 return m_preferred_display_language;
379 return GetCompilerTypeImpl().GetMinimumLanguage();
Enrico Granatac1247f52014-11-06 21:23:20 +0000380}