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 12 #include "lldb/Core/ValueObjectChild.h" 13 #include "lldb/Core/ValueObjectConstResultChild.h" 14 #include "lldb/Core/DataExtractor.h" 15 #include "lldb/Core/Module.h" 16 #include "lldb/Core/ValueObjectDynamicValue.h" 17 #include "lldb/Core/ValueObjectList.h" 18 19 #include "lldb/Symbol/CompilerType.h" 20 #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 29 using namespace lldb; 30 using namespace lldb_private; 31 32 ValueObjectSP 33 ValueObjectConstResult::Create (ExecutionContextScope *exe_scope, 34 ByteOrder byte_order, 35 uint32_t addr_byte_size, 36 lldb::addr_t address) 37 { 38 return (new ValueObjectConstResult (exe_scope, 39 byte_order, 40 addr_byte_size, 41 address))->GetSP(); 42 } 43 44 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope, 45 ByteOrder byte_order, 46 uint32_t addr_byte_size, 47 lldb::addr_t address) : 48 ValueObject (exe_scope), 49 m_type_name (), 50 m_byte_size (0), 51 m_impl(this, address) 52 { 53 SetIsConstant (); 54 SetValueIsValid(true); 55 m_data.SetByteOrder(byte_order); 56 m_data.SetAddressByteSize(addr_byte_size); 57 SetAddressTypeOfChildren(eAddressTypeLoad); 58 } 59 60 ValueObjectSP 61 ValueObjectConstResult::Create 62 ( 63 ExecutionContextScope *exe_scope, 64 const CompilerType &compiler_type, 65 const ConstString &name, 66 const DataExtractor &data, 67 lldb::addr_t address 68 ) 69 { 70 return (new ValueObjectConstResult (exe_scope, 71 compiler_type, 72 name, 73 data, 74 address))->GetSP(); 75 } 76 77 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope, 78 const CompilerType &compiler_type, 79 const ConstString &name, 80 const DataExtractor &data, 81 lldb::addr_t address) : 82 ValueObject (exe_scope), 83 m_type_name (), 84 m_byte_size (0), 85 m_impl(this, address) 86 { 87 m_data = data; 88 89 if (!m_data.GetSharedDataBuffer()) 90 { 91 DataBufferSP shared_data_buffer(new DataBufferHeap(data.GetDataStart(), data.GetByteSize())); 92 m_data.SetData(shared_data_buffer); 93 } 94 95 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart(); 96 m_value.SetValueType(Value::eValueTypeHostAddress); 97 m_value.SetCompilerType(compiler_type); 98 m_name = name; 99 SetIsConstant (); 100 SetValueIsValid(true); 101 SetAddressTypeOfChildren(eAddressTypeLoad); 102 } 103 104 ValueObjectSP 105 ValueObjectConstResult::Create (ExecutionContextScope *exe_scope, 106 const CompilerType &compiler_type, 107 const ConstString &name, 108 const lldb::DataBufferSP &data_sp, 109 lldb::ByteOrder data_byte_order, 110 uint32_t data_addr_size, 111 lldb::addr_t address) 112 { 113 return (new ValueObjectConstResult (exe_scope, 114 compiler_type, 115 name, 116 data_sp, 117 data_byte_order, 118 data_addr_size, 119 address))->GetSP(); 120 } 121 122 ValueObjectSP 123 ValueObjectConstResult::Create (ExecutionContextScope *exe_scope, 124 Value &value, 125 const ConstString &name, 126 Module *module) 127 { 128 return (new ValueObjectConstResult (exe_scope, value, name, module))->GetSP(); 129 } 130 131 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope, 132 const CompilerType &compiler_type, 133 const ConstString &name, 134 const lldb::DataBufferSP &data_sp, 135 lldb::ByteOrder data_byte_order, 136 uint32_t data_addr_size, 137 lldb::addr_t address) : 138 ValueObject (exe_scope), 139 m_type_name (), 140 m_byte_size (0), 141 m_impl(this, address) 142 { 143 m_data.SetByteOrder(data_byte_order); 144 m_data.SetAddressByteSize(data_addr_size); 145 m_data.SetData(data_sp); 146 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes(); 147 m_value.SetValueType(Value::eValueTypeHostAddress); 148 //m_value.SetContext(Value::eContextTypeClangType, compiler_type); 149 m_value.SetCompilerType (compiler_type); 150 m_name = name; 151 SetIsConstant (); 152 SetValueIsValid(true); 153 SetAddressTypeOfChildren(eAddressTypeLoad); 154 } 155 156 ValueObjectSP 157 ValueObjectConstResult::Create (ExecutionContextScope *exe_scope, 158 const CompilerType &compiler_type, 159 const ConstString &name, 160 lldb::addr_t address, 161 AddressType address_type, 162 uint32_t addr_byte_size) 163 { 164 return (new ValueObjectConstResult (exe_scope, 165 compiler_type, 166 name, 167 address, 168 address_type, 169 addr_byte_size))->GetSP(); 170 } 171 172 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope, 173 const CompilerType &compiler_type, 174 const ConstString &name, 175 lldb::addr_t address, 176 AddressType address_type, 177 uint32_t addr_byte_size) : 178 ValueObject (exe_scope), 179 m_type_name (), 180 m_byte_size (0), 181 m_impl(this, address) 182 { 183 m_value.GetScalar() = address; 184 m_data.SetAddressByteSize(addr_byte_size); 185 m_value.GetScalar().GetData (m_data, addr_byte_size); 186 //m_value.SetValueType(Value::eValueTypeHostAddress); 187 switch (address_type) 188 { 189 case eAddressTypeInvalid: m_value.SetValueType(Value::eValueTypeScalar); break; 190 case eAddressTypeFile: m_value.SetValueType(Value::eValueTypeFileAddress); break; 191 case eAddressTypeLoad: m_value.SetValueType(Value::eValueTypeLoadAddress); break; 192 case eAddressTypeHost: m_value.SetValueType(Value::eValueTypeHostAddress); break; 193 } 194 // m_value.SetContext(Value::eContextTypeClangType, compiler_type); 195 m_value.SetCompilerType (compiler_type); 196 m_name = name; 197 SetIsConstant (); 198 SetValueIsValid(true); 199 SetAddressTypeOfChildren(eAddressTypeLoad); 200 } 201 202 ValueObjectSP 203 ValueObjectConstResult::Create 204 ( 205 ExecutionContextScope *exe_scope, 206 const Error& error 207 ) 208 { 209 return (new ValueObjectConstResult (exe_scope, 210 error))->GetSP(); 211 } 212 213 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope, 214 const Error& error) : 215 ValueObject (exe_scope), 216 m_type_name (), 217 m_byte_size (0), 218 m_impl(this) 219 { 220 m_error = error; 221 SetIsConstant (); 222 } 223 224 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope, 225 const Value &value, 226 const ConstString &name, 227 Module *module) : 228 ValueObject (exe_scope), 229 m_type_name (), 230 m_byte_size (0), 231 m_impl(this) 232 { 233 m_value = value; 234 m_name = name; 235 ExecutionContext exe_ctx; 236 exe_scope->CalculateExecutionContext(exe_ctx); 237 m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, module); 238 } 239 240 ValueObjectConstResult::~ValueObjectConstResult() 241 { 242 } 243 244 CompilerType 245 ValueObjectConstResult::GetCompilerTypeImpl() 246 { 247 return m_value.GetCompilerType(); 248 } 249 250 lldb::ValueType 251 ValueObjectConstResult::GetValueType() const 252 { 253 return eValueTypeConstResult; 254 } 255 256 uint64_t 257 ValueObjectConstResult::GetByteSize() 258 { 259 ExecutionContext exe_ctx(GetExecutionContextRef()); 260 261 if (m_byte_size == 0) 262 SetByteSize(GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope())); 263 return m_byte_size; 264 } 265 266 void 267 ValueObjectConstResult::SetByteSize (size_t size) 268 { 269 m_byte_size = size; 270 } 271 272 size_t 273 ValueObjectConstResult::CalculateNumChildren(uint32_t max) 274 { 275 auto children_count = GetCompilerType().GetNumChildren (true); 276 return children_count <= max ? children_count : max; 277 } 278 279 ConstString 280 ValueObjectConstResult::GetTypeName() 281 { 282 if (m_type_name.IsEmpty()) 283 m_type_name = GetCompilerType().GetConstTypeName (); 284 return m_type_name; 285 } 286 287 ConstString 288 ValueObjectConstResult::GetDisplayTypeName() 289 { 290 return GetCompilerType().GetDisplayTypeName(); 291 } 292 293 bool 294 ValueObjectConstResult::UpdateValue () 295 { 296 // Const value is always valid 297 SetValueIsValid (true); 298 return true; 299 } 300 301 302 bool 303 ValueObjectConstResult::IsInScope () 304 { 305 // A const result value is always in scope since it serializes all 306 // information needed to contain the constant value. 307 return true; 308 } 309 310 lldb::ValueObjectSP 311 ValueObjectConstResult::Dereference (Error &error) 312 { 313 return m_impl.Dereference(error); 314 } 315 316 lldb::ValueObjectSP 317 ValueObjectConstResult::GetSyntheticChildAtOffset(uint32_t offset, 318 const CompilerType& type, 319 bool can_create, 320 ConstString name_const_str) 321 { 322 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create, name_const_str); 323 } 324 325 lldb::ValueObjectSP 326 ValueObjectConstResult::AddressOf (Error &error) 327 { 328 return m_impl.AddressOf(error); 329 } 330 331 lldb::addr_t 332 ValueObjectConstResult::GetAddressOf (bool scalar_is_load_address, 333 AddressType *address_type) 334 { 335 return m_impl.GetAddressOf(scalar_is_load_address, address_type); 336 } 337 338 ValueObject * 339 ValueObjectConstResult::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index) 340 { 341 return m_impl.CreateChildAtIndex(idx, synthetic_array_member, synthetic_index); 342 } 343 344 size_t 345 ValueObjectConstResult::GetPointeeData (DataExtractor& data, 346 uint32_t item_idx, 347 uint32_t item_count) 348 { 349 return m_impl.GetPointeeData(data, item_idx, item_count); 350 } 351 352 lldb::ValueObjectSP 353 ValueObjectConstResult::GetDynamicValue (lldb::DynamicValueType use_dynamic) 354 { 355 // Always recalculate dynamic values for const results as the memory that 356 // they might point to might have changed at any time. 357 if (use_dynamic != eNoDynamicValues) 358 { 359 if (!IsDynamic()) 360 { 361 ExecutionContext exe_ctx (GetExecutionContextRef()); 362 Process *process = exe_ctx.GetProcessPtr(); 363 if (process && process->IsPossibleDynamicValue(*this)) 364 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic); 365 } 366 if (m_dynamic_value) 367 return m_dynamic_value->GetSP(); 368 } 369 return ValueObjectSP(); 370 } 371 372 lldb::ValueObjectSP 373 ValueObjectConstResult::Cast (const CompilerType &compiler_type) 374 { 375 return m_impl.Cast(compiler_type); 376 } 377 378 lldb::LanguageType 379 ValueObjectConstResult::GetPreferredDisplayLanguage () 380 { 381 if (m_preferred_display_language != lldb::eLanguageTypeUnknown) 382 return m_preferred_display_language; 383 return GetCompilerTypeImpl().GetMinimumLanguage(); 384 } 385