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 uint32_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 uint32_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 uint32_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 uint32_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 case eAddressTypeInvalid: m_value.SetValueType(Value::eValueTypeScalar); break; 223 case eAddressTypeFile: m_value.SetValueType(Value::eValueTypeFileAddress); break; 224 case eAddressTypeLoad: m_value.SetValueType(Value::eValueTypeLoadAddress); break; 225 case eAddressTypeHost: m_value.SetValueType(Value::eValueTypeHostAddress); break; 226 } 227 m_value.SetContext(Value::eContextTypeClangType, clang_type); 228 m_name = name; 229 SetIsConstant (); 230 SetValueIsValid(true); 231 SetAddressTypeOfChildren(eAddressTypeLoad); 232 } 233 234 ValueObjectSP 235 ValueObjectConstResult::Create 236 ( 237 ExecutionContextScope *exe_scope, 238 const Error& error 239 ) 240 { 241 return (new ValueObjectConstResult (exe_scope, 242 error))->GetSP(); 243 } 244 245 ValueObjectConstResult::ValueObjectConstResult ( 246 ExecutionContextScope *exe_scope, 247 const Error& error) : 248 ValueObject (exe_scope), 249 m_clang_ast (NULL), 250 m_type_name (), 251 m_byte_size (0), 252 m_impl(this) 253 { 254 m_error = error; 255 SetIsConstant (); 256 } 257 258 ValueObjectConstResult::ValueObjectConstResult ( 259 ExecutionContextScope *exe_scope, 260 clang::ASTContext *clang_ast, 261 const Value &value, 262 const ConstString &name) : 263 ValueObject (exe_scope), 264 m_clang_ast (clang_ast), 265 m_type_name (), 266 m_byte_size (0), 267 m_impl(this) 268 { 269 m_value = value; 270 m_value.GetData(m_data); 271 } 272 273 ValueObjectConstResult::~ValueObjectConstResult() 274 { 275 } 276 277 lldb::clang_type_t 278 ValueObjectConstResult::GetClangTypeImpl() 279 { 280 return m_value.GetClangType(); 281 } 282 283 lldb::ValueType 284 ValueObjectConstResult::GetValueType() const 285 { 286 return eValueTypeConstResult; 287 } 288 289 uint64_t 290 ValueObjectConstResult::GetByteSize() 291 { 292 if (m_byte_size == 0) 293 m_byte_size = ClangASTType::GetTypeByteSize(GetClangAST(), GetClangType()); 294 return m_byte_size; 295 } 296 297 void 298 ValueObjectConstResult::SetByteSize (size_t size) 299 { 300 m_byte_size = size; 301 } 302 303 size_t 304 ValueObjectConstResult::CalculateNumChildren() 305 { 306 return ClangASTContext::GetNumChildren (GetClangAST (), GetClangType(), true); 307 } 308 309 clang::ASTContext * 310 ValueObjectConstResult::GetClangASTImpl () 311 { 312 return m_clang_ast; 313 } 314 315 ConstString 316 ValueObjectConstResult::GetTypeName() 317 { 318 if (m_type_name.IsEmpty()) 319 m_type_name = ClangASTType::GetConstTypeName (GetClangAST(), GetClangType()); 320 return m_type_name; 321 } 322 323 bool 324 ValueObjectConstResult::UpdateValue () 325 { 326 // Const value is always valid 327 SetValueIsValid (true); 328 return true; 329 } 330 331 332 bool 333 ValueObjectConstResult::IsInScope () 334 { 335 // A const result value is always in scope since it serializes all 336 // information needed to contain the constant value. 337 return true; 338 } 339 340 lldb::ValueObjectSP 341 ValueObjectConstResult::Dereference (Error &error) 342 { 343 return m_impl.Dereference(error); 344 } 345 346 lldb::ValueObjectSP 347 ValueObjectConstResult::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create) 348 { 349 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create); 350 } 351 352 lldb::ValueObjectSP 353 ValueObjectConstResult::AddressOf (Error &error) 354 { 355 return m_impl.AddressOf(error); 356 } 357 358 lldb::addr_t 359 ValueObjectConstResult::GetAddressOf (bool scalar_is_load_address, 360 AddressType *address_type) 361 { 362 return m_impl.GetAddressOf(scalar_is_load_address, address_type); 363 } 364 365 ValueObject * 366 ValueObjectConstResult::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index) 367 { 368 return m_impl.CreateChildAtIndex(idx, synthetic_array_member, synthetic_index); 369 } 370 371 size_t 372 ValueObjectConstResult::GetPointeeData (DataExtractor& data, 373 uint32_t item_idx, 374 uint32_t item_count) 375 { 376 return m_impl.GetPointeeData(data, item_idx, item_count); 377 } 378 379 lldb::ValueObjectSP 380 ValueObjectConstResult::GetDynamicValue (lldb::DynamicValueType use_dynamic) 381 { 382 // Always recalculate dynamic values for const results as the memory that 383 // they might point to might have changed at any time. 384 if (use_dynamic != eNoDynamicValues) 385 { 386 if (!IsDynamic()) 387 { 388 ExecutionContext exe_ctx (GetExecutionContextRef()); 389 Process *process = exe_ctx.GetProcessPtr(); 390 if (process && process->IsPossibleDynamicValue(*this)) 391 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic); 392 } 393 if (m_dynamic_value) 394 return m_dynamic_value->GetSP(); 395 } 396 return ValueObjectSP(); 397 } 398 399