1435933ddSDimitry Andric //===-- ValueObjectCast.cpp -------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
10ac7ddfbfSEd Maste #include "lldb/Core/ValueObjectCast.h"
11ac7ddfbfSEd Maste
12ac7ddfbfSEd Maste #include "lldb/Core/Value.h"
13ac7ddfbfSEd Maste #include "lldb/Core/ValueObject.h"
149f2f44ceSEd Maste #include "lldb/Symbol/CompilerType.h"
15ac7ddfbfSEd Maste #include "lldb/Target/ExecutionContext.h"
16*b5893f02SDimitry Andric #include "lldb/Utility/Scalar.h"
17*b5893f02SDimitry Andric #include "lldb/Utility/Status.h"
18f678e45dSDimitry Andric
19f678e45dSDimitry Andric namespace lldb_private {
20f678e45dSDimitry Andric class ConstString;
21f678e45dSDimitry Andric }
22ac7ddfbfSEd Maste
23ac7ddfbfSEd Maste using namespace lldb_private;
24ac7ddfbfSEd Maste
Create(ValueObject & parent,const ConstString & name,const CompilerType & cast_type)25435933ddSDimitry Andric lldb::ValueObjectSP ValueObjectCast::Create(ValueObject &parent,
26ac7ddfbfSEd Maste const ConstString &name,
27435933ddSDimitry Andric const CompilerType &cast_type) {
28435933ddSDimitry Andric ValueObjectCast *cast_valobj_ptr =
29435933ddSDimitry Andric new ValueObjectCast(parent, name, cast_type);
30ac7ddfbfSEd Maste return cast_valobj_ptr->GetSP();
31ac7ddfbfSEd Maste }
32ac7ddfbfSEd Maste
ValueObjectCast(ValueObject & parent,const ConstString & name,const CompilerType & cast_type)33435933ddSDimitry Andric ValueObjectCast::ValueObjectCast(ValueObject &parent, const ConstString &name,
34435933ddSDimitry Andric const CompilerType &cast_type)
35435933ddSDimitry Andric : ValueObject(parent), m_cast_type(cast_type) {
36ac7ddfbfSEd Maste SetName(name);
37435933ddSDimitry Andric // m_value.SetContext (Value::eContextTypeClangType,
38435933ddSDimitry Andric // cast_type.GetOpaqueQualType());
399f2f44ceSEd Maste m_value.SetCompilerType(cast_type);
40ac7ddfbfSEd Maste }
41ac7ddfbfSEd Maste
~ValueObjectCast()42435933ddSDimitry Andric ValueObjectCast::~ValueObjectCast() {}
43ac7ddfbfSEd Maste
GetCompilerTypeImpl()44435933ddSDimitry Andric CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; }
45ac7ddfbfSEd Maste
CalculateNumChildren(uint32_t max)46435933ddSDimitry Andric size_t ValueObjectCast::CalculateNumChildren(uint32_t max) {
47*b5893f02SDimitry Andric ExecutionContext exe_ctx(GetExecutionContextRef());
48*b5893f02SDimitry Andric auto children_count = GetCompilerType().GetNumChildren(
49*b5893f02SDimitry Andric true, &exe_ctx);
509f2f44ceSEd Maste return children_count <= max ? children_count : max;
51ac7ddfbfSEd Maste }
52ac7ddfbfSEd Maste
GetByteSize()53435933ddSDimitry Andric uint64_t ValueObjectCast::GetByteSize() {
549f2f44ceSEd Maste ExecutionContext exe_ctx(GetExecutionContextRef());
559f2f44ceSEd Maste return m_value.GetValueByteSize(nullptr, &exe_ctx);
56ac7ddfbfSEd Maste }
57ac7ddfbfSEd Maste
GetValueType() const58435933ddSDimitry Andric lldb::ValueType ValueObjectCast::GetValueType() const {
59ac7ddfbfSEd Maste // Let our parent answer global, local, argument, etc...
60ac7ddfbfSEd Maste return m_parent->GetValueType();
61ac7ddfbfSEd Maste }
62ac7ddfbfSEd Maste
UpdateValue()63435933ddSDimitry Andric bool ValueObjectCast::UpdateValue() {
64ac7ddfbfSEd Maste SetValueIsValid(false);
65ac7ddfbfSEd Maste m_error.Clear();
66ac7ddfbfSEd Maste
67435933ddSDimitry Andric if (m_parent->UpdateValueIfNeeded(false)) {
68ac7ddfbfSEd Maste Value old_value(m_value);
69ac7ddfbfSEd Maste m_update_point.SetUpdated();
70ac7ddfbfSEd Maste m_value = m_parent->GetValue();
719f2f44ceSEd Maste CompilerType compiler_type(GetCompilerType());
729f2f44ceSEd Maste // m_value.SetContext (Value::eContextTypeClangType, compiler_type);
739f2f44ceSEd Maste m_value.SetCompilerType(compiler_type);
74ac7ddfbfSEd Maste SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren());
75435933ddSDimitry Andric if (!CanProvideValue()) {
764ba319b5SDimitry Andric // this value object represents an aggregate type whose children have
774ba319b5SDimitry Andric // values, but this object does not. So we say we are changed if our
784ba319b5SDimitry Andric // location has changed.
79435933ddSDimitry Andric SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() ||
80435933ddSDimitry Andric m_value.GetScalar() != old_value.GetScalar());
81ac7ddfbfSEd Maste }
82ac7ddfbfSEd Maste ExecutionContext exe_ctx(GetExecutionContextRef());
83ac7ddfbfSEd Maste m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get());
84ac7ddfbfSEd Maste SetValueDidChange(m_parent->GetValueDidChange());
85ac7ddfbfSEd Maste return true;
86ac7ddfbfSEd Maste }
87ac7ddfbfSEd Maste
88ac7ddfbfSEd Maste // The dynamic value failed to get an error, pass the error along
89ac7ddfbfSEd Maste if (m_error.Success() && m_parent->GetError().Fail())
90ac7ddfbfSEd Maste m_error = m_parent->GetError();
91ac7ddfbfSEd Maste SetValueIsValid(false);
92ac7ddfbfSEd Maste return false;
93ac7ddfbfSEd Maste }
94ac7ddfbfSEd Maste
IsInScope()95435933ddSDimitry Andric bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); }
96