blob: c05d0395d9691bc2315781749566e8561ae868f7 [file] [log] [blame]
Enrico Granata21fd13f2012-10-27 02:05:48 +00001//===-- 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 Claytona1e5dc82015-08-11 22:53:00 +000023#include "lldb/Symbol/CompilerType.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000024#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 Granata21fd13f2012-10-27 02:05:48 +000030#include "lldb/Target/Process.h"
31#include "lldb/Target/RegisterContext.h"
32#include "lldb/Target/Target.h"
33#include "lldb/Target/Thread.h"
34
35using namespace lldb_private;
36
37lldb::ValueObjectSP
38ValueObjectCast::Create (ValueObject &parent,
39 const ConstString &name,
Greg Claytona1e5dc82015-08-11 22:53:00 +000040 const CompilerType &cast_type)
Enrico Granata21fd13f2012-10-27 02:05:48 +000041{
42 ValueObjectCast *cast_valobj_ptr = new ValueObjectCast (parent, name, cast_type);
43 return cast_valobj_ptr->GetSP();
44}
45
46ValueObjectCast::ValueObjectCast
47(
48 ValueObject &parent,
49 const ConstString &name,
Greg Claytona1e5dc82015-08-11 22:53:00 +000050 const CompilerType &cast_type
Enrico Granata21fd13f2012-10-27 02:05:48 +000051) :
52 ValueObject(parent),
53 m_cast_type (cast_type)
54{
55 SetName (name);
Greg Clayton57ee3062013-07-11 22:46:58 +000056 //m_value.SetContext (Value::eContextTypeClangType, cast_type.GetOpaqueQualType());
Greg Clayton99558cc42015-08-24 23:46:31 +000057 m_value.SetCompilerType (cast_type);
Enrico Granata21fd13f2012-10-27 02:05:48 +000058}
59
60ValueObjectCast::~ValueObjectCast()
61{
62}
63
Greg Claytona1e5dc82015-08-11 22:53:00 +000064CompilerType
Greg Clayton99558cc42015-08-24 23:46:31 +000065ValueObjectCast::GetCompilerTypeImpl ()
Enrico Granata21fd13f2012-10-27 02:05:48 +000066{
Greg Clayton57ee3062013-07-11 22:46:58 +000067 return m_cast_type;
Enrico Granata21fd13f2012-10-27 02:05:48 +000068}
69
Greg Claytonc7bece562013-01-25 18:06:21 +000070size_t
Enrico Granata21fd13f2012-10-27 02:05:48 +000071ValueObjectCast::CalculateNumChildren()
72{
Greg Clayton99558cc42015-08-24 23:46:31 +000073 return GetCompilerType().GetNumChildren (true);
Enrico Granata21fd13f2012-10-27 02:05:48 +000074}
75
Greg Claytonfaac1112013-03-14 18:31:44 +000076uint64_t
Enrico Granata21fd13f2012-10-27 02:05:48 +000077ValueObjectCast::GetByteSize()
78{
Greg Clayton57ee3062013-07-11 22:46:58 +000079 return m_value.GetValueByteSize(NULL);
Enrico Granata21fd13f2012-10-27 02:05:48 +000080}
81
82lldb::ValueType
83ValueObjectCast::GetValueType() const
84{
85 // Let our parent answer global, local, argument, etc...
86 return m_parent->GetValueType();
87}
88
89bool
90ValueObjectCast::UpdateValue ()
91{
92 SetValueIsValid (false);
93 m_error.Clear();
94
95 if (m_parent->UpdateValueIfNeeded(false))
96 {
97 Value old_value(m_value);
98 m_update_point.SetUpdated();
99 m_value = m_parent->GetValue();
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000100 CompilerType compiler_type (GetCompilerType());
101 //m_value.SetContext (Value::eContextTypeClangType, compiler_type);
102 m_value.SetCompilerType (compiler_type);
Enrico Granata21fd13f2012-10-27 02:05:48 +0000103 SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren());
Enrico Granatad07cfd32014-10-08 18:27:36 +0000104 if (!CanProvideValue())
Enrico Granata21fd13f2012-10-27 02:05:48 +0000105 {
106 // this value object represents an aggregate type whose
107 // children have values, but this object does not. So we
108 // say we are changed if our location has changed.
109 SetValueDidChange (m_value.GetValueType() != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar());
110 }
111 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Clayton57ee3062013-07-11 22:46:58 +0000112 m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get());
Enrico Granata21fd13f2012-10-27 02:05:48 +0000113 SetValueDidChange (m_parent->GetValueDidChange());
114 return true;
115 }
116
117 // The dynamic value failed to get an error, pass the error along
118 if (m_error.Success() && m_parent->GetError().Fail())
119 m_error = m_parent->GetError();
120 SetValueIsValid (false);
121 return false;
122}
123
124bool
125ValueObjectCast::IsInScope ()
126{
127 return m_parent->IsInScope();
128}