1696bd635SAlexander Shaposhnikov //===-- ValueObjectCast.cpp -------------------------------------*- C++ -*-===// 221fd13f9SEnrico Granata // 321fd13f9SEnrico Granata // The LLVM Compiler Infrastructure 421fd13f9SEnrico Granata // 521fd13f9SEnrico Granata // This file is distributed under the University of Illinois Open Source 621fd13f9SEnrico Granata // License. See LICENSE.TXT for details. 721fd13f9SEnrico Granata // 821fd13f9SEnrico Granata //===----------------------------------------------------------------------===// 921fd13f9SEnrico Granata 1021fd13f9SEnrico Granata #include "lldb/Core/ValueObjectCast.h" 1121fd13f9SEnrico Granata 12*2f3df613SZachary Turner #include "lldb/Core/Scalar.h" // for operator!=, Scalar 1321fd13f9SEnrico Granata #include "lldb/Core/Value.h" 1421fd13f9SEnrico Granata #include "lldb/Core/ValueObject.h" 15a1e5dc86SGreg Clayton #include "lldb/Symbol/CompilerType.h" 1621fd13f9SEnrico Granata #include "lldb/Target/ExecutionContext.h" 17*2f3df613SZachary Turner #include "lldb/Utility/Error.h" // for Error 18*2f3df613SZachary Turner 19*2f3df613SZachary Turner namespace lldb_private { 20*2f3df613SZachary Turner class ConstString; 21*2f3df613SZachary Turner } 2221fd13f9SEnrico Granata 2321fd13f9SEnrico Granata using namespace lldb_private; 2421fd13f9SEnrico Granata 25b9c1b51eSKate Stone lldb::ValueObjectSP ValueObjectCast::Create(ValueObject &parent, 2621fd13f9SEnrico Granata const ConstString &name, 27b9c1b51eSKate Stone const CompilerType &cast_type) { 28b9c1b51eSKate Stone ValueObjectCast *cast_valobj_ptr = 29b9c1b51eSKate Stone new ValueObjectCast(parent, name, cast_type); 3021fd13f9SEnrico Granata return cast_valobj_ptr->GetSP(); 3121fd13f9SEnrico Granata } 3221fd13f9SEnrico Granata 33b9c1b51eSKate Stone ValueObjectCast::ValueObjectCast(ValueObject &parent, const ConstString &name, 34b9c1b51eSKate Stone const CompilerType &cast_type) 35b9c1b51eSKate Stone : ValueObject(parent), m_cast_type(cast_type) { 3621fd13f9SEnrico Granata SetName(name); 37b9c1b51eSKate Stone // m_value.SetContext (Value::eContextTypeClangType, 38b9c1b51eSKate Stone // cast_type.GetOpaqueQualType()); 3999558cc4SGreg Clayton m_value.SetCompilerType(cast_type); 4021fd13f9SEnrico Granata } 4121fd13f9SEnrico Granata 42b9c1b51eSKate Stone ValueObjectCast::~ValueObjectCast() {} 4321fd13f9SEnrico Granata 44b9c1b51eSKate Stone CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; } 4521fd13f9SEnrico Granata 46b9c1b51eSKate Stone size_t ValueObjectCast::CalculateNumChildren(uint32_t max) { 479ac7a6c5SSiva Chandra auto children_count = GetCompilerType().GetNumChildren(true); 489ac7a6c5SSiva Chandra return children_count <= max ? children_count : max; 4921fd13f9SEnrico Granata } 5021fd13f9SEnrico Granata 51b9c1b51eSKate Stone uint64_t ValueObjectCast::GetByteSize() { 5295438038SEnrico Granata ExecutionContext exe_ctx(GetExecutionContextRef()); 5395438038SEnrico Granata return m_value.GetValueByteSize(nullptr, &exe_ctx); 5421fd13f9SEnrico Granata } 5521fd13f9SEnrico Granata 56b9c1b51eSKate Stone lldb::ValueType ValueObjectCast::GetValueType() const { 5721fd13f9SEnrico Granata // Let our parent answer global, local, argument, etc... 5821fd13f9SEnrico Granata return m_parent->GetValueType(); 5921fd13f9SEnrico Granata } 6021fd13f9SEnrico Granata 61b9c1b51eSKate Stone bool ValueObjectCast::UpdateValue() { 6221fd13f9SEnrico Granata SetValueIsValid(false); 6321fd13f9SEnrico Granata m_error.Clear(); 6421fd13f9SEnrico Granata 65b9c1b51eSKate Stone if (m_parent->UpdateValueIfNeeded(false)) { 6621fd13f9SEnrico Granata Value old_value(m_value); 6721fd13f9SEnrico Granata m_update_point.SetUpdated(); 6821fd13f9SEnrico Granata m_value = m_parent->GetValue(); 693ad353f3SBruce Mitchener CompilerType compiler_type(GetCompilerType()); 703ad353f3SBruce Mitchener // m_value.SetContext (Value::eContextTypeClangType, compiler_type); 713ad353f3SBruce Mitchener m_value.SetCompilerType(compiler_type); 7221fd13f9SEnrico Granata SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren()); 73b9c1b51eSKate Stone if (!CanProvideValue()) { 7421fd13f9SEnrico Granata // this value object represents an aggregate type whose 7521fd13f9SEnrico Granata // children have values, but this object does not. So we 7621fd13f9SEnrico Granata // say we are changed if our location has changed. 77b9c1b51eSKate Stone SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() || 78b9c1b51eSKate Stone m_value.GetScalar() != old_value.GetScalar()); 7921fd13f9SEnrico Granata } 8021fd13f9SEnrico Granata ExecutionContext exe_ctx(GetExecutionContextRef()); 8157ee3067SGreg Clayton m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get()); 8221fd13f9SEnrico Granata SetValueDidChange(m_parent->GetValueDidChange()); 8321fd13f9SEnrico Granata return true; 8421fd13f9SEnrico Granata } 8521fd13f9SEnrico Granata 8621fd13f9SEnrico Granata // The dynamic value failed to get an error, pass the error along 8721fd13f9SEnrico Granata if (m_error.Success() && m_parent->GetError().Fail()) 8821fd13f9SEnrico Granata m_error = m_parent->GetError(); 8921fd13f9SEnrico Granata SetValueIsValid(false); 9021fd13f9SEnrico Granata return false; 9121fd13f9SEnrico Granata } 9221fd13f9SEnrico Granata 93b9c1b51eSKate Stone bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); } 94