Path: blob/main/contrib/llvm-project/lldb/source/Core/ValueObjectCast.cpp
39587 views
//===-- ValueObjectCast.cpp -----------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Core/ValueObjectCast.h"910#include "lldb/Core/Value.h"11#include "lldb/Core/ValueObject.h"12#include "lldb/Symbol/CompilerType.h"13#include "lldb/Target/ExecutionContext.h"14#include "lldb/Utility/Scalar.h"15#include "lldb/Utility/Status.h"16#include <optional>1718namespace lldb_private {19class ConstString;20}2122using namespace lldb_private;2324lldb::ValueObjectSP ValueObjectCast::Create(ValueObject &parent,25ConstString name,26const CompilerType &cast_type) {27ValueObjectCast *cast_valobj_ptr =28new ValueObjectCast(parent, name, cast_type);29return cast_valobj_ptr->GetSP();30}3132ValueObjectCast::ValueObjectCast(ValueObject &parent, ConstString name,33const CompilerType &cast_type)34: ValueObject(parent), m_cast_type(cast_type) {35SetName(name);36m_value.SetCompilerType(cast_type);37}3839ValueObjectCast::~ValueObjectCast() = default;4041CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; }4243llvm::Expected<uint32_t> ValueObjectCast::CalculateNumChildren(uint32_t max) {44ExecutionContext exe_ctx(GetExecutionContextRef());45auto children_count = GetCompilerType().GetNumChildren(46true, &exe_ctx);47if (!children_count)48return children_count;49return *children_count <= max ? *children_count : max;50}5152std::optional<uint64_t> ValueObjectCast::GetByteSize() {53ExecutionContext exe_ctx(GetExecutionContextRef());54return m_value.GetValueByteSize(nullptr, &exe_ctx);55}5657lldb::ValueType ValueObjectCast::GetValueType() const {58// Let our parent answer global, local, argument, etc...59return m_parent->GetValueType();60}6162bool ValueObjectCast::UpdateValue() {63SetValueIsValid(false);64m_error.Clear();6566if (m_parent->UpdateValueIfNeeded(false)) {67Value old_value(m_value);68m_update_point.SetUpdated();69m_value = m_parent->GetValue();70CompilerType compiler_type(GetCompilerType());71m_value.SetCompilerType(compiler_type);72SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren());73if (!CanProvideValue()) {74// this value object represents an aggregate type whose children have75// values, but this object does not. So we say we are changed if our76// location has changed.77SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() ||78m_value.GetScalar() != old_value.GetScalar());79}80ExecutionContext exe_ctx(GetExecutionContextRef());81m_error = m_value.GetValueAsData(&exe_ctx, m_data, GetModule().get());82SetValueDidChange(m_parent->GetValueDidChange());83return true;84}8586// The dynamic value failed to get an error, pass the error along87if (m_error.Success() && m_parent->GetError().Fail())88m_error = m_parent->GetError();89SetValueIsValid(false);90return false;91}9293bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); }949596