Coverage Report

Created: 2023-09-12 09:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Core/ValueObjectConstResult.cpp
Line
Count
Source (jump to first uncovered line)
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
9
#include "lldb/Core/ValueObjectConstResult.h"
10
11
#include "lldb/Core/ValueObjectDynamicValue.h"
12
#include "lldb/Symbol/CompilerType.h"
13
#include "lldb/Target/ExecutionContext.h"
14
#include "lldb/Target/ExecutionContextScope.h"
15
#include "lldb/Target/Process.h"
16
#include "lldb/Utility/DataBuffer.h"
17
#include "lldb/Utility/DataBufferHeap.h"
18
#include "lldb/Utility/DataExtractor.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
12.8k
                                             lldb::addr_t address) {
33
12.8k
  auto manager_sp = ValueObjectManager::Create();
34
12.8k
  return (new ValueObjectConstResult(exe_scope, *manager_sp, byte_order,
35
12.8k
                                     addr_byte_size, address))
36
12.8k
      ->GetSP();
37
12.8k
}
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
12.8k
    : ValueObject(exe_scope, manager), m_impl(this, address) {
45
12.8k
  SetIsConstant();
46
12.8k
  SetValueIsValid(true);
47
12.8k
  m_data.SetByteOrder(byte_order);
48
12.8k
  m_data.SetAddressByteSize(addr_byte_size);
49
12.8k
  SetAddressTypeOfChildren(eAddressTypeLoad);
50
12.8k
}
51
52
ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
53
                                             const CompilerType &compiler_type,
54
                                             ConstString name,
55
                                             const DataExtractor &data,
56
9.14k
                                             lldb::addr_t address) {
57
9.14k
  auto manager_sp = ValueObjectManager::Create();
58
9.14k
  return (new ValueObjectConstResult(exe_scope, *manager_sp, compiler_type,
59
9.14k
                                     name, data, address))
60
9.14k
      ->GetSP();
61
9.14k
}
62
63
ValueObjectConstResult::ValueObjectConstResult(
64
    ExecutionContextScope *exe_scope, ValueObjectManager &manager,
65
    const CompilerType &compiler_type, ConstString name,
66
    const DataExtractor &data, lldb::addr_t address)
67
9.14k
    : ValueObject(exe_scope, manager), m_impl(this, address) {
68
9.14k
  m_data = data;
69
70
9.14k
  if (!m_data.GetSharedDataBuffer()) {
71
6.80k
    DataBufferSP shared_data_buffer(
72
6.80k
        new DataBufferHeap(data.GetDataStart(), data.GetByteSize()));
73
6.80k
    m_data.SetData(shared_data_buffer);
74
6.80k
  }
75
76
9.14k
  m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
77
9.14k
  m_value.SetValueType(Value::ValueType::HostAddress);
78
9.14k
  m_value.SetCompilerType(compiler_type);
79
9.14k
  m_name = name;
80
9.14k
  SetIsConstant();
81
9.14k
  SetValueIsValid(true);
82
9.14k
  SetAddressTypeOfChildren(eAddressTypeLoad);
83
9.14k
}
84
85
ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
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
615
                                             lldb::addr_t address) {
92
615
  auto manager_sp = ValueObjectManager::Create();
93
615
  return (new ValueObjectConstResult(exe_scope, *manager_sp, compiler_type,
94
615
                                     name, data_sp, data_byte_order,
95
615
                                     data_addr_size, address))
96
615
      ->GetSP();
97
615
}
98
99
ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
100
                                             Value &value,
101
                                             ConstString name,
102
112
                                             Module *module) {
103
112
  auto manager_sp = ValueObjectManager::Create();
104
112
  return (new ValueObjectConstResult(exe_scope, *manager_sp, value, name,
105
112
                                     module))
106
112
      ->GetSP();
107
112
}
108
109
ValueObjectConstResult::ValueObjectConstResult(
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
615
    : ValueObject(exe_scope, manager), m_impl(this, address) {
115
615
  m_data.SetByteOrder(data_byte_order);
116
615
  m_data.SetAddressByteSize(data_addr_size);
117
615
  m_data.SetData(data_sp);
118
615
  m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
119
615
  m_value.SetValueType(Value::ValueType::HostAddress);
120
615
  m_value.SetCompilerType(compiler_type);
121
615
  m_name = name;
122
615
  SetIsConstant();
123
615
  SetValueIsValid(true);
124
615
  SetAddressTypeOfChildren(eAddressTypeLoad);
125
615
}
126
127
ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
128
                                             const CompilerType &compiler_type,
129
                                             ConstString name,
130
                                             lldb::addr_t address,
131
                                             AddressType address_type,
132
4.65k
                                             uint32_t addr_byte_size) {
133
4.65k
  auto manager_sp = ValueObjectManager::Create();
134
4.65k
  return (new ValueObjectConstResult(exe_scope, *manager_sp, compiler_type,
135
4.65k
                                     name, address, address_type,
136
4.65k
                                     addr_byte_size))
137
4.65k
      ->GetSP();
138
4.65k
}
139
140
ValueObjectConstResult::ValueObjectConstResult(
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
4.65k
      m_impl(this, address) {
146
4.65k
  m_value.GetScalar() = address;
147
4.65k
  m_data.SetAddressByteSize(addr_byte_size);
148
4.65k
  m_value.GetScalar().GetData(m_data, addr_byte_size);
149
  // m_value.SetValueType(Value::ValueType::HostAddress);
150
4.65k
  switch (address_type) {
151
100
  case eAddressTypeInvalid:
152
100
    m_value.SetValueType(Value::ValueType::Scalar);
153
100
    break;
154
0
  case eAddressTypeFile:
155
0
    m_value.SetValueType(Value::ValueType::FileAddress);
156
0
    break;
157
4.55k
  case eAddressTypeLoad:
158
4.55k
    m_value.SetValueType(Value::ValueType::LoadAddress);
159
4.55k
    break;
160
0
  case eAddressTypeHost:
161
0
    m_value.SetValueType(Value::ValueType::HostAddress);
162
0
    break;
163
4.65k
  }
164
4.65k
  m_value.SetCompilerType(compiler_type);
165
4.65k
  m_name = name;
166
4.65k
  SetIsConstant();
167
4.65k
  SetValueIsValid(true);
168
4.65k
  SetAddressTypeOfChildren(eAddressTypeLoad);
169
4.65k
}
170
171
ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
172
440
                                             const Status &error) {
173
440
  auto manager_sp = ValueObjectManager::Create();
174
440
  return (new ValueObjectConstResult(exe_scope, *manager_sp, error))->GetSP();
175
440
}
176
177
ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope,
178
                                               ValueObjectManager &manager,
179
                                               const Status &error)
180
440
    : ValueObject(exe_scope, manager), m_impl(this) {
181
440
  m_error = error;
182
440
  SetIsConstant();
183
440
}
184
185
ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope,
186
                                               ValueObjectManager &manager,
187
                                               const Value &value,
188
                                               ConstString name, Module *module)
189
112
    : ValueObject(exe_scope, manager), m_impl(this) {
190
112
  m_value = value;
191
112
  m_name = name;
192
112
  ExecutionContext exe_ctx;
193
112
  exe_scope->CalculateExecutionContext(exe_ctx);
194
112
  m_error = m_value.GetValueAsData(&exe_ctx, m_data, module);
195
112
}
196
197
25.1k
ValueObjectConstResult::~ValueObjectConstResult() = default;
198
199
673k
CompilerType ValueObjectConstResult::GetCompilerTypeImpl() {
200
673k
  return m_value.GetCompilerType();
201
673k
}
202
203
10
lldb::ValueType ValueObjectConstResult::GetValueType() const {
204
10
  return eValueTypeConstResult;
205
10
}
206
207
12.8k
std::optional<uint64_t> ValueObjectConstResult::GetByteSize() {
208
12.8k
  ExecutionContext exe_ctx(GetExecutionContextRef());
209
12.8k
  if (!m_byte_size) {
210
6.30k
    if (auto size =
211
6.30k
        GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope()))
212
6.30k
      SetByteSize(*size);
213
6.30k
  }
214
12.8k
  return m_byte_size;
215
12.8k
}
216
217
6.30k
void ValueObjectConstResult::SetByteSize(size_t size) { m_byte_size = size; }
218
219
14.0k
size_t ValueObjectConstResult::CalculateNumChildren(uint32_t max) {
220
14.0k
  ExecutionContext exe_ctx(GetExecutionContextRef());
221
14.0k
  auto children_count = GetCompilerType().GetNumChildren(true, &exe_ctx);
222
14.0k
  return children_count <= max ? children_count : 
max0
;
223
14.0k
}
224
225
411
ConstString ValueObjectConstResult::GetTypeName() {
226
411
  if (m_type_name.IsEmpty())
227
213
    m_type_name = GetCompilerType().GetTypeName();
228
411
  return m_type_name;
229
411
}
230
231
16.9k
ConstString ValueObjectConstResult::GetDisplayTypeName() {
232
16.9k
  return GetCompilerType().GetDisplayTypeName();
233
16.9k
}
234
235
82
bool ValueObjectConstResult::UpdateValue() {
236
  // Const value is always valid
237
82
  SetValueIsValid(true);
238
82
  return true;
239
82
}
240
241
29.5k
bool ValueObjectConstResult::IsInScope() {
242
  // A const result value is always in scope since it serializes all
243
  // information needed to contain the constant value.
244
29.5k
  return true;
245
29.5k
}
246
247
623
lldb::ValueObjectSP ValueObjectConstResult::Dereference(Status &error) {
248
623
  return m_impl.Dereference(error);
249
623
}
250
251
lldb::ValueObjectSP ValueObjectConstResult::GetSyntheticChildAtOffset(
252
    uint32_t offset, const CompilerType &type, bool can_create,
253
60
    ConstString name_const_str) {
254
60
  return m_impl.GetSyntheticChildAtOffset(offset, type, can_create,
255
60
                                          name_const_str);
256
60
}
257
258
24
lldb::ValueObjectSP ValueObjectConstResult::AddressOf(Status &error) {
259
24
  return m_impl.AddressOf(error);
260
24
}
261
262
lldb::addr_t ValueObjectConstResult::GetAddressOf(bool scalar_is_load_address,
263
128
                                                  AddressType *address_type) {
264
128
  return m_impl.GetAddressOf(scalar_is_load_address, address_type);
265
128
}
266
267
ValueObject *ValueObjectConstResult::CreateChildAtIndex(
268
4.43k
    size_t idx, bool synthetic_array_member, int32_t synthetic_index) {
269
4.43k
  return m_impl.CreateChildAtIndex(idx, synthetic_array_member,
270
4.43k
                                   synthetic_index);
271
4.43k
}
272
273
size_t ValueObjectConstResult::GetPointeeData(DataExtractor &data,
274
                                              uint32_t item_idx,
275
249
                                              uint32_t item_count) {
276
249
  return m_impl.GetPointeeData(data, item_idx, item_count);
277
249
}
278
279
lldb::ValueObjectSP
280
47.6k
ValueObjectConstResult::GetDynamicValue(lldb::DynamicValueType use_dynamic) {
281
  // Always recalculate dynamic values for const results as the memory that
282
  // they might point to might have changed at any time.
283
47.6k
  if (use_dynamic != eNoDynamicValues) {
284
47.6k
    if (!IsDynamic()) {
285
47.6k
      ExecutionContext exe_ctx(GetExecutionContextRef());
286
47.6k
      Process *process = exe_ctx.GetProcessPtr();
287
47.6k
      if (process && 
process->IsPossibleDynamicValue(*this)47.5k
)
288
231
        m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic);
289
47.6k
    }
290
47.6k
    if (m_dynamic_value && 
m_dynamic_value->GetError().Success()231
)
291
203
      return m_dynamic_value->GetSP();
292
47.6k
  }
293
47.4k
  return ValueObjectSP();
294
47.6k
}
295
296
lldb::ValueObjectSP
297
4
ValueObjectConstResult::DoCast(const CompilerType &compiler_type) {
298
4
  return m_impl.Cast(compiler_type);
299
4
}
300
301
20.3k
lldb::LanguageType ValueObjectConstResult::GetPreferredDisplayLanguage() {
302
20.3k
  if (m_preferred_display_language != lldb::eLanguageTypeUnknown)
303
19.4k
    return m_preferred_display_language;
304
872
  return GetCompilerTypeImpl().GetMinimumLanguage();
305
20.3k
}