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