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 
22 namespace lldb_private {
23 class Module;
24 }
25 
26 using namespace lldb;
27 using namespace lldb_private;
28 
29 ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
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 
39 ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope,
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) {
45  SetIsConstant();
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;
80  SetIsConstant();
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;
122  SetIsConstant();
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) {
151  case eAddressTypeInvalid:
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;
166  SetIsConstant();
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;
182  SetIsConstant();
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 
204  return eValueTypeConstResult;
205 }
206 
207 std::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 
221  auto children_count = GetCompilerType().GetNumChildren(true, &exe_ctx);
222  return children_count <= max ? children_count : max;
223 }
224 
226  if (m_type_name.IsEmpty())
228  return m_type_name;
229 }
230 
233 }
234 
236  // Const value is always valid
237  SetValueIsValid(true);
238  return true;
239 }
240 
242  // A const result value is always in scope since it serializes all
243  // information needed to contain the constant value.
244  return true;
245 }
246 
248  return m_impl.Dereference(error);
249 }
250 
252  uint32_t offset, const CompilerType &type, bool can_create,
253  ConstString name_const_str) {
254  return m_impl.GetSyntheticChildAtOffset(offset, type, can_create,
255  name_const_str);
256 }
257 
259  return m_impl.AddressOf(error);
260 }
261 
263  AddressType *address_type) {
264  return m_impl.GetAddressOf(scalar_is_load_address, address_type);
265 }
266 
268  size_t idx, bool synthetic_array_member, int32_t synthetic_index) {
269  return m_impl.CreateChildAtIndex(idx, synthetic_array_member,
270  synthetic_index);
271 }
272 
274  uint32_t item_idx,
275  uint32_t item_count) {
276  return m_impl.GetPointeeData(data, item_idx, item_count);
277 }
278 
279 lldb::ValueObjectSP
281  // Always recalculate dynamic values for const results as the memory that
282  // they might point to might have changed at any time.
283  if (use_dynamic != eNoDynamicValues) {
284  if (!IsDynamic()) {
286  Process *process = exe_ctx.GetProcessPtr();
287  if (process && process->IsPossibleDynamicValue(*this))
288  m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic);
289  }
290  if (m_dynamic_value)
291  return m_dynamic_value->GetSP();
292  }
293  return ValueObjectSP();
294 }
295 
296 lldb::ValueObjectSP
298  return m_impl.Cast(compiler_type);
299 }
300 
305 }
lldb_private::ValueObjectConstResult::GetDisplayTypeName
ConstString GetDisplayTypeName() override
Definition: ValueObjectConstResult.cpp:231
lldb_private::ValueObjectConstResultImpl::AddressOf
lldb::ValueObjectSP AddressOf(Status &error)
Definition: ValueObjectConstResultImpl.cpp:122
lldb_private::DataExtractor::GetSharedDataBuffer
lldb::DataBufferSP & GetSharedDataBuffer()
Definition: DataExtractor.h:807
lldb_private::Value::ValueType::Scalar
@ Scalar
A raw scalar value.
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
Scalar.h
lldb_private::ValueObjectConstResult::GetByteSize
std::optional< uint64_t > GetByteSize() override
Definition: ValueObjectConstResult.cpp:207
lldb_private::ValueObject::SetValueIsValid
void SetValueIsValid(bool valid)
Definition: ValueObject.h:980
lldb_private::ValueObjectConstResult::Cast
lldb::ValueObjectSP Cast(const CompilerType &compiler_type) override
Definition: ValueObjectConstResult.cpp:297
lldb_private::Scalar::GetData
bool GetData(DataExtractor &data, size_t limit_byte_size=UINT32_MAX) const
Definition: Scalar.cpp:84
lldb_private::ValueObjectConstResultImpl::Dereference
lldb::ValueObjectSP Dereference(Status &error)
Definition: ValueObjectConstResultImpl.cpp:40
lldb_private::ValueObject::IsDynamic
virtual bool IsDynamic()
Definition: ValueObject.h:637
lldb_private::Value
Definition: Value.h:38
lldb::eNoDynamicValues
@ eNoDynamicValues
Definition: lldb-enumerations.h:502
lldb_private::Value::SetValueType
void SetValueType(ValueType value_type)
Definition: Value.h:89
lldb_private::ExecutionContext::GetProcessPtr
Process * GetProcessPtr() const
Returns a pointer to the process object.
Definition: ExecutionContext.cpp:206
lldb_private::Value::GetValueAsData
Status GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, Module *module)
Definition: Value.cpp:299
lldb_private::ValueObjectConstResultImpl::Cast
lldb::ValueObjectSP Cast(const CompilerType &compiler_type)
Definition: ValueObjectConstResultImpl.cpp:151
lldb_private::Value::ValueType::FileAddress
@ FileAddress
A file address value.
lldb_private::ValueObjectConstResult::GetPreferredDisplayLanguage
lldb::LanguageType GetPreferredDisplayLanguage() override
Definition: ValueObjectConstResult.cpp:301
lldb_private::AddressType
AddressType
Definition: lldb-private-enumerations.h:30
lldb_private::CompilerType::GetTypeName
ConstString GetTypeName(bool BaseOnly=false) const
Definition: CompilerType.cpp:322
lldb_private::ValueObject::m_name
ConstString m_name
The name of this object.
Definition: ValueObject.h:849
lldb_private::ClusterManager
Definition: SharedCluster.h:22
lldb_private::Process
Definition: Process.h:338
lldb_private::eAddressTypeHost
@ eAddressTypeHost
Address is an address in the process that is running this code.
Definition: lldb-private-enumerations.h:36
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:443
lldb_private::ValueObjectConstResult::GetAddressOf
lldb::addr_t GetAddressOf(bool scalar_is_load_address=true, AddressType *address_type=nullptr) override
Definition: ValueObjectConstResult.cpp:262
lldb_private::Module
Definition: Module.h:87
lldb_private::ValueObjectConstResultImpl::GetSyntheticChildAtOffset
lldb::ValueObjectSP GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type, bool can_create, ConstString name_const_str=ConstString())
Definition: ValueObjectConstResultImpl.cpp:112
lldb_private::ValueObjectConstResult::GetValueType
lldb::ValueType GetValueType() const override
Definition: ValueObjectConstResult.cpp:203
lldb_private::Value::ValueType::LoadAddress
@ LoadAddress
A load address value.
lldb_private::ValueObjectDynamicValue
A ValueObject that represents memory at a given address, viewed as some set lldb type.
Definition: ValueObjectDynamicValue.h:34
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::ValueObject::m_preferred_display_language
lldb::LanguageType m_preferred_display_language
Definition: ValueObject.h:900
ValueObjectDynamicValue.h
lldb_private::ValueObjectConstResultImpl::GetPointeeData
virtual size_t GetPointeeData(DataExtractor &data, uint32_t item_idx=0, uint32_t item_count=1)
Definition: ValueObjectConstResultImpl.cpp:179
lldb_private::DataExtractor::SetData
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
Definition: DataExtractor.cpp:223
Process.h
lldb_private::ValueObject::SetIsConstant
void SetIsConstant()
Definition: ValueObject.h:701
lldb_private::Value::SetCompilerType
void SetCompilerType(const CompilerType &compiler_type)
Definition: Value.cpp:252
lldb_private::ValueObject::m_data
DataExtractor m_data
A data extractor that can be used to extract the value.
Definition: ValueObject.h:851
lldb_private::DataExtractor::SetByteOrder
void SetByteOrder(lldb::ByteOrder byte_order)
Set the byte_order value.
Definition: DataExtractor.h:931
lldb_private::Value::GetScalar
const Scalar & GetScalar() const
Definition: Value.h:112
lldb_private::ValueObjectConstResult::IsInScope
bool IsInScope() override
Definition: ValueObjectConstResult.cpp:241
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::ValueObjectConstResult::GetCompilerTypeImpl
CompilerType GetCompilerTypeImpl() override
Definition: ValueObjectConstResult.cpp:199
lldb_private::CompilerType::GetDisplayTypeName
ConstString GetDisplayTypeName() const
Definition: CompilerType.cpp:330
lldb_private::ValueObjectConstResult::AddressOf
lldb::ValueObjectSP AddressOf(Status &error) override
Definition: ValueObjectConstResult.cpp:258
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::eAddressTypeInvalid
@ eAddressTypeInvalid
Definition: lldb-private-enumerations.h:31
lldb_private::ExecutionContextScope
Definition: ExecutionContextScope.h:32
lldb_private::ConstString::IsEmpty
bool IsEmpty() const
Test for empty string.
Definition: ConstString.h:303
lldb_private::ValueObject::GetSP
lldb::ValueObjectSP GetSP()
Definition: ValueObject.h:555
lldb_private::ValueObjectConstResult::SetByteSize
void SetByteSize(size_t size)
Definition: ValueObjectConstResult.cpp:217
lldb_private::ValueObject::SetAddressTypeOfChildren
void SetAddressTypeOfChildren(AddressType at)
Definition: ValueObject.h:759
lldb_private::DataExtractor::SetAddressByteSize
void SetAddressByteSize(uint32_t addr_size)
Set the address byte size.
Definition: DataExtractor.h:845
lldb_private::DataExtractor::GetDataStart
const uint8_t * GetDataStart() const
Get the data start pointer.
Definition: DataExtractor.h:422
lldb_private::ValueObjectConstResult::m_impl
ValueObjectConstResultImpl m_impl
Definition: ValueObjectConstResult.h:119
lldb_private::ConstString
Definition: ConstString.h:39
lldb_private::ValueObjectConstResult::CalculateNumChildren
size_t CalculateNumChildren(uint32_t max) override
Should only be called by ValueObject::GetNumChildren().
Definition: ValueObjectConstResult.cpp:219
lldb_private::ValueObjectConstResultImpl::CreateChildAtIndex
ValueObject * CreateChildAtIndex(size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Definition: ValueObjectConstResultImpl.cpp:47
lldb_private::Scalar::GetBytes
void GetBytes(llvm::MutableArrayRef< uint8_t > storage) const
Store the binary representation of this value into the given storage.
Definition: Scalar.cpp:113
lldb::DynamicValueType
DynamicValueType
Definition: lldb-enumerations.h:501
lldb_private::ValueObjectConstResultImpl::GetAddressOf
virtual lldb::addr_t GetAddressOf(bool scalar_is_load_address=true, AddressType *address_type=nullptr)
Definition: ValueObjectConstResultImpl.cpp:162
lldb_private::ValueObject::GetExecutionContextRef
const ExecutionContextRef & GetExecutionContextRef() const
Definition: ValueObject.h:330
lldb_private::eAddressTypeLoad
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
Definition: lldb-private-enumerations.h:34
CompilerType.h
lldb_private::ValueObjectConstResult::m_type_name
ConstString m_type_name
Definition: ValueObjectConstResult.h:116
lldb_private::CompilerType::GetNumChildren
uint32_t GetNumChildren(bool omit_empty_base_classes, const ExecutionContext *exe_ctx) const
Definition: CompilerType.cpp:588
ValueObjectConstResult.h
lldb_private::ValueObjectConstResult::CreateChildAtIndex
ValueObject * CreateChildAtIndex(size_t idx, bool synthetic_array_member, int32_t synthetic_index) override
Should only be called by ValueObject::GetChildAtIndex().
Definition: ValueObjectConstResult.cpp:267
lldb_private::ValueObjectConstResult::GetSyntheticChildAtOffset
lldb::ValueObjectSP GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type, bool can_create, ConstString name_const_str=ConstString()) override
Definition: ValueObjectConstResult.cpp:251
lldb_private::Process::IsPossibleDynamicValue
bool IsPossibleDynamicValue(ValueObject &in_value)
Definition: Process.cpp:1541
lldb_private::Status
Definition: Status.h:44
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
lldb::ValueType
ValueType
Definition: lldb-enumerations.h:316
lldb_private::ValueObjectConstResult::m_byte_size
std::optional< uint64_t > m_byte_size
Definition: ValueObjectConstResult.h:117
lldb::eLanguageTypeUnknown
@ eLanguageTypeUnknown
Unknown or invalid language value.
Definition: lldb-enumerations.h:444
uint32_t
lldb_private::ExecutionContext::GetBestExecutionContextScope
ExecutionContextScope * GetBestExecutionContextScope() const
Definition: ExecutionContext.cpp:214
lldb_private::ValueObject::m_value
Value m_value
Definition: ValueObject.h:852
lldb_private::Value::ValueType::HostAddress
@ HostAddress
A host address value (for memory in the process that < A is using liblldb).
lldb_private::eAddressTypeFile
@ eAddressTypeFile
Address is an address as found in an object or symbol file.
Definition: lldb-private-enumerations.h:32
ExecutionContextScope.h
lldb_private::ValueObject::GetCompilerType
CompilerType GetCompilerType()
Definition: ValueObject.h:352
lldb_private::ValueObjectConstResult
A frozen ValueObject copied into host memory.
Definition: ValueObjectConstResult.h:34
DataExtractor.h
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
lldb_private::ValueObjectConstResult::Create
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address=LLDB_INVALID_ADDRESS)
Definition: ValueObjectConstResult.cpp:29
lldb_private::Value::GetCompilerType
const CompilerType & GetCompilerType()
Definition: Value.cpp:223
lldb_private::ValueObjectConstResult::GetPointeeData
size_t GetPointeeData(DataExtractor &data, uint32_t item_idx=0, uint32_t item_count=1) override
Definition: ValueObjectConstResult.cpp:273
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::eValueTypeConstResult
@ eValueTypeConstResult
constant result variables
Definition: lldb-enumerations.h:324
lldb_private::CompilerType::GetMinimumLanguage
lldb::LanguageType GetMinimumLanguage()
Definition: CompilerType.cpp:346
lldb_private::ValueObject::m_dynamic_value
ValueObject * m_dynamic_value
Definition: ValueObject.h:881
lldb_private::ValueObject::m_error
Status m_error
An error object that can describe any errors that occur when updating values.
Definition: ValueObject.h:855
lldb_private::ValueObjectConstResult::GetDynamicValue
lldb::ValueObjectSP GetDynamicValue(lldb::DynamicValueType valueType) override
Definition: ValueObjectConstResult.cpp:280
lldb_private::ExecutionContextScope::CalculateExecutionContext
virtual void CalculateExecutionContext(ExecutionContext &exe_ctx)=0
Reconstruct the object's execution context into sc.
DataBuffer.h
lldb_private::DataExtractor::GetByteSize
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
Definition: DataExtractor.h:270
lldb_private::ValueObjectConstResult::ValueObjectConstResult
ValueObjectConstResult(ExecutionContextScope *exe_scope, ValueObjectManager &manager, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address)
Definition: ValueObjectConstResult.cpp:39
lldb_private::ValueObjectConstResult::UpdateValue
bool UpdateValue() override
Definition: ValueObjectConstResult.cpp:235
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
lldb_private::ValueObjectConstResult::Dereference
lldb::ValueObjectSP Dereference(Status &error) override
Definition: ValueObjectConstResult.cpp:247
lldb
Definition: SBAddress.h:15
ExecutionContext.h
DataBufferHeap.h
lldb_private::ClusterManager::Create
static std::shared_ptr< ClusterManager > Create()
Definition: SharedCluster.h:24
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:139
lldb_private::ValueObjectConstResult::~ValueObjectConstResult
~ValueObjectConstResult() override
lldb_private::ValueObjectConstResult::GetTypeName
ConstString GetTypeName() override
Definition: ValueObjectConstResult.cpp:225