1 //===-- ValueObjectCast.cpp -------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/ValueObjectCast.h"
14 // Other libraries and framework includes
16 #include "lldb/Core/Log.h"
17 #include "lldb/Core/Module.h"
18 #include "lldb/Core/Value.h"
19 #include "lldb/Core/ValueObject.h"
20 #include "lldb/Core/ValueObjectList.h"
22 #include "lldb/Symbol/CompilerType.h"
23 #include "lldb/Symbol/ObjectFile.h"
24 #include "lldb/Symbol/SymbolContext.h"
25 #include "lldb/Symbol/Type.h"
26 #include "lldb/Symbol/Variable.h"
28 #include "lldb/Target/ExecutionContext.h"
29 #include "lldb/Target/Process.h"
30 #include "lldb/Target/RegisterContext.h"
31 #include "lldb/Target/Target.h"
32 #include "lldb/Target/Thread.h"
34 using namespace lldb_private;
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();
44 ValueObjectCast::ValueObjectCast(ValueObject &parent, const ConstString &name,
45 const CompilerType &cast_type)
46 : ValueObject(parent), m_cast_type(cast_type) {
48 // m_value.SetContext (Value::eContextTypeClangType,
49 // cast_type.GetOpaqueQualType());
50 m_value.SetCompilerType(cast_type);
53 ValueObjectCast::~ValueObjectCast() {}
55 CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; }
57 size_t ValueObjectCast::CalculateNumChildren(uint32_t max) {
58 auto children_count = GetCompilerType().GetNumChildren(true);
59 return children_count <= max ? children_count : max;
62 uint64_t ValueObjectCast::GetByteSize() {
63 ExecutionContext exe_ctx(GetExecutionContextRef());
64 return m_value.GetValueByteSize(nullptr, &exe_ctx);
67 lldb::ValueType ValueObjectCast::GetValueType() const {
68 // Let our parent answer global, local, argument, etc...
69 return m_parent->GetValueType();
72 bool ValueObjectCast::UpdateValue() {
73 SetValueIsValid(false);
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());
91 ExecutionContext exe_ctx(GetExecutionContextRef());
92 m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get());
93 SetValueDidChange(m_parent->GetValueDidChange());
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);
104 bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); }