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/ClangASTType.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 ClangASTType &clang_type, 65 const ConstString &name, 66 const DataExtractor &data, 67 lldb::addr_t address 68 ) 69 { 70 return (new ValueObjectConstResult (exe_scope, 71 clang_type, 72 name, 73 data, 74 address))->GetSP(); 75 } 76 77 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope, 78 const ClangASTType &clang_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.SetClangType(clang_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 ClangASTType &clang_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 clang_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 ClangASTType &clang_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, clang_type); 149 m_value.SetClangType (clang_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 ClangASTType &clang_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 clang_type, 166 name, 167 address, 168 address_type, 169 addr_byte_size))->GetSP(); 170 } 171 172 ValueObjectConstResult::ValueObjectConstResult (ExecutionContextScope *exe_scope, 173 const ClangASTType &clang_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, clang_type); 195 m_value.SetClangType (clang_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 ClangASTType 245 ValueObjectConstResult::GetClangTypeImpl() 246 { 247 return m_value.GetClangType(); 248 } 249 250 lldb::ValueType 251 ValueObjectConstResult::GetValueType() const 252 { 253 return eValueTypeConstResult; 254 } 255 256 uint64_t 257 ValueObjectConstResult::GetByteSize() 258 { 259 if (m_byte_size == 0) 260 m_byte_size = GetClangType().GetByteSize(); 261 return m_byte_size; 262 } 263 264 void 265 ValueObjectConstResult::SetByteSize (size_t size) 266 { 267 m_byte_size = size; 268 } 269 270 size_t 271 ValueObjectConstResult::CalculateNumChildren() 272 { 273 return GetClangType().GetNumChildren (true); 274 } 275 276 ConstString 277 ValueObjectConstResult::GetTypeName() 278 { 279 if (m_type_name.IsEmpty()) 280 m_type_name = GetClangType().GetConstTypeName (); 281 return m_type_name; 282 } 283 284 ConstString 285 ValueObjectConstResult::GetDisplayTypeName() 286 { 287 return GetClangType().GetDisplayTypeName(); 288 } 289 290 bool 291 ValueObjectConstResult::UpdateValue () 292 { 293 // Const value is always valid 294 SetValueIsValid (true); 295 return true; 296 } 297 298 299 bool 300 ValueObjectConstResult::IsInScope () 301 { 302 // A const result value is always in scope since it serializes all 303 // information needed to contain the constant value. 304 return true; 305 } 306 307 lldb::ValueObjectSP 308 ValueObjectConstResult::Dereference (Error &error) 309 { 310 return m_impl.Dereference(error); 311 } 312 313 lldb::ValueObjectSP 314 ValueObjectConstResult::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create) 315 { 316 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create); 317 } 318 319 lldb::ValueObjectSP 320 ValueObjectConstResult::AddressOf (Error &error) 321 { 322 return m_impl.AddressOf(error); 323 } 324 325 lldb::addr_t 326 ValueObjectConstResult::GetAddressOf (bool scalar_is_load_address, 327 AddressType *address_type) 328 { 329 return m_impl.GetAddressOf(scalar_is_load_address, address_type); 330 } 331 332 ValueObject * 333 ValueObjectConstResult::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index) 334 { 335 return m_impl.CreateChildAtIndex(idx, synthetic_array_member, synthetic_index); 336 } 337 338 size_t 339 ValueObjectConstResult::GetPointeeData (DataExtractor& data, 340 uint32_t item_idx, 341 uint32_t item_count) 342 { 343 return m_impl.GetPointeeData(data, item_idx, item_count); 344 } 345 346 lldb::ValueObjectSP 347 ValueObjectConstResult::GetDynamicValue (lldb::DynamicValueType use_dynamic) 348 { 349 // Always recalculate dynamic values for const results as the memory that 350 // they might point to might have changed at any time. 351 if (use_dynamic != eNoDynamicValues) 352 { 353 if (!IsDynamic()) 354 { 355 ExecutionContext exe_ctx (GetExecutionContextRef()); 356 Process *process = exe_ctx.GetProcessPtr(); 357 if (process && process->IsPossibleDynamicValue(*this)) 358 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic); 359 } 360 if (m_dynamic_value) 361 return m_dynamic_value->GetSP(); 362 } 363 return ValueObjectSP(); 364 } 365 366 lldb::LanguageType 367 ValueObjectConstResult::GetPreferredDisplayLanguage () 368 { 369 return lldb::eLanguageTypeUnknown; 370 } 371