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() 274 { 275 return GetCompilerType().GetNumChildren (true); 276 } 277 278 ConstString 279 ValueObjectConstResult::GetTypeName() 280 { 281 if (m_type_name.IsEmpty()) 282 m_type_name = GetCompilerType().GetConstTypeName (); 283 return m_type_name; 284 } 285 286 ConstString 287 ValueObjectConstResult::GetDisplayTypeName() 288 { 289 return GetCompilerType().GetDisplayTypeName(); 290 } 291 292 bool 293 ValueObjectConstResult::UpdateValue () 294 { 295 // Const value is always valid 296 SetValueIsValid (true); 297 return true; 298 } 299 300 301 bool 302 ValueObjectConstResult::IsInScope () 303 { 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 } 308 309 lldb::ValueObjectSP 310 ValueObjectConstResult::Dereference (Error &error) 311 { 312 return m_impl.Dereference(error); 313 } 314 315 lldb::ValueObjectSP 316 ValueObjectConstResult::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create) 317 { 318 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create); 319 } 320 321 lldb::ValueObjectSP 322 ValueObjectConstResult::AddressOf (Error &error) 323 { 324 return m_impl.AddressOf(error); 325 } 326 327 lldb::addr_t 328 ValueObjectConstResult::GetAddressOf (bool scalar_is_load_address, 329 AddressType *address_type) 330 { 331 return m_impl.GetAddressOf(scalar_is_load_address, address_type); 332 } 333 334 ValueObject * 335 ValueObjectConstResult::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index) 336 { 337 return m_impl.CreateChildAtIndex(idx, synthetic_array_member, synthetic_index); 338 } 339 340 size_t 341 ValueObjectConstResult::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 } 347 348 lldb::ValueObjectSP 349 ValueObjectConstResult::GetDynamicValue (lldb::DynamicValueType use_dynamic) 350 { 351 // Always recalculate dynamic values for const results as the memory that 352 // they might point to might have changed at any time. 353 if (use_dynamic != eNoDynamicValues) 354 { 355 if (!IsDynamic()) 356 { 357 ExecutionContext exe_ctx (GetExecutionContextRef()); 358 Process *process = exe_ctx.GetProcessPtr(); 359 if (process && process->IsPossibleDynamicValue(*this)) 360 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic); 361 } 362 if (m_dynamic_value) 363 return m_dynamic_value->GetSP(); 364 } 365 return ValueObjectSP(); 366 } 367 368 lldb::ValueObjectSP 369 ValueObjectConstResult::Cast (const CompilerType &compiler_type) 370 { 371 return m_impl.Cast(compiler_type); 372 } 373 374 lldb::LanguageType 375 ValueObjectConstResult::GetPreferredDisplayLanguage () 376 { 377 return lldb::eLanguageTypeUnknown; 378 } 379