LLDB  mainline
ValueObjectCast.cpp
Go to the documentation of this file.
1 //===-- ValueObjectCast.cpp -----------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 #include "lldb/Core/Value.h"
12 #include "lldb/Core/ValueObject.h"
15 #include "lldb/Utility/Scalar.h"
16 #include "lldb/Utility/Status.h"
17 
18 namespace lldb_private {
19 class ConstString;
20 }
21 
22 using namespace lldb_private;
23 
24 lldb::ValueObjectSP ValueObjectCast::Create(ValueObject &parent,
25  ConstString name,
26  const CompilerType &cast_type) {
27  ValueObjectCast *cast_valobj_ptr =
28  new ValueObjectCast(parent, name, cast_type);
29  return cast_valobj_ptr->GetSP();
30 }
31 
33  const CompilerType &cast_type)
34  : ValueObject(parent), m_cast_type(cast_type) {
35  SetName(name);
36  m_value.SetCompilerType(cast_type);
37 }
38 
40 
42 
45  auto children_count = GetCompilerType().GetNumChildren(
46  true, &exe_ctx);
47  return children_count <= max ? children_count : max;
48 }
49 
50 llvm::Optional<uint64_t> ValueObjectCast::GetByteSize() {
52  return m_value.GetValueByteSize(nullptr, &exe_ctx);
53 }
54 
56  // Let our parent answer global, local, argument, etc...
57  return m_parent->GetValueType();
58 }
59 
61  SetValueIsValid(false);
62  m_error.Clear();
63 
64  if (m_parent->UpdateValueIfNeeded(false)) {
65  Value old_value(m_value);
68  CompilerType compiler_type(GetCompilerType());
69  m_value.SetCompilerType(compiler_type);
71  if (!CanProvideValue()) {
72  // this value object represents an aggregate type whose children have
73  // values, but this object does not. So we say we are changed if our
74  // location has changed.
76  m_value.GetScalar() != old_value.GetScalar());
77  }
79  m_error = m_value.GetValueAsData(&exe_ctx, m_data, GetModule().get());
81  return true;
82  }
83 
84  // The dynamic value failed to get an error, pass the error along
85  if (m_error.Success() && m_parent->GetError().Fail())
87  SetValueIsValid(false);
88  return false;
89 }
90 
lldb_private::ValueObjectCast::UpdateValue
bool UpdateValue() override
Definition: ValueObjectCast.cpp:60
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
Scalar.h
lldb_private::ValueObject::IsInScope
virtual bool IsInScope()
Definition: ValueObject.h:420
lldb_private::ValueObject::CanProvideValue
virtual bool CanProvideValue()
Definition: ValueObject.cpp:3103
lldb_private::ValueObject::SetValueIsValid
void SetValueIsValid(bool valid)
Definition: ValueObject.h:980
lldb_private::ValueObject::GetValue
const Value & GetValue() const
Definition: ValueObject.h:497
lldb_private::Value
Definition: Value.h:38
lldb_private::Value::GetValueAsData
Status GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, Module *module)
Definition: Value.cpp:301
lldb_private::Value::GetValueType
ValueType GetValueType() const
Definition: Value.cpp:109
lldb_private::ValueObject::EvaluationPoint::SetUpdated
void SetUpdated()
Definition: ValueObject.cpp:2922
lldb_private::ValueObject::GetValueDidChange
bool GetValueDidChange()
Definition: ValueObject.h:549
lldb_private::ValueObjectCast::Create
static lldb::ValueObjectSP Create(ValueObject &parent, ConstString name, const CompilerType &cast_type)
Definition: ValueObjectCast.cpp:24
lldb_private::ValueObject::SetValueDidChange
void SetValueDidChange(bool value_changed)
Definition: ValueObject.h:976
lldb_private::ValueObjectCast::GetByteSize
llvm::Optional< uint64_t > GetByteSize() override
Definition: ValueObjectCast.cpp:50
lldb_private::ValueObject::GetError
const Status & GetError()
Definition: ValueObject.cpp:283
lldb_private::Value::SetCompilerType
void SetCompilerType(const CompilerType &compiler_type)
Definition: Value.cpp:254
lldb_private::ValueObject::m_data
DataExtractor m_data
A data extractor that can be used to extract the value.
Definition: ValueObject.h:851
lldb_private::Value::GetScalar
const Scalar & GetScalar() const
Definition: Value.h:112
lldb_private::Status::Success
bool Success() const
Test for success condition.
Definition: Status.cpp:288
lldb_private::ValueObjectCast::ValueObjectCast
ValueObjectCast(ValueObject &parent, ConstString name, const CompilerType &cast_type)
Definition: ValueObjectCast.cpp:32
lldb_private::ValueObject::GetSP
lldb::ValueObjectSP GetSP()
Definition: ValueObject.h:555
lldb_private::ValueObject::SetAddressTypeOfChildren
void SetAddressTypeOfChildren(AddressType at)
Definition: ValueObject.h:759
lldb_private::ValueObjectCast
A ValueObject that represents a given value represented as a different type.
Definition: ValueObjectCast.h:25
lldb_private::Status::Fail
bool Fail() const
Test for error condition.
Definition: Status.cpp:182
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::ValueObject::UpdateValueIfNeeded
bool UpdateValueIfNeeded(bool update_format=true)
Definition: ValueObject.cpp:111
lldb_private::ValueObjectCast::GetValueType
lldb::ValueType GetValueType() const override
Definition: ValueObjectCast.cpp:55
ValueObjectCast.h
lldb_private::ValueObject::GetExecutionContextRef
const ExecutionContextRef & GetExecutionContextRef() const
Definition: ValueObject.h:330
lldb_private::ValueObjectCast::m_cast_type
CompilerType m_cast_type
Definition: ValueObjectCast.h:57
CompilerType.h
lldb_private::ValueObject::SetName
void SetName(ConstString name)
Change the name of the current ValueObject.
Definition: ValueObject.h:560
ValueObject.h
lldb_private::CompilerType::GetNumChildren
uint32_t GetNumChildren(bool omit_empty_base_classes, const ExecutionContext *exe_ctx) const
Definition: CompilerType.cpp:515
lldb_private::ValueObjectCast::IsInScope
bool IsInScope() override
Definition: ValueObjectCast.cpp:91
lldb_private::ValueObject::GetValueType
virtual lldb::ValueType GetValueType() const =0
lldb_private::ValueObjectCast::GetCompilerTypeImpl
CompilerType GetCompilerTypeImpl() override
Definition: ValueObjectCast.cpp:41
lldb_private::ValueObject::m_update_point
EvaluationPoint m_update_point
Stores both the stop id and the full context at which this value was last updated.
Definition: ValueObject.h:847
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
lldb::ValueType
ValueType
Definition: lldb-enumerations.h:315
uint32_t
lldb_private::ValueObject::m_value
Value m_value
Definition: ValueObject.h:852
lldb_private::ValueObject::m_parent
ValueObject * m_parent
The parent value object, or nullptr if this has no parent.
Definition: ValueObject.h:840
lldb_private::ValueObject::GetCompilerType
CompilerType GetCompilerType()
Definition: ValueObject.h:352
lldb_private::ValueObject::GetModule
virtual lldb::ModuleSP GetModule()
Return the module associated with this value object in case the value is from an executable file and ...
Definition: ValueObject.cpp:3024
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
Status.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ValueObjectCast::CalculateNumChildren
size_t CalculateNumChildren(uint32_t max) override
Should only be called by ValueObject::GetNumChildren().
Definition: ValueObjectCast.cpp:43
lldb_private::Status::Clear
void Clear()
Clear the object state.
Definition: Status.cpp:168
lldb_private::Value::GetValueByteSize
uint64_t GetValueByteSize(Status *error_ptr, ExecutionContext *exe_ctx)
Definition: Value.cpp:197
lldb_private::ValueObject::m_error
Status m_error
An error object that can describe any errors that occur when updating values.
Definition: ValueObject.h:855
lldb_private::ValueObjectCast::~ValueObjectCast
~ValueObjectCast() override
Value.h
ExecutionContext.h
lldb_private::ValueObject::GetAddressTypeOfChildren
AddressType GetAddressTypeOfChildren()
Definition: ValueObject.cpp:3050