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 | |
| 23 | #include "lldb/Symbol/ClangASTType.h" |
| 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" |
| 30 | #include "lldb/Target/LanguageRuntime.h" |
| 31 | #include "lldb/Target/Process.h" |
| 32 | #include "lldb/Target/RegisterContext.h" |
| 33 | #include "lldb/Target/Target.h" |
| 34 | #include "lldb/Target/Thread.h" |
| 35 | |
| 36 | using namespace lldb_private; |
| 37 | |
| 38 | lldb::ValueObjectSP |
| 39 | ValueObjectCast::Create (ValueObject &parent, |
| 40 | const ConstString &name, |
| 41 | const ClangASTType &cast_type) |
| 42 | { |
| 43 | ValueObjectCast *cast_valobj_ptr = new ValueObjectCast (parent, name, cast_type); |
| 44 | return cast_valobj_ptr->GetSP(); |
| 45 | } |
| 46 | |
| 47 | ValueObjectCast::ValueObjectCast |
| 48 | ( |
| 49 | ValueObject &parent, |
| 50 | const ConstString &name, |
| 51 | const ClangASTType &cast_type |
| 52 | ) : |
| 53 | ValueObject(parent), |
| 54 | m_cast_type (cast_type) |
| 55 | { |
| 56 | SetName (name); |
| 57 | m_value.SetContext (Value::eContextTypeClangType, cast_type.GetOpaqueQualType()); |
| 58 | } |
| 59 | |
| 60 | ValueObjectCast::~ValueObjectCast() |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | lldb::clang_type_t |
| 65 | ValueObjectCast::GetClangTypeImpl () |
| 66 | { |
| 67 | return m_cast_type.GetOpaqueQualType(); |
| 68 | } |
| 69 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 70 | size_t |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 71 | ValueObjectCast::CalculateNumChildren() |
| 72 | { |
| 73 | return ClangASTContext::GetNumChildren (GetClangAST (), GetClangType(), true); |
| 74 | } |
| 75 | |
| 76 | clang::ASTContext * |
| 77 | ValueObjectCast::GetClangASTImpl () |
| 78 | { |
| 79 | return m_cast_type.GetASTContext(); |
| 80 | } |
| 81 | |
Greg Clayton | faac111 | 2013-03-14 18:31:44 +0000 | [diff] [blame^] | 82 | uint64_t |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 83 | ValueObjectCast::GetByteSize() |
| 84 | { |
| 85 | return m_value.GetValueByteSize(GetClangAST(), NULL); |
| 86 | } |
| 87 | |
| 88 | lldb::ValueType |
| 89 | ValueObjectCast::GetValueType() const |
| 90 | { |
| 91 | // Let our parent answer global, local, argument, etc... |
| 92 | return m_parent->GetValueType(); |
| 93 | } |
| 94 | |
| 95 | bool |
| 96 | ValueObjectCast::UpdateValue () |
| 97 | { |
| 98 | SetValueIsValid (false); |
| 99 | m_error.Clear(); |
| 100 | |
| 101 | if (m_parent->UpdateValueIfNeeded(false)) |
| 102 | { |
| 103 | Value old_value(m_value); |
| 104 | m_update_point.SetUpdated(); |
| 105 | m_value = m_parent->GetValue(); |
| 106 | m_value.SetContext (Value::eContextTypeClangType, GetClangType()); |
| 107 | SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren()); |
| 108 | if (ClangASTContext::IsAggregateType (GetClangType())) |
| 109 | { |
| 110 | // this value object represents an aggregate type whose |
| 111 | // children have values, but this object does not. So we |
| 112 | // say we are changed if our location has changed. |
| 113 | SetValueDidChange (m_value.GetValueType() != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar()); |
| 114 | } |
| 115 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 116 | m_error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), m_data, 0, GetModule().get()); |
| 117 | SetValueDidChange (m_parent->GetValueDidChange()); |
| 118 | return true; |
| 119 | } |
| 120 | |
| 121 | // The dynamic value failed to get an error, pass the error along |
| 122 | if (m_error.Success() && m_parent->GetError().Fail()) |
| 123 | m_error = m_parent->GetError(); |
| 124 | SetValueIsValid (false); |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | bool |
| 129 | ValueObjectCast::IsInScope () |
| 130 | { |
| 131 | return m_parent->IsInScope(); |
| 132 | } |