Coverage Report

Created: 2022-01-22 13:19

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Core/ValueObject.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- ValueObject.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/ValueObject.h"
10
11
#include "lldb/Core/Address.h"
12
#include "lldb/Core/Declaration.h"
13
#include "lldb/Core/Module.h"
14
#include "lldb/Core/ValueObjectCast.h"
15
#include "lldb/Core/ValueObjectChild.h"
16
#include "lldb/Core/ValueObjectConstResult.h"
17
#include "lldb/Core/ValueObjectDynamicValue.h"
18
#include "lldb/Core/ValueObjectMemory.h"
19
#include "lldb/Core/ValueObjectSyntheticFilter.h"
20
#include "lldb/DataFormatters/DataVisualization.h"
21
#include "lldb/DataFormatters/DumpValueObjectOptions.h"
22
#include "lldb/DataFormatters/FormatManager.h"
23
#include "lldb/DataFormatters/StringPrinter.h"
24
#include "lldb/DataFormatters/TypeFormat.h"
25
#include "lldb/DataFormatters/TypeSummary.h"
26
#include "lldb/DataFormatters/ValueObjectPrinter.h"
27
#include "lldb/Expression/ExpressionVariable.h"
28
#include "lldb/Host/Config.h"
29
#include "lldb/Symbol/CompileUnit.h"
30
#include "lldb/Symbol/CompilerType.h"
31
#include "lldb/Symbol/SymbolContext.h"
32
#include "lldb/Symbol/Type.h"
33
#include "lldb/Symbol/Variable.h"
34
#include "lldb/Target/ExecutionContext.h"
35
#include "lldb/Target/Language.h"
36
#include "lldb/Target/LanguageRuntime.h"
37
#include "lldb/Target/Process.h"
38
#include "lldb/Target/StackFrame.h"
39
#include "lldb/Target/Target.h"
40
#include "lldb/Target/Thread.h"
41
#include "lldb/Target/ThreadList.h"
42
#include "lldb/Utility/DataBuffer.h"
43
#include "lldb/Utility/DataBufferHeap.h"
44
#include "lldb/Utility/Flags.h"
45
#include "lldb/Utility/Log.h"
46
#include "lldb/Utility/Logging.h"
47
#include "lldb/Utility/Scalar.h"
48
#include "lldb/Utility/Stream.h"
49
#include "lldb/Utility/StreamString.h"
50
#include "lldb/lldb-private-types.h"
51
52
#include "llvm/Support/Compiler.h"
53
54
#include <algorithm>
55
#include <cstdint>
56
#include <cstdlib>
57
#include <memory>
58
#include <tuple>
59
60
#include <cassert>
61
#include <cinttypes>
62
#include <cstdio>
63
#include <cstring>
64
65
#include <lldb/Core/ValueObject.h>
66
67
namespace lldb_private {
68
class ExecutionContextScope;
69
}
70
namespace lldb_private {
71
class SymbolContextScope;
72
}
73
74
using namespace lldb;
75
using namespace lldb_private;
76
77
static user_id_t g_value_obj_uid = 0;
78
79
// ValueObject constructor
80
ValueObject::ValueObject(ValueObject &parent)
81
    : m_parent(&parent), m_update_point(parent.GetUpdatePoint()),
82
62.5k
      m_manager(parent.GetManager()), m_id(++g_value_obj_uid) {
83
62.5k
  m_flags.m_is_synthetic_children_generated =
84
62.5k
      parent.m_flags.m_is_synthetic_children_generated;
85
62.5k
  m_data.SetByteOrder(parent.GetDataExtractor().GetByteOrder());
86
62.5k
  m_data.SetAddressByteSize(parent.GetDataExtractor().GetAddressByteSize());
87
62.5k
  m_manager->ManageObject(this);
88
62.5k
}
89
90
// ValueObject constructor
91
ValueObject::ValueObject(ExecutionContextScope *exe_scope,
92
                         ValueObjectManager &manager,
93
                         AddressType child_ptr_or_ref_addr_type)
94
    : m_update_point(exe_scope), m_manager(&manager),
95
      m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
96
80.0k
      m_id(++g_value_obj_uid) {
97
80.0k
  if (exe_scope) {
98
80.0k
    TargetSP target_sp(exe_scope->CalculateTarget());
99
80.0k
    if (target_sp) {
100
80.0k
      const ArchSpec &arch = target_sp->GetArchitecture();
101
80.0k
      m_data.SetByteOrder(arch.GetByteOrder());
102
80.0k
      m_data.SetAddressByteSize(arch.GetAddressByteSize());
103
80.0k
    }
104
80.0k
  }
105
80.0k
  m_manager->ManageObject(this);
106
80.0k
}
107
108
// Destructor
109
113k
ValueObject::~ValueObject() = default;
110
111
1.18M
bool ValueObject::UpdateValueIfNeeded(bool update_format) {
112
113
1.18M
  bool did_change_formats = false;
114
115
1.18M
  if (update_format)
116
536k
    did_change_formats = UpdateFormatsIfNeeded();
117
118
  // If this is a constant value, then our success is predicated on whether we
119
  // have an error or not
120
1.18M
  if (GetIsConstant()) {
121
    // if you are constant, things might still have changed behind your back
122
    // (e.g. you are a frozen object and things have changed deeper than you
123
    // cared to freeze-dry yourself) in this case, your value has not changed,
124
    // but "computed" entries might have, so you might now have a different
125
    // summary, or a different object description. clear these so we will
126
    // recompute them
127
449k
    if (update_format && 
!did_change_formats235k
)
128
226k
      ClearUserVisibleData(eClearUserVisibleDataItemsSummary |
129
226k
                           eClearUserVisibleDataItemsDescription);
130
449k
    return m_error.Success();
131
449k
  }
132
133
736k
  bool first_update = IsChecksumEmpty();
134
135
736k
  if (NeedsUpdating()) {
136
82.3k
    m_update_point.SetUpdated();
137
138
    // Save the old value using swap to avoid a string copy which also will
139
    // clear our m_value_str
140
82.3k
    if (m_value_str.empty()) {
141
82.1k
      m_flags.m_old_value_valid = false;
142
82.1k
    } else {
143
219
      m_flags.m_old_value_valid = true;
144
219
      m_old_value_str.swap(m_value_str);
145
219
      ClearUserVisibleData(eClearUserVisibleDataItemsValue);
146
219
    }
147
148
82.3k
    ClearUserVisibleData();
149
150
82.3k
    if (IsInScope()) {
151
82.3k
      const bool value_was_valid = GetValueIsValid();
152
82.3k
      SetValueDidChange(false);
153
154
82.3k
      m_error.Clear();
155
156
      // Call the pure virtual function to update the value
157
158
82.3k
      bool need_compare_checksums = false;
159
82.3k
      llvm::SmallVector<uint8_t, 16> old_checksum;
160
161
82.3k
      if (!first_update && 
CanProvideValue()757
) {
162
630
        need_compare_checksums = true;
163
630
        old_checksum.resize(m_value_checksum.size());
164
630
        std::copy(m_value_checksum.begin(), m_value_checksum.end(),
165
630
                  old_checksum.begin());
166
630
      }
167
168
82.3k
      bool success = UpdateValue();
169
170
82.3k
      SetValueIsValid(success);
171
172
82.3k
      if (success) {
173
81.9k
        UpdateChildrenAddressType();
174
81.9k
        const uint64_t max_checksum_size = 128;
175
81.9k
        m_data.Checksum(m_value_checksum, max_checksum_size);
176
81.9k
      } else {
177
423
        need_compare_checksums = false;
178
423
        m_value_checksum.clear();
179
423
      }
180
181
82.3k
      assert(!need_compare_checksums ||
182
82.3k
             (!old_checksum.empty() && !m_value_checksum.empty()));
183
184
82.3k
      if (first_update)
185
81.5k
        SetValueDidChange(false);
186
757
      else if (!m_flags.m_value_did_change && 
!success730
) {
187
        // The value wasn't gotten successfully, so we mark this as changed if
188
        // the value used to be valid and now isn't
189
6
        SetValueDidChange(value_was_valid);
190
751
      } else if (need_compare_checksums) {
191
624
        SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0],
192
624
                                 m_value_checksum.size()));
193
624
      }
194
195
82.3k
    } else {
196
18
      m_error.SetErrorString("out of scope");
197
18
    }
198
82.3k
  }
199
0
  return m_error.Success();
200
1.18M
}
201
202
955k
bool ValueObject::UpdateFormatsIfNeeded() {
203
955k
  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS));
204
955k
  LLDB_LOGF(log,
205
955k
            "[%s %p] checking for FormatManager revisions. ValueObject "
206
955k
            "rev: %d - Global rev: %d",
207
955k
            GetName().GetCString(), static_cast<void *>(this),
208
955k
            m_last_format_mgr_revision,
209
955k
            DataVisualization::GetCurrentRevision());
210
211
955k
  bool any_change = false;
212
213
955k
  if ((m_last_format_mgr_revision != DataVisualization::GetCurrentRevision())) {
214
91.9k
    m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
215
91.9k
    any_change = true;
216
217
91.9k
    SetValueFormat(DataVisualization::GetFormat(*this, eNoDynamicValues));
218
91.9k
    SetSummaryFormat(
219
91.9k
        DataVisualization::GetSummaryFormat(*this, GetDynamicValueType()));
220
91.9k
#if LLDB_ENABLE_PYTHON
221
91.9k
    SetSyntheticChildren(
222
91.9k
        DataVisualization::GetSyntheticChildren(*this, GetDynamicValueType()));
223
91.9k
#endif
224
91.9k
  }
225
226
955k
  return any_change;
227
955k
}
228
229
47
void ValueObject::SetNeedsUpdate() {
230
47
  m_update_point.SetNeedsUpdate();
231
  // We have to clear the value string here so ConstResult children will notice
232
  // if their values are changed by hand (i.e. with SetValueAsCString).
233
47
  ClearUserVisibleData(eClearUserVisibleDataItemsValue);
234
47
}
235
236
1.75k
void ValueObject::ClearDynamicTypeInformation() {
237
1.75k
  m_flags.m_children_count_valid = false;
238
1.75k
  m_flags.m_did_calculate_complete_objc_class_type = false;
239
1.75k
  m_last_format_mgr_revision = 0;
240
1.75k
  m_override_type = CompilerType();
241
1.75k
  SetValueFormat(lldb::TypeFormatImplSP());
242
1.75k
  SetSummaryFormat(lldb::TypeSummaryImplSP());
243
1.75k
  SetSyntheticChildren(lldb::SyntheticChildrenSP());
244
1.75k
}
245
246
3.11M
CompilerType ValueObject::MaybeCalculateCompleteType() {
247
3.11M
  CompilerType compiler_type(GetCompilerTypeImpl());
248
249
3.11M
  if (m_flags.m_did_calculate_complete_objc_class_type) {
250
3.00M
    if (m_override_type.IsValid())
251
11.8k
      return m_override_type;
252
2.99M
    else
253
2.99M
      return compiler_type;
254
3.00M
  }
255
256
107k
  m_flags.m_did_calculate_complete_objc_class_type = true;
257
258
107k
  ProcessSP process_sp(
259
107k
      GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
260
261
107k
  if (!process_sp)
262
1.25k
    return compiler_type;
263
264
105k
  if (auto *runtime =
265
105k
          process_sp->GetLanguageRuntime(GetObjectRuntimeLanguage())) {
266
56.0k
    if (llvm::Optional<CompilerType> complete_type =
267
56.0k
            runtime->GetRuntimeType(compiler_type)) {
268
607
      m_override_type = complete_type.getValue();
269
607
      if (m_override_type.IsValid())
270
607
        return m_override_type;
271
607
    }
272
56.0k
  }
273
105k
  return compiler_type;
274
105k
}
275
276
277
278
151k
DataExtractor &ValueObject::GetDataExtractor() {
279
151k
  UpdateValueIfNeeded(false);
280
151k
  return m_data;
281
151k
}
282
283
92.8k
const Status &ValueObject::GetError() {
284
92.8k
  UpdateValueIfNeeded(false);
285
92.8k
  return m_error;
286
92.8k
}
287
288
const char *ValueObject::GetLocationAsCStringImpl(const Value &value,
289
479
                                                  const DataExtractor &data) {
290
479
  if (UpdateValueIfNeeded(false)) {
291
479
    if (m_location_str.empty()) {
292
380
      StreamString sstr;
293
294
380
      Value::ValueType value_type = value.GetValueType();
295
296
380
      switch (value_type) {
297
0
      case Value::ValueType::Invalid:
298
0
        m_location_str = "invalid";
299
0
        break;
300
6
      case Value::ValueType::Scalar:
301
6
        if (value.GetContextType() == Value::ContextType::RegisterInfo) {
302
6
          RegisterInfo *reg_info = value.GetRegisterInfo();
303
6
          if (reg_info) {
304
6
            if (reg_info->name)
305
6
              m_location_str = reg_info->name;
306
0
            else if (reg_info->alt_name)
307
0
              m_location_str = reg_info->alt_name;
308
6
            if (m_location_str.empty())
309
0
              m_location_str = (reg_info->encoding == lldb::eEncodingVector)
310
0
                                   ? "vector"
311
0
                                   : "scalar";
312
6
          }
313
6
        }
314
6
        if (m_location_str.empty())
315
0
          m_location_str = "scalar";
316
6
        break;
317
318
350
      case Value::ValueType::LoadAddress:
319
350
      case Value::ValueType::FileAddress:
320
374
      case Value::ValueType::HostAddress: {
321
374
        uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
322
374
        sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size,
323
374
                    value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
324
374
        m_location_str = std::string(sstr.GetString());
325
374
      } break;
326
380
      }
327
380
    }
328
479
  }
329
479
  return m_location_str.c_str();
330
479
}
331
332
58.6k
bool ValueObject::ResolveValue(Scalar &scalar) {
333
58.6k
  if (UpdateValueIfNeeded(
334
58.6k
          false)) // make sure that you are up to date before returning anything
335
58.5k
  {
336
58.5k
    ExecutionContext exe_ctx(GetExecutionContextRef());
337
58.5k
    Value tmp_value(m_value);
338
58.5k
    scalar = tmp_value.ResolveValue(&exe_ctx);
339
58.5k
    if (scalar.IsValid()) {
340
58.5k
      const uint32_t bitfield_bit_size = GetBitfieldBitSize();
341
58.5k
      if (bitfield_bit_size)
342
44
        return scalar.ExtractBitfield(bitfield_bit_size,
343
44
                                      GetBitfieldBitOffset());
344
58.5k
      return true;
345
58.5k
    }
346
58.5k
  }
347
74
  return false;
348
58.6k
}
349
350
77
bool ValueObject::IsLogicalTrue(Status &error) {
351
77
  if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage())) {
352
0
    LazyBool is_logical_true = language->IsLogicalTrue(*this, error);
353
0
    switch (is_logical_true) {
354
0
    case eLazyBoolYes:
355
0
    case eLazyBoolNo:
356
0
      return (is_logical_true == true);
357
0
    case eLazyBoolCalculate:
358
0
      break;
359
0
    }
360
0
  }
361
362
77
  Scalar scalar_value;
363
364
77
  if (!ResolveValue(scalar_value)) {
365
0
    error.SetErrorString("failed to get a scalar result");
366
0
    return false;
367
0
  }
368
369
77
  bool ret;
370
77
  ret = scalar_value.ULongLong(1) != 0;
371
77
  error.Clear();
372
77
  return ret;
373
77
}
374
375
127k
ValueObjectSP ValueObject::GetChildAtIndex(size_t idx, bool can_create) {
376
127k
  ValueObjectSP child_sp;
377
  // We may need to update our value if we are dynamic
378
127k
  if (IsPossibleDynamicType())
379
715
    UpdateValueIfNeeded(false);
380
127k
  if (idx < GetNumChildren()) {
381
    // Check if we have already made the child value object?
382
127k
    if (can_create && !m_children.HasChildAtIndex(idx)) {
383
      // No we haven't created the child at this index, so lets have our
384
      // subclass do it and cache the result for quick future access.
385
53.9k
      m_children.SetChildAtIndex(idx, CreateChildAtIndex(idx, false, 0));
386
53.9k
    }
387
388
127k
    ValueObject *child = m_children.GetChildAtIndex(idx);
389
127k
    if (child != nullptr)
390
127k
      return child->GetSP();
391
127k
  }
392
331
  return child_sp;
393
127k
}
394
395
lldb::ValueObjectSP
396
ValueObject::GetChildAtIndexPath(llvm::ArrayRef<size_t> idxs,
397
2.55k
                                 size_t *index_of_error) {
398
2.55k
  if (idxs.size() == 0)
399
0
    return GetSP();
400
2.55k
  ValueObjectSP root(GetSP());
401
7.65k
  for (size_t idx : idxs) {
402
7.65k
    root = root->GetChildAtIndex(idx, true);
403
7.65k
    if (!root) {
404
0
      if (index_of_error)
405
0
        *index_of_error = idx;
406
0
      return root;
407
0
    }
408
7.65k
  }
409
2.55k
  return root;
410
2.55k
}
411
412
lldb::ValueObjectSP ValueObject::GetChildAtIndexPath(
413
0
  llvm::ArrayRef<std::pair<size_t, bool>> idxs, size_t *index_of_error) {
414
0
  if (idxs.size() == 0)
415
0
    return GetSP();
416
0
  ValueObjectSP root(GetSP());
417
0
  for (std::pair<size_t, bool> idx : idxs) {
418
0
    root = root->GetChildAtIndex(idx.first, idx.second);
419
0
    if (!root) {
420
0
      if (index_of_error)
421
0
        *index_of_error = idx.first;
422
0
      return root;
423
0
    }
424
0
  }
425
0
  return root;
426
0
}
427
428
lldb::ValueObjectSP
429
ValueObject::GetChildAtNamePath(llvm::ArrayRef<ConstString> names,
430
494
                                ConstString *name_of_error) {
431
494
  if (names.size() == 0)
432
0
    return GetSP();
433
494
  ValueObjectSP root(GetSP());
434
1.06k
  for (ConstString name : names) {
435
1.06k
    root = root->GetChildMemberWithName(name, true);
436
1.06k
    if (!root) {
437
23
      if (name_of_error)
438
0
        *name_of_error = name;
439
23
      return root;
440
23
    }
441
1.06k
  }
442
471
  return root;
443
494
}
444
445
lldb::ValueObjectSP ValueObject::GetChildAtNamePath(
446
    llvm::ArrayRef<std::pair<ConstString, bool>> names,
447
0
    ConstString *name_of_error) {
448
0
  if (names.size() == 0)
449
0
    return GetSP();
450
0
  ValueObjectSP root(GetSP());
451
0
  for (std::pair<ConstString, bool> name : names) {
452
0
    root = root->GetChildMemberWithName(name.first, name.second);
453
0
    if (!root) {
454
0
      if (name_of_error)
455
0
        *name_of_error = name.first;
456
0
      return root;
457
0
    }
458
0
  }
459
0
  return root;
460
0
}
461
462
0
size_t ValueObject::GetIndexOfChildWithName(ConstString name) {
463
0
  bool omit_empty_base_classes = true;
464
0
  return GetCompilerType().GetIndexOfChildWithName(name.GetCString(),
465
0
                                                   omit_empty_base_classes);
466
0
}
467
468
ValueObjectSP ValueObject::GetChildMemberWithName(ConstString name,
469
24.8k
                                                  bool can_create) {
470
  // We may need to update our value if we are dynamic.
471
24.8k
  if (IsPossibleDynamicType())
472
334
    UpdateValueIfNeeded(false);
473
474
  // When getting a child by name, it could be buried inside some base classes
475
  // (which really aren't part of the expression path), so we need a vector of
476
  // indexes that can get us down to the correct child.
477
24.8k
  std::vector<uint32_t> child_indexes;
478
24.8k
  bool omit_empty_base_classes = true;
479
480
24.8k
  if (!GetCompilerType().IsValid())
481
0
    return ValueObjectSP();
482
483
24.8k
  const size_t num_child_indexes =
484
24.8k
      GetCompilerType().GetIndexOfChildMemberWithName(
485
24.8k
          name.GetCString(), omit_empty_base_classes, child_indexes);
486
24.8k
  if (num_child_indexes == 0)
487
757
    return nullptr;
488
489
24.0k
  ValueObjectSP child_sp = GetSP();
490
24.0k
  for (uint32_t idx : child_indexes)
491
39.2k
    if (child_sp)
492
39.2k
      child_sp = child_sp->GetChildAtIndex(idx, can_create);
493
24.0k
  return child_sp;
494
24.8k
}
495
496
270k
size_t ValueObject::GetNumChildren(uint32_t max) {
497
270k
  UpdateValueIfNeeded();
498
499
270k
  if (max < UINT32_MAX) {
500
9
    if (m_flags.m_children_count_valid) {
501
0
      size_t children_count = m_children.GetChildrenCount();
502
0
      return children_count <= max ? children_count : max;
503
0
    } else
504
9
      return CalculateNumChildren(max);
505
9
  }
506
507
270k
  if (!m_flags.m_children_count_valid) {
508
71.3k
    SetNumChildren(CalculateNumChildren());
509
71.3k
  }
510
270k
  return m_children.GetChildrenCount();
511
270k
}
512
513
64
bool ValueObject::MightHaveChildren() {
514
64
  bool has_children = false;
515
64
  const uint32_t type_info = GetTypeInfo();
516
64
  if (type_info) {
517
64
    if (type_info & (eTypeHasChildren | eTypeIsPointer | eTypeIsReference))
518
64
      has_children = true;
519
64
  } else {
520
0
    has_children = GetNumChildren() > 0;
521
0
  }
522
64
  return has_children;
523
64
}
524
525
// Should only be called by ValueObject::GetNumChildren()
526
71.3k
void ValueObject::SetNumChildren(size_t num_children) {
527
71.3k
  m_flags.m_children_count_valid = true;
528
71.3k
  m_children.SetChildrenCount(num_children);
529
71.3k
}
530
531
ValueObject *ValueObject::CreateChildAtIndex(size_t idx,
532
                                             bool synthetic_array_member,
533
40.3k
                                             int32_t synthetic_index) {
534
40.3k
  ValueObject *valobj = nullptr;
535
536
40.3k
  bool omit_empty_base_classes = true;
537
40.3k
  bool ignore_array_bounds = synthetic_array_member;
538
40.3k
  std::string child_name_str;
539
40.3k
  uint32_t child_byte_size = 0;
540
40.3k
  int32_t child_byte_offset = 0;
541
40.3k
  uint32_t child_bitfield_bit_size = 0;
542
40.3k
  uint32_t child_bitfield_bit_offset = 0;
543
40.3k
  bool child_is_base_class = false;
544
40.3k
  bool child_is_deref_of_parent = false;
545
40.3k
  uint64_t language_flags = 0;
546
547
40.3k
  const bool transparent_pointers = !synthetic_array_member;
548
40.3k
  CompilerType child_compiler_type;
549
550
40.3k
  ExecutionContext exe_ctx(GetExecutionContextRef());
551
552
40.3k
  child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex(
553
40.3k
      &exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
554
40.3k
      ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset,
555
40.3k
      child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
556
40.3k
      child_is_deref_of_parent, this, language_flags);
557
40.3k
  if (child_compiler_type) {
558
40.2k
    if (synthetic_index)
559
95
      child_byte_offset += child_byte_size * synthetic_index;
560
561
40.2k
    ConstString child_name;
562
40.2k
    if (!child_name_str.empty())
563
39.8k
      child_name.SetCString(child_name_str.c_str());
564
565
40.2k
    valobj = new ValueObjectChild(
566
40.2k
        *this, child_compiler_type, child_name, child_byte_size,
567
40.2k
        child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset,
568
40.2k
        child_is_base_class, child_is_deref_of_parent, eAddressTypeInvalid,
569
40.2k
        language_flags);
570
40.2k
  }
571
572
  // In case of an incomplete type, try to use the ValueObject's
573
  // synthetic value to create the child ValueObject.
574
40.3k
  if (!valobj && 
synthetic_array_member65
) {
575
2
    if (ValueObjectSP synth_valobj_sp = GetSyntheticValue()) {
576
0
      valobj = synth_valobj_sp
577
0
                   ->GetChildAtIndex(synthetic_index, synthetic_array_member)
578
0
                   .get();
579
0
    }
580
2
  }
581
582
40.3k
  return valobj;
583
40.3k
}
584
585
bool ValueObject::GetSummaryAsCString(TypeSummaryImpl *summary_ptr,
586
                                      std::string &destination,
587
7.97k
                                      lldb::LanguageType lang) {
588
7.97k
  return GetSummaryAsCString(summary_ptr, destination,
589
7.97k
                             TypeSummaryOptions().SetLanguage(lang));
590
7.97k
}
591
592
bool ValueObject::GetSummaryAsCString(TypeSummaryImpl *summary_ptr,
593
                                      std::string &destination,
594
76.5k
                                      const TypeSummaryOptions &options) {
595
76.5k
  destination.clear();
596
597
  // ideally we would like to bail out if passing NULL, but if we do so we end
598
  // up not providing the summary for function pointers anymore
599
76.5k
  if (/*summary_ptr == NULL ||*/ m_flags.m_is_getting_summary)
600
0
    return false;
601
602
76.5k
  m_flags.m_is_getting_summary = true;
603
604
76.5k
  TypeSummaryOptions actual_options(options);
605
606
76.5k
  if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown)
607
23.7k
    actual_options.SetLanguage(GetPreferredDisplayLanguage());
608
609
  // this is a hot path in code and we prefer to avoid setting this string all
610
  // too often also clearing out other information that we might care to see in
611
  // a crash log. might be useful in very specific situations though.
612
  /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s.
613
   Summary provider's description is %s",
614
   GetTypeName().GetCString(),
615
   GetName().GetCString(),
616
   summary_ptr->GetDescription().c_str());*/
617
618
76.5k
  if (UpdateValueIfNeeded(false) && 
summary_ptr76.4k
) {
619
10.1k
    if (HasSyntheticValue())
620
46
      m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on
621
                                                // the synthetic children being
622
                                                // up-to-date (e.g. ${svar%#})
623
10.1k
    summary_ptr->FormatObject(this, destination, actual_options);
624
10.1k
  }
625
76.5k
  m_flags.m_is_getting_summary = false;
626
76.5k
  return !destination.empty();
627
76.5k
}
628
629
70.1k
const char *ValueObject::GetSummaryAsCString(lldb::LanguageType lang) {
630
70.1k
  if (UpdateValueIfNeeded(true) && 
m_summary_str.empty()70.0k
) {
631
68.5k
    TypeSummaryOptions summary_options;
632
68.5k
    summary_options.SetLanguage(lang);
633
68.5k
    GetSummaryAsCString(GetSummaryFormat().get(), m_summary_str,
634
68.5k
                        summary_options);
635
68.5k
  }
636
70.1k
  if (m_summary_str.empty())
637
66.6k
    return nullptr;
638
3.58k
  return m_summary_str.c_str();
639
70.1k
}
640
641
bool ValueObject::GetSummaryAsCString(std::string &destination,
642
23
                                      const TypeSummaryOptions &options) {
643
23
  return GetSummaryAsCString(GetSummaryFormat().get(), destination, options);
644
23
}
645
646
4.29k
bool ValueObject::IsCStringContainer(bool check_pointer) {
647
4.29k
  CompilerType pointee_or_element_compiler_type;
648
4.29k
  const Flags type_flags(GetTypeInfo(&pointee_or_element_compiler_type));
649
4.29k
  bool is_char_arr_ptr(type_flags.AnySet(eTypeIsArray | eTypeIsPointer) &&
650
4.29k
                       pointee_or_element_compiler_type.IsCharType());
651
4.29k
  if (!is_char_arr_ptr)
652
102
    return false;
653
4.19k
  if (!check_pointer)
654
0
    return true;
655
4.19k
  if (type_flags.Test(eTypeIsArray))
656
2.81k
    return true;
657
1.38k
  addr_t cstr_address = LLDB_INVALID_ADDRESS;
658
1.38k
  AddressType cstr_address_type = eAddressTypeInvalid;
659
1.38k
  cstr_address = GetPointerValue(&cstr_address_type);
660
1.38k
  return (cstr_address != LLDB_INVALID_ADDRESS);
661
4.19k
}
662
663
size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx,
664
3.25k
                                   uint32_t item_count) {
665
3.25k
  CompilerType pointee_or_element_compiler_type;
666
3.25k
  const uint32_t type_info = GetTypeInfo(&pointee_or_element_compiler_type);
667
3.25k
  const bool is_pointer_type = type_info & eTypeIsPointer;
668
3.25k
  const bool is_array_type = type_info & eTypeIsArray;
669
3.25k
  if (!(is_pointer_type || 
is_array_type2.07k
))
670
0
    return 0;
671
672
3.25k
  if (item_count == 0)
673
0
    return 0;
674
675
3.25k
  ExecutionContext exe_ctx(GetExecutionContextRef());
676
677
3.25k
  llvm::Optional<uint64_t> item_type_size =
678
3.25k
      pointee_or_element_compiler_type.GetByteSize(
679
3.25k
          exe_ctx.GetBestExecutionContextScope());
680
3.25k
  if (!item_type_size)
681
0
    return 0;
682
3.25k
  const uint64_t bytes = item_count * *item_type_size;
683
3.25k
  const uint64_t offset = item_idx * *item_type_size;
684
685
3.25k
  if (item_idx == 0 && 
item_count == 13.03k
) // simply a deref
686
155
  {
687
155
    if (is_pointer_type) {
688
8
      Status error;
689
8
      ValueObjectSP pointee_sp = Dereference(error);
690
8
      if (error.Fail() || pointee_sp.get() == nullptr)
691
0
        return 0;
692
8
      return pointee_sp->GetData(data, error);
693
147
    } else {
694
147
      ValueObjectSP child_sp = GetChildAtIndex(0, true);
695
147
      if (child_sp.get() == nullptr)
696
0
        return 0;
697
147
      Status error;
698
147
      return child_sp->GetData(data, error);
699
147
    }
700
0
    return true;
701
155
  } else /* (items > 1) */
702
3.10k
  {
703
3.10k
    Status error;
704
3.10k
    lldb_private::DataBufferHeap *heap_buf_ptr = nullptr;
705
3.10k
    lldb::DataBufferSP data_sp(heap_buf_ptr =
706
3.10k
                                   new lldb_private::DataBufferHeap());
707
708
3.10k
    AddressType addr_type;
709
3.10k
    lldb::addr_t addr = is_pointer_type ? 
GetPointerValue(&addr_type)1.17k
710
3.10k
                                        : 
GetAddressOf(true, &addr_type)1.92k
;
711
712
3.10k
    switch (addr_type) {
713
18
    case eAddressTypeFile: {
714
18
      ModuleSP module_sp(GetModule());
715
18
      if (module_sp) {
716
18
        addr = addr + offset;
717
18
        Address so_addr;
718
18
        module_sp->ResolveFileAddress(addr, so_addr);
719
18
        ExecutionContext exe_ctx(GetExecutionContextRef());
720
18
        Target *target = exe_ctx.GetTargetPtr();
721
18
        if (target) {
722
18
          heap_buf_ptr->SetByteSize(bytes);
723
18
          size_t bytes_read = target->ReadMemory(
724
18
              so_addr, heap_buf_ptr->GetBytes(), bytes, error, true);
725
18
          if (error.Success()) {
726
18
            data.SetData(data_sp);
727
18
            return bytes_read;
728
18
          }
729
18
        }
730
18
      }
731
18
    } 
break0
;
732
2.75k
    case eAddressTypeLoad: {
733
2.75k
      ExecutionContext exe_ctx(GetExecutionContextRef());
734
2.75k
      Process *process = exe_ctx.GetProcessPtr();
735
2.75k
      if (process) {
736
2.75k
        heap_buf_ptr->SetByteSize(bytes);
737
2.75k
        size_t bytes_read = process->ReadMemory(
738
2.75k
            addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
739
2.75k
        if (error.Success() || 
bytes_read > 011
) {
740
2.74k
          data.SetData(data_sp);
741
2.74k
          return bytes_read;
742
2.74k
        }
743
2.75k
      }
744
2.75k
    } 
break11
;
745
327
    case eAddressTypeHost: {
746
327
      auto max_bytes =
747
327
          GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
748
327
      if (max_bytes && *max_bytes > offset) {
749
327
        size_t bytes_read = std::min<uint64_t>(*max_bytes - offset, bytes);
750
327
        addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
751
327
        if (addr == 0 || addr == LLDB_INVALID_ADDRESS)
752
0
          break;
753
327
        heap_buf_ptr->CopyData((uint8_t *)(addr + offset), bytes_read);
754
327
        data.SetData(data_sp);
755
327
        return bytes_read;
756
327
      }
757
327
    } 
break0
;
758
0
    case eAddressTypeInvalid:
759
0
      break;
760
3.10k
    }
761
3.10k
  }
762
11
  return 0;
763
3.25k
}
764
765
47.7k
uint64_t ValueObject::GetData(DataExtractor &data, Status &error) {
766
47.7k
  UpdateValueIfNeeded(false);
767
47.7k
  ExecutionContext exe_ctx(GetExecutionContextRef());
768
47.7k
  error = m_value.GetValueAsData(&exe_ctx, data, GetModule().get());
769
47.7k
  if (error.Fail()) {
770
0
    if (m_data.GetByteSize()) {
771
0
      data = m_data;
772
0
      error.Clear();
773
0
      return data.GetByteSize();
774
0
    } else {
775
0
      return 0;
776
0
    }
777
0
  }
778
47.7k
  data.SetAddressByteSize(m_data.GetAddressByteSize());
779
47.7k
  data.SetByteOrder(m_data.GetByteOrder());
780
47.7k
  return data.GetByteSize();
781
47.7k
}
782
783
6
bool ValueObject::SetData(DataExtractor &data, Status &error) {
784
6
  error.Clear();
785
  // Make sure our value is up to date first so that our location and location
786
  // type is valid.
787
6
  if (!UpdateValueIfNeeded(false)) {
788
0
    error.SetErrorString("unable to read value");
789
0
    return false;
790
0
  }
791
792
6
  uint64_t count = 0;
793
6
  const Encoding encoding = GetCompilerType().GetEncoding(count);
794
795
6
  const size_t byte_size = GetByteSize().getValueOr(0);
796
797
6
  Value::ValueType value_type = m_value.GetValueType();
798
799
6
  switch (value_type) {
800
0
  case Value::ValueType::Invalid:
801
0
    error.SetErrorString("invalid location");
802
0
    return false;
803
0
  case Value::ValueType::Scalar: {
804
0
    Status set_error =
805
0
        m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
806
807
0
    if (!set_error.Success()) {
808
0
      error.SetErrorStringWithFormat("unable to set scalar value: %s",
809
0
                                     set_error.AsCString());
810
0
      return false;
811
0
    }
812
0
  } break;
813
6
  case Value::ValueType::LoadAddress: {
814
    // If it is a load address, then the scalar value is the storage location
815
    // of the data, and we have to shove this value down to that load location.
816
6
    ExecutionContext exe_ctx(GetExecutionContextRef());
817
6
    Process *process = exe_ctx.GetProcessPtr();
818
6
    if (process) {
819
6
      addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
820
6
      size_t bytes_written = process->WriteMemory(
821
6
          target_addr, data.GetDataStart(), byte_size, error);
822
6
      if (!error.Success())
823
0
        return false;
824
6
      if (bytes_written != byte_size) {
825
0
        error.SetErrorString("unable to write value to memory");
826
0
        return false;
827
0
      }
828
6
    }
829
6
  } break;
830
6
  case Value::ValueType::HostAddress: {
831
    // If it is a host address, then we stuff the scalar as a DataBuffer into
832
    // the Value's data.
833
0
    DataBufferSP buffer_sp(new DataBufferHeap(byte_size, 0));
834
0
    m_data.SetData(buffer_sp, 0);
835
0
    data.CopyByteOrderedData(0, byte_size,
836
0
                             const_cast<uint8_t *>(m_data.GetDataStart()),
837
0
                             byte_size, m_data.GetByteOrder());
838
0
    m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
839
0
  } break;
840
0
  case Value::ValueType::FileAddress:
841
0
    break;
842
6
  }
843
844
  // If we have reached this point, then we have successfully changed the
845
  // value.
846
6
  SetNeedsUpdate();
847
6
  return true;
848
6
}
849
850
static bool CopyStringDataToBufferSP(const StreamString &source,
851
2.09k
                                     lldb::DataBufferSP &destination) {
852
2.09k
  llvm::StringRef src = source.GetString();
853
2.09k
  src.consume_back(llvm::StringRef("\0", 1));
854
2.09k
  destination = std::make_shared<DataBufferHeap>(src.size(), 0);
855
2.09k
  memcpy(destination->GetBytes(), src.data(), src.size());
856
2.09k
  return true;
857
2.09k
}
858
859
std::pair<size_t, bool>
860
ValueObject::ReadPointedString(lldb::DataBufferSP &buffer_sp, Status &error,
861
                               uint32_t max_length, bool honor_array,
862
2.09k
                               Format item_format) {
863
2.09k
  bool was_capped = false;
864
2.09k
  StreamString s;
865
2.09k
  ExecutionContext exe_ctx(GetExecutionContextRef());
866
2.09k
  Target *target = exe_ctx.GetTargetPtr();
867
868
2.09k
  if (!target) {
869
0
    s << "<no target to read from>";
870
0
    error.SetErrorString("no target to read from");
871
0
    CopyStringDataToBufferSP(s, buffer_sp);
872
0
    return {0, was_capped};
873
0
  }
874
875
2.09k
  if (max_length == 0)
876
2.09k
    max_length = target->GetMaximumSizeOfStringSummary();
877
878
2.09k
  size_t bytes_read = 0;
879
2.09k
  size_t total_bytes_read = 0;
880
881
2.09k
  CompilerType compiler_type = GetCompilerType();
882
2.09k
  CompilerType elem_or_pointee_compiler_type;
883
2.09k
  const Flags type_flags(GetTypeInfo(&elem_or_pointee_compiler_type));
884
2.09k
  if (type_flags.AnySet(eTypeIsArray | eTypeIsPointer) &&
885
2.09k
      elem_or_pointee_compiler_type.IsCharType()) {
886
2.09k
    addr_t cstr_address = LLDB_INVALID_ADDRESS;
887
2.09k
    AddressType cstr_address_type = eAddressTypeInvalid;
888
889
2.09k
    size_t cstr_len = 0;
890
2.09k
    bool capped_data = false;
891
2.09k
    const bool is_array = type_flags.Test(eTypeIsArray);
892
2.09k
    if (is_array) {
893
      // We have an array
894
1.40k
      uint64_t array_size = 0;
895
1.40k
      if (compiler_type.IsArrayType(nullptr, &array_size)) {
896
1.40k
        cstr_len = array_size;
897
1.40k
        if (cstr_len > max_length) {
898
0
          capped_data = true;
899
0
          cstr_len = max_length;
900
0
        }
901
1.40k
      }
902
1.40k
      cstr_address = GetAddressOf(true, &cstr_address_type);
903
1.40k
    } else {
904
      // We have a pointer
905
690
      cstr_address = GetPointerValue(&cstr_address_type);
906
690
    }
907
908
2.09k
    if (cstr_address == 0 || 
cstr_address == 2.06k
LLDB_INVALID_ADDRESS2.06k
) {
909
39
      if (cstr_address_type == eAddressTypeHost && 
is_array5
) {
910
5
        const char *cstr = GetDataExtractor().PeekCStr(0);
911
5
        if (cstr == nullptr) {
912
0
          s << "<invalid address>";
913
0
          error.SetErrorString("invalid address");
914
0
          CopyStringDataToBufferSP(s, buffer_sp);
915
0
          return {0, was_capped};
916
0
        }
917
5
        s << llvm::StringRef(cstr, cstr_len);
918
5
        CopyStringDataToBufferSP(s, buffer_sp);
919
5
        return {cstr_len, was_capped};
920
34
      } else {
921
34
        s << "<invalid address>";
922
34
        error.SetErrorString("invalid address");
923
34
        CopyStringDataToBufferSP(s, buffer_sp);
924
34
        return {0, was_capped};
925
34
      }
926
39
    }
927
928
2.05k
    Address cstr_so_addr(cstr_address);
929
2.05k
    DataExtractor data;
930
2.05k
    if (cstr_len > 0 && 
honor_array1.39k
) {
931
      // I am using GetPointeeData() here to abstract the fact that some
932
      // ValueObjects are actually frozen pointers in the host but the pointed-
933
      // to data lives in the debuggee, and GetPointeeData() automatically
934
      // takes care of this
935
1.36k
      GetPointeeData(data, 0, cstr_len);
936
937
1.36k
      if ((bytes_read = data.GetByteSize()) > 0) {
938
1.36k
        total_bytes_read = bytes_read;
939
1.20M
        for (size_t offset = 0; offset < bytes_read; 
offset++1.20M
)
940
1.20M
          s.Printf("%c", *data.PeekData(offset, 1));
941
1.36k
        if (capped_data)
942
0
          was_capped = true;
943
1.36k
      }
944
1.36k
    } else {
945
695
      cstr_len = max_length;
946
695
      const size_t k_max_buf_size = 64;
947
948
695
      size_t offset = 0;
949
950
695
      int cstr_len_displayed = -1;
951
695
      bool capped_cstr = false;
952
      // I am using GetPointeeData() here to abstract the fact that some
953
      // ValueObjects are actually frozen pointers in the host but the pointed-
954
      // to data lives in the debuggee, and GetPointeeData() automatically
955
      // takes care of this
956
918
      while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0) {
957
914
        total_bytes_read += bytes_read;
958
914
        const char *cstr = data.PeekCStr(0);
959
914
        size_t len = strnlen(cstr, k_max_buf_size);
960
914
        if (cstr_len_displayed < 0)
961
691
          cstr_len_displayed = len;
962
963
914
        if (len == 0)
964
17
          break;
965
897
        cstr_len_displayed += len;
966
897
        if (len > bytes_read)
967
0
          len = bytes_read;
968
897
        if (len > cstr_len)
969
0
          len = cstr_len;
970
971
58.3k
        for (size_t offset = 0; offset < bytes_read; 
offset++57.4k
)
972
57.4k
          s.Printf("%c", *data.PeekData(offset, 1));
973
974
897
        if (len < k_max_buf_size)
975
668
          break;
976
977
229
        if (len >= cstr_len) {
978
6
          capped_cstr = true;
979
6
          break;
980
6
        }
981
982
223
        cstr_len -= len;
983
223
        offset += len;
984
223
      }
985
986
695
      if (cstr_len_displayed >= 0) {
987
691
        if (capped_cstr)
988
6
          was_capped = true;
989
691
      }
990
695
    }
991
2.05k
  } else {
992
0
    error.SetErrorString("not a string object");
993
0
    s << "<not a string object>";
994
0
  }
995
2.05k
  CopyStringDataToBufferSP(s, buffer_sp);
996
2.05k
  return {total_bytes_read, was_capped};
997
2.09k
}
998
999
226
const char *ValueObject::GetObjectDescription() {
1000
226
  if (!UpdateValueIfNeeded(true))
1001
0
    return nullptr;
1002
1003
  // Return cached value.
1004
226
  if (!m_object_desc_str.empty())
1005
0
    return m_object_desc_str.c_str();
1006
1007
226
  ExecutionContext exe_ctx(GetExecutionContextRef());
1008
226
  Process *process = exe_ctx.GetProcessPtr();
1009
226
  if (!process)
1010
0
    return nullptr;
1011
1012
  // Returns the object description produced by one language runtime.
1013
265
  
auto get_object_description = [&](LanguageType language) -> const char * 226
{
1014
265
    if (LanguageRuntime *runtime = process->GetLanguageRuntime(language)) {
1015
232
      StreamString s;
1016
232
      if (runtime->GetObjectDescription(s, *this)) {
1017
208
        m_object_desc_str.append(std::string(s.GetString()));
1018
208
        return m_object_desc_str.c_str();
1019
208
      }
1020
232
    }
1021
57
    return nullptr;
1022
265
  };
1023
1024
  // Try the native language runtime first.
1025
226
  LanguageType native_language = GetObjectRuntimeLanguage();
1026
226
  if (const char *desc = get_object_description(native_language))
1027
187
    return desc;
1028
1029
  // Try the Objective-C language runtime. This fallback is necessary
1030
  // for Objective-C++ and mixed Objective-C / C++ programs.
1031
39
  if (Language::LanguageIsCFamily(native_language))
1032
39
    return get_object_description(eLanguageTypeObjC);
1033
0
  return nullptr;
1034
39
}
1035
1036
bool ValueObject::GetValueAsCString(const lldb_private::TypeFormatImpl &format,
1037
54.4k
                                    std::string &destination) {
1038
54.4k
  if (UpdateValueIfNeeded(false))
1039
54.4k
    return format.FormatObject(this, destination);
1040
0
  else
1041
0
    return false;
1042
54.4k
}
1043
1044
bool ValueObject::GetValueAsCString(lldb::Format format,
1045
537
                                    std::string &destination) {
1046
537
  return GetValueAsCString(TypeFormatImpl_Format(format), destination);
1047
537
}
1048
1049
94.7k
const char *ValueObject::GetValueAsCString() {
1050
94.7k
  if (UpdateValueIfNeeded(true)) {
1051
94.5k
    lldb::TypeFormatImplSP format_sp;
1052
94.5k
    lldb::Format my_format = GetFormat();
1053
94.5k
    if (my_format == lldb::eFormatDefault) {
1054
93.3k
      if (m_type_format_sp)
1055
860
        format_sp = m_type_format_sp;
1056
92.5k
      else {
1057
92.5k
        if (m_flags.m_is_bitfield_for_scalar)
1058
33
          my_format = eFormatUnsigned;
1059
92.4k
        else {
1060
92.4k
          if (m_value.GetContextType() == Value::ContextType::RegisterInfo) {
1061
1.26k
            const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1062
1.26k
            if (reg_info)
1063
1.26k
              my_format = reg_info->format;
1064
91.2k
          } else {
1065
91.2k
            my_format = GetValue().GetCompilerType().GetFormat();
1066
91.2k
          }
1067
92.4k
        }
1068
92.5k
      }
1069
93.3k
    }
1070
94.5k
    if (my_format != m_last_format || 
m_value_str.empty()47.4k
) {
1071
53.9k
      m_last_format = my_format;
1072
53.9k
      if (!format_sp)
1073
53.6k
        format_sp = std::make_shared<TypeFormatImpl_Format>(my_format);
1074
53.9k
      if (GetValueAsCString(*format_sp.get(), m_value_str)) {
1075
42.4k
        if (!m_flags.m_value_did_change && 
m_flags.m_old_value_valid42.4k
) {
1076
          // The value was gotten successfully, so we consider the value as
1077
          // changed if the value string differs
1078
68
          SetValueDidChange(m_old_value_str != m_value_str);
1079
68
        }
1080
42.4k
      }
1081
53.9k
    }
1082
94.5k
  }
1083
94.7k
  if (m_value_str.empty())
1084
11.6k
    return nullptr;
1085
83.0k
  return m_value_str.c_str();
1086
94.7k
}
1087
1088
// if > 8bytes, 0 is returned. this method should mostly be used to read
1089
// address values out of pointers
1090
58.4k
uint64_t ValueObject::GetValueAsUnsigned(uint64_t fail_value, bool *success) {
1091
  // If our byte size is zero this is an aggregate type that has children
1092
58.4k
  if (CanProvideValue()) {
1093
58.1k
    Scalar scalar;
1094
58.1k
    if (ResolveValue(scalar)) {
1095
58.0k
      if (success)
1096
4.26k
        *success = true;
1097
58.0k
      scalar.MakeUnsigned();
1098
58.0k
      return scalar.ULongLong(fail_value);
1099
58.0k
    }
1100
    // fallthrough, otherwise...
1101
58.1k
  }
1102
1103
393
  if (success)
1104
34
    *success = false;
1105
393
  return fail_value;
1106
58.4k
}
1107
1108
456
int64_t ValueObject::GetValueAsSigned(int64_t fail_value, bool *success) {
1109
  // If our byte size is zero this is an aggregate type that has children
1110
456
  if (CanProvideValue()) {
1111
456
    Scalar scalar;
1112
456
    if (ResolveValue(scalar)) {
1113
456
      if (success)
1114
53
        *success = true;
1115
456
      scalar.MakeSigned();
1116
456
      return scalar.SLongLong(fail_value);
1117
456
    }
1118
    // fallthrough, otherwise...
1119
456
  }
1120
1121
0
  if (success)
1122
0
    *success = false;
1123
0
  return fail_value;
1124
456
}
1125
1126
// if any more "special cases" are added to
1127
// ValueObject::DumpPrintableRepresentation() please keep this call up to date
1128
// by returning true for your new special cases. We will eventually move to
1129
// checking this call result before trying to display special cases
1130
bool ValueObject::HasSpecialPrintableRepresentation(
1131
2.16k
    ValueObjectRepresentationStyle val_obj_display, Format custom_format) {
1132
2.16k
  Flags flags(GetTypeInfo());
1133
2.16k
  if (flags.AnySet(eTypeIsArray | eTypeIsPointer) &&
1134
2.16k
      val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) {
1135
2.16k
    if (IsCStringContainer(true) &&
1136
2.16k
        
(2.09k
custom_format == eFormatCString2.09k
||
custom_format == eFormatCharArray1.41k
||
1137
2.09k
         
custom_format == eFormatChar1.39k
||
custom_format == eFormatVectorOfChar1.36k
))
1138
2.09k
      return true;
1139
1140
66
    if (flags.Test(eTypeIsArray)) {
1141
36
      if ((custom_format == eFormatBytes) ||
1142
36
          
(custom_format == eFormatBytesWithASCII)24
)
1143
24
        return true;
1144
1145
12
      if ((custom_format == eFormatVectorOfChar) ||
1146
12
          (custom_format == eFormatVectorOfFloat32) ||
1147
12
          
(custom_format == eFormatVectorOfFloat64)6
||
1148
12
          
(custom_format == eFormatVectorOfSInt16)6
||
1149
12
          
(custom_format == eFormatVectorOfSInt32)6
||
1150
12
          
(custom_format == eFormatVectorOfSInt64)6
||
1151
12
          
(custom_format == eFormatVectorOfSInt8)6
||
1152
12
          
(custom_format == eFormatVectorOfUInt128)6
||
1153
12
          
(custom_format == eFormatVectorOfUInt16)6
||
1154
12
          
(custom_format == eFormatVectorOfUInt32)6
||
1155
12
          
(custom_format == eFormatVectorOfUInt64)0
||
1156
12
          
(custom_format == eFormatVectorOfUInt8)0
)
1157
12
        return true;
1158
12
    }
1159
66
  }
1160
30
  return false;
1161
2.16k
}
1162
1163
bool ValueObject::DumpPrintableRepresentation(
1164
    Stream &s, ValueObjectRepresentationStyle val_obj_display,
1165
    Format custom_format, PrintableRepresentationSpecialCases special,
1166
27.6k
    bool do_dump_error) {
1167
1168
27.6k
  Flags flags(GetTypeInfo());
1169
1170
27.6k
  bool allow_special =
1171
27.6k
      (special == ValueObject::PrintableRepresentationSpecialCases::eAllow);
1172
27.6k
  const bool only_special = false;
1173
1174
27.6k
  if (allow_special) {
1175
9.80k
    if (flags.AnySet(eTypeIsArray | eTypeIsPointer) &&
1176
9.80k
        
val_obj_display == ValueObject::eValueObjectRepresentationStyleValue4.80k
) {
1177
      // when being asked to get a printable display an array or pointer type
1178
      // directly, try to "do the right thing"
1179
1180
2.13k
      if (IsCStringContainer(true) &&
1181
2.13k
          
(2.09k
custom_format == eFormatCString2.09k
||
1182
2.09k
           
custom_format == eFormatCharArray1.41k
||
custom_format == eFormatChar1.39k
||
1183
2.09k
           custom_format ==
1184
1.36k
               eFormatVectorOfChar)) // print char[] & char* directly
1185
2.09k
      {
1186
2.09k
        Status error;
1187
2.09k
        lldb::DataBufferSP buffer_sp;
1188
2.09k
        std::pair<size_t, bool> read_string = ReadPointedString(
1189
2.09k
            buffer_sp, error, 0, (custom_format == eFormatVectorOfChar) ||
1190
2.09k
                                     
(custom_format == eFormatCharArray)729
);
1191
2.09k
        lldb_private::formatters::StringPrinter::
1192
2.09k
            ReadBufferAndDumpToStreamOptions options(*this);
1193
2.09k
        options.SetData(DataExtractor(
1194
2.09k
            buffer_sp, lldb::eByteOrderInvalid,
1195
2.09k
            8)); // none of this matters for a string - pass some defaults
1196
2.09k
        options.SetStream(&s);
1197
2.09k
        options.SetPrefixToken(nullptr);
1198
2.09k
        options.SetQuote('"');
1199
2.09k
        options.SetSourceSize(buffer_sp->GetByteSize());
1200
2.09k
        options.SetIsTruncated(read_string.second);
1201
2.09k
        options.SetBinaryZeroIsTerminator(custom_format != eFormatVectorOfChar);
1202
2.09k
        formatters::StringPrinter::ReadBufferAndDumpToStream<
1203
2.09k
            lldb_private::formatters::StringPrinter::StringElementType::ASCII>(
1204
2.09k
            options);
1205
2.09k
        return !error.Fail();
1206
2.09k
      }
1207
1208
36
      if (custom_format == eFormatEnum)
1209
0
        return false;
1210
1211
      // this only works for arrays, because I have no way to know when the
1212
      // pointed memory ends, and no special \0 end of data marker
1213
36
      if (flags.Test(eTypeIsArray)) {
1214
36
        if ((custom_format == eFormatBytes) ||
1215
36
            
(custom_format == eFormatBytesWithASCII)24
) {
1216
24
          const size_t count = GetNumChildren();
1217
1218
24
          s << '[';
1219
168
          for (size_t low = 0; low < count; 
low++144
) {
1220
1221
144
            if (low)
1222
120
              s << ',';
1223
1224
144
            ValueObjectSP child = GetChildAtIndex(low, true);
1225
144
            if (!child.get()) {
1226
0
              s << "<invalid child>";
1227
0
              continue;
1228
0
            }
1229
144
            child->DumpPrintableRepresentation(
1230
144
                s, ValueObject::eValueObjectRepresentationStyleValue,
1231
144
                custom_format);
1232
144
          }
1233
1234
24
          s << ']';
1235
1236
24
          return true;
1237
24
        }
1238
1239
12
        if ((custom_format == eFormatVectorOfChar) ||
1240
12
            (custom_format == eFormatVectorOfFloat32) ||
1241
12
            
(custom_format == eFormatVectorOfFloat64)6
||
1242
12
            
(custom_format == eFormatVectorOfSInt16)6
||
1243
12
            
(custom_format == eFormatVectorOfSInt32)6
||
1244
12
            
(custom_format == eFormatVectorOfSInt64)6
||
1245
12
            
(custom_format == eFormatVectorOfSInt8)6
||
1246
12
            
(custom_format == eFormatVectorOfUInt128)6
||
1247
12
            
(custom_format == eFormatVectorOfUInt16)6
||
1248
12
            
(custom_format == eFormatVectorOfUInt32)6
||
1249
12
            
(custom_format == eFormatVectorOfUInt64)0
||
1250
12
            
(custom_format == eFormatVectorOfUInt8)0
) // arrays of bytes, bytes
1251
                                                     // with ASCII or any vector
1252
                                                     // format should be printed
1253
                                                     // directly
1254
12
        {
1255
12
          const size_t count = GetNumChildren();
1256
1257
12
          Format format = FormatManager::GetSingleItemFormat(custom_format);
1258
1259
12
          s << '[';
1260
84
          for (size_t low = 0; low < count; 
low++72
) {
1261
1262
72
            if (low)
1263
60
              s << ',';
1264
1265
72
            ValueObjectSP child = GetChildAtIndex(low, true);
1266
72
            if (!child.get()) {
1267
0
              s << "<invalid child>";
1268
0
              continue;
1269
0
            }
1270
72
            child->DumpPrintableRepresentation(
1271
72
                s, ValueObject::eValueObjectRepresentationStyleValue, format);
1272
72
          }
1273
1274
12
          s << ']';
1275
1276
12
          return true;
1277
12
        }
1278
12
      }
1279
1280
0
      if ((custom_format == eFormatBoolean) ||
1281
0
          (custom_format == eFormatBinary) || (custom_format == eFormatChar) ||
1282
0
          (custom_format == eFormatCharPrintable) ||
1283
0
          (custom_format == eFormatComplexFloat) ||
1284
0
          (custom_format == eFormatDecimal) || (custom_format == eFormatHex) ||
1285
0
          (custom_format == eFormatHexUppercase) ||
1286
0
          (custom_format == eFormatFloat) || (custom_format == eFormatOctal) ||
1287
0
          (custom_format == eFormatOSType) ||
1288
0
          (custom_format == eFormatUnicode16) ||
1289
0
          (custom_format == eFormatUnicode32) ||
1290
0
          (custom_format == eFormatUnsigned) ||
1291
0
          (custom_format == eFormatPointer) ||
1292
0
          (custom_format == eFormatComplexInteger) ||
1293
0
          (custom_format == eFormatComplex) ||
1294
0
          (custom_format == eFormatDefault)) // use the [] operator
1295
0
        return false;
1296
0
    }
1297
9.80k
  }
1298
1299
25.5k
  if (only_special)
1300
0
    return false;
1301
1302
25.5k
  bool var_success = false;
1303
1304
25.5k
  {
1305
25.5k
    llvm::StringRef str;
1306
1307
    // this is a local stream that we are using to ensure that the data pointed
1308
    // to by cstr survives long enough for us to copy it to its destination -
1309
    // it is necessary to have this temporary storage area for cases where our
1310
    // desired output is not backed by some other longer-term storage
1311
25.5k
    StreamString strm;
1312
1313
25.5k
    if (custom_format != eFormatInvalid)
1314
543
      SetFormat(custom_format);
1315
1316
25.5k
    switch (val_obj_display) {
1317
432
    case eValueObjectRepresentationStyleValue:
1318
432
      str = GetValueAsCString();
1319
432
      break;
1320
1321
23.8k
    case eValueObjectRepresentationStyleSummary:
1322
23.8k
      str = GetSummaryAsCString();
1323
23.8k
      break;
1324
1325
6
    case eValueObjectRepresentationStyleLanguageSpecific:
1326
6
      str = GetObjectDescription();
1327
6
      break;
1328
1329
30
    case eValueObjectRepresentationStyleLocation:
1330
30
      str = GetLocationAsCString();
1331
30
      break;
1332
1333
1.17k
    case eValueObjectRepresentationStyleChildrenCount:
1334
1.17k
      strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
1335
1.17k
      str = strm.GetString();
1336
1.17k
      break;
1337
1338
15
    case eValueObjectRepresentationStyleType:
1339
15
      str = GetTypeName().GetStringRef();
1340
15
      break;
1341
1342
0
    case eValueObjectRepresentationStyleName:
1343
0
      str = GetName().GetStringRef();
1344
0
      break;
1345
1346
0
    case eValueObjectRepresentationStyleExpressionPath:
1347
0
      GetExpressionPath(strm);
1348
0
      str = strm.GetString();
1349
0
      break;
1350
25.5k
    }
1351
1352
25.5k
    if (str.empty()) {
1353
20.9k
      if (val_obj_display == eValueObjectRepresentationStyleValue)
1354
0
        str = GetSummaryAsCString();
1355
20.9k
      else if (val_obj_display == eValueObjectRepresentationStyleSummary) {
1356
20.9k
        if (!CanProvideValue()) {
1357
157
          strm.Printf("%s @ %s", GetTypeName().AsCString(),
1358
157
                      GetLocationAsCString());
1359
157
          str = strm.GetString();
1360
157
        } else
1361
20.8k
          str = GetValueAsCString();
1362
20.9k
      }
1363
20.9k
    }
1364
1365
25.5k
    if (!str.empty())
1366
25.3k
      s << str;
1367
142
    else {
1368
142
      if (m_error.Fail()) {
1369
127
        if (do_dump_error)
1370
12
          s.Printf("<%s>", m_error.AsCString());
1371
115
        else
1372
115
          return false;
1373
127
      } else 
if (15
val_obj_display == eValueObjectRepresentationStyleSummary15
)
1374
12
        s.PutCString("<no summary available>");
1375
3
      else if (val_obj_display == eValueObjectRepresentationStyleValue)
1376
0
        s.PutCString("<no value available>");
1377
3
      else if (val_obj_display ==
1378
3
               eValueObjectRepresentationStyleLanguageSpecific)
1379
3
        s.PutCString("<not a valid Objective-C object>"); // edit this if we
1380
                                                          // have other runtimes
1381
                                                          // that support a
1382
                                                          // description
1383
0
      else
1384
0
        s.PutCString("<no printable representation>");
1385
142
    }
1386
1387
    // we should only return false here if we could not do *anything* even if
1388
    // we have an error message as output, that's a success from our callers'
1389
    // perspective, so return true
1390
25.4k
    var_success = true;
1391
1392
25.4k
    if (custom_format != eFormatInvalid)
1393
543
      SetFormat(eFormatDefault);
1394
25.4k
  }
1395
1396
0
  return var_success;
1397
25.5k
}
1398
1399
addr_t ValueObject::GetAddressOf(bool scalar_is_load_address,
1400
8.40k
                                 AddressType *address_type) {
1401
  // Can't take address of a bitfield
1402
8.40k
  if (IsBitfield())
1403
0
    return LLDB_INVALID_ADDRESS;
1404
1405
8.40k
  if (!UpdateValueIfNeeded(false))
1406
0
    return LLDB_INVALID_ADDRESS;
1407
1408
8.40k
  switch (m_value.GetValueType()) {
1409
0
  case Value::ValueType::Invalid:
1410
0
    return LLDB_INVALID_ADDRESS;
1411
104
  case Value::ValueType::Scalar:
1412
104
    if (scalar_is_load_address) {
1413
61
      if (address_type)
1414
18
        *address_type = eAddressTypeLoad;
1415
61
      return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1416
61
    }
1417
43
    break;
1418
1419
7.68k
  case Value::ValueType::LoadAddress:
1420
7.92k
  case Value::ValueType::FileAddress: {
1421
7.92k
    if (address_type)
1422
7.75k
      *address_type = m_value.GetValueAddressType();
1423
7.92k
    return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1424
7.68k
  } 
break0
;
1425
369
  case Value::ValueType::HostAddress: {
1426
369
    if (address_type)
1427
369
      *address_type = m_value.GetValueAddressType();
1428
369
    return LLDB_INVALID_ADDRESS;
1429
7.68k
  } 
break0
;
1430
8.40k
  }
1431
43
  if (address_type)
1432
43
    *address_type = eAddressTypeInvalid;
1433
43
  return LLDB_INVALID_ADDRESS;
1434
8.40k
}
1435
1436
45.7k
addr_t ValueObject::GetPointerValue(AddressType *address_type) {
1437
45.7k
  addr_t address = LLDB_INVALID_ADDRESS;
1438
45.7k
  if (address_type)
1439
8.87k
    *address_type = eAddressTypeInvalid;
1440
1441
45.7k
  if (!UpdateValueIfNeeded(false))
1442
0
    return address;
1443
1444
45.7k
  switch (m_value.GetValueType()) {
1445
0
  case Value::ValueType::Invalid:
1446
0
    return LLDB_INVALID_ADDRESS;
1447
3.58k
  case Value::ValueType::Scalar:
1448
3.58k
    address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1449
3.58k
    break;
1450
1451
5.32k
  case Value::ValueType::HostAddress:
1452
42.0k
  case Value::ValueType::LoadAddress:
1453
42.1k
  case Value::ValueType::FileAddress: {
1454
42.1k
    lldb::offset_t data_offset = 0;
1455
42.1k
    address = m_data.GetAddress(&data_offset);
1456
42.1k
  } break;
1457
45.7k
  }
1458
1459
45.7k
  if (address_type)
1460
8.87k
    *address_type = GetAddressTypeOfChildren();
1461
1462
45.7k
  return address;
1463
45.7k
}
1464
1465
16
bool ValueObject::SetValueFromCString(const char *value_str, Status &error) {
1466
16
  error.Clear();
1467
  // Make sure our value is up to date first so that our location and location
1468
  // type is valid.
1469
16
  if (!UpdateValueIfNeeded(false)) {
1470
0
    error.SetErrorString("unable to read value");
1471
0
    return false;
1472
0
  }
1473
1474
16
  uint64_t count = 0;
1475
16
  const Encoding encoding = GetCompilerType().GetEncoding(count);
1476
1477
16
  const size_t byte_size = GetByteSize().getValueOr(0);
1478
1479
16
  Value::ValueType value_type = m_value.GetValueType();
1480
1481
16
  if (value_type == Value::ValueType::Scalar) {
1482
    // If the value is already a scalar, then let the scalar change itself:
1483
0
    m_value.GetScalar().SetValueFromCString(value_str, encoding, byte_size);
1484
16
  } else if (byte_size <= 16) {
1485
    // If the value fits in a scalar, then make a new scalar and again let the
1486
    // scalar code do the conversion, then figure out where to put the new
1487
    // value.
1488
16
    Scalar new_scalar;
1489
16
    error = new_scalar.SetValueFromCString(value_str, encoding, byte_size);
1490
16
    if (error.Success()) {
1491
16
      switch (value_type) {
1492
16
      case Value::ValueType::LoadAddress: {
1493
        // If it is a load address, then the scalar value is the storage
1494
        // location of the data, and we have to shove this value down to that
1495
        // load location.
1496
16
        ExecutionContext exe_ctx(GetExecutionContextRef());
1497
16
        Process *process = exe_ctx.GetProcessPtr();
1498
16
        if (process) {
1499
16
          addr_t target_addr =
1500
16
              m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1501
16
          size_t bytes_written = process->WriteScalarToMemory(
1502
16
              target_addr, new_scalar, byte_size, error);
1503
16
          if (!error.Success())
1504
0
            return false;
1505
16
          if (bytes_written != byte_size) {
1506
0
            error.SetErrorString("unable to write value to memory");
1507
0
            return false;
1508
0
          }
1509
16
        }
1510
16
      } break;
1511
16
      case Value::ValueType::HostAddress: {
1512
        // If it is a host address, then we stuff the scalar as a DataBuffer
1513
        // into the Value's data.
1514
0
        DataExtractor new_data;
1515
0
        new_data.SetByteOrder(m_data.GetByteOrder());
1516
1517
0
        DataBufferSP buffer_sp(new DataBufferHeap(byte_size, 0));
1518
0
        m_data.SetData(buffer_sp, 0);
1519
0
        bool success = new_scalar.GetData(new_data);
1520
0
        if (success) {
1521
0
          new_data.CopyByteOrderedData(
1522
0
              0, byte_size, const_cast<uint8_t *>(m_data.GetDataStart()),
1523
0
              byte_size, m_data.GetByteOrder());
1524
0
        }
1525
0
        m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1526
1527
0
      } break;
1528
0
      case Value::ValueType::Invalid:
1529
0
        error.SetErrorString("invalid location");
1530
0
        return false;
1531
0
      case Value::ValueType::FileAddress:
1532
0
      case Value::ValueType::Scalar:
1533
0
        break;
1534
16
      }
1535
16
    } else {
1536
0
      return false;
1537
0
    }
1538
16
  } else {
1539
    // We don't support setting things bigger than a scalar at present.
1540
0
    error.SetErrorString("unable to write aggregate data type");
1541
0
    return false;
1542
0
  }
1543
1544
  // If we have reached this point, then we have successfully changed the
1545
  // value.
1546
16
  SetNeedsUpdate();
1547
16
  return true;
1548
16
}
1549
1550
3
bool ValueObject::GetDeclaration(Declaration &decl) {
1551
3
  decl.Clear();
1552
3
  return false;
1553
3
}
1554
1555
void ValueObject::AddSyntheticChild(ConstString key,
1556
3.12k
                                    ValueObject *valobj) {
1557
3.12k
  m_synthetic_children[key] = valobj;
1558
3.12k
}
1559
1560
3.42k
ValueObjectSP ValueObject::GetSyntheticChild(ConstString key) const {
1561
3.42k
  ValueObjectSP synthetic_child_sp;
1562
3.42k
  std::map<ConstString, ValueObject *>::const_iterator pos =
1563
3.42k
      m_synthetic_children.find(key);
1564
3.42k
  if (pos != m_synthetic_children.end())
1565
289
    synthetic_child_sp = pos->second->GetSP();
1566
3.42k
  return synthetic_child_sp;
1567
3.42k
}
1568
1569
152k
bool ValueObject::IsPossibleDynamicType() {
1570
152k
  ExecutionContext exe_ctx(GetExecutionContextRef());
1571
152k
  Process *process = exe_ctx.GetProcessPtr();
1572
152k
  if (process)
1573
151k
    return process->IsPossibleDynamicValue(*this);
1574
746
  else
1575
746
    return GetCompilerType().IsPossibleDynamicType(nullptr, true, true);
1576
152k
}
1577
1578
2.97k
bool ValueObject::IsRuntimeSupportValue() {
1579
2.97k
  Process *process(GetProcessSP().get());
1580
2.97k
  if (!process)
1581
373
    return false;
1582
1583
  // We trust that the compiler did the right thing and marked runtime support
1584
  // values as artificial.
1585
2.60k
  if (!GetVariable() || 
!GetVariable()->IsArtificial()2.56k
)
1586
2.57k
    return false;
1587
1588
30
  if (auto *runtime = process->GetLanguageRuntime(GetVariable()->GetLanguage()))
1589
27
    if (runtime->IsAllowedRuntimeValue(GetName()))
1590
27
      return false;
1591
1592
3
  return true;
1593
30
}
1594
1595
53.9k
bool ValueObject::IsNilReference() {
1596
53.9k
  if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage())) {
1597
14.0k
    return language->IsNilReference(*this);
1598
14.0k
  }
1599
39.9k
  return false;
1600
53.9k
}
1601
1602
53.9k
bool ValueObject::IsUninitializedReference() {
1603
53.9k
  if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage())) {
1604
14.0k
    return language->IsUninitializedReference(*this);
1605
14.0k
  }
1606
39.9k
  return false;
1607
53.9k
}
1608
1609
// This allows you to create an array member using and index that doesn't not
1610
// fall in the normal bounds of the array. Many times structure can be defined
1611
// as: struct Collection {
1612
//     uint32_t item_count;
1613
//     Item item_array[0];
1614
// };
1615
// The size of the "item_array" is 1, but many times in practice there are more
1616
// items in "item_array".
1617
1618
ValueObjectSP ValueObject::GetSyntheticArrayMember(size_t index,
1619
338
                                                   bool can_create) {
1620
338
  ValueObjectSP synthetic_child_sp;
1621
338
  if (IsPointerType() || 
IsArrayType()6
) {
1622
338
    std::string index_str = llvm::formatv("[{0}]", index);
1623
338
    ConstString index_const_str(index_str);
1624
    // Check if we have already created a synthetic array member in this valid
1625
    // object. If we have we will re-use it.
1626
338
    synthetic_child_sp = GetSyntheticChild(index_const_str);
1627
338
    if (!synthetic_child_sp) {
1628
317
      ValueObject *synthetic_child;
1629
      // We haven't made a synthetic array member for INDEX yet, so lets make
1630
      // one and cache it for any future reference.
1631
317
      synthetic_child = CreateChildAtIndex(0, true, index);
1632
1633
      // Cache the value if we got one back...
1634
317
      if (synthetic_child) {
1635
315
        AddSyntheticChild(index_const_str, synthetic_child);
1636
315
        synthetic_child_sp = synthetic_child->GetSP();
1637
315
        synthetic_child_sp->SetName(ConstString(index_str));
1638
315
        synthetic_child_sp->m_flags.m_is_array_item_for_pointer = true;
1639
315
      }
1640
317
    }
1641
338
  }
1642
338
  return synthetic_child_sp;
1643
338
}
1644
1645
ValueObjectSP ValueObject::GetSyntheticBitFieldChild(uint32_t from, uint32_t to,
1646
69
                                                     bool can_create) {
1647
69
  ValueObjectSP synthetic_child_sp;
1648
69
  if (IsScalarType()) {
1649
69
    std::string index_str = llvm::formatv("[{0}-{1}]", from, to);
1650
69
    ConstString index_const_str(index_str);
1651
    // Check if we have already created a synthetic array member in this valid
1652
    // object. If we have we will re-use it.
1653
69
    synthetic_child_sp = GetSyntheticChild(index_const_str);
1654
69
    if (!synthetic_child_sp) {
1655
60
      uint32_t bit_field_size = to - from + 1;
1656
60
      uint32_t bit_field_offset = from;
1657
60
      if (GetDataExtractor().GetByteOrder() == eByteOrderBig)
1658
0
        bit_field_offset =
1659
0
            GetByteSize().getValueOr(0) * 8 - bit_field_size - bit_field_offset;
1660
      // We haven't made a synthetic array member for INDEX yet, so lets make
1661
      // one and cache it for any future reference.
1662
60
      ValueObjectChild *synthetic_child = new ValueObjectChild(
1663
60
          *this, GetCompilerType(), index_const_str,
1664
60
          GetByteSize().getValueOr(0), 0, bit_field_size, bit_field_offset,
1665
60
          false, false, eAddressTypeInvalid, 0);
1666
1667
      // Cache the value if we got one back...
1668
60
      if (synthetic_child) {
1669
60
        AddSyntheticChild(index_const_str, synthetic_child);
1670
60
        synthetic_child_sp = synthetic_child->GetSP();
1671
60
        synthetic_child_sp->SetName(ConstString(index_str));
1672
60
        synthetic_child_sp->m_flags.m_is_bitfield_for_scalar = true;
1673
60
      }
1674
60
    }
1675
69
  }
1676
69
  return synthetic_child_sp;
1677
69
}
1678
1679
ValueObjectSP ValueObject::GetSyntheticChildAtOffset(
1680
    uint32_t offset, const CompilerType &type, bool can_create,
1681
2.90k
    ConstString name_const_str) {
1682
1683
2.90k
  ValueObjectSP synthetic_child_sp;
1684
1685
2.90k
  if (name_const_str.IsEmpty()) {
1686
2.32k
    name_const_str.SetString("@" + std::to_string(offset));
1687
2.32k
  }
1688
1689
  // Check if we have already created a synthetic array member in this valid
1690
  // object. If we have we will re-use it.
1691
2.90k
  synthetic_child_sp = GetSyntheticChild(name_const_str);
1692
1693
2.90k
  if (synthetic_child_sp.get())
1694
246
    return synthetic_child_sp;
1695
1696
2.66k
  if (!can_create)
1697
0
    return {};
1698
1699
2.66k
  ExecutionContext exe_ctx(GetExecutionContextRef());
1700
2.66k
  llvm::Optional<uint64_t> size =
1701
2.66k
      type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
1702
2.66k
  if (!size)
1703
0
    return {};
1704
2.66k
  ValueObjectChild *synthetic_child =
1705
2.66k
      new ValueObjectChild(*this, type, name_const_str, *size, offset, 0, 0,
1706
2.66k
                           false, false, eAddressTypeInvalid, 0);
1707
2.66k
  if (synthetic_child) {
1708
2.66k
    AddSyntheticChild(name_const_str, synthetic_child);
1709
2.66k
    synthetic_child_sp = synthetic_child->GetSP();
1710
2.66k
    synthetic_child_sp->SetName(name_const_str);
1711
2.66k
    synthetic_child_sp->m_flags.m_is_child_at_offset = true;
1712
2.66k
  }
1713
2.66k
  return synthetic_child_sp;
1714
2.66k
}
1715
1716
ValueObjectSP ValueObject::GetSyntheticBase(uint32_t offset,
1717
                                            const CompilerType &type,
1718
                                            bool can_create,
1719
0
                                            ConstString name_const_str) {
1720
0
  ValueObjectSP synthetic_child_sp;
1721
1722
0
  if (name_const_str.IsEmpty()) {
1723
0
    char name_str[128];
1724
0
    snprintf(name_str, sizeof(name_str), "base%s@%i",
1725
0
             type.GetTypeName().AsCString("<unknown>"), offset);
1726
0
    name_const_str.SetCString(name_str);
1727
0
  }
1728
1729
  // Check if we have already created a synthetic array member in this valid
1730
  // object. If we have we will re-use it.
1731
0
  synthetic_child_sp = GetSyntheticChild(name_const_str);
1732
1733
0
  if (synthetic_child_sp.get())
1734
0
    return synthetic_child_sp;
1735
1736
0
  if (!can_create)
1737
0
    return {};
1738
1739
0
  const bool is_base_class = true;
1740
1741
0
  ExecutionContext exe_ctx(GetExecutionContextRef());
1742
0
  llvm::Optional<uint64_t> size =
1743
0
      type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
1744
0
  if (!size)
1745
0
    return {};
1746
0
  ValueObjectChild *synthetic_child =
1747
0
      new ValueObjectChild(*this, type, name_const_str, *size, offset, 0, 0,
1748
0
                           is_base_class, false, eAddressTypeInvalid, 0);
1749
0
  if (synthetic_child) {
1750
0
    AddSyntheticChild(name_const_str, synthetic_child);
1751
0
    synthetic_child_sp = synthetic_child->GetSP();
1752
0
    synthetic_child_sp->SetName(name_const_str);
1753
0
  }
1754
0
  return synthetic_child_sp;
1755
0
}
1756
1757
// your expression path needs to have a leading . or -> (unless it somehow
1758
// "looks like" an array, in which case it has a leading [ symbol). while the [
1759
// is meaningful and should be shown to the user, . and -> are just parser
1760
// design, but by no means added information for the user.. strip them off
1761
92
static const char *SkipLeadingExpressionPathSeparators(const char *expression) {
1762
92
  if (!expression || !expression[0])
1763
0
    return expression;
1764
92
  if (expression[0] == '.')
1765
92
    return expression + 1;
1766
0
  if (expression[0] == '-' && expression[1] == '>')
1767
0
    return expression + 2;
1768
0
  return expression;
1769
0
}
1770
1771
ValueObjectSP
1772
ValueObject::GetSyntheticExpressionPathChild(const char *expression,
1773
105
                                             bool can_create) {
1774
105
  ValueObjectSP synthetic_child_sp;
1775
105
  ConstString name_const_string(expression);
1776
  // Check if we have already created a synthetic array member in this valid
1777
  // object. If we have we will re-use it.
1778
105
  synthetic_child_sp = GetSyntheticChild(name_const_string);
1779
105
  if (!synthetic_child_sp) {
1780
    // We haven't made a synthetic array member for expression yet, so lets
1781
    // make one and cache it for any future reference.
1782
92
    synthetic_child_sp = GetValueForExpressionPath(
1783
92
        expression, nullptr, nullptr,
1784
92
        GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(
1785
92
            GetValueForExpressionPathOptions::SyntheticChildrenTraversal::
1786
92
                None));
1787
1788
    // Cache the value if we got one back...
1789
92
    if (synthetic_child_sp.get()) {
1790
      // FIXME: this causes a "real" child to end up with its name changed to
1791
      // the contents of expression
1792
92
      AddSyntheticChild(name_const_string, synthetic_child_sp.get());
1793
92
      synthetic_child_sp->SetName(
1794
92
          ConstString(SkipLeadingExpressionPathSeparators(expression)));
1795
92
    }
1796
92
  }
1797
105
  return synthetic_child_sp;
1798
105
}
1799
1800
186k
void ValueObject::CalculateSyntheticValue() {
1801
186k
  TargetSP target_sp(GetTargetSP());
1802
186k
  if (target_sp && !target_sp->GetEnableSyntheticValue()) {
1803
2
    m_synthetic_value = nullptr;
1804
2
    return;
1805
2
  }
1806
1807
186k
  lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
1808
1809
186k
  if (!UpdateFormatsIfNeeded() && 
m_synthetic_value144k
)
1810
24.9k
    return;
1811
1812
161k
  if (m_synthetic_children_sp.get() == nullptr)
1813
159k
    return;
1814
1815
2.52k
  if (current_synth_sp == m_synthetic_children_sp && 
m_synthetic_value1.36k
)
1816
3
    return;
1817
1818
2.52k
  m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
1819
2.52k
}
1820
1821
3.22k
void ValueObject::CalculateDynamicValue(DynamicValueType use_dynamic) {
1822
3.22k
  if (use_dynamic == eNoDynamicValues)
1823
0
    return;
1824
1825
3.22k
  if (!m_dynamic_value && !IsDynamic()) {
1826
3.22k
    ExecutionContext exe_ctx(GetExecutionContextRef());
1827
3.22k
    Process *process = exe_ctx.GetProcessPtr();
1828
3.22k
    if (process && 
process->IsPossibleDynamicValue(*this)2.90k
) {
1829
708
      ClearDynamicTypeInformation();
1830
708
      m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic);
1831
708
    }
1832
3.22k
  }
1833
3.22k
}
1834
1835
4.15k
ValueObjectSP ValueObject::GetDynamicValue(DynamicValueType use_dynamic) {
1836
4.15k
  if (use_dynamic == eNoDynamicValues)
1837
0
    return ValueObjectSP();
1838
1839
4.15k
  if (!IsDynamic() && m_dynamic_value == nullptr) {
1840
3.22k
    CalculateDynamicValue(use_dynamic);
1841
3.22k
  }
1842
4.15k
  if (m_dynamic_value)
1843
1.64k
    return m_dynamic_value->GetSP();
1844
2.51k
  else
1845
2.51k
    return ValueObjectSP();
1846
4.15k
}
1847
1848
186k
ValueObjectSP ValueObject::GetSyntheticValue() {
1849
186k
  CalculateSyntheticValue();
1850
1851
186k
  if (m_synthetic_value)
1852
27.4k
    return m_synthetic_value->GetSP();
1853
159k
  else
1854
159k
    return ValueObjectSP();
1855
186k
}
1856
1857
7.84k
bool ValueObject::HasSyntheticValue() {
1858
7.84k
  UpdateFormatsIfNeeded();
1859
1860
7.84k
  if (m_synthetic_children_sp.get() == nullptr)
1861
7.76k
    return false;
1862
1863
79
  CalculateSyntheticValue();
1864
1865
79
  return m_synthetic_value != nullptr;
1866
7.84k
}
1867
1868
5.32k
ValueObject *ValueObject::GetNonBaseClassParent() {
1869
5.32k
  if (GetParent()) {
1870
3.88k
    if (GetParent()->IsBaseClass())
1871
1.24k
      return GetParent()->GetNonBaseClassParent();
1872
2.63k
    else
1873
2.63k
      return GetParent();
1874
3.88k
  }
1875
1.44k
  return nullptr;
1876
5.32k
}
1877
1878
0
bool ValueObject::IsBaseClass(uint32_t &depth) {
1879
0
  if (!IsBaseClass()) {
1880
0
    depth = 0;
1881
0
    return false;
1882
0
  }
1883
0
  if (GetParent()) {
1884
0
    GetParent()->IsBaseClass(depth);
1885
0
    depth = depth + 1;
1886
0
    return true;
1887
0
  }
1888
  // TODO: a base of no parent? weird..
1889
0
  depth = 1;
1890
0
  return true;
1891
0
}
1892
1893
void ValueObject::GetExpressionPath(Stream &s,
1894
5.48k
                                    GetExpressionPathFormat epformat) {
1895
  // synthetic children do not actually "exist" as part of the hierarchy, and
1896
  // sometimes they are consed up in ways that don't make sense from an
1897
  // underlying language/API standpoint. So, use a special code path here to
1898
  // return something that can hopefully be used in expression
1899
5.48k
  if (m_flags.m_is_synthetic_children_generated) {
1900
6
    UpdateValueIfNeeded();
1901
1902
6
    if (m_value.GetValueType() == Value::ValueType::LoadAddress) {
1903
6
      if (IsPointerOrReferenceType()) {
1904
3
        s.Printf("((%s)0x%" PRIx64 ")", GetTypeName().AsCString("void"),
1905
3
                 GetValueAsUnsigned(0));
1906
3
        return;
1907
3
      } else {
1908
3
        uint64_t load_addr =
1909
3
            m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1910
3
        if (load_addr != LLDB_INVALID_ADDRESS) {
1911
3
          s.Printf("(*( (%s *)0x%" PRIx64 "))", GetTypeName().AsCString("void"),
1912
3
                   load_addr);
1913
3
          return;
1914
3
        }
1915
3
      }
1916
6
    }
1917
1918
0
    if (CanProvideValue()) {
1919
0
      s.Printf("((%s)%s)", GetTypeName().AsCString("void"),
1920
0
               GetValueAsCString());
1921
0
      return;
1922
0
    }
1923
1924
0
    return;
1925
0
  }
1926
1927
5.48k
  const bool is_deref_of_parent = IsDereferenceOfParent();
1928
1929
5.48k
  if (is_deref_of_parent &&
1930
5.48k
      
epformat == eGetExpressionPathFormatDereferencePointers143
) {
1931
    // this is the original format of GetExpressionPath() producing code like
1932
    // *(a_ptr).memberName, which is entirely fine, until you put this into
1933
    // StackFrame::GetValueForVariableExpressionPath() which prefers to see
1934
    // a_ptr->memberName. the eHonorPointers mode is meant to produce strings
1935
    // in this latter format
1936
15
    s.PutCString("*(");
1937
15
  }
1938
1939
5.48k
  ValueObject *parent = GetParent();
1940
1941
5.48k
  if (parent)
1942
4.04k
    parent->GetExpressionPath(s, epformat);
1943
1944
  // if we are a deref_of_parent just because we are synthetic array members
1945
  // made up to allow ptr[%d] syntax to work in variable printing, then add our
1946
  // name ([%d]) to the expression path
1947
5.48k
  if (m_flags.m_is_array_item_for_pointer &&
1948
5.48k
      
epformat == eGetExpressionPathFormatHonorPointers21
)
1949
6
    s.PutCString(m_name.GetStringRef());
1950
1951
5.48k
  if (!IsBaseClass()) {
1952
4.22k
    if (!is_deref_of_parent) {
1953
4.07k
      ValueObject *non_base_class_parent = GetNonBaseClassParent();
1954
4.07k
      if (non_base_class_parent &&
1955
4.07k
          
!non_base_class_parent->GetName().IsEmpty()2.63k
) {
1956
2.62k
        CompilerType non_base_class_parent_compiler_type =
1957
2.62k
            non_base_class_parent->GetCompilerType();
1958
2.62k
        if (non_base_class_parent_compiler_type) {
1959
2.62k
          if (parent && parent->IsDereferenceOfParent() &&
1960
2.62k
              
epformat == eGetExpressionPathFormatHonorPointers48
) {
1961
48
            s.PutCString("->");
1962
2.57k
          } else {
1963
2.57k
            const uint32_t non_base_class_parent_type_info =
1964
2.57k
                non_base_class_parent_compiler_type.GetTypeInfo();
1965
1966
2.57k
            if (non_base_class_parent_type_info & eTypeIsPointer) {
1967
1
              s.PutCString("->");
1968
2.57k
            } else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
1969
2.57k
                       !(non_base_class_parent_type_info & eTypeIsArray)) {
1970
2.55k
              s.PutChar('.');
1971
2.55k
            }
1972
2.57k
          }
1973
2.62k
        }
1974
2.62k
      }
1975
1976
4.07k
      const char *name = GetName().GetCString();
1977
4.07k
      if (name)
1978
4.06k
        s.PutCString(name);
1979
4.07k
    }
1980
4.22k
  }
1981
1982
5.48k
  if (is_deref_of_parent &&
1983
5.48k
      
epformat == eGetExpressionPathFormatDereferencePointers143
) {
1984
15
    s.PutChar(')');
1985
15
  }
1986
5.48k
}
1987
1988
ValueObjectSP ValueObject::GetValueForExpressionPath(
1989
    llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop,
1990
    ExpressionPathEndResultType *final_value_type,
1991
    const GetValueForExpressionPathOptions &options,
1992
1.33k
    ExpressionPathAftermath *final_task_on_target) {
1993
1994
1.33k
  ExpressionPathScanEndReason dummy_reason_to_stop =
1995
1.33k
      ValueObject::eExpressionPathScanEndReasonUnknown;
1996
1.33k
  ExpressionPathEndResultType dummy_final_value_type =
1997
1.33k
      ValueObject::eExpressionPathEndResultTypeInvalid;
1998
1.33k
  ExpressionPathAftermath dummy_final_task_on_target =
1999
1.33k
      ValueObject::eExpressionPathAftermathNothing;
2000
2001
1.33k
  ValueObjectSP ret_val = GetValueForExpressionPath_Impl(
2002
1.33k
      expression, reason_to_stop ? 
reason_to_stop1.14k
:
&dummy_reason_to_stop186
,
2003
1.33k
      final_value_type ? 
final_value_type1.14k
:
&dummy_final_value_type186
, options,
2004
1.33k
      final_task_on_target ? 
final_task_on_target1.14k
2005
1.33k
                           : 
&dummy_final_task_on_target186
);
2006
2007
1.33k
  if (!final_task_on_target ||
2008
1.33k
      
*final_task_on_target == ValueObject::eExpressionPathAftermathNothing1.14k
)
2009
1.32k
    return ret_val;
2010
2011
15
  if (ret_val.get() &&
2012
15
      ((final_value_type ? *final_value_type : 
dummy_final_value_type0
) ==
2013
15
       eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress
2014
                                           // of plain objects
2015
9
  {
2016
9
    if ((final_task_on_target ? *final_task_on_target
2017
9
                              : 
dummy_final_task_on_target0
) ==
2018
9
        ValueObject::eExpressionPathAftermathDereference) {
2019
9
      Status error;
2020
9
      ValueObjectSP final_value = ret_val->Dereference(error);
2021
9
      if (error.Fail() || !final_value.get()) {
2022
0
        if (reason_to_stop)
2023
0
          *reason_to_stop =
2024
0
              ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2025
0
        if (final_value_type)
2026
0
          *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2027
0
        return ValueObjectSP();
2028
9
      } else {
2029
9
        if (final_task_on_target)
2030
9
          *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2031
9
        return final_value;
2032
9
      }
2033
9
    }
2034
0
    if (*final_task_on_target ==
2035
0
        ValueObject::eExpressionPathAftermathTakeAddress) {
2036
0
      Status error;
2037
0
      ValueObjectSP final_value = ret_val->AddressOf(error);
2038
0
      if (error.Fail() || !final_value.get()) {
2039
0
        if (reason_to_stop)
2040
0
          *reason_to_stop =
2041
0
              ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2042
0
        if (final_value_type)
2043
0
          *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2044
0
        return ValueObjectSP();
2045
0
      } else {
2046
0
        if (final_task_on_target)
2047
0
          *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2048
0
        return final_value;
2049
0
      }
2050
0
    }
2051
0
  }
2052
6
  return ret_val; // final_task_on_target will still have its original value, so
2053
                  // you know I did not do it
2054
15
}
2055
2056
ValueObjectSP ValueObject::GetValueForExpressionPath_Impl(
2057
    llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop,
2058
    ExpressionPathEndResultType *final_result,
2059
    const GetValueForExpressionPathOptions &options,
2060
1.33k
    ExpressionPathAftermath *what_next) {
2061
1.33k
  ValueObjectSP root = GetSP();
2062
2063
1.33k
  if (!root)
2064
0
    return nullptr;
2065
2066
1.33k
  llvm::StringRef remainder = expression;
2067
2068
1.81k
  while (true) {
2069
1.81k
    llvm::StringRef temp_expression = remainder;
2070
2071
1.81k
    CompilerType root_compiler_type = root->GetCompilerType();
2072
1.81k
    CompilerType pointee_compiler_type;
2073
1.81k
    Flags pointee_compiler_type_info;
2074
2075
1.81k
    Flags root_compiler_type_info(
2076
1.81k
        root_compiler_type.GetTypeInfo(&pointee_compiler_type));
2077
1.81k
    if (pointee_compiler_type)
2078
546
      pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
2079
2080
1.81k
    if (temp_expression.empty()) {
2081
302
      *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2082
302
      return root;
2083
302
    }
2084
2085
1.51k
    switch (temp_expression.front()) {
2086
33
    case '-': {
2087
33
      temp_expression = temp_expression.drop_front();
2088
33
      if (options.m_check_dot_vs_arrow_syntax &&
2089
33
          
root_compiler_type_info.Test(eTypeIsPointer)0
) // if you are trying to
2090
                                                        // use -> on a
2091
                                                        // non-pointer and I
2092
                                                        // must catch the error
2093
0
      {
2094
0
        *reason_to_stop =
2095
0
            ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2096
0
        *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2097
0
        return ValueObjectSP();
2098
0
      }
2099
33
      if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to
2100
                                                       // extract an ObjC IVar
2101
                                                       // when this is forbidden
2102
33
          
root_compiler_type_info.Test(eTypeIsPointer)0
&&
2103
33
          
options.m_no_fragile_ivar0
) {
2104
0
        *reason_to_stop =
2105
0
            ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2106
0
        *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2107
0
        return ValueObjectSP();
2108
0
      }
2109
33
      if (!temp_expression.startswith(">")) {
2110
0
        *reason_to_stop =
2111
0
            ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2112
0
        *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2113
0
        return ValueObjectSP();
2114
0
      }
2115
33
    }
2116
33
      LLVM_FALLTHROUGH;
2117
1.03k
    case '.': // or fallthrough from ->
2118
1.03k
    {
2119
1.03k
      if (options.m_check_dot_vs_arrow_syntax &&
2120
1.03k
          
temp_expression.front() == '.'0
&&
2121
1.03k
          
root_compiler_type_info.Test(eTypeIsPointer)0
) // if you are trying to
2122
                                                        // use . on a pointer
2123
                                                        // and I must catch the
2124
                                                        // error
2125
0
      {
2126
0
        *reason_to_stop =
2127
0
            ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2128
0
        *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2129
0
        return nullptr;
2130
0
      }
2131
1.03k
      temp_expression = temp_expression.drop_front(); // skip . or >
2132
2133
1.03k
      size_t next_sep_pos = temp_expression.find_first_of("-.[", 1);
2134
1.03k
      ConstString child_name;
2135
1.03k
      if (next_sep_pos == llvm::StringRef::npos) // if no other separator just
2136
                                                 // expand this last layer
2137
884
      {
2138
884
        child_name.SetString(temp_expression);
2139
884
        ValueObjectSP child_valobj_sp =
2140
884
            root->GetChildMemberWithName(child_name, true);
2141
2142
884
        if (child_valobj_sp.get()) // we know we are done, so just return
2143
836
        {
2144
836
          *reason_to_stop =
2145
836
              ValueObject::eExpressionPathScanEndReasonEndOfString;
2146
836
          *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2147
836
          return child_valobj_sp;
2148
836
        } else {
2149
48
          switch (options.m_synthetic_children_traversal) {
2150
24
          case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::
2151
24
              None:
2152
24
            break;
2153
0
          case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::
2154
0
              FromSynthetic:
2155
0
            if (root->IsSynthetic()) {
2156
0
              child_valobj_sp = root->GetNonSyntheticValue();
2157
0
              if (child_valobj_sp.get())
2158
0
                child_valobj_sp =
2159
0
                    child_valobj_sp->GetChildMemberWithName(child_name, true);
2160
0
            }
2161
0
            break;
2162
0
          case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::
2163
0
              ToSynthetic:
2164
0
            if (!root->IsSynthetic()) {
2165
0
              child_valobj_sp = root->GetSyntheticValue();
2166
0
              if (child_valobj_sp.get())
2167
0
                child_valobj_sp =
2168
0
                    child_valobj_sp->GetChildMemberWithName(child_name, true);
2169
0
            }
2170
0
            break;
2171
24
          case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::
2172
24
              Both:
2173
24
            if (root->IsSynthetic()) {
2174
6
              child_valobj_sp = root->GetNonSyntheticValue();
2175
6
              if (child_valobj_sp.get())
2176
6
                child_valobj_sp =
2177
6
                    child_valobj_sp->GetChildMemberWithName(child_name, true);
2178
18
            } else {
2179
18
              child_valobj_sp = root->GetSyntheticValue();
2180
18
              if (child_valobj_sp.get())
2181
0
                child_valobj_sp =
2182
0
                    child_valobj_sp->GetChildMemberWithName(child_name, true);
2183
18
            }
2184
24
            break;
2185
48
          }
2186
48
        }
2187
2188
        // if we are here and options.m_no_synthetic_children is true,
2189
        // child_valobj_sp is going to be a NULL SP, so we hit the "else"
2190
        // branch, and return an error
2191
48
        if (child_valobj_sp.get()) // if it worked, just return
2192
6
        {
2193
6
          *reason_to_stop =
2194
6
              ValueObject::eExpressionPathScanEndReasonEndOfString;
2195
6
          *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2196
6
          return child_valobj_sp;
2197
42
        } else {
2198
42
          *reason_to_stop =
2199
42
              ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2200
42
          *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2201
42
          return nullptr;
2202
42
        }
2203
48
      } else // other layers do expand
2204
153
      {
2205
153
        llvm::StringRef next_separator = temp_expression.substr(next_sep_pos);
2206
2207
153
        child_name.SetString(temp_expression.slice(0, next_sep_pos));
2208
2209
153
        ValueObjectSP child_valobj_sp =
2210
153
            root->GetChildMemberWithName(child_name, true);
2211
153
        if (child_valobj_sp.get()) // store the new root and move on
2212
153
        {
2213
153
          root = child_valobj_sp;
2214
153
          remainder = next_separator;
2215
153
          *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2216
153
          continue;
2217
153
        } else {
2218
0
          switch (options.m_synthetic_children_traversal) {
2219
0
          case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::
2220
0
              None:
2221
0
            break;
2222
0
          case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::
2223
0
              FromSynthetic:
2224
0
            if (root->IsSynthetic()) {
2225
0
              child_valobj_sp = root->GetNonSyntheticValue();
2226
0
              if (child_valobj_sp.get())
2227
0
                child_valobj_sp =
2228
0
                    child_valobj_sp->GetChildMemberWithName(child_name, true);
2229
0
            }
2230
0
            break;
2231
0
          case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::
2232
0
              ToSynthetic:
2233
0
            if (!root->IsSynthetic()) {
2234
0
              child_valobj_sp = root->GetSyntheticValue();
2235
0
              if (child_valobj_sp.get())
2236
0
                child_valobj_sp =
2237
0
                    child_valobj_sp->GetChildMemberWithName(child_name, true);
2238
0
            }
2239
0
            break;
2240
0
          case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::
2241
0
              Both:
2242
0
            if (root->IsSynthetic()) {
2243
0
              child_valobj_sp = root->GetNonSyntheticValue();
2244
0
              if (child_valobj_sp.get())
2245
0
                child_valobj_sp =
2246
0
                    child_valobj_sp->GetChildMemberWithName(child_name, true);
2247
0
            } else {
2248
0
              child_valobj_sp = root->GetSyntheticValue();
2249
0
              if (child_valobj_sp.get())
2250
0
                child_valobj_sp =
2251
0
                    child_valobj_sp->GetChildMemberWithName(child_name, true);
2252
0
            }
2253
0
            break;
2254
0
          }
2255
0
        }
2256
2257
        // if we are here and options.m_no_synthetic_children is true,
2258
        // child_valobj_sp is going to be a NULL SP, so we hit the "else"
2259
        // branch, and return an error
2260
0
        if (child_valobj_sp.get()) // if it worked, move on
2261
0
        {
2262
0
          root = child_valobj_sp;
2263
0
          remainder = next_separator;
2264
0
          *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2265
0
          continue;
2266
0
        } else {
2267
0
          *reason_to_stop =
2268
0
              ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2269
0
          *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2270
0
          return nullptr;
2271
0
        }
2272
0
      }
2273
0
      break;
2274
1.03k
    }
2275
478
    case '[': {
2276
478
      if (!root_compiler_type_info.Test(eTypeIsArray) &&
2277
478
          
!root_compiler_type_info.Test(eTypeIsPointer)197
&&
2278
478
          !root_compiler_type_info.Test(
2279
78
              eTypeIsVector)) // if this is not a T[] nor a T*
2280
78
      {
2281
78
        if (!root_compiler_type_info.Test(
2282
78
                eTypeIsScalar)) // if this is not even a scalar...
2283
9
        {
2284
9
          if (options.m_synthetic_children_traversal ==
2285
9
              GetValueForExpressionPathOptions::SyntheticChildrenTraversal::
2286
9
                  None) // ...only chance left is synthetic
2287
0
          {
2288
0
            *reason_to_stop =
2289
0
                ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2290
0
            *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2291
0
            return ValueObjectSP();
2292
0
          }
2293
69
        } else if (!options.m_allow_bitfields_syntax) // if this is a scalar,
2294
                                                      // check that we can
2295
                                                      // expand bitfields
2296
0
        {
2297
0
          *reason_to_stop =
2298
0
              ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2299
0
          *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2300
0
          return ValueObjectSP();
2301
0
        }
2302
78
      }
2303
478
      if (temp_expression[1] ==
2304
478
          ']') // if this is an unbounded range it only works for arrays
2305
42
      {
2306
42
        if (!root_compiler_type_info.Test(eTypeIsArray)) {
2307
12
          *reason_to_stop =
2308
12
              ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2309
12
          *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2310
12
          return nullptr;
2311
12
        } else // even if something follows, we cannot expand unbounded ranges,
2312
               // just let the caller do it
2313
30
        {
2314
30
          *reason_to_stop =
2315
30
              ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2316
30
          *final_result =
2317
30
              ValueObject::eExpressionPathEndResultTypeUnboundedRange;
2318
30
          return root;
2319
30
        }
2320
42
      }
2321
2322
436
      size_t close_bracket_position = temp_expression.find(']', 1);
2323
436
      if (close_bracket_position ==
2324
436
          llvm::StringRef::npos) // if there is no ], this is a syntax error
2325
0
      {
2326
0
        *reason_to_stop =
2327
0
            ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2328
0
        *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2329
0
        return nullptr;
2330
0
      }
2331
2332
436
      llvm::StringRef bracket_expr =
2333
436
          temp_expression.slice(1, close_bracket_position);
2334
2335
      // If this was an empty expression it would have been caught by the if
2336
      // above.
2337
436
      assert(!bracket_expr.empty());
2338
2339
436
      if (!bracket_expr.contains('-')) {
2340
        // if no separator, this is of the form [N].  Note that this cannot be
2341
        // an unbounded range of the form [], because that case was handled
2342
        // above with an unconditional return.
2343
325
        unsigned long index = 0;
2344
325
        if (bracket_expr.getAsInteger(0, index)) {
2345
0
          *reason_to_stop =
2346
0
              ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2347
0
          *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2348
0
          return nullptr;
2349
0
        }
2350
2351
        // from here on we do have a valid index
2352
325
        if (root_compiler_type_info.Test(eTypeIsArray)) {
2353
233
          ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2354
233
          if (!child_valobj_sp)
2355
0
            child_valobj_sp = root->GetSyntheticArrayMember(index, true);
2356
233
          if (!child_valobj_sp)
2357
0
            if (root->HasSyntheticValue() &&
2358
0
                root->GetSyntheticValue()->GetNumChildren() > index)
2359
0
              child_valobj_sp =
2360
0
                  root->GetSyntheticValue()->GetChildAtIndex(index, true);
2361
233
          if (child_valobj_sp) {
2362
233
            root = child_valobj_sp;
2363
233
            remainder =
2364
233
                temp_expression.substr(close_bracket_position + 1); // skip ]
2365
233
            *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2366
233
            continue;
2367
233
          } else {
2368
0
            *reason_to_stop =
2369
0
                ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2370
0
            *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2371
0
            return nullptr;
2372
0
          }
2373
233
        } else 
if (92
root_compiler_type_info.Test(eTypeIsPointer)92
) {
2374
74
          if (*what_next ==
2375
74
                  ValueObject::
2376
74
                      eExpressionPathAftermathDereference && // if this is a
2377
                                                             // ptr-to-scalar, I
2378
                                                             // am accessing it
2379
                                                             // by index and I
2380
                                                             // would have
2381
                                                             // deref'ed anyway,
2382
                                                             // then do it now
2383
                                                             // and use this as
2384
                                                             // a bitfield
2385
74
              
pointee_compiler_type_info.Test(eTypeIsScalar)6
) {
2386
6
            Status error;
2387
6
            root = root->Dereference(error);
2388
6
            if (error.Fail() || !root) {
2389
0
              *reason_to_stop =
2390
0
                  ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2391
0
              *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2392
0
              return nullptr;
2393
6
            } else {
2394
6
              *what_next = eExpressionPathAftermathNothing;
2395
6
              continue;
2396
6
            }
2397
68
          } else {
2398
68
            if (root->GetCompilerType().GetMinimumLanguage() ==
2399
68
                    eLanguageTypeObjC &&
2400
68
                
pointee_compiler_type_info.AllClear(eTypeIsPointer)0
&&
2401
68
                
root->HasSyntheticValue()0
&&
2402
68
                
(0
options.m_synthetic_children_traversal ==
2403
0
                     GetValueForExpressionPathOptions::
2404
0
                         SyntheticChildrenTraversal::ToSynthetic ||
2405
0
                 options.m_synthetic_children_traversal ==
2406
0
                     GetValueForExpressionPathOptions::
2407
0
                         SyntheticChildrenTraversal::Both)) {
2408
0
              root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
2409
0
            } else
2410
68
              root = root->GetSyntheticArrayMember(index, true);
2411
68
            if (!root) {
2412
2
              *reason_to_stop =
2413
2
                  ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2414
2
              *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2415
2
              return nullptr;
2416
66
            } else {
2417
66
              remainder =
2418
66
                  temp_expression.substr(close_bracket_position + 1); // skip ]
2419
66
              *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2420
66
              continue;
2421
66
            }
2422
68
          }
2423
74
        } else 
if (18
root_compiler_type_info.Test(eTypeIsScalar)18
) {
2424
9
          root = root->GetSyntheticBitFieldChild(index, index, true);
2425
9
          if (!root) {
2426
0
            *reason_to_stop =
2427
0
                ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2428
0
            *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2429
0
            return nullptr;
2430
0
          } else // we do not know how to expand members of bitfields, so we
2431
                 // just return and let the caller do any further processing
2432
9
          {
2433
9
            *reason_to_stop = ValueObject::
2434
9
                eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2435
9
            *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
2436
9
            return root;
2437
9
          }
2438
9
        } else if (root_compiler_type_info.Test(eTypeIsVector)) {
2439
0
          root = root->GetChildAtIndex(index, true);
2440
0
          if (!root) {
2441
0
            *reason_to_stop =
2442
0
                ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2443
0
            *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2444
0
            return ValueObjectSP();
2445
0
          } else {
2446
0
            remainder =
2447
0
                temp_expression.substr(close_bracket_position + 1); // skip ]
2448
0
            *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2449
0
            continue;
2450
0
          }
2451
9
        } else if (options.m_synthetic_children_traversal ==
2452
9
                       GetValueForExpressionPathOptions::
2453
9
                           SyntheticChildrenTraversal::ToSynthetic ||
2454
9
                   options.m_synthetic_children_traversal ==
2455
9
                       GetValueForExpressionPathOptions::
2456
9
                           SyntheticChildrenTraversal::Both) {
2457
9
          if (root->HasSyntheticValue())
2458
0
            root = root->GetSyntheticValue();
2459
9
          else if (!root->IsSynthetic()) {
2460
0
            *reason_to_stop =
2461
0
                ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2462
0
            *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2463
0
            return nullptr;
2464
0
          }
2465
          // if we are here, then root itself is a synthetic VO.. should be
2466
          // good to go
2467
2468
9
          if (!root) {
2469
0
            *reason_to_stop =
2470
0
                ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2471
0
            *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2472
0
            return nullptr;
2473
0
          }
2474
9
          root = root->GetChildAtIndex(index, true);
2475
9
          if (!root) {
2476
0
            *reason_to_stop =
2477
0
                ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2478
0
            *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2479
0
            return nullptr;
2480
9
          } else {
2481
9
            remainder =
2482
9
                temp_expression.substr(close_bracket_position + 1); // skip ]
2483
9
            *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2484
9
            continue;
2485
9
          }
2486
9
        } else {
2487
0
          *reason_to_stop =
2488
0
              ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2489
0
          *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2490
0
          return nullptr;
2491
0
        }
2492
325
      } else {
2493
        // we have a low and a high index
2494
111
        llvm::StringRef sleft, sright;
2495
111
        unsigned long low_index, high_index;
2496
111
        std::tie(sleft, sright) = bracket_expr.split('-');
2497
111
        if (sleft.getAsInteger(0, low_index) ||
2498
111
            sright.getAsInteger(0, high_index)) {
2499
0
          *reason_to_stop =
2500
0
              ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2501
0
          *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2502
0
          return nullptr;
2503
0
        }
2504
2505
111
        if (low_index > high_index) // swap indices if required
2506
3
          std::swap(low_index, high_index);
2507
2508
111
        if (root_compiler_type_info.Test(
2509
111
                eTypeIsScalar)) // expansion only works for scalars
2510
60
        {
2511
60
          root = root->GetSyntheticBitFieldChild(low_index, high_index, true);
2512
60
          if (!root) {
2513
0
            *reason_to_stop =
2514
0
                ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2515
0
            *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2516
0
            return nullptr;
2517
60
          } else {
2518
60
            *reason_to_stop = ValueObject::
2519
60
                eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2520
60
            *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
2521
60
            return root;
2522
60
          }
2523
60
        } else 
if (51
root_compiler_type_info.Test(
2524
51
                       eTypeIsPointer) && // if this is a ptr-to-scalar, I am
2525
                                          // accessing it by index and I would
2526
                                          // have deref'ed anyway, then do it
2527
                                          // now and use this as a bitfield
2528
51
                   *what_next ==
2529
33
                       ValueObject::eExpressionPathAftermathDereference &&
2530
51
                   
pointee_compiler_type_info.Test(eTypeIsScalar)15
) {
2531
15
          Status error;
2532
15
          root = root->Dereference(error);
2533
15
          if (error.Fail() || !root) {
2534
0
            *reason_to_stop =
2535
0
                ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2536
0
            *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2537
0
            return nullptr;
2538
15
          } else {
2539
15
            *what_next = ValueObject::eExpressionPathAftermathNothing;
2540
15
            continue;
2541
15
          }
2542
36
        } else {
2543
36
          *reason_to_stop =
2544
36
              ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2545
36
          *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
2546
36
          return root;
2547
36
        }
2548
111
      }
2549
0
      break;
2550
436
    }
2551
0
    default: // some non-separator is in the way
2552
0
    {
2553
0
      *reason_to_stop =
2554
0
          ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2555
0
      *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2556
0
      return nullptr;
2557
436
    }
2558
1.51k
    }
2559
1.51k
  }
2560
1.33k
}
2561
2562
24.0k
void ValueObject::Dump(Stream &s) { Dump(s, DumpValueObjectOptions(*this)); }
2563
2564
37.1k
void ValueObject::Dump(Stream &s, const DumpValueObjectOptions &options) {
2565
37.1k
  ValueObjectPrinter printer(this, &s, options);
2566
37.1k
  printer.PrintValueObject();
2567
37.1k
}
2568
2569
220
ValueObjectSP ValueObject::CreateConstantValue(ConstString name) {
2570
220
  ValueObjectSP valobj_sp;
2571
2572
220
  if (UpdateValueIfNeeded(false) && m_error.Success()) {
2573
220
    ExecutionContext exe_ctx(GetExecutionContextRef());
2574
2575
220
    DataExtractor data;
2576
220
    data.SetByteOrder(m_data.GetByteOrder());
2577
220
    data.SetAddressByteSize(m_data.GetAddressByteSize());
2578
2579
220
    if (IsBitfield()) {
2580
0
      Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
2581
0
      m_error = v.GetValueAsData(&exe_ctx, data, GetModule().get());
2582
0
    } else
2583
220
      m_error = m_value.GetValueAsData(&exe_ctx, data, GetModule().get());
2584
2585
220
    valobj_sp = ValueObjectConstResult::Create(
2586
220
        exe_ctx.GetBestExecutionContextScope(), GetCompilerType(), name, data,
2587
220
        GetAddressOf());
2588
220
  }
2589
2590
220
  if (!valobj_sp) {
2591
0
    ExecutionContext exe_ctx(GetExecutionContextRef());
2592
0
    valobj_sp = ValueObjectConstResult::Create(
2593
0
        exe_ctx.GetBestExecutionContextScope(), m_error);
2594
0
  }
2595
220
  return valobj_sp;
2596
220
}
2597
2598
ValueObjectSP ValueObject::GetQualifiedRepresentationIfAvailable(
2599
351k
    lldb::DynamicValueType dynValue, bool synthValue) {
2600
351k
  ValueObjectSP result_sp(GetSP());
2601
2602
351k
  switch (dynValue) {
2603
3.11k
  case lldb::eDynamicCanRunTarget:
2604
5.98k
  case lldb::eDynamicDontRunTarget: {
2605
5.98k
    if (!result_sp->IsDynamic()) {
2606
1.76k
      if (result_sp->GetDynamicValue(dynValue))
2607
302
        result_sp = result_sp->GetDynamicValue(dynValue);
2608
1.76k
    }
2609
5.98k
  } break;
2610
345k
  case lldb::eNoDynamicValues: {
2611
345k
    if (result_sp->IsDynamic()) {
2612
2.11k
      if (result_sp->GetStaticValue())
2613
2.11k
        result_sp = result_sp->GetStaticValue();
2614
2.11k
    }
2615
345k
  } break;
2616
351k
  }
2617
2618
351k
  if (synthValue) {
2619
16.7k
    if (!result_sp->IsSynthetic()) {
2620
9.75k
      if (result_sp->GetSyntheticValue())
2621
301
        result_sp = result_sp->GetSyntheticValue();
2622
9.75k
    }
2623
335k
  } else {
2624
335k
    if (result_sp->IsSynthetic()) {
2625
46
      if (result_sp->GetNonSyntheticValue())
2626
46
        result_sp = result_sp->GetNonSyntheticValue();
2627
46
    }
2628
335k
  }
2629
2630
351k
  return result_sp;
2631
351k
}
2632
2633
2.08k
ValueObjectSP ValueObject::Dereference(Status &error) {
2634
2.08k
  if (m_deref_valobj)
2635
391
    return m_deref_valobj->GetSP();
2636
2637
1.69k
  const bool is_pointer_or_reference_type = IsPointerOrReferenceType();
2638
1.69k
  if (is_pointer_or_reference_type) {
2639
1.67k
    bool omit_empty_base_classes = true;
2640
1.67k
    bool ignore_array_bounds = false;
2641
2642
1.67k
    std::string child_name_str;
2643
1.67k
    uint32_t child_byte_size = 0;
2644
1.67k
    int32_t child_byte_offset = 0;
2645
1.67k
    uint32_t child_bitfield_bit_size = 0;
2646
1.67k
    uint32_t child_bitfield_bit_offset = 0;
2647
1.67k
    bool child_is_base_class = false;
2648
1.67k
    bool child_is_deref_of_parent = false;
2649
1.67k
    const bool transparent_pointers = false;
2650
1.67k
    CompilerType compiler_type = GetCompilerType();
2651
1.67k
    CompilerType child_compiler_type;
2652
1.67k
    uint64_t language_flags = 0;
2653
2654
1.67k
    ExecutionContext exe_ctx(GetExecutionContextRef());
2655
2656
1.67k
    child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex(
2657
1.67k
        &exe_ctx, 0, transparent_pointers, omit_empty_base_classes,
2658
1.67k
        ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset,
2659
1.67k
        child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
2660
1.67k
        child_is_deref_of_parent, this, language_flags);
2661
1.67k
    if (child_compiler_type && 
child_byte_size1.65k
) {
2662
1.65k
      ConstString child_name;
2663
1.65k
      if (!child_name_str.empty())
2664
1.65k
        child_name.SetCString(child_name_str.c_str());
2665
2666
1.65k
      m_deref_valobj = new ValueObjectChild(
2667
1.65k
          *this, child_compiler_type, child_name, child_byte_size,
2668
1.65k
          child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset,
2669
1.65k
          child_is_base_class, child_is_deref_of_parent, eAddressTypeInvalid,
2670
1.65k
          language_flags);
2671
1.65k
    }
2672
2673
    // In case of incomplete child compiler type, use the pointee type and try
2674
    // to recreate a new ValueObjectChild using it.
2675
1.67k
    if (!m_deref_valobj) {
2676
13
      if (HasSyntheticValue()) {
2677
6
        child_compiler_type = compiler_type.GetPointeeType();
2678
2679
6
        if (child_compiler_type) {
2680
6
          ConstString child_name;
2681
6
          if (!child_name_str.empty())
2682
6
            child_name.SetCString(child_name_str.c_str());
2683
2684
6
          m_deref_valobj = new ValueObjectChild(
2685
6
              *this, child_compiler_type, child_name, child_byte_size,
2686
6
              child_byte_offset, child_bitfield_bit_size,
2687
6
              child_bitfield_bit_offset, child_is_base_class,
2688
6
              child_is_deref_of_parent, eAddressTypeInvalid, language_flags);
2689
6
        }
2690
6
      }
2691
13
    }
2692
2693
1.67k
  } else 
if (22
HasSyntheticValue()22
) {
2694
13
    m_deref_valobj =
2695
13
        GetSyntheticValue()
2696
13
            ->GetChildMemberWithName(ConstString("$$dereference$$"), true)
2697
13
            .get();
2698
13
  } else 
if (9
IsSynthetic()9
) {
2699
3
    m_deref_valobj =
2700
3
        GetChildMemberWithName(ConstString("$$dereference$$"), true).get();
2701
3
  }
2702
2703
1.69k
  if (m_deref_valobj) {
2704
1.68k
    error.Clear();
2705
1.68k
    return m_deref_valobj->GetSP();
2706
1.68k
  } else {
2707
13
    StreamString strm;
2708
13
    GetExpressionPath(strm);
2709
2710
13
    if (is_pointer_or_reference_type)
2711
7
      error.SetErrorStringWithFormat("dereference failed: (%s) %s",
2712
7
                                     GetTypeName().AsCString("<invalid type>"),
2713
7
                                     strm.GetData());
2714
6
    else
2715
6
      error.SetErrorStringWithFormat("not a pointer or reference type: (%s) %s",
2716
6
                                     GetTypeName().AsCString("<invalid type>"),
2717
6
                                     strm.GetData());
2718
13
    return ValueObjectSP();
2719
13
  }
2720
1.69k
}
2721
2722
238
ValueObjectSP ValueObject::AddressOf(Status &error) {
2723
238
  if (m_addr_of_valobj_sp)
2724
89
    return m_addr_of_valobj_sp;
2725
2726
149
  AddressType address_type = eAddressTypeInvalid;
2727
149
  const bool scalar_is_load_address = false;
2728
149
  addr_t addr = GetAddressOf(scalar_is_load_address, &address_type);
2729
149
  error.Clear();
2730
149
  if (addr != LLDB_INVALID_ADDRESS && 
address_type != eAddressTypeHost140
) {
2731
140
    switch (address_type) {
2732
0
    case eAddressTypeInvalid: {
2733
0
      StreamString expr_path_strm;
2734
0
      GetExpressionPath(expr_path_strm);
2735
0
      error.SetErrorStringWithFormat("'%s' is not in memory",
2736
0
                                     expr_path_strm.GetData());
2737
0
    } break;
2738
2739
0
    case eAddressTypeFile:
2740
140
    case eAddressTypeLoad: {
2741
140
      CompilerType compiler_type = GetCompilerType();
2742
140
      if (compiler_type) {
2743
140
        std::string name(1, '&');
2744
140
        name.append(m_name.AsCString(""));
2745
140
        ExecutionContext exe_ctx(GetExecutionContextRef());
2746
140
        m_addr_of_valobj_sp = ValueObjectConstResult::Create(
2747
140
            exe_ctx.GetBestExecutionContextScope(),
2748
140
            compiler_type.GetPointerType(), ConstString(name.c_str()), addr,
2749
140
            eAddressTypeInvalid, m_data.GetAddressByteSize());
2750
140
      }
2751
140
    } break;
2752
0
    default:
2753
0
      break;
2754
140
    }
2755
140
  } else {
2756
9
    StreamString expr_path_strm;
2757
9
    GetExpressionPath(expr_path_strm);
2758
9
    error.SetErrorStringWithFormat("'%s' doesn't have a valid address",
2759
9
                                   expr_path_strm.GetData());
2760
9
  }
2761
2762
149
  return m_addr_of_valobj_sp;
2763
149
}
2764
2765
118
ValueObjectSP ValueObject::Cast(const CompilerType &compiler_type) {
2766
118
  return ValueObjectCast::Create(*this, GetName(), compiler_type);
2767
118
}
2768
2769
60
lldb::ValueObjectSP ValueObject::Clone(ConstString new_name) {
2770
60
  return ValueObjectCast::Create(*this, new_name, GetCompilerType());
2771
60
}
2772
2773
ValueObjectSP ValueObject::CastPointerType(const char *name,
2774
0
                                           CompilerType &compiler_type) {
2775
0
  ValueObjectSP valobj_sp;
2776
0
  AddressType address_type;
2777
0
  addr_t ptr_value = GetPointerValue(&address_type);
2778
2779
0
  if (ptr_value != LLDB_INVALID_ADDRESS) {
2780
0
    Address ptr_addr(ptr_value);
2781
0
    ExecutionContext exe_ctx(GetExecutionContextRef());
2782
0
    valobj_sp = ValueObjectMemory::Create(
2783
0
        exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, compiler_type);
2784
0
  }
2785
0
  return valobj_sp;
2786
0
}
2787
2788
0
ValueObjectSP ValueObject::CastPointerType(const char *name, TypeSP &type_sp) {
2789
0
  ValueObjectSP valobj_sp;
2790
0
  AddressType address_type;
2791
0
  addr_t ptr_value = GetPointerValue(&address_type);
2792
2793
0
  if (ptr_value != LLDB_INVALID_ADDRESS) {
2794
0
    Address ptr_addr(ptr_value);
2795
0
    ExecutionContext exe_ctx(GetExecutionContextRef());
2796
0
    valobj_sp = ValueObjectMemory::Create(
2797
0
        exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, type_sp);
2798
0
  }
2799
0
  return valobj_sp;
2800
0
}
2801
2802
0
ValueObject::EvaluationPoint::EvaluationPoint() : m_mod_id(), m_exe_ctx_ref() {}
2803
2804
ValueObject::EvaluationPoint::EvaluationPoint(ExecutionContextScope *exe_scope,
2805
                                              bool use_selected)
2806
80.0k
    : m_mod_id(), m_exe_ctx_ref(), m_needs_update(true) {
2807
80.0k
  ExecutionContext exe_ctx(exe_scope);
2808
80.0k
  TargetSP target_sp(exe_ctx.GetTargetSP());
2809
80.0k
  if (target_sp) {
2810
80.0k
    m_exe_ctx_ref.SetTargetSP(target_sp);
2811
80.0k
    ProcessSP process_sp(exe_ctx.GetProcessSP());
2812
80.0k
    if (!process_sp)
2813
1.76k
      process_sp = target_sp->GetProcessSP();
2814
2815
80.0k
    if (process_sp) {
2816
78.4k
      m_mod_id = process_sp->GetModID();
2817
78.4k
      m_exe_ctx_ref.SetProcessSP(process_sp);
2818
2819
78.4k
      ThreadSP thread_sp(exe_ctx.GetThreadSP());
2820
2821
78.4k
      if (!thread_sp) {
2822
662
        if (use_selected)
2823
0
          thread_sp = process_sp->GetThreadList().GetSelectedThread();
2824
662
      }
2825
2826
78.4k
      if (thread_sp) {
2827
77.7k
        m_exe_ctx_ref.SetThreadSP(thread_sp);
2828
2829
77.7k
        StackFrameSP frame_sp(exe_ctx.GetFrameSP());
2830
77.7k
        if (!frame_sp) {
2831
127
          if (use_selected)
2832
0
            frame_sp = thread_sp->GetSelectedFrame();
2833
127
        }
2834
77.7k
        if (frame_sp)
2835
77.6k
          m_exe_ctx_ref.SetFrameSP(frame_sp);
2836
77.7k
      }
2837
78.4k
    }
2838
80.0k
  }
2839
80.0k
}
2840
2841
ValueObject::EvaluationPoint::EvaluationPoint(
2842
    const ValueObject::EvaluationPoint &rhs)
2843
62.5k
    : m_mod_id(), m_exe_ctx_ref(rhs.m_exe_ctx_ref), m_needs_update(true) {}
2844
2845
113k
ValueObject::EvaluationPoint::~EvaluationPoint() = default;
2846
2847
// This function checks the EvaluationPoint against the current process state.
2848
// If the current state matches the evaluation point, or the evaluation point
2849
// is already invalid, then we return false, meaning "no change".  If the
2850
// current state is different, we update our state, and return true meaning
2851
// "yes, change".  If we did see a change, we also set m_needs_update to true,
2852
// so future calls to NeedsUpdate will return true. exe_scope will be set to
2853
// the current execution context scope.
2854
2855
bool ValueObject::EvaluationPoint::SyncWithProcessState(
2856
736k
    bool accept_invalid_exe_ctx) {
2857
  // Start with the target, if it is NULL, then we're obviously not going to
2858
  // get any further:
2859
736k
  const bool thread_and_frame_only_if_stopped = true;
2860
736k
  ExecutionContext exe_ctx(
2861
736k
      m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
2862
2863
736k
  if (exe_ctx.GetTargetPtr() == nullptr)
2864
0
    return false;
2865
2866
  // If we don't have a process nothing can change.
2867
736k
  Process *process = exe_ctx.GetProcessPtr();
2868
736k
  if (process == nullptr)
2869
7.46k
    return false;
2870
2871
  // If our stop id is the current stop ID, nothing has changed:
2872
729k
  ProcessModID current_mod_id = process->GetModID();
2873
2874
  // If the current stop id is 0, either we haven't run yet, or the process
2875
  // state has been cleared. In either case, we aren't going to be able to sync
2876
  // with the process state.
2877
729k
  if (current_mod_id.GetStopID() == 0)
2878
0
    return false;
2879
2880
729k
  bool changed = false;
2881
729k
  const bool was_valid = m_mod_id.IsValid();
2882
729k
  if (was_valid) {
2883
729k
    if (m_mod_id == current_mod_id) {
2884
      // Everything is already up to date in this object, no need to update the
2885
      // execution context scope.
2886
667k
      changed = false;
2887
667k
    } else {
2888
62.1k
      m_mod_id = current_mod_id;
2889
62.1k
      m_needs_update = true;
2890
62.1k
      changed = true;
2891
62.1k
    }
2892
729k
  }
2893
2894
  // Now re-look up the thread and frame in case the underlying objects have
2895
  // gone away & been recreated. That way we'll be sure to return a valid
2896
  // exe_scope. If we used to have a thread or a frame but can't find it
2897
  // anymore, then mark ourselves as invalid.
2898
2899
729k
  if (!accept_invalid_exe_ctx) {
2900
607k
    if (m_exe_ctx_ref.HasThreadRef()) {
2901
604k
      ThreadSP thread_sp(m_exe_ctx_ref.GetThreadSP());
2902
604k
      if (thread_sp) {
2903
604k
        if (m_exe_ctx_ref.HasFrameRef()) {
2904
603k
          StackFrameSP frame_sp(m_exe_ctx_ref.GetFrameSP());
2905
603k
          if (!frame_sp) {
2906
            // We used to have a frame, but now it is gone
2907
411
            SetInvalid();
2908
411
            changed = was_valid;
2909
411
          }
2910
603k
        }
2911
604k
      } else {
2912
        // We used to have a thread, but now it is gone
2913
0
        SetInvalid();
2914
0
        changed = was_valid;
2915
0
      }
2916
604k
    }
2917
607k
  }
2918
2919
729k
  return changed;
2920
729k
}
2921
2922
124k
void ValueObject::EvaluationPoint::SetUpdated() {
2923
124k
  ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
2924
124k
  if (process_sp)
2925
122k
    m_mod_id = process_sp->GetModID();
2926
124k
  m_needs_update = false;
2927
124k
}
2928
2929
512k
void ValueObject::ClearUserVisibleData(uint32_t clear_mask) {
2930
512k
  if ((clear_mask & eClearUserVisibleDataItemsValue) ==
2931
512k
      eClearUserVisibleDataItemsValue)
2932
186k
    m_value_str.clear();
2933
2934
512k
  if ((clear_mask & eClearUserVisibleDataItemsLocation) ==
2935
512k
      eClearUserVisibleDataItemsLocation)
2936
82.3k
    m_location_str.clear();
2937
2938
512k
  if ((clear_mask & eClearUserVisibleDataItemsSummary) ==
2939
512k
      eClearUserVisibleDataItemsSummary)
2940
411k
    m_summary_str.clear();
2941
2942
512k
  if ((clear_mask & eClearUserVisibleDataItemsDescription) ==
2943
512k
      eClearUserVisibleDataItemsDescription)
2944
317k
    m_object_desc_str.clear();
2945
2946
512k
  if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) ==
2947
512k
      eClearUserVisibleDataItemsSyntheticChildren) {
2948
5.10k
    if (m_synthetic_value)
2949
106
      m_synthetic_value = nullptr;
2950
5.10k
  }
2951
512k
}
2952
2953
0
SymbolContextScope *ValueObject::GetSymbolContextScope() {
2954
0
  if (m_parent) {
2955
0
    if (!m_parent->IsPointerOrReferenceType())
2956
0
      return m_parent->GetSymbolContextScope();
2957
0
  }
2958
0
  return nullptr;
2959
0
}
2960
2961
lldb::ValueObjectSP
2962
ValueObject::CreateValueObjectFromExpression(llvm::StringRef name,
2963
                                             llvm::StringRef expression,
2964
10
                                             const ExecutionContext &exe_ctx) {
2965
10
  return CreateValueObjectFromExpression(name, expression, exe_ctx,
2966
10
                                         EvaluateExpressionOptions());
2967
10
}
2968
2969
lldb::ValueObjectSP ValueObject::CreateValueObjectFromExpression(
2970
    llvm::StringRef name, llvm::StringRef expression,
2971
1.28k
    const ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options) {
2972
1.28k
  lldb::ValueObjectSP retval_sp;
2973
1.28k
  lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
2974
1.28k
  if (!target_sp)
2975
0
    return retval_sp;
2976
1.28k
  if (expression.empty())
2977
3
    return retval_sp;
2978
1.27k
  target_sp->EvaluateExpression(expression, exe_ctx.GetFrameSP().get(),
2979
1.27k
                                retval_sp, options);
2980
1.27k
  if (retval_sp && !name.empty())
2981
1.27k
    retval_sp->SetName(ConstString(name));
2982
1.27k
  return retval_sp;
2983
1.28k
}
2984
2985
lldb::ValueObjectSP ValueObject::CreateValueObjectFromAddress(
2986
    llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx,
2987
912
    CompilerType type) {
2988
912
  if (type) {
2989
911
    CompilerType pointer_type(type.GetPointerType());
2990
911
    if (pointer_type) {
2991
911
      lldb::DataBufferSP buffer(
2992
911
          new lldb_private::DataBufferHeap(&address, sizeof(lldb::addr_t)));
2993
911
      lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create(
2994
911
          exe_ctx.GetBestExecutionContextScope(), pointer_type,
2995
911
          ConstString(name), buffer, exe_ctx.GetByteOrder(),
2996
911
          exe_ctx.GetAddressByteSize()));
2997
911
      if (ptr_result_valobj_sp) {
2998
911
        ptr_result_valobj_sp->GetValue().SetValueType(
2999
911
            Value::ValueType::LoadAddress);
3000
911
        Status err;
3001
911
        ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
3002
911
        if (ptr_result_valobj_sp && !name.empty())
3003
911
          ptr_result_valobj_sp->SetName(ConstString(name));
3004
911
      }
3005
911
      return ptr_result_valobj_sp;
3006
911
    }
3007
911
  }
3008
1
  return lldb::ValueObjectSP();
3009
912
}
3010
3011
lldb::ValueObjectSP ValueObject::CreateValueObjectFromData(
3012
    llvm::StringRef name, const DataExtractor &data,
3013
14.1k
    const ExecutionContext &exe_ctx, CompilerType type) {
3014
14.1k
  lldb::ValueObjectSP new_value_sp;
3015
14.1k
  new_value_sp = ValueObjectConstResult::Create(
3016
14.1k
      exe_ctx.GetBestExecutionContextScope(), type, ConstString(name), data,
3017
14.1k
      LLDB_INVALID_ADDRESS);
3018
14.1k
  new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
3019
14.1k
  if (new_value_sp && !name.empty())
3020
14.1k
    new_value_sp->SetName(ConstString(name));
3021
14.1k
  return new_value_sp;
3022
14.1k
}
3023
3024
105k
ModuleSP ValueObject::GetModule() {
3025
105k
  ValueObject *root(GetRoot());
3026
105k
  if (root != this)
3027
66.1k
    return root->GetModule();
3028
39.7k
  return lldb::ModuleSP();
3029
105k
}
3030
3031
307k
ValueObject *ValueObject::GetRoot() {
3032
307k
  if (m_root)
3033
203k
    return m_root;
3034
118M
  
return (m_root = FollowParentChain([](ValueObject *vo) -> bool 104k
{
3035
118M
            return (vo->m_parent != nullptr);
3036
118M
          }));
3037
307k
}
3038
3039
ValueObject *
3040
160k
ValueObject::FollowParentChain(std::function<bool(ValueObject *)> f) {
3041
160k
  ValueObject *vo = this;
3042
236M
  while (vo) {
3043
236M
    if (!f(vo))
3044
105k
      break;
3045
236M
    vo = vo->m_parent;
3046
236M
  }
3047
160k
  return vo;
3048
160k
}
3049
3050
39.5k
AddressType ValueObject::GetAddressTypeOfChildren() {
3051
39.5k
  if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid) {
3052
1.82k
    ValueObject *root(GetRoot());
3053
1.82k
    if (root != this)
3054
1.82k
      return root->GetAddressTypeOfChildren();
3055
1.82k
  }
3056
37.7k
  return m_address_type_of_ptr_or_ref_children;
3057
39.5k
}
3058
3059
208k
lldb::DynamicValueType ValueObject::GetDynamicValueType() {
3060
208k
  ValueObject *with_dv_info = this;
3061
235M
  while (with_dv_info) {
3062
234M
    if (with_dv_info->HasDynamicValueTypeInfo())
3063
5.81k
      return with_dv_info->GetDynamicValueTypeImpl();
3064
234M
    with_dv_info = with_dv_info->m_parent;
3065
234M
  }
3066
203k
  return lldb::eNoDynamicValues;
3067
208k
}
3068
3069
95.1k
lldb::Format ValueObject::GetFormat() const {
3070
95.1k
  const ValueObject *with_fmt_info = this;
3071
252k
  while (with_fmt_info) {
3072
159k
    if (with_fmt_info->m_format != lldb::eFormatDefault)
3073
1.27k
      return with_fmt_info->m_format;
3074
157k
    with_fmt_info = with_fmt_info->m_parent;
3075
157k
  }
3076
93.8k
  return m_format;
3077
95.1k
}
3078
3079
57.8k
lldb::LanguageType ValueObject::GetPreferredDisplayLanguage() {
3080
57.8k
  lldb::LanguageType type = m_preferred_display_language;
3081
57.8k
  if (m_preferred_display_language == lldb::eLanguageTypeUnknown) {
3082
21.3k
    if (GetRoot()) {
3083
21.3k
      if (GetRoot() == this) {
3084
11.5k
        if (StackFrameSP frame_sp = GetFrameSP()) {
3085
10.5k
          const SymbolContext &sc(
3086
10.5k
              frame_sp->GetSymbolContext(eSymbolContextCompUnit));
3087
10.5k
          if (CompileUnit *cu = sc.comp_unit)
3088
10.5k
            type = cu->GetLanguage();
3089
10.5k
        }
3090
11.5k
      } else {
3091
9.80k
        type = GetRoot()->GetPreferredDisplayLanguage();
3092
9.80k
      }
3093
21.3k
    }
3094
21.3k
  }
3095
57.8k
  return (m_preferred_display_language = type); // only compute it once
3096
57.8k
}
3097
3098
16.4k
void ValueObject::SetPreferredDisplayLanguageIfNeeded(lldb::LanguageType lt) {
3099
16.4k
  if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
3100
15.0k
    SetPreferredDisplayLanguage(lt);
3101
16.4k
}
3102
3103
156k
bool ValueObject::CanProvideValue() {
3104
  // we need to support invalid types as providers of values because some bare-
3105
  // board debugging scenarios have no notion of types, but still manage to
3106
  // have raw numeric values for things like registers. sigh.
3107
156k
  CompilerType type = GetCompilerType();
3108
156k
  return (!type.IsValid()) || 
(0 != (type.GetTypeInfo() & eTypeHasValue))155k
;
3109
156k
}
3110
3111
3112
3113
3
ValueObjectSP ValueObject::Persist() {
3114
3
  if (!UpdateValueIfNeeded())
3115
0
    return nullptr;
3116
3117
3
  TargetSP target_sp(GetTargetSP());
3118
3
  if (!target_sp)
3119
0
    return nullptr;
3120
3121
3
  PersistentExpressionState *persistent_state =
3122
3
      target_sp->GetPersistentExpressionStateForLanguage(
3123
3
          GetPreferredDisplayLanguage());
3124
3125
3
  if (!persistent_state)
3126
0
    return nullptr;
3127
3128
3
  ConstString name = persistent_state->GetNextPersistentVariableName();
3129
3130
3
  ValueObjectSP const_result_sp =
3131
3
      ValueObjectConstResult::Create(target_sp.get(), GetValue(), name);
3132
3133
3
  ExpressionVariableSP persistent_var_sp =
3134
3
      persistent_state->CreatePersistentVariable(const_result_sp);
3135
3
  persistent_var_sp->m_live_sp = persistent_var_sp->m_frozen_sp;
3136
3
  persistent_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference;
3137
3138
3
  return persistent_var_sp->GetValueObject();
3139
3
}