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