Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 1 | //===-- ValueObjectDynamicValue.cpp ---------------------------------*- C++ -*-===// |
| 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 | |
| 10 | |
| 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" |
| 19 | #include "lldb/Core/ValueObjectList.h" |
| 20 | #include "lldb/Core/Value.h" |
| 21 | #include "lldb/Core/ValueObject.h" |
| 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 | |
| 37 | lldb::ValueObjectSP |
| 38 | ValueObjectCast::Create (ValueObject &parent, |
| 39 | const ConstString &name, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 40 | const CompilerType &cast_type) |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 41 | { |
| 42 | ValueObjectCast *cast_valobj_ptr = new ValueObjectCast (parent, name, cast_type); |
| 43 | return cast_valobj_ptr->GetSP(); |
| 44 | } |
| 45 | |
| 46 | ValueObjectCast::ValueObjectCast |
| 47 | ( |
| 48 | ValueObject &parent, |
| 49 | const ConstString &name, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 50 | const CompilerType &cast_type |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 51 | ) : |
| 52 | ValueObject(parent), |
| 53 | m_cast_type (cast_type) |
| 54 | { |
| 55 | SetName (name); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 56 | //m_value.SetContext (Value::eContextTypeClangType, cast_type.GetOpaqueQualType()); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 57 | m_value.SetCompilerType (cast_type); |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | ValueObjectCast::~ValueObjectCast() |
| 61 | { |
| 62 | } |
| 63 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 64 | CompilerType |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 65 | ValueObjectCast::GetCompilerTypeImpl () |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 66 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 67 | return m_cast_type; |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 70 | size_t |
Siva Chandra | 9ac7a6c | 2015-10-21 19:28:08 +0000 | [diff] [blame] | 71 | ValueObjectCast::CalculateNumChildren(uint32_t max) |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 72 | { |
Siva Chandra | 9ac7a6c | 2015-10-21 19:28:08 +0000 | [diff] [blame] | 73 | auto children_count = GetCompilerType().GetNumChildren (true); |
| 74 | return children_count <= max ? children_count : max; |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Greg Clayton | faac111 | 2013-03-14 18:31:44 +0000 | [diff] [blame] | 77 | uint64_t |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 78 | ValueObjectCast::GetByteSize() |
| 79 | { |
Enrico Granata | 9543803 | 2015-10-14 22:44:30 +0000 | [diff] [blame] | 80 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 81 | return m_value.GetValueByteSize(nullptr, &exe_ctx); |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | lldb::ValueType |
| 85 | ValueObjectCast::GetValueType() const |
| 86 | { |
| 87 | // Let our parent answer global, local, argument, etc... |
| 88 | return m_parent->GetValueType(); |
| 89 | } |
| 90 | |
| 91 | bool |
| 92 | ValueObjectCast::UpdateValue () |
| 93 | { |
| 94 | SetValueIsValid (false); |
| 95 | m_error.Clear(); |
| 96 | |
| 97 | if (m_parent->UpdateValueIfNeeded(false)) |
| 98 | { |
| 99 | Value old_value(m_value); |
| 100 | m_update_point.SetUpdated(); |
| 101 | m_value = m_parent->GetValue(); |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 102 | CompilerType compiler_type (GetCompilerType()); |
| 103 | //m_value.SetContext (Value::eContextTypeClangType, compiler_type); |
| 104 | m_value.SetCompilerType (compiler_type); |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 105 | SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren()); |
Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 106 | if (!CanProvideValue()) |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 107 | { |
| 108 | // this value object represents an aggregate type whose |
| 109 | // children have values, but this object does not. So we |
| 110 | // say we are changed if our location has changed. |
| 111 | SetValueDidChange (m_value.GetValueType() != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar()); |
| 112 | } |
| 113 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 114 | m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get()); |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 115 | SetValueDidChange (m_parent->GetValueDidChange()); |
| 116 | return true; |
| 117 | } |
| 118 | |
| 119 | // The dynamic value failed to get an error, pass the error along |
| 120 | if (m_error.Success() && m_parent->GetError().Fail()) |
| 121 | m_error = m_parent->GetError(); |
| 122 | SetValueIsValid (false); |
| 123 | return false; |
| 124 | } |
| 125 | |
| 126 | bool |
| 127 | ValueObjectCast::IsInScope () |
| 128 | { |
| 129 | return m_parent->IsInScope(); |
| 130 | } |