Path: blob/main/contrib/llvm-project/lldb/source/ValueObject/ValueObjectCast.cpp
213764 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/ValueObject/ValueObjectCast.h"910#include "lldb/Core/Value.h"11#include "lldb/Symbol/CompilerType.h"12#include "lldb/Target/ExecutionContext.h"13#include "lldb/Utility/Scalar.h"14#include "lldb/Utility/Status.h"15#include "lldb/ValueObject/ValueObject.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(true, &exe_ctx);46if (!children_count)47return children_count;48return *children_count <= max ? *children_count : max;49}5051llvm::Expected<uint64_t> ValueObjectCast::GetByteSize() {52ExecutionContext exe_ctx(GetExecutionContextRef());53return m_value.GetValueByteSize(nullptr, &exe_ctx);54}5556lldb::ValueType ValueObjectCast::GetValueType() const {57// Let our parent answer global, local, argument, etc...58return m_parent->GetValueType();59}6061bool ValueObjectCast::UpdateValue() {62SetValueIsValid(false);63m_error.Clear();6465if (m_parent->UpdateValueIfNeeded(false)) {66Value old_value(m_value);67m_update_point.SetUpdated();68m_value = m_parent->GetValue();69CompilerType compiler_type(GetCompilerType());70m_value.SetCompilerType(compiler_type);71SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren());72if (!CanProvideValue()) {73// this value object represents an aggregate type whose children have74// values, but this object does not. So we say we are changed if our75// location has changed.76SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() ||77m_value.GetScalar() != old_value.GetScalar());78}79ExecutionContext exe_ctx(GetExecutionContextRef());80m_error = m_value.GetValueAsData(&exe_ctx, m_data, GetModule().get());81SetValueDidChange(m_parent->GetValueDidChange());82return true;83}8485// The dynamic value failed to get an error, pass the error along86if (m_error.Success() && m_parent->GetError().Fail())87m_error = m_parent->GetError().Clone();88SetValueIsValid(false);89return false;90}9192bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); }939495