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
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(
47 true, &exe_ctx);
48 if (!children_count)
49 return children_count;
50 return *children_count <= max ? *children_count : max;
51}
52
53std::optional<uint64_t> ValueObjectCast::GetByteSize() {
55 return m_value.GetValueByteSize(nullptr, &exe_ctx);
56}
57
59 // Let our parent answer global, local, argument, etc...
60 return m_parent->GetValueType();
61}
62
64 SetValueIsValid(false);
65 m_error.Clear();
66
67 if (m_parent->UpdateValueIfNeeded(false)) {
68 Value old_value(m_value);
71 CompilerType compiler_type(GetCompilerType());
72 m_value.SetCompilerType(compiler_type);
74 if (!CanProvideValue()) {
75 // this value object represents an aggregate type whose children have
76 // values, but this object does not. So we say we are changed if our
77 // location has changed.
79 m_value.GetScalar() != old_value.GetScalar());
80 }
82 m_error = m_value.GetValueAsData(&exe_ctx, m_data, GetModule().get());
84 return true;
85 }
86
87 // The dynamic value failed to get an error, pass the error along
88 if (m_error.Success() && m_parent->GetError().Fail())
90 SetValueIsValid(false);
91 return false;
92}
93
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
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.
void Clear()
Clear the object state.
Definition: Status.cpp:166
bool Fail() const
Test for error condition.
Definition: Status.cpp:180
bool Success() const
Test for success condition.
Definition: Status.cpp:278
A ValueObject that represents a given value represented as a different type.
CompilerType GetCompilerTypeImpl() override
llvm::Expected< uint32_t > CalculateNumChildren(uint32_t max) override
Should only be called by ValueObject::GetNumChildren().
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)
lldb::ValueType GetValueType() const override
void SetValueIsValid(bool valid)
Definition: ValueObject.h:1059
EvaluationPoint m_update_point
Stores both the stop id and the full context at which this value was last updated.
Definition: ValueObject.h:922
virtual bool IsInScope()
Definition: ValueObject.h:420
CompilerType GetCompilerType()
Definition: ValueObject.h:352
lldb::ValueObjectSP GetSP()
Definition: ValueObject.h:569
Status m_error
An error object that can describe any errors that occur when updating values.
Definition: ValueObject.h:930
DataExtractor m_data
A data extractor that can be used to extract the value.
Definition: ValueObject.h:926
virtual lldb::ValueType GetValueType() const =0
void SetValueDidChange(bool value_changed)
Definition: ValueObject.h:1055
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:915
bool UpdateValueIfNeeded(bool update_format=true)
void SetName(ConstString name)
Change the name of the current ValueObject.
Definition: ValueObject.h:574
AddressType GetAddressTypeOfChildren()
const Status & GetError()
const ExecutionContextRef & GetExecutionContextRef() const
Definition: ValueObject.h:330
virtual bool CanProvideValue()
const Value & GetValue() const
Definition: ValueObject.h:511
void SetAddressTypeOfChildren(AddressType at)
Definition: ValueObject.h:834
const Scalar & GetScalar() const
Definition: Value.h:112
Status GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, Module *module)
Definition: Value.cpp:315
ValueType GetValueType() const
Definition: Value.cpp:109
void SetCompilerType(const CompilerType &compiler_type)
Definition: Value.cpp:268
uint64_t GetValueByteSize(Status *error_ptr, ExecutionContext *exe_ctx)
Definition: Value.cpp:211
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:480