1 //===-- ValueObjectConstResult.cpp ------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/ValueObjectConstResult.h"
12 #include "lldb/Core/ValueObjectDynamicValue.h"
13 #include "lldb/Symbol/CompilerType.h"
14 #include "lldb/Target/ExecutionContext.h"
15 #include "lldb/Target/ExecutionContextScope.h"
16 #include "lldb/Target/Process.h"
17 #include "lldb/Utility/DataBuffer.h"
18 #include "lldb/Utility/DataBufferHeap.h"
19 #include "lldb/Utility/DataExtractor.h"
20 #include "lldb/Utility/Scalar.h"
22 namespace lldb_private {
27 using namespace lldb_private;
29 ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
31 uint32_t addr_byte_size,
32 lldb::addr_t address) {
33 return (new ValueObjectConstResult(exe_scope, byte_order, addr_byte_size,
38 ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope,
40 uint32_t addr_byte_size,
42 : ValueObject(exe_scope), m_type_name(), m_byte_size(0),
43 m_impl(this, address) {
45 SetValueIsValid(true);
46 m_data.SetByteOrder(byte_order);
47 m_data.SetAddressByteSize(addr_byte_size);
48 SetAddressTypeOfChildren(eAddressTypeLoad);
51 ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
52 const CompilerType &compiler_type,
53 const ConstString &name,
54 const DataExtractor &data,
55 lldb::addr_t address) {
56 return (new ValueObjectConstResult(exe_scope, compiler_type, name, data,
61 ValueObjectConstResult::ValueObjectConstResult(
62 ExecutionContextScope *exe_scope, const CompilerType &compiler_type,
63 const ConstString &name, const DataExtractor &data, lldb::addr_t address)
64 : ValueObject(exe_scope), m_type_name(), m_byte_size(0),
65 m_impl(this, address) {
68 if (!m_data.GetSharedDataBuffer()) {
69 DataBufferSP shared_data_buffer(
70 new DataBufferHeap(data.GetDataStart(), data.GetByteSize()));
71 m_data.SetData(shared_data_buffer);
74 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
75 m_value.SetValueType(Value::eValueTypeHostAddress);
76 m_value.SetCompilerType(compiler_type);
79 SetValueIsValid(true);
80 SetAddressTypeOfChildren(eAddressTypeLoad);
83 ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
84 const CompilerType &compiler_type,
85 const ConstString &name,
86 const lldb::DataBufferSP &data_sp,
87 lldb::ByteOrder data_byte_order,
88 uint32_t data_addr_size,
89 lldb::addr_t address) {
90 return (new ValueObjectConstResult(exe_scope, compiler_type, name, data_sp,
91 data_byte_order, data_addr_size, address))
95 ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
97 const ConstString &name,
99 return (new ValueObjectConstResult(exe_scope, value, name, module))->GetSP();
102 ValueObjectConstResult::ValueObjectConstResult(
103 ExecutionContextScope *exe_scope, const CompilerType &compiler_type,
104 const ConstString &name, const lldb::DataBufferSP &data_sp,
105 lldb::ByteOrder data_byte_order, uint32_t data_addr_size,
106 lldb::addr_t address)
107 : ValueObject(exe_scope), m_type_name(), m_byte_size(0),
108 m_impl(this, address) {
109 m_data.SetByteOrder(data_byte_order);
110 m_data.SetAddressByteSize(data_addr_size);
111 m_data.SetData(data_sp);
112 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
113 m_value.SetValueType(Value::eValueTypeHostAddress);
114 // m_value.SetContext(Value::eContextTypeClangType, compiler_type);
115 m_value.SetCompilerType(compiler_type);
118 SetValueIsValid(true);
119 SetAddressTypeOfChildren(eAddressTypeLoad);
122 ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
123 const CompilerType &compiler_type,
124 const ConstString &name,
125 lldb::addr_t address,
126 AddressType address_type,
127 uint32_t addr_byte_size) {
128 return (new ValueObjectConstResult(exe_scope, compiler_type, name, address,
129 address_type, addr_byte_size))
133 ValueObjectConstResult::ValueObjectConstResult(
134 ExecutionContextScope *exe_scope, const CompilerType &compiler_type,
135 const ConstString &name, lldb::addr_t address, AddressType address_type,
136 uint32_t addr_byte_size)
137 : ValueObject(exe_scope), m_type_name(), m_byte_size(0),
138 m_impl(this, address) {
139 m_value.GetScalar() = address;
140 m_data.SetAddressByteSize(addr_byte_size);
141 m_value.GetScalar().GetData(m_data, addr_byte_size);
142 // m_value.SetValueType(Value::eValueTypeHostAddress);
143 switch (address_type) {
144 case eAddressTypeInvalid:
145 m_value.SetValueType(Value::eValueTypeScalar);
147 case eAddressTypeFile:
148 m_value.SetValueType(Value::eValueTypeFileAddress);
150 case eAddressTypeLoad:
151 m_value.SetValueType(Value::eValueTypeLoadAddress);
153 case eAddressTypeHost:
154 m_value.SetValueType(Value::eValueTypeHostAddress);
157 // m_value.SetContext(Value::eContextTypeClangType, compiler_type);
158 m_value.SetCompilerType(compiler_type);
161 SetValueIsValid(true);
162 SetAddressTypeOfChildren(eAddressTypeLoad);
165 ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
166 const Status &error) {
167 return (new ValueObjectConstResult(exe_scope, error))->GetSP();
170 ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope,
172 : ValueObject(exe_scope), m_type_name(), m_byte_size(0), m_impl(this) {
177 ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope,
179 const ConstString &name,
181 : ValueObject(exe_scope), m_type_name(), m_byte_size(0), m_impl(this) {
184 ExecutionContext exe_ctx;
185 exe_scope->CalculateExecutionContext(exe_ctx);
186 m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, module);
189 ValueObjectConstResult::~ValueObjectConstResult() {}
191 CompilerType ValueObjectConstResult::GetCompilerTypeImpl() {
192 return m_value.GetCompilerType();
195 lldb::ValueType ValueObjectConstResult::GetValueType() const {
196 return eValueTypeConstResult;
199 uint64_t ValueObjectConstResult::GetByteSize() {
200 ExecutionContext exe_ctx(GetExecutionContextRef());
201 if (m_byte_size == 0) {
203 GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope()))
209 void ValueObjectConstResult::SetByteSize(size_t size) { m_byte_size = size; }
211 size_t ValueObjectConstResult::CalculateNumChildren(uint32_t max) {
212 ExecutionContext exe_ctx(GetExecutionContextRef());
213 auto children_count = GetCompilerType().GetNumChildren(true, &exe_ctx);
214 return children_count <= max ? children_count : max;
217 ConstString ValueObjectConstResult::GetTypeName() {
218 if (m_type_name.IsEmpty())
219 m_type_name = GetCompilerType().GetConstTypeName();
223 ConstString ValueObjectConstResult::GetDisplayTypeName() {
224 return GetCompilerType().GetDisplayTypeName();
227 bool ValueObjectConstResult::UpdateValue() {
228 // Const value is always valid
229 SetValueIsValid(true);
233 bool ValueObjectConstResult::IsInScope() {
234 // A const result value is always in scope since it serializes all
235 // information needed to contain the constant value.
239 lldb::ValueObjectSP ValueObjectConstResult::Dereference(Status &error) {
240 return m_impl.Dereference(error);
243 lldb::ValueObjectSP ValueObjectConstResult::GetSyntheticChildAtOffset(
244 uint32_t offset, const CompilerType &type, bool can_create,
245 ConstString name_const_str) {
246 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create,
250 lldb::ValueObjectSP ValueObjectConstResult::AddressOf(Status &error) {
251 return m_impl.AddressOf(error);
254 lldb::addr_t ValueObjectConstResult::GetAddressOf(bool scalar_is_load_address,
255 AddressType *address_type) {
256 return m_impl.GetAddressOf(scalar_is_load_address, address_type);
259 ValueObject *ValueObjectConstResult::CreateChildAtIndex(
260 size_t idx, bool synthetic_array_member, int32_t synthetic_index) {
261 return m_impl.CreateChildAtIndex(idx, synthetic_array_member,
265 size_t ValueObjectConstResult::GetPointeeData(DataExtractor &data,
267 uint32_t item_count) {
268 return m_impl.GetPointeeData(data, item_idx, item_count);
272 ValueObjectConstResult::GetDynamicValue(lldb::DynamicValueType use_dynamic) {
273 // Always recalculate dynamic values for const results as the memory that
274 // they might point to might have changed at any time.
275 if (use_dynamic != eNoDynamicValues) {
277 ExecutionContext exe_ctx(GetExecutionContextRef());
278 Process *process = exe_ctx.GetProcessPtr();
279 if (process && process->IsPossibleDynamicValue(*this))
280 m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic);
283 return m_dynamic_value->GetSP();
285 return ValueObjectSP();
289 ValueObjectConstResult::Cast(const CompilerType &compiler_type) {
290 return m_impl.Cast(compiler_type);
293 lldb::LanguageType ValueObjectConstResult::GetPreferredDisplayLanguage() {
294 if (m_preferred_display_language != lldb::eLanguageTypeUnknown)
295 return m_preferred_display_language;
296 return GetCompilerTypeImpl().GetMinimumLanguage();