LLDB mainline
ValueObject.cpp
Go to the documentation of this file.
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
10
11#include "lldb/Core/Address.h"
13#include "lldb/Core/Module.h"
22#include "lldb/Host/Config.h"
26#include "lldb/Symbol/Type.h"
31#include "lldb/Target/Process.h"
33#include "lldb/Target/Target.h"
34#include "lldb/Target/Thread.h"
38#include "lldb/Utility/Flags.h"
40#include "lldb/Utility/Log.h"
41#include "lldb/Utility/Scalar.h"
42#include "lldb/Utility/Stream.h"
52
53#include "llvm/Support/Compiler.h"
54
55#include <algorithm>
56#include <cstdint>
57#include <cstdlib>
58#include <memory>
59#include <optional>
60#include <tuple>
61
62#include <cassert>
63#include <cinttypes>
64#include <cstdio>
65#include <cstring>
66
67namespace lldb_private {
69}
70namespace lldb_private {
72}
73
74using namespace lldb;
75using namespace lldb_private;
76
78
79// FIXME: this will return true for vector types whose elements
80// are floats. Audit all usages of this function and call
81// IsFloatingPointType() instead if vectors of floats aren't intended
82// to be supported.
84 return ct.GetTypeInfo() & eTypeIsFloat;
85}
86
87// ValueObject constructor
89 : m_parent(&parent), m_update_point(parent.GetUpdatePoint()),
91 m_flags.m_is_synthetic_children_generated =
93 m_data.SetByteOrder(parent.GetDataExtractor().GetByteOrder());
94 m_data.SetAddressByteSize(parent.GetDataExtractor().GetAddressByteSize());
95 m_manager->ManageObject(this);
96}
97
98// ValueObject constructor
100 ValueObjectManager &manager,
101 AddressType child_ptr_or_ref_addr_type)
102 : m_update_point(exe_scope), m_manager(&manager),
103 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
105 if (exe_scope) {
106 TargetSP target_sp(exe_scope->CalculateTarget());
107 if (target_sp) {
108 const ArchSpec &arch = target_sp->GetArchitecture();
109 m_data.SetByteOrder(arch.GetByteOrder());
110 m_data.SetAddressByteSize(arch.GetAddressByteSize());
111 }
112 }
113 m_manager->ManageObject(this);
114}
115
116// Destructor
117ValueObject::~ValueObject() = default;
118
119bool ValueObject::UpdateValueIfNeeded(bool update_format) {
120
121 bool did_change_formats = false;
122
123 if (update_format)
124 did_change_formats = UpdateFormatsIfNeeded();
125
126 // If this is a constant value, then our success is predicated on whether we
127 // have an error or not
128 if (GetIsConstant()) {
129 // if you are constant, things might still have changed behind your back
130 // (e.g. you are a frozen object and things have changed deeper than you
131 // cared to freeze-dry yourself) in this case, your value has not changed,
132 // but "computed" entries might have, so you might now have a different
133 // summary, or a different object description. clear these so we will
134 // recompute them
135 if (update_format && !did_change_formats)
138 return m_error.Success();
139 }
140
141 bool first_update = IsChecksumEmpty();
142
143 if (NeedsUpdating()) {
144 m_update_point.SetUpdated();
145
146 // Save the old value using swap to avoid a string copy which also will
147 // clear our m_value_str
148 if (m_value_str.empty()) {
149 m_flags.m_old_value_valid = false;
150 } else {
151 m_flags.m_old_value_valid = true;
154 }
155
157
158 if (IsInScope()) {
159 const bool value_was_valid = GetValueIsValid();
160 SetValueDidChange(false);
161
162 m_error.Clear();
163
164 // Call the pure virtual function to update the value
165
166 bool need_compare_checksums = false;
167 llvm::SmallVector<uint8_t, 16> old_checksum;
168
169 if (!first_update && CanProvideValue()) {
170 need_compare_checksums = true;
171 old_checksum.resize(m_value_checksum.size());
172 std::copy(m_value_checksum.begin(), m_value_checksum.end(),
173 old_checksum.begin());
174 }
175
176 bool success = UpdateValue();
177
178 SetValueIsValid(success);
179
180 if (success) {
182 const uint64_t max_checksum_size = 128;
183 m_data.Checksum(m_value_checksum, max_checksum_size);
184 } else {
185 need_compare_checksums = false;
186 m_value_checksum.clear();
187 }
188
189 assert(!need_compare_checksums ||
190 (!old_checksum.empty() && !m_value_checksum.empty()));
191
192 if (first_update)
193 SetValueDidChange(false);
194 else if (!m_flags.m_value_did_change && !success) {
195 // The value wasn't gotten successfully, so we mark this as changed if
196 // the value used to be valid and now isn't
197 SetValueDidChange(value_was_valid);
198 } else if (need_compare_checksums) {
199 SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0],
200 m_value_checksum.size()));
201 }
202
203 } else {
204 m_error = Status::FromErrorString("out of scope");
205 }
206 }
207 return m_error.Success();
208}
209
212 LLDB_LOGF(log,
213 "[%s %p] checking for FormatManager revisions. ValueObject "
214 "rev: %d - Global rev: %d",
215 GetName().GetCString(), static_cast<void *>(this),
218
219 bool any_change = false;
220
223 any_change = true;
224
230 }
231
232 return any_change;
233}
234
236 m_update_point.SetNeedsUpdate();
237 // We have to clear the value string here so ConstResult children will notice
238 // if their values are changed by hand (i.e. with SetValueAsCString).
240}
241
243 m_flags.m_children_count_valid = false;
244 m_flags.m_did_calculate_complete_objc_class_type = false;
250}
251
253 CompilerType compiler_type(GetCompilerTypeImpl());
254
255 if (m_flags.m_did_calculate_complete_objc_class_type) {
256 if (m_override_type.IsValid())
257 return m_override_type;
258 else
259 return compiler_type;
260 }
261
262 m_flags.m_did_calculate_complete_objc_class_type = true;
263
264 ProcessSP process_sp(
266
267 if (!process_sp)
268 return compiler_type;
269
270 if (auto *runtime =
271 process_sp->GetLanguageRuntime(GetObjectRuntimeLanguage())) {
272 if (std::optional<CompilerType> complete_type =
273 runtime->GetRuntimeType(compiler_type)) {
274 m_override_type = *complete_type;
275 if (m_override_type.IsValid())
276 return m_override_type;
277 }
278 }
279 return compiler_type;
280}
281
286
288 UpdateValueIfNeeded(false);
289 return m_error;
290}
291
293 const DataExtractor &data) {
294 if (UpdateValueIfNeeded(false)) {
295 if (m_location_str.empty()) {
296 StreamString sstr;
297
298 Value::ValueType value_type = value.GetValueType();
299
300 switch (value_type) {
302 m_location_str = "invalid";
303 break;
306 RegisterInfo *reg_info = value.GetRegisterInfo();
307 if (reg_info) {
308 if (reg_info->name)
309 m_location_str = reg_info->name;
310 else if (reg_info->alt_name)
311 m_location_str = reg_info->alt_name;
312 if (m_location_str.empty())
314 ? "vector"
315 : "scalar";
316 }
317 }
318 if (m_location_str.empty())
319 m_location_str = "scalar";
320 break;
321
325 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
326 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size,
328 m_location_str = std::string(sstr.GetString());
329 } break;
330 }
331 }
332 }
333 return m_location_str.c_str();
334}
335
338 false)) // make sure that you are up to date before returning anything
339 {
341 Value tmp_value(m_value);
342 scalar = tmp_value.ResolveValue(&exe_ctx, GetModule().get());
343 if (scalar.IsValid()) {
344 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
345 if (bitfield_bit_size)
346 return scalar.ExtractBitfield(bitfield_bit_size,
348 return true;
349 }
350 }
351 return false;
352}
353
356 LazyBool is_logical_true = language->IsLogicalTrue(*this, error);
357 switch (is_logical_true) {
358 case eLazyBoolYes:
359 case eLazyBoolNo:
360 return (is_logical_true == true);
362 break;
363 }
364 }
365
366 Scalar scalar_value;
367
368 if (!ResolveValue(scalar_value)) {
369 error = Status::FromErrorString("failed to get a scalar result");
370 return false;
371 }
372
373 bool ret;
374 ret = scalar_value.ULongLong(1) != 0;
375 error.Clear();
376 return ret;
377}
378
379ValueObjectSP ValueObject::GetChildAtIndex(uint32_t idx, bool can_create) {
380 ValueObjectSP child_sp;
381 // We may need to update our value if we are dynamic
383 UpdateValueIfNeeded(false);
384 if (idx < GetNumChildrenIgnoringErrors()) {
385 // Check if we have already made the child value object?
386 if (can_create && !m_children.HasChildAtIndex(idx)) {
387 // No we haven't created the child at this index, so lets have our
388 // subclass do it and cache the result for quick future access.
389 m_children.SetChildAtIndex(idx, CreateChildAtIndex(idx));
390 }
391
392 ValueObject *child = m_children.GetChildAtIndex(idx);
393 if (child != nullptr)
394 return child->GetSP();
395 }
396 return child_sp;
397}
398
400ValueObject::GetChildAtNamePath(llvm::ArrayRef<llvm::StringRef> names) {
401 if (names.size() == 0)
402 return GetSP();
403 ValueObjectSP root(GetSP());
404 for (llvm::StringRef name : names) {
405 root = root->GetChildMemberWithName(name);
406 if (!root) {
407 return root;
408 }
409 }
410 return root;
411}
412
413llvm::Expected<size_t>
415 bool omit_empty_base_classes = true;
417 omit_empty_base_classes);
418}
419
421 bool can_create) {
422 // We may need to update our value if we are dynamic.
424 UpdateValueIfNeeded(false);
425
426 // When getting a child by name, it could be buried inside some base classes
427 // (which really aren't part of the expression path), so we need a vector of
428 // indexes that can get us down to the correct child.
429 std::vector<uint32_t> child_indexes;
430 bool omit_empty_base_classes = true;
431
432 if (!GetCompilerType().IsValid())
433 return ValueObjectSP();
434
435 const size_t num_child_indexes =
437 name, omit_empty_base_classes, child_indexes);
438 if (num_child_indexes == 0)
439 return nullptr;
440
441 ValueObjectSP child_sp = GetSP();
442 for (uint32_t idx : child_indexes)
443 if (child_sp)
444 child_sp = child_sp->GetChildAtIndex(idx, can_create);
445 return child_sp;
446}
447
448llvm::Expected<uint32_t> ValueObject::GetNumChildren(uint32_t max) {
450
451 if (max < UINT32_MAX) {
452 if (m_flags.m_children_count_valid) {
453 size_t children_count = m_children.GetChildrenCount();
454 return children_count <= max ? children_count : max;
455 } else
456 return CalculateNumChildren(max);
457 }
458
459 if (!m_flags.m_children_count_valid) {
460 auto num_children_or_err = CalculateNumChildren();
461 if (num_children_or_err)
462 SetNumChildren(*num_children_or_err);
463 else
464 return num_children_or_err;
465 }
466 return m_children.GetChildrenCount();
467}
468
470 auto value_or_err = GetNumChildren(max);
471 if (value_or_err)
472 return *value_or_err;
473 LLDB_LOG_ERRORV(GetLog(LLDBLog::DataFormatters), value_or_err.takeError(),
474 "{0}");
475 return 0;
476}
477
479 bool has_children = false;
480 const uint32_t type_info = GetTypeInfo();
481 if (type_info) {
482 if (type_info & (eTypeHasChildren | eTypeIsPointer | eTypeIsReference))
483 has_children = true;
484 } else {
485 has_children = GetNumChildrenIgnoringErrors() > 0;
486 }
487 return has_children;
488}
489
490// Should only be called by ValueObject::GetNumChildren()
491void ValueObject::SetNumChildren(uint32_t num_children) {
492 m_flags.m_children_count_valid = true;
493 m_children.SetChildrenCount(num_children);
494}
495
497 bool omit_empty_base_classes = true;
498 bool ignore_array_bounds = false;
499 std::string child_name;
500 uint32_t child_byte_size = 0;
501 int32_t child_byte_offset = 0;
502 uint32_t child_bitfield_bit_size = 0;
503 uint32_t child_bitfield_bit_offset = 0;
504 bool child_is_base_class = false;
505 bool child_is_deref_of_parent = false;
506 uint64_t language_flags = 0;
507 const bool transparent_pointers = true;
508
510
511 auto child_compiler_type_or_err =
513 &exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
514 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
515 child_bitfield_bit_size, child_bitfield_bit_offset,
516 child_is_base_class, child_is_deref_of_parent, this, language_flags);
517 if (!child_compiler_type_or_err || !child_compiler_type_or_err->IsValid()) {
519 child_compiler_type_or_err.takeError(),
520 "could not find child: {0}");
521 return nullptr;
522 }
523
524 return new ValueObjectChild(
525 *this, *child_compiler_type_or_err, ConstString(child_name),
526 child_byte_size, child_byte_offset, child_bitfield_bit_size,
527 child_bitfield_bit_offset, child_is_base_class, child_is_deref_of_parent,
528 eAddressTypeInvalid, language_flags);
529}
530
532 bool omit_empty_base_classes = true;
533 bool ignore_array_bounds = true;
534 std::string child_name;
535 uint32_t child_byte_size = 0;
536 int32_t child_byte_offset = 0;
537 uint32_t child_bitfield_bit_size = 0;
538 uint32_t child_bitfield_bit_offset = 0;
539 bool child_is_base_class = false;
540 bool child_is_deref_of_parent = false;
541 uint64_t language_flags = 0;
542 const bool transparent_pointers = false;
543
545
546 auto child_compiler_type_or_err =
548 &exe_ctx, 0, transparent_pointers, omit_empty_base_classes,
549 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
550 child_bitfield_bit_size, child_bitfield_bit_offset,
551 child_is_base_class, child_is_deref_of_parent, this, language_flags);
552 if (!child_compiler_type_or_err) {
554 child_compiler_type_or_err.takeError(),
555 "could not find child: {0}");
556 return nullptr;
557 }
558
559 if (child_compiler_type_or_err->IsValid()) {
560 child_byte_offset += child_byte_size * idx;
561
562 return new ValueObjectChild(
563 *this, *child_compiler_type_or_err, ConstString(child_name),
564 child_byte_size, child_byte_offset, child_bitfield_bit_size,
565 child_bitfield_bit_offset, child_is_base_class,
566 child_is_deref_of_parent, eAddressTypeInvalid, language_flags);
567 }
568
569 // In case of an incomplete type, try to use the ValueObject's
570 // synthetic value to create the child ValueObject.
571 if (ValueObjectSP synth_valobj_sp = GetSyntheticValue())
572 return synth_valobj_sp->GetChildAtIndex(idx, /*can_create=*/true).get();
573
574 return nullptr;
575}
576
578 std::string &destination,
579 lldb::LanguageType lang) {
580 return GetSummaryAsCString(summary_ptr, destination,
581 TypeSummaryOptions().SetLanguage(lang));
582}
583
585 std::string &destination,
586 const TypeSummaryOptions &options) {
587 destination.clear();
588
589 // If we have a forcefully completed type, don't try and show a summary from
590 // a valid summary string or function because the type is not complete and
591 // no member variables or member functions will be available.
592 if (GetCompilerType().IsForcefullyCompleted()) {
593 destination = "<incomplete type>";
594 return true;
595 }
596
597 // ideally we would like to bail out if passing NULL, but if we do so we end
598 // up not providing the summary for function pointers anymore
599 if (/*summary_ptr == NULL ||*/ m_flags.m_is_getting_summary)
600 return false;
601
602 m_flags.m_is_getting_summary = true;
603
604 TypeSummaryOptions actual_options(options);
605
606 if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown)
608
609 // this is a hot path in code and we prefer to avoid setting this string all
610 // too often also clearing out other information that we might care to see in
611 // a crash log. might be useful in very specific situations though.
612 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s.
613 Summary provider's description is %s",
614 GetTypeName().GetCString(),
615 GetName().GetCString(),
616 summary_ptr->GetDescription().c_str());*/
617
618 if (UpdateValueIfNeeded(false) && summary_ptr) {
619 if (HasSyntheticValue())
620 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on
621 // the synthetic children being
622 // up-to-date (e.g. ${svar%#})
623
624 if (TargetSP target_sp = GetExecutionContextRef().GetTargetSP()) {
625 SummaryStatisticsSP stats_sp =
626 target_sp->GetSummaryStatisticsCache()
627 .GetSummaryStatisticsForProvider(*summary_ptr);
628
629 // Construct RAII types to time and collect data on summary creation.
630 SummaryStatistics::SummaryInvocation invocation(stats_sp);
631 summary_ptr->FormatObject(this, destination, actual_options);
632 } else
633 summary_ptr->FormatObject(this, destination, actual_options);
634 }
635 m_flags.m_is_getting_summary = false;
636 return !destination.empty();
637}
638
640 if (UpdateValueIfNeeded(true) && m_summary_str.empty()) {
641 TypeSummaryOptions summary_options;
642 summary_options.SetLanguage(lang);
644 summary_options);
645 }
646 if (m_summary_str.empty())
647 return nullptr;
648 return m_summary_str.c_str();
649}
650
651bool ValueObject::GetSummaryAsCString(std::string &destination,
652 const TypeSummaryOptions &options) {
653 return GetSummaryAsCString(GetSummaryFormat().get(), destination, options);
654}
655
656bool ValueObject::IsCStringContainer(bool check_pointer) {
657 CompilerType pointee_or_element_compiler_type;
658 const Flags type_flags(GetTypeInfo(&pointee_or_element_compiler_type));
659 bool is_char_arr_ptr(type_flags.AnySet(eTypeIsArray | eTypeIsPointer) &&
660 pointee_or_element_compiler_type.IsCharType());
661 if (!is_char_arr_ptr)
662 return false;
663 if (!check_pointer)
664 return true;
665 if (type_flags.Test(eTypeIsArray))
666 return true;
667 addr_t cstr_address = GetPointerValue().address;
668 return (cstr_address != LLDB_INVALID_ADDRESS);
669}
670
671size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx,
672 uint32_t item_count) {
673 CompilerType pointee_or_element_compiler_type;
674 const uint32_t type_info = GetTypeInfo(&pointee_or_element_compiler_type);
675 const bool is_pointer_type = type_info & eTypeIsPointer;
676 const bool is_array_type = type_info & eTypeIsArray;
677 if (!(is_pointer_type || is_array_type))
678 return 0;
679
680 if (item_count == 0)
681 return 0;
682
684
685 std::optional<uint64_t> item_type_size =
686 llvm::expectedToOptional(pointee_or_element_compiler_type.GetByteSize(
688 if (!item_type_size)
689 return 0;
690 const uint64_t bytes = item_count * *item_type_size;
691 const uint64_t offset = item_idx * *item_type_size;
692
693 if (item_idx == 0 && item_count == 1) // simply a deref
694 {
695 if (is_pointer_type) {
697 ValueObjectSP pointee_sp = Dereference(error);
698 if (error.Fail() || pointee_sp.get() == nullptr)
699 return 0;
700 return pointee_sp->GetData(data, error);
701 } else {
702 ValueObjectSP child_sp = GetChildAtIndex(0);
703 if (child_sp.get() == nullptr)
704 return 0;
706 return child_sp->GetData(data, error);
707 }
708 return true;
709 } else /* (items > 1) */
710 {
712 lldb_private::DataBufferHeap *heap_buf_ptr = nullptr;
713 lldb::DataBufferSP data_sp(heap_buf_ptr =
715
716 auto [addr, addr_type] =
717 is_pointer_type ? GetPointerValue() : GetAddressOf(true);
718
719 switch (addr_type) {
720 case eAddressTypeFile: {
721 ModuleSP module_sp(GetModule());
722 if (module_sp) {
723 addr = addr + offset;
724 Address so_addr;
725 module_sp->ResolveFileAddress(addr, so_addr);
727 Target *target = exe_ctx.GetTargetPtr();
728 if (target) {
729 heap_buf_ptr->SetByteSize(bytes);
730 size_t bytes_read = target->ReadMemory(
731 so_addr, heap_buf_ptr->GetBytes(), bytes, error, true);
732 if (error.Success()) {
733 data.SetData(data_sp);
734 return bytes_read;
735 }
736 }
737 }
738 } break;
739 case eAddressTypeLoad: {
741 if (Target *target = exe_ctx.GetTargetPtr()) {
742 heap_buf_ptr->SetByteSize(bytes);
743 Address target_addr;
744 target_addr.SetLoadAddress(addr + offset, target);
745 size_t bytes_read =
746 target->ReadMemory(target_addr, heap_buf_ptr->GetBytes(), bytes,
747 error, /*force_live_memory=*/true);
748 if (error.Success() || bytes_read > 0) {
749 data.SetData(data_sp);
750 return bytes_read;
751 }
752 }
753 } break;
754 case eAddressTypeHost: {
755 auto max_bytes = llvm::expectedToOptional(GetCompilerType().GetByteSize(
757 if (max_bytes && *max_bytes > offset) {
758 size_t bytes_read = std::min<uint64_t>(*max_bytes - offset, bytes);
759 addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
760 if (addr == 0 || addr == LLDB_INVALID_ADDRESS)
761 break;
762 heap_buf_ptr->CopyData((uint8_t *)(addr + offset), bytes_read);
763 data.SetData(data_sp);
764 return bytes_read;
765 }
766 } break;
768 break;
769 }
770 }
771 return 0;
772}
773
775 UpdateValueIfNeeded(false);
777 error = m_value.GetValueAsData(&exe_ctx, data, GetModule().get());
778 if (error.Fail()) {
779 if (m_data.GetByteSize()) {
780 data = m_data;
781 error.Clear();
782 return data.GetByteSize();
783 } else {
784 return 0;
785 }
786 }
787 data.SetAddressByteSize(m_data.GetAddressByteSize());
788 data.SetByteOrder(m_data.GetByteOrder());
789 return data.GetByteSize();
790}
791
793 error.Clear();
794 // Make sure our value is up to date first so that our location and location
795 // type is valid.
796 if (!UpdateValueIfNeeded(false)) {
797 error = Status::FromErrorString("unable to read value");
798 return false;
799 }
800
801 const Encoding encoding = GetCompilerType().GetEncoding();
802
803 const size_t byte_size = llvm::expectedToOptional(GetByteSize()).value_or(0);
804
805 Value::ValueType value_type = m_value.GetValueType();
806
807 switch (value_type) {
809 error = Status::FromErrorString("invalid location");
810 return false;
812 Status set_error =
813 m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
814
815 if (!set_error.Success()) {
817 "unable to set scalar value: %s", set_error.AsCString());
818 return false;
819 }
820 } break;
822 // If it is a load address, then the scalar value is the storage location
823 // of the data, and we have to shove this value down to that load location.
825 Process *process = exe_ctx.GetProcessPtr();
826 if (process) {
827 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
828 size_t bytes_written = process->WriteMemory(
829 target_addr, data.GetDataStart(), byte_size, error);
830 if (!error.Success())
831 return false;
832 if (bytes_written != byte_size) {
833 error = Status::FromErrorString("unable to write value to memory");
834 return false;
835 }
836 }
837 } break;
839 // If it is a host address, then we stuff the scalar as a DataBuffer into
840 // the Value's data.
841 DataBufferSP buffer_sp(new DataBufferHeap(byte_size, 0));
842 m_data.SetData(buffer_sp, 0);
843 data.CopyByteOrderedData(0, byte_size,
844 const_cast<uint8_t *>(m_data.GetDataStart()),
845 byte_size, m_data.GetByteOrder());
846 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
847 } break;
849 break;
850 }
851
852 // If we have reached this point, then we have successfully changed the
853 // value.
855 return true;
856}
857
858llvm::ArrayRef<uint8_t> ValueObject::GetLocalBuffer() const {
859 if (m_value.GetValueType() != Value::ValueType::HostAddress)
860 return {};
861 auto start = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
862 if (start == LLDB_INVALID_ADDRESS)
863 return {};
864 // Does our pointer point to this value object's m_data buffer?
865 if ((uint64_t)m_data.GetDataStart() == start)
866 return m_data.GetData();
867 // Does our pointer point to the value's buffer?
868 if ((uint64_t)m_value.GetBuffer().GetBytes() == start)
869 return m_value.GetBuffer().GetData();
870 // Our pointer points to something else. We can't know what the size is.
871 return {};
872}
873
874static bool CopyStringDataToBufferSP(const StreamString &source,
875 lldb::WritableDataBufferSP &destination) {
876 llvm::StringRef src = source.GetString();
877 src = src.rtrim('\0');
878 destination = std::make_shared<DataBufferHeap>(src.size(), 0);
879 memcpy(destination->GetBytes(), src.data(), src.size());
880 return true;
881}
882
883std::pair<size_t, bool>
885 Status &error, bool honor_array) {
886 bool was_capped = false;
887 StreamString s;
889 Target *target = exe_ctx.GetTargetPtr();
890
891 if (!target) {
892 s << "<no target to read from>";
893 error = Status::FromErrorString("no target to read from");
894 CopyStringDataToBufferSP(s, buffer_sp);
895 return {0, was_capped};
896 }
897
898 const auto max_length = target->GetMaximumSizeOfStringSummary();
899
900 size_t bytes_read = 0;
901 size_t total_bytes_read = 0;
902
903 CompilerType compiler_type = GetCompilerType();
904 CompilerType elem_or_pointee_compiler_type;
905 const Flags type_flags(GetTypeInfo(&elem_or_pointee_compiler_type));
906 if (type_flags.AnySet(eTypeIsArray | eTypeIsPointer) &&
907 elem_or_pointee_compiler_type.IsCharType()) {
908 AddrAndType cstr_address;
909
910 size_t cstr_len = 0;
911 bool capped_data = false;
912 const bool is_array = type_flags.Test(eTypeIsArray);
913 if (is_array) {
914 // We have an array
915 uint64_t array_size = 0;
916 if (compiler_type.IsArrayType(nullptr, &array_size)) {
917 cstr_len = array_size;
918 if (cstr_len > max_length) {
919 capped_data = true;
920 cstr_len = max_length;
921 }
922 }
923 cstr_address = GetAddressOf(true);
924 } else {
925 // We have a pointer
926 cstr_address = GetPointerValue();
927 }
928
929 if (cstr_address.address == 0 ||
930 cstr_address.address == LLDB_INVALID_ADDRESS) {
931 if (cstr_address.type == eAddressTypeHost && is_array) {
932 const char *cstr = GetDataExtractor().PeekCStr(0);
933 if (cstr == nullptr) {
934 s << "<invalid address>";
935 error = Status::FromErrorString("invalid address");
936 CopyStringDataToBufferSP(s, buffer_sp);
937 return {0, was_capped};
938 }
939 s << llvm::StringRef(cstr, cstr_len);
940 CopyStringDataToBufferSP(s, buffer_sp);
941 return {cstr_len, was_capped};
942 } else {
943 s << "<invalid address>";
944 error = Status::FromErrorString("invalid address");
945 CopyStringDataToBufferSP(s, buffer_sp);
946 return {0, was_capped};
947 }
948 }
949
950 Address cstr_so_addr(cstr_address.address);
951 DataExtractor data;
952 if (cstr_len > 0 && honor_array) {
953 // I am using GetPointeeData() here to abstract the fact that some
954 // ValueObjects are actually frozen pointers in the host but the pointed-
955 // to data lives in the debuggee, and GetPointeeData() automatically
956 // takes care of this
957 GetPointeeData(data, 0, cstr_len);
958
959 if ((bytes_read = data.GetByteSize()) > 0) {
960 total_bytes_read = bytes_read;
961 for (size_t offset = 0; offset < bytes_read; offset++)
962 s.Printf("%c", *data.PeekData(offset, 1));
963 if (capped_data)
964 was_capped = true;
965 }
966 } else {
967 cstr_len = max_length;
968 const size_t k_max_buf_size = 64;
969
970 size_t offset = 0;
971
972 int cstr_len_displayed = -1;
973 bool capped_cstr = false;
974 // I am using GetPointeeData() here to abstract the fact that some
975 // ValueObjects are actually frozen pointers in the host but the pointed-
976 // to data lives in the debuggee, and GetPointeeData() automatically
977 // takes care of this
978 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0) {
979 total_bytes_read += bytes_read;
980 const char *cstr = data.PeekCStr(0);
981 size_t len = strnlen(cstr, k_max_buf_size);
982 if (cstr_len_displayed < 0)
983 cstr_len_displayed = len;
984
985 if (len == 0)
986 break;
987 cstr_len_displayed += len;
988 if (len > bytes_read)
989 len = bytes_read;
990 if (len > cstr_len)
991 len = cstr_len;
992
993 for (size_t offset = 0; offset < bytes_read; offset++)
994 s.Printf("%c", *data.PeekData(offset, 1));
995
996 if (len < k_max_buf_size)
997 break;
998
999 if (len >= cstr_len) {
1000 capped_cstr = true;
1001 break;
1002 }
1003
1004 cstr_len -= len;
1005 offset += len;
1006 }
1007
1008 if (cstr_len_displayed >= 0) {
1009 if (capped_cstr)
1010 was_capped = true;
1011 }
1012 }
1013 } else {
1014 error = Status::FromErrorString("not a string object");
1015 s << "<not a string object>";
1016 }
1017 CopyStringDataToBufferSP(s, buffer_sp);
1018 return {total_bytes_read, was_capped};
1019}
1020
1021llvm::Expected<std::string> ValueObject::GetObjectDescription() {
1022 if (!UpdateValueIfNeeded(true))
1023 return llvm::createStringError("could not update value");
1024
1025 // Return cached value.
1026 if (!m_object_desc_str.empty())
1027 return m_object_desc_str;
1028
1030 Process *process = exe_ctx.GetProcessPtr();
1031 if (!process)
1032 return llvm::createStringError("no process");
1033
1034 // Returns the object description produced by one language runtime.
1035 auto get_object_description =
1036 [&](LanguageType language) -> llvm::Expected<std::string> {
1037 if (LanguageRuntime *runtime = process->GetLanguageRuntime(language)) {
1038 StreamString s;
1039 if (llvm::Error error = runtime->GetObjectDescription(s, *this))
1040 return error;
1042 return m_object_desc_str;
1043 }
1044 return llvm::createStringError("no native language runtime");
1045 };
1046
1047 // Try the native language runtime first.
1048 LanguageType native_language = GetObjectRuntimeLanguage();
1049 llvm::Expected<std::string> desc = get_object_description(native_language);
1050 if (desc)
1051 return desc;
1052
1053 // Try the Objective-C language runtime. This fallback is necessary
1054 // for Objective-C++ and mixed Objective-C / C++ programs.
1055 if (Language::LanguageIsCFamily(native_language)) {
1056 // We're going to try again, so let's drop the first error.
1057 llvm::consumeError(desc.takeError());
1058 return get_object_description(eLanguageTypeObjC);
1059 }
1060 return desc;
1061}
1062
1064 std::string &destination) {
1065 if (UpdateValueIfNeeded(false))
1066 return format.FormatObject(this, destination);
1067 else
1068 return false;
1069}
1070
1072 std::string &destination) {
1073 return GetValueAsCString(TypeFormatImpl_Format(format), destination);
1074}
1075
1077 if (UpdateValueIfNeeded(true)) {
1078 lldb::TypeFormatImplSP format_sp;
1079 lldb::Format my_format = GetFormat();
1080 if (my_format == lldb::eFormatDefault) {
1081 if (m_type_format_sp)
1082 format_sp = m_type_format_sp;
1083 else {
1084 if (m_flags.m_is_bitfield_for_scalar)
1085 my_format = eFormatUnsigned;
1086 else {
1087 if (m_value.GetContextType() == Value::ContextType::RegisterInfo) {
1088 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1089 if (reg_info)
1090 my_format = reg_info->format;
1091 } else {
1092 my_format = GetValue().GetCompilerType().GetFormat();
1093 }
1094 }
1095 }
1096 }
1097 if (my_format != m_last_format || m_value_str.empty()) {
1098 m_last_format = my_format;
1099 if (!format_sp)
1100 format_sp = std::make_shared<TypeFormatImpl_Format>(my_format);
1101 if (GetValueAsCString(*format_sp.get(), m_value_str)) {
1102 if (!m_flags.m_value_did_change && m_flags.m_old_value_valid) {
1103 // The value was gotten successfully, so we consider the value as
1104 // changed if the value string differs
1106 }
1107 }
1108 }
1109 }
1110 if (m_value_str.empty())
1111 return nullptr;
1112 return m_value_str.c_str();
1113}
1114
1115// if > 8bytes, 0 is returned. this method should mostly be used to read
1116// address values out of pointers
1117uint64_t ValueObject::GetValueAsUnsigned(uint64_t fail_value, bool *success) {
1118 // If our byte size is zero this is an aggregate type that has children
1119 if (CanProvideValue()) {
1120 Scalar scalar;
1121 if (ResolveValue(scalar)) {
1122 if (success)
1123 *success = true;
1124 scalar.MakeUnsigned();
1125 return scalar.ULongLong(fail_value);
1126 }
1127 // fallthrough, otherwise...
1128 }
1129
1130 if (success)
1131 *success = false;
1132 return fail_value;
1133}
1134
1135int64_t ValueObject::GetValueAsSigned(int64_t fail_value, bool *success) {
1136 // If our byte size is zero this is an aggregate type that has children
1137 if (CanProvideValue()) {
1138 Scalar scalar;
1139 if (ResolveValue(scalar)) {
1140 if (success)
1141 *success = true;
1142 scalar.MakeSigned();
1143 return scalar.SLongLong(fail_value);
1144 }
1145 // fallthrough, otherwise...
1146 }
1147
1148 if (success)
1149 *success = false;
1150 return fail_value;
1151}
1152
1153llvm::Expected<llvm::APSInt> ValueObject::GetValueAsAPSInt() {
1154 // Make sure the type can be converted to an APSInt.
1155 if (!GetCompilerType().IsInteger() &&
1156 !GetCompilerType().IsScopedEnumerationType() &&
1157 !GetCompilerType().IsEnumerationType() &&
1159 !GetCompilerType().IsNullPtrType() &&
1160 !GetCompilerType().IsReferenceType() && !GetCompilerType().IsBoolean())
1161 return llvm::createStringError("type cannot be converted to APSInt");
1162
1163 if (CanProvideValue()) {
1164 Scalar scalar;
1165 if (ResolveValue(scalar))
1166 return scalar.GetAPSInt();
1167 }
1168
1169 return llvm::createStringError("error occurred; unable to convert to APSInt");
1170}
1171
1172llvm::Expected<llvm::APFloat> ValueObject::GetValueAsAPFloat() {
1174 return llvm::createStringError("type cannot be converted to APFloat");
1175
1176 if (CanProvideValue()) {
1177 Scalar scalar;
1178 if (ResolveValue(scalar))
1179 return scalar.GetAPFloat();
1180 }
1181
1182 return llvm::createStringError(
1183 "error occurred; unable to convert to APFloat");
1184}
1185
1186llvm::Expected<bool> ValueObject::GetValueAsBool() {
1187 CompilerType val_type = GetCompilerType();
1188 if (val_type.IsInteger() || val_type.IsUnscopedEnumerationType() ||
1189 val_type.IsPointerType()) {
1190 auto value_or_err = GetValueAsAPSInt();
1191 if (value_or_err)
1192 return value_or_err->getBoolValue();
1193 }
1194 if (HasFloatingRepresentation(val_type)) {
1195 auto value_or_err = GetValueAsAPFloat();
1196 if (value_or_err)
1197 return value_or_err->isNonZero();
1198 }
1199 if (val_type.IsArrayType())
1200 return GetAddressOf().address != 0;
1201
1202 return llvm::createStringError("type cannot be converted to bool");
1203}
1204
1205void ValueObject::SetValueFromInteger(const llvm::APInt &value, Status &error) {
1206 // Verify the current object is an integer object
1207 CompilerType val_type = GetCompilerType();
1208 if (!val_type.IsInteger() && !val_type.IsUnscopedEnumerationType() &&
1209 !HasFloatingRepresentation(val_type) && !val_type.IsPointerType() &&
1210 !val_type.IsScalarType()) {
1211 error =
1212 Status::FromErrorString("current value object is not an integer objet");
1213 return;
1214 }
1215
1216 // Verify the current object is not actually associated with any program
1217 // variable.
1218 if (GetVariable()) {
1220 "current value object is not a temporary object");
1221 return;
1222 }
1223
1224 // Verify the proposed new value is the right size.
1225 lldb::TargetSP target = GetTargetSP();
1226 uint64_t byte_size = 0;
1227 if (auto temp =
1228 llvm::expectedToOptional(GetCompilerType().GetByteSize(target.get())))
1229 byte_size = temp.value();
1230 if (value.getBitWidth() != byte_size * CHAR_BIT) {
1232 "illegal argument: new value should be of the same size");
1233 return;
1234 }
1235
1236 lldb::DataExtractorSP data_sp = std::make_shared<DataExtractor>(
1237 reinterpret_cast<const void *>(value.getRawData()), byte_size,
1238 target->GetArchitecture().GetByteOrder(),
1239 static_cast<uint8_t>(target->GetArchitecture().GetAddressByteSize()));
1240 SetData(*data_sp, error);
1241}
1242
1244 Status &error) {
1245 // Verify the current object is an integer object
1246 CompilerType val_type = GetCompilerType();
1247 if (!val_type.IsInteger() && !val_type.IsUnscopedEnumerationType() &&
1248 !HasFloatingRepresentation(val_type) && !val_type.IsPointerType() &&
1249 !val_type.IsScalarType()) {
1250 error =
1251 Status::FromErrorString("current value object is not an integer objet");
1252 return;
1253 }
1254
1255 // Verify the current object is not actually associated with any program
1256 // variable.
1257 if (GetVariable()) {
1259 "current value object is not a temporary object");
1260 return;
1261 }
1262
1263 // Verify the proposed new value is the right type.
1264 CompilerType new_val_type = new_val_sp->GetCompilerType();
1265 if (!new_val_type.IsInteger() && !HasFloatingRepresentation(new_val_type) &&
1266 !new_val_type.IsPointerType()) {
1268 "illegal argument: new value should be of the same size");
1269 return;
1270 }
1271
1272 if (new_val_type.IsInteger()) {
1273 auto value_or_err = new_val_sp->GetValueAsAPSInt();
1274 if (value_or_err)
1275 SetValueFromInteger(*value_or_err, error);
1276 else
1277 error = Status::FromErrorString("error getting APSInt from new_val_sp");
1278 } else if (HasFloatingRepresentation(new_val_type)) {
1279 auto value_or_err = new_val_sp->GetValueAsAPFloat();
1280 if (value_or_err)
1281 SetValueFromInteger(value_or_err->bitcastToAPInt(), error);
1282 else
1283 error = Status::FromErrorString("error getting APFloat from new_val_sp");
1284 } else if (new_val_type.IsPointerType()) {
1285 bool success = true;
1286 uint64_t int_val = new_val_sp->GetValueAsUnsigned(0, &success);
1287 if (success) {
1288 lldb::TargetSP target = GetTargetSP();
1289 uint64_t num_bits = 0;
1290 if (auto temp = llvm::expectedToOptional(
1291 new_val_sp->GetCompilerType().GetBitSize(target.get())))
1292 num_bits = temp.value();
1293 SetValueFromInteger(llvm::APInt(num_bits, int_val), error);
1294 } else
1295 error = Status::FromErrorString("error converting new_val_sp to integer");
1296 }
1297}
1298
1299// if any more "special cases" are added to
1300// ValueObject::DumpPrintableRepresentation() please keep this call up to date
1301// by returning true for your new special cases. We will eventually move to
1302// checking this call result before trying to display special cases
1304 ValueObjectRepresentationStyle val_obj_display, Format custom_format) {
1305 Flags flags(GetTypeInfo());
1306 if (flags.AnySet(eTypeIsArray | eTypeIsPointer) &&
1308 if (IsCStringContainer(true) &&
1309 (custom_format == eFormatCString || custom_format == eFormatCharArray ||
1310 custom_format == eFormatChar || custom_format == eFormatVectorOfChar))
1311 return true;
1312
1313 if (flags.Test(eTypeIsArray)) {
1314 if ((custom_format == eFormatBytes) ||
1315 (custom_format == eFormatBytesWithASCII))
1316 return true;
1317
1318 if ((custom_format == eFormatVectorOfChar) ||
1319 (custom_format == eFormatVectorOfFloat32) ||
1320 (custom_format == eFormatVectorOfFloat64) ||
1321 (custom_format == eFormatVectorOfSInt16) ||
1322 (custom_format == eFormatVectorOfSInt32) ||
1323 (custom_format == eFormatVectorOfSInt64) ||
1324 (custom_format == eFormatVectorOfSInt8) ||
1325 (custom_format == eFormatVectorOfUInt128) ||
1326 (custom_format == eFormatVectorOfUInt16) ||
1327 (custom_format == eFormatVectorOfUInt32) ||
1328 (custom_format == eFormatVectorOfUInt64) ||
1329 (custom_format == eFormatVectorOfUInt8))
1330 return true;
1331 }
1332 }
1333 return false;
1334}
1335
1337 Stream &s, ValueObjectRepresentationStyle val_obj_display,
1338 Format custom_format, PrintableRepresentationSpecialCases special,
1339 bool do_dump_error) {
1340
1341 // If the ValueObject has an error, we might end up dumping the type, which
1342 // is useful, but if we don't even have a type, then don't examine the object
1343 // further as that's not meaningful, only the error is.
1344 if (m_error.Fail() && !GetCompilerType().IsValid()) {
1345 if (do_dump_error)
1346 s.Printf("<%s>", m_error.AsCString());
1347 return false;
1348 }
1349
1350 Flags flags(GetTypeInfo());
1351
1352 bool allow_special =
1354 const bool only_special = false;
1355
1356 if (allow_special) {
1357 if (flags.AnySet(eTypeIsArray | eTypeIsPointer) &&
1359 // when being asked to get a printable display an array or pointer type
1360 // directly, try to "do the right thing"
1361
1362 if (IsCStringContainer(true) &&
1363 (custom_format == eFormatCString ||
1364 custom_format == eFormatCharArray || custom_format == eFormatChar ||
1365 custom_format ==
1366 eFormatVectorOfChar)) // print char[] & char* directly
1367 {
1368 Status error;
1370 std::pair<size_t, bool> read_string =
1371 ReadPointedString(buffer_sp, error,
1372 (custom_format == eFormatVectorOfChar) ||
1373 (custom_format == eFormatCharArray));
1374 lldb_private::formatters::StringPrinter::
1375 ReadBufferAndDumpToStreamOptions options(*this);
1376 options.SetData(DataExtractor(
1377 buffer_sp, lldb::eByteOrderInvalid,
1378 8)); // none of this matters for a string - pass some defaults
1379 options.SetStream(&s);
1380 options.SetPrefixToken(nullptr);
1381 options.SetQuote('"');
1382 options.SetSourceSize(buffer_sp->GetByteSize());
1383 options.SetIsTruncated(read_string.second);
1384 options.SetBinaryZeroIsTerminator(custom_format != eFormatVectorOfChar);
1386 lldb_private::formatters::StringPrinter::StringElementType::ASCII>(
1387 options);
1388 return !error.Fail();
1389 }
1390
1391 if (custom_format == eFormatEnum)
1392 return false;
1393
1394 // this only works for arrays, because I have no way to know when the
1395 // pointed memory ends, and no special \0 end of data marker
1396 if (flags.Test(eTypeIsArray)) {
1397 if ((custom_format == eFormatBytes) ||
1398 (custom_format == eFormatBytesWithASCII)) {
1399 const size_t count = GetNumChildrenIgnoringErrors();
1400
1401 s << '[';
1402 for (size_t low = 0; low < count; low++) {
1403
1404 if (low)
1405 s << ',';
1406
1407 ValueObjectSP child = GetChildAtIndex(low);
1408 if (!child.get()) {
1409 s << "<invalid child>";
1410 continue;
1411 }
1412 child->DumpPrintableRepresentation(
1414 custom_format);
1415 }
1416
1417 s << ']';
1418
1419 return true;
1420 }
1421
1422 if ((custom_format == eFormatVectorOfChar) ||
1423 (custom_format == eFormatVectorOfFloat32) ||
1424 (custom_format == eFormatVectorOfFloat64) ||
1425 (custom_format == eFormatVectorOfSInt16) ||
1426 (custom_format == eFormatVectorOfSInt32) ||
1427 (custom_format == eFormatVectorOfSInt64) ||
1428 (custom_format == eFormatVectorOfSInt8) ||
1429 (custom_format == eFormatVectorOfUInt128) ||
1430 (custom_format == eFormatVectorOfUInt16) ||
1431 (custom_format == eFormatVectorOfUInt32) ||
1432 (custom_format == eFormatVectorOfUInt64) ||
1433 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes
1434 // with ASCII or any vector
1435 // format should be printed
1436 // directly
1437 {
1438 const size_t count = GetNumChildrenIgnoringErrors();
1439
1440 Format format = FormatManager::GetSingleItemFormat(custom_format);
1441
1442 s << '[';
1443 for (size_t low = 0; low < count; low++) {
1444
1445 if (low)
1446 s << ',';
1447
1448 ValueObjectSP child = GetChildAtIndex(low);
1449 if (!child.get()) {
1450 s << "<invalid child>";
1451 continue;
1452 }
1453 child->DumpPrintableRepresentation(
1455 }
1456
1457 s << ']';
1458
1459 return true;
1460 }
1461 }
1462
1463 if ((custom_format == eFormatBoolean) ||
1464 (custom_format == eFormatBinary) || (custom_format == eFormatChar) ||
1465 (custom_format == eFormatCharPrintable) ||
1466 (custom_format == eFormatComplexFloat) ||
1467 (custom_format == eFormatDecimal) || (custom_format == eFormatHex) ||
1468 (custom_format == eFormatHexUppercase) ||
1469 (custom_format == eFormatFloat) ||
1470 (custom_format == eFormatFloat128) ||
1471 (custom_format == eFormatOctal) || (custom_format == eFormatOSType) ||
1472 (custom_format == eFormatUnicode16) ||
1473 (custom_format == eFormatUnicode32) ||
1474 (custom_format == eFormatUnsigned) ||
1475 (custom_format == eFormatPointer) ||
1476 (custom_format == eFormatComplexInteger) ||
1477 (custom_format == eFormatComplex) ||
1478 (custom_format == eFormatDefault)) // use the [] operator
1479 return false;
1480 }
1481 }
1482
1483 if (only_special)
1484 return false;
1485
1486 bool var_success = false;
1487
1488 {
1489 llvm::StringRef str;
1490
1491 // this is a local stream that we are using to ensure that the data pointed
1492 // to by cstr survives long enough for us to copy it to its destination -
1493 // it is necessary to have this temporary storage area for cases where our
1494 // desired output is not backed by some other longer-term storage
1495 StreamString strm;
1496
1497 if (custom_format != eFormatInvalid)
1498 SetFormat(custom_format);
1499
1500 switch (val_obj_display) {
1502 str = GetValueAsCString();
1503 break;
1504
1506 str = GetSummaryAsCString();
1507 break;
1508
1510 llvm::Expected<std::string> desc = GetObjectDescription();
1511 if (!desc) {
1512 strm << "error: " << toString(desc.takeError());
1513 str = strm.GetString();
1514 } else {
1515 strm << *desc;
1516 str = strm.GetString();
1517 }
1518 } break;
1519
1521 str = GetLocationAsCString();
1522 break;
1523
1525 if (auto err = GetNumChildren()) {
1526 strm.Printf("%" PRIu32, *err);
1527 str = strm.GetString();
1528 } else {
1529 strm << "error: " << toString(err.takeError());
1530 str = strm.GetString();
1531 }
1532 break;
1533 }
1534
1536 str = GetTypeName().GetStringRef();
1537 break;
1538
1540 str = GetName().GetStringRef();
1541 break;
1542
1544 GetExpressionPath(strm);
1545 str = strm.GetString();
1546 break;
1547 }
1548
1549 // If the requested display style produced no output, try falling back to
1550 // alternative presentations.
1551 if (str.empty()) {
1552 if (val_obj_display == eValueObjectRepresentationStyleValue)
1553 str = GetSummaryAsCString();
1554 else if (val_obj_display == eValueObjectRepresentationStyleSummary) {
1555 if (!CanProvideValue()) {
1556 strm.Printf("%s @ %s", GetTypeName().AsCString(),
1558 str = strm.GetString();
1559 } else
1560 str = GetValueAsCString();
1561 }
1562 }
1563
1564 if (!str.empty())
1565 s << str;
1566 else {
1567 // We checked for errors at the start, but do it again here in case
1568 // realizing the value for dumping produced an error.
1569 if (m_error.Fail()) {
1570 if (do_dump_error)
1571 s.Printf("<%s>", m_error.AsCString());
1572 else
1573 return false;
1574 } else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1575 s.PutCString("<no summary available>");
1576 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1577 s.PutCString("<no value available>");
1578 else if (val_obj_display ==
1580 s.PutCString("<not a valid Objective-C object>"); // edit this if we
1581 // have other runtimes
1582 // that support a
1583 // description
1584 else
1585 s.PutCString("<no printable representation>");
1586 }
1587
1588 // we should only return false here if we could not do *anything* even if
1589 // we have an error message as output, that's a success from our callers'
1590 // perspective, so return true
1591 var_success = true;
1592
1593 if (custom_format != eFormatInvalid)
1595 }
1596
1597 return var_success;
1598}
1599
1601ValueObject::GetAddressOf(bool scalar_is_load_address) {
1602 // Can't take address of a bitfield
1603 if (IsBitfield())
1604 return {};
1605
1606 if (!UpdateValueIfNeeded(false))
1607 return {};
1608
1609 switch (m_value.GetValueType()) {
1611 return {};
1613 if (scalar_is_load_address) {
1614 return {m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS),
1616 }
1617 return {};
1618
1621 return {m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS),
1622 m_value.GetValueAddressType()};
1624 return {LLDB_INVALID_ADDRESS, m_value.GetValueAddressType()};
1625 }
1626 llvm_unreachable("Unhandled value type!");
1627}
1628
1630 if (!UpdateValueIfNeeded(false))
1631 return {};
1632
1633 switch (m_value.GetValueType()) {
1635 return {};
1637 return {m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS),
1639
1643 lldb::offset_t data_offset = 0;
1644 return {m_data.GetAddress(&data_offset), GetAddressTypeOfChildren()};
1645 }
1646 }
1647
1648 llvm_unreachable("Unhandled value type!");
1649}
1650
1651static const char *ConvertBoolean(lldb::LanguageType language_type,
1652 const char *value_str) {
1653 if (Language *language = Language::FindPlugin(language_type))
1654 if (auto boolean = language->GetBooleanFromString(value_str))
1655 return *boolean ? "1" : "0";
1656
1657 return llvm::StringSwitch<const char *>(value_str)
1658 .Case("true", "1")
1659 .Case("false", "0")
1660 .Default(value_str);
1661}
1662
1663bool ValueObject::SetValueFromCString(const char *value_str, Status &error) {
1664 error.Clear();
1665 // Make sure our value is up to date first so that our location and location
1666 // type is valid.
1667 if (!UpdateValueIfNeeded(false)) {
1668 error = Status::FromErrorString("unable to read value");
1669 return false;
1670 }
1671
1672 const Encoding encoding = GetCompilerType().GetEncoding();
1673
1674 const size_t byte_size = llvm::expectedToOptional(GetByteSize()).value_or(0);
1675
1676 Value::ValueType value_type = m_value.GetValueType();
1677
1678 if (value_type == Value::ValueType::Scalar) {
1679 // If the value is already a scalar, then let the scalar change itself:
1680 m_value.GetScalar().SetValueFromCString(value_str, encoding, byte_size);
1681 } else if (byte_size <= 16) {
1682 if (GetCompilerType().IsBoolean())
1683 value_str = ConvertBoolean(GetObjectRuntimeLanguage(), value_str);
1684
1685 // If the value fits in a scalar, then make a new scalar and again let the
1686 // scalar code do the conversion, then figure out where to put the new
1687 // value.
1688 Scalar new_scalar;
1689 error = new_scalar.SetValueFromCString(value_str, encoding, byte_size);
1690 if (error.Success()) {
1691 switch (value_type) {
1693 // If it is a load address, then the scalar value is the storage
1694 // location of the data, and we have to shove this value down to that
1695 // load location.
1697 Process *process = exe_ctx.GetProcessPtr();
1698 if (process) {
1699 addr_t target_addr =
1700 m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1701 size_t bytes_written = process->WriteScalarToMemory(
1702 target_addr, new_scalar, byte_size, error);
1703 if (!error.Success())
1704 return false;
1705 if (bytes_written != byte_size) {
1706 error = Status::FromErrorString("unable to write value to memory");
1707 return false;
1708 }
1709 }
1710 } break;
1712 // If it is a host address, then we stuff the scalar as a DataBuffer
1713 // into the Value's data.
1714 DataExtractor new_data;
1715 new_data.SetByteOrder(m_data.GetByteOrder());
1716
1717 DataBufferSP buffer_sp(new DataBufferHeap(byte_size, 0));
1718 m_data.SetData(buffer_sp, 0);
1719 bool success = new_scalar.GetData(new_data);
1720 if (success) {
1721 new_data.CopyByteOrderedData(
1722 0, byte_size, const_cast<uint8_t *>(m_data.GetDataStart()),
1723 byte_size, m_data.GetByteOrder());
1724 }
1725 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1726
1727 } break;
1729 error = Status::FromErrorString("invalid location");
1730 return false;
1733 break;
1734 }
1735 } else {
1736 return false;
1737 }
1738 } else {
1739 // We don't support setting things bigger than a scalar at present.
1740 error = Status::FromErrorString("unable to write aggregate data type");
1741 return false;
1742 }
1743
1744 // If we have reached this point, then we have successfully changed the
1745 // value.
1747 return true;
1748}
1749
1751 decl.Clear();
1752 return false;
1753}
1754
1758
1760 ValueObjectSP synthetic_child_sp;
1761 std::map<ConstString, ValueObject *>::const_iterator pos =
1762 m_synthetic_children.find(key);
1763 if (pos != m_synthetic_children.end())
1764 synthetic_child_sp = pos->second->GetSP();
1765 return synthetic_child_sp;
1766}
1767
1770 Process *process = exe_ctx.GetProcessPtr();
1771 if (process)
1772 return process->IsPossibleDynamicValue(*this);
1773 else
1774 return GetCompilerType().IsPossibleDynamicType(nullptr, true, true);
1775}
1776
1778 Process *process(GetProcessSP().get());
1779 if (!process)
1780 return false;
1781
1782 // We trust that the compiler did the right thing and marked runtime support
1783 // values as artificial.
1784 if (!GetVariable() || !GetVariable()->IsArtificial())
1785 return false;
1786
1787 if (auto *runtime = process->GetLanguageRuntime(GetVariable()->GetLanguage()))
1788 if (runtime->IsAllowedRuntimeValue(GetName()))
1789 return false;
1790
1791 return true;
1792}
1793
1796 return language->IsNilReference(*this);
1797 }
1798 return false;
1799}
1800
1803 return language->IsUninitializedReference(*this);
1804 }
1805 return false;
1806}
1807
1808// This allows you to create an array member using and index that doesn't not
1809// fall in the normal bounds of the array. Many times structure can be defined
1810// as: struct Collection {
1811// uint32_t item_count;
1812// Item item_array[0];
1813// };
1814// The size of the "item_array" is 1, but many times in practice there are more
1815// items in "item_array".
1816
1818 bool can_create) {
1819 ValueObjectSP synthetic_child_sp;
1820 if (IsPointerType() || IsArrayType()) {
1821 std::string index_str = llvm::formatv("[{0}]", index);
1822 ConstString index_const_str(index_str);
1823 // Check if we have already created a synthetic array member in this valid
1824 // object. If we have we will re-use it.
1825 synthetic_child_sp = GetSyntheticChild(index_const_str);
1826 if (!synthetic_child_sp) {
1827 ValueObject *synthetic_child;
1828 // We haven't made a synthetic array member for INDEX yet, so lets make
1829 // one and cache it for any future reference.
1830 synthetic_child = CreateSyntheticArrayMember(index);
1831
1832 // Cache the value if we got one back...
1833 if (synthetic_child) {
1834 AddSyntheticChild(index_const_str, synthetic_child);
1835 synthetic_child_sp = synthetic_child->GetSP();
1836 synthetic_child_sp->SetName(ConstString(index_str));
1837 synthetic_child_sp->m_flags.m_is_array_item_for_pointer = true;
1838 }
1839 }
1840 }
1841 return synthetic_child_sp;
1842}
1843
1845 bool can_create) {
1846 ValueObjectSP synthetic_child_sp;
1847 if (IsScalarType()) {
1848 std::string index_str = llvm::formatv("[{0}-{1}]", from, to);
1849 ConstString index_const_str(index_str);
1850 // Check if we have already created a synthetic array member in this valid
1851 // object. If we have we will re-use it.
1852 synthetic_child_sp = GetSyntheticChild(index_const_str);
1853 if (!synthetic_child_sp) {
1854 uint32_t bit_field_size = to - from + 1;
1855 uint32_t bit_field_offset = from;
1856 if (GetDataExtractor().GetByteOrder() == eByteOrderBig)
1857 bit_field_offset =
1858 llvm::expectedToOptional(GetByteSize()).value_or(0) * 8 -
1859 bit_field_size - bit_field_offset;
1860 // We haven't made a synthetic array member for INDEX yet, so lets make
1861 // one and cache it for any future reference.
1862 ValueObjectChild *synthetic_child = new ValueObjectChild(
1863 *this, GetCompilerType(), index_const_str,
1864 llvm::expectedToOptional(GetByteSize()).value_or(0), 0,
1865 bit_field_size, bit_field_offset, false, false, eAddressTypeInvalid,
1866 0);
1867
1868 // Cache the value if we got one back...
1869 if (synthetic_child) {
1870 AddSyntheticChild(index_const_str, synthetic_child);
1871 synthetic_child_sp = synthetic_child->GetSP();
1872 synthetic_child_sp->SetName(ConstString(index_str));
1873 synthetic_child_sp->m_flags.m_is_bitfield_for_scalar = true;
1874 }
1875 }
1876 }
1877 return synthetic_child_sp;
1878}
1879
1881 uint32_t offset, const CompilerType &type, bool can_create,
1882 ConstString name_const_str) {
1883
1884 ValueObjectSP synthetic_child_sp;
1885
1886 if (name_const_str.IsEmpty()) {
1887 name_const_str.SetString("@" + std::to_string(offset));
1888 }
1889
1890 // Check if we have already created a synthetic array member in this valid
1891 // object. If we have we will re-use it.
1892 synthetic_child_sp = GetSyntheticChild(name_const_str);
1893
1894 if (synthetic_child_sp.get())
1895 return synthetic_child_sp;
1896
1897 if (!can_create)
1898 return {};
1899
1901 std::optional<uint64_t> size = llvm::expectedToOptional(
1903 if (!size)
1904 return {};
1905 ValueObjectChild *synthetic_child =
1906 new ValueObjectChild(*this, type, name_const_str, *size, offset, 0, 0,
1907 false, false, eAddressTypeInvalid, 0);
1908 if (synthetic_child) {
1909 AddSyntheticChild(name_const_str, synthetic_child);
1910 synthetic_child_sp = synthetic_child->GetSP();
1911 synthetic_child_sp->SetName(name_const_str);
1912 synthetic_child_sp->m_flags.m_is_child_at_offset = true;
1913 }
1914 return synthetic_child_sp;
1915}
1916
1918 const CompilerType &type,
1919 bool can_create,
1920 ConstString name_const_str) {
1921 ValueObjectSP synthetic_child_sp;
1922
1923 if (name_const_str.IsEmpty()) {
1924 char name_str[128];
1925 snprintf(name_str, sizeof(name_str), "base%s@%i",
1926 type.GetTypeName().AsCString("<unknown>"), offset);
1927 name_const_str.SetCString(name_str);
1928 }
1929
1930 // Check if we have already created a synthetic array member in this valid
1931 // object. If we have we will re-use it.
1932 synthetic_child_sp = GetSyntheticChild(name_const_str);
1933
1934 if (synthetic_child_sp.get())
1935 return synthetic_child_sp;
1936
1937 if (!can_create)
1938 return {};
1939
1940 const bool is_base_class = true;
1941
1943 std::optional<uint64_t> size = llvm::expectedToOptional(
1945 if (!size)
1946 return {};
1947 ValueObjectChild *synthetic_child =
1948 new ValueObjectChild(*this, type, name_const_str, *size, offset, 0, 0,
1949 is_base_class, false, eAddressTypeInvalid, 0);
1950 if (synthetic_child) {
1951 AddSyntheticChild(name_const_str, synthetic_child);
1952 synthetic_child_sp = synthetic_child->GetSP();
1953 synthetic_child_sp->SetName(name_const_str);
1954 }
1955 return synthetic_child_sp;
1956}
1957
1958// your expression path needs to have a leading . or -> (unless it somehow
1959// "looks like" an array, in which case it has a leading [ symbol). while the [
1960// is meaningful and should be shown to the user, . and -> are just parser
1961// design, but by no means added information for the user.. strip them off
1962static const char *SkipLeadingExpressionPathSeparators(const char *expression) {
1963 if (!expression || !expression[0])
1964 return expression;
1965 if (expression[0] == '.')
1966 return expression + 1;
1967 if (expression[0] == '-' && expression[1] == '>')
1968 return expression + 2;
1969 return expression;
1970}
1971
1974 bool can_create) {
1975 ValueObjectSP synthetic_child_sp;
1976 ConstString name_const_string(expression);
1977 // Check if we have already created a synthetic array member in this valid
1978 // object. If we have we will re-use it.
1979 synthetic_child_sp = GetSyntheticChild(name_const_string);
1980 if (!synthetic_child_sp) {
1981 // We haven't made a synthetic array member for expression yet, so lets
1982 // make one and cache it for any future reference.
1983 synthetic_child_sp = GetValueForExpressionPath(
1984 expression, nullptr, nullptr,
1985 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(
1987 None));
1988
1989 // Cache the value if we got one back...
1990 if (synthetic_child_sp.get()) {
1991 // FIXME: this causes a "real" child to end up with its name changed to
1992 // the contents of expression
1993 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
1994 synthetic_child_sp->SetName(
1996 }
1997 }
1998 return synthetic_child_sp;
1999}
2000
2002 TargetSP target_sp(GetTargetSP());
2003 if (target_sp && !target_sp->GetEnableSyntheticValue()) {
2004 m_synthetic_value = nullptr;
2005 return;
2006 }
2007
2009
2011 return;
2012
2013 if (m_synthetic_children_sp.get() == nullptr)
2014 return;
2015
2016 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2017 return;
2018
2020}
2021
2023 if (use_dynamic == eNoDynamicValues)
2024 return;
2025
2026 if (!m_dynamic_value && !IsDynamic()) {
2028 Process *process = exe_ctx.GetProcessPtr();
2029 if (process && process->IsPossibleDynamicValue(*this)) {
2031 m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic);
2032 }
2033 }
2034}
2035
2037 if (use_dynamic == eNoDynamicValues)
2038 return ValueObjectSP();
2039
2040 if (!IsDynamic() && m_dynamic_value == nullptr) {
2041 CalculateDynamicValue(use_dynamic);
2042 }
2043 if (m_dynamic_value && m_dynamic_value->GetError().Success())
2044 return m_dynamic_value->GetSP();
2045 else
2046 return ValueObjectSP();
2047}
2048
2051
2053 return m_synthetic_value->GetSP();
2054 else
2055 return ValueObjectSP();
2056}
2057
2060
2061 if (m_synthetic_children_sp.get() == nullptr)
2062 return false;
2063
2065
2066 return m_synthetic_value != nullptr;
2067}
2068
2070 if (GetParent()) {
2071 if (GetParent()->IsBaseClass())
2072 return GetParent()->GetNonBaseClassParent();
2073 else
2074 return GetParent();
2075 }
2076 return nullptr;
2077}
2078
2079bool ValueObject::IsBaseClass(uint32_t &depth) {
2080 if (!IsBaseClass()) {
2081 depth = 0;
2082 return false;
2083 }
2084 if (GetParent()) {
2085 GetParent()->IsBaseClass(depth);
2086 depth = depth + 1;
2087 return true;
2088 }
2089 // TODO: a base of no parent? weird..
2090 depth = 1;
2091 return true;
2092}
2093
2095 GetExpressionPathFormat epformat) {
2096 // synthetic children do not actually "exist" as part of the hierarchy, and
2097 // sometimes they are consed up in ways that don't make sense from an
2098 // underlying language/API standpoint. So, use a special code path here to
2099 // return something that can hopefully be used in expression
2100 if (m_flags.m_is_synthetic_children_generated) {
2102
2103 if (m_value.GetValueType() == Value::ValueType::LoadAddress) {
2105 s.Printf("((%s)0x%" PRIx64 ")", GetTypeName().AsCString("void"),
2107 return;
2108 } else {
2109 uint64_t load_addr =
2110 m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2111 if (load_addr != LLDB_INVALID_ADDRESS) {
2112 s.Printf("(*( (%s *)0x%" PRIx64 "))", GetTypeName().AsCString("void"),
2113 load_addr);
2114 return;
2115 }
2116 }
2117 }
2118
2119 if (CanProvideValue()) {
2120 s.Printf("((%s)%s)", GetTypeName().AsCString("void"),
2122 return;
2123 }
2124
2125 return;
2126 }
2127
2128 const bool is_deref_of_parent = IsDereferenceOfParent();
2129
2130 if (is_deref_of_parent &&
2132 // this is the original format of GetExpressionPath() producing code like
2133 // *(a_ptr).memberName, which is entirely fine, until you put this into
2134 // StackFrame::GetValueForVariableExpressionPath() which prefers to see
2135 // a_ptr->memberName. the eHonorPointers mode is meant to produce strings
2136 // in this latter format
2137 s.PutCString("*(");
2138 }
2139
2140 ValueObject *parent = GetParent();
2141
2142 if (parent) {
2143 parent->GetExpressionPath(s, epformat);
2144 const CompilerType parentType = parent->GetCompilerType();
2145 if (parentType.IsPointerType() &&
2146 parentType.GetPointeeType().IsArrayType(nullptr, nullptr, nullptr)) {
2147 // When the parent is a pointer to an array, then we have to:
2148 // - follow the expression path of the parent with "[0]"
2149 // (that will indicate dereferencing the pointer to the array)
2150 // - and then follow that with this ValueObject's name
2151 // (which will be something like "[i]" to indicate
2152 // the i-th element of the array)
2153 s.PutCString("[0]");
2154 s.PutCString(GetName().GetCString());
2155 return;
2156 }
2157 }
2158
2159 // if we are a deref_of_parent just because we are synthetic array members
2160 // made up to allow ptr[%d] syntax to work in variable printing, then add our
2161 // name ([%d]) to the expression path
2162 if (m_flags.m_is_array_item_for_pointer &&
2164 s.PutCString(m_name.GetStringRef());
2165
2166 if (!IsBaseClass()) {
2167 if (!is_deref_of_parent) {
2168 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2169 if (non_base_class_parent &&
2170 !non_base_class_parent->GetName().IsEmpty()) {
2171 CompilerType non_base_class_parent_compiler_type =
2172 non_base_class_parent->GetCompilerType();
2173 if (non_base_class_parent_compiler_type) {
2174 if (parent && parent->IsDereferenceOfParent() &&
2176 s.PutCString("->");
2177 } else {
2178 const uint32_t non_base_class_parent_type_info =
2179 non_base_class_parent_compiler_type.GetTypeInfo();
2180
2181 if (non_base_class_parent_type_info & eTypeIsPointer) {
2182 s.PutCString("->");
2183 } else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2184 !(non_base_class_parent_type_info & eTypeIsArray)) {
2185 s.PutChar('.');
2186 }
2187 }
2188 }
2189 }
2190
2191 const char *name = GetName().GetCString();
2192 if (name)
2193 s.PutCString(name);
2194 }
2195 }
2196
2197 if (is_deref_of_parent &&
2199 s.PutChar(')');
2200 }
2201}
2202
2203// Return the alternate value (synthetic if the input object is non-synthetic
2204// and otherwise) this is permitted by the expression path options.
2206 ValueObject &valobj,
2208 synth_traversal) {
2209 using SynthTraversal =
2211
2212 if (valobj.IsSynthetic()) {
2213 if (synth_traversal == SynthTraversal::FromSynthetic ||
2214 synth_traversal == SynthTraversal::Both)
2215 return valobj.GetNonSyntheticValue();
2216 } else {
2217 if (synth_traversal == SynthTraversal::ToSynthetic ||
2218 synth_traversal == SynthTraversal::Both)
2219 return valobj.GetSyntheticValue();
2220 }
2221 return nullptr;
2222}
2223
2224// Dereference the provided object or the alternate value, if permitted by the
2225// expression path options.
2227 ValueObject &valobj,
2229 synth_traversal,
2230 Status &error) {
2231 error.Clear();
2232 ValueObjectSP result = valobj.Dereference(error);
2233 if (!result || error.Fail()) {
2234 if (ValueObjectSP alt_obj = GetAlternateValue(valobj, synth_traversal)) {
2235 error.Clear();
2236 result = alt_obj->Dereference(error);
2237 }
2238 }
2239 return result;
2240}
2241
2243 llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop,
2244 ExpressionPathEndResultType *final_value_type,
2245 const GetValueForExpressionPathOptions &options,
2246 ExpressionPathAftermath *final_task_on_target) {
2247
2248 ExpressionPathScanEndReason dummy_reason_to_stop =
2250 ExpressionPathEndResultType dummy_final_value_type =
2252 ExpressionPathAftermath dummy_final_task_on_target =
2254
2256 expression, reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2257 final_value_type ? final_value_type : &dummy_final_value_type, options,
2258 final_task_on_target ? final_task_on_target
2259 : &dummy_final_task_on_target);
2260
2261 if (!final_task_on_target ||
2262 *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
2263 return ret_val;
2264
2265 if (ret_val.get() &&
2266 ((final_value_type ? *final_value_type : dummy_final_value_type) ==
2267 eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress
2268 // of plain objects
2269 {
2270 if ((final_task_on_target ? *final_task_on_target
2271 : dummy_final_task_on_target) ==
2273 Status error;
2275 *ret_val, options.m_synthetic_children_traversal, error);
2276 if (error.Fail() || !final_value.get()) {
2277 if (reason_to_stop)
2278 *reason_to_stop =
2280 if (final_value_type)
2282 return ValueObjectSP();
2283 } else {
2284 if (final_task_on_target)
2285 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2286 return final_value;
2287 }
2288 }
2289 if (*final_task_on_target ==
2291 Status error;
2292 ValueObjectSP final_value = ret_val->AddressOf(error);
2293 if (error.Fail() || !final_value.get()) {
2294 if (reason_to_stop)
2295 *reason_to_stop =
2297 if (final_value_type)
2299 return ValueObjectSP();
2300 } else {
2301 if (final_task_on_target)
2302 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2303 return final_value;
2304 }
2305 }
2306 }
2307 return ret_val; // final_task_on_target will still have its original value, so
2308 // you know I did not do it
2309}
2310
2312 llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop,
2313 ExpressionPathEndResultType *final_result,
2314 const GetValueForExpressionPathOptions &options,
2315 ExpressionPathAftermath *what_next) {
2316 ValueObjectSP root = GetSP();
2317
2318 if (!root)
2319 return nullptr;
2320
2321 llvm::StringRef remainder = expression;
2322
2323 while (true) {
2324 llvm::StringRef temp_expression = remainder;
2325
2326 CompilerType root_compiler_type = root->GetCompilerType();
2327 CompilerType pointee_compiler_type;
2328 Flags pointee_compiler_type_info;
2329
2330 Flags root_compiler_type_info(
2331 root_compiler_type.GetTypeInfo(&pointee_compiler_type));
2332 if (pointee_compiler_type)
2333 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
2334
2335 if (temp_expression.empty()) {
2337 return root;
2338 }
2339
2340 switch (temp_expression.front()) {
2341 case '-': {
2342 temp_expression = temp_expression.drop_front();
2343 if (options.m_check_dot_vs_arrow_syntax &&
2344 root_compiler_type_info.Test(eTypeIsPointer)) // if you are trying to
2345 // use -> on a
2346 // non-pointer and I
2347 // must catch the error
2348 {
2349 *reason_to_stop =
2352 return ValueObjectSP();
2353 }
2354 if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to
2355 // extract an ObjC IVar
2356 // when this is forbidden
2357 root_compiler_type_info.Test(eTypeIsPointer) &&
2358 options.m_no_fragile_ivar) {
2359 *reason_to_stop =
2362 return ValueObjectSP();
2363 }
2364 if (!temp_expression.starts_with(">")) {
2365 *reason_to_stop =
2368 return ValueObjectSP();
2369 }
2370 }
2371 [[fallthrough]];
2372 case '.': // or fallthrough from ->
2373 {
2374 if (options.m_check_dot_vs_arrow_syntax &&
2375 temp_expression.front() == '.' &&
2376 root_compiler_type_info.Test(eTypeIsPointer)) // if you are trying to
2377 // use . on a pointer
2378 // and I must catch the
2379 // error
2380 {
2381 *reason_to_stop =
2384 return nullptr;
2385 }
2386 temp_expression = temp_expression.drop_front(); // skip . or >
2387
2388 size_t next_sep_pos = temp_expression.find_first_of("-.[", 1);
2389 if (next_sep_pos == llvm::StringRef::npos) {
2390 // if no other separator just expand this last layer
2391 llvm::StringRef child_name = temp_expression;
2392 ValueObjectSP child_valobj_sp =
2393 root->GetChildMemberWithName(child_name);
2394 if (!child_valobj_sp) {
2395 if (ValueObjectSP altroot = GetAlternateValue(
2396 *root, options.m_synthetic_children_traversal))
2397 child_valobj_sp = altroot->GetChildMemberWithName(child_name);
2398 }
2399 if (child_valobj_sp) {
2400 *reason_to_stop =
2403 return child_valobj_sp;
2404 }
2407 return nullptr;
2408 }
2409
2410 llvm::StringRef next_separator = temp_expression.substr(next_sep_pos);
2411 llvm::StringRef child_name = temp_expression.slice(0, next_sep_pos);
2412
2413 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name);
2414 if (!child_valobj_sp) {
2415 if (ValueObjectSP altroot = GetAlternateValue(
2416 *root, options.m_synthetic_children_traversal))
2417 child_valobj_sp = altroot->GetChildMemberWithName(child_name);
2418 }
2419 if (child_valobj_sp) {
2420 root = child_valobj_sp;
2421 remainder = next_separator;
2423 continue;
2424 }
2427 return nullptr;
2428 }
2429 case '[': {
2430 if (!root_compiler_type_info.Test(eTypeIsArray) &&
2431 !root_compiler_type_info.Test(eTypeIsPointer) &&
2432 !root_compiler_type_info.Test(
2433 eTypeIsVector)) // if this is not a T[] nor a T*
2434 {
2435 if (!root_compiler_type_info.Test(
2436 eTypeIsScalar)) // if this is not even a scalar...
2437 {
2438 if (options.m_synthetic_children_traversal ==
2440 None) // ...only chance left is synthetic
2441 {
2442 *reason_to_stop =
2445 return ValueObjectSP();
2446 }
2447 } else if (!options.m_allow_bitfields_syntax) // if this is a scalar,
2448 // check that we can
2449 // expand bitfields
2450 {
2451 *reason_to_stop =
2454 return ValueObjectSP();
2455 }
2456 }
2457 if (temp_expression[1] ==
2458 ']') // if this is an unbounded range it only works for arrays
2459 {
2460 if (!root_compiler_type_info.Test(eTypeIsArray)) {
2461 *reason_to_stop =
2464 return nullptr;
2465 } else // even if something follows, we cannot expand unbounded ranges,
2466 // just let the caller do it
2467 {
2468 *reason_to_stop =
2470 *final_result =
2472 return root;
2473 }
2474 }
2475
2476 size_t close_bracket_position = temp_expression.find(']', 1);
2477 if (close_bracket_position ==
2478 llvm::StringRef::npos) // if there is no ], this is a syntax error
2479 {
2480 *reason_to_stop =
2483 return nullptr;
2484 }
2485
2486 llvm::StringRef bracket_expr =
2487 temp_expression.slice(1, close_bracket_position);
2488
2489 // If this was an empty expression it would have been caught by the if
2490 // above.
2491 assert(!bracket_expr.empty());
2492
2493 if (!bracket_expr.contains('-')) {
2494 // if no separator, this is of the form [N]. Note that this cannot be
2495 // an unbounded range of the form [], because that case was handled
2496 // above with an unconditional return.
2497 unsigned long index = 0;
2498 if (bracket_expr.getAsInteger(0, index)) {
2499 *reason_to_stop =
2502 return nullptr;
2503 }
2504
2505 // from here on we do have a valid index
2506 if (root_compiler_type_info.Test(eTypeIsArray)) {
2507 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index);
2508 if (!child_valobj_sp)
2509 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
2510 if (!child_valobj_sp)
2511 if (root->HasSyntheticValue() &&
2512 llvm::expectedToStdOptional(
2513 root->GetSyntheticValue()->GetNumChildren())
2514 .value_or(0) > index)
2515 child_valobj_sp =
2516 root->GetSyntheticValue()->GetChildAtIndex(index);
2517 if (child_valobj_sp) {
2518 root = child_valobj_sp;
2519 remainder =
2520 temp_expression.substr(close_bracket_position + 1); // skip ]
2522 continue;
2523 } else {
2524 *reason_to_stop =
2527 return nullptr;
2528 }
2529 } else if (root_compiler_type_info.Test(eTypeIsPointer)) {
2530 if (*what_next ==
2531 ValueObject::
2532 eExpressionPathAftermathDereference && // if this is a
2533 // ptr-to-scalar, I
2534 // am accessing it
2535 // by index and I
2536 // would have
2537 // deref'ed anyway,
2538 // then do it now
2539 // and use this as
2540 // a bitfield
2541 pointee_compiler_type_info.Test(eTypeIsScalar)) {
2542 Status error;
2544 *root, options.m_synthetic_children_traversal, error);
2545 if (error.Fail() || !root) {
2546 *reason_to_stop =
2549 return nullptr;
2550 } else {
2552 continue;
2553 }
2554 } else {
2555 if (root->GetCompilerType().GetMinimumLanguage() ==
2557 pointee_compiler_type_info.AllClear(eTypeIsPointer) &&
2558 root->HasSyntheticValue() &&
2561 SyntheticChildrenTraversal::ToSynthetic ||
2564 SyntheticChildrenTraversal::Both)) {
2565 root = root->GetSyntheticValue()->GetChildAtIndex(index);
2566 } else
2567 root = root->GetSyntheticArrayMember(index, true);
2568 if (!root) {
2569 *reason_to_stop =
2572 return nullptr;
2573 } else {
2574 remainder =
2575 temp_expression.substr(close_bracket_position + 1); // skip ]
2577 continue;
2578 }
2579 }
2580 } else if (root_compiler_type_info.Test(eTypeIsScalar)) {
2581 root = root->GetSyntheticBitFieldChild(index, index, true);
2582 if (!root) {
2583 *reason_to_stop =
2586 return nullptr;
2587 } else // we do not know how to expand members of bitfields, so we
2588 // just return and let the caller do any further processing
2589 {
2590 *reason_to_stop = ValueObject::
2591 eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2593 return root;
2594 }
2595 } else if (root_compiler_type_info.Test(eTypeIsVector)) {
2596 root = root->GetChildAtIndex(index);
2597 if (!root) {
2598 *reason_to_stop =
2601 return ValueObjectSP();
2602 } else {
2603 remainder =
2604 temp_expression.substr(close_bracket_position + 1); // skip ]
2606 continue;
2607 }
2608 } else if (options.m_synthetic_children_traversal ==
2610 SyntheticChildrenTraversal::ToSynthetic ||
2613 SyntheticChildrenTraversal::Both) {
2614 if (root->HasSyntheticValue())
2615 root = root->GetSyntheticValue();
2616 else if (!root->IsSynthetic()) {
2617 *reason_to_stop =
2620 return nullptr;
2621 }
2622 // if we are here, then root itself is a synthetic VO.. should be
2623 // good to go
2624
2625 if (!root) {
2626 *reason_to_stop =
2629 return nullptr;
2630 }
2631 root = root->GetChildAtIndex(index);
2632 if (!root) {
2633 *reason_to_stop =
2636 return nullptr;
2637 } else {
2638 remainder =
2639 temp_expression.substr(close_bracket_position + 1); // skip ]
2641 continue;
2642 }
2643 } else {
2644 *reason_to_stop =
2647 return nullptr;
2648 }
2649 } else {
2650 // we have a low and a high index
2651 llvm::StringRef sleft, sright;
2652 unsigned long low_index, high_index;
2653 std::tie(sleft, sright) = bracket_expr.split('-');
2654 if (sleft.getAsInteger(0, low_index) ||
2655 sright.getAsInteger(0, high_index)) {
2656 *reason_to_stop =
2659 return nullptr;
2660 }
2661
2662 if (low_index > high_index) // swap indices if required
2663 std::swap(low_index, high_index);
2664
2665 if (root_compiler_type_info.Test(
2666 eTypeIsScalar)) // expansion only works for scalars
2667 {
2668 root = root->GetSyntheticBitFieldChild(low_index, high_index, true);
2669 if (!root) {
2670 *reason_to_stop =
2673 return nullptr;
2674 } else {
2675 *reason_to_stop = ValueObject::
2676 eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2678 return root;
2679 }
2680 } else if (root_compiler_type_info.Test(
2681 eTypeIsPointer) && // if this is a ptr-to-scalar, I am
2682 // accessing it by index and I would
2683 // have deref'ed anyway, then do it
2684 // now and use this as a bitfield
2685 *what_next ==
2687 pointee_compiler_type_info.Test(eTypeIsScalar)) {
2688 Status error;
2690 *root, options.m_synthetic_children_traversal, error);
2691 if (error.Fail() || !root) {
2692 *reason_to_stop =
2695 return nullptr;
2696 } else {
2698 continue;
2699 }
2700 } else {
2701 *reason_to_stop =
2704 return root;
2705 }
2706 }
2707 break;
2708 }
2709 default: // some non-separator is in the way
2710 {
2711 *reason_to_stop =
2714 return nullptr;
2715 }
2716 }
2717 }
2718}
2719
2720llvm::Error ValueObject::Dump(Stream &s) {
2721 return Dump(s, DumpValueObjectOptions(*this));
2722}
2723
2725 const DumpValueObjectOptions &options) {
2726 ValueObjectPrinter printer(*this, &s, options);
2727 return printer.PrintValueObject();
2728}
2729
2731 ValueObjectSP valobj_sp;
2732
2733 if (UpdateValueIfNeeded(false) && m_error.Success()) {
2735
2736 DataExtractor data;
2737 data.SetByteOrder(m_data.GetByteOrder());
2738 data.SetAddressByteSize(m_data.GetAddressByteSize());
2739
2740 if (IsBitfield()) {
2742 m_error = v.GetValueAsData(&exe_ctx, data, GetModule().get());
2743 } else
2744 m_error = m_value.GetValueAsData(&exe_ctx, data, GetModule().get());
2745
2747 exe_ctx.GetBestExecutionContextScope(), GetCompilerType(), name, data,
2748 GetAddressOf().address);
2749 }
2750
2751 if (!valobj_sp) {
2754 exe_ctx.GetBestExecutionContextScope(), m_error.Clone());
2755 }
2756 return valobj_sp;
2757}
2758
2760 lldb::DynamicValueType dynValue, bool synthValue) {
2761 ValueObjectSP result_sp;
2762 switch (dynValue) {
2765 if (!IsDynamic())
2766 result_sp = GetDynamicValue(dynValue);
2767 } break;
2769 if (IsDynamic())
2770 result_sp = GetStaticValue();
2771 } break;
2772 }
2773 if (!result_sp)
2774 result_sp = GetSP();
2775 assert(result_sp);
2776
2777 bool is_synthetic = result_sp->IsSynthetic();
2778 if (synthValue && !is_synthetic) {
2779 if (auto synth_sp = result_sp->GetSyntheticValue())
2780 return synth_sp;
2781 }
2782 if (!synthValue && is_synthetic) {
2783 if (auto non_synth_sp = result_sp->GetNonSyntheticValue())
2784 return non_synth_sp;
2785 }
2786
2787 return result_sp;
2788}
2789
2791 if (m_deref_valobj)
2792 return m_deref_valobj->GetSP();
2793
2794 std::string deref_name_str;
2795 uint32_t deref_byte_size = 0;
2796 int32_t deref_byte_offset = 0;
2797 CompilerType compiler_type = GetCompilerType();
2798 uint64_t language_flags = 0;
2799
2801
2802 CompilerType deref_compiler_type;
2803 auto deref_compiler_type_or_err = compiler_type.GetDereferencedType(
2804 &exe_ctx, deref_name_str, deref_byte_size, deref_byte_offset, this,
2805 language_flags);
2806
2807 std::string deref_error;
2808 if (deref_compiler_type_or_err) {
2809 deref_compiler_type = *deref_compiler_type_or_err;
2810 } else {
2811 deref_error = llvm::toString(deref_compiler_type_or_err.takeError());
2812 LLDB_LOG(GetLog(LLDBLog::Types), "could not find child: {0}", deref_error);
2813 }
2814
2815 if (deref_compiler_type && deref_byte_size) {
2816 ConstString deref_name;
2817 if (!deref_name_str.empty())
2818 deref_name.SetCString(deref_name_str.c_str());
2819
2821 new ValueObjectChild(*this, deref_compiler_type, deref_name,
2822 deref_byte_size, deref_byte_offset, 0, 0, false,
2823 true, eAddressTypeInvalid, language_flags);
2824 }
2825
2826 // In case of incomplete deref compiler type, use the pointee type and try
2827 // to recreate a new ValueObjectChild using it.
2828 if (!m_deref_valobj) {
2829 // FIXME(#59012): C++ stdlib formatters break with incomplete types (e.g.
2830 // `std::vector<int> &`). Remove ObjC restriction once that's resolved.
2833 deref_compiler_type = compiler_type.GetPointeeType();
2834
2835 if (deref_compiler_type) {
2836 ConstString deref_name;
2837 if (!deref_name_str.empty())
2838 deref_name.SetCString(deref_name_str.c_str());
2839
2841 *this, deref_compiler_type, deref_name, deref_byte_size,
2842 deref_byte_offset, 0, 0, false, true, eAddressTypeInvalid,
2843 language_flags);
2844 }
2845 }
2846 }
2847
2848 if (!m_deref_valobj && IsSynthetic())
2849 m_deref_valobj = GetChildMemberWithName("$$dereference$$").get();
2850
2851 if (m_deref_valobj) {
2852 error.Clear();
2853 return m_deref_valobj->GetSP();
2854 } else {
2855 StreamString strm;
2856 GetExpressionPath(strm);
2857
2858 if (deref_error.empty())
2860 "dereference failed: (%s) %s",
2861 GetTypeName().AsCString("<invalid type>"), strm.GetData());
2862 else
2864 "dereference failed: %s: (%s) %s", deref_error.c_str(),
2865 GetTypeName().AsCString("<invalid type>"), strm.GetData());
2866 return ValueObjectSP();
2867 }
2868}
2869
2872 return m_addr_of_valobj_sp;
2873
2874 auto [addr, address_type] = GetAddressOf(/*scalar_is_load_address=*/false);
2875 error.Clear();
2876 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost) {
2877 switch (address_type) {
2878 case eAddressTypeInvalid: {
2879 StreamString expr_path_strm;
2880 GetExpressionPath(expr_path_strm);
2881 error = Status::FromErrorStringWithFormat("'%s' is not in memory",
2882 expr_path_strm.GetData());
2883 } break;
2884
2885 case eAddressTypeFile:
2886 case eAddressTypeLoad: {
2887 CompilerType compiler_type = GetCompilerType();
2888 if (compiler_type) {
2889 std::string name(1, '&');
2890 name.append(m_name.AsCString(""));
2892
2893 lldb::DataBufferSP buffer(
2894 new lldb_private::DataBufferHeap(&addr, sizeof(lldb::addr_t)));
2897 compiler_type.GetPointerType(), ConstString(name.c_str()), buffer,
2899 }
2900 } break;
2901 default:
2902 break;
2903 }
2904 } else {
2905 StreamString expr_path_strm;
2906 GetExpressionPath(expr_path_strm);
2908 "'%s' doesn't have a valid address", expr_path_strm.GetData());
2909 }
2910
2911 return m_addr_of_valobj_sp;
2912}
2913
2915 return ValueObjectCast::Create(*this, GetName(), compiler_type);
2916}
2917
2919 // Only allow casts if the original type is equal or larger than the cast
2920 // type, unless we know this is a load address. Getting the size wrong for
2921 // a host side storage could leak lldb memory, so we absolutely want to
2922 // prevent that. We may not always get the right value, for instance if we
2923 // have an expression result value that's copied into a storage location in
2924 // the target may not have copied enough memory. I'm not trying to fix that
2925 // here, I'm just making Cast from a smaller to a larger possible in all the
2926 // cases where that doesn't risk making a Value out of random lldb memory.
2927 // You have to check the ValueObject's Value for the address types, since
2928 // ValueObjects that use live addresses will tell you they fetch data from the
2929 // live address, but once they are made, they actually don't.
2930 // FIXME: Can we make ValueObject's with a live address fetch "more data" from
2931 // the live address if it is still valid?
2932
2933 Status error;
2934 CompilerType my_type = GetCompilerType();
2935
2936 ExecutionContextScope *exe_scope =
2938 if (llvm::expectedToOptional(compiler_type.GetByteSize(exe_scope))
2939 .value_or(0) <=
2940 llvm::expectedToOptional(GetCompilerType().GetByteSize(exe_scope))
2941 .value_or(0) ||
2942 m_value.GetValueType() == Value::ValueType::LoadAddress)
2943 return DoCast(compiler_type);
2944
2946 "Can only cast to a type that is equal to or smaller "
2947 "than the orignal type.");
2948
2950 ExecutionContext(GetExecutionContextRef()).GetBestExecutionContextScope(),
2951 std::move(error));
2952}
2953
2957
2959 CompilerType &compiler_type) {
2960 ValueObjectSP valobj_sp;
2961 addr_t ptr_value = GetPointerValue().address;
2962
2963 if (ptr_value != LLDB_INVALID_ADDRESS) {
2964 Address ptr_addr(ptr_value);
2966 valobj_sp = ValueObjectMemory::Create(
2967 exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, compiler_type);
2968 }
2969 return valobj_sp;
2970}
2971
2973 ValueObjectSP valobj_sp;
2974 addr_t ptr_value = GetPointerValue().address;
2975
2976 if (ptr_value != LLDB_INVALID_ADDRESS) {
2977 Address ptr_addr(ptr_value);
2979 valobj_sp = ValueObjectMemory::Create(
2980 exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, type_sp);
2981 }
2982 return valobj_sp;
2983}
2984
2986 if (auto target_sp = GetTargetSP()) {
2987 const bool scalar_is_load_address = true;
2988 auto [addr_value, addr_type] = GetAddressOf(scalar_is_load_address);
2989 if (addr_type == eAddressTypeFile) {
2990 lldb::ModuleSP module_sp(GetModule());
2991 if (!module_sp)
2992 addr_value = LLDB_INVALID_ADDRESS;
2993 else {
2994 Address tmp_addr;
2995 module_sp->ResolveFileAddress(addr_value, tmp_addr);
2996 addr_value = tmp_addr.GetLoadAddress(target_sp.get());
2997 }
2998 } else if (addr_type == eAddressTypeHost ||
2999 addr_type == eAddressTypeInvalid)
3000 addr_value = LLDB_INVALID_ADDRESS;
3001 return addr_value;
3002 }
3003 return LLDB_INVALID_ADDRESS;
3004}
3005
3006llvm::Expected<lldb::ValueObjectSP> ValueObject::CastDerivedToBaseType(
3007 CompilerType type, const llvm::ArrayRef<uint32_t> &base_type_indices) {
3008 // Make sure the starting type and the target type are both valid for this
3009 // type of cast; otherwise return the shared pointer to the original
3010 // (unchanged) ValueObject.
3011 if (!type.IsPointerType() && !type.IsReferenceType())
3012 return llvm::createStringError(
3013 "Invalid target type: should be a pointer or a reference");
3014
3015 CompilerType start_type = GetCompilerType();
3016 if (start_type.IsReferenceType())
3017 start_type = start_type.GetNonReferenceType();
3018
3019 auto target_record_type =
3020 type.IsPointerType() ? type.GetPointeeType() : type.GetNonReferenceType();
3021 auto start_record_type =
3022 start_type.IsPointerType() ? start_type.GetPointeeType() : start_type;
3023
3024 if (!target_record_type.IsRecordType() || !start_record_type.IsRecordType())
3025 return llvm::createStringError(
3026 "Underlying start & target types should be record types");
3027
3028 if (target_record_type.CompareTypes(start_record_type))
3029 return llvm::createStringError(
3030 "Underlying start & target types should be different");
3031
3032 if (base_type_indices.empty())
3033 return llvm::createStringError("Children sequence must be non-empty");
3034
3035 // Both the starting & target types are valid for the cast, and the list of
3036 // base class indices is non-empty, so we can proceed with the cast.
3037
3038 lldb::TargetSP target = GetTargetSP();
3039 // The `value` can be a pointer, but GetChildAtIndex works for pointers too.
3040 lldb::ValueObjectSP inner_value = GetSP();
3041
3042 for (const uint32_t i : base_type_indices)
3043 // Create synthetic value if needed.
3044 inner_value =
3045 inner_value->GetChildAtIndex(i, /*can_create_synthetic*/ true);
3046
3047 // At this point type of `inner_value` should be the dereferenced target
3048 // type.
3049 CompilerType inner_value_type = inner_value->GetCompilerType();
3050 if (type.IsPointerType()) {
3051 if (!inner_value_type.CompareTypes(type.GetPointeeType()))
3052 return llvm::createStringError(
3053 "casted value doesn't match the desired type");
3054
3055 uintptr_t addr = inner_value->GetLoadAddress();
3056 llvm::StringRef name = "";
3057 ExecutionContext exe_ctx(target.get(), false);
3058 return ValueObject::CreateValueObjectFromAddress(name, addr, exe_ctx, type,
3059 /* do deref */ false);
3060 }
3061
3062 // At this point the target type should be a reference.
3063 if (!inner_value_type.CompareTypes(type.GetNonReferenceType()))
3064 return llvm::createStringError(
3065 "casted value doesn't match the desired type");
3066
3067 return lldb::ValueObjectSP(inner_value->Cast(type.GetNonReferenceType()));
3068}
3069
3070llvm::Expected<lldb::ValueObjectSP>
3072 // Make sure the starting type and the target type are both valid for this
3073 // type of cast; otherwise return the shared pointer to the original
3074 // (unchanged) ValueObject.
3075 if (!type.IsPointerType() && !type.IsReferenceType())
3076 return llvm::createStringError(
3077 "Invalid target type: should be a pointer or a reference");
3078
3079 CompilerType start_type = GetCompilerType();
3080 if (start_type.IsReferenceType())
3081 start_type = start_type.GetNonReferenceType();
3082
3083 auto target_record_type =
3084 type.IsPointerType() ? type.GetPointeeType() : type.GetNonReferenceType();
3085 auto start_record_type =
3086 start_type.IsPointerType() ? start_type.GetPointeeType() : start_type;
3087
3088 if (!target_record_type.IsRecordType() || !start_record_type.IsRecordType())
3089 return llvm::createStringError(
3090 "Underlying start & target types should be record types");
3091
3092 if (target_record_type.CompareTypes(start_record_type))
3093 return llvm::createStringError(
3094 "Underlying start & target types should be different");
3095
3096 CompilerType virtual_base;
3097 if (target_record_type.IsVirtualBase(start_record_type, &virtual_base)) {
3098 if (!virtual_base.IsValid())
3099 return llvm::createStringError("virtual base should be valid");
3100 return llvm::createStringError(
3101 llvm::Twine("cannot cast " + start_type.TypeDescription() + " to " +
3102 type.TypeDescription() + " via virtual base " +
3103 virtual_base.TypeDescription())
3104 .str());
3105 }
3106
3107 // Both the starting & target types are valid for the cast, so we can
3108 // proceed with the cast.
3109
3110 lldb::TargetSP target = GetTargetSP();
3111 auto pointer_type =
3112 type.IsPointerType() ? type : type.GetNonReferenceType().GetPointerType();
3113
3114 uintptr_t addr =
3116
3117 llvm::StringRef name = "";
3118 ExecutionContext exe_ctx(target.get(), false);
3120 name, addr - offset, exe_ctx, pointer_type, /* do_deref */ false);
3121
3122 if (type.IsPointerType())
3123 return value;
3124
3125 // At this point the target type is a reference. Since `value` is a pointer,
3126 // it has to be dereferenced.
3127 Status error;
3128 return value->Dereference(error);
3129}
3130
3132 bool is_scalar = GetCompilerType().IsScalarType();
3133 bool is_enum = GetCompilerType().IsEnumerationType();
3134 bool is_pointer =
3136 bool is_float = HasFloatingRepresentation(GetCompilerType());
3137 bool is_integer = GetCompilerType().IsInteger();
3139
3140 if (!type.IsScalarType())
3143 Status::FromErrorString("target type must be a scalar"));
3144
3145 if (!is_scalar && !is_enum && !is_pointer)
3148 Status::FromErrorString("argument must be a scalar, enum, or pointer"));
3149
3150 lldb::TargetSP target = GetTargetSP();
3151 uint64_t type_byte_size = 0;
3152 uint64_t val_byte_size = 0;
3153 if (auto temp = llvm::expectedToOptional(type.GetByteSize(target.get())))
3154 type_byte_size = temp.value();
3155 if (auto temp =
3156 llvm::expectedToOptional(GetCompilerType().GetByteSize(target.get())))
3157 val_byte_size = temp.value();
3158
3159 if (is_pointer) {
3160 if (!type.IsInteger() && !type.IsBoolean())
3163 Status::FromErrorString("target type must be an integer or boolean"));
3164 if (!type.IsBoolean() && type_byte_size < val_byte_size)
3168 "target type cannot be smaller than the pointer type"));
3169 }
3170
3171 if (type.IsBoolean()) {
3172 if (!is_scalar || is_integer)
3174 target, GetValueAsUnsigned(0) != 0, "result");
3175 else if (is_scalar && is_float) {
3176 auto float_value_or_err = GetValueAsAPFloat();
3177 if (float_value_or_err)
3179 target, !float_value_or_err->isZero(), "result");
3180 else
3184 "cannot get value as APFloat: %s",
3185 llvm::toString(float_value_or_err.takeError()).c_str()));
3186 }
3187 }
3188
3189 if (type.IsInteger()) {
3190 if (!is_scalar || is_integer) {
3191 auto int_value_or_err = GetValueAsAPSInt();
3192 if (int_value_or_err) {
3193 // Get the value as APSInt and extend or truncate it to the requested
3194 // size.
3195 llvm::APSInt ext =
3196 int_value_or_err->extOrTrunc(type_byte_size * CHAR_BIT);
3197 return ValueObject::CreateValueObjectFromAPInt(target, ext, type,
3198 "result");
3199 } else
3203 "cannot get value as APSInt: %s",
3204 llvm::toString(int_value_or_err.takeError()).c_str()));
3205 } else if (is_scalar && is_float) {
3206 llvm::APSInt integer(type_byte_size * CHAR_BIT, !type.IsSigned());
3207 bool is_exact;
3208 auto float_value_or_err = GetValueAsAPFloat();
3209 if (float_value_or_err) {
3210 llvm::APFloatBase::opStatus status =
3211 float_value_or_err->convertToInteger(
3212 integer, llvm::APFloat::rmTowardZero, &is_exact);
3213
3214 // Casting floating point values that are out of bounds of the target
3215 // type is undefined behaviour.
3216 if (status & llvm::APFloatBase::opInvalidOp)
3220 "invalid type cast detected: %s",
3221 llvm::toString(float_value_or_err.takeError()).c_str()));
3223 "result");
3224 }
3225 }
3226 }
3227
3228 if (HasFloatingRepresentation(type)) {
3229 if (!is_scalar) {
3230 auto int_value_or_err = GetValueAsAPSInt();
3231 if (int_value_or_err) {
3232 llvm::APSInt ext =
3233 int_value_or_err->extOrTrunc(type_byte_size * CHAR_BIT);
3234 Scalar scalar_int(ext);
3235 llvm::APFloat f =
3237 return ValueObject::CreateValueObjectFromAPFloat(target, f, type,
3238 "result");
3239 } else {
3243 "cannot get value as APSInt: %s",
3244 llvm::toString(int_value_or_err.takeError()).c_str()));
3245 }
3246 } else {
3247 if (is_integer) {
3248 auto int_value_or_err = GetValueAsAPSInt();
3249 if (int_value_or_err) {
3250 Scalar scalar_int(*int_value_or_err);
3251 llvm::APFloat f = scalar_int.CreateAPFloatFromAPSInt(
3253 return ValueObject::CreateValueObjectFromAPFloat(target, f, type,
3254 "result");
3255 } else {
3259 "cannot get value as APSInt: %s",
3260 llvm::toString(int_value_or_err.takeError()).c_str()));
3261 }
3262 }
3263 if (is_float) {
3264 auto float_value_or_err = GetValueAsAPFloat();
3265 if (float_value_or_err) {
3266 Scalar scalar_float(*float_value_or_err);
3267 llvm::APFloat f = scalar_float.CreateAPFloatFromAPFloat(
3269 return ValueObject::CreateValueObjectFromAPFloat(target, f, type,
3270 "result");
3271 } else {
3275 "cannot get value as APFloat: %s",
3276 llvm::toString(float_value_or_err.takeError()).c_str()));
3277 }
3278 }
3279 }
3280 }
3281
3284 Status::FromErrorString("Unable to perform requested cast"));
3285}
3286
3288 bool is_enum = GetCompilerType().IsEnumerationType();
3289 bool is_integer = GetCompilerType().IsInteger();
3290 bool is_float = HasFloatingRepresentation(GetCompilerType());
3292
3293 if (!is_enum && !is_integer && !is_float)
3297 "argument must be an integer, a float, or an enum"));
3298
3299 if (!type.IsEnumerationType())
3302 Status::FromErrorString("target type must be an enum"));
3303
3304 lldb::TargetSP target = GetTargetSP();
3305 uint64_t byte_size = 0;
3306 if (auto temp = llvm::expectedToOptional(type.GetByteSize(target.get())))
3307 byte_size = temp.value();
3308
3309 if (is_float) {
3310 llvm::APSInt integer(byte_size * CHAR_BIT, !type.IsSigned());
3311 bool is_exact;
3312 auto value_or_err = GetValueAsAPFloat();
3313 if (value_or_err) {
3314 llvm::APFloatBase::opStatus status = value_or_err->convertToInteger(
3315 integer, llvm::APFloat::rmTowardZero, &is_exact);
3316
3317 // Casting floating point values that are out of bounds of the target
3318 // type is undefined behaviour.
3319 if (status & llvm::APFloatBase::opInvalidOp)
3323 "invalid type cast detected: %s",
3324 llvm::toString(value_or_err.takeError()).c_str()));
3326 "result");
3327 } else
3330 Status::FromErrorString("cannot get value as APFloat"));
3331 } else {
3332 // Get the value as APSInt and extend or truncate it to the requested size.
3333 auto value_or_err = GetValueAsAPSInt();
3334 if (value_or_err) {
3335 llvm::APSInt ext = value_or_err->extOrTrunc(byte_size * CHAR_BIT);
3336 return ValueObject::CreateValueObjectFromAPInt(target, ext, type,
3337 "result");
3338 } else
3342 "cannot get value as APSInt: %s",
3343 llvm::toString(value_or_err.takeError()).c_str()));
3344 }
3347 Status::FromErrorString("Cannot perform requested cast"));
3348}
3349
3351
3353 bool use_selected)
3354 : m_mod_id(), m_exe_ctx_ref() {
3355 ExecutionContext exe_ctx(exe_scope);
3356 TargetSP target_sp(exe_ctx.GetTargetSP());
3357 if (target_sp) {
3358 m_exe_ctx_ref.SetTargetSP(target_sp);
3359 ProcessSP process_sp(exe_ctx.GetProcessSP());
3360 if (!process_sp)
3361 process_sp = target_sp->GetProcessSP();
3362
3363 if (process_sp) {
3364 m_mod_id = process_sp->GetModID();
3365 m_exe_ctx_ref.SetProcessSP(process_sp);
3366
3367 ThreadSP thread_sp(exe_ctx.GetThreadSP());
3368
3369 if (!thread_sp) {
3370 if (use_selected)
3371 thread_sp = process_sp->GetThreadList().GetSelectedThread();
3372 }
3373
3374 if (thread_sp) {
3375 m_exe_ctx_ref.SetThreadSP(thread_sp);
3376
3377 StackFrameSP frame_sp(exe_ctx.GetFrameSP());
3378 if (!frame_sp) {
3379 if (use_selected)
3380 frame_sp = thread_sp->GetSelectedFrame(DoNoSelectMostRelevantFrame);
3381 }
3382 if (frame_sp)
3383 m_exe_ctx_ref.SetFrameSP(frame_sp);
3384 }
3385 }
3386 }
3387}
3388
3392
3394
3395// This function checks the EvaluationPoint against the current process state.
3396// If the current state matches the evaluation point, or the evaluation point
3397// is already invalid, then we return false, meaning "no change". If the
3398// current state is different, we update our state, and return true meaning
3399// "yes, change". If we did see a change, we also set m_needs_update to true,
3400// so future calls to NeedsUpdate will return true. exe_scope will be set to
3401// the current execution context scope.
3402
3404 bool accept_invalid_exe_ctx) {
3405 // Start with the target, if it is NULL, then we're obviously not going to
3406 // get any further:
3407 const bool thread_and_frame_only_if_stopped = true;
3408 ExecutionContext exe_ctx(
3409 m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
3410
3411 if (exe_ctx.GetTargetPtr() == nullptr)
3412 return false;
3413
3414 // If we don't have a process nothing can change.
3415 Process *process = exe_ctx.GetProcessPtr();
3416 if (process == nullptr)
3417 return false;
3418
3419 // If our stop id is the current stop ID, nothing has changed:
3420 ProcessModID current_mod_id = process->GetModID();
3421
3422 // If the current stop id is 0, either we haven't run yet, or the process
3423 // state has been cleared. In either case, we aren't going to be able to sync
3424 // with the process state.
3425 if (current_mod_id.GetStopID() == 0)
3426 return false;
3427
3428 bool changed = false;
3429 const bool was_valid = m_mod_id.IsValid();
3430 if (was_valid) {
3431 if (m_mod_id == current_mod_id) {
3432 // Everything is already up to date in this object, no need to update the
3433 // execution context scope.
3434 changed = false;
3435 } else {
3436 m_mod_id = current_mod_id;
3437 m_needs_update = true;
3438 changed = true;
3439 }
3440 }
3441
3442 // Now re-look up the thread and frame in case the underlying objects have
3443 // gone away & been recreated. That way we'll be sure to return a valid
3444 // exe_scope. If we used to have a thread or a frame but can't find it
3445 // anymore, then mark ourselves as invalid.
3446
3447 if (!accept_invalid_exe_ctx) {
3448 if (m_exe_ctx_ref.HasThreadRef()) {
3449 ThreadSP thread_sp(m_exe_ctx_ref.GetThreadSP());
3450 if (thread_sp) {
3451 if (m_exe_ctx_ref.HasFrameRef()) {
3452 StackFrameSP frame_sp(m_exe_ctx_ref.GetFrameSP());
3453 if (!frame_sp) {
3454 // We used to have a frame, but now it is gone
3455 SetInvalid();
3456 changed = was_valid;
3457 }
3458 }
3459 } else {
3460 // We used to have a thread, but now it is gone
3461 SetInvalid();
3462 changed = was_valid;
3463 }
3464 }
3465 }
3466
3467 return changed;
3468}
3469
3471 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3472 if (process_sp)
3473 m_mod_id = process_sp->GetModID();
3474 m_needs_update = false;
3475}
3476
3477void ValueObject::ClearUserVisibleData(uint32_t clear_mask) {
3478 if ((clear_mask & eClearUserVisibleDataItemsValue) ==
3480 m_value_str.clear();
3481
3482 if ((clear_mask & eClearUserVisibleDataItemsLocation) ==
3484 m_location_str.clear();
3485
3486 if ((clear_mask & eClearUserVisibleDataItemsSummary) ==
3488 m_summary_str.clear();
3489
3490 if ((clear_mask & eClearUserVisibleDataItemsDescription) ==
3492 m_object_desc_str.clear();
3493
3497 m_synthetic_value = nullptr;
3498 }
3499}
3500
3502 if (m_parent) {
3503 if (!m_parent->IsPointerOrReferenceType())
3504 return m_parent->GetSymbolContextScope();
3505 }
3506 return nullptr;
3507}
3508
3511 llvm::StringRef expression,
3512 const ExecutionContext &exe_ctx) {
3513 return CreateValueObjectFromExpression(name, expression, exe_ctx,
3515}
3516
3518 llvm::StringRef name, llvm::StringRef expression,
3519 const ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options) {
3520 lldb::ValueObjectSP retval_sp;
3521 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
3522 if (!target_sp)
3523 return retval_sp;
3524 if (expression.empty())
3525 return retval_sp;
3526 target_sp->EvaluateExpression(expression, exe_ctx.GetFrameSP().get(),
3527 retval_sp, options);
3528 if (retval_sp && !name.empty())
3529 retval_sp->SetName(ConstString(name));
3530 return retval_sp;
3531}
3532
3534 llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx,
3535 CompilerType type, bool do_deref) {
3536 if (type) {
3537 CompilerType pointer_type(type.GetPointerType());
3538 if (!do_deref)
3539 pointer_type = type;
3540 if (pointer_type) {
3541 lldb::DataBufferSP buffer(
3542 new lldb_private::DataBufferHeap(&address, sizeof(lldb::addr_t)));
3544 exe_ctx.GetBestExecutionContextScope(), pointer_type,
3545 ConstString(name), buffer, exe_ctx.GetByteOrder(),
3546 exe_ctx.GetAddressByteSize()));
3547 if (ptr_result_valobj_sp) {
3548 if (do_deref)
3549 ptr_result_valobj_sp->GetValue().SetValueType(
3551 Status err;
3552 if (do_deref)
3553 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
3554 if (ptr_result_valobj_sp && !name.empty())
3555 ptr_result_valobj_sp->SetName(ConstString(name));
3556 }
3557 return ptr_result_valobj_sp;
3558 }
3559 }
3560 return lldb::ValueObjectSP();
3561}
3562
3564 llvm::StringRef name, const DataExtractor &data,
3565 const ExecutionContext &exe_ctx, CompilerType type) {
3566 lldb::ValueObjectSP new_value_sp;
3567 new_value_sp = ValueObjectConstResult::Create(
3568 exe_ctx.GetBestExecutionContextScope(), type, ConstString(name), data,
3570 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
3571 if (new_value_sp && !name.empty())
3572 new_value_sp->SetName(ConstString(name));
3573 return new_value_sp;
3574}
3575
3578 const llvm::APInt &v, CompilerType type,
3579 llvm::StringRef name) {
3580 ExecutionContext exe_ctx(target.get(), false);
3581 uint64_t byte_size = 0;
3582 if (auto temp = llvm::expectedToOptional(type.GetByteSize(target.get())))
3583 byte_size = temp.value();
3584 lldb::DataExtractorSP data_sp = std::make_shared<DataExtractor>(
3585 reinterpret_cast<const void *>(v.getRawData()), byte_size,
3586 exe_ctx.GetByteOrder(), exe_ctx.GetAddressByteSize());
3587 return ValueObject::CreateValueObjectFromData(name, *data_sp, exe_ctx, type);
3588}
3589
3591 lldb::TargetSP target, const llvm::APFloat &v, CompilerType type,
3592 llvm::StringRef name) {
3593 return CreateValueObjectFromAPInt(target, v.bitcastToAPInt(), type, name);
3594}
3595
3597 lldb::TargetSP target, Scalar &s, CompilerType type, llvm::StringRef name) {
3598 ExecutionContext exe_ctx(target.get(), false);
3600 type, s, ConstString(name));
3601}
3602
3605 llvm::StringRef name) {
3606 CompilerType target_type;
3607 if (target) {
3608 for (auto type_system_sp : target->GetScratchTypeSystems())
3609 if (auto compiler_type =
3610 type_system_sp->GetBasicTypeFromAST(lldb::eBasicTypeBool)) {
3611 target_type = compiler_type;
3612 break;
3613 }
3614 }
3615 ExecutionContext exe_ctx(target.get(), false);
3616 uint64_t byte_size = 0;
3617 if (auto temp =
3618 llvm::expectedToOptional(target_type.GetByteSize(target.get())))
3619 byte_size = temp.value();
3620 lldb::DataExtractorSP data_sp = std::make_shared<DataExtractor>(
3621 reinterpret_cast<const void *>(&value), byte_size, exe_ctx.GetByteOrder(),
3622 exe_ctx.GetAddressByteSize());
3623 return ValueObject::CreateValueObjectFromData(name, *data_sp, exe_ctx,
3624 target_type);
3625}
3626
3628 lldb::TargetSP target, CompilerType type, llvm::StringRef name) {
3629 if (!type.IsNullPtrType()) {
3630 lldb::ValueObjectSP ret_val;
3631 return ret_val;
3632 }
3633 uintptr_t zero = 0;
3634 ExecutionContext exe_ctx(target.get(), false);
3635 uint64_t byte_size = 0;
3636 if (auto temp = llvm::expectedToOptional(type.GetByteSize(target.get())))
3637 byte_size = temp.value();
3638 lldb::DataExtractorSP data_sp = std::make_shared<DataExtractor>(
3639 reinterpret_cast<const void *>(zero), byte_size, exe_ctx.GetByteOrder(),
3640 exe_ctx.GetAddressByteSize());
3641 return ValueObject::CreateValueObjectFromData(name, *data_sp, exe_ctx, type);
3642}
3643
3645 ValueObject *root(GetRoot());
3646 if (root != this)
3647 return root->GetModule();
3648 return lldb::ModuleSP();
3649}
3650
3652 if (m_root)
3653 return m_root;
3654 return (m_root = FollowParentChain([](ValueObject *vo) -> bool {
3655 return (vo->m_parent != nullptr);
3656 }));
3657}
3658
3661 ValueObject *vo = this;
3662 while (vo) {
3663 if (!f(vo))
3664 break;
3665 vo = vo->m_parent;
3666 }
3667 return vo;
3668}
3669
3678
3680 ValueObject *with_dv_info = this;
3681 while (with_dv_info) {
3682 if (with_dv_info->HasDynamicValueTypeInfo())
3683 return with_dv_info->GetDynamicValueTypeImpl();
3684 with_dv_info = with_dv_info->m_parent;
3685 }
3687}
3688
3690 const ValueObject *with_fmt_info = this;
3691 while (with_fmt_info) {
3692 if (with_fmt_info->m_format != lldb::eFormatDefault)
3693 return with_fmt_info->m_format;
3694 with_fmt_info = with_fmt_info->m_parent;
3695 }
3696 return m_format;
3697}
3698
3702 if (GetRoot()) {
3703 if (GetRoot() == this) {
3704 if (StackFrameSP frame_sp = GetFrameSP()) {
3705 const SymbolContext &sc(
3706 frame_sp->GetSymbolContext(eSymbolContextCompUnit));
3707 if (CompileUnit *cu = sc.comp_unit)
3708 type = cu->GetLanguage();
3709 }
3710 } else {
3712 }
3713 }
3714 }
3715 return (m_preferred_display_language = type); // only compute it once
3716}
3717
3722
3724 // we need to support invalid types as providers of values because some bare-
3725 // board debugging scenarios have no notion of types, but still manage to
3726 // have raw numeric values for things like registers. sigh.
3728 return (!type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
3729}
3730
3732 if (!UpdateValueIfNeeded())
3733 return nullptr;
3734
3735 TargetSP target_sp(GetTargetSP());
3736 if (!target_sp)
3737 return nullptr;
3738
3739 PersistentExpressionState *persistent_state =
3740 target_sp->GetPersistentExpressionStateForLanguage(
3742
3743 if (!persistent_state)
3744 return nullptr;
3745
3746 ConstString name = persistent_state->GetNextPersistentVariableName();
3747
3748 ValueObjectSP const_result_sp =
3749 ValueObjectConstResult::Create(target_sp.get(), GetValue(), name);
3750
3751 ExpressionVariableSP persistent_var_sp =
3752 persistent_state->CreatePersistentVariable(const_result_sp);
3753 persistent_var_sp->m_live_sp = persistent_var_sp->m_frozen_sp;
3754 persistent_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference;
3755
3756 return persistent_var_sp->GetValueObject();
3757}
3758
3762
3764 lldb::DynamicValueType use_dynamic, bool use_synthetic,
3765 const char *name)
3766 : m_use_dynamic(use_dynamic), m_use_synthetic(use_synthetic), m_name(name) {
3767 if (in_valobj_sp) {
3768 if ((m_valobj_sp = in_valobj_sp->GetQualifiedRepresentationIfAvailable(
3769 lldb::eNoDynamicValues, false))) {
3770 if (!m_name.IsEmpty())
3771 m_valobj_sp->SetName(m_name);
3772 }
3773 }
3774}
3775
3777 if (this != &rhs) {
3781 m_name = rhs.m_name;
3782 }
3783 return *this;
3784}
3785
3787 if (m_valobj_sp.get() == nullptr)
3788 return false;
3789
3790 // FIXME: This check is necessary but not sufficient. We for sure don't
3791 // want to touch SBValues whose owning
3792 // targets have gone away. This check is a little weak in that it
3793 // enforces that restriction when you call IsValid, but since IsValid
3794 // doesn't lock the target, you have no guarantee that the SBValue won't
3795 // go invalid after you call this... Also, an SBValue could depend on
3796 // data from one of the modules in the target, and those could go away
3797 // independently of the target, for instance if a module is unloaded.
3798 // But right now, neither SBValues nor ValueObjects know which modules
3799 // they depend on. So I have no good way to make that check without
3800 // tracking that in all the ValueObject subclasses.
3801 TargetSP target_sp = m_valobj_sp->GetTargetSP();
3802 return target_sp && target_sp->IsValid();
3803}
3804
3807 std::unique_lock<std::recursive_mutex> &lock, Status &error) {
3808 if (!m_valobj_sp) {
3809 error = Status::FromErrorString("invalid value object");
3810 return m_valobj_sp;
3811 }
3812
3814
3815 Target *target = value_sp->GetTargetSP().get();
3816 // If this ValueObject holds an error, then it is valuable for that.
3817 if (value_sp->GetError().Fail())
3818 return value_sp;
3819
3820 if (!target)
3821 return ValueObjectSP();
3822
3823 lock = std::unique_lock<std::recursive_mutex>(target->GetAPIMutex());
3824
3825 ProcessSP process_sp(value_sp->GetProcessSP());
3826 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock())) {
3827 // We don't allow people to play around with ValueObject if the process
3828 // is running. If you want to look at values, pause the process, then
3829 // look.
3830 error = Status::FromErrorString("process must be stopped.");
3831 return ValueObjectSP();
3832 }
3833
3835 ValueObjectSP dynamic_sp = value_sp->GetDynamicValue(m_use_dynamic);
3836 if (dynamic_sp)
3837 value_sp = dynamic_sp;
3838 }
3839
3840 if (m_use_synthetic) {
3841 ValueObjectSP synthetic_sp = value_sp->GetSyntheticValue();
3842 if (synthetic_sp)
3843 value_sp = synthetic_sp;
3844 }
3845
3846 if (!value_sp)
3847 error = Status::FromErrorString("invalid value object");
3848 if (!m_name.IsEmpty())
3849 value_sp->SetName(m_name);
3850
3851 return value_sp;
3852}
static llvm::raw_ostream & error(Stream &strm)
#define integer
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:369
#define LLDB_LOG_ERRORV(log, error,...)
Definition Log.h:408
#define LLDB_LOGF(log,...)
Definition Log.h:376
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:392
static user_id_t g_value_obj_uid
static const char * ConvertBoolean(lldb::LanguageType language_type, const char *value_str)
static bool CopyStringDataToBufferSP(const StreamString &source, lldb::WritableDataBufferSP &destination)
static ValueObjectSP DereferenceValueOrAlternate(ValueObject &valobj, ValueObject::GetValueForExpressionPathOptions::SyntheticChildrenTraversal synth_traversal, Status &error)
static bool HasFloatingRepresentation(CompilerType ct)
static ValueObjectSP GetAlternateValue(ValueObject &valobj, ValueObject::GetValueForExpressionPathOptions::SyntheticChildrenTraversal synth_traversal)
static const char * SkipLeadingExpressionPathSeparators(const char *expression)
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:301
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
Definition Address.cpp:1035
An architecture specification class.
Definition ArchSpec.h:32
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition ArchSpec.cpp:681
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Definition ArchSpec.cpp:730
A class that describes a compilation unit.
Definition CompileUnit.h:43
Generic representation of a type in a programming language.
bool IsEnumerationType(bool &is_signed) const
lldb::BasicType GetBasicTypeEnumeration() const
bool IsPossibleDynamicType(CompilerType *target_type, bool check_cplusplus, bool check_objc) const
bool IsArrayType(CompilerType *element_type=nullptr, uint64_t *size=nullptr, bool *is_incomplete=nullptr) const
size_t GetIndexOfChildMemberWithName(llvm::StringRef name, bool omit_empty_base_classes, std::vector< uint32_t > &child_indexes) const
Lookup a child member given a name.
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
lldb::Encoding GetEncoding() const
CompilerType GetNonReferenceType() const
If this type is a reference to a type (L value or R value reference), return a new type with the refe...
ConstString GetTypeName(bool BaseOnly=false) const
bool IsReferenceType(CompilerType *pointee_type=nullptr, bool *is_rvalue=nullptr) const
bool IsInteger() const
This is used when you don't care about the signedness of the integer.
llvm::Expected< CompilerType > GetDereferencedType(ExecutionContext *exe_ctx, std::string &deref_name, uint32_t &deref_byte_size, int32_t &deref_byte_offset, ValueObject *valobj, uint64_t &language_flags) const
lldb::Format GetFormat() const
llvm::Expected< CompilerType > GetChildCompilerTypeAtIndex(ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, bool omit_empty_base_classes, bool ignore_array_bounds, std::string &child_name, uint32_t &child_byte_size, int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, bool &child_is_deref_of_parent, ValueObject *valobj, uint64_t &language_flags) const
CompilerType GetPointeeType() const
If this type is a pointer type, return the type that the pointer points to, else return an invalid ty...
bool IsUnscopedEnumerationType() const
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
llvm::Expected< uint32_t > GetIndexOfChildWithName(llvm::StringRef name, bool omit_empty_base_classes) const
Lookup a child given a name.
bool CompareTypes(CompilerType rhs) const
bool IsPointerType(CompilerType *pointee_type=nullptr) const
A uniqued constant string class.
Definition ConstString.h:40
void SetCString(const char *cstr)
Set the C string value.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
bool IsEmpty() const
Test for empty string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
void SetString(llvm::StringRef s)
const char * GetCString() const
Get the string value as a C string.
A subclass of DataBuffer that stores a data buffer on the heap.
lldb::offset_t SetByteSize(lldb::offset_t byte_size)
Set the number of bytes in the data buffer.
void CopyData(const void *src, lldb::offset_t src_len)
Makes a copy of the src_len bytes in src.
An data extractor class.
virtual const uint8_t * PeekData(lldb::offset_t offset, lldb::offset_t length) const
Peek at a bytes at offset.
virtual uint64_t GetByteSize() const
Get the number of bytes contained in this object.
void SetByteOrder(lldb::ByteOrder byte_order)
Set the byte_order value.
const uint8_t * GetDataStart() const
Get the data start pointer.
virtual lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
uint32_t GetAddressByteSize() const
Get the current address size.
lldb::ByteOrder GetByteOrder() const
Get the current byte order value.
void SetAddressByteSize(uint32_t addr_size)
Set the address byte size.
lldb::offset_t CopyByteOrderedData(lldb::offset_t src_offset, lldb::offset_t src_len, void *dst, lldb::offset_t dst_len, lldb::ByteOrder dst_byte_order) const
Copy dst_len bytes from *offset_ptr and ensure the copied data is treated as a value that can be swap...
const char * PeekCStr(lldb::offset_t offset) const
Peek at a C string at offset.
static lldb::TypeSummaryImplSP GetSummaryFormat(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
static lldb::TypeFormatImplSP GetFormat(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
static lldb::SyntheticChildrenSP GetSyntheticChildren(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
A class that describes the declaration location of a lldb object.
Definition Declaration.h:24
void Clear()
Clear the object's state.
Definition Declaration.h:57
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
virtual lldb::TargetSP CalculateTarget()=0
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
const lldb::ProcessSP & GetProcessSP() const
Get accessor to get the process shared pointer.
lldb::ByteOrder GetByteOrder() const
const lldb::StackFrameSP & GetFrameSP() const
Get accessor to get the frame shared pointer.
Target * GetTargetPtr() const
Returns a pointer to the target object.
const lldb::ThreadSP & GetThreadSP() const
Get accessor to get the thread shared pointer.
Process * GetProcessPtr() const
Returns a pointer to the process object.
@ EVIsProgramReference
This variable is a reference to a (possibly invalid) area managed by the target program.
A class to manage flags.
Definition Flags.h:22
bool AllClear(ValueType mask) const
Test if all bits in mask are clear.
Definition Flags.h:103
void Reset(ValueType flags)
Set accessor for all flags.
Definition Flags.h:52
bool Test(ValueType bit) const
Test a single flag bit.
Definition Flags.h:96
bool AnySet(ValueType mask) const
Test one or more flags.
Definition Flags.h:90
static lldb::Format GetSingleItemFormat(lldb::Format vector_format)
static Language * FindPlugin(lldb::LanguageType language)
Definition Language.cpp:84
static bool LanguageIsCFamily(lldb::LanguageType language)
Equivalent to LanguageIsC||LanguageIsObjC||LanguageIsCPlusPlus.
Definition Language.cpp:379
static bool LanguageIsObjC(lldb::LanguageType language)
Definition Language.cpp:357
virtual lldb::ExpressionVariableSP CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp)=0
virtual ConstString GetNextPersistentVariableName(bool is_error=false)=0
Return a new persistent variable name with the specified prefix.
uint32_t GetStopID() const
Definition Process.h:250
A plug-in interface definition class for debugging a process.
Definition Process.h:354
ProcessModID GetModID() const
Get the Modification ID of the process.
Definition Process.h:1451
ProcessRunLock::ProcessRunLocker StopLocker
Definition Process.h:393
bool IsPossibleDynamicValue(ValueObject &in_value)
Definition Process.cpp:1511
LanguageRuntime * GetLanguageRuntime(lldb::LanguageType language)
Definition Process.cpp:1483
size_t WriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size, Status &error)
Write memory to a process.
Definition Process.cpp:2370
size_t WriteScalarToMemory(lldb::addr_t vm_addr, const Scalar &scalar, size_t size, Status &error)
Write all or part of a scalar value to memory.
Definition Process.cpp:2451
llvm::APFloat CreateAPFloatFromAPFloat(lldb::BasicType basic_type)
Definition Scalar.cpp:850
llvm::APFloat CreateAPFloatFromAPSInt(lldb::BasicType basic_type)
Definition Scalar.cpp:830
unsigned long long ULongLong(unsigned long long fail_value=0) const
Definition Scalar.cpp:365
llvm::APFloat GetAPFloat() const
Definition Scalar.h:190
long long SLongLong(long long fail_value=0) const
Definition Scalar.cpp:361
bool ExtractBitfield(uint32_t bit_size, uint32_t bit_offset)
Definition Scalar.cpp:813
Status SetValueFromCString(const char *s, lldb::Encoding encoding, size_t byte_size)
Definition Scalar.cpp:648
bool GetData(DataExtractor &data) const
Get data with a byte size of GetByteSize().
Definition Scalar.cpp:85
bool IsValid() const
Definition Scalar.h:111
llvm::APSInt GetAPSInt() const
Definition Scalar.h:188
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:194
bool Success() const
Test for success condition.
Definition Status.cpp:303
const char * GetData() const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:65
size_t PutChar(char ch)
Definition Stream.cpp:131
Basic RAII class to increment the summary count when the call is complete.
Definition Statistics.h:256
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
Defines a symbol context baton that can be handed other debug core functions.
CompileUnit * comp_unit
The CompileUnit for a given query.
uint32_t GetMaximumSizeOfStringSummary() const
Definition Target.cpp:4978
std::recursive_mutex & GetAPIMutex()
Definition Target.cpp:5330
virtual size_t ReadMemory(const Address &addr, void *dst, size_t dst_len, Status &error, bool force_live_memory=false, lldb::addr_t *load_addr_ptr=nullptr, bool *did_read_live_memory=nullptr)
Definition Target.cpp:2004
virtual bool FormatObject(ValueObject *valobj, std::string &dest) const =0
virtual bool FormatObject(ValueObject *valobj, std::string &dest, const TypeSummaryOptions &options)=0
lldb::LanguageType GetLanguage() const
TypeSummaryOptions & SetLanguage(lldb::LanguageType)
lldb::ValueObjectSP m_valobj_sp
lldb::DynamicValueType m_use_dynamic
lldb::ValueObjectSP GetSP(Process::StopLocker &stop_locker, std::unique_lock< std::recursive_mutex > &lock, Status &error)
ValueImpl & operator=(const ValueImpl &rhs)
static lldb::ValueObjectSP Create(ValueObject &parent, ConstString name, const CompilerType &cast_type)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address=LLDB_INVALID_ADDRESS)
A ValueObject that represents memory at a given address, viewed as some set lldb type.
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, llvm::StringRef name, const Address &address, lldb::TypeSP &type_sp)
static lldb::ValueObjectSP Create(ValueObject &parent)
bool SyncWithProcessState(bool accept_invalid_exe_ctx)
AddressType m_address_type_of_ptr_or_ref_children
void SetValueIsValid(bool valid)
EvaluationPoint m_update_point
Stores both the stop id and the full context at which this value was last updated.
lldb::TypeSummaryImplSP GetSummaryFormat()
llvm::SmallVector< uint8_t, 16 > m_value_checksum
llvm::Expected< llvm::APFloat > GetValueAsAPFloat()
If the current ValueObject is of an appropriate type, convert the value to an APFloat and return that...
virtual uint32_t GetBitfieldBitSize()
void ClearUserVisibleData(uint32_t items=ValueObject::eClearUserVisibleDataItemsAllStrings)
ValueObject * FollowParentChain(std::function< bool(ValueObject *)>)
Given a ValueObject, loop over itself and its parent, and its parent's parent, .
CompilerType m_override_type
If the type of the value object should be overridden, the type to impose.
lldb::ValueObjectSP Cast(const CompilerType &compiler_type)
const EvaluationPoint & GetUpdatePoint() const
void AddSyntheticChild(ConstString key, ValueObject *valobj)
virtual uint64_t GetData(DataExtractor &data, Status &error)
friend class ValueObjectSynthetic
bool DumpPrintableRepresentation(Stream &s, ValueObjectRepresentationStyle val_obj_display=eValueObjectRepresentationStyleSummary, lldb::Format custom_format=lldb::eFormatInvalid, PrintableRepresentationSpecialCases special=PrintableRepresentationSpecialCases::eAllow, bool do_dump_error=true)
ValueObject * m_deref_valobj
virtual lldb::ValueObjectSP GetChildAtIndex(uint32_t idx, bool can_create=true)
virtual lldb::DynamicValueType GetDynamicValueTypeImpl()
static lldb::ValueObjectSP CreateValueObjectFromBool(lldb::TargetSP target, bool value, llvm::StringRef name)
Create a value object containing the given boolean value.
virtual bool GetIsConstant() const
virtual bool MightHaveChildren()
Find out if a ValueObject might have children.
static lldb::ValueObjectSP CreateValueObjectFromExpression(llvm::StringRef name, llvm::StringRef expression, const ExecutionContext &exe_ctx)
virtual bool IsDereferenceOfParent()
virtual llvm::Expected< size_t > GetIndexOfChildWithName(llvm::StringRef name)
virtual ValueObject * CreateSyntheticArrayMember(size_t idx)
Should only be called by ValueObject::GetSyntheticArrayMember().
void SetValueFormat(lldb::TypeFormatImplSP format)
virtual void CalculateSyntheticValue()
void SetPreferredDisplayLanguage(lldb::LanguageType lt)
struct lldb_private::ValueObject::Bitflags m_flags
ClusterManager< ValueObject > ValueObjectManager
ValueObject(ExecutionContextScope *exe_scope, ValueObjectManager &manager, AddressType child_ptr_or_ref_addr_type=eAddressTypeLoad)
Use this constructor to create a "root variable object".
std::string m_summary_str
Cached summary string that will get cleared if/when the value is updated.
virtual lldb::ValueObjectSP DoCast(const CompilerType &compiler_type)
lldb::ValueObjectSP GetSP()
ChildrenManager m_children
virtual lldb::ValueObjectSP CastPointerType(const char *name, CompilerType &ast_type)
Status m_error
An error object that can describe any errors that occur when updating values.
virtual size_t GetPointeeData(DataExtractor &data, uint32_t item_idx=0, uint32_t item_count=1)
lldb::ValueObjectSP GetSyntheticValue()
static lldb::ValueObjectSP CreateValueObjectFromAPFloat(lldb::TargetSP target, const llvm::APFloat &v, CompilerType type, llvm::StringRef name)
Create a value object containing the given APFloat value.
ValueObjectManager * m_manager
This object is managed by the root object (any ValueObject that gets created without a parent....
lldb::ValueObjectSP GetSyntheticBitFieldChild(uint32_t from, uint32_t to, bool can_create)
lldb::ProcessSP GetProcessSP() const
lldb::ValueObjectSP GetSyntheticChild(ConstString key) const
@ eExpressionPathScanEndReasonArrowInsteadOfDot
-> used when . should be used.
@ eExpressionPathScanEndReasonDereferencingFailed
Impossible to apply * operator.
@ eExpressionPathScanEndReasonNoSuchChild
Child element not found.
@ eExpressionPathScanEndReasonDotInsteadOfArrow
. used when -> should be used.
@ eExpressionPathScanEndReasonEndOfString
Out of data to parse.
@ eExpressionPathScanEndReasonRangeOperatorNotAllowed
[] not allowed by options.
@ eExpressionPathScanEndReasonEmptyRangeNotAllowed
[] only allowed for arrays.
@ eExpressionPathScanEndReasonRangeOperatorInvalid
[] not valid on objects other than scalars, pointers or arrays.
@ eExpressionPathScanEndReasonUnexpectedSymbol
Something is malformed in he expression.
@ eExpressionPathScanEndReasonArrayRangeOperatorMet
[] is good for arrays, but I cannot parse it.
@ eExpressionPathScanEndReasonSyntheticValueMissing
getting the synthetic children failed.
@ eExpressionPathScanEndReasonTakingAddressFailed
Impossible to apply & operator.
@ eExpressionPathScanEndReasonFragileIVarNotAllowed
ObjC ivar expansion not allowed.
virtual bool UpdateValue()=0
lldb::Format GetFormat() const
virtual lldb::VariableSP GetVariable()
@ eExpressionPathAftermathNothing
Just return it.
@ eExpressionPathAftermathDereference
Dereference the target.
@ eExpressionPathAftermathTakeAddress
Take target's address.
lldb::ValueObjectSP CastToBasicType(CompilerType type)
ValueObject * GetNonBaseClassParent()
virtual ValueObject * CreateChildAtIndex(size_t idx)
Should only be called by ValueObject::GetChildAtIndex().
lldb::ValueObjectSP GetValueForExpressionPath(llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop=nullptr, ExpressionPathEndResultType *final_value_type=nullptr, const GetValueForExpressionPathOptions &options=GetValueForExpressionPathOptions::DefaultOptions(), ExpressionPathAftermath *final_task_on_target=nullptr)
virtual lldb::ValueObjectSP GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type, bool can_create, ConstString name_const_str=ConstString())
virtual void CalculateDynamicValue(lldb::DynamicValueType use_dynamic)
DataExtractor m_data
A data extractor that can be used to extract the value.
static lldb::ValueObjectSP CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx, CompilerType type, bool do_deref=true)
Given an address either create a value object containing the value at that address,...
virtual llvm::Expected< uint64_t > GetByteSize()=0
virtual CompilerType GetCompilerTypeImpl()=0
virtual lldb::ValueObjectSP GetSyntheticBase(uint32_t offset, const CompilerType &type, bool can_create, ConstString name_const_str=ConstString())
virtual uint64_t GetValueAsUnsigned(uint64_t fail_value, bool *success=nullptr)
virtual lldb::ValueObjectSP GetChildMemberWithName(llvm::StringRef name, bool can_create=true)
lldb::ValueObjectSP CastToEnumType(CompilerType type)
llvm::Expected< uint32_t > GetNumChildren(uint32_t max=UINT32_MAX)
virtual void GetExpressionPath(Stream &s, GetExpressionPathFormat=eGetExpressionPathFormatDereferencePointers)
virtual bool HasSyntheticValue()
lldb::StackFrameSP GetFrameSP() const
lldb::ValueObjectSP GetChildAtNamePath(llvm::ArrayRef< llvm::StringRef > names)
void SetSummaryFormat(lldb::TypeSummaryImplSP format)
virtual bool IsRuntimeSupportValue()
virtual ConstString GetTypeName()
DataExtractor & GetDataExtractor()
static lldb::ValueObjectSP CreateValueObjectFromData(llvm::StringRef name, const DataExtractor &data, const ExecutionContext &exe_ctx, CompilerType type)
void SetValueDidChange(bool value_changed)
ValueObjectManager * GetManager()
ValueObject * m_root
The root of the hierarchy for this ValueObject (or nullptr if never calculated).
lldb::addr_t GetLoadAddress()
Return the target load address associated with this value object.
virtual lldb::ModuleSP GetModule()
Return the module associated with this value object in case the value is from an executable file and ...
static lldb::ValueObjectSP CreateValueObjectFromScalar(lldb::TargetSP target, Scalar &s, CompilerType type, llvm::StringRef name)
Create a value object containing the given Scalar value.
virtual lldb::ValueObjectSP GetDynamicValue(lldb::DynamicValueType valueType)
llvm::Expected< lldb::ValueObjectSP > CastDerivedToBaseType(CompilerType type, const llvm::ArrayRef< uint32_t > &base_type_indices)
Take a ValueObject whose type is an inherited class, and cast it to 'type', which should be one of it...
virtual lldb::ValueObjectSP AddressOf(Status &error)
lldb::DynamicValueType GetDynamicValueType()
llvm::Expected< lldb::ValueObjectSP > CastBaseToDerivedType(CompilerType type, uint64_t offset)
Take a ValueObject whose type is a base class, and cast it to 'type', which should be one of its deri...
lldb::LanguageType m_preferred_display_language
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr)
virtual llvm::Expected< uint32_t > CalculateNumChildren(uint32_t max=UINT32_MAX)=0
Should only be called by ValueObject::GetNumChildren().
lldb::LanguageType GetObjectRuntimeLanguage()
virtual lldb::ValueObjectSP CreateConstantValue(ConstString name)
virtual bool IsLogicalTrue(Status &error)
virtual SymbolContextScope * GetSymbolContextScope()
virtual bool HasDynamicValueTypeInfo()
static lldb::ValueObjectSP CreateValueObjectFromNullptr(lldb::TargetSP target, CompilerType type, llvm::StringRef name)
Create a nullptr value object with the specified type (must be a nullptr type).
ValueObject * m_synthetic_value
void SetNumChildren(uint32_t num_children)
ValueObject * m_parent
The parent value object, or nullptr if this has no parent.
virtual bool IsBaseClass()
llvm::Expected< bool > GetValueAsBool()
If the current ValueObject is of an appropriate type, convert the value to a boolean and return that.
virtual bool GetDeclaration(Declaration &decl)
virtual lldb::ValueObjectSP Clone(ConstString new_name)
Creates a copy of the ValueObject with a new name and setting the current ValueObject as its parent.
lldb::ValueObjectSP GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue, bool synthValue)
lldb::ValueObjectSP m_addr_of_valobj_sp
We have to hold onto a shared pointer to this one because it is created as an independent ValueObject...
std::pair< size_t, bool > ReadPointedString(lldb::WritableDataBufferSP &buffer_sp, Status &error, bool honor_array)
llvm::Error Dump(Stream &s)
bool UpdateValueIfNeeded(bool update_format=true)
static lldb::ValueObjectSP CreateValueObjectFromAPInt(lldb::TargetSP target, const llvm::APInt &v, CompilerType type, llvm::StringRef name)
Create a value object containing the given APInt value.
AddressType GetAddressTypeOfChildren()
const Status & GetError()
lldb::TypeFormatImplSP m_type_format_sp
lldb::TargetSP GetTargetSP() const
@ eExpressionPathEndResultTypePlain
Anything but...
@ eExpressionPathEndResultTypeBoundedRange
A range [low-high].
@ eExpressionPathEndResultTypeBitfield
A bitfield.
@ eExpressionPathEndResultTypeUnboundedRange
A range [].
virtual lldb::ValueObjectSP Dereference(Status &error)
CompilerType GetCompilerType()
void SetPreferredDisplayLanguageIfNeeded(lldb::LanguageType)
virtual const char * GetValueAsCString()
bool HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display, lldb::Format custom_format)
virtual const char * GetLocationAsCString()
ConstString GetName() const
std::string m_location_str
Cached location string that will get cleared if/when the value is updated.
lldb::ValueObjectSP GetVTable()
If this object represents a C++ class with a vtable, return an object that represents the virtual fun...
virtual bool SetValueFromCString(const char *value_str, Status &error)
virtual lldb::ValueObjectSP GetStaticValue()
lldb::ValueObjectSP Persist()
std::string m_object_desc_str
Cached result of the "object printer".
virtual ValueObject * GetParent()
lldb::SyntheticChildrenSP m_synthetic_children_sp
virtual uint32_t GetBitfieldBitOffset()
llvm::Expected< std::string > GetObjectDescription()
std::string m_old_value_str
Cached old value string from the last time the value was gotten.
virtual lldb::ValueObjectSP GetNonSyntheticValue()
lldb::ValueObjectSP GetSyntheticExpressionPathChild(const char *expression, bool can_create)
virtual bool SetData(DataExtractor &data, Status &error)
virtual int64_t GetValueAsSigned(int64_t fail_value, bool *success=nullptr)
void SetValueFromInteger(const llvm::APInt &value, Status &error)
Update an existing integer ValueObject with a new integer value.
const char * GetSummaryAsCString(lldb::LanguageType lang=lldb::eLanguageTypeUnknown)
std::string m_value_str
Cached value string that will get cleared if/when the value is updated.
lldb::ValueObjectSP GetSyntheticArrayMember(size_t index, bool can_create)
virtual bool ResolveValue(Scalar &scalar)
llvm::Expected< llvm::APSInt > GetValueAsAPSInt()
If the current ValueObject is of an appropriate type, convert the value to an APSInt and return that.
void SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp)
ConstString m_name
The name of this object.
const char * GetLocationAsCStringImpl(const Value &value, const DataExtractor &data)
virtual void SetFormat(lldb::Format format)
ValueObject * m_dynamic_value
bool IsCStringContainer(bool check_pointer=false)
Returns true if this is a char* or a char[] if it is a char* and check_pointer is true,...
virtual bool IsSynthetic()
std::map< ConstString, ValueObject * > m_synthetic_children
llvm::ArrayRef< uint8_t > GetLocalBuffer() const
Returns the local buffer that this ValueObject points to if it's available.
const ExecutionContextRef & GetExecutionContextRef() const
virtual AddrAndType GetAddressOf(bool scalar_is_load_address=true)
uint32_t GetNumChildrenIgnoringErrors(uint32_t max=UINT32_MAX)
Like GetNumChildren but returns 0 on error.
UserID m_id
Unique identifier for every value object.
const Value & GetValue() const
virtual lldb::LanguageType GetPreferredDisplayLanguage()
lldb::ValueObjectSP GetValueForExpressionPath_Impl(llvm::StringRef expression_cstr, ExpressionPathScanEndReason *reason_to_stop, ExpressionPathEndResultType *final_value_type, const GetValueForExpressionPathOptions &options, ExpressionPathAftermath *final_task_on_target)
const Scalar & GetScalar() const
See comment on m_scalar to understand what GetScalar returns.
Definition Value.h:113
Status GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, Module *module)
Definition Value.cpp:323
RegisterInfo * GetRegisterInfo() const
Definition Value.cpp:142
ValueType
Type that describes Value::m_value.
Definition Value.h:41
@ HostAddress
A host address value (for memory in the process that < A is using liblldb).
Definition Value.h:52
@ FileAddress
A file address value.
Definition Value.h:47
@ LoadAddress
A load address value.
Definition Value.h:49
@ Scalar
A raw scalar value.
Definition Value.h:45
ValueType GetValueType() const
Definition Value.cpp:111
Scalar & ResolveValue(ExecutionContext *exe_ctx, Module *module=nullptr)
Definition Value.cpp:589
@ RegisterInfo
RegisterInfo * (can be a scalar or a vector register).
Definition Value.h:61
ContextType GetContextType() const
Definition Value.h:87
const CompilerType & GetCompilerType()
Definition Value.cpp:247
uint8_t * GetBytes()
Get a pointer to the data.
Definition DataBuffer.h:108
static bool ReadBufferAndDumpToStream(const ReadBufferAndDumpToStreamOptions &options)
#define UINT64_MAX
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
@ DoNoSelectMostRelevantFrame
lldb::ByteOrder InlHostByteOrder()
Definition Endian.h:25
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
std::shared_ptr< SummaryStatistics > SummaryStatisticsSP
Definition Statistics.h:33
@ eAddressTypeFile
Address is an address as found in an object or symbol file.
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
@ eAddressTypeHost
Address is an address in the process that is running this code.
std::string toString(FormatterBytecode::OpCodes op)
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::TypeFormatImpl > TypeFormatImplSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::ExpressionVariable > ExpressionVariableSP
Format
Display format definitions.
@ eFormatCString
NULL terminated C strings.
@ eFormatCharArray
Print characters with no single quotes, used for character arrays that can contain non printable char...
@ eFormatVectorOfChar
@ eFormatVectorOfUInt64
@ eFormatVectorOfSInt64
@ eFormatComplex
Floating point complex type.
@ eFormatBytesWithASCII
@ eFormatOSType
OS character codes encoded into an integer 'PICT' 'text' etc...
@ eFormatVectorOfUInt128
@ eFormatVectorOfUInt8
@ eFormatComplexFloat
@ eFormatVectorOfFloat32
@ eFormatVectorOfSInt32
@ eFormatVectorOfSInt8
@ eFormatVectorOfUInt16
@ eFormatHexUppercase
@ eFormatVectorOfFloat64
@ eFormatCharPrintable
Only printable characters, '.' if not printable.
@ eFormatComplexInteger
Integer complex type.
@ eFormatVectorOfSInt16
@ eFormatFloat128
Disambiguate between 128-bit long double (which uses eFormatFloat) and __float128 (which uses eFormat...
@ eFormatVectorOfUInt32
uint64_t offset_t
Definition lldb-types.h:85
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ eLanguageTypeObjC
Objective-C.
std::shared_ptr< lldb_private::Type > TypeSP
std::shared_ptr< lldb_private::Process > ProcessSP
Encoding
Register encoding definitions.
@ eEncodingVector
vector registers
std::shared_ptr< lldb_private::SyntheticChildren > SyntheticChildrenSP
uint64_t user_id_t
Definition lldb-types.h:82
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
@ eDynamicDontRunTarget
@ eDynamicCanRunTarget
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP
Every register is described in detail including its name, alternate name (optional),...
lldb::Encoding encoding
Encoding of the register bits.
const char * alt_name
Alternate name of this register, can be NULL.
const char * name
Name of this register, can't be NULL.
lldb::Format format
Default display format.