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"
19#include "lldb/Utility/Endian.h"
21#include "lldb/Utility/Log.h"
22#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
37 ValueObject *valobj, lldb::addr_t live_address)
38 : m_impl_backend(valobj), m_live_address(live_address),
39 m_live_address_type(eAddressTypeLoad),
40 m_address_of_backend() {}
41
43 if (m_impl_backend == nullptr)
44 return lldb::ValueObjectSP();
45
46 return m_impl_backend->ValueObject::Dereference(error);
47}
48
50 if (m_impl_backend == nullptr)
51 return nullptr;
52
54
55 bool omit_empty_base_classes = true;
56 bool ignore_array_bounds = false;
57 std::string child_name;
58 uint32_t child_byte_size = 0;
59 int32_t child_byte_offset = 0;
60 uint32_t child_bitfield_bit_size = 0;
61 uint32_t child_bitfield_bit_offset = 0;
62 bool child_is_base_class = false;
63 bool child_is_deref_of_parent = false;
64 uint64_t language_flags;
65 const bool transparent_pointers = true;
67
69
70 auto child_compiler_type_or_err = compiler_type.GetChildCompilerTypeAtIndex(
71 &exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
72 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
73 child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
74 child_is_deref_of_parent, m_impl_backend, language_flags);
75
76 // One might think we should check that the size of the children
77 // is always strictly positive, hence we could avoid creating a
78 // ValueObject if that's not the case, but it turns out there
79 // are languages out there which allow zero-size types with
80 // children (e.g. Swift).
81 if (!child_compiler_type_or_err || !child_compiler_type_or_err->IsValid()) {
83 child_compiler_type_or_err.takeError(),
84 "could not find child: {0}");
85 return nullptr;
86 }
87
88 lldb::addr_t child_live_addr = LLDB_INVALID_ADDRESS;
89 // Transfer the live address (with offset) to the child. But if
90 // the parent is a pointer, the live address is where that pointer
91 // value lives in memory, so the children live addresses aren't
92 // offsets from that value, they are just other load addresses that
93 // are recorded in the Value of the child ValueObjects.
94 if (m_live_address != LLDB_INVALID_ADDRESS && !compiler_type.IsPointerType())
95 child_live_addr = m_live_address + child_byte_offset;
96
98 *m_impl_backend, *child_compiler_type_or_err, ConstString(child_name),
99 child_byte_size, child_byte_offset, child_bitfield_bit_size,
100 child_bitfield_bit_offset, child_is_base_class, child_is_deref_of_parent,
101 child_live_addr, language_flags);
102}
103
106 if (m_impl_backend == nullptr)
107 return nullptr;
108
110
111 bool omit_empty_base_classes = true;
112 bool ignore_array_bounds = true;
113 std::string child_name;
114 uint32_t child_byte_size = 0;
115 int32_t child_byte_offset = 0;
116 uint32_t child_bitfield_bit_size = 0;
117 uint32_t child_bitfield_bit_offset = 0;
118 bool child_is_base_class = false;
119 bool child_is_deref_of_parent = false;
120 uint64_t language_flags;
121
122 const bool transparent_pointers = false;
124
126
127 auto child_compiler_type_or_err = compiler_type.GetChildCompilerTypeAtIndex(
128 &exe_ctx, 0, transparent_pointers, omit_empty_base_classes,
129 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
130 child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
131 child_is_deref_of_parent, m_impl_backend, language_flags);
132 // One might think we should check that the size of the children
133 // is always strictly positive, hence we could avoid creating a
134 // ValueObject if that's not the case, but it turns out there
135 // are languages out there which allow zero-size types with
136 // children (e.g. Swift).
137 if (!child_compiler_type_or_err || !child_compiler_type_or_err->IsValid()) {
139 child_compiler_type_or_err.takeError(),
140 "could not find child: {0}");
141 return nullptr;
142 }
143
144 child_byte_offset += child_byte_size * idx;
145
146 lldb::addr_t child_live_addr = LLDB_INVALID_ADDRESS;
147 // Transfer the live address (with offset) to the child. But if
148 // the parent is a pointer, the live address is where that pointer
149 // value lives in memory, so the children live addresses aren't
150 // offsets from that value, they are just other load addresses that
151 // are recorded in the Value of the child ValueObjects.
152 if (m_live_address != LLDB_INVALID_ADDRESS && !compiler_type.IsPointerType())
153 child_live_addr = m_live_address + child_byte_offset;
155 *m_impl_backend, *child_compiler_type_or_err, ConstString(child_name),
156 child_byte_size, child_byte_offset, child_bitfield_bit_size,
157 child_bitfield_bit_offset, child_is_base_class, child_is_deref_of_parent,
158 child_live_addr, language_flags);
159}
160
162 uint32_t offset, const CompilerType &type, bool can_create,
163 ConstString name_const_str) {
164 if (m_impl_backend == nullptr)
165 return lldb::ValueObjectSP();
166
167 return m_impl_backend->ValueObject::GetSyntheticChildAtOffset(
168 offset, type, can_create, name_const_str);
169}
170
172 if (m_address_of_backend.get() != nullptr)
174
175 if (m_impl_backend == nullptr)
176 return lldb::ValueObjectSP();
179
181 &m_live_address, sizeof(lldb::addr_t)));
182
183 std::string new_name("&");
184 new_name.append(m_impl_backend->GetName().AsCString(""));
187 exe_ctx.GetBestExecutionContextScope(), compiler_type.GetPointerType(),
188 ConstString(new_name.c_str()), buffer, endian::InlHostByteOrder(),
189 exe_ctx.GetAddressByteSize());
190
191 m_address_of_backend->GetValue().SetValueType(Value::ValueType::Scalar);
192 m_address_of_backend->GetValue().GetScalar() = m_live_address;
193
195 } else
196 return m_impl_backend->ValueObject::AddressOf(error);
197}
198
201 if (m_impl_backend == nullptr)
202 return lldb::ValueObjectSP();
203
204 ValueObjectConstResultCast *result_cast =
206 compiler_type, m_live_address);
207 return result_cast->GetSP();
208}
209
212 AddressType *address_type) {
213
214 if (m_impl_backend == nullptr)
215 return 0;
216
218 return m_impl_backend->ValueObject::GetAddressOf(scalar_is_load_address,
219 address_type);
220 }
221
222 if (address_type)
223 *address_type = m_live_address_type;
224
225 return m_live_address;
226}
227
229 uint32_t item_idx,
230 uint32_t item_count) {
231 if (m_impl_backend == nullptr)
232 return 0;
233 return m_impl_backend->ValueObject::GetPointeeData(data, item_idx,
234 item_count);
235}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:382
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
llvm::Expected< CompilerType > GetChildCompilerTypeAtIndex(ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, bool omit_empty_base_classes, bool ignore_array_bounds, std::string &child_name, uint32_t &child_byte_size, int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, bool &child_is_deref_of_parent, ValueObject *valobj, uint64_t &language_flags) const
bool IsPointerType(CompilerType *pointee_type=nullptr) const
A uniqued constant string class.
Definition: ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:188
A subclass of DataBuffer that stores a data buffer on the heap.
An data extractor class.
Definition: DataExtractor.h:48
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
An error handling class.
Definition: Status.h:44
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)
virtual lldb::addr_t GetAddressOf(bool scalar_is_load_address=true, AddressType *address_type=nullptr)
lldb::ValueObjectSP Dereference(Status &error)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address=LLDB_INVALID_ADDRESS)
CompilerType GetCompilerType()
Definition: ValueObject.h:352
lldb::ValueObjectSP GetSP()
Definition: ValueObject.h:569
bool UpdateValueIfNeeded(bool update_format=true)
ConstString GetName() const
Definition: ValueObject.h:487
const ExecutionContextRef & GetExecutionContextRef() const
Definition: ValueObject.h:330
@ Scalar
A raw scalar value.
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
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:331
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:479
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:333
uint64_t addr_t
Definition: lldb-types.h:80