1 //===-- ValueObjectCast.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/ValueObjectCast.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 #include "lldb/Core/Module.h" 17 #include "lldb/Core/Value.h" 18 #include "lldb/Core/ValueObject.h" 19 #include "lldb/Core/ValueObjectList.h" 20 #include "lldb/Utility/Log.h" 21 22 #include "lldb/Symbol/CompilerType.h" 23 #include "lldb/Symbol/ObjectFile.h" 24 #include "lldb/Symbol/SymbolContext.h" 25 #include "lldb/Symbol/Type.h" 26 #include "lldb/Symbol/Variable.h" 27 28 #include "lldb/Target/ExecutionContext.h" 29 #include "lldb/Target/Process.h" 30 #include "lldb/Target/RegisterContext.h" 31 #include "lldb/Target/Target.h" 32 #include "lldb/Target/Thread.h" 33 34 using namespace lldb_private; 35 36 lldb::ValueObjectSP ValueObjectCast::Create(ValueObject &parent, 37 const ConstString &name, 38 const CompilerType &cast_type) { 39 ValueObjectCast *cast_valobj_ptr = 40 new ValueObjectCast(parent, name, cast_type); 41 return cast_valobj_ptr->GetSP(); 42 } 43 44 ValueObjectCast::ValueObjectCast(ValueObject &parent, const ConstString &name, 45 const CompilerType &cast_type) 46 : ValueObject(parent), m_cast_type(cast_type) { 47 SetName(name); 48 // m_value.SetContext (Value::eContextTypeClangType, 49 // cast_type.GetOpaqueQualType()); 50 m_value.SetCompilerType(cast_type); 51 } 52 53 ValueObjectCast::~ValueObjectCast() {} 54 55 CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; } 56 57 size_t ValueObjectCast::CalculateNumChildren(uint32_t max) { 58 auto children_count = GetCompilerType().GetNumChildren(true); 59 return children_count <= max ? children_count : max; 60 } 61 62 uint64_t ValueObjectCast::GetByteSize() { 63 ExecutionContext exe_ctx(GetExecutionContextRef()); 64 return m_value.GetValueByteSize(nullptr, &exe_ctx); 65 } 66 67 lldb::ValueType ValueObjectCast::GetValueType() const { 68 // Let our parent answer global, local, argument, etc... 69 return m_parent->GetValueType(); 70 } 71 72 bool ValueObjectCast::UpdateValue() { 73 SetValueIsValid(false); 74 m_error.Clear(); 75 76 if (m_parent->UpdateValueIfNeeded(false)) { 77 Value old_value(m_value); 78 m_update_point.SetUpdated(); 79 m_value = m_parent->GetValue(); 80 CompilerType compiler_type(GetCompilerType()); 81 // m_value.SetContext (Value::eContextTypeClangType, compiler_type); 82 m_value.SetCompilerType(compiler_type); 83 SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren()); 84 if (!CanProvideValue()) { 85 // this value object represents an aggregate type whose 86 // children have values, but this object does not. So we 87 // say we are changed if our location has changed. 88 SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() || 89 m_value.GetScalar() != old_value.GetScalar()); 90 } 91 ExecutionContext exe_ctx(GetExecutionContextRef()); 92 m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get()); 93 SetValueDidChange(m_parent->GetValueDidChange()); 94 return true; 95 } 96 97 // The dynamic value failed to get an error, pass the error along 98 if (m_error.Success() && m_parent->GetError().Fail()) 99 m_error = m_parent->GetError(); 100 SetValueIsValid(false); 101 return false; 102 } 103 104 bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); } 105