1696bd635SAlexander Shaposhnikov //===-- ValueObjectCast.cpp -------------------------------------*- C++ -*-===// 221fd13f9SEnrico Granata // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 621fd13f9SEnrico Granata // 721fd13f9SEnrico Granata //===----------------------------------------------------------------------===// 821fd13f9SEnrico Granata 921fd13f9SEnrico Granata #include "lldb/Core/ValueObjectCast.h" 1021fd13f9SEnrico Granata 1121fd13f9SEnrico Granata #include "lldb/Core/Value.h" 1221fd13f9SEnrico Granata #include "lldb/Core/ValueObject.h" 13a1e5dc86SGreg Clayton #include "lldb/Symbol/CompilerType.h" 1421fd13f9SEnrico Granata #include "lldb/Target/ExecutionContext.h" 15672d2c12SJonas Devlieghere #include "lldb/Utility/Scalar.h" 16672d2c12SJonas Devlieghere #include "lldb/Utility/Status.h" 172f3df613SZachary Turner 182f3df613SZachary Turner namespace lldb_private { 192f3df613SZachary Turner class ConstString; 202f3df613SZachary Turner } 2121fd13f9SEnrico Granata 2221fd13f9SEnrico Granata using namespace lldb_private; 2321fd13f9SEnrico Granata 24b9c1b51eSKate Stone lldb::ValueObjectSP ValueObjectCast::Create(ValueObject &parent, 250e4c4821SAdrian Prantl ConstString name, 26b9c1b51eSKate Stone const CompilerType &cast_type) { 27b9c1b51eSKate Stone ValueObjectCast *cast_valobj_ptr = 28b9c1b51eSKate Stone new ValueObjectCast(parent, name, cast_type); 2921fd13f9SEnrico Granata return cast_valobj_ptr->GetSP(); 3021fd13f9SEnrico Granata } 3121fd13f9SEnrico Granata 320e4c4821SAdrian Prantl ValueObjectCast::ValueObjectCast(ValueObject &parent, ConstString name, 33b9c1b51eSKate Stone const CompilerType &cast_type) 34b9c1b51eSKate Stone : ValueObject(parent), m_cast_type(cast_type) { 3521fd13f9SEnrico Granata SetName(name); 36b9c1b51eSKate Stone // m_value.SetContext (Value::eContextTypeClangType, 37b9c1b51eSKate Stone // cast_type.GetOpaqueQualType()); 3899558cc4SGreg Clayton m_value.SetCompilerType(cast_type); 3921fd13f9SEnrico Granata } 4021fd13f9SEnrico Granata 41b9c1b51eSKate Stone ValueObjectCast::~ValueObjectCast() {} 4221fd13f9SEnrico Granata 43b9c1b51eSKate Stone CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; } 4421fd13f9SEnrico Granata 45b9c1b51eSKate Stone size_t ValueObjectCast::CalculateNumChildren(uint32_t max) { 46eca07c59SAdrian Prantl ExecutionContext exe_ctx(GetExecutionContextRef()); 47eca07c59SAdrian Prantl auto children_count = GetCompilerType().GetNumChildren( 48eca07c59SAdrian Prantl true, &exe_ctx); 499ac7a6c5SSiva Chandra return children_count <= max ? children_count : max; 5021fd13f9SEnrico Granata } 5121fd13f9SEnrico Granata 52b9c1b51eSKate Stone uint64_t ValueObjectCast::GetByteSize() { 5395438038SEnrico Granata ExecutionContext exe_ctx(GetExecutionContextRef()); 5495438038SEnrico Granata return m_value.GetValueByteSize(nullptr, &exe_ctx); 5521fd13f9SEnrico Granata } 5621fd13f9SEnrico Granata 57b9c1b51eSKate Stone lldb::ValueType ValueObjectCast::GetValueType() const { 5821fd13f9SEnrico Granata // Let our parent answer global, local, argument, etc... 5921fd13f9SEnrico Granata return m_parent->GetValueType(); 6021fd13f9SEnrico Granata } 6121fd13f9SEnrico Granata 62b9c1b51eSKate Stone bool ValueObjectCast::UpdateValue() { 6321fd13f9SEnrico Granata SetValueIsValid(false); 6421fd13f9SEnrico Granata m_error.Clear(); 6521fd13f9SEnrico Granata 66b9c1b51eSKate Stone if (m_parent->UpdateValueIfNeeded(false)) { 6721fd13f9SEnrico Granata Value old_value(m_value); 6821fd13f9SEnrico Granata m_update_point.SetUpdated(); 6921fd13f9SEnrico Granata m_value = m_parent->GetValue(); 703ad353f3SBruce Mitchener CompilerType compiler_type(GetCompilerType()); 713ad353f3SBruce Mitchener // m_value.SetContext (Value::eContextTypeClangType, compiler_type); 723ad353f3SBruce Mitchener m_value.SetCompilerType(compiler_type); 7321fd13f9SEnrico Granata SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren()); 74b9c1b51eSKate Stone if (!CanProvideValue()) { 7505097246SAdrian Prantl // this value object represents an aggregate type whose children have 7605097246SAdrian Prantl // values, but this object does not. So we say we are changed if our 7705097246SAdrian Prantl // location has changed. 78b9c1b51eSKate Stone SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() || 79b9c1b51eSKate Stone m_value.GetScalar() != old_value.GetScalar()); 8021fd13f9SEnrico Granata } 8121fd13f9SEnrico Granata ExecutionContext exe_ctx(GetExecutionContextRef()); 82*d9cbd2acSAdrian Prantl m_error = m_value.GetValueAsData(&exe_ctx, m_data, GetModule().get()); 8321fd13f9SEnrico Granata SetValueDidChange(m_parent->GetValueDidChange()); 8421fd13f9SEnrico Granata return true; 8521fd13f9SEnrico Granata } 8621fd13f9SEnrico Granata 8721fd13f9SEnrico Granata // The dynamic value failed to get an error, pass the error along 8821fd13f9SEnrico Granata if (m_error.Success() && m_parent->GetError().Fail()) 8921fd13f9SEnrico Granata m_error = m_parent->GetError(); 9021fd13f9SEnrico Granata SetValueIsValid(false); 9121fd13f9SEnrico Granata return false; 9221fd13f9SEnrico Granata } 9321fd13f9SEnrico Granata 94b9c1b51eSKate Stone bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); } 95