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
15#include "lldb/Target/Process.h"
19#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 auto manager_sp = ValueObjectManager::Create();
34 return (new ValueObjectConstResult(exe_scope, *manager_sp, byte_order,
35 addr_byte_size, address))
36 ->GetSP();
37}
38
40 ValueObjectManager &manager,
41 ByteOrder byte_order,
42 uint32_t addr_byte_size,
43 lldb::addr_t address)
44 : ValueObject(exe_scope, manager), m_impl(this, address) {
46 SetValueIsValid(true);
47 m_data.SetByteOrder(byte_order);
48 m_data.SetAddressByteSize(addr_byte_size);
50}
51
53 const CompilerType &compiler_type,
54 ConstString name,
55 const DataExtractor &data,
56 lldb::addr_t address) {
57 auto manager_sp = ValueObjectManager::Create();
58 return (new ValueObjectConstResult(exe_scope, *manager_sp, compiler_type,
59 name, data, address))
60 ->GetSP();
61}
62
64 ExecutionContextScope *exe_scope, ValueObjectManager &manager,
65 const CompilerType &compiler_type, ConstString name,
66 const DataExtractor &data, lldb::addr_t address)
67 : ValueObject(exe_scope, manager), m_impl(this, address) {
68 m_data = data;
69
71 DataBufferSP shared_data_buffer(
72 new DataBufferHeap(data.GetDataStart(), data.GetByteSize()));
73 m_data.SetData(shared_data_buffer);
74 }
75
76 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
78 m_value.SetCompilerType(compiler_type);
79 m_name = name;
81 SetValueIsValid(true);
83}
84
86 const CompilerType &compiler_type,
87 ConstString name,
88 const lldb::DataBufferSP &data_sp,
89 lldb::ByteOrder data_byte_order,
90 uint32_t data_addr_size,
91 lldb::addr_t address) {
92 auto manager_sp = ValueObjectManager::Create();
93 return (new ValueObjectConstResult(exe_scope, *manager_sp, compiler_type,
94 name, data_sp, data_byte_order,
95 data_addr_size, address))
96 ->GetSP();
97}
98
100 Value &value,
101 ConstString name,
102 Module *module) {
103 auto manager_sp = ValueObjectManager::Create();
104 return (new ValueObjectConstResult(exe_scope, *manager_sp, value, name,
105 module))
106 ->GetSP();
107}
108
110 ExecutionContextScope *exe_scope, ValueObjectManager &manager,
111 const CompilerType &compiler_type, ConstString name,
112 const lldb::DataBufferSP &data_sp, lldb::ByteOrder data_byte_order,
113 uint32_t data_addr_size, lldb::addr_t address)
114 : ValueObject(exe_scope, manager), m_impl(this, address) {
115 m_data.SetByteOrder(data_byte_order);
116 m_data.SetAddressByteSize(data_addr_size);
117 m_data.SetData(data_sp);
118 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
120 m_value.SetCompilerType(compiler_type);
121 m_name = name;
123 SetValueIsValid(true);
125}
126
128 const CompilerType &compiler_type,
129 ConstString name,
130 lldb::addr_t address,
131 AddressType address_type,
132 uint32_t addr_byte_size) {
133 auto manager_sp = ValueObjectManager::Create();
134 return (new ValueObjectConstResult(exe_scope, *manager_sp, compiler_type,
135 name, address, address_type,
136 addr_byte_size))
137 ->GetSP();
138}
139
141 ExecutionContextScope *exe_scope, ValueObjectManager &manager,
142 const CompilerType &compiler_type, ConstString name, lldb::addr_t address,
143 AddressType address_type, uint32_t addr_byte_size)
144 : ValueObject(exe_scope, manager), m_type_name(),
145 m_impl(this, address) {
146 m_value.GetScalar() = address;
147 m_data.SetAddressByteSize(addr_byte_size);
148 m_value.GetScalar().GetData(m_data, addr_byte_size);
149 // m_value.SetValueType(Value::ValueType::HostAddress);
150 switch (address_type) {
153 break;
154 case eAddressTypeFile:
156 break;
157 case eAddressTypeLoad:
159 break;
160 case eAddressTypeHost:
162 break;
163 }
164 m_value.SetCompilerType(compiler_type);
165 m_name = name;
167 SetValueIsValid(true);
169}
170
172 const Status &error) {
173 auto manager_sp = ValueObjectManager::Create();
174 return (new ValueObjectConstResult(exe_scope, *manager_sp, error))->GetSP();
175}
176
178 ValueObjectManager &manager,
179 const Status &error)
180 : ValueObject(exe_scope, manager), m_impl(this) {
181 m_error = error;
183}
184
186 ValueObjectManager &manager,
187 const Value &value,
188 ConstString name, Module *module)
189 : ValueObject(exe_scope, manager), m_impl(this) {
190 m_value = value;
191 m_name = name;
192 ExecutionContext exe_ctx;
193 exe_scope->CalculateExecutionContext(exe_ctx);
194 m_error = m_value.GetValueAsData(&exe_ctx, m_data, module);
195}
196
198
200 return m_value.GetCompilerType();
201}
202
205}
206
207std::optional<uint64_t> ValueObjectConstResult::GetByteSize() {
209 if (!m_byte_size) {
210 if (auto size =
212 SetByteSize(*size);
213 }
214 return m_byte_size;
215}
216
218
219llvm::Expected<uint32_t>
222 auto children_count = GetCompilerType().GetNumChildren(true, &exe_ctx);
223 if (!children_count)
224 return children_count;
225 return *children_count <= max ? *children_count : max;
226}
227
229 if (m_type_name.IsEmpty())
231 return m_type_name;
232}
233
236}
237
239 // Const value is always valid
240 SetValueIsValid(true);
241 return true;
242}
243
245 // A const result value is always in scope since it serializes all
246 // information needed to contain the constant value.
247 return true;
248}
249
251 return m_impl.Dereference(error);
252}
253
255 uint32_t offset, const CompilerType &type, bool can_create,
256 ConstString name_const_str) {
257 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create,
258 name_const_str);
259}
260
262 return m_impl.AddressOf(error);
263}
264
266 AddressType *address_type) {
267 return m_impl.GetAddressOf(scalar_is_load_address, address_type);
268}
269
271 uint32_t item_idx,
272 uint32_t item_count) {
273 return m_impl.GetPointeeData(data, item_idx, item_count);
274}
275
278 // Always recalculate dynamic values for const results as the memory that
279 // they might point to might have changed at any time.
280 if (use_dynamic != eNoDynamicValues) {
281 if (!IsDynamic()) {
283 Process *process = exe_ctx.GetProcessPtr();
284 if (process && process->IsPossibleDynamicValue(*this))
285 m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic);
286 }
288 return m_dynamic_value->GetSP();
289 }
290 return ValueObjectSP();
291}
292
295 return m_impl.Cast(compiler_type);
296}
297
302}
static llvm::raw_ostream & error(Stream &strm)
static std::shared_ptr< ClusterManager > Create()
Definition: SharedCluster.h:24
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
lldb::LanguageType GetMinimumLanguage()
ConstString GetDisplayTypeName() const
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
bool IsEmpty() const
Test for empty string.
Definition: ConstString.h:304
A subclass of DataBuffer that stores a data buffer on the heap.
An data extractor class.
Definition: DataExtractor.h:48
lldb::DataBufferSP & GetSharedDataBuffer()
void SetByteOrder(lldb::ByteOrder byte_order)
Set the byte_order value.
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
const uint8_t * GetDataStart() const
Get the data start pointer.
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
void SetAddressByteSize(uint32_t addr_size)
Set the address byte size.
"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:88
A plug-in interface definition class for debugging a process.
Definition: Process.h:341
bool IsPossibleDynamicValue(ValueObject &in_value)
Definition: Process.cpp:1582
void GetBytes(llvm::MutableArrayRef< uint8_t > storage) const
Store the binary representation of this value into the given storage.
Definition: Scalar.cpp:114
bool GetData(DataExtractor &data, size_t limit_byte_size=UINT32_MAX) const
Definition: Scalar.cpp:85
An error handling class.
Definition: Status.h:44
bool Success() const
Test for success condition.
Definition: Status.cpp:278
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)
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)
A frozen ValueObject copied into host memory.
lldb::ValueObjectSP AddressOf(Status &error) override
std::optional< uint64_t > GetByteSize() override
lldb::ValueObjectSP Dereference(Status &error) override
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 DoCast(const CompilerType &compiler_type) override
lldb::addr_t GetAddressOf(bool scalar_is_load_address=true, AddressType *address_type=nullptr) 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
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
A ValueObject that represents memory at a given address, viewed as some set lldb type.
void SetValueIsValid(bool valid)
Definition: ValueObject.h:1059
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 bool IsDynamic()
Definition: ValueObject.h:683
lldb::LanguageType m_preferred_display_language
Definition: ValueObject.h:975
const Status & GetError()
ConstString m_name
The name of this object.
Definition: ValueObject.h:924
ValueObject * m_dynamic_value
Definition: ValueObject.h:956
const ExecutionContextRef & GetExecutionContextRef() const
Definition: ValueObject.h:330
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
@ HostAddress
A host address value (for memory in the process that < A is using liblldb).
@ FileAddress
A file address value.
@ LoadAddress
A load address value.
@ Scalar
A raw scalar value.
void SetCompilerType(const CompilerType &compiler_type)
Definition: Value.cpp:268
void SetValueType(ValueType value_type)
Definition: Value.h:89
const CompilerType & GetCompilerType()
Definition: Value.cpp:239
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.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:478
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:332
uint64_t addr_t
Definition: lldb-types.h:80
@ eNoDynamicValues
@ eValueTypeConstResult
constant result variables