Coverage Report

Created: 2023-09-30 09:22

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