LLDB  mainline
ValueObjectConstResultImpl.cpp
Go to the documentation of this file.
1 //===-- ValueObjectConstResultImpl.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 
11 #include "lldb/Core/Value.h"
12 #include "lldb/Core/ValueObject.h"
19 #include "lldb/Utility/Endian.h"
20 #include "lldb/Utility/Scalar.h"
21 
22 #include <string>
23 
24 namespace lldb_private {
25 class DataExtractor;
26 }
27 namespace lldb_private {
28 class Status;
29 }
30 
31 using namespace lldb;
32 using namespace lldb_private;
33 
34 ValueObjectConstResultImpl::ValueObjectConstResultImpl(
35  ValueObject *valobj, lldb::addr_t live_address)
36  : m_impl_backend(valobj), m_live_address(live_address),
37  m_live_address_type(eAddressTypeLoad), m_load_addr_backend(),
38  m_address_of_backend() {}
39 
41  if (m_impl_backend == nullptr)
42  return lldb::ValueObjectSP();
43 
44  return m_impl_backend->ValueObject::Dereference(error);
45 }
46 
48  size_t idx, bool synthetic_array_member, int32_t synthetic_index) {
49  if (m_impl_backend == nullptr)
50  return nullptr;
51 
53 
54  ValueObjectConstResultChild *valobj = nullptr;
55 
56  bool omit_empty_base_classes = true;
57  bool ignore_array_bounds = synthetic_array_member;
58  std::string child_name_str;
59  uint32_t child_byte_size = 0;
60  int32_t child_byte_offset = 0;
61  uint32_t child_bitfield_bit_size = 0;
62  uint32_t child_bitfield_bit_offset = 0;
63  bool child_is_base_class = false;
64  bool child_is_deref_of_parent = false;
65  uint64_t language_flags;
66 
67  const bool transparent_pointers = !synthetic_array_member;
68  CompilerType compiler_type = m_impl_backend->GetCompilerType();
69  CompilerType child_compiler_type;
70 
72 
73  child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex(
74  &exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
75  ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset,
76  child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
77  child_is_deref_of_parent, m_impl_backend, language_flags);
78 
79  // One might think we should check that the size of the children
80  // is always strictly positive, hence we could avoid creating a
81  // ValueObject if that's not the case, but it turns out there
82  // are languages out there which allow zero-size types with
83  // children (e.g. Swift).
84  if (child_compiler_type) {
85  if (synthetic_index)
86  child_byte_offset += child_byte_size * synthetic_index;
87 
88  ConstString child_name;
89  if (!child_name_str.empty())
90  child_name.SetCString(child_name_str.c_str());
91 
92  valobj = new ValueObjectConstResultChild(
93  *m_impl_backend, child_compiler_type, child_name, child_byte_size,
94  child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset,
95  child_is_base_class, child_is_deref_of_parent,
98  : m_live_address + child_byte_offset,
99  language_flags);
100  }
101 
102  return valobj;
103 }
104 
106  uint32_t offset, const CompilerType &type, bool can_create,
107  ConstString name_const_str) {
108  if (m_impl_backend == nullptr)
109  return lldb::ValueObjectSP();
110 
111  return m_impl_backend->ValueObject::GetSyntheticChildAtOffset(
112  offset, type, can_create, name_const_str);
113 }
114 
116  if (m_address_of_backend.get() != nullptr)
117  return m_address_of_backend;
118 
119  if (m_impl_backend == nullptr)
120  return lldb::ValueObjectSP();
122  CompilerType compiler_type(m_impl_backend->GetCompilerType());
123 
124  lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(
125  &m_live_address, sizeof(lldb::addr_t)));
126 
127  std::string new_name("&");
128  new_name.append(m_impl_backend->GetName().AsCString(""));
131  exe_ctx.GetBestExecutionContextScope(), compiler_type.GetPointerType(),
132  ConstString(new_name.c_str()), buffer, endian::InlHostByteOrder(),
133  exe_ctx.GetAddressByteSize());
134 
135  m_address_of_backend->GetValue().SetValueType(Value::ValueType::Scalar);
136  m_address_of_backend->GetValue().GetScalar() = m_live_address;
137 
138  return m_address_of_backend;
139  } else
140  return m_impl_backend->ValueObject::AddressOf(error);
141 }
142 
143 lldb::ValueObjectSP
145  if (m_impl_backend == nullptr)
146  return lldb::ValueObjectSP();
147 
148  ValueObjectConstResultCast *result_cast =
150  compiler_type, m_live_address);
151  return result_cast->GetSP();
152 }
153 
155 ValueObjectConstResultImpl::GetAddressOf(bool scalar_is_load_address,
156  AddressType *address_type) {
157 
158  if (m_impl_backend == nullptr)
159  return 0;
160 
162  return m_impl_backend->ValueObject::GetAddressOf(scalar_is_load_address,
163  address_type);
164  }
165 
166  if (address_type)
167  *address_type = m_live_address_type;
168 
169  return m_live_address;
170 }
171 
173  uint32_t item_idx,
174  uint32_t item_count) {
175  if (m_impl_backend == nullptr)
176  return 0;
177  return m_impl_backend->ValueObject::GetPointeeData(data, item_idx,
178  item_count);
179 }
lldb_private::ValueObjectConstResultImpl::AddressOf
lldb::ValueObjectSP AddressOf(Status &error)
Definition: ValueObjectConstResultImpl.cpp:115
lldb_private::ValueObjectConstResultCast
Definition: ValueObjectConstResultCast.h:28
lldb_private::Value::ValueType::Scalar
@ Scalar
A raw scalar value.
lldb_private::ExecutionContext
Definition: ExecutionContext.h:291
Scalar.h
lldb_private::ValueObjectConstResultImpl::Dereference
lldb::ValueObjectSP Dereference(Status &error)
Definition: ValueObjectConstResultImpl.cpp:40
lldb_private::ValueObjectConstResultImpl::Cast
lldb::ValueObjectSP Cast(const CompilerType &compiler_type)
Definition: ValueObjectConstResultImpl.cpp:144
lldb_private::AddressType
AddressType
Definition: lldb-private-enumerations.h:30
lldb_private::ConstString::SetCString
void SetCString(const char *cstr)
Set the C string value.
Definition: ConstString.cpp:302
lldb_private::ConstString::AsCString
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:193
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::ValueObjectConstResultChild
Definition: ValueObjectConstResultChild.h:29
ValueObjectConstResultCast.h
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
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::ValueObjectConstResultImpl::m_impl_backend
ValueObject * m_impl_backend
Definition: ValueObjectConstResultImpl.h:68
ValueObjectConstResultImpl.h
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::ExecutionContext::GetAddressByteSize
uint32_t GetAddressByteSize() const
Definition: ExecutionContext.cpp:176
lldb_private::ValueObjectConstResultImpl::m_live_address_type
AddressType m_live_address_type
Definition: ValueObjectConstResultImpl.h:70
lldb_private::ValueObjectConstResultImpl::m_live_address
lldb::addr_t m_live_address
Definition: ValueObjectConstResultImpl.h:69
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::ValueObject::GetSP
lldb::ValueObjectSP GetSP()
Definition: ValueObject.h:555
lldb_private::CompilerType::GetChildCompilerTypeAtIndex
CompilerType GetChildCompilerTypeAtIndex(ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, bool omit_empty_base_classes, bool ignore_array_bounds, std::string &child_name, uint32_t &child_byte_size, int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, bool &child_is_deref_of_parent, ValueObject *valobj, uint64_t &language_flags) const
Definition: CompilerType.cpp:602
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::ValueObjectConstResultImpl::CreateChildAtIndex
ValueObject * CreateChildAtIndex(size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Definition: ValueObjectConstResultImpl.cpp:47
lldb_private::ValueObject::UpdateValueIfNeeded
bool UpdateValueIfNeeded(bool update_format=true)
Definition: ValueObject.cpp:111
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
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:38
lldb_private::eAddressTypeLoad
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
Definition: lldb-private-enumerations.h:34
CompilerType.h
ValueObject.h
ValueObjectConstResult.h
lldb_private::Status
Definition: Status.h:44
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
lldb_private::CompilerType::GetPointerType
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
Definition: CompilerType.cpp:407
lldb_private::ValueObject::GetName
ConstString GetName() const
Definition: ValueObject.h:467
uint32_t
lldb_private::ExecutionContext::GetBestExecutionContextScope
ExecutionContextScope * GetBestExecutionContextScope() const
Definition: ExecutionContext.cpp:216
lldb_private::endian::InlHostByteOrder
lldb::ByteOrder InlHostByteOrder()
Definition: Endian.h:25
lldb_private::ValueObject::GetCompilerType
CompilerType GetCompilerType()
Definition: ValueObject.h:352
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
lldb_private::ValueObjectConstResultImpl::m_address_of_backend
lldb::ValueObjectSP m_address_of_backend
Definition: ValueObjectConstResultImpl.h:72
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
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
lldb
Definition: SBAddress.h:15
Endian.h
Value.h
ValueObjectConstResultChild.h
ExecutionContext.h
DataBufferHeap.h