1 //===-- ValueObjectCast.cpp -------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/ValueObjectCast.h"
11 #include "lldb/Core/Value.h"
12 #include "lldb/Core/ValueObject.h"
13 #include "lldb/Symbol/CompilerType.h"
14 #include "lldb/Target/ExecutionContext.h"
15 #include "lldb/Utility/Scalar.h"
16 #include "lldb/Utility/Status.h"
18 namespace lldb_private {
22 using namespace lldb_private;
24 lldb::ValueObjectSP ValueObjectCast::Create(ValueObject &parent,
26 const CompilerType &cast_type) {
27 ValueObjectCast *cast_valobj_ptr =
28 new ValueObjectCast(parent, name, cast_type);
29 return cast_valobj_ptr->GetSP();
32 ValueObjectCast::ValueObjectCast(ValueObject &parent, ConstString name,
33 const CompilerType &cast_type)
34 : ValueObject(parent), m_cast_type(cast_type) {
36 // m_value.SetContext (Value::eContextTypeClangType,
37 // cast_type.GetOpaqueQualType());
38 m_value.SetCompilerType(cast_type);
41 ValueObjectCast::~ValueObjectCast() {}
43 CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; }
45 size_t ValueObjectCast::CalculateNumChildren(uint32_t max) {
46 ExecutionContext exe_ctx(GetExecutionContextRef());
47 auto children_count = GetCompilerType().GetNumChildren(
49 return children_count <= max ? children_count : max;
52 uint64_t ValueObjectCast::GetByteSize() {
53 ExecutionContext exe_ctx(GetExecutionContextRef());
54 return m_value.GetValueByteSize(nullptr, &exe_ctx);
57 lldb::ValueType ValueObjectCast::GetValueType() const {
58 // Let our parent answer global, local, argument, etc...
59 return m_parent->GetValueType();
62 bool ValueObjectCast::UpdateValue() {
63 SetValueIsValid(false);
66 if (m_parent->UpdateValueIfNeeded(false)) {
67 Value old_value(m_value);
68 m_update_point.SetUpdated();
69 m_value = m_parent->GetValue();
70 CompilerType compiler_type(GetCompilerType());
71 // m_value.SetContext (Value::eContextTypeClangType, compiler_type);
72 m_value.SetCompilerType(compiler_type);
73 SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren());
74 if (!CanProvideValue()) {
75 // this value object represents an aggregate type whose children have
76 // values, but this object does not. So we say we are changed if our
77 // location has changed.
78 SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() ||
79 m_value.GetScalar() != old_value.GetScalar());
81 ExecutionContext exe_ctx(GetExecutionContextRef());
82 m_error = m_value.GetValueAsData(&exe_ctx, m_data, GetModule().get());
83 SetValueDidChange(m_parent->GetValueDidChange());
87 // The dynamic value failed to get an error, pass the error along
88 if (m_error.Success() && m_parent->GetError().Fail())
89 m_error = m_parent->GetError();
90 SetValueIsValid(false);
94 bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); }