LLDB mainline
ValueObjectConstResultImpl.cpp
Go to the documentation of this file.
1//===-- ValueObjectConstResultImpl.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/Endian.h"
17#include "lldb/Utility/Log.h"
18#include "lldb/Utility/Scalar.h"
23
24#include <string>
25
26namespace lldb_private {
27class DataExtractor;
28}
29namespace lldb_private {
30class Status;
31}
32
33using namespace lldb;
34using namespace lldb_private;
35
40
42 if (m_impl_backend == nullptr)
43 return lldb::ValueObjectSP();
44
45 return m_impl_backend->ValueObject::Dereference(error);
46}
47
49 if (m_impl_backend == nullptr)
50 return nullptr;
51
52 m_impl_backend->UpdateValueIfNeeded(false);
53
54 bool omit_empty_base_classes = true;
55 bool ignore_array_bounds = false;
56 const bool transparent_pointers = true;
57 CompilerType compiler_type = m_impl_backend->GetCompilerType();
58
59 ExecutionContext exe_ctx(m_impl_backend->GetExecutionContextRef());
60
61 auto child_or_err = compiler_type.GetChildAtIndex(
62 &exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
63 ignore_array_bounds, m_impl_backend);
64
65 // One might think we should check that the size of the children
66 // is always strictly positive, hence we could avoid creating a
67 // ValueObject if that's not the case, but it turns out there
68 // are languages out there which allow zero-size types with
69 // children (e.g. Swift).
70 if (!child_or_err || !child_or_err->type.IsValid()) {
71 LLDB_LOG_ERROR(GetLog(LLDBLog::Types), child_or_err.takeError(),
72 "could not find child: {0}");
73 return nullptr;
74 }
75 const ChildTypeInfo &child = *child_or_err;
76
77 lldb::addr_t child_live_addr = LLDB_INVALID_ADDRESS;
78 // Transfer the live address (with offset) to the child. But if
79 // the parent is a pointer, the live address is where that pointer
80 // value lives in memory, so the children live addresses aren't
81 // offsets from that value, they are just other load addresses that
82 // are recorded in the Value of the child ValueObjects.
83 if (m_live_address != LLDB_INVALID_ADDRESS && !compiler_type.IsPointerType())
84 child_live_addr = m_live_address + child.byte_offset;
85
87 *m_impl_backend, child.type, ConstString(child.name), child.byte_size,
89 child.is_base_class, child.is_deref_of_parent, child_live_addr,
90 child.language_flags);
91}
92
95 if (m_impl_backend == nullptr)
96 return nullptr;
97
98 m_impl_backend->UpdateValueIfNeeded(false);
99
100 bool omit_empty_base_classes = true;
101 bool ignore_array_bounds = true;
102
103 const bool transparent_pointers = false;
104 CompilerType compiler_type = m_impl_backend->GetCompilerType();
105
106 ExecutionContext exe_ctx(m_impl_backend->GetExecutionContextRef());
107
108 auto child_or_err = compiler_type.GetChildAtIndex(
109 &exe_ctx, 0, transparent_pointers, omit_empty_base_classes,
110 ignore_array_bounds, m_impl_backend);
111 // One might think we should check that the size of the children
112 // is always strictly positive, hence we could avoid creating a
113 // ValueObject if that's not the case, but it turns out there
114 // are languages out there which allow zero-size types with
115 // children (e.g. Swift).
116 if (!child_or_err || !child_or_err->type.IsValid()) {
117 LLDB_LOG_ERROR(GetLog(LLDBLog::Types), child_or_err.takeError(),
118 "could not find child: {0}");
119 return nullptr;
120 }
121 ChildTypeInfo &child = *child_or_err;
122
123 child.byte_offset += child.byte_size * idx;
124
125 lldb::addr_t child_live_addr = LLDB_INVALID_ADDRESS;
126 // Transfer the live address (with offset) to the child. But if
127 // the parent is a pointer, the live address is where that pointer
128 // value lives in memory, so the children live addresses aren't
129 // offsets from that value, they are just other load addresses that
130 // are recorded in the Value of the child ValueObjects.
131 if (m_live_address != LLDB_INVALID_ADDRESS && !compiler_type.IsPointerType())
132 child_live_addr = m_live_address + child.byte_offset;
134 *m_impl_backend, child.type, ConstString(child.name), child.byte_size,
136 child.is_base_class, child.is_deref_of_parent, child_live_addr,
137 child.language_flags);
138}
139
141 uint32_t offset, const CompilerType &type, bool can_create,
142 ConstString name_const_str) {
143 if (m_impl_backend == nullptr)
144 return lldb::ValueObjectSP();
145
146 return m_impl_backend->ValueObject::GetSyntheticChildAtOffset(
147 offset, type, can_create, name_const_str);
148}
149
151 if (m_address_of_backend.get() != nullptr)
153
154 if (m_impl_backend == nullptr)
155 return lldb::ValueObjectSP();
157 CompilerType compiler_type(m_impl_backend->GetCompilerType());
158
160 &m_live_address, sizeof(lldb::addr_t)));
161
162 std::string new_name("&");
163 new_name.append(m_impl_backend->GetName().AsCString(""));
164 ExecutionContext exe_ctx(m_impl_backend->GetExecutionContextRef());
166 exe_ctx.GetBestExecutionContextScope(), compiler_type.GetPointerType(),
167 ConstString(new_name), buffer, endian::InlHostByteOrder(),
169 m_impl_backend->GetManager());
170
171 m_address_of_backend->GetValue().SetValueType(Value::ValueType::Scalar);
172 m_address_of_backend->GetValue().GetScalar() = m_live_address;
173
175 } else
176 return m_impl_backend->ValueObject::AddressOf(error);
177}
178
181 if (m_impl_backend == nullptr)
182 return lldb::ValueObjectSP();
183
184 ValueObjectConstResultCast *result_cast =
186 compiler_type, m_live_address);
187 return result_cast->GetSP();
188}
189
191ValueObjectConstResultImpl::GetAddressOf(bool scalar_is_load_address) {
192
193 if (m_impl_backend == nullptr)
194 return {0, eAddressTypeInvalid};
195
197 return m_impl_backend->ValueObject::GetAddressOf(scalar_is_load_address);
198
200}
201
203 uint32_t item_idx,
204 uint32_t item_count) {
205 if (m_impl_backend == nullptr)
206 return 0;
207 return m_impl_backend->ValueObject::GetPointeeData(data, item_idx,
208 item_count);
209}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:405
Generic representation of a type in a programming language.
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
llvm::Expected< ChildTypeInfo > GetChildAtIndex(ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, bool omit_empty_base_classes, bool ignore_array_bounds, ValueObject *valobj) const
Get the child at idx, such as a field, a base class or a pointee.
bool IsPointerType(CompilerType *pointee_type=nullptr) const
A uniqued constant string class.
Definition ConstString.h:40
A subclass of DataBuffer that stores a data buffer on the heap.
An data extractor class.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
An error handling class.
Definition Status.h:118
lldb::ValueObjectSP GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type, bool can_create, ConstString name_const_str=ConstString())
virtual size_t GetPointeeData(DataExtractor &data, uint32_t item_idx=0, uint32_t item_count=1)
ValueObjectConstResultImpl(ValueObject *valobj, lldb::addr_t live_address=LLDB_INVALID_ADDRESS)
lldb::ValueObjectSP Cast(const CompilerType &compiler_type)
lldb::addr_t m_live_address
The memory address in the inferior process that this ValueObject tracks.
virtual ValueObject::AddrAndType GetAddressOf(bool scalar_is_load_address=true)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address=LLDB_INVALID_ADDRESS, ValueObjectManager *manager=nullptr)
These routines create ValueObjectConstResult ValueObjects from various data sources.
lldb::ValueObjectSP GetSP()
@ Scalar
A raw scalar value.
Definition Value.h:46
#define LLDB_INVALID_ADDRESS
lldb::ByteOrder InlHostByteOrder()
Definition Endian.h:25
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
A child of a type, as returned by CompilerType::GetChildAtIndex.