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 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
70 if (!m_data.GetSharedDataBuffer()) {
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, ConstString name,
101 Module *module) {
102 auto manager_sp = ValueObjectManager::Create();
103 return (new ValueObjectConstResult(exe_scope, *manager_sp, value, name,
104 module))
105 ->GetSP();
106}
107
109 const CompilerType &compiler_type,
110 Scalar &scalar, ConstString name,
111 Module *module) {
112 auto manager_sp = ValueObjectManager::Create();
113 return (new ValueObjectConstResult(exe_scope, *manager_sp, compiler_type,
114 scalar, name, module))
115 ->GetSP();
116}
117
119 ExecutionContextScope *exe_scope, ValueObjectManager &manager,
120 const CompilerType &compiler_type, ConstString name,
121 const lldb::DataBufferSP &data_sp, lldb::ByteOrder data_byte_order,
122 uint32_t data_addr_size, lldb::addr_t address)
123 : ValueObject(exe_scope, manager), m_impl(this, address) {
124 m_data.SetByteOrder(data_byte_order);
125 m_data.SetAddressByteSize(data_addr_size);
126 m_data.SetData(data_sp);
127 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
129 m_value.SetCompilerType(compiler_type);
130 m_name = name;
132 SetValueIsValid(true);
134}
135
137 const CompilerType &compiler_type,
138 ConstString name,
139 lldb::addr_t address,
140 AddressType address_type,
141 uint32_t addr_byte_size) {
142 auto manager_sp = ValueObjectManager::Create();
143 return (new ValueObjectConstResult(exe_scope, *manager_sp, compiler_type,
144 name, address, address_type,
145 addr_byte_size))
146 ->GetSP();
147}
148
150 ExecutionContextScope *exe_scope, ValueObjectManager &manager,
151 const CompilerType &compiler_type, ConstString name, lldb::addr_t address,
152 AddressType address_type, uint32_t addr_byte_size)
153 : ValueObject(exe_scope, manager), m_type_name(), m_impl(this, address) {
154 m_value.GetScalar() = address;
155 m_data.SetAddressByteSize(addr_byte_size);
156 m_value.GetScalar().GetData(m_data, addr_byte_size);
157 // m_value.SetValueType(Value::ValueType::HostAddress);
158 switch (address_type) {
160 m_value.SetValueType(Value::ValueType::Scalar);
161 break;
162 case eAddressTypeFile:
164 break;
165 case eAddressTypeLoad:
167 break;
168 case eAddressTypeHost:
170 break;
171 }
172 m_value.SetCompilerType(compiler_type);
173 m_name = name;
175 SetValueIsValid(true);
177}
178
180 Status &&error) {
181 auto manager_sp = ValueObjectManager::Create();
182 return (new ValueObjectConstResult(exe_scope, *manager_sp, std::move(error)))
183 ->GetSP();
184}
185
187 ValueObjectManager &manager,
188 Status &&error)
189 : ValueObject(exe_scope, manager), m_impl(this) {
190 m_error = std::move(error);
192}
193
195 ValueObjectManager &manager,
196 const Value &value,
197 ConstString name, Module *module)
198 : ValueObject(exe_scope, manager), m_impl(this) {
199 m_value = value;
200 m_name = name;
201 ExecutionContext exe_ctx;
202 exe_scope->CalculateExecutionContext(exe_ctx);
203 m_error = m_value.GetValueAsData(&exe_ctx, m_data, module);
204}
205
207 ExecutionContextScope *exe_scope, ValueObjectManager &manager,
208 const CompilerType &compiler_type, const Scalar &scalar, ConstString name,
209 Module *module)
210 : ValueObject(exe_scope, manager), m_impl(this) {
211 m_value = Value(scalar);
212 m_value.SetCompilerType(compiler_type);
213 m_value.SetValueType(Value::ValueType::Scalar);
214 m_name = name;
215 ExecutionContext exe_ctx;
216 exe_scope->CalculateExecutionContext(exe_ctx);
217 m_error = m_value.GetValueAsData(&exe_ctx, m_data, module);
219 SetValueIsValid(true);
221}
222
224
228
232
233llvm::Expected<uint64_t> ValueObjectConstResult::GetByteSize() {
235 if (!m_byte_size) {
236 auto size_or_err =
238 if (!size_or_err)
239 return size_or_err;
240 SetByteSize(*size_or_err);
241 }
242 if (m_byte_size)
243 return *m_byte_size;
244 return llvm::createStringError("unknown size of const result");
245}
246
248
249llvm::Expected<uint32_t>
252 auto children_count = GetCompilerType().GetNumChildren(true, &exe_ctx);
253 if (!children_count)
254 return children_count;
255 return *children_count <= max ? *children_count : max;
256}
257
263
267
269 // Const value is always valid
270 SetValueIsValid(true);
271 return true;
272}
273
275 // A const result value is always in scope since it serializes all
276 // information needed to contain the constant value.
277 return true;
278}
279
283
285 uint32_t offset, const CompilerType &type, bool can_create,
286 ConstString name_const_str) {
287 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create,
288 name_const_str);
289}
290
294
296ValueObjectConstResult::GetAddressOf(bool scalar_is_load_address) {
297 return m_impl.GetAddressOf(scalar_is_load_address);
298}
299
301 uint32_t item_idx,
302 uint32_t item_count) {
303 return m_impl.GetPointeeData(data, item_idx, item_count);
304}
305
308 // Always recalculate dynamic values for const results as the memory that
309 // they might point to might have changed at any time.
310 if (use_dynamic != eNoDynamicValues) {
311 if (!IsDynamic()) {
313 Process *process = exe_ctx.GetProcessPtr();
314 if (process && process->IsPossibleDynamicValue(*this))
315 m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic);
316 }
317 if (m_dynamic_value && m_dynamic_value->GetError().Success())
318 return m_dynamic_value->GetSP();
319 }
320 return ValueObjectSP();
321}
322
325 return m_impl.Cast(compiler_type);
326}
327
static llvm::raw_ostream & error(Stream &strm)
static std::shared_ptr< ClusterManager > Create()
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:357
bool IsPossibleDynamicValue(ValueObject &in_value)
Definition Process.cpp:1535
An error handling class.
Definition Status.h:118
lldb::ValueObjectSP AddressOf(Status &error) 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)
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
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)
CompilerType GetCompilerType()
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
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.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
@ eValueTypeConstResult
constant result variables