LLDB mainline
ValueObjectConstResult.cpp
Go to the documentation of this file.
1//===-- ValueObjectConstResult.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
14#include "lldb/Target/Process.h"
18#include "lldb/Utility/Scalar.h"
20#include <optional>
21
22namespace lldb_private {
23class Module;
24}
25
26using namespace lldb;
27using namespace lldb_private;
28
30 ByteOrder byte_order,
31 uint32_t addr_byte_size,
32 lldb::addr_t address,
33 ValueObjectManager *manager) {
34 ValueObjectManagerSP manager_sp = CreateManagerIfEmpty(manager);
35
36 return (new ValueObjectConstResult(exe_scope, *manager, byte_order,
37 addr_byte_size, address))
38 ->GetSP();
39}
40
42 ValueObjectManager &manager,
43 ByteOrder byte_order,
44 uint32_t addr_byte_size,
45 lldb::addr_t address)
46 : ValueObject(exe_scope, manager), m_impl(this, address) {
48 SetValueIsValid(true);
49 m_data.SetByteOrder(byte_order);
50 m_data.SetAddressByteSize(addr_byte_size);
52}
53
55 const CompilerType &compiler_type,
56 ConstString name,
57 const DataExtractor &data,
58 lldb::addr_t address,
59 ValueObjectManager *manager) {
60 std::shared_ptr<ValueObjectManager> manager_sp =
61 CreateManagerIfEmpty(manager);
62 return (new ValueObjectConstResult(exe_scope, *manager, compiler_type, name,
63 data, address))
64 ->GetSP();
65}
66
68 ExecutionContextScope *exe_scope, ValueObjectManager &manager,
69 const CompilerType &compiler_type, ConstString name,
70 const DataExtractor &data, lldb::addr_t address)
71 : ValueObject(exe_scope, manager), m_impl(this, address) {
72 m_data = data;
73
74 if (!m_data.GetSharedDataBuffer()) {
75 DataBufferSP shared_data_buffer(
76 new DataBufferHeap(data.GetDataStart(), data.GetByteSize()));
77 m_data.SetData(shared_data_buffer);
78 }
79
80 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
82 m_value.SetCompilerType(compiler_type);
83 m_name = name;
85 SetValueIsValid(true);
87}
88
90 ExecutionContextScope *exe_scope, const CompilerType &compiler_type,
91 ConstString name, const lldb::DataBufferSP &data_sp,
92 lldb::ByteOrder data_byte_order, uint32_t data_addr_size,
93 lldb::addr_t address, ValueObjectManager *manager) {
94 std::shared_ptr<ValueObjectManager> manager_sp =
95 CreateManagerIfEmpty(manager);
96 return (new ValueObjectConstResult(exe_scope, *manager, compiler_type, name,
97 data_sp, data_byte_order, data_addr_size,
98 address))
99 ->GetSP();
100}
101
103 Value &value, ConstString name,
104 Module *module,
105 ValueObjectManager *manager) {
106 std::shared_ptr<ValueObjectManager> manager_sp =
107 CreateManagerIfEmpty(manager);
108 return (new ValueObjectConstResult(exe_scope, *manager, value, name, module))
109 ->GetSP();
110}
111
113 const CompilerType &compiler_type,
114 Scalar &scalar, ConstString name,
115 Module *module,
116 ValueObjectManager *manager) {
117 std::shared_ptr<ValueObjectManager> manager_sp =
118 CreateManagerIfEmpty(manager);
119 return (new ValueObjectConstResult(exe_scope, *manager, compiler_type, scalar,
120 name, module))
121 ->GetSP();
122}
123
125 ExecutionContextScope *exe_scope, ValueObjectManager &manager,
126 const CompilerType &compiler_type, ConstString name,
127 const lldb::DataBufferSP &data_sp, lldb::ByteOrder data_byte_order,
128 uint32_t data_addr_size, lldb::addr_t address)
129 : ValueObject(exe_scope, manager), m_impl(this, address) {
130 m_data.SetByteOrder(data_byte_order);
131 m_data.SetAddressByteSize(data_addr_size);
132 m_data.SetData(data_sp);
133 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
135 m_value.SetCompilerType(compiler_type);
136 m_name = name;
138 SetValueIsValid(true);
140}
141
143 ExecutionContextScope *exe_scope, const CompilerType &compiler_type,
144 ConstString name, lldb::addr_t address, AddressType address_type,
145 uint32_t addr_byte_size, ValueObjectManager *manager) {
146 std::shared_ptr<ValueObjectManager> manager_sp =
147 CreateManagerIfEmpty(manager);
148 return (new ValueObjectConstResult(exe_scope, *manager, compiler_type, name,
149 address, address_type, addr_byte_size))
150 ->GetSP();
151}
152
154 ExecutionContextScope *exe_scope, ValueObjectManager &manager,
155 const CompilerType &compiler_type, ConstString name, lldb::addr_t address,
156 AddressType address_type, uint32_t addr_byte_size)
157 : ValueObject(exe_scope, manager), m_type_name(), m_impl(this, address) {
158 m_value.GetScalar() = address;
159 m_data.SetAddressByteSize(addr_byte_size);
160 m_value.GetScalar().GetData(m_data, addr_byte_size);
161 // m_value.SetValueType(Value::ValueType::HostAddress);
162 switch (address_type) {
164 m_value.SetValueType(Value::ValueType::Scalar);
165 break;
166 case eAddressTypeFile:
168 break;
169 case eAddressTypeLoad:
171 break;
172 case eAddressTypeHost:
174 break;
175 }
176 m_value.SetCompilerType(compiler_type);
177 m_name = name;
179 SetValueIsValid(true);
181}
182
184 Status &&error,
185 ValueObjectManager *manager) {
186
187 std::shared_ptr<ValueObjectManager> manager_sp =
188 CreateManagerIfEmpty(manager);
189 return (new ValueObjectConstResult(exe_scope, *manager, std::move(error)))
190 ->GetSP();
191}
192
194 ValueObjectManager &manager,
195 Status &&error)
196 : ValueObject(exe_scope, manager), m_impl(this) {
197 m_error = std::move(error);
199}
200
202 ValueObjectManager &manager,
203 const Value &value,
204 ConstString name, Module *module)
205 : ValueObject(exe_scope, manager), m_impl(this) {
206 m_value = value;
207 m_name = name;
208 ExecutionContext exe_ctx;
209 exe_scope->CalculateExecutionContext(exe_ctx);
210 m_error = m_value.GetValueAsData(&exe_ctx, m_data, module);
211}
212
214 ExecutionContextScope *exe_scope, ValueObjectManager &manager,
215 const CompilerType &compiler_type, const Scalar &scalar, ConstString name,
216 Module *module)
217 : ValueObject(exe_scope, manager), m_impl(this) {
218 m_value = Value(scalar);
219 m_value.SetCompilerType(compiler_type);
220 m_value.SetValueType(Value::ValueType::Scalar);
221 m_name = name;
222 ExecutionContext exe_ctx;
223 exe_scope->CalculateExecutionContext(exe_ctx);
224 m_error = m_value.GetValueAsData(&exe_ctx, m_data, module);
226 SetValueIsValid(true);
228}
229
231
235
239
240llvm::Expected<uint64_t> ValueObjectConstResult::GetByteSize() {
242 if (!m_byte_size) {
243 auto size_or_err =
245 if (!size_or_err)
246 return size_or_err;
247 SetByteSize(*size_or_err);
248 }
249 if (m_byte_size)
250 return *m_byte_size;
251 return llvm::createStringError("unknown size of const result");
252}
253
255
256llvm::Expected<uint32_t>
259 auto children_count = GetCompilerType().GetNumChildren(true, &exe_ctx);
260 if (!children_count)
261 return children_count;
262 return *children_count <= max ? *children_count : max;
263}
264
270
274
276 // Const value is always valid
277 SetValueIsValid(true);
278 return true;
279}
280
282 // A const result value is always in scope since it serializes all
283 // information needed to contain the constant value.
284 return true;
285}
286
290
292 uint32_t offset, const CompilerType &type, bool can_create,
293 ConstString name_const_str) {
294 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create,
295 name_const_str);
296}
297
301
303ValueObjectConstResult::GetAddressOf(bool scalar_is_load_address) {
304 return m_impl.GetAddressOf(scalar_is_load_address);
305}
306
308 uint32_t item_idx,
309 uint32_t item_count) {
310 return m_impl.GetPointeeData(data, item_idx, item_count);
311}
312
315 // Always recalculate dynamic values for const results as the memory that
316 // they might point to might have changed at any time.
317 if (use_dynamic != eNoDynamicValues) {
318 if (!IsDynamic()) {
320 Process *process = exe_ctx.GetProcessPtr();
321 if (process && process->IsPossibleDynamicValue(*this))
322 m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic);
323 }
324 if (m_dynamic_value && m_dynamic_value->GetError().Success())
325 return m_dynamic_value->GetSP();
326 }
327 return ValueObjectSP();
328}
329
332 return m_impl.Cast(compiler_type);
333}
334
static llvm::raw_ostream & error(Stream &strm)
Generic representation of a type in a programming language.
lldb::LanguageType GetMinimumLanguage()
ConstString GetDisplayTypeName() const
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
ConstString GetTypeName(bool BaseOnly=false) const
llvm::Expected< uint32_t > GetNumChildren(bool omit_empty_base_classes, const ExecutionContext *exe_ctx) const
A uniqued constant string class.
Definition ConstString.h:40
An data extractor class.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
virtual void CalculateExecutionContext(ExecutionContext &exe_ctx)=0
Reconstruct the object's execution context into sc.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
Process * GetProcessPtr() const
Returns a pointer to the process object.
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:90
A plug-in interface definition class for debugging a process.
Definition Process.h:356
bool IsPossibleDynamicValue(ValueObject &in_value)
Definition Process.cpp:1536
An error handling class.
Definition Status.h:118
lldb::ValueObjectSP AddressOf(Status &error) override
lldb::ValueObjectSP Dereference(Status &error) override
AddrAndType GetAddressOf(bool scalar_is_load_address=true) override
lldb::ValueObjectSP DoCast(const CompilerType &compiler_type) override
lldb::ValueObjectSP GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type, bool can_create, ConstString name_const_str=ConstString()) override
lldb::ValueObjectSP GetDynamicValue(lldb::DynamicValueType valueType) override
llvm::Expected< uint32_t > CalculateNumChildren(uint32_t max) override
Should only be called by ValueObject::GetNumChildren().
lldb::ValueType GetValueType() const override
llvm::Expected< uint64_t > GetByteSize() override
size_t GetPointeeData(DataExtractor &data, uint32_t item_idx=0, uint32_t item_count=1) override
ValueObjectConstResult(ExecutionContextScope *exe_scope, ValueObjectManager &manager, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address)
lldb::LanguageType GetPreferredDisplayLanguage() override
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.
A ValueObject that represents memory at a given address, viewed as some set lldb type.
void SetValueIsValid(bool valid)
virtual uint64_t GetData(DataExtractor &data, Status &error)
ClusterManager< ValueObject > ValueObjectManager
ValueObject(ExecutionContextScope *exe_scope, ValueObjectManager &manager, AddressType child_ptr_or_ref_addr_type=eAddressTypeLoad)
Use this constructor to create a "root variable object".
Status m_error
An error object that can describe any errors that occur when updating values.
DataExtractor m_data
A data extractor that can be used to extract the value.
lldb::LanguageType m_preferred_display_language
static ValueObjectManagerSP CreateManagerIfEmpty(ValueObjectManager *&manager)
If manager is null, makes a new ValueObjectManager and sets manager to the new ValueObjectManager.
CompilerType GetCompilerType()
std::shared_ptr< ValueObjectManager > ValueObjectManagerSP
ConstString m_name
The name of this object.
ValueObject * m_dynamic_value
const ExecutionContextRef & GetExecutionContextRef() const
void SetAddressTypeOfChildren(AddressType at)
@ HostAddress
A host address value (for memory in the process that < A is using liblldb).
Definition Value.h:52
@ FileAddress
A file address value.
Definition Value.h:47
@ LoadAddress
A load address value.
Definition Value.h:49
@ Scalar
A raw scalar value.
Definition Value.h:45
A class that represents a running process on the host machine.
@ eAddressTypeFile
Address is an address as found in an object or symbol file.
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
@ eAddressTypeHost
Address is an address in the process that is running this code.
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
ByteOrder
Byte ordering definitions.
@ eValueTypeConstResult
constant result variables
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
uint64_t addr_t
Definition lldb-types.h:80