blob: fa1503f3217db89df22184ceddc8998d9e64dcbe [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;
101 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
102 m_value.SetValueType(Value::eValueTypeHostAddress);
103 m_value.SetContext(Value::eContextTypeClangType, clang_type);
104 m_name = name;
105 SetIsConstant ();
106 SetValueIsValid(true);
Enrico Granata9128ee22011-09-06 19:20:51 +0000107 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000108}
109
Jim Ingham58b59f92011-04-22 23:53:53 +0000110ValueObjectSP
111ValueObjectConstResult::Create
112(
113 ExecutionContextScope *exe_scope,
114 clang::ASTContext *clang_ast,
115 void *clang_type,
116 const ConstString &name,
117 const lldb::DataBufferSP &data_sp,
118 lldb::ByteOrder data_byte_order,
Enrico Granata9128ee22011-09-06 19:20:51 +0000119 uint8_t data_addr_size,
120 lldb::addr_t address
Jim Ingham58b59f92011-04-22 23:53:53 +0000121)
122{
123 return (new ValueObjectConstResult (exe_scope,
124 clang_ast,
125 clang_type,
126 name,
127 data_sp,
128 data_byte_order,
Enrico Granata9128ee22011-09-06 19:20:51 +0000129 data_addr_size,
130 address))->GetSP();
Jim Ingham58b59f92011-04-22 23:53:53 +0000131}
132
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000133ValueObjectConstResult::ValueObjectConstResult
134(
Jim Ingham6035b672011-03-31 00:19:25 +0000135 ExecutionContextScope *exe_scope,
Greg Clayton1d3afba2010-10-05 00:00:42 +0000136 clang::ASTContext *clang_ast,
137 void *clang_type,
138 const ConstString &name,
139 const lldb::DataBufferSP &data_sp,
140 lldb::ByteOrder data_byte_order,
Enrico Granata9128ee22011-09-06 19:20:51 +0000141 uint8_t data_addr_size,
142 lldb::addr_t address
Greg Clayton1d3afba2010-10-05 00:00:42 +0000143) :
Jim Ingham6035b672011-03-31 00:19:25 +0000144 ValueObject (exe_scope),
Greg Clayton1d3afba2010-10-05 00:00:42 +0000145 m_clang_ast (clang_ast),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000146 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +0000147 m_byte_size (0),
148 m_impl(this, address)
Greg Clayton1d3afba2010-10-05 00:00:42 +0000149{
150 m_data.SetByteOrder(data_byte_order);
151 m_data.SetAddressByteSize(data_addr_size);
152 m_data.SetData(data_sp);
153 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
154 m_value.SetValueType(Value::eValueTypeHostAddress);
Greg Clayton526e5af2010-11-13 03:52:47 +0000155 m_value.SetContext(Value::eContextTypeClangType, clang_type);
Greg Clayton1d3afba2010-10-05 00:00:42 +0000156 m_name = name;
Greg Claytonb71f3842010-10-05 03:13:51 +0000157 SetIsConstant ();
Jim Inghame2f88412010-10-15 22:47:36 +0000158 SetValueIsValid(true);
Enrico Granata9128ee22011-09-06 19:20:51 +0000159 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000160}
161
Jim Ingham58b59f92011-04-22 23:53:53 +0000162ValueObjectSP
163ValueObjectConstResult::Create
164(
165 ExecutionContextScope *exe_scope,
166 clang::ASTContext *clang_ast,
167 void *clang_type,
168 const ConstString &name,
169 lldb::addr_t address,
170 AddressType address_type,
171 uint8_t addr_byte_size
172)
173{
174 return (new ValueObjectConstResult (exe_scope,
175 clang_ast,
176 clang_type,
177 name,
178 address,
179 address_type,
180 addr_byte_size))->GetSP();
181}
182
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000183ValueObjectConstResult::ValueObjectConstResult
184(
Jim Ingham6035b672011-03-31 00:19:25 +0000185 ExecutionContextScope *exe_scope,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000186 clang::ASTContext *clang_ast,
187 void *clang_type,
188 const ConstString &name,
189 lldb::addr_t address,
Greg Claytone0d378b2011-03-24 21:19:54 +0000190 AddressType address_type,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000191 uint8_t addr_byte_size
192) :
Jim Ingham6035b672011-03-31 00:19:25 +0000193 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000194 m_clang_ast (clang_ast),
195 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +0000196 m_byte_size (0),
197 m_impl(this, address)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000198{
199 m_value.GetScalar() = address;
200 m_data.SetAddressByteSize(addr_byte_size);
201 m_value.GetScalar().GetData (m_data, addr_byte_size);
202 //m_value.SetValueType(Value::eValueTypeHostAddress);
203 switch (address_type)
204 {
205 default:
206 case eAddressTypeInvalid: m_value.SetValueType(Value::eValueTypeScalar); break;
207 case eAddressTypeFile: m_value.SetValueType(Value::eValueTypeFileAddress); break;
208 case eAddressTypeLoad: m_value.SetValueType(Value::eValueTypeLoadAddress); break;
209 case eAddressTypeHost: m_value.SetValueType(Value::eValueTypeHostAddress); break;
210 }
211 m_value.SetContext(Value::eContextTypeClangType, clang_type);
212 m_name = name;
213 SetIsConstant ();
214 SetValueIsValid(true);
Enrico Granata9128ee22011-09-06 19:20:51 +0000215 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Claytonb71f3842010-10-05 03:13:51 +0000216}
217
Jim Ingham58b59f92011-04-22 23:53:53 +0000218ValueObjectSP
219ValueObjectConstResult::Create
220(
221 ExecutionContextScope *exe_scope,
222 const Error& error
223)
224{
225 return (new ValueObjectConstResult (exe_scope,
226 error))->GetSP();
227}
228
Jim Ingham6035b672011-03-31 00:19:25 +0000229ValueObjectConstResult::ValueObjectConstResult (
230 ExecutionContextScope *exe_scope,
231 const Error& error) :
232 ValueObject (exe_scope),
Greg Claytonb71f3842010-10-05 03:13:51 +0000233 m_clang_ast (NULL),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000234 m_type_name (),
Enrico Granata9128ee22011-09-06 19:20:51 +0000235 m_byte_size (0),
236 m_impl(this)
Greg Claytonb71f3842010-10-05 03:13:51 +0000237{
238 m_error = error;
239 SetIsConstant ();
Greg Clayton1d3afba2010-10-05 00:00:42 +0000240}
241
242ValueObjectConstResult::~ValueObjectConstResult()
243{
244}
245
Greg Clayton6beaaa62011-01-17 03:46:26 +0000246lldb::clang_type_t
Greg Clayton1d3afba2010-10-05 00:00:42 +0000247ValueObjectConstResult::GetClangType()
248{
249 return m_value.GetClangType();
250}
251
252lldb::ValueType
253ValueObjectConstResult::GetValueType() const
254{
255 return eValueTypeConstResult;
256}
257
258size_t
259ValueObjectConstResult::GetByteSize()
260{
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000261 if (m_byte_size == 0)
Enrico Granata9128ee22011-09-06 19:20:51 +0000262 m_byte_size = ClangASTType::GetTypeByteSize(GetClangAST(), GetClangType());
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
272uint32_t
273ValueObjectConstResult::CalculateNumChildren()
274{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000275 return ClangASTContext::GetNumChildren (GetClangAST (), GetClangType(), true);
Greg Clayton1d3afba2010-10-05 00:00:42 +0000276}
277
278clang::ASTContext *
279ValueObjectConstResult::GetClangAST ()
280{
281 return m_clang_ast;
282}
283
284ConstString
285ValueObjectConstResult::GetTypeName()
286{
287 if (m_type_name.IsEmpty())
Greg Claytone3055942011-06-30 02:28:26 +0000288 m_type_name = ClangASTType::GetConstTypeName (GetClangType());
Greg Clayton1d3afba2010-10-05 00:00:42 +0000289 return m_type_name;
290}
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
316ValueObjectConstResult::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
317{
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 *
335ValueObjectConstResult::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
336{
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}