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 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Module.h" |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Value.h" |
| 18 | #include "lldb/Core/ValueObject.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 19 | #include "lldb/Core/ValueObjectList.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 20 | #include "lldb/Utility/Log.h" |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 21 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 22 | #include "lldb/Symbol/CompilerType.h" |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 23 | #include "lldb/Symbol/ObjectFile.h" |
| 24 | #include "lldb/Symbol/SymbolContext.h" |
| 25 | #include "lldb/Symbol/Type.h" |
| 26 | #include "lldb/Symbol/Variable.h" |
| 27 | |
| 28 | #include "lldb/Target/ExecutionContext.h" |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 29 | #include "lldb/Target/Process.h" |
| 30 | #include "lldb/Target/RegisterContext.h" |
| 31 | #include "lldb/Target/Target.h" |
| 32 | #include "lldb/Target/Thread.h" |
| 33 | |
| 34 | using namespace lldb_private; |
| 35 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 36 | lldb::ValueObjectSP ValueObjectCast::Create(ValueObject &parent, |
| 37 | const ConstString &name, |
| 38 | const CompilerType &cast_type) { |
| 39 | ValueObjectCast *cast_valobj_ptr = |
| 40 | new ValueObjectCast(parent, name, cast_type); |
| 41 | return cast_valobj_ptr->GetSP(); |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 44 | ValueObjectCast::ValueObjectCast(ValueObject &parent, const ConstString &name, |
| 45 | const CompilerType &cast_type) |
| 46 | : ValueObject(parent), m_cast_type(cast_type) { |
| 47 | SetName(name); |
| 48 | // m_value.SetContext (Value::eContextTypeClangType, |
| 49 | // cast_type.GetOpaqueQualType()); |
| 50 | m_value.SetCompilerType(cast_type); |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 53 | ValueObjectCast::~ValueObjectCast() {} |
| 54 | |
| 55 | CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; } |
| 56 | |
| 57 | size_t ValueObjectCast::CalculateNumChildren(uint32_t max) { |
| 58 | auto children_count = GetCompilerType().GetNumChildren(true); |
| 59 | return children_count <= max ? children_count : max; |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | uint64_t ValueObjectCast::GetByteSize() { |
| 63 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 64 | return m_value.GetValueByteSize(nullptr, &exe_ctx); |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 67 | lldb::ValueType ValueObjectCast::GetValueType() const { |
| 68 | // Let our parent answer global, local, argument, etc... |
| 69 | return m_parent->GetValueType(); |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | bool ValueObjectCast::UpdateValue() { |
| 73 | SetValueIsValid(false); |
| 74 | m_error.Clear(); |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 75 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 76 | if (m_parent->UpdateValueIfNeeded(false)) { |
| 77 | Value old_value(m_value); |
| 78 | m_update_point.SetUpdated(); |
| 79 | m_value = m_parent->GetValue(); |
| 80 | CompilerType compiler_type(GetCompilerType()); |
| 81 | // m_value.SetContext (Value::eContextTypeClangType, compiler_type); |
| 82 | m_value.SetCompilerType(compiler_type); |
| 83 | SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren()); |
| 84 | if (!CanProvideValue()) { |
| 85 | // this value object represents an aggregate type whose |
| 86 | // children have values, but this object does not. So we |
| 87 | // say we are changed if our location has changed. |
| 88 | SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() || |
| 89 | m_value.GetScalar() != old_value.GetScalar()); |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 90 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 91 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 92 | m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get()); |
| 93 | SetValueDidChange(m_parent->GetValueDidChange()); |
| 94 | return true; |
| 95 | } |
| 96 | |
| 97 | // The dynamic value failed to get an error, pass the error along |
| 98 | if (m_error.Success() && m_parent->GetError().Fail()) |
| 99 | m_error = m_parent->GetError(); |
| 100 | SetValueIsValid(false); |
| 101 | return false; |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 104 | bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); } |