blob: cc6bafc0e88308d23f9844a6873d3ba17ebb9d7f [file] [log] [blame]
Greg Clayton66ed2fb2010-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 Granata91544802011-09-06 19:20:51 +000012#include "lldb/Core/ValueObjectChild.h"
13#include "lldb/Core/ValueObjectConstResultChild.h"
Greg Clayton66ed2fb2010-10-05 00:00:42 +000014#include "lldb/Core/DataExtractor.h"
15#include "lldb/Core/Module.h"
Greg Clayton0d0f56d2012-07-07 01:22:45 +000016#include "lldb/Core/ValueObjectDynamicValue.h"
Greg Clayton66ed2fb2010-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 Ingham47da8102011-04-22 23:53:53 +000032ValueObjectSP
33ValueObjectConstResult::Create
34(
35 ExecutionContextScope *exe_scope,
36 ByteOrder byte_order,
Enrico Granata91544802011-09-06 19:20:51 +000037 uint32_t addr_byte_size,
38 lldb::addr_t address
Jim Ingham47da8102011-04-22 23:53:53 +000039)
40{
41 return (new ValueObjectConstResult (exe_scope,
42 byte_order,
Enrico Granata91544802011-09-06 19:20:51 +000043 addr_byte_size,
44 address))->GetSP();
Jim Ingham47da8102011-04-22 23:53:53 +000045}
46
Greg Clayton66ed2fb2010-10-05 00:00:42 +000047ValueObjectConstResult::ValueObjectConstResult
48(
Jim Inghamfa3a16a2011-03-31 00:19:25 +000049 ExecutionContextScope *exe_scope,
Greg Clayton427f2902010-12-14 02:59:59 +000050 ByteOrder byte_order,
Enrico Granata91544802011-09-06 19:20:51 +000051 uint32_t addr_byte_size,
52 lldb::addr_t address
Greg Clayton427f2902010-12-14 02:59:59 +000053) :
Jim Inghamfa3a16a2011-03-31 00:19:25 +000054 ValueObject (exe_scope),
Greg Clayton427f2902010-12-14 02:59:59 +000055 m_clang_ast (NULL),
56 m_type_name (),
Enrico Granata91544802011-09-06 19:20:51 +000057 m_byte_size (0),
58 m_impl(this, address)
Greg Clayton427f2902010-12-14 02:59:59 +000059{
60 SetIsConstant ();
61 SetValueIsValid(true);
62 m_data.SetByteOrder(byte_order);
63 m_data.SetAddressByteSize(addr_byte_size);
Enrico Granata91544802011-09-06 19:20:51 +000064 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Clayton427f2902010-12-14 02:59:59 +000065}
66
Jim Ingham47da8102011-04-22 23:53:53 +000067ValueObjectSP
68ValueObjectConstResult::Create
69(
70 ExecutionContextScope *exe_scope,
71 clang::ASTContext *clang_ast,
72 void *clang_type,
73 const ConstString &name,
Enrico Granata91544802011-09-06 19:20:51 +000074 const DataExtractor &data,
75 lldb::addr_t address
Jim Ingham47da8102011-04-22 23:53:53 +000076)
77{
78 return (new ValueObjectConstResult (exe_scope,
79 clang_ast,
80 clang_type,
81 name,
Enrico Granata91544802011-09-06 19:20:51 +000082 data,
83 address))->GetSP();
Jim Ingham47da8102011-04-22 23:53:53 +000084}
85
Greg Clayton427f2902010-12-14 02:59:59 +000086ValueObjectConstResult::ValueObjectConstResult
87(
Jim Inghamfa3a16a2011-03-31 00:19:25 +000088 ExecutionContextScope *exe_scope,
Greg Clayton427f2902010-12-14 02:59:59 +000089 clang::ASTContext *clang_ast,
90 void *clang_type,
91 const ConstString &name,
Enrico Granata91544802011-09-06 19:20:51 +000092 const DataExtractor &data,
93 lldb::addr_t address
Greg Clayton427f2902010-12-14 02:59:59 +000094) :
Jim Inghamfa3a16a2011-03-31 00:19:25 +000095 ValueObject (exe_scope),
Greg Clayton427f2902010-12-14 02:59:59 +000096 m_clang_ast (clang_ast),
97 m_type_name (),
Enrico Granata91544802011-09-06 19:20:51 +000098 m_byte_size (0),
99 m_impl(this, address)
Greg Clayton427f2902010-12-14 02:59:59 +0000100{
101 m_data = data;
Sean Callanan9ac3d8b2012-01-05 01:11:09 +0000102
103 if (!m_data.GetSharedDataBuffer())
104 {
105 DataBufferSP shared_data_buffer(new DataBufferHeap(data.GetDataStart(), data.GetByteSize()));
106 m_data.SetData(shared_data_buffer);
107 }
108
Greg Clayton427f2902010-12-14 02:59:59 +0000109 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
110 m_value.SetValueType(Value::eValueTypeHostAddress);
111 m_value.SetContext(Value::eContextTypeClangType, clang_type);
112 m_name = name;
113 SetIsConstant ();
114 SetValueIsValid(true);
Enrico Granata91544802011-09-06 19:20:51 +0000115 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Clayton427f2902010-12-14 02:59:59 +0000116}
117
Jim Ingham47da8102011-04-22 23:53:53 +0000118ValueObjectSP
119ValueObjectConstResult::Create
120(
121 ExecutionContextScope *exe_scope,
122 clang::ASTContext *clang_ast,
123 void *clang_type,
124 const ConstString &name,
125 const lldb::DataBufferSP &data_sp,
126 lldb::ByteOrder data_byte_order,
Enrico Granata91544802011-09-06 19:20:51 +0000127 uint8_t data_addr_size,
128 lldb::addr_t address
Jim Ingham47da8102011-04-22 23:53:53 +0000129)
130{
131 return (new ValueObjectConstResult (exe_scope,
132 clang_ast,
133 clang_type,
134 name,
135 data_sp,
136 data_byte_order,
Enrico Granata91544802011-09-06 19:20:51 +0000137 data_addr_size,
138 address))->GetSP();
Jim Ingham47da8102011-04-22 23:53:53 +0000139}
140
Jim Ingham1586d972011-12-17 01:35:57 +0000141ValueObjectSP
142ValueObjectConstResult::Create (ExecutionContextScope *exe_scope,
143 clang::ASTContext *clang_ast,
144 Value &value,
145 const ConstString &name)
146{
147 return (new ValueObjectConstResult (exe_scope, clang_ast, value, name))->GetSP();
148}
149
Greg Clayton427f2902010-12-14 02:59:59 +0000150ValueObjectConstResult::ValueObjectConstResult
151(
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000152 ExecutionContextScope *exe_scope,
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000153 clang::ASTContext *clang_ast,
154 void *clang_type,
155 const ConstString &name,
156 const lldb::DataBufferSP &data_sp,
157 lldb::ByteOrder data_byte_order,
Enrico Granata91544802011-09-06 19:20:51 +0000158 uint8_t data_addr_size,
159 lldb::addr_t address
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000160) :
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000161 ValueObject (exe_scope),
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000162 m_clang_ast (clang_ast),
Greg Clayton427f2902010-12-14 02:59:59 +0000163 m_type_name (),
Enrico Granata91544802011-09-06 19:20:51 +0000164 m_byte_size (0),
165 m_impl(this, address)
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000166{
167 m_data.SetByteOrder(data_byte_order);
168 m_data.SetAddressByteSize(data_addr_size);
169 m_data.SetData(data_sp);
170 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
171 m_value.SetValueType(Value::eValueTypeHostAddress);
Greg Clayton6916e352010-11-13 03:52:47 +0000172 m_value.SetContext(Value::eContextTypeClangType, clang_type);
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000173 m_name = name;
Greg Claytond1719722010-10-05 03:13:51 +0000174 SetIsConstant ();
Jim Ingham80c1f6f2010-10-15 22:47:36 +0000175 SetValueIsValid(true);
Enrico Granata91544802011-09-06 19:20:51 +0000176 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Clayton427f2902010-12-14 02:59:59 +0000177}
178
Jim Ingham47da8102011-04-22 23:53:53 +0000179ValueObjectSP
180ValueObjectConstResult::Create
181(
182 ExecutionContextScope *exe_scope,
183 clang::ASTContext *clang_ast,
184 void *clang_type,
185 const ConstString &name,
186 lldb::addr_t address,
187 AddressType address_type,
188 uint8_t addr_byte_size
189)
190{
191 return (new ValueObjectConstResult (exe_scope,
192 clang_ast,
193 clang_type,
194 name,
195 address,
196 address_type,
197 addr_byte_size))->GetSP();
198}
199
Greg Clayton427f2902010-12-14 02:59:59 +0000200ValueObjectConstResult::ValueObjectConstResult
201(
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000202 ExecutionContextScope *exe_scope,
Greg Clayton427f2902010-12-14 02:59:59 +0000203 clang::ASTContext *clang_ast,
204 void *clang_type,
205 const ConstString &name,
206 lldb::addr_t address,
Greg Claytonb3448432011-03-24 21:19:54 +0000207 AddressType address_type,
Greg Clayton427f2902010-12-14 02:59:59 +0000208 uint8_t addr_byte_size
209) :
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000210 ValueObject (exe_scope),
Greg Clayton427f2902010-12-14 02:59:59 +0000211 m_clang_ast (clang_ast),
212 m_type_name (),
Enrico Granata91544802011-09-06 19:20:51 +0000213 m_byte_size (0),
214 m_impl(this, address)
Greg Clayton427f2902010-12-14 02:59:59 +0000215{
216 m_value.GetScalar() = address;
217 m_data.SetAddressByteSize(addr_byte_size);
218 m_value.GetScalar().GetData (m_data, addr_byte_size);
219 //m_value.SetValueType(Value::eValueTypeHostAddress);
220 switch (address_type)
221 {
Greg Clayton427f2902010-12-14 02:59:59 +0000222 case eAddressTypeInvalid: m_value.SetValueType(Value::eValueTypeScalar); break;
223 case eAddressTypeFile: m_value.SetValueType(Value::eValueTypeFileAddress); break;
224 case eAddressTypeLoad: m_value.SetValueType(Value::eValueTypeLoadAddress); break;
225 case eAddressTypeHost: m_value.SetValueType(Value::eValueTypeHostAddress); break;
226 }
227 m_value.SetContext(Value::eContextTypeClangType, clang_type);
228 m_name = name;
229 SetIsConstant ();
230 SetValueIsValid(true);
Enrico Granata91544802011-09-06 19:20:51 +0000231 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Claytond1719722010-10-05 03:13:51 +0000232}
233
Jim Ingham47da8102011-04-22 23:53:53 +0000234ValueObjectSP
235ValueObjectConstResult::Create
236(
237 ExecutionContextScope *exe_scope,
238 const Error& error
239)
240{
241 return (new ValueObjectConstResult (exe_scope,
242 error))->GetSP();
243}
244
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000245ValueObjectConstResult::ValueObjectConstResult (
246 ExecutionContextScope *exe_scope,
247 const Error& error) :
248 ValueObject (exe_scope),
Greg Claytond1719722010-10-05 03:13:51 +0000249 m_clang_ast (NULL),
Greg Clayton427f2902010-12-14 02:59:59 +0000250 m_type_name (),
Enrico Granata91544802011-09-06 19:20:51 +0000251 m_byte_size (0),
252 m_impl(this)
Greg Claytond1719722010-10-05 03:13:51 +0000253{
254 m_error = error;
255 SetIsConstant ();
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000256}
257
Jim Ingham1586d972011-12-17 01:35:57 +0000258ValueObjectConstResult::ValueObjectConstResult (
259 ExecutionContextScope *exe_scope,
260 clang::ASTContext *clang_ast,
261 const Value &value,
262 const ConstString &name) :
263 ValueObject (exe_scope),
Bill Wendling87058762012-04-04 21:19:57 +0000264 m_clang_ast (clang_ast),
Jim Ingham1586d972011-12-17 01:35:57 +0000265 m_type_name (),
266 m_byte_size (0),
Jim Ingham1586d972011-12-17 01:35:57 +0000267 m_impl(this)
268{
269 m_value = value;
270 m_value.GetData(m_data);
271}
272
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000273ValueObjectConstResult::~ValueObjectConstResult()
274{
275}
276
Greg Claytonb01000f2011-01-17 03:46:26 +0000277lldb::clang_type_t
Sean Callanan931acec2012-02-22 23:57:45 +0000278ValueObjectConstResult::GetClangTypeImpl()
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000279{
280 return m_value.GetClangType();
281}
282
283lldb::ValueType
284ValueObjectConstResult::GetValueType() const
285{
286 return eValueTypeConstResult;
287}
288
289size_t
290ValueObjectConstResult::GetByteSize()
291{
Greg Clayton427f2902010-12-14 02:59:59 +0000292 if (m_byte_size == 0)
Enrico Granata91544802011-09-06 19:20:51 +0000293 m_byte_size = ClangASTType::GetTypeByteSize(GetClangAST(), GetClangType());
Greg Clayton427f2902010-12-14 02:59:59 +0000294 return m_byte_size;
295}
296
297void
298ValueObjectConstResult::SetByteSize (size_t size)
299{
300 m_byte_size = size;
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000301}
302
303uint32_t
304ValueObjectConstResult::CalculateNumChildren()
305{
Greg Claytonb01000f2011-01-17 03:46:26 +0000306 return ClangASTContext::GetNumChildren (GetClangAST (), GetClangType(), true);
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000307}
308
309clang::ASTContext *
Sean Callanan931acec2012-02-22 23:57:45 +0000310ValueObjectConstResult::GetClangASTImpl ()
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000311{
312 return m_clang_ast;
313}
314
315ConstString
316ValueObjectConstResult::GetTypeName()
317{
318 if (m_type_name.IsEmpty())
Greg Claytondc0a38c2012-03-26 23:03:23 +0000319 m_type_name = ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000320 return m_type_name;
321}
322
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000323bool
324ValueObjectConstResult::UpdateValue ()
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000325{
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000326 // Const value is always valid
327 SetValueIsValid (true);
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000328 return true;
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000329}
330
331
332bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000333ValueObjectConstResult::IsInScope ()
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000334{
335 // A const result value is always in scope since it serializes all
336 // information needed to contain the constant value.
337 return true;
338}
Enrico Granata91544802011-09-06 19:20:51 +0000339
340lldb::ValueObjectSP
341ValueObjectConstResult::Dereference (Error &error)
342{
343 return m_impl.Dereference(error);
344}
345
346lldb::ValueObjectSP
347ValueObjectConstResult::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
348{
349 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create);
350}
351
352lldb::ValueObjectSP
353ValueObjectConstResult::AddressOf (Error &error)
354{
355 return m_impl.AddressOf(error);
356}
357
Johnny Chendfafa142011-12-16 23:04:52 +0000358lldb::addr_t
359ValueObjectConstResult::GetAddressOf (bool scalar_is_load_address,
360 AddressType *address_type)
361{
362 return m_impl.GetAddressOf(scalar_is_load_address, address_type);
363}
364
Enrico Granata91544802011-09-06 19:20:51 +0000365ValueObject *
366ValueObjectConstResult::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
367{
368 return m_impl.CreateChildAtIndex(idx, synthetic_array_member, synthetic_index);
369}
370
371size_t
372ValueObjectConstResult::GetPointeeData (DataExtractor& data,
373 uint32_t item_idx,
374 uint32_t item_count)
375{
376 return m_impl.GetPointeeData(data, item_idx, item_count);
377}
Greg Clayton0d0f56d2012-07-07 01:22:45 +0000378
379lldb::ValueObjectSP
380ValueObjectConstResult::GetDynamicValue (lldb::DynamicValueType use_dynamic)
381{
382 // Always recalculate dynamic values for const results as the memory that
383 // they might point to might have changed at any time.
384 if (use_dynamic != eNoDynamicValues)
385 {
386 if (!IsDynamic())
387 {
388 ExecutionContext exe_ctx (GetExecutionContextRef());
389 Process *process = exe_ctx.GetProcessPtr();
390 if (process && process->IsPossibleDynamicValue(*this))
391 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
392 }
393 if (m_dynamic_value)
394 return m_dynamic_value->GetSP();
395 }
396 return ValueObjectSP();
397}
398