blob: 9845b2fea1b7e847ce1a84a56640d2687f2613bf [file] [log] [blame]
Alexander Shaposhnikov696bd632016-11-26 05:23:44 +00001//===-- ValueObjectCast.cpp -------------------------------------*- C++ -*-===//
Enrico Granata21fd13f2012-10-27 02:05:48 +00002//
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
Enrico Granata21fd13f2012-10-27 02:05:48 +000010#include "lldb/Core/ValueObjectCast.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Enrico Granata21fd13f2012-10-27 02:05:48 +000016#include "lldb/Core/Module.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000017#include "lldb/Core/Value.h"
18#include "lldb/Core/ValueObject.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000019#include "lldb/Core/ValueObjectList.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000020#include "lldb/Utility/Log.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000021
Greg Claytona1e5dc82015-08-11 22:53:00 +000022#include "lldb/Symbol/CompilerType.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000023#include "lldb/Symbol/ObjectFile.h"
24#include "lldb/Symbol/SymbolContext.h"
25#include "lldb/Symbol/Type.h"
26#include "lldb/Symbol/Variable.h"
27
28#include "lldb/Target/ExecutionContext.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000029#include "lldb/Target/Process.h"
30#include "lldb/Target/RegisterContext.h"
31#include "lldb/Target/Target.h"
32#include "lldb/Target/Thread.h"
33
34using namespace lldb_private;
35
Kate Stoneb9c1b512016-09-06 20:57:50 +000036lldb::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();
Enrico Granata21fd13f2012-10-27 02:05:48 +000042}
43
Kate Stoneb9c1b512016-09-06 20:57:50 +000044ValueObjectCast::ValueObjectCast(ValueObject &parent, const ConstString &name,
45 const CompilerType &cast_type)
46 : ValueObject(parent), m_cast_type(cast_type) {
47 SetName(name);
48 // m_value.SetContext (Value::eContextTypeClangType,
49 // cast_type.GetOpaqueQualType());
50 m_value.SetCompilerType(cast_type);
Enrico Granata21fd13f2012-10-27 02:05:48 +000051}
52
Kate Stoneb9c1b512016-09-06 20:57:50 +000053ValueObjectCast::~ValueObjectCast() {}
54
55CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; }
56
57size_t ValueObjectCast::CalculateNumChildren(uint32_t max) {
58 auto children_count = GetCompilerType().GetNumChildren(true);
59 return children_count <= max ? children_count : max;
Enrico Granata21fd13f2012-10-27 02:05:48 +000060}
61
Kate Stoneb9c1b512016-09-06 20:57:50 +000062uint64_t ValueObjectCast::GetByteSize() {
63 ExecutionContext exe_ctx(GetExecutionContextRef());
64 return m_value.GetValueByteSize(nullptr, &exe_ctx);
Enrico Granata21fd13f2012-10-27 02:05:48 +000065}
66
Kate Stoneb9c1b512016-09-06 20:57:50 +000067lldb::ValueType ValueObjectCast::GetValueType() const {
68 // Let our parent answer global, local, argument, etc...
69 return m_parent->GetValueType();
Enrico Granata21fd13f2012-10-27 02:05:48 +000070}
71
Kate Stoneb9c1b512016-09-06 20:57:50 +000072bool ValueObjectCast::UpdateValue() {
73 SetValueIsValid(false);
74 m_error.Clear();
Enrico Granata21fd13f2012-10-27 02:05:48 +000075
Kate Stoneb9c1b512016-09-06 20:57:50 +000076 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());
Enrico Granata21fd13f2012-10-27 02:05:48 +000090 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000091 ExecutionContext exe_ctx(GetExecutionContextRef());
92 m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get());
93 SetValueDidChange(m_parent->GetValueDidChange());
94 return true;
95 }
96
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);
101 return false;
Enrico Granata21fd13f2012-10-27 02:05:48 +0000102}
103
Kate Stoneb9c1b512016-09-06 20:57:50 +0000104bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); }