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 std::string child_name;
57 uint32_t child_byte_size = 0;
58 int32_t child_byte_offset = 0;
59 uint32_t child_bitfield_bit_size = 0;
60 uint32_t child_bitfield_bit_offset = 0;
61 bool child_is_base_class = false;
62 bool child_is_deref_of_parent = false;
63 uint64_t language_flags;
64 const bool transparent_pointers = true;
65 CompilerType compiler_type = m_impl_backend->GetCompilerType();
66
67 ExecutionContext exe_ctx(m_impl_backend->GetExecutionContextRef());
68
69 auto child_compiler_type_or_err = compiler_type.GetChildCompilerTypeAtIndex(
70 &exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
71 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
72 child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
73 child_is_deref_of_parent, m_impl_backend, language_flags);
74
75 // One might think we should check that the size of the children
76 // is always strictly positive, hence we could avoid creating a
77 // ValueObject if that's not the case, but it turns out there
78 // are languages out there which allow zero-size types with
79 // children (e.g. Swift).
80 if (!child_compiler_type_or_err || !child_compiler_type_or_err->IsValid()) {
82 child_compiler_type_or_err.takeError(),
83 "could not find child: {0}");
84 return nullptr;
85 }
86
87 lldb::addr_t child_live_addr = LLDB_INVALID_ADDRESS;
88 // Transfer the live address (with offset) to the child. But if
89 // the parent is a pointer, the live address is where that pointer
90 // value lives in memory, so the children live addresses aren't
91 // offsets from that value, they are just other load addresses that
92 // are recorded in the Value of the child ValueObjects.
93 if (m_live_address != LLDB_INVALID_ADDRESS && !compiler_type.IsPointerType())
94 child_live_addr = m_live_address + child_byte_offset;
95
97 *m_impl_backend, *child_compiler_type_or_err, ConstString(child_name),
98 child_byte_size, child_byte_offset, child_bitfield_bit_size,
99 child_bitfield_bit_offset, child_is_base_class, child_is_deref_of_parent,
100 child_live_addr, language_flags);
101}
102
105 if (m_impl_backend == nullptr)
106 return nullptr;
107
108 m_impl_backend->UpdateValueIfNeeded(false);
109
110 bool omit_empty_base_classes = true;
111 bool ignore_array_bounds = true;
112 std::string child_name;
113 uint32_t child_byte_size = 0;
114 int32_t child_byte_offset = 0;
115 uint32_t child_bitfield_bit_size = 0;
116 uint32_t child_bitfield_bit_offset = 0;
117 bool child_is_base_class = false;
118 bool child_is_deref_of_parent = false;
119 uint64_t language_flags;
120
121 const bool transparent_pointers = false;
122 CompilerType compiler_type = m_impl_backend->GetCompilerType();
123
124 ExecutionContext exe_ctx(m_impl_backend->GetExecutionContextRef());
125
126 auto child_compiler_type_or_err = compiler_type.GetChildCompilerTypeAtIndex(
127 &exe_ctx, 0, transparent_pointers, omit_empty_base_classes,
128 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
129 child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
130 child_is_deref_of_parent, m_impl_backend, language_flags);
131 // One might think we should check that the size of the children
132 // is always strictly positive, hence we could avoid creating a
133 // ValueObject if that's not the case, but it turns out there
134 // are languages out there which allow zero-size types with
135 // children (e.g. Swift).
136 if (!child_compiler_type_or_err || !child_compiler_type_or_err->IsValid()) {
138 child_compiler_type_or_err.takeError(),
139 "could not find child: {0}");
140 return nullptr;
141 }
142
143 child_byte_offset += child_byte_size * idx;
144
145 lldb::addr_t child_live_addr = LLDB_INVALID_ADDRESS;
146 // Transfer the live address (with offset) to the child. But if
147 // the parent is a pointer, the live address is where that pointer
148 // value lives in memory, so the children live addresses aren't
149 // offsets from that value, they are just other load addresses that
150 // are recorded in the Value of the child ValueObjects.
151 if (m_live_address != LLDB_INVALID_ADDRESS && !compiler_type.IsPointerType())
152 child_live_addr = m_live_address + child_byte_offset;
154 *m_impl_backend, *child_compiler_type_or_err, ConstString(child_name),
155 child_byte_size, child_byte_offset, child_bitfield_bit_size,
156 child_bitfield_bit_offset, child_is_base_class, child_is_deref_of_parent,
157 child_live_addr, language_flags);
158}
159
161 uint32_t offset, const CompilerType &type, bool can_create,
162 ConstString name_const_str) {
163 if (m_impl_backend == nullptr)
164 return lldb::ValueObjectSP();
165
166 return m_impl_backend->ValueObject::GetSyntheticChildAtOffset(
167 offset, type, can_create, name_const_str);
168}
169
171 if (m_address_of_backend.get() != nullptr)
173
174 if (m_impl_backend == nullptr)
175 return lldb::ValueObjectSP();
177 CompilerType compiler_type(m_impl_backend->GetCompilerType());
178
180 &m_live_address, sizeof(lldb::addr_t)));
181
182 std::string new_name("&");
183 new_name.append(m_impl_backend->GetName().AsCString(""));
184 ExecutionContext exe_ctx(m_impl_backend->GetExecutionContextRef());
186 exe_ctx.GetBestExecutionContextScope(), compiler_type.GetPointerType(),
187 ConstString(new_name.c_str()), buffer, endian::InlHostByteOrder(),
188 exe_ctx.GetAddressByteSize());
189
190 m_address_of_backend->GetValue().SetValueType(Value::ValueType::Scalar);
191 m_address_of_backend->GetValue().GetScalar() = m_live_address;
192
194 } else
195 return m_impl_backend->ValueObject::AddressOf(error);
196}
197
200 if (m_impl_backend == nullptr)
201 return lldb::ValueObjectSP();
202
203 ValueObjectConstResultCast *result_cast =
205 compiler_type, m_live_address);
206 return result_cast->GetSP();
207}
208
210ValueObjectConstResultImpl::GetAddressOf(bool scalar_is_load_address) {
211
212 if (m_impl_backend == nullptr)
213 return {0, eAddressTypeInvalid};
214
216 return m_impl_backend->ValueObject::GetAddressOf(scalar_is_load_address);
217
219}
220
222 uint32_t item_idx,
223 uint32_t item_count) {
224 if (m_impl_backend == nullptr)
225 return 0;
226 return m_impl_backend->ValueObject::GetPointeeData(data, item_idx,
227 item_count);
228}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:392
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< 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
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)
lldb::ValueObjectSP GetSP()
@ Scalar
A raw scalar value.
Definition Value.h:45
#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:332
@ 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