Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 1 | //===-- ValueObjectConstResultImpl.cpp ---------------------------*- C++-*-===// |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/Core/ValueObjectConstResultImpl.h" |
| 11 | |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Value.h" // for Value, Value::Val... |
| 13 | #include "lldb/Core/ValueObject.h" // for ValueObject |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 14 | #include "lldb/Core/ValueObjectConstResult.h" |
Siva Chandra | f8877ef | 2015-07-16 01:47:12 +0000 | [diff] [blame] | 15 | #include "lldb/Core/ValueObjectConstResultCast.h" |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 16 | #include "lldb/Core/ValueObjectConstResultChild.h" |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 17 | #include "lldb/Symbol/CompilerType.h" |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 18 | #include "lldb/Target/ExecutionContext.h" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 19 | #include "lldb/Utility/DataBufferHeap.h" // for DataBufferHeap |
| 20 | #include "lldb/Utility/Endian.h" // for InlHostByteOrder |
Pavel Labath | d821c99 | 2018-08-07 11:07:21 +0000 | [diff] [blame] | 21 | #include "lldb/Utility/Scalar.h" // for Scalar |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 22 | #include "lldb/Utility/SharingPtr.h" // for SharingPtr |
| 23 | |
| 24 | #include <string> // for string |
| 25 | |
| 26 | namespace lldb_private { |
| 27 | class DataExtractor; |
| 28 | } |
| 29 | namespace lldb_private { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 30 | class Status; |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 31 | } |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 32 | |
| 33 | using namespace lldb; |
| 34 | using namespace lldb_private; |
| 35 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 36 | ValueObjectConstResultImpl::ValueObjectConstResultImpl( |
| 37 | ValueObject *valobj, lldb::addr_t live_address) |
| 38 | : m_impl_backend(valobj), m_live_address(live_address), |
| 39 | m_live_address_type(eAddressTypeLoad), m_load_addr_backend(), |
| 40 | m_address_of_backend() {} |
| 41 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 42 | lldb::ValueObjectSP ValueObjectConstResultImpl::Dereference(Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 43 | if (m_impl_backend == NULL) |
| 44 | return lldb::ValueObjectSP(); |
| 45 | |
| 46 | return m_impl_backend->ValueObject::Dereference(error); |
| 47 | } |
| 48 | |
| 49 | ValueObject *ValueObjectConstResultImpl::CreateChildAtIndex( |
| 50 | size_t idx, bool synthetic_array_member, int32_t synthetic_index) { |
| 51 | if (m_impl_backend == NULL) |
| 52 | return NULL; |
| 53 | |
| 54 | m_impl_backend->UpdateValueIfNeeded(false); |
| 55 | |
| 56 | ValueObjectConstResultChild *valobj = NULL; |
| 57 | |
| 58 | bool omit_empty_base_classes = true; |
| 59 | bool ignore_array_bounds = synthetic_array_member; |
| 60 | std::string child_name_str; |
| 61 | uint32_t child_byte_size = 0; |
| 62 | int32_t child_byte_offset = 0; |
| 63 | uint32_t child_bitfield_bit_size = 0; |
| 64 | uint32_t child_bitfield_bit_offset = 0; |
| 65 | bool child_is_base_class = false; |
| 66 | bool child_is_deref_of_parent = false; |
| 67 | uint64_t language_flags; |
| 68 | |
| 69 | const bool transparent_pointers = synthetic_array_member == false; |
| 70 | CompilerType compiler_type = m_impl_backend->GetCompilerType(); |
| 71 | CompilerType child_compiler_type; |
| 72 | |
| 73 | ExecutionContext exe_ctx(m_impl_backend->GetExecutionContextRef()); |
| 74 | |
| 75 | child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex( |
| 76 | &exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 77 | ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset, |
| 78 | child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, |
| 79 | child_is_deref_of_parent, m_impl_backend, language_flags); |
Davide Italiano | 70152d3 | 2018-10-23 00:31:46 +0000 | [diff] [blame] | 80 | |
| 81 | // One might think we should check that the size of the children |
| 82 | // is always strictly positive, hence we could avoid creating a |
| 83 | // ValueObject if that's not the case, but it turns out there |
| 84 | // are languages out there which allow zero-size types with |
| 85 | // children (e.g. Swift). |
| 86 | if (child_compiler_type) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 87 | if (synthetic_index) |
| 88 | child_byte_offset += child_byte_size * synthetic_index; |
| 89 | |
| 90 | ConstString child_name; |
| 91 | if (!child_name_str.empty()) |
| 92 | child_name.SetCString(child_name_str.c_str()); |
| 93 | |
| 94 | valobj = new ValueObjectConstResultChild( |
| 95 | *m_impl_backend, child_compiler_type, child_name, child_byte_size, |
| 96 | child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, |
| 97 | child_is_base_class, child_is_deref_of_parent, |
| 98 | m_live_address == LLDB_INVALID_ADDRESS |
| 99 | ? m_live_address |
| 100 | : m_live_address + child_byte_offset, |
| 101 | language_flags); |
| 102 | } |
| 103 | |
| 104 | return valobj; |
| 105 | } |
| 106 | |
| 107 | lldb::ValueObjectSP ValueObjectConstResultImpl::GetSyntheticChildAtOffset( |
| 108 | uint32_t offset, const CompilerType &type, bool can_create, |
| 109 | ConstString name_const_str) { |
| 110 | if (m_impl_backend == NULL) |
| 111 | return lldb::ValueObjectSP(); |
| 112 | |
| 113 | return m_impl_backend->ValueObject::GetSyntheticChildAtOffset( |
| 114 | offset, type, can_create, name_const_str); |
| 115 | } |
| 116 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 117 | lldb::ValueObjectSP ValueObjectConstResultImpl::AddressOf(Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 118 | if (m_address_of_backend.get() != NULL) |
| 119 | return m_address_of_backend; |
| 120 | |
| 121 | if (m_impl_backend == NULL) |
| 122 | return lldb::ValueObjectSP(); |
| 123 | if (m_live_address != LLDB_INVALID_ADDRESS) { |
| 124 | CompilerType compiler_type(m_impl_backend->GetCompilerType()); |
| 125 | |
| 126 | lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap( |
| 127 | &m_live_address, sizeof(lldb::addr_t))); |
| 128 | |
| 129 | std::string new_name("&"); |
| 130 | new_name.append(m_impl_backend->GetName().AsCString("")); |
| 131 | ExecutionContext exe_ctx(m_impl_backend->GetExecutionContextRef()); |
| 132 | m_address_of_backend = ValueObjectConstResult::Create( |
| 133 | exe_ctx.GetBestExecutionContextScope(), compiler_type.GetPointerType(), |
| 134 | ConstString(new_name.c_str()), buffer, endian::InlHostByteOrder(), |
| 135 | exe_ctx.GetAddressByteSize()); |
| 136 | |
| 137 | m_address_of_backend->GetValue().SetValueType(Value::eValueTypeScalar); |
| 138 | m_address_of_backend->GetValue().GetScalar() = m_live_address; |
| 139 | |
| 140 | return m_address_of_backend; |
| 141 | } else |
| 142 | return m_impl_backend->ValueObject::AddressOf(error); |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | lldb::ValueObjectSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 146 | ValueObjectConstResultImpl::Cast(const CompilerType &compiler_type) { |
| 147 | if (m_impl_backend == NULL) |
| 148 | return lldb::ValueObjectSP(); |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 149 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 150 | ValueObjectConstResultCast *result_cast = |
| 151 | new ValueObjectConstResultCast(*m_impl_backend, m_impl_backend->GetName(), |
| 152 | compiler_type, m_live_address); |
| 153 | return result_cast->GetSP(); |
Siva Chandra | f8877ef | 2015-07-16 01:47:12 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Johnny Chen | b456b79 | 2011-12-16 23:04:52 +0000 | [diff] [blame] | 156 | lldb::addr_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 157 | ValueObjectConstResultImpl::GetAddressOf(bool scalar_is_load_address, |
| 158 | AddressType *address_type) { |
| 159 | |
| 160 | if (m_impl_backend == NULL) |
| 161 | return 0; |
| 162 | |
| 163 | if (m_live_address == LLDB_INVALID_ADDRESS) { |
| 164 | return m_impl_backend->ValueObject::GetAddressOf(scalar_is_load_address, |
| 165 | address_type); |
| 166 | } |
| 167 | |
| 168 | if (address_type) |
| 169 | *address_type = m_live_address_type; |
| 170 | |
| 171 | return m_live_address; |
Johnny Chen | b456b79 | 2011-12-16 23:04:52 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 174 | size_t ValueObjectConstResultImpl::GetPointeeData(DataExtractor &data, |
| 175 | uint32_t item_idx, |
| 176 | uint32_t item_count) { |
| 177 | if (m_impl_backend == NULL) |
| 178 | return 0; |
| 179 | return m_impl_backend->ValueObject::GetPointeeData(data, item_idx, |
| 180 | item_count); |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 181 | } |