blob: 5aa2446127afa40bfd9d7b90e98258157f51d53d [file] [log] [blame]
Kate Stoneb9c1b512016-09-06 20:57:50 +00001//===-- ValueObjectDynamicValue.cpp ---------------------------------*- C++
2//-*-===//
Enrico Granata21fd13f2012-10-27 02:05:48 +00003//
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
Enrico Granata21fd13f2012-10-27 02:05:48 +000011#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"
Enrico Granata21fd13f2012-10-27 02:05:48 +000019#include "lldb/Core/Value.h"
20#include "lldb/Core/ValueObject.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000021#include "lldb/Core/ValueObjectList.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000022
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
Kate Stoneb9c1b512016-09-06 20:57:50 +000037lldb::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();
Enrico Granata21fd13f2012-10-27 02:05:48 +000043}
44
Kate Stoneb9c1b512016-09-06 20:57:50 +000045ValueObjectCast::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);
Enrico Granata21fd13f2012-10-27 02:05:48 +000052}
53
Kate Stoneb9c1b512016-09-06 20:57:50 +000054ValueObjectCast::~ValueObjectCast() {}
55
56CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; }
57
58size_t ValueObjectCast::CalculateNumChildren(uint32_t max) {
59 auto children_count = GetCompilerType().GetNumChildren(true);
60 return children_count <= max ? children_count : max;
Enrico Granata21fd13f2012-10-27 02:05:48 +000061}
62
Kate Stoneb9c1b512016-09-06 20:57:50 +000063uint64_t ValueObjectCast::GetByteSize() {
64 ExecutionContext exe_ctx(GetExecutionContextRef());
65 return m_value.GetValueByteSize(nullptr, &exe_ctx);
Enrico Granata21fd13f2012-10-27 02:05:48 +000066}
67
Kate Stoneb9c1b512016-09-06 20:57:50 +000068lldb::ValueType ValueObjectCast::GetValueType() const {
69 // Let our parent answer global, local, argument, etc...
70 return m_parent->GetValueType();
Enrico Granata21fd13f2012-10-27 02:05:48 +000071}
72
Kate Stoneb9c1b512016-09-06 20:57:50 +000073bool ValueObjectCast::UpdateValue() {
74 SetValueIsValid(false);
75 m_error.Clear();
Enrico Granata21fd13f2012-10-27 02:05:48 +000076
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 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());
Enrico Granata21fd13f2012-10-27 02:05:48 +000091 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000092 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;
Enrico Granata21fd13f2012-10-27 02:05:48 +0000103}
104
Kate Stoneb9c1b512016-09-06 20:57:50 +0000105bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); }