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
19using namespace lldb_private;
20
22 llvm::StringRef name,
23 const CompilerType &cast_type) {
24 ValueObjectCast *cast_valobj_ptr =
25 new ValueObjectCast(parent, name, cast_type);
26 return cast_valobj_ptr->GetSP();
27}
28
29ValueObjectCast::ValueObjectCast(ValueObject &parent, llvm::StringRef name,
30 const CompilerType &cast_type)
31 : ValueObject(parent), m_cast_type(cast_type) {
32 SetName(name);
33 m_value.SetCompilerType(cast_type);
34}
35
37
39
40llvm::Expected<uint32_t> ValueObjectCast::CalculateNumChildren(uint32_t max) {
42 auto children_count = GetCompilerType().GetNumChildren(true, &exe_ctx);
43 if (!children_count)
44 return children_count;
45 return *children_count <= max ? *children_count : max;
46}
47
48llvm::Expected<uint64_t> ValueObjectCast::GetByteSize() {
50 return m_value.GetValueByteSize(nullptr, &exe_ctx);
51}
52
54 // Let our parent answer global, local, argument, etc...
55 return m_parent->GetValueType();
56}
57
59 SetValueIsValid(false);
60 m_error.Clear();
61
62 if (m_parent->UpdateValueIfNeeded(false)) {
63 Value old_value(m_value);
64 m_update_point.SetUpdated();
65 m_value = m_parent->GetValue();
66 CompilerType compiler_type(GetCompilerType());
67 m_value.SetCompilerType(compiler_type);
68 SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren());
69 if (!CanProvideValue()) {
70 // this value object represents an aggregate type whose children have
71 // values, but this object does not. So we say we are changed if our
72 // location has changed.
73 SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() ||
74 m_value.GetScalar() != old_value.GetScalar());
75 }
77 m_error = m_value.GetValueAsData(&exe_ctx, m_data, GetModule().get());
78 SetValueDidChange(m_parent->GetValueDidChange());
79 return true;
80 }
81
82 // The dynamic value failed to get an error, pass the error along
83 if (m_error.Success() && m_parent->GetError().Fail())
84 m_error = m_parent->GetError().Clone();
85 SetValueIsValid(false);
86 return false;
87}
88
89bool 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
"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, llvm::StringRef name, const CompilerType &cast_type)
ValueObjectCast(ValueObject &parent, llvm::StringRef 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.
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(llvm::StringRef name)
Change the name of the current ValueObject.
CompilerType GetCompilerType()
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