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"
15#include "lldb/Utility/Scalar.h"
16#include "lldb/Utility/Status.h"
17#include <optional>
18
19namespace lldb_private {
20class ConstString;
21}
22
23using namespace lldb_private;
24
25lldb::ValueObjectSP ValueObjectCast::Create(ValueObject &parent,
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
46 auto children_count = GetCompilerType().GetNumChildren(
47 true, &exe_ctx);
48 return children_count <= max ? children_count : max;
49}
50
51std::optional<uint64_t> ValueObjectCast::GetByteSize() {
53 return m_value.GetValueByteSize(nullptr, &exe_ctx);
54}
55
57 // Let our parent answer global, local, argument, etc...
58 return m_parent->GetValueType();
59}
60
62 SetValueIsValid(false);
63 m_error.Clear();
64
65 if (m_parent->UpdateValueIfNeeded(false)) {
66 Value old_value(m_value);
69 CompilerType compiler_type(GetCompilerType());
70 m_value.SetCompilerType(compiler_type);
72 if (!CanProvideValue()) {
73 // this value object represents an aggregate type whose children have
74 // values, but this object does not. So we say we are changed if our
75 // location has changed.
77 m_value.GetScalar() != old_value.GetScalar());
78 }
80 m_error = m_value.GetValueAsData(&exe_ctx, m_data, GetModule().get());
82 return true;
83 }
84
85 // The dynamic value failed to get an error, pass the error along
86 if (m_error.Success() && m_parent->GetError().Fail())
88 SetValueIsValid(false);
89 return false;
90}
91
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
uint32_t GetNumChildren(bool omit_empty_base_classes, const ExecutionContext *exe_ctx) const
A uniqued constant string class.
Definition: ConstString.h:39
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void Clear()
Clear the object state.
Definition: Status.cpp:167
bool Fail() const
Test for error condition.
Definition: Status.cpp:181
bool Success() const
Test for success condition.
Definition: Status.cpp:287
A ValueObject that represents a given value represented as a different type.
CompilerType GetCompilerTypeImpl() override
static lldb::ValueObjectSP Create(ValueObject &parent, ConstString name, const CompilerType &cast_type)
std::optional< uint64_t > GetByteSize() override
ValueObjectCast(ValueObject &parent, ConstString name, const CompilerType &cast_type)
size_t CalculateNumChildren(uint32_t max) override
Should only be called by ValueObject::GetNumChildren().
lldb::ValueType GetValueType() const override
void SetValueIsValid(bool valid)
Definition: ValueObject.h:980
EvaluationPoint m_update_point
Stores both the stop id and the full context at which this value was last updated.
Definition: ValueObject.h:847
virtual bool IsInScope()
Definition: ValueObject.h:420
CompilerType GetCompilerType()
Definition: ValueObject.h:352
lldb::ValueObjectSP GetSP()
Definition: ValueObject.h:555
Status m_error
An error object that can describe any errors that occur when updating values.
Definition: ValueObject.h:855
DataExtractor m_data
A data extractor that can be used to extract the value.
Definition: ValueObject.h:851
virtual lldb::ValueType GetValueType() const =0
void SetValueDidChange(bool value_changed)
Definition: ValueObject.h:976
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.
Definition: ValueObject.h:840
bool UpdateValueIfNeeded(bool update_format=true)
void SetName(ConstString name)
Change the name of the current ValueObject.
Definition: ValueObject.h:560
AddressType GetAddressTypeOfChildren()
const Status & GetError()
const ExecutionContextRef & GetExecutionContextRef() const
Definition: ValueObject.h:330
virtual bool CanProvideValue()
const Value & GetValue() const
Definition: ValueObject.h:497
void SetAddressTypeOfChildren(AddressType at)
Definition: ValueObject.h:759
const Scalar & GetScalar() const
Definition: Value.h:112
Status GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, Module *module)
Definition: Value.cpp:299
ValueType GetValueType() const
Definition: Value.cpp:107
void SetCompilerType(const CompilerType &compiler_type)
Definition: Value.cpp:252
uint64_t GetValueByteSize(Status *error_ptr, ExecutionContext *exe_ctx)
Definition: Value.cpp:195
A class that represents a running process on the host machine.