Alexander Shaposhnikov | 696bd63 | 2016-11-26 05:23:44 +0000 | [diff] [blame] | 1 | //===-- ValueObjectCast.cpp -------------------------------------*- C++ -*-===// |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 2 | // |
| 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 Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 10 | #include "lldb/Core/ValueObjectCast.h" |
| 11 | |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Value.h" |
| 13 | #include "lldb/Core/ValueObject.h" |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 14 | #include "lldb/Symbol/CompilerType.h" |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 15 | #include "lldb/Target/ExecutionContext.h" |
Pavel Labath | d821c99 | 2018-08-07 11:07:21 +0000 | [diff] [blame] | 16 | #include "lldb/Utility/Scalar.h" // for operator!=, Scalar |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 17 | #include "lldb/Utility/Status.h" // for Status |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 18 | |
| 19 | namespace lldb_private { |
| 20 | class ConstString; |
| 21 | } |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace lldb_private; |
| 24 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 25 | lldb::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 Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 33 | ValueObjectCast::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 Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 42 | ValueObjectCast::~ValueObjectCast() {} |
| 43 | |
| 44 | CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; } |
| 45 | |
| 46 | size_t ValueObjectCast::CalculateNumChildren(uint32_t max) { |
| 47 | auto children_count = GetCompilerType().GetNumChildren(true); |
| 48 | return children_count <= max ? children_count : max; |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | uint64_t ValueObjectCast::GetByteSize() { |
| 52 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 53 | return m_value.GetValueByteSize(nullptr, &exe_ctx); |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | lldb::ValueType ValueObjectCast::GetValueType() const { |
| 57 | // Let our parent answer global, local, argument, etc... |
| 58 | return m_parent->GetValueType(); |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | bool ValueObjectCast::UpdateValue() { |
| 62 | SetValueIsValid(false); |
| 63 | m_error.Clear(); |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 64 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | 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 Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 74 | // 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 Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() || |
| 78 | m_value.GetScalar() != old_value.GetScalar()); |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 79 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | 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 Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 93 | bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); } |