Coverage Report

Created: 2023-09-21 18:56

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Core/ValueObjectConstResultImpl.cpp
Line
Count
Source (jump to first uncovered line)
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
9
#include "lldb/Core/ValueObjectConstResultImpl.h"
10
11
#include "lldb/Core/Value.h"
12
#include "lldb/Core/ValueObject.h"
13
#include "lldb/Core/ValueObjectConstResult.h"
14
#include "lldb/Core/ValueObjectConstResultCast.h"
15
#include "lldb/Core/ValueObjectConstResultChild.h"
16
#include "lldb/Symbol/CompilerType.h"
17
#include "lldb/Target/ExecutionContext.h"
18
#include "lldb/Utility/DataBufferHeap.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
36.2k
    : m_impl_backend(valobj), m_live_address(live_address),
37
36.2k
      m_live_address_type(eAddressTypeLoad),
38
36.2k
      m_address_of_backend() {}
39
40
871
lldb::ValueObjectSP ValueObjectConstResultImpl::Dereference(Status &error) {
41
871
  if (m_impl_backend == nullptr)
42
0
    return lldb::ValueObjectSP();
43
44
871
  return m_impl_backend->ValueObject::Dereference(error);
45
871
}
46
47
ValueObject *ValueObjectConstResultImpl::CreateChildAtIndex(
48
6.41k
    size_t idx, bool synthetic_array_member, int32_t synthetic_index) {
49
6.41k
  if (m_impl_backend == nullptr)
50
0
    return nullptr;
51
52
6.41k
  m_impl_backend->UpdateValueIfNeeded(false);
53
54
6.41k
  ValueObjectConstResultChild *valobj = nullptr;
55
56
6.41k
  bool omit_empty_base_classes = true;
57
6.41k
  bool ignore_array_bounds = synthetic_array_member;
58
6.41k
  std::string child_name_str;
59
6.41k
  uint32_t child_byte_size = 0;
60
6.41k
  int32_t child_byte_offset = 0;
61
6.41k
  uint32_t child_bitfield_bit_size = 0;
62
6.41k
  uint32_t child_bitfield_bit_offset = 0;
63
6.41k
  bool child_is_base_class = false;
64
6.41k
  bool child_is_deref_of_parent = false;
65
6.41k
  uint64_t language_flags;
66
67
6.41k
  const bool transparent_pointers = !synthetic_array_member;
68
6.41k
  CompilerType compiler_type = m_impl_backend->GetCompilerType();
69
6.41k
  CompilerType child_compiler_type;
70
71
6.41k
  ExecutionContext exe_ctx(m_impl_backend->GetExecutionContextRef());
72
73
6.41k
  child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex(
74
6.41k
      &exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
75
6.41k
      ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset,
76
6.41k
      child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
77
6.41k
      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
6.41k
  if (child_compiler_type) {
85
6.38k
    if (synthetic_index)
86
84
      child_byte_offset += child_byte_size * synthetic_index;
87
88
6.38k
    ConstString child_name;
89
6.38k
    if (!child_name_str.empty())
90
6.14k
      child_name.SetCString(child_name_str.c_str());
91
92
6.38k
    lldb::addr_t child_live_addr = LLDB_INVALID_ADDRESS;
93
    // Transfer the live address (with offset) to the child.  But if
94
    // the parent is a pointer, the live address is where that pointer
95
    // value lives in memory, so the children live addresses aren't
96
    // offsets from that value, they are just other load addresses that
97
    // are recorded in the Value of the child ValueObjects.
98
6.38k
    if (m_live_address != LLDB_INVALID_ADDRESS) {
99
4.44k
      if (!compiler_type.IsPointerType())
100
4.21k
        child_live_addr = m_live_address + child_byte_offset;
101
4.44k
    }
102
6.38k
    valobj = new ValueObjectConstResultChild(
103
6.38k
        *m_impl_backend, child_compiler_type, child_name, child_byte_size,
104
6.38k
        child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset,
105
6.38k
        child_is_base_class, child_is_deref_of_parent, child_live_addr,
106
6.38k
        language_flags);
107
6.38k
  }
108
109
6.41k
  return valobj;
110
6.41k
}
111
112
lldb::ValueObjectSP ValueObjectConstResultImpl::GetSyntheticChildAtOffset(
113
    uint32_t offset, const CompilerType &type, bool can_create,
114
114
    ConstString name_const_str) {
115
114
  if (m_impl_backend == nullptr)
116
0
    return lldb::ValueObjectSP();
117
118
114
  return m_impl_backend->ValueObject::GetSyntheticChildAtOffset(
119
114
      offset, type, can_create, name_const_str);
120
114
}
121
122
66
lldb::ValueObjectSP ValueObjectConstResultImpl::AddressOf(Status &error) {
123
66
  if (m_address_of_backend.get() != nullptr)
124
20
    return m_address_of_backend;
125
126
46
  if (m_impl_backend == nullptr)
127
0
    return lldb::ValueObjectSP();
128
46
  if (m_live_address != LLDB_INVALID_ADDRESS) {
129
36
    CompilerType compiler_type(m_impl_backend->GetCompilerType());
130
131
36
    lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(
132
36
        &m_live_address, sizeof(lldb::addr_t)));
133
134
36
    std::string new_name("&");
135
36
    new_name.append(m_impl_backend->GetName().AsCString(""));
136
36
    ExecutionContext exe_ctx(m_impl_backend->GetExecutionContextRef());
137
36
    m_address_of_backend = ValueObjectConstResult::Create(
138
36
        exe_ctx.GetBestExecutionContextScope(), compiler_type.GetPointerType(),
139
36
        ConstString(new_name.c_str()), buffer, endian::InlHostByteOrder(),
140
36
        exe_ctx.GetAddressByteSize());
141
142
36
    m_address_of_backend->GetValue().SetValueType(Value::ValueType::Scalar);
143
36
    m_address_of_backend->GetValue().GetScalar() = m_live_address;
144
145
36
    return m_address_of_backend;
146
36
  } else
147
10
    return m_impl_backend->ValueObject::AddressOf(error);
148
46
}
149
150
lldb::ValueObjectSP
151
4
ValueObjectConstResultImpl::Cast(const CompilerType &compiler_type) {
152
4
  if (m_impl_backend == nullptr)
153
0
    return lldb::ValueObjectSP();
154
155
4
  ValueObjectConstResultCast *result_cast =
156
4
      new ValueObjectConstResultCast(*m_impl_backend, m_impl_backend->GetName(),
157
4
                                     compiler_type, m_live_address);
158
4
  return result_cast->GetSP();
159
4
}
160
161
lldb::addr_t
162
ValueObjectConstResultImpl::GetAddressOf(bool scalar_is_load_address,
163
1.91k
                                         AddressType *address_type) {
164
165
1.91k
  if (m_impl_backend == nullptr)
166
0
    return 0;
167
168
1.91k
  if (m_live_address == LLDB_INVALID_ADDRESS) {
169
229
    return m_impl_backend->ValueObject::GetAddressOf(scalar_is_load_address,
170
229
                                                     address_type);
171
229
  }
172
173
1.69k
  if (address_type)
174
1.69k
    *address_type = m_live_address_type;
175
176
1.69k
  return m_live_address;
177
1.91k
}
178
179
size_t ValueObjectConstResultImpl::GetPointeeData(DataExtractor &data,
180
                                                  uint32_t item_idx,
181
1.25k
                                                  uint32_t item_count) {
182
1.25k
  if (m_impl_backend == nullptr)
183
0
    return 0;
184
1.25k
  return m_impl_backend->ValueObject::GetPointeeData(data, item_idx,
185
1.25k
                                                     item_count);
186
1.25k
}