2016-11-26 13:23:44 +08:00
|
|
|
//===-- ValueObjectCast.cpp -------------------------------------*- C++ -*-===//
|
2012-10-27 10:05:48 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Core/ValueObjectCast.h"
|
|
|
|
|
|
|
|
#include "lldb/Core/Value.h"
|
|
|
|
#include "lldb/Core/ValueObject.h"
|
2015-08-12 06:53:00 +08:00
|
|
|
#include "lldb/Symbol/CompilerType.h"
|
2012-10-27 10:05:48 +08:00
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
2018-08-07 19:07:21 +08:00
|
|
|
#include "lldb/Utility/Scalar.h" // for operator!=, Scalar
|
2017-05-12 12:51:55 +08:00
|
|
|
#include "lldb/Utility/Status.h" // for Status
|
2017-04-07 05:28:29 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
class ConstString;
|
|
|
|
}
|
2012-10-27 10:05:48 +08:00
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::ValueObjectSP ValueObjectCast::Create(ValueObject &parent,
|
|
|
|
const ConstString &name,
|
|
|
|
const CompilerType &cast_type) {
|
|
|
|
ValueObjectCast *cast_valobj_ptr =
|
|
|
|
new ValueObjectCast(parent, name, cast_type);
|
|
|
|
return cast_valobj_ptr->GetSP();
|
2012-10-27 10:05:48 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ValueObjectCast::ValueObjectCast(ValueObject &parent, const ConstString &name,
|
|
|
|
const CompilerType &cast_type)
|
|
|
|
: ValueObject(parent), m_cast_type(cast_type) {
|
|
|
|
SetName(name);
|
|
|
|
// m_value.SetContext (Value::eContextTypeClangType,
|
|
|
|
// cast_type.GetOpaqueQualType());
|
|
|
|
m_value.SetCompilerType(cast_type);
|
2012-10-27 10:05:48 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ValueObjectCast::~ValueObjectCast() {}
|
2012-10-27 10:05:48 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; }
|
2012-10-27 10:05:48 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t ValueObjectCast::CalculateNumChildren(uint32_t max) {
|
2018-11-06 04:49:07 +08:00
|
|
|
ExecutionContext exe_ctx(GetExecutionContextRef());
|
|
|
|
auto children_count = GetCompilerType().GetNumChildren(
|
|
|
|
true, &exe_ctx);
|
2016-09-07 04:57:50 +08:00
|
|
|
return children_count <= max ? children_count : max;
|
2012-10-27 10:05:48 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint64_t ValueObjectCast::GetByteSize() {
|
|
|
|
ExecutionContext exe_ctx(GetExecutionContextRef());
|
|
|
|
return m_value.GetValueByteSize(nullptr, &exe_ctx);
|
2012-10-27 10:05:48 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::ValueType ValueObjectCast::GetValueType() const {
|
|
|
|
// Let our parent answer global, local, argument, etc...
|
|
|
|
return m_parent->GetValueType();
|
2012-10-27 10:05:48 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool ValueObjectCast::UpdateValue() {
|
|
|
|
SetValueIsValid(false);
|
|
|
|
m_error.Clear();
|
|
|
|
|
|
|
|
if (m_parent->UpdateValueIfNeeded(false)) {
|
|
|
|
Value old_value(m_value);
|
|
|
|
m_update_point.SetUpdated();
|
|
|
|
m_value = m_parent->GetValue();
|
|
|
|
CompilerType compiler_type(GetCompilerType());
|
|
|
|
// m_value.SetContext (Value::eContextTypeClangType, compiler_type);
|
|
|
|
m_value.SetCompilerType(compiler_type);
|
|
|
|
SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren());
|
|
|
|
if (!CanProvideValue()) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// this value object represents an aggregate type whose children have
|
|
|
|
// values, but this object does not. So we say we are changed if our
|
|
|
|
// location has changed.
|
2016-09-07 04:57:50 +08:00
|
|
|
SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() ||
|
|
|
|
m_value.GetScalar() != old_value.GetScalar());
|
2012-10-27 10:05:48 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
ExecutionContext exe_ctx(GetExecutionContextRef());
|
|
|
|
m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get());
|
|
|
|
SetValueDidChange(m_parent->GetValueDidChange());
|
|
|
|
return true;
|
|
|
|
}
|
2012-10-27 10:05:48 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// The dynamic value failed to get an error, pass the error along
|
|
|
|
if (m_error.Success() && m_parent->GetError().Fail())
|
|
|
|
m_error = m_parent->GetError();
|
|
|
|
SetValueIsValid(false);
|
|
|
|
return false;
|
2012-10-27 10:05:48 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); }
|