Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1 | //===-- 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 Clayton | 9407302 | 2012-07-07 01:22:45 +0000 | [diff] [blame] | 12 | #include "lldb/Core/ValueObjectDynamicValue.h" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 13 | #include "lldb/Symbol/CompilerType.h" |
| 14 | #include "lldb/Target/ExecutionContext.h" |
| 15 | #include "lldb/Target/ExecutionContextScope.h" // for ExecutionContextScope |
| 16 | #include "lldb/Target/Process.h" |
| 17 | #include "lldb/Utility/DataBuffer.h" // for DataBuffer |
| 18 | #include "lldb/Utility/DataBufferHeap.h" // for DataBufferHeap |
Zachary Turner | 666cc0b | 2017-03-04 01:30:05 +0000 | [diff] [blame] | 19 | #include "lldb/Utility/DataExtractor.h" |
Pavel Labath | d821c99 | 2018-08-07 11:07:21 +0000 | [diff] [blame] | 20 | #include "lldb/Utility/Scalar.h" // for Scalar |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 21 | |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 22 | namespace lldb_private { |
| 23 | class Module; |
| 24 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 25 | |
| 26 | using namespace lldb; |
| 27 | using namespace lldb_private; |
| 28 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 29 | ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope, |
| 30 | ByteOrder byte_order, |
| 31 | uint32_t addr_byte_size, |
| 32 | lldb::addr_t address) { |
| 33 | return (new ValueObjectConstResult(exe_scope, byte_order, addr_byte_size, |
| 34 | address)) |
| 35 | ->GetSP(); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 38 | ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope, |
| 39 | ByteOrder byte_order, |
| 40 | uint32_t addr_byte_size, |
| 41 | lldb::addr_t address) |
| 42 | : ValueObject(exe_scope), m_type_name(), m_byte_size(0), |
| 43 | m_impl(this, address) { |
| 44 | SetIsConstant(); |
| 45 | SetValueIsValid(true); |
| 46 | m_data.SetByteOrder(byte_order); |
| 47 | m_data.SetAddressByteSize(addr_byte_size); |
| 48 | SetAddressTypeOfChildren(eAddressTypeLoad); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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, |
| 57 | address)) |
| 58 | ->GetSP(); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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) { |
| 66 | m_data = data; |
| 67 | |
| 68 | if (!m_data.GetSharedDataBuffer()) { |
| 69 | DataBufferSP shared_data_buffer( |
| 70 | new DataBufferHeap(data.GetDataStart(), data.GetByteSize())); |
| 71 | m_data.SetData(shared_data_buffer); |
| 72 | } |
| 73 | |
| 74 | m_value.GetScalar() = (uintptr_t)m_data.GetDataStart(); |
| 75 | m_value.SetValueType(Value::eValueTypeHostAddress); |
| 76 | m_value.SetCompilerType(compiler_type); |
| 77 | m_name = name; |
| 78 | SetIsConstant(); |
| 79 | SetValueIsValid(true); |
| 80 | SetAddressTypeOfChildren(eAddressTypeLoad); |
| 81 | } |
| 82 | |
| 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)) |
| 92 | ->GetSP(); |
| 93 | } |
| 94 | |
| 95 | ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope, |
| 96 | Value &value, |
| 97 | const ConstString &name, |
| 98 | Module *module) { |
| 99 | return (new ValueObjectConstResult(exe_scope, value, name, module))->GetSP(); |
| 100 | } |
| 101 | |
| 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); |
| 116 | m_name = name; |
| 117 | SetIsConstant(); |
| 118 | SetValueIsValid(true); |
| 119 | SetAddressTypeOfChildren(eAddressTypeLoad); |
| 120 | } |
| 121 | |
| 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)) |
| 130 | ->GetSP(); |
| 131 | } |
| 132 | |
| 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); |
| 146 | break; |
| 147 | case eAddressTypeFile: |
| 148 | m_value.SetValueType(Value::eValueTypeFileAddress); |
| 149 | break; |
| 150 | case eAddressTypeLoad: |
| 151 | m_value.SetValueType(Value::eValueTypeLoadAddress); |
| 152 | break; |
| 153 | case eAddressTypeHost: |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 154 | m_value.SetValueType(Value::eValueTypeHostAddress); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 155 | break; |
| 156 | } |
| 157 | // m_value.SetContext(Value::eContextTypeClangType, compiler_type); |
| 158 | m_value.SetCompilerType(compiler_type); |
| 159 | m_name = name; |
| 160 | SetIsConstant(); |
| 161 | SetValueIsValid(true); |
| 162 | SetAddressTypeOfChildren(eAddressTypeLoad); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 165 | ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 166 | const Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 167 | return (new ValueObjectConstResult(exe_scope, error))->GetSP(); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 170 | ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 171 | const Status &error) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 172 | : ValueObject(exe_scope), m_type_name(), m_byte_size(0), m_impl(this) { |
| 173 | m_error = error; |
| 174 | SetIsConstant(); |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 177 | ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope, |
| 178 | const Value &value, |
| 179 | const ConstString &name, |
| 180 | Module *module) |
| 181 | : ValueObject(exe_scope), m_type_name(), m_byte_size(0), m_impl(this) { |
| 182 | m_value = value; |
| 183 | m_name = name; |
| 184 | ExecutionContext exe_ctx; |
| 185 | exe_scope->CalculateExecutionContext(exe_ctx); |
| 186 | m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, module); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 189 | ValueObjectConstResult::~ValueObjectConstResult() {} |
| 190 | |
| 191 | CompilerType ValueObjectConstResult::GetCompilerTypeImpl() { |
| 192 | return m_value.GetCompilerType(); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 195 | lldb::ValueType ValueObjectConstResult::GetValueType() const { |
| 196 | return eValueTypeConstResult; |
| 197 | } |
| 198 | |
| 199 | uint64_t ValueObjectConstResult::GetByteSize() { |
| 200 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 201 | |
| 202 | if (m_byte_size == 0) |
| 203 | SetByteSize( |
| 204 | GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope())); |
| 205 | return m_byte_size; |
| 206 | } |
| 207 | |
| 208 | void ValueObjectConstResult::SetByteSize(size_t size) { m_byte_size = size; } |
| 209 | |
| 210 | size_t ValueObjectConstResult::CalculateNumChildren(uint32_t max) { |
Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame^] | 211 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 212 | auto children_count = GetCompilerType().GetNumChildren(true, &exe_ctx); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 213 | return children_count <= max ? children_count : max; |
| 214 | } |
| 215 | |
| 216 | ConstString ValueObjectConstResult::GetTypeName() { |
| 217 | if (m_type_name.IsEmpty()) |
| 218 | m_type_name = GetCompilerType().GetConstTypeName(); |
| 219 | return m_type_name; |
| 220 | } |
| 221 | |
| 222 | ConstString ValueObjectConstResult::GetDisplayTypeName() { |
| 223 | return GetCompilerType().GetDisplayTypeName(); |
| 224 | } |
| 225 | |
| 226 | bool ValueObjectConstResult::UpdateValue() { |
| 227 | // Const value is always valid |
| 228 | SetValueIsValid(true); |
| 229 | return true; |
| 230 | } |
| 231 | |
| 232 | bool ValueObjectConstResult::IsInScope() { |
| 233 | // A const result value is always in scope since it serializes all |
| 234 | // information needed to contain the constant value. |
| 235 | return true; |
| 236 | } |
| 237 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 238 | lldb::ValueObjectSP ValueObjectConstResult::Dereference(Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 239 | return m_impl.Dereference(error); |
| 240 | } |
| 241 | |
| 242 | lldb::ValueObjectSP ValueObjectConstResult::GetSyntheticChildAtOffset( |
| 243 | uint32_t offset, const CompilerType &type, bool can_create, |
| 244 | ConstString name_const_str) { |
| 245 | return m_impl.GetSyntheticChildAtOffset(offset, type, can_create, |
| 246 | name_const_str); |
| 247 | } |
| 248 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 249 | lldb::ValueObjectSP ValueObjectConstResult::AddressOf(Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 250 | return m_impl.AddressOf(error); |
| 251 | } |
| 252 | |
| 253 | lldb::addr_t ValueObjectConstResult::GetAddressOf(bool scalar_is_load_address, |
| 254 | AddressType *address_type) { |
| 255 | return m_impl.GetAddressOf(scalar_is_load_address, address_type); |
| 256 | } |
| 257 | |
| 258 | ValueObject *ValueObjectConstResult::CreateChildAtIndex( |
| 259 | size_t idx, bool synthetic_array_member, int32_t synthetic_index) { |
| 260 | return m_impl.CreateChildAtIndex(idx, synthetic_array_member, |
| 261 | synthetic_index); |
| 262 | } |
| 263 | |
| 264 | size_t ValueObjectConstResult::GetPointeeData(DataExtractor &data, |
| 265 | uint32_t item_idx, |
| 266 | uint32_t item_count) { |
| 267 | return m_impl.GetPointeeData(data, item_idx, item_count); |
| 268 | } |
| 269 | |
| 270 | lldb::ValueObjectSP |
| 271 | ValueObjectConstResult::GetDynamicValue(lldb::DynamicValueType use_dynamic) { |
| 272 | // Always recalculate dynamic values for const results as the memory that |
| 273 | // they might point to might have changed at any time. |
| 274 | if (use_dynamic != eNoDynamicValues) { |
| 275 | if (!IsDynamic()) { |
| 276 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 277 | Process *process = exe_ctx.GetProcessPtr(); |
| 278 | if (process && process->IsPossibleDynamicValue(*this)) |
| 279 | m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 280 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 281 | if (m_dynamic_value) |
| 282 | return m_dynamic_value->GetSP(); |
| 283 | } |
| 284 | return ValueObjectSP(); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 285 | } |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 286 | |
| 287 | lldb::ValueObjectSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 288 | ValueObjectConstResult::Cast(const CompilerType &compiler_type) { |
| 289 | return m_impl.Cast(compiler_type); |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 292 | lldb::LanguageType ValueObjectConstResult::GetPreferredDisplayLanguage() { |
| 293 | if (m_preferred_display_language != lldb::eLanguageTypeUnknown) |
| 294 | return m_preferred_display_language; |
| 295 | return GetCompilerTypeImpl().GetMinimumLanguage(); |
Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 296 | } |