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 
21 namespace lldb_private {
22 class Module;
23 }
24 
25 using namespace lldb;
26 using namespace lldb_private;
27 
28 ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
29  ByteOrder byte_order,
30  uint32_t addr_byte_size,
31  lldb::addr_t address) {
32  auto manager_sp = ValueObjectManager::Create();
33  return (new ValueObjectConstResult(exe_scope, *manager_sp, byte_order,
34  addr_byte_size, address))
35  ->GetSP();
36 }
37 
38 ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope,
39  ValueObjectManager &manager,
40  ByteOrder byte_order,
41  uint32_t addr_byte_size,
42  lldb::addr_t address)
43  : ValueObject(exe_scope, manager), m_impl(this, address) {
44  SetIsConstant();
45  SetValueIsValid(true);
46  m_data.SetByteOrder(byte_order);
47  m_data.SetAddressByteSize(addr_byte_size);
49 }
50 
52  const CompilerType &compiler_type,
53  ConstString name,
54  const DataExtractor &data,
55  lldb::addr_t address) {
56  auto manager_sp = ValueObjectManager::Create();
57  return (new ValueObjectConstResult(exe_scope, *manager_sp, compiler_type,
58  name, data, address))
59  ->GetSP();
60 }
61 
63  ExecutionContextScope *exe_scope, ValueObjectManager &manager,
64  const CompilerType &compiler_type, ConstString name,
65  const DataExtractor &data, lldb::addr_t address)
66  : ValueObject(exe_scope, manager), m_impl(this, address) {
67  m_data = data;
68 
69  if (!m_data.GetSharedDataBuffer()) {
70  DataBufferSP shared_data_buffer(
71  new DataBufferHeap(data.GetDataStart(), data.GetByteSize()));
72  m_data.SetData(shared_data_buffer);
73  }
74 
75  m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
77  m_value.SetCompilerType(compiler_type);
78  m_name = name;
79  SetIsConstant();
80  SetValueIsValid(true);
82 }
83 
85  const CompilerType &compiler_type,
86  ConstString name,
87  const lldb::DataBufferSP &data_sp,
88  lldb::ByteOrder data_byte_order,
89  uint32_t data_addr_size,
90  lldb::addr_t address) {
91  auto manager_sp = ValueObjectManager::Create();
92  return (new ValueObjectConstResult(exe_scope, *manager_sp, compiler_type,
93  name, data_sp, data_byte_order,
94  data_addr_size, address))
95  ->GetSP();
96 }
97 
99  Value &value,
100  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  ExecutionContextScope *exe_scope, ValueObjectManager &manager,
110  const CompilerType &compiler_type, ConstString name,
111  const lldb::DataBufferSP &data_sp, lldb::ByteOrder data_byte_order,
112  uint32_t data_addr_size, lldb::addr_t address)
113  : ValueObject(exe_scope, manager), m_impl(this, address) {
114  m_data.SetByteOrder(data_byte_order);
115  m_data.SetAddressByteSize(data_addr_size);
116  m_data.SetData(data_sp);
117  m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
119  m_value.SetCompilerType(compiler_type);
120  m_name = name;
121  SetIsConstant();
122  SetValueIsValid(true);
124 }
125 
127  const CompilerType &compiler_type,
128  ConstString name,
129  lldb::addr_t address,
130  AddressType address_type,
131  uint32_t addr_byte_size) {
132  auto manager_sp = ValueObjectManager::Create();
133  return (new ValueObjectConstResult(exe_scope, *manager_sp, compiler_type,
134  name, address, address_type,
135  addr_byte_size))
136  ->GetSP();
137 }
138 
140  ExecutionContextScope *exe_scope, ValueObjectManager &manager,
141  const CompilerType &compiler_type, ConstString name, lldb::addr_t address,
142  AddressType address_type, uint32_t addr_byte_size)
143  : ValueObject(exe_scope, manager), m_type_name(),
144  m_impl(this, address) {
145  m_value.GetScalar() = address;
146  m_data.SetAddressByteSize(addr_byte_size);
147  m_value.GetScalar().GetData(m_data, addr_byte_size);
148  // m_value.SetValueType(Value::ValueType::HostAddress);
149  switch (address_type) {
150  case eAddressTypeInvalid:
152  break;
153  case eAddressTypeFile:
155  break;
156  case eAddressTypeLoad:
158  break;
159  case eAddressTypeHost:
161  break;
162  }
163  m_value.SetCompilerType(compiler_type);
164  m_name = name;
165  SetIsConstant();
166  SetValueIsValid(true);
168 }
169 
171  const Status &error) {
172  auto manager_sp = ValueObjectManager::Create();
173  return (new ValueObjectConstResult(exe_scope, *manager_sp, error))->GetSP();
174 }
175 
177  ValueObjectManager &manager,
178  const Status &error)
179  : ValueObject(exe_scope, manager), m_impl(this) {
180  m_error = error;
181  SetIsConstant();
182 }
183 
185  ValueObjectManager &manager,
186  const Value &value,
187  ConstString name, Module *module)
188  : ValueObject(exe_scope, manager), m_impl(this) {
189  m_value = value;
190  m_name = name;
191  ExecutionContext exe_ctx;
192  exe_scope->CalculateExecutionContext(exe_ctx);
193  m_error = m_value.GetValueAsData(&exe_ctx, m_data, module);
194 }
195 
197 
199  return m_value.GetCompilerType();
200 }
201 
203  return eValueTypeConstResult;
204 }
205 
206 llvm::Optional<uint64_t> ValueObjectConstResult::GetByteSize() {
208  if (!m_byte_size) {
209  if (auto size =
211  SetByteSize(*size);
212  }
213  return m_byte_size;
214 }
215 
217 
220  auto children_count = GetCompilerType().GetNumChildren(true, &exe_ctx);
221  return children_count <= max ? children_count : max;
222 }
223 
225  if (m_type_name.IsEmpty())
227  return m_type_name;
228 }
229 
232 }
233 
235  // Const value is always valid
236  SetValueIsValid(true);
237  return true;
238 }
239 
241  // A const result value is always in scope since it serializes all
242  // information needed to contain the constant value.
243  return true;
244 }
245 
247  return m_impl.Dereference(error);
248 }
249 
251  uint32_t offset, const CompilerType &type, bool can_create,
252  ConstString name_const_str) {
253  return m_impl.GetSyntheticChildAtOffset(offset, type, can_create,
254  name_const_str);
255 }
256 
258  return m_impl.AddressOf(error);
259 }
260 
262  AddressType *address_type) {
263  return m_impl.GetAddressOf(scalar_is_load_address, address_type);
264 }
265 
267  size_t idx, bool synthetic_array_member, int32_t synthetic_index) {
268  return m_impl.CreateChildAtIndex(idx, synthetic_array_member,
269  synthetic_index);
270 }
271 
273  uint32_t item_idx,
274  uint32_t item_count) {
275  return m_impl.GetPointeeData(data, item_idx, item_count);
276 }
277 
278 lldb::ValueObjectSP
280  // Always recalculate dynamic values for const results as the memory that
281  // they might point to might have changed at any time.
282  if (use_dynamic != eNoDynamicValues) {
283  if (!IsDynamic()) {
285  Process *process = exe_ctx.GetProcessPtr();
286  if (process && process->IsPossibleDynamicValue(*this))
287  m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic);
288  }
289  if (m_dynamic_value)
290  return m_dynamic_value->GetSP();
291  }
292  return ValueObjectSP();
293 }
294 
295 lldb::ValueObjectSP
297  return m_impl.Cast(compiler_type);
298 }
299 
304 }
lldb_private::ValueObjectConstResult::GetDisplayTypeName
ConstString GetDisplayTypeName() override
Definition: ValueObjectConstResult.cpp:230
lldb_private::ValueObjectConstResultImpl::AddressOf
lldb::ValueObjectSP AddressOf(Status &error)
Definition: ValueObjectConstResultImpl.cpp:115
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::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:296
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:495
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:208
lldb_private::Value::GetValueAsData
Status GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, Module *module)
Definition: Value.cpp:301
lldb_private::ValueObjectConstResultImpl::Cast
lldb::ValueObjectSP Cast(const CompilerType &compiler_type)
Definition: ValueObjectConstResultImpl.cpp:144
lldb_private::Value::ValueType::FileAddress
@ FileAddress
A file address value.
lldb_private::ValueObjectConstResult::GetPreferredDisplayLanguage
lldb::LanguageType GetPreferredDisplayLanguage() override
Definition: ValueObjectConstResult.cpp:300
lldb_private::AddressType
AddressType
Definition: lldb-private-enumerations.h:30
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:341
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:436
lldb_private::ValueObjectConstResult::GetAddressOf
lldb::addr_t GetAddressOf(bool scalar_is_load_address=true, AddressType *address_type=nullptr) override
Definition: ValueObjectConstResult.cpp:261
lldb_private::Module
Definition: Module.h:84
lldb_private::ValueObjectConstResultImpl::GetSyntheticChildAtOffset
lldb::ValueObjectSP GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type, bool can_create, ConstString name_const_str=ConstString())
Definition: ValueObjectConstResultImpl.cpp:105
lldb_private::ValueObjectConstResult::GetValueType
lldb::ValueType GetValueType() const override
Definition: ValueObjectConstResult.cpp:202
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:33
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:172
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:225
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:254
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:240
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::ValueObjectConstResult::GetCompilerTypeImpl
CompilerType GetCompilerTypeImpl() override
Definition: ValueObjectConstResult.cpp:198
lldb_private::CompilerType::GetDisplayTypeName
ConstString GetDisplayTypeName() const
Definition: CompilerType.cpp:284
lldb_private::ValueObjectConstResult::AddressOf
lldb::ValueObjectSP AddressOf(Status &error) override
Definition: ValueObjectConstResult.cpp:257
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:304
lldb_private::ValueObject::GetSP
lldb::ValueObjectSP GetSP()
Definition: ValueObject.h:555
lldb_private::ValueObjectConstResult::SetByteSize
void SetByteSize(size_t size)
Definition: ValueObjectConstResult.cpp:216
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:118
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::ValueObjectConstResult::CalculateNumChildren
size_t CalculateNumChildren(uint32_t max) override
Should only be called by ValueObject::GetNumChildren().
Definition: ValueObjectConstResult.cpp:218
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:494
lldb_private::ValueObjectConstResultImpl::GetAddressOf
virtual lldb::addr_t GetAddressOf(bool scalar_is_load_address=true, AddressType *address_type=nullptr)
Definition: ValueObjectConstResultImpl.cpp:155
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:115
lldb_private::CompilerType::GetNumChildren
uint32_t GetNumChildren(bool omit_empty_base_classes, const ExecutionContext *exe_ctx) const
Definition: CompilerType.cpp:515
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:266
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:250
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:315
lldb::eLanguageTypeUnknown
@ eLanguageTypeUnknown
Unknown or invalid language value.
Definition: lldb-enumerations.h:437
uint32_t
lldb_private::ExecutionContext::GetBestExecutionContextScope
ExecutionContextScope * GetBestExecutionContextScope() const
Definition: ExecutionContext.cpp:216
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::CompilerType::GetTypeName
ConstString GetTypeName() const
Definition: CompilerType.cpp:277
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::GetByteSize
llvm::Optional< uint64_t > GetByteSize() override
Definition: ValueObjectConstResult.cpp:206
lldb_private::ValueObjectConstResult
A frozen ValueObject copied into host memory.
Definition: ValueObjectConstResult.h:33
DataExtractor.h
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
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:28
lldb_private::Value::GetCompilerType
const CompilerType & GetCompilerType()
Definition: Value.cpp:225
lldb_private::ValueObjectConstResult::GetPointeeData
size_t GetPointeeData(DataExtractor &data, uint32_t item_idx=0, uint32_t item_count=1) override
Definition: ValueObjectConstResult.cpp:272
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:323
lldb_private::CompilerType::GetMinimumLanguage
lldb::LanguageType GetMinimumLanguage()
Definition: CompilerType.cpp:298
lldb_private::ValueObjectConstResult::m_byte_size
llvm::Optional< uint64_t > m_byte_size
Definition: ValueObjectConstResult.h:116
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:279
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:38
lldb_private::ValueObjectConstResult::UpdateValue
bool UpdateValue() override
Definition: ValueObjectConstResult.cpp:234
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
lldb_private::ValueObjectConstResult::Dereference
lldb::ValueObjectSP Dereference(Status &error) override
Definition: ValueObjectConstResult.cpp:246
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:138
lldb_private::ValueObjectConstResult::~ValueObjectConstResult
~ValueObjectConstResult() override
lldb_private::ValueObjectConstResult::GetTypeName
ConstString GetTypeName() override
Definition: ValueObjectConstResult.cpp:224