blob: 08d983276a9c024acc2228da169a130056c05f52 [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"
16#include "lldb/Core/ValueObjectList.h"
17
18#include "lldb/Symbol/ClangASTType.h"
19#include "lldb/Symbol/ObjectFile.h"
20#include "lldb/Symbol/SymbolContext.h"
21#include "lldb/Symbol/Type.h"
22#include "lldb/Symbol/Variable.h"
23
24#include "lldb/Target/ExecutionContext.h"
25#include "lldb/Target/Process.h"
26#include "lldb/Target/Target.h"
27
28using namespace lldb;
29using namespace lldb_private;
30
Jim Ingham58b59f92011-04-22 23:53:53 +000031ValueObjectSP
32ValueObjectConstResult::Create
33(
34 ExecutionContextScope *exe_scope,
35 ByteOrder byte_order,
Enrico Granata9128ee22011-09-06 19:20:51 +000036 uint32_t addr_byte_size,
37 lldb::addr_t address
Jim Ingham58b59f92011-04-22 23:53:53 +000038)
39{
40 return (new ValueObjectConstResult (exe_scope,
41 byte_order,
Enrico Granata9128ee22011-09-06 19:20:51 +000042 addr_byte_size,
43 address))->GetSP();
Jim Ingham58b59f92011-04-22 23:53:53 +000044}
45
Greg Clayton1d3afba2010-10-05 00:00:42 +000046ValueObjectConstResult::ValueObjectConstResult
47(
Jim Ingham6035b672011-03-31 00:19:25 +000048 ExecutionContextScope *exe_scope,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000049 ByteOrder byte_order,
Enrico Granata9128ee22011-09-06 19:20:51 +000050 uint32_t addr_byte_size,
51 lldb::addr_t address
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000052) :
Jim Ingham6035b672011-03-31 00:19:25 +000053 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000054 m_clang_ast (NULL),
55 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +000056 m_byte_size (0),
57 m_impl(this, address)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000058{
59 SetIsConstant ();
60 SetValueIsValid(true);
61 m_data.SetByteOrder(byte_order);
62 m_data.SetAddressByteSize(addr_byte_size);
Enrico Granata9128ee22011-09-06 19:20:51 +000063 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000064}
65
Jim Ingham58b59f92011-04-22 23:53:53 +000066ValueObjectSP
67ValueObjectConstResult::Create
68(
69 ExecutionContextScope *exe_scope,
70 clang::ASTContext *clang_ast,
71 void *clang_type,
72 const ConstString &name,
Enrico Granata9128ee22011-09-06 19:20:51 +000073 const DataExtractor &data,
74 lldb::addr_t address
Jim Ingham58b59f92011-04-22 23:53:53 +000075)
76{
77 return (new ValueObjectConstResult (exe_scope,
78 clang_ast,
79 clang_type,
80 name,
Enrico Granata9128ee22011-09-06 19:20:51 +000081 data,
82 address))->GetSP();
Jim Ingham58b59f92011-04-22 23:53:53 +000083}
84
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000085ValueObjectConstResult::ValueObjectConstResult
86(
Jim Ingham6035b672011-03-31 00:19:25 +000087 ExecutionContextScope *exe_scope,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000088 clang::ASTContext *clang_ast,
89 void *clang_type,
90 const ConstString &name,
Enrico Granata9128ee22011-09-06 19:20:51 +000091 const DataExtractor &data,
92 lldb::addr_t address
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000093) :
Jim Ingham6035b672011-03-31 00:19:25 +000094 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000095 m_clang_ast (clang_ast),
96 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +000097 m_byte_size (0),
98 m_impl(this, address)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000099{
100 m_data = data;
Sean Callanan31a8d052012-01-05 01:11:09 +0000101
102 if (!m_data.GetSharedDataBuffer())
103 {
104 DataBufferSP shared_data_buffer(new DataBufferHeap(data.GetDataStart(), data.GetByteSize()));
105 m_data.SetData(shared_data_buffer);
106 }
107
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000108 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
109 m_value.SetValueType(Value::eValueTypeHostAddress);
110 m_value.SetContext(Value::eContextTypeClangType, clang_type);
111 m_name = name;
112 SetIsConstant ();
113 SetValueIsValid(true);
Enrico Granata9128ee22011-09-06 19:20:51 +0000114 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000115}
116
Jim Ingham58b59f92011-04-22 23:53:53 +0000117ValueObjectSP
118ValueObjectConstResult::Create
119(
120 ExecutionContextScope *exe_scope,
121 clang::ASTContext *clang_ast,
122 void *clang_type,
123 const ConstString &name,
124 const lldb::DataBufferSP &data_sp,
125 lldb::ByteOrder data_byte_order,
Enrico Granata9128ee22011-09-06 19:20:51 +0000126 uint8_t data_addr_size,
127 lldb::addr_t address
Jim Ingham58b59f92011-04-22 23:53:53 +0000128)
129{
130 return (new ValueObjectConstResult (exe_scope,
131 clang_ast,
132 clang_type,
133 name,
134 data_sp,
135 data_byte_order,
Enrico Granata9128ee22011-09-06 19:20:51 +0000136 data_addr_size,
137 address))->GetSP();
Jim Ingham58b59f92011-04-22 23:53:53 +0000138}
139
Jim Ingham73ca05a2011-12-17 01:35:57 +0000140ValueObjectSP
141ValueObjectConstResult::Create (ExecutionContextScope *exe_scope,
142 clang::ASTContext *clang_ast,
143 Value &value,
144 const ConstString &name)
145{
146 return (new ValueObjectConstResult (exe_scope, clang_ast, value, name))->GetSP();
147}
148
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000149ValueObjectConstResult::ValueObjectConstResult
150(
Jim Ingham6035b672011-03-31 00:19:25 +0000151 ExecutionContextScope *exe_scope,
Greg Clayton1d3afba2010-10-05 00:00:42 +0000152 clang::ASTContext *clang_ast,
153 void *clang_type,
154 const ConstString &name,
155 const lldb::DataBufferSP &data_sp,
156 lldb::ByteOrder data_byte_order,
Enrico Granata9128ee22011-09-06 19:20:51 +0000157 uint8_t data_addr_size,
158 lldb::addr_t address
Greg Clayton1d3afba2010-10-05 00:00:42 +0000159) :
Jim Ingham6035b672011-03-31 00:19:25 +0000160 ValueObject (exe_scope),
Greg Clayton1d3afba2010-10-05 00:00:42 +0000161 m_clang_ast (clang_ast),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000162 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +0000163 m_byte_size (0),
164 m_impl(this, address)
Greg Clayton1d3afba2010-10-05 00:00:42 +0000165{
166 m_data.SetByteOrder(data_byte_order);
167 m_data.SetAddressByteSize(data_addr_size);
168 m_data.SetData(data_sp);
169 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
170 m_value.SetValueType(Value::eValueTypeHostAddress);
Greg Clayton526e5af2010-11-13 03:52:47 +0000171 m_value.SetContext(Value::eContextTypeClangType, clang_type);
Greg Clayton1d3afba2010-10-05 00:00:42 +0000172 m_name = name;
Greg Claytonb71f3842010-10-05 03:13:51 +0000173 SetIsConstant ();
Jim Inghame2f88412010-10-15 22:47:36 +0000174 SetValueIsValid(true);
Enrico Granata9128ee22011-09-06 19:20:51 +0000175 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000176}
177
Jim Ingham58b59f92011-04-22 23:53:53 +0000178ValueObjectSP
179ValueObjectConstResult::Create
180(
181 ExecutionContextScope *exe_scope,
182 clang::ASTContext *clang_ast,
183 void *clang_type,
184 const ConstString &name,
185 lldb::addr_t address,
186 AddressType address_type,
187 uint8_t addr_byte_size
188)
189{
190 return (new ValueObjectConstResult (exe_scope,
191 clang_ast,
192 clang_type,
193 name,
194 address,
195 address_type,
196 addr_byte_size))->GetSP();
197}
198
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000199ValueObjectConstResult::ValueObjectConstResult
200(
Jim Ingham6035b672011-03-31 00:19:25 +0000201 ExecutionContextScope *exe_scope,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000202 clang::ASTContext *clang_ast,
203 void *clang_type,
204 const ConstString &name,
205 lldb::addr_t address,
Greg Claytone0d378b2011-03-24 21:19:54 +0000206 AddressType address_type,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000207 uint8_t addr_byte_size
208) :
Jim Ingham6035b672011-03-31 00:19:25 +0000209 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000210 m_clang_ast (clang_ast),
211 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +0000212 m_byte_size (0),
213 m_impl(this, address)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000214{
215 m_value.GetScalar() = address;
216 m_data.SetAddressByteSize(addr_byte_size);
217 m_value.GetScalar().GetData (m_data, addr_byte_size);
218 //m_value.SetValueType(Value::eValueTypeHostAddress);
219 switch (address_type)
220 {
221 default:
222 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 Granata9128ee22011-09-06 19:20:51 +0000231 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Claytonb71f3842010-10-05 03:13:51 +0000232}
233
Jim Ingham58b59f92011-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 Ingham6035b672011-03-31 00:19:25 +0000245ValueObjectConstResult::ValueObjectConstResult (
246 ExecutionContextScope *exe_scope,
247 const Error& error) :
248 ValueObject (exe_scope),
Greg Claytonb71f3842010-10-05 03:13:51 +0000249 m_clang_ast (NULL),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000250 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +0000251 m_byte_size (0),
252 m_impl(this)
Greg Claytonb71f3842010-10-05 03:13:51 +0000253{
254 m_error = error;
255 SetIsConstant ();
Greg Clayton1d3afba2010-10-05 00:00:42 +0000256}
257
Jim Ingham73ca05a2011-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),
264 m_type_name (),
265 m_byte_size (0),
266 m_clang_ast (clang_ast),
267 m_impl(this)
268{
269 m_value = value;
270 m_value.GetData(m_data);
271}
272
Greg Clayton1d3afba2010-10-05 00:00:42 +0000273ValueObjectConstResult::~ValueObjectConstResult()
274{
275}
276
Greg Clayton6beaaa62011-01-17 03:46:26 +0000277lldb::clang_type_t
Sean Callanan72772842012-02-22 23:57:45 +0000278ValueObjectConstResult::GetClangTypeImpl()
Greg Clayton1d3afba2010-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 Clayton8b2fe6d2010-12-14 02:59:59 +0000292 if (m_byte_size == 0)
Enrico Granata9128ee22011-09-06 19:20:51 +0000293 m_byte_size = ClangASTType::GetTypeByteSize(GetClangAST(), GetClangType());
Greg Clayton8b2fe6d2010-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 Clayton1d3afba2010-10-05 00:00:42 +0000301}
302
303uint32_t
304ValueObjectConstResult::CalculateNumChildren()
305{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000306 return ClangASTContext::GetNumChildren (GetClangAST (), GetClangType(), true);
Greg Clayton1d3afba2010-10-05 00:00:42 +0000307}
308
309clang::ASTContext *
Sean Callanan72772842012-02-22 23:57:45 +0000310ValueObjectConstResult::GetClangASTImpl ()
Greg Clayton1d3afba2010-10-05 00:00:42 +0000311{
312 return m_clang_ast;
313}
314
315ConstString
316ValueObjectConstResult::GetTypeName()
317{
318 if (m_type_name.IsEmpty())
Greg Clayton84db9102012-03-26 23:03:23 +0000319 m_type_name = ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
Greg Clayton1d3afba2010-10-05 00:00:42 +0000320 return m_type_name;
321}
322
Jim Ingham6035b672011-03-31 00:19:25 +0000323bool
324ValueObjectConstResult::UpdateValue ()
Greg Clayton1d3afba2010-10-05 00:00:42 +0000325{
Greg Clayton1d3afba2010-10-05 00:00:42 +0000326 // Const value is always valid
327 SetValueIsValid (true);
Jim Ingham6035b672011-03-31 00:19:25 +0000328 return true;
Greg Clayton1d3afba2010-10-05 00:00:42 +0000329}
330
331
332bool
Jim Ingham6035b672011-03-31 00:19:25 +0000333ValueObjectConstResult::IsInScope ()
Greg Clayton1d3afba2010-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 Granata9128ee22011-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 Chenb456b792011-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 Granata9128ee22011-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}