blob: f6ec026e079124c6c97c6b4aed357ccb41ad73a5 [file] [log] [blame]
Alexander Shaposhnikov696bd632016-11-26 05:23:44 +00001//===-- ValueObjectCast.cpp -------------------------------------*- C++ -*-===//
Enrico Granata21fd13f2012-10-27 02:05:48 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Enrico Granata21fd13f2012-10-27 02:05:48 +000010#include "lldb/Core/ValueObjectCast.h"
11
Enrico Granata21fd13f2012-10-27 02:05:48 +000012#include "lldb/Core/Value.h"
13#include "lldb/Core/ValueObject.h"
Greg Claytona1e5dc82015-08-11 22:53:00 +000014#include "lldb/Symbol/CompilerType.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000015#include "lldb/Target/ExecutionContext.h"
Pavel Labathd821c992018-08-07 11:07:21 +000016#include "lldb/Utility/Scalar.h" // for operator!=, Scalar
Zachary Turner97206d52017-05-12 04:51:55 +000017#include "lldb/Utility/Status.h" // for Status
Zachary Turner2f3df612017-04-06 21:28:29 +000018
19namespace lldb_private {
20class ConstString;
21}
Enrico Granata21fd13f2012-10-27 02:05:48 +000022
23using namespace lldb_private;
24
Kate Stoneb9c1b512016-09-06 20:57:50 +000025lldb::ValueObjectSP ValueObjectCast::Create(ValueObject &parent,
26 const ConstString &name,
27 const CompilerType &cast_type) {
28 ValueObjectCast *cast_valobj_ptr =
29 new ValueObjectCast(parent, name, cast_type);
30 return cast_valobj_ptr->GetSP();
Enrico Granata21fd13f2012-10-27 02:05:48 +000031}
32
Kate Stoneb9c1b512016-09-06 20:57:50 +000033ValueObjectCast::ValueObjectCast(ValueObject &parent, const ConstString &name,
34 const CompilerType &cast_type)
35 : ValueObject(parent), m_cast_type(cast_type) {
36 SetName(name);
37 // m_value.SetContext (Value::eContextTypeClangType,
38 // cast_type.GetOpaqueQualType());
39 m_value.SetCompilerType(cast_type);
Enrico Granata21fd13f2012-10-27 02:05:48 +000040}
41
Kate Stoneb9c1b512016-09-06 20:57:50 +000042ValueObjectCast::~ValueObjectCast() {}
43
44CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; }
45
46size_t ValueObjectCast::CalculateNumChildren(uint32_t max) {
47 auto children_count = GetCompilerType().GetNumChildren(true);
48 return children_count <= max ? children_count : max;
Enrico Granata21fd13f2012-10-27 02:05:48 +000049}
50
Kate Stoneb9c1b512016-09-06 20:57:50 +000051uint64_t ValueObjectCast::GetByteSize() {
52 ExecutionContext exe_ctx(GetExecutionContextRef());
53 return m_value.GetValueByteSize(nullptr, &exe_ctx);
Enrico Granata21fd13f2012-10-27 02:05:48 +000054}
55
Kate Stoneb9c1b512016-09-06 20:57:50 +000056lldb::ValueType ValueObjectCast::GetValueType() const {
57 // Let our parent answer global, local, argument, etc...
58 return m_parent->GetValueType();
Enrico Granata21fd13f2012-10-27 02:05:48 +000059}
60
Kate Stoneb9c1b512016-09-06 20:57:50 +000061bool ValueObjectCast::UpdateValue() {
62 SetValueIsValid(false);
63 m_error.Clear();
Enrico Granata21fd13f2012-10-27 02:05:48 +000064
Kate Stoneb9c1b512016-09-06 20:57:50 +000065 if (m_parent->UpdateValueIfNeeded(false)) {
66 Value old_value(m_value);
67 m_update_point.SetUpdated();
68 m_value = m_parent->GetValue();
69 CompilerType compiler_type(GetCompilerType());
70 // m_value.SetContext (Value::eContextTypeClangType, compiler_type);
71 m_value.SetCompilerType(compiler_type);
72 SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren());
73 if (!CanProvideValue()) {
Adrian Prantl05097242018-04-30 16:49:04 +000074 // this value object represents an aggregate type whose children have
75 // values, but this object does not. So we say we are changed if our
76 // location has changed.
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() ||
78 m_value.GetScalar() != old_value.GetScalar());
Enrico Granata21fd13f2012-10-27 02:05:48 +000079 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000080 ExecutionContext exe_ctx(GetExecutionContextRef());
81 m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get());
82 SetValueDidChange(m_parent->GetValueDidChange());
83 return true;
84 }
85
86 // The dynamic value failed to get an error, pass the error along
87 if (m_error.Success() && m_parent->GetError().Fail())
88 m_error = m_parent->GetError();
89 SetValueIsValid(false);
90 return false;
Enrico Granata21fd13f2012-10-27 02:05:48 +000091}
92
Kate Stoneb9c1b512016-09-06 20:57:50 +000093bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); }