Coverage Report

Created: 2022-01-15 10:30

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