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"
14#include "lldb/Utility/Scalar.h"
15#include "lldb/Utility/Status.h"
17#include <optional>
18
19namespace lldb_private {
20class ConstString;
21}
22
23using namespace lldb_private;
24
26 ConstString name,
27 const CompilerType &cast_type) {
28 ValueObjectCast *cast_valobj_ptr =
29 new ValueObjectCast(parent, name, cast_type);
30 return cast_valobj_ptr->GetSP();
31}
32
34 const CompilerType &cast_type)
35 : ValueObject(parent), m_cast_type(cast_type) {
36 SetName(name);
37 m_value.SetCompilerType(cast_type);
38}
39
41
43
44llvm::Expected<uint32_t> ValueObjectCast::CalculateNumChildren(uint32_t max) {
46 auto children_count = GetCompilerType().GetNumChildren(true, &exe_ctx);
47 if (!children_count)
48 return children_count;
49 return *children_count <= max ? *children_count : max;
50}
51
52llvm::Expected<uint64_t> ValueObjectCast::GetByteSize() {
54 return m_value.GetValueByteSize(nullptr, &exe_ctx);
55}
56
58 // Let our parent answer global, local, argument, etc...
59 return m_parent->GetValueType();
60}
61
63 SetValueIsValid(false);
64 m_error.Clear();
65
66 if (m_parent->UpdateValueIfNeeded(false)) {
67 Value old_value(m_value);
68 m_update_point.SetUpdated();
69 m_value = m_parent->GetValue();
70 CompilerType compiler_type(GetCompilerType());
71 m_value.SetCompilerType(compiler_type);
72 SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren());
73 if (!CanProvideValue()) {
74 // this value object represents an aggregate type whose children have
75 // values, but this object does not. So we say we are changed if our
76 // location has changed.
77 SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() ||
78 m_value.GetScalar() != old_value.GetScalar());
79 }
81 m_error = m_value.GetValueAsData(&exe_ctx, m_data, GetModule().get());
82 SetValueDidChange(m_parent->GetValueDidChange());
83 return true;
84 }
85
86 // The dynamic value failed to get an error, pass the error along
87 if (m_error.Success() && m_parent->GetError().Fail())
88 m_error = m_parent->GetError().Clone();
89 SetValueIsValid(false);
90 return false;
91}
92
93bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); }
Generic representation of a type in a programming language.
llvm::Expected< uint32_t > GetNumChildren(bool omit_empty_base_classes, const ExecutionContext *exe_ctx) const
A uniqued constant string class.
Definition ConstString.h:40
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
CompilerType GetCompilerTypeImpl() override
llvm::Expected< uint32_t > CalculateNumChildren(uint32_t max) override
Should only be called by ValueObject::GetNumChildren().
llvm::Expected< uint64_t > GetByteSize() override
static lldb::ValueObjectSP Create(ValueObject &parent, ConstString name, const CompilerType &cast_type)
ValueObjectCast(ValueObject &parent, ConstString name, const CompilerType &cast_type)
lldb::ValueType GetValueType() const override
void SetValueIsValid(bool valid)
EvaluationPoint m_update_point
Stores both the stop id and the full context at which this value was last updated.
CompilerType GetCompilerType()
ValueObject(ExecutionContextScope *exe_scope, ValueObjectManager &manager, AddressType child_ptr_or_ref_addr_type=eAddressTypeLoad)
Use this constructor to create a "root variable object".
lldb::ValueObjectSP GetSP()
Status m_error
An error object that can describe any errors that occur when updating values.
DataExtractor m_data
A data extractor that can be used to extract the value.
void SetValueDidChange(bool value_changed)
virtual lldb::ModuleSP GetModule()
Return the module associated with this value object in case the value is from an executable file and ...
ValueObject * m_parent
The parent value object, or nullptr if this has no parent.
void SetName(ConstString name)
Change the name of the current ValueObject.
const ExecutionContextRef & GetExecutionContextRef() const
void SetAddressTypeOfChildren(AddressType at)
const Scalar & GetScalar() const
See comment on m_scalar to understand what GetScalar returns.
Definition Value.h:113
ValueType GetValueType() const
Definition Value.cpp:111
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP