1 //===-- ValueObjectDynamicValue.cpp ---------------------------------*- C++
2 //-*-===//
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 
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/Value.h"
20 #include "lldb/Core/ValueObject.h"
21 #include "lldb/Core/ValueObjectList.h"
22 
23 #include "lldb/Symbol/CompilerType.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/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 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();
43 }
44 
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);
52 }
53 
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;
61 }
62 
63 uint64_t ValueObjectCast::GetByteSize() {
64   ExecutionContext exe_ctx(GetExecutionContextRef());
65   return m_value.GetValueByteSize(nullptr, &exe_ctx);
66 }
67 
68 lldb::ValueType ValueObjectCast::GetValueType() const {
69   // Let our parent answer global, local, argument, etc...
70   return m_parent->GetValueType();
71 }
72 
73 bool ValueObjectCast::UpdateValue() {
74   SetValueIsValid(false);
75   m_error.Clear();
76 
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());
91     }
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;
103 }
104 
105 bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); }
106