blob: cac7b2657b7a31e0cac5d8ee78c68853b203f480 [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
Greg Clayton1d3afba2010-10-05 00:00:42 +000012#include "lldb/Core/Module.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000013#include "lldb/Core/ValueObjectChild.h"
14#include "lldb/Core/ValueObjectConstResultChild.h"
Greg Clayton94073022012-07-07 01:22:45 +000015#include "lldb/Core/ValueObjectDynamicValue.h"
Greg Clayton1d3afba2010-10-05 00:00:42 +000016#include "lldb/Core/ValueObjectList.h"
Zachary Turner666cc0b2017-03-04 01:30:05 +000017#include "lldb/Utility/DataExtractor.h"
Greg Clayton1d3afba2010-10-05 00:00:42 +000018
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
Kate Stoneb9c1b512016-09-06 20:57:50 +000032ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
33 ByteOrder byte_order,
34 uint32_t addr_byte_size,
35 lldb::addr_t address) {
36 return (new ValueObjectConstResult(exe_scope, byte_order, addr_byte_size,
37 address))
38 ->GetSP();
Jim Ingham58b59f92011-04-22 23:53:53 +000039}
40
Kate Stoneb9c1b512016-09-06 20:57:50 +000041ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope,
42 ByteOrder byte_order,
43 uint32_t addr_byte_size,
44 lldb::addr_t address)
45 : ValueObject(exe_scope), m_type_name(), m_byte_size(0),
46 m_impl(this, address) {
47 SetIsConstant();
48 SetValueIsValid(true);
49 m_data.SetByteOrder(byte_order);
50 m_data.SetAddressByteSize(addr_byte_size);
51 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000052}
53
Kate Stoneb9c1b512016-09-06 20:57:50 +000054ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
55 const CompilerType &compiler_type,
56 const ConstString &name,
57 const DataExtractor &data,
58 lldb::addr_t address) {
59 return (new ValueObjectConstResult(exe_scope, compiler_type, name, data,
60 address))
61 ->GetSP();
Jim Ingham58b59f92011-04-22 23:53:53 +000062}
63
Kate Stoneb9c1b512016-09-06 20:57:50 +000064ValueObjectConstResult::ValueObjectConstResult(
65 ExecutionContextScope *exe_scope, const CompilerType &compiler_type,
66 const ConstString &name, const DataExtractor &data, lldb::addr_t address)
67 : ValueObject(exe_scope), m_type_name(), m_byte_size(0),
68 m_impl(this, address) {
69 m_data = data;
70
71 if (!m_data.GetSharedDataBuffer()) {
72 DataBufferSP shared_data_buffer(
73 new DataBufferHeap(data.GetDataStart(), data.GetByteSize()));
74 m_data.SetData(shared_data_buffer);
75 }
76
77 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
78 m_value.SetValueType(Value::eValueTypeHostAddress);
79 m_value.SetCompilerType(compiler_type);
80 m_name = name;
81 SetIsConstant();
82 SetValueIsValid(true);
83 SetAddressTypeOfChildren(eAddressTypeLoad);
84}
85
86ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
87 const CompilerType &compiler_type,
88 const ConstString &name,
89 const lldb::DataBufferSP &data_sp,
90 lldb::ByteOrder data_byte_order,
91 uint32_t data_addr_size,
92 lldb::addr_t address) {
93 return (new ValueObjectConstResult(exe_scope, compiler_type, name, data_sp,
94 data_byte_order, data_addr_size, address))
95 ->GetSP();
96}
97
98ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
99 Value &value,
100 const ConstString &name,
101 Module *module) {
102 return (new ValueObjectConstResult(exe_scope, value, name, module))->GetSP();
103}
104
105ValueObjectConstResult::ValueObjectConstResult(
106 ExecutionContextScope *exe_scope, const CompilerType &compiler_type,
107 const ConstString &name, const lldb::DataBufferSP &data_sp,
108 lldb::ByteOrder data_byte_order, uint32_t data_addr_size,
109 lldb::addr_t address)
110 : ValueObject(exe_scope), m_type_name(), m_byte_size(0),
111 m_impl(this, address) {
112 m_data.SetByteOrder(data_byte_order);
113 m_data.SetAddressByteSize(data_addr_size);
114 m_data.SetData(data_sp);
115 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
116 m_value.SetValueType(Value::eValueTypeHostAddress);
117 // m_value.SetContext(Value::eContextTypeClangType, compiler_type);
118 m_value.SetCompilerType(compiler_type);
119 m_name = name;
120 SetIsConstant();
121 SetValueIsValid(true);
122 SetAddressTypeOfChildren(eAddressTypeLoad);
123}
124
125ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
126 const CompilerType &compiler_type,
127 const ConstString &name,
128 lldb::addr_t address,
129 AddressType address_type,
130 uint32_t addr_byte_size) {
131 return (new ValueObjectConstResult(exe_scope, compiler_type, name, address,
132 address_type, addr_byte_size))
133 ->GetSP();
134}
135
136ValueObjectConstResult::ValueObjectConstResult(
137 ExecutionContextScope *exe_scope, const CompilerType &compiler_type,
138 const ConstString &name, lldb::addr_t address, AddressType address_type,
139 uint32_t addr_byte_size)
140 : ValueObject(exe_scope), m_type_name(), m_byte_size(0),
141 m_impl(this, address) {
142 m_value.GetScalar() = address;
143 m_data.SetAddressByteSize(addr_byte_size);
144 m_value.GetScalar().GetData(m_data, addr_byte_size);
145 // m_value.SetValueType(Value::eValueTypeHostAddress);
146 switch (address_type) {
147 case eAddressTypeInvalid:
148 m_value.SetValueType(Value::eValueTypeScalar);
149 break;
150 case eAddressTypeFile:
151 m_value.SetValueType(Value::eValueTypeFileAddress);
152 break;
153 case eAddressTypeLoad:
154 m_value.SetValueType(Value::eValueTypeLoadAddress);
155 break;
156 case eAddressTypeHost:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000157 m_value.SetValueType(Value::eValueTypeHostAddress);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000158 break;
159 }
160 // m_value.SetContext(Value::eContextTypeClangType, compiler_type);
161 m_value.SetCompilerType(compiler_type);
162 m_name = name;
163 SetIsConstant();
164 SetValueIsValid(true);
165 SetAddressTypeOfChildren(eAddressTypeLoad);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000166}
167
Kate Stoneb9c1b512016-09-06 20:57:50 +0000168ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
169 const Error &error) {
170 return (new ValueObjectConstResult(exe_scope, error))->GetSP();
Jim Ingham58b59f92011-04-22 23:53:53 +0000171}
172
Kate Stoneb9c1b512016-09-06 20:57:50 +0000173ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope,
174 const Error &error)
175 : ValueObject(exe_scope), m_type_name(), m_byte_size(0), m_impl(this) {
176 m_error = error;
177 SetIsConstant();
Jim Ingham73ca05a2011-12-17 01:35:57 +0000178}
179
Kate Stoneb9c1b512016-09-06 20:57:50 +0000180ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope,
181 const Value &value,
182 const ConstString &name,
183 Module *module)
184 : ValueObject(exe_scope), m_type_name(), m_byte_size(0), m_impl(this) {
185 m_value = value;
186 m_name = name;
187 ExecutionContext exe_ctx;
188 exe_scope->CalculateExecutionContext(exe_ctx);
189 m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, module);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000190}
191
Kate Stoneb9c1b512016-09-06 20:57:50 +0000192ValueObjectConstResult::~ValueObjectConstResult() {}
193
194CompilerType ValueObjectConstResult::GetCompilerTypeImpl() {
195 return m_value.GetCompilerType();
Jim Ingham58b59f92011-04-22 23:53:53 +0000196}
197
Kate Stoneb9c1b512016-09-06 20:57:50 +0000198lldb::ValueType ValueObjectConstResult::GetValueType() const {
199 return eValueTypeConstResult;
200}
201
202uint64_t ValueObjectConstResult::GetByteSize() {
203 ExecutionContext exe_ctx(GetExecutionContextRef());
204
205 if (m_byte_size == 0)
206 SetByteSize(
207 GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope()));
208 return m_byte_size;
209}
210
211void ValueObjectConstResult::SetByteSize(size_t size) { m_byte_size = size; }
212
213size_t ValueObjectConstResult::CalculateNumChildren(uint32_t max) {
214 auto children_count = GetCompilerType().GetNumChildren(true);
215 return children_count <= max ? children_count : max;
216}
217
218ConstString ValueObjectConstResult::GetTypeName() {
219 if (m_type_name.IsEmpty())
220 m_type_name = GetCompilerType().GetConstTypeName();
221 return m_type_name;
222}
223
224ConstString ValueObjectConstResult::GetDisplayTypeName() {
225 return GetCompilerType().GetDisplayTypeName();
226}
227
228bool ValueObjectConstResult::UpdateValue() {
229 // Const value is always valid
230 SetValueIsValid(true);
231 return true;
232}
233
234bool ValueObjectConstResult::IsInScope() {
235 // A const result value is always in scope since it serializes all
236 // information needed to contain the constant value.
237 return true;
238}
239
240lldb::ValueObjectSP ValueObjectConstResult::Dereference(Error &error) {
241 return m_impl.Dereference(error);
242}
243
244lldb::ValueObjectSP ValueObjectConstResult::GetSyntheticChildAtOffset(
245 uint32_t offset, const CompilerType &type, bool can_create,
246 ConstString name_const_str) {
247 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create,
248 name_const_str);
249}
250
251lldb::ValueObjectSP ValueObjectConstResult::AddressOf(Error &error) {
252 return m_impl.AddressOf(error);
253}
254
255lldb::addr_t ValueObjectConstResult::GetAddressOf(bool scalar_is_load_address,
256 AddressType *address_type) {
257 return m_impl.GetAddressOf(scalar_is_load_address, address_type);
258}
259
260ValueObject *ValueObjectConstResult::CreateChildAtIndex(
261 size_t idx, bool synthetic_array_member, int32_t synthetic_index) {
262 return m_impl.CreateChildAtIndex(idx, synthetic_array_member,
263 synthetic_index);
264}
265
266size_t ValueObjectConstResult::GetPointeeData(DataExtractor &data,
267 uint32_t item_idx,
268 uint32_t item_count) {
269 return m_impl.GetPointeeData(data, item_idx, item_count);
270}
271
272lldb::ValueObjectSP
273ValueObjectConstResult::GetDynamicValue(lldb::DynamicValueType use_dynamic) {
274 // Always recalculate dynamic values for const results as the memory that
275 // they might point to might have changed at any time.
276 if (use_dynamic != eNoDynamicValues) {
277 if (!IsDynamic()) {
278 ExecutionContext exe_ctx(GetExecutionContextRef());
279 Process *process = exe_ctx.GetProcessPtr();
280 if (process && process->IsPossibleDynamicValue(*this))
281 m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000282 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000283 if (m_dynamic_value)
284 return m_dynamic_value->GetSP();
285 }
286 return ValueObjectSP();
Greg Clayton1d3afba2010-10-05 00:00:42 +0000287}
Enrico Granata9128ee22011-09-06 19:20:51 +0000288
289lldb::ValueObjectSP
Kate Stoneb9c1b512016-09-06 20:57:50 +0000290ValueObjectConstResult::Cast(const CompilerType &compiler_type) {
291 return m_impl.Cast(compiler_type);
Enrico Granata9128ee22011-09-06 19:20:51 +0000292}
293
Kate Stoneb9c1b512016-09-06 20:57:50 +0000294lldb::LanguageType ValueObjectConstResult::GetPreferredDisplayLanguage() {
295 if (m_preferred_display_language != lldb::eLanguageTypeUnknown)
296 return m_preferred_display_language;
297 return GetCompilerTypeImpl().GetMinimumLanguage();
Enrico Granatac1247f52014-11-06 21:23:20 +0000298}