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"
53
54#include "llvm/Support/Compiler.h"
55
56#include <algorithm>
57#include <cstdint>
58#include <cstdlib>
59#include <memory>
60#include <optional>
61#include <tuple>
62
63#include <cassert>
64#include <cinttypes>
65#include <cstdio>
66#include <cstring>
67
68namespace lldb_private {
70}
71namespace lldb_private {
73}
74
75using namespace lldb;
76using namespace lldb_private;
77
79
80// ValueObject constructor
82 : m_parent(&parent), m_update_point(parent.GetUpdatePoint()),
83 m_manager(parent.GetManager()), m_id(++g_value_obj_uid) {
89}
90
91// ValueObject constructor
93 ValueObjectManager &manager,
94 AddressType child_ptr_or_ref_addr_type)
95 : m_update_point(exe_scope), m_manager(&manager),
96 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
97 m_id(++g_value_obj_uid) {
98 if (exe_scope) {
99 TargetSP target_sp(exe_scope->CalculateTarget());
100 if (target_sp) {
101 const ArchSpec &arch = target_sp->GetArchitecture();
104 }
105 }
106 m_manager->ManageObject(this);
107}
108
109// Destructor
110ValueObject::~ValueObject() = default;
111
112bool ValueObject::UpdateValueIfNeeded(bool update_format) {
113
114 bool did_change_formats = false;
115
116 if (update_format)
117 did_change_formats = UpdateFormatsIfNeeded();
118
119 // If this is a constant value, then our success is predicated on whether we
120 // have an error or not
121 if (GetIsConstant()) {
122 // if you are constant, things might still have changed behind your back
123 // (e.g. you are a frozen object and things have changed deeper than you
124 // cared to freeze-dry yourself) in this case, your value has not changed,
125 // but "computed" entries might have, so you might now have a different
126 // summary, or a different object description. clear these so we will
127 // recompute them
128 if (update_format && !did_change_formats)
131 return m_error.Success();
132 }
133
134 bool first_update = IsChecksumEmpty();
135
136 if (NeedsUpdating()) {
138
139 // Save the old value using swap to avoid a string copy which also will
140 // clear our m_value_str
141 if (m_value_str.empty()) {
143 } else {
147 }
148
150
151 if (IsInScope()) {
152 const bool value_was_valid = GetValueIsValid();
153 SetValueDidChange(false);
154
155 m_error.Clear();
156
157 // Call the pure virtual function to update the value
158
159 bool need_compare_checksums = false;
160 llvm::SmallVector<uint8_t, 16> old_checksum;
161
162 if (!first_update && CanProvideValue()) {
163 need_compare_checksums = true;
164 old_checksum.resize(m_value_checksum.size());
165 std::copy(m_value_checksum.begin(), m_value_checksum.end(),
166 old_checksum.begin());
167 }
168
169 bool success = UpdateValue();
170
171 SetValueIsValid(success);
172
173 if (success) {
175 const uint64_t max_checksum_size = 128;
176 m_data.Checksum(m_value_checksum, max_checksum_size);
177 } else {
178 need_compare_checksums = false;
179 m_value_checksum.clear();
180 }
181
182 assert(!need_compare_checksums ||
183 (!old_checksum.empty() && !m_value_checksum.empty()));
184
185 if (first_update)
186 SetValueDidChange(false);
187 else if (!m_flags.m_value_did_change && !success) {
188 // The value wasn't gotten successfully, so we mark this as changed if
189 // the value used to be valid and now isn't
190 SetValueDidChange(value_was_valid);
191 } else if (need_compare_checksums) {
192 SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0],
193 m_value_checksum.size()));
194 }
195
196 } else {
197 m_error = Status::FromErrorString("out of scope");
198 }
199 }
200 return m_error.Success();
201}
202
205 LLDB_LOGF(log,
206 "[%s %p] checking for FormatManager revisions. ValueObject "
207 "rev: %d - Global rev: %d",
208 GetName().GetCString(), static_cast<void *>(this),
211
212 bool any_change = false;
213
216 any_change = true;
217
223 }
224
225 return any_change;
226}
227
230 // We have to clear the value string here so ConstResult children will notice
231 // if their values are changed by hand (i.e. with SetValueAsCString).
233}
234
243}
244
246 CompilerType compiler_type(GetCompilerTypeImpl());
247
250 return m_override_type;
251 else
252 return compiler_type;
253 }
254
256
257 ProcessSP process_sp(
259
260 if (!process_sp)
261 return compiler_type;
262
263 if (auto *runtime =
264 process_sp->GetLanguageRuntime(GetObjectRuntimeLanguage())) {
265 if (std::optional<CompilerType> complete_type =
266 runtime->GetRuntimeType(compiler_type)) {
267 m_override_type = *complete_type;
269 return m_override_type;
270 }
271 }
272 return compiler_type;
273}
274
276 UpdateValueIfNeeded(false);
277 return m_data;
278}
279
281 UpdateValueIfNeeded(false);
282 return m_error;
283}
284
286 const DataExtractor &data) {
287 if (UpdateValueIfNeeded(false)) {
288 if (m_location_str.empty()) {
289 StreamString sstr;
290
291 Value::ValueType value_type = value.GetValueType();
292
293 switch (value_type) {
295 m_location_str = "invalid";
296 break;
299 RegisterInfo *reg_info = value.GetRegisterInfo();
300 if (reg_info) {
301 if (reg_info->name)
302 m_location_str = reg_info->name;
303 else if (reg_info->alt_name)
304 m_location_str = reg_info->alt_name;
305 if (m_location_str.empty())
307 ? "vector"
308 : "scalar";
309 }
310 }
311 if (m_location_str.empty())
312 m_location_str = "scalar";
313 break;
314
318 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
319 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size,
321 m_location_str = std::string(sstr.GetString());
322 } break;
323 }
324 }
325 }
326 return m_location_str.c_str();
327}
328
331 false)) // make sure that you are up to date before returning anything
332 {
334 Value tmp_value(m_value);
335 scalar = tmp_value.ResolveValue(&exe_ctx, GetModule().get());
336 if (scalar.IsValid()) {
337 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
338 if (bitfield_bit_size)
339 return scalar.ExtractBitfield(bitfield_bit_size,
341 return true;
342 }
343 }
344 return false;
345}
346
349 LazyBool is_logical_true = language->IsLogicalTrue(*this, error);
350 switch (is_logical_true) {
351 case eLazyBoolYes:
352 case eLazyBoolNo:
353 return (is_logical_true == true);
355 break;
356 }
357 }
358
359 Scalar scalar_value;
360
361 if (!ResolveValue(scalar_value)) {
362 error = Status::FromErrorString("failed to get a scalar result");
363 return false;
364 }
365
366 bool ret;
367 ret = scalar_value.ULongLong(1) != 0;
368 error.Clear();
369 return ret;
370}
371
372ValueObjectSP ValueObject::GetChildAtIndex(uint32_t idx, bool can_create) {
373 ValueObjectSP child_sp;
374 // We may need to update our value if we are dynamic
376 UpdateValueIfNeeded(false);
377 if (idx < GetNumChildrenIgnoringErrors()) {
378 // Check if we have already made the child value object?
379 if (can_create && !m_children.HasChildAtIndex(idx)) {
380 // No we haven't created the child at this index, so lets have our
381 // subclass do it and cache the result for quick future access.
383 }
384
386 if (child != nullptr)
387 return child->GetSP();
388 }
389 return child_sp;
390}
391
393ValueObject::GetChildAtNamePath(llvm::ArrayRef<llvm::StringRef> names) {
394 if (names.size() == 0)
395 return GetSP();
396 ValueObjectSP root(GetSP());
397 for (llvm::StringRef name : names) {
398 root = root->GetChildMemberWithName(name);
399 if (!root) {
400 return root;
401 }
402 }
403 return root;
404}
405
406size_t ValueObject::GetIndexOfChildWithName(llvm::StringRef name) {
407 bool omit_empty_base_classes = true;
409 omit_empty_base_classes);
410}
411
413 bool can_create) {
414 // We may need to update our value if we are dynamic.
416 UpdateValueIfNeeded(false);
417
418 // When getting a child by name, it could be buried inside some base classes
419 // (which really aren't part of the expression path), so we need a vector of
420 // indexes that can get us down to the correct child.
421 std::vector<uint32_t> child_indexes;
422 bool omit_empty_base_classes = true;
423
424 if (!GetCompilerType().IsValid())
425 return ValueObjectSP();
426
427 const size_t num_child_indexes =
429 name, omit_empty_base_classes, child_indexes);
430 if (num_child_indexes == 0)
431 return nullptr;
432
433 ValueObjectSP child_sp = GetSP();
434 for (uint32_t idx : child_indexes)
435 if (child_sp)
436 child_sp = child_sp->GetChildAtIndex(idx, can_create);
437 return child_sp;
438}
439
440llvm::Expected<uint32_t> ValueObject::GetNumChildren(uint32_t max) {
442
443 if (max < UINT32_MAX) {
445 size_t children_count = m_children.GetChildrenCount();
446 return children_count <= max ? children_count : max;
447 } else
448 return CalculateNumChildren(max);
449 }
450
452 auto num_children_or_err = CalculateNumChildren();
453 if (num_children_or_err)
454 SetNumChildren(*num_children_or_err);
455 else
456 return num_children_or_err;
457 }
459}
460
462 auto value_or_err = GetNumChildren(max);
463 if (value_or_err)
464 return *value_or_err;
465 LLDB_LOG_ERRORV(GetLog(LLDBLog::DataFormatters), value_or_err.takeError(),
466 "{0}");
467 return 0;
468}
469
471 bool has_children = false;
472 const uint32_t type_info = GetTypeInfo();
473 if (type_info) {
474 if (type_info & (eTypeHasChildren | eTypeIsPointer | eTypeIsReference))
475 has_children = true;
476 } else {
477 has_children = GetNumChildrenIgnoringErrors() > 0;
478 }
479 return has_children;
480}
481
482// Should only be called by ValueObject::GetNumChildren()
483void ValueObject::SetNumChildren(uint32_t num_children) {
485 m_children.SetChildrenCount(num_children);
486}
487
489 bool omit_empty_base_classes = true;
490 bool ignore_array_bounds = false;
491 std::string child_name;
492 uint32_t child_byte_size = 0;
493 int32_t child_byte_offset = 0;
494 uint32_t child_bitfield_bit_size = 0;
495 uint32_t child_bitfield_bit_offset = 0;
496 bool child_is_base_class = false;
497 bool child_is_deref_of_parent = false;
498 uint64_t language_flags = 0;
499 const bool transparent_pointers = true;
500
502
503 auto child_compiler_type_or_err =
505 &exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
506 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
507 child_bitfield_bit_size, child_bitfield_bit_offset,
508 child_is_base_class, child_is_deref_of_parent, this, language_flags);
509 if (!child_compiler_type_or_err || !child_compiler_type_or_err->IsValid()) {
511 child_compiler_type_or_err.takeError(),
512 "could not find child: {0}");
513 return nullptr;
514 }
515
516 return new ValueObjectChild(
517 *this, *child_compiler_type_or_err, ConstString(child_name),
518 child_byte_size, child_byte_offset, child_bitfield_bit_size,
519 child_bitfield_bit_offset, child_is_base_class, child_is_deref_of_parent,
520 eAddressTypeInvalid, language_flags);
521}
522
524 bool omit_empty_base_classes = true;
525 bool ignore_array_bounds = true;
526 std::string child_name;
527 uint32_t child_byte_size = 0;
528 int32_t child_byte_offset = 0;
529 uint32_t child_bitfield_bit_size = 0;
530 uint32_t child_bitfield_bit_offset = 0;
531 bool child_is_base_class = false;
532 bool child_is_deref_of_parent = false;
533 uint64_t language_flags = 0;
534 const bool transparent_pointers = false;
535
537
538 auto child_compiler_type_or_err =
540 &exe_ctx, 0, transparent_pointers, omit_empty_base_classes,
541 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
542 child_bitfield_bit_size, child_bitfield_bit_offset,
543 child_is_base_class, child_is_deref_of_parent, this, language_flags);
544 if (!child_compiler_type_or_err) {
546 child_compiler_type_or_err.takeError(),
547 "could not find child: {0}");
548 return nullptr;
549 }
550
551 if (child_compiler_type_or_err->IsValid()) {
552 child_byte_offset += child_byte_size * idx;
553
554 return new ValueObjectChild(
555 *this, *child_compiler_type_or_err, ConstString(child_name),
556 child_byte_size, child_byte_offset, child_bitfield_bit_size,
557 child_bitfield_bit_offset, child_is_base_class,
558 child_is_deref_of_parent, eAddressTypeInvalid, language_flags);
559 }
560
561 // In case of an incomplete type, try to use the ValueObject's
562 // synthetic value to create the child ValueObject.
563 if (ValueObjectSP synth_valobj_sp = GetSyntheticValue())
564 return synth_valobj_sp->GetChildAtIndex(idx, /*can_create=*/true).get();
565
566 return nullptr;
567}
568
570 std::string &destination,
571 lldb::LanguageType lang) {
572 return GetSummaryAsCString(summary_ptr, destination,
573 TypeSummaryOptions().SetLanguage(lang));
574}
575
577 std::string &destination,
578 const TypeSummaryOptions &options) {
579 destination.clear();
580
581 // If we have a forcefully completed type, don't try and show a summary from
582 // a valid summary string or function because the type is not complete and
583 // no member variables or member functions will be available.
584 if (GetCompilerType().IsForcefullyCompleted()) {
585 destination = "<incomplete type>";
586 return true;
587 }
588
589 // ideally we would like to bail out if passing NULL, but if we do so we end
590 // up not providing the summary for function pointers anymore
591 if (/*summary_ptr == NULL ||*/ m_flags.m_is_getting_summary)
592 return false;
593
595
596 TypeSummaryOptions actual_options(options);
597
598 if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown)
600
601 // this is a hot path in code and we prefer to avoid setting this string all
602 // too often also clearing out other information that we might care to see in
603 // a crash log. might be useful in very specific situations though.
604 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s.
605 Summary provider's description is %s",
606 GetTypeName().GetCString(),
607 GetName().GetCString(),
608 summary_ptr->GetDescription().c_str());*/
609
610 if (UpdateValueIfNeeded(false) && summary_ptr) {
611 if (HasSyntheticValue())
612 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on
613 // the synthetic children being
614 // up-to-date (e.g. ${svar%#})
615
616 if (TargetSP target_sp = GetExecutionContextRef().GetTargetSP()) {
617 SummaryStatisticsSP stats_sp =
618 target_sp->GetSummaryStatisticsCache()
619 .GetSummaryStatisticsForProvider(*summary_ptr);
620
621 // Construct RAII types to time and collect data on summary creation.
622 SummaryStatistics::SummaryInvocation invocation(stats_sp);
623 summary_ptr->FormatObject(this, destination, actual_options);
624 } else
625 summary_ptr->FormatObject(this, destination, actual_options);
626 }
628 return !destination.empty();
629}
630
632 if (UpdateValueIfNeeded(true) && m_summary_str.empty()) {
633 TypeSummaryOptions summary_options;
634 summary_options.SetLanguage(lang);
636 summary_options);
637 }
638 if (m_summary_str.empty())
639 return nullptr;
640 return m_summary_str.c_str();
641}
642
643bool ValueObject::GetSummaryAsCString(std::string &destination,
644 const TypeSummaryOptions &options) {
645 return GetSummaryAsCString(GetSummaryFormat().get(), destination, options);
646}
647
648bool ValueObject::IsCStringContainer(bool check_pointer) {
649 CompilerType pointee_or_element_compiler_type;
650 const Flags type_flags(GetTypeInfo(&pointee_or_element_compiler_type));
651 bool is_char_arr_ptr(type_flags.AnySet(eTypeIsArray | eTypeIsPointer) &&
652 pointee_or_element_compiler_type.IsCharType());
653 if (!is_char_arr_ptr)
654 return false;
655 if (!check_pointer)
656 return true;
657 if (type_flags.Test(eTypeIsArray))
658 return true;
659 addr_t cstr_address = LLDB_INVALID_ADDRESS;
660 AddressType cstr_address_type = eAddressTypeInvalid;
661 cstr_address = GetPointerValue(&cstr_address_type);
662 return (cstr_address != LLDB_INVALID_ADDRESS);
663}
664
665size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx,
666 uint32_t item_count) {
667 CompilerType pointee_or_element_compiler_type;
668 const uint32_t type_info = GetTypeInfo(&pointee_or_element_compiler_type);
669 const bool is_pointer_type = type_info & eTypeIsPointer;
670 const bool is_array_type = type_info & eTypeIsArray;
671 if (!(is_pointer_type || is_array_type))
672 return 0;
673
674 if (item_count == 0)
675 return 0;
676
678
679 std::optional<uint64_t> item_type_size =
680 pointee_or_element_compiler_type.GetByteSize(
682 if (!item_type_size)
683 return 0;
684 const uint64_t bytes = item_count * *item_type_size;
685 const uint64_t offset = item_idx * *item_type_size;
686
687 if (item_idx == 0 && item_count == 1) // simply a deref
688 {
689 if (is_pointer_type) {
691 ValueObjectSP pointee_sp = Dereference(error);
692 if (error.Fail() || pointee_sp.get() == nullptr)
693 return 0;
694 return pointee_sp->GetData(data, error);
695 } else {
696 ValueObjectSP child_sp = GetChildAtIndex(0);
697 if (child_sp.get() == nullptr)
698 return 0;
700 return child_sp->GetData(data, error);
701 }
702 return true;
703 } else /* (items > 1) */
704 {
706 lldb_private::DataBufferHeap *heap_buf_ptr = nullptr;
707 lldb::DataBufferSP data_sp(heap_buf_ptr =
709
710 AddressType addr_type;
711 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type)
712 : GetAddressOf(true, &addr_type);
713
714 switch (addr_type) {
715 case eAddressTypeFile: {
716 ModuleSP module_sp(GetModule());
717 if (module_sp) {
718 addr = addr + offset;
719 Address so_addr;
720 module_sp->ResolveFileAddress(addr, so_addr);
722 Target *target = exe_ctx.GetTargetPtr();
723 if (target) {
724 heap_buf_ptr->SetByteSize(bytes);
725 size_t bytes_read = target->ReadMemory(
726 so_addr, heap_buf_ptr->GetBytes(), bytes, error, true);
727 if (error.Success()) {
728 data.SetData(data_sp);
729 return bytes_read;
730 }
731 }
732 }
733 } break;
734 case eAddressTypeLoad: {
736 Process *process = exe_ctx.GetProcessPtr();
737 if (process) {
738 heap_buf_ptr->SetByteSize(bytes);
739 size_t bytes_read = process->ReadMemory(
740 addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
741 if (error.Success() || bytes_read > 0) {
742 data.SetData(data_sp);
743 return bytes_read;
744 }
745 }
746 } break;
747 case eAddressTypeHost: {
748 auto max_bytes =
750 if (max_bytes && *max_bytes > offset) {
751 size_t bytes_read = std::min<uint64_t>(*max_bytes - offset, bytes);
753 if (addr == 0 || addr == LLDB_INVALID_ADDRESS)
754 break;
755 heap_buf_ptr->CopyData((uint8_t *)(addr + offset), bytes_read);
756 data.SetData(data_sp);
757 return bytes_read;
758 }
759 } break;
761 break;
762 }
763 }
764 return 0;
765}
766
768 UpdateValueIfNeeded(false);
770 error = m_value.GetValueAsData(&exe_ctx, data, GetModule().get());
771 if (error.Fail()) {
772 if (m_data.GetByteSize()) {
773 data = m_data;
774 error.Clear();
775 return data.GetByteSize();
776 } else {
777 return 0;
778 }
779 }
782 return data.GetByteSize();
783}
784
786 error.Clear();
787 // Make sure our value is up to date first so that our location and location
788 // type is valid.
789 if (!UpdateValueIfNeeded(false)) {
790 error = Status::FromErrorString("unable to read value");
791 return false;
792 }
793
794 uint64_t count = 0;
795 const Encoding encoding = GetCompilerType().GetEncoding(count);
796
797 const size_t byte_size = GetByteSize().value_or(0);
798
800
801 switch (value_type) {
803 error = Status::FromErrorString("invalid location");
804 return false;
806 Status set_error =
807 m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
808
809 if (!set_error.Success()) {
811 "unable to set scalar value: %s", set_error.AsCString());
812 return false;
813 }
814 } break;
816 // If it is a load address, then the scalar value is the storage location
817 // of the data, and we have to shove this value down to that load location.
819 Process *process = exe_ctx.GetProcessPtr();
820 if (process) {
822 size_t bytes_written = process->WriteMemory(
823 target_addr, data.GetDataStart(), byte_size, error);
824 if (!error.Success())
825 return false;
826 if (bytes_written != byte_size) {
827 error = Status::FromErrorString("unable to write value to memory");
828 return false;
829 }
830 }
831 } break;
833 // If it is a host address, then we stuff the scalar as a DataBuffer into
834 // the Value's data.
835 DataBufferSP buffer_sp(new DataBufferHeap(byte_size, 0));
836 m_data.SetData(buffer_sp, 0);
837 data.CopyByteOrderedData(0, byte_size,
838 const_cast<uint8_t *>(m_data.GetDataStart()),
839 byte_size, m_data.GetByteOrder());
840 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
841 } break;
843 break;
844 }
845
846 // If we have reached this point, then we have successfully changed the
847 // value.
849 return true;
850}
851
852static bool CopyStringDataToBufferSP(const StreamString &source,
853 lldb::WritableDataBufferSP &destination) {
854 llvm::StringRef src = source.GetString();
855 src = src.rtrim('\0');
856 destination = std::make_shared<DataBufferHeap>(src.size(), 0);
857 memcpy(destination->GetBytes(), src.data(), src.size());
858 return true;
859}
860
861std::pair<size_t, bool>
863 Status &error, bool honor_array) {
864 bool was_capped = false;
865 StreamString s;
867 Target *target = exe_ctx.GetTargetPtr();
868
869 if (!target) {
870 s << "<no target to read from>";
871 error = Status::FromErrorString("no target to read from");
872 CopyStringDataToBufferSP(s, buffer_sp);
873 return {0, was_capped};
874 }
875
876 const auto max_length = target->GetMaximumSizeOfStringSummary();
877
878 size_t bytes_read = 0;
879 size_t total_bytes_read = 0;
880
881 CompilerType compiler_type = GetCompilerType();
882 CompilerType elem_or_pointee_compiler_type;
883 const Flags type_flags(GetTypeInfo(&elem_or_pointee_compiler_type));
884 if (type_flags.AnySet(eTypeIsArray | eTypeIsPointer) &&
885 elem_or_pointee_compiler_type.IsCharType()) {
886 addr_t cstr_address = LLDB_INVALID_ADDRESS;
887 AddressType cstr_address_type = eAddressTypeInvalid;
888
889 size_t cstr_len = 0;
890 bool capped_data = false;
891 const bool is_array = type_flags.Test(eTypeIsArray);
892 if (is_array) {
893 // We have an array
894 uint64_t array_size = 0;
895 if (compiler_type.IsArrayType(nullptr, &array_size)) {
896 cstr_len = array_size;
897 if (cstr_len > max_length) {
898 capped_data = true;
899 cstr_len = max_length;
900 }
901 }
902 cstr_address = GetAddressOf(true, &cstr_address_type);
903 } else {
904 // We have a pointer
905 cstr_address = GetPointerValue(&cstr_address_type);
906 }
907
908 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS) {
909 if (cstr_address_type == eAddressTypeHost && is_array) {
910 const char *cstr = GetDataExtractor().PeekCStr(0);
911 if (cstr == nullptr) {
912 s << "<invalid address>";
913 error = Status::FromErrorString("invalid address");
914 CopyStringDataToBufferSP(s, buffer_sp);
915 return {0, was_capped};
916 }
917 s << llvm::StringRef(cstr, cstr_len);
918 CopyStringDataToBufferSP(s, buffer_sp);
919 return {cstr_len, was_capped};
920 } else {
921 s << "<invalid address>";
922 error = Status::FromErrorString("invalid address");
923 CopyStringDataToBufferSP(s, buffer_sp);
924 return {0, was_capped};
925 }
926 }
927
928 Address cstr_so_addr(cstr_address);
929 DataExtractor data;
930 if (cstr_len > 0 && honor_array) {
931 // I am using GetPointeeData() here to abstract the fact that some
932 // ValueObjects are actually frozen pointers in the host but the pointed-
933 // to data lives in the debuggee, and GetPointeeData() automatically
934 // takes care of this
935 GetPointeeData(data, 0, cstr_len);
936
937 if ((bytes_read = data.GetByteSize()) > 0) {
938 total_bytes_read = bytes_read;
939 for (size_t offset = 0; offset < bytes_read; offset++)
940 s.Printf("%c", *data.PeekData(offset, 1));
941 if (capped_data)
942 was_capped = true;
943 }
944 } else {
945 cstr_len = max_length;
946 const size_t k_max_buf_size = 64;
947
948 size_t offset = 0;
949
950 int cstr_len_displayed = -1;
951 bool capped_cstr = false;
952 // I am using GetPointeeData() here to abstract the fact that some
953 // ValueObjects are actually frozen pointers in the host but the pointed-
954 // to data lives in the debuggee, and GetPointeeData() automatically
955 // takes care of this
956 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0) {
957 total_bytes_read += bytes_read;
958 const char *cstr = data.PeekCStr(0);
959 size_t len = strnlen(cstr, k_max_buf_size);
960 if (cstr_len_displayed < 0)
961 cstr_len_displayed = len;
962
963 if (len == 0)
964 break;
965 cstr_len_displayed += len;
966 if (len > bytes_read)
967 len = bytes_read;
968 if (len > cstr_len)
969 len = cstr_len;
970
971 for (size_t offset = 0; offset < bytes_read; offset++)
972 s.Printf("%c", *data.PeekData(offset, 1));
973
974 if (len < k_max_buf_size)
975 break;
976
977 if (len >= cstr_len) {
978 capped_cstr = true;
979 break;
980 }
981
982 cstr_len -= len;
983 offset += len;
984 }
985
986 if (cstr_len_displayed >= 0) {
987 if (capped_cstr)
988 was_capped = true;
989 }
990 }
991 } else {
992 error = Status::FromErrorString("not a string object");
993 s << "<not a string object>";
994 }
995 CopyStringDataToBufferSP(s, buffer_sp);
996 return {total_bytes_read, was_capped};
997}
998
999llvm::Expected<std::string> ValueObject::GetObjectDescription() {
1000 if (!UpdateValueIfNeeded(true))
1001 return llvm::createStringError("could not update value");
1002
1003 // Return cached value.
1004 if (!m_object_desc_str.empty())
1005 return m_object_desc_str;
1006
1008 Process *process = exe_ctx.GetProcessPtr();
1009 if (!process)
1010 return llvm::createStringError("no process");
1011
1012 // Returns the object description produced by one language runtime.
1013 auto get_object_description =
1014 [&](LanguageType language) -> llvm::Expected<std::string> {
1015 if (LanguageRuntime *runtime = process->GetLanguageRuntime(language)) {
1016 StreamString s;
1017 if (llvm::Error error = runtime->GetObjectDescription(s, *this))
1018 return error;
1020 return m_object_desc_str;
1021 }
1022 return llvm::createStringError("no native language runtime");
1023 };
1024
1025 // Try the native language runtime first.
1026 LanguageType native_language = GetObjectRuntimeLanguage();
1027 llvm::Expected<std::string> desc = get_object_description(native_language);
1028 if (desc)
1029 return desc;
1030
1031 // Try the Objective-C language runtime. This fallback is necessary
1032 // for Objective-C++ and mixed Objective-C / C++ programs.
1033 if (Language::LanguageIsCFamily(native_language)) {
1034 // We're going to try again, so let's drop the first error.
1035 llvm::consumeError(desc.takeError());
1036 return get_object_description(eLanguageTypeObjC);
1037 }
1038 return desc;
1039}
1040
1042 std::string &destination) {
1043 if (UpdateValueIfNeeded(false))
1044 return format.FormatObject(this, destination);
1045 else
1046 return false;
1047}
1048
1050 std::string &destination) {
1051 return GetValueAsCString(TypeFormatImpl_Format(format), destination);
1052}
1053
1055 if (UpdateValueIfNeeded(true)) {
1056 lldb::TypeFormatImplSP format_sp;
1057 lldb::Format my_format = GetFormat();
1058 if (my_format == lldb::eFormatDefault) {
1059 if (m_type_format_sp)
1060 format_sp = m_type_format_sp;
1061 else {
1063 my_format = eFormatUnsigned;
1064 else {
1066 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1067 if (reg_info)
1068 my_format = reg_info->format;
1069 } else {
1070 my_format = GetValue().GetCompilerType().GetFormat();
1071 }
1072 }
1073 }
1074 }
1075 if (my_format != m_last_format || m_value_str.empty()) {
1076 m_last_format = my_format;
1077 if (!format_sp)
1078 format_sp = std::make_shared<TypeFormatImpl_Format>(my_format);
1079 if (GetValueAsCString(*format_sp.get(), m_value_str)) {
1081 // The value was gotten successfully, so we consider the value as
1082 // changed if the value string differs
1084 }
1085 }
1086 }
1087 }
1088 if (m_value_str.empty())
1089 return nullptr;
1090 return m_value_str.c_str();
1091}
1092
1093// if > 8bytes, 0 is returned. this method should mostly be used to read
1094// address values out of pointers
1095uint64_t ValueObject::GetValueAsUnsigned(uint64_t fail_value, bool *success) {
1096 // If our byte size is zero this is an aggregate type that has children
1097 if (CanProvideValue()) {
1098 Scalar scalar;
1099 if (ResolveValue(scalar)) {
1100 if (success)
1101 *success = true;
1102 scalar.MakeUnsigned();
1103 return scalar.ULongLong(fail_value);
1104 }
1105 // fallthrough, otherwise...
1106 }
1107
1108 if (success)
1109 *success = false;
1110 return fail_value;
1111}
1112
1113int64_t ValueObject::GetValueAsSigned(int64_t fail_value, bool *success) {
1114 // If our byte size is zero this is an aggregate type that has children
1115 if (CanProvideValue()) {
1116 Scalar scalar;
1117 if (ResolveValue(scalar)) {
1118 if (success)
1119 *success = true;
1120 scalar.MakeSigned();
1121 return scalar.SLongLong(fail_value);
1122 }
1123 // fallthrough, otherwise...
1124 }
1125
1126 if (success)
1127 *success = false;
1128 return fail_value;
1129}
1130
1131llvm::Expected<llvm::APSInt> ValueObject::GetValueAsAPSInt() {
1132 // Make sure the type can be converted to an APSInt.
1133 if (!GetCompilerType().IsInteger() &&
1134 !GetCompilerType().IsScopedEnumerationType() &&
1135 !GetCompilerType().IsEnumerationType() &&
1137 !GetCompilerType().IsNullPtrType() &&
1138 !GetCompilerType().IsReferenceType() && !GetCompilerType().IsBoolean())
1139 return llvm::make_error<llvm::StringError>(
1140 "type cannot be converted to APSInt", llvm::inconvertibleErrorCode());
1141
1142 if (CanProvideValue()) {
1143 Scalar scalar;
1144 if (ResolveValue(scalar))
1145 return scalar.GetAPSInt();
1146 }
1147
1148 return llvm::make_error<llvm::StringError>(
1149 "error occurred; unable to convert to APSInt",
1150 llvm::inconvertibleErrorCode());
1151}
1152
1153llvm::Expected<llvm::APFloat> ValueObject::GetValueAsAPFloat() {
1154 if (!GetCompilerType().IsFloat())
1155 return llvm::make_error<llvm::StringError>(
1156 "type cannot be converted to APFloat", llvm::inconvertibleErrorCode());
1157
1158 if (CanProvideValue()) {
1159 Scalar scalar;
1160 if (ResolveValue(scalar))
1161 return scalar.GetAPFloat();
1162 }
1163
1164 return llvm::make_error<llvm::StringError>(
1165 "error occurred; unable to convert to APFloat",
1166 llvm::inconvertibleErrorCode());
1167}
1168
1169llvm::Expected<bool> ValueObject::GetValueAsBool() {
1170 CompilerType val_type = GetCompilerType();
1171 if (val_type.IsInteger() || val_type.IsUnscopedEnumerationType() ||
1172 val_type.IsPointerType()) {
1173 auto value_or_err = GetValueAsAPSInt();
1174 if (value_or_err)
1175 return value_or_err->getBoolValue();
1176 }
1177 if (val_type.IsFloat()) {
1178 auto value_or_err = GetValueAsAPFloat();
1179 if (value_or_err)
1180 return value_or_err->isNonZero();
1181 }
1182 if (val_type.IsArrayType())
1183 return GetAddressOf() != 0;
1184
1185 return llvm::make_error<llvm::StringError>("type cannot be converted to bool",
1186 llvm::inconvertibleErrorCode());
1187}
1188
1189void ValueObject::SetValueFromInteger(const llvm::APInt &value, Status &error) {
1190 // Verify the current object is an integer object
1191 CompilerType val_type = GetCompilerType();
1192 if (!val_type.IsInteger() && !val_type.IsUnscopedEnumerationType() &&
1193 !val_type.IsFloat() && !val_type.IsPointerType() &&
1194 !val_type.IsScalarType()) {
1195 error =
1196 Status::FromErrorString("current value object is not an integer objet");
1197 return;
1198 }
1199
1200 // Verify the current object is not actually associated with any program
1201 // variable.
1202 if (GetVariable()) {
1204 "current value object is not a temporary object");
1205 return;
1206 }
1207
1208 // Verify the proposed new value is the right size.
1209 lldb::TargetSP target = GetTargetSP();
1210 uint64_t byte_size = 0;
1211 if (auto temp = GetCompilerType().GetByteSize(target.get()))
1212 byte_size = temp.value();
1213 if (value.getBitWidth() != byte_size * CHAR_BIT) {
1215 "illegal argument: new value should be of the same size");
1216 return;
1217 }
1218
1219 lldb::DataExtractorSP data_sp;
1220 data_sp->SetData(value.getRawData(), byte_size,
1221 target->GetArchitecture().GetByteOrder());
1222 data_sp->SetAddressByteSize(
1223 static_cast<uint8_t>(target->GetArchitecture().GetAddressByteSize()));
1224 SetData(*data_sp, error);
1225}
1226
1228 Status &error) {
1229 // Verify the current object is an integer object
1230 CompilerType val_type = GetCompilerType();
1231 if (!val_type.IsInteger() && !val_type.IsUnscopedEnumerationType() &&
1232 !val_type.IsFloat() && !val_type.IsPointerType() &&
1233 !val_type.IsScalarType()) {
1234 error =
1235 Status::FromErrorString("current value object is not an integer objet");
1236 return;
1237 }
1238
1239 // Verify the current object is not actually associated with any program
1240 // variable.
1241 if (GetVariable()) {
1243 "current value object is not a temporary object");
1244 return;
1245 }
1246
1247 // Verify the proposed new value is the right type.
1248 CompilerType new_val_type = new_val_sp->GetCompilerType();
1249 if (!new_val_type.IsInteger() && !new_val_type.IsFloat() &&
1250 !new_val_type.IsPointerType()) {
1252 "illegal argument: new value should be of the same size");
1253 return;
1254 }
1255
1256 if (new_val_type.IsInteger()) {
1257 auto value_or_err = new_val_sp->GetValueAsAPSInt();
1258 if (value_or_err)
1259 SetValueFromInteger(*value_or_err, error);
1260 else
1261 error = Status::FromErrorString("error getting APSInt from new_val_sp");
1262 } else if (new_val_type.IsFloat()) {
1263 auto value_or_err = new_val_sp->GetValueAsAPFloat();
1264 if (value_or_err)
1265 SetValueFromInteger(value_or_err->bitcastToAPInt(), error);
1266 else
1267 error = Status::FromErrorString("error getting APFloat from new_val_sp");
1268 } else if (new_val_type.IsPointerType()) {
1269 bool success = true;
1270 uint64_t int_val = new_val_sp->GetValueAsUnsigned(0, &success);
1271 if (success) {
1272 lldb::TargetSP target = GetTargetSP();
1273 uint64_t num_bits = 0;
1274 if (auto temp = new_val_sp->GetCompilerType().GetBitSize(target.get()))
1275 num_bits = temp.value();
1276 SetValueFromInteger(llvm::APInt(num_bits, int_val), error);
1277 } else
1278 error = Status::FromErrorString("error converting new_val_sp to integer");
1279 }
1280}
1281
1282// if any more "special cases" are added to
1283// ValueObject::DumpPrintableRepresentation() please keep this call up to date
1284// by returning true for your new special cases. We will eventually move to
1285// checking this call result before trying to display special cases
1287 ValueObjectRepresentationStyle val_obj_display, Format custom_format) {
1288 Flags flags(GetTypeInfo());
1289 if (flags.AnySet(eTypeIsArray | eTypeIsPointer) &&
1291 if (IsCStringContainer(true) &&
1292 (custom_format == eFormatCString || custom_format == eFormatCharArray ||
1293 custom_format == eFormatChar || custom_format == eFormatVectorOfChar))
1294 return true;
1295
1296 if (flags.Test(eTypeIsArray)) {
1297 if ((custom_format == eFormatBytes) ||
1298 (custom_format == eFormatBytesWithASCII))
1299 return true;
1300
1301 if ((custom_format == eFormatVectorOfChar) ||
1302 (custom_format == eFormatVectorOfFloat32) ||
1303 (custom_format == eFormatVectorOfFloat64) ||
1304 (custom_format == eFormatVectorOfSInt16) ||
1305 (custom_format == eFormatVectorOfSInt32) ||
1306 (custom_format == eFormatVectorOfSInt64) ||
1307 (custom_format == eFormatVectorOfSInt8) ||
1308 (custom_format == eFormatVectorOfUInt128) ||
1309 (custom_format == eFormatVectorOfUInt16) ||
1310 (custom_format == eFormatVectorOfUInt32) ||
1311 (custom_format == eFormatVectorOfUInt64) ||
1312 (custom_format == eFormatVectorOfUInt8))
1313 return true;
1314 }
1315 }
1316 return false;
1317}
1318
1320 Stream &s, ValueObjectRepresentationStyle val_obj_display,
1321 Format custom_format, PrintableRepresentationSpecialCases special,
1322 bool do_dump_error) {
1323
1324 // If the ValueObject has an error, we might end up dumping the type, which
1325 // is useful, but if we don't even have a type, then don't examine the object
1326 // further as that's not meaningful, only the error is.
1327 if (m_error.Fail() && !GetCompilerType().IsValid()) {
1328 if (do_dump_error)
1329 s.Printf("<%s>", m_error.AsCString());
1330 return false;
1331 }
1332
1333 Flags flags(GetTypeInfo());
1334
1335 bool allow_special =
1337 const bool only_special = false;
1338
1339 if (allow_special) {
1340 if (flags.AnySet(eTypeIsArray | eTypeIsPointer) &&
1342 // when being asked to get a printable display an array or pointer type
1343 // directly, try to "do the right thing"
1344
1345 if (IsCStringContainer(true) &&
1346 (custom_format == eFormatCString ||
1347 custom_format == eFormatCharArray || custom_format == eFormatChar ||
1348 custom_format ==
1349 eFormatVectorOfChar)) // print char[] & char* directly
1350 {
1351 Status error;
1353 std::pair<size_t, bool> read_string =
1354 ReadPointedString(buffer_sp, error,
1355 (custom_format == eFormatVectorOfChar) ||
1356 (custom_format == eFormatCharArray));
1357 lldb_private::formatters::StringPrinter::
1358 ReadBufferAndDumpToStreamOptions options(*this);
1359 options.SetData(DataExtractor(
1360 buffer_sp, lldb::eByteOrderInvalid,
1361 8)); // none of this matters for a string - pass some defaults
1362 options.SetStream(&s);
1363 options.SetPrefixToken(nullptr);
1364 options.SetQuote('"');
1365 options.SetSourceSize(buffer_sp->GetByteSize());
1366 options.SetIsTruncated(read_string.second);
1367 options.SetBinaryZeroIsTerminator(custom_format != eFormatVectorOfChar);
1369 lldb_private::formatters::StringPrinter::StringElementType::ASCII>(
1370 options);
1371 return !error.Fail();
1372 }
1373
1374 if (custom_format == eFormatEnum)
1375 return false;
1376
1377 // this only works for arrays, because I have no way to know when the
1378 // pointed memory ends, and no special \0 end of data marker
1379 if (flags.Test(eTypeIsArray)) {
1380 if ((custom_format == eFormatBytes) ||
1381 (custom_format == eFormatBytesWithASCII)) {
1382 const size_t count = GetNumChildrenIgnoringErrors();
1383
1384 s << '[';
1385 for (size_t low = 0; low < count; low++) {
1386
1387 if (low)
1388 s << ',';
1389
1390 ValueObjectSP child = GetChildAtIndex(low);
1391 if (!child.get()) {
1392 s << "<invalid child>";
1393 continue;
1394 }
1395 child->DumpPrintableRepresentation(
1397 custom_format);
1398 }
1399
1400 s << ']';
1401
1402 return true;
1403 }
1404
1405 if ((custom_format == eFormatVectorOfChar) ||
1406 (custom_format == eFormatVectorOfFloat32) ||
1407 (custom_format == eFormatVectorOfFloat64) ||
1408 (custom_format == eFormatVectorOfSInt16) ||
1409 (custom_format == eFormatVectorOfSInt32) ||
1410 (custom_format == eFormatVectorOfSInt64) ||
1411 (custom_format == eFormatVectorOfSInt8) ||
1412 (custom_format == eFormatVectorOfUInt128) ||
1413 (custom_format == eFormatVectorOfUInt16) ||
1414 (custom_format == eFormatVectorOfUInt32) ||
1415 (custom_format == eFormatVectorOfUInt64) ||
1416 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes
1417 // with ASCII or any vector
1418 // format should be printed
1419 // directly
1420 {
1421 const size_t count = GetNumChildrenIgnoringErrors();
1422
1423 Format format = FormatManager::GetSingleItemFormat(custom_format);
1424
1425 s << '[';
1426 for (size_t low = 0; low < count; low++) {
1427
1428 if (low)
1429 s << ',';
1430
1431 ValueObjectSP child = GetChildAtIndex(low);
1432 if (!child.get()) {
1433 s << "<invalid child>";
1434 continue;
1435 }
1436 child->DumpPrintableRepresentation(
1438 }
1439
1440 s << ']';
1441
1442 return true;
1443 }
1444 }
1445
1446 if ((custom_format == eFormatBoolean) ||
1447 (custom_format == eFormatBinary) || (custom_format == eFormatChar) ||
1448 (custom_format == eFormatCharPrintable) ||
1449 (custom_format == eFormatComplexFloat) ||
1450 (custom_format == eFormatDecimal) || (custom_format == eFormatHex) ||
1451 (custom_format == eFormatHexUppercase) ||
1452 (custom_format == eFormatFloat) || (custom_format == eFormatOctal) ||
1453 (custom_format == eFormatOSType) ||
1454 (custom_format == eFormatUnicode16) ||
1455 (custom_format == eFormatUnicode32) ||
1456 (custom_format == eFormatUnsigned) ||
1457 (custom_format == eFormatPointer) ||
1458 (custom_format == eFormatComplexInteger) ||
1459 (custom_format == eFormatComplex) ||
1460 (custom_format == eFormatDefault)) // use the [] operator
1461 return false;
1462 }
1463 }
1464
1465 if (only_special)
1466 return false;
1467
1468 bool var_success = false;
1469
1470 {
1471 llvm::StringRef str;
1472
1473 // this is a local stream that we are using to ensure that the data pointed
1474 // to by cstr survives long enough for us to copy it to its destination -
1475 // it is necessary to have this temporary storage area for cases where our
1476 // desired output is not backed by some other longer-term storage
1477 StreamString strm;
1478
1479 if (custom_format != eFormatInvalid)
1480 SetFormat(custom_format);
1481
1482 switch (val_obj_display) {
1484 str = GetValueAsCString();
1485 break;
1486
1488 str = GetSummaryAsCString();
1489 break;
1490
1492 llvm::Expected<std::string> desc = GetObjectDescription();
1493 if (!desc) {
1494 strm << "error: " << toString(desc.takeError());
1495 str = strm.GetString();
1496 } else {
1497 strm << *desc;
1498 str = strm.GetString();
1499 }
1500 } break;
1501
1503 str = GetLocationAsCString();
1504 break;
1505
1507 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildrenIgnoringErrors());
1508 str = strm.GetString();
1509 break;
1510
1512 str = GetTypeName().GetStringRef();
1513 break;
1514
1516 str = GetName().GetStringRef();
1517 break;
1518
1520 GetExpressionPath(strm);
1521 str = strm.GetString();
1522 break;
1523 }
1524
1525 // If the requested display style produced no output, try falling back to
1526 // alternative presentations.
1527 if (str.empty()) {
1528 if (val_obj_display == eValueObjectRepresentationStyleValue)
1529 str = GetSummaryAsCString();
1530 else if (val_obj_display == eValueObjectRepresentationStyleSummary) {
1531 if (!CanProvideValue()) {
1532 strm.Printf("%s @ %s", GetTypeName().AsCString(),
1534 str = strm.GetString();
1535 } else
1536 str = GetValueAsCString();
1537 }
1538 }
1539
1540 if (!str.empty())
1541 s << str;
1542 else {
1543 // We checked for errors at the start, but do it again here in case
1544 // realizing the value for dumping produced an error.
1545 if (m_error.Fail()) {
1546 if (do_dump_error)
1547 s.Printf("<%s>", m_error.AsCString());
1548 else
1549 return false;
1550 } else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1551 s.PutCString("<no summary available>");
1552 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1553 s.PutCString("<no value available>");
1554 else if (val_obj_display ==
1556 s.PutCString("<not a valid Objective-C object>"); // edit this if we
1557 // have other runtimes
1558 // that support a
1559 // description
1560 else
1561 s.PutCString("<no printable representation>");
1562 }
1563
1564 // we should only return false here if we could not do *anything* even if
1565 // we have an error message as output, that's a success from our callers'
1566 // perspective, so return true
1567 var_success = true;
1568
1569 if (custom_format != eFormatInvalid)
1571 }
1572
1573 return var_success;
1574}
1575
1576addr_t ValueObject::GetAddressOf(bool scalar_is_load_address,
1577 AddressType *address_type) {
1578 // Can't take address of a bitfield
1579 if (IsBitfield())
1580 return LLDB_INVALID_ADDRESS;
1581
1582 if (!UpdateValueIfNeeded(false))
1583 return LLDB_INVALID_ADDRESS;
1584
1585 switch (m_value.GetValueType()) {
1587 return LLDB_INVALID_ADDRESS;
1589 if (scalar_is_load_address) {
1590 if (address_type)
1591 *address_type = eAddressTypeLoad;
1593 }
1594 break;
1595
1598 if (address_type)
1599 *address_type = m_value.GetValueAddressType();
1601 } break;
1603 if (address_type)
1604 *address_type = m_value.GetValueAddressType();
1605 return LLDB_INVALID_ADDRESS;
1606 } break;
1607 }
1608 if (address_type)
1609 *address_type = eAddressTypeInvalid;
1610 return LLDB_INVALID_ADDRESS;
1611}
1612
1614 addr_t address = LLDB_INVALID_ADDRESS;
1615 if (address_type)
1616 *address_type = eAddressTypeInvalid;
1617
1618 if (!UpdateValueIfNeeded(false))
1619 return address;
1620
1621 switch (m_value.GetValueType()) {
1623 return LLDB_INVALID_ADDRESS;
1626 break;
1627
1631 lldb::offset_t data_offset = 0;
1632 address = m_data.GetAddress(&data_offset);
1633 } break;
1634 }
1635
1636 if (address_type)
1637 *address_type = GetAddressTypeOfChildren();
1638
1639 return address;
1640}
1641
1642static const char *ConvertBoolean(lldb::LanguageType language_type,
1643 const char *value_str) {
1644 if (Language *language = Language::FindPlugin(language_type))
1645 if (auto boolean = language->GetBooleanFromString(value_str))
1646 return *boolean ? "1" : "0";
1647
1648 return llvm::StringSwitch<const char *>(value_str)
1649 .Case("true", "1")
1650 .Case("false", "0")
1651 .Default(value_str);
1652}
1653
1654bool ValueObject::SetValueFromCString(const char *value_str, Status &error) {
1655 error.Clear();
1656 // Make sure our value is up to date first so that our location and location
1657 // type is valid.
1658 if (!UpdateValueIfNeeded(false)) {
1659 error = Status::FromErrorString("unable to read value");
1660 return false;
1661 }
1662
1663 uint64_t count = 0;
1664 const Encoding encoding = GetCompilerType().GetEncoding(count);
1665
1666 const size_t byte_size = GetByteSize().value_or(0);
1667
1668 Value::ValueType value_type = m_value.GetValueType();
1669
1670 if (value_type == Value::ValueType::Scalar) {
1671 // If the value is already a scalar, then let the scalar change itself:
1672 m_value.GetScalar().SetValueFromCString(value_str, encoding, byte_size);
1673 } else if (byte_size <= 16) {
1674 if (GetCompilerType().IsBoolean())
1675 value_str = ConvertBoolean(GetObjectRuntimeLanguage(), value_str);
1676
1677 // If the value fits in a scalar, then make a new scalar and again let the
1678 // scalar code do the conversion, then figure out where to put the new
1679 // value.
1680 Scalar new_scalar;
1681 error = new_scalar.SetValueFromCString(value_str, encoding, byte_size);
1682 if (error.Success()) {
1683 switch (value_type) {
1685 // If it is a load address, then the scalar value is the storage
1686 // location of the data, and we have to shove this value down to that
1687 // load location.
1689 Process *process = exe_ctx.GetProcessPtr();
1690 if (process) {
1691 addr_t target_addr =
1693 size_t bytes_written = process->WriteScalarToMemory(
1694 target_addr, new_scalar, byte_size, error);
1695 if (!error.Success())
1696 return false;
1697 if (bytes_written != byte_size) {
1698 error = Status::FromErrorString("unable to write value to memory");
1699 return false;
1700 }
1701 }
1702 } break;
1704 // If it is a host address, then we stuff the scalar as a DataBuffer
1705 // into the Value's data.
1706 DataExtractor new_data;
1707 new_data.SetByteOrder(m_data.GetByteOrder());
1708
1709 DataBufferSP buffer_sp(new DataBufferHeap(byte_size, 0));
1710 m_data.SetData(buffer_sp, 0);
1711 bool success = new_scalar.GetData(new_data);
1712 if (success) {
1713 new_data.CopyByteOrderedData(
1714 0, byte_size, const_cast<uint8_t *>(m_data.GetDataStart()),
1715 byte_size, m_data.GetByteOrder());
1716 }
1717 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1718
1719 } break;
1721 error = Status::FromErrorString("invalid location");
1722 return false;
1725 break;
1726 }
1727 } else {
1728 return false;
1729 }
1730 } else {
1731 // We don't support setting things bigger than a scalar at present.
1732 error = Status::FromErrorString("unable to write aggregate data type");
1733 return false;
1734 }
1735
1736 // If we have reached this point, then we have successfully changed the
1737 // value.
1739 return true;
1740}
1741
1743 decl.Clear();
1744 return false;
1745}
1746
1748 m_synthetic_children[key] = valobj;
1749}
1750
1752 ValueObjectSP synthetic_child_sp;
1753 std::map<ConstString, ValueObject *>::const_iterator pos =
1754 m_synthetic_children.find(key);
1755 if (pos != m_synthetic_children.end())
1756 synthetic_child_sp = pos->second->GetSP();
1757 return synthetic_child_sp;
1758}
1759
1762 Process *process = exe_ctx.GetProcessPtr();
1763 if (process)
1764 return process->IsPossibleDynamicValue(*this);
1765 else
1766 return GetCompilerType().IsPossibleDynamicType(nullptr, true, true);
1767}
1768
1770 Process *process(GetProcessSP().get());
1771 if (!process)
1772 return false;
1773
1774 // We trust that the compiler did the right thing and marked runtime support
1775 // values as artificial.
1776 if (!GetVariable() || !GetVariable()->IsArtificial())
1777 return false;
1778
1779 if (auto *runtime = process->GetLanguageRuntime(GetVariable()->GetLanguage()))
1780 if (runtime->IsAllowedRuntimeValue(GetName()))
1781 return false;
1782
1783 return true;
1784}
1785
1788 return language->IsNilReference(*this);
1789 }
1790 return false;
1791}
1792
1795 return language->IsUninitializedReference(*this);
1796 }
1797 return false;
1798}
1799
1800// This allows you to create an array member using and index that doesn't not
1801// fall in the normal bounds of the array. Many times structure can be defined
1802// as: struct Collection {
1803// uint32_t item_count;
1804// Item item_array[0];
1805// };
1806// The size of the "item_array" is 1, but many times in practice there are more
1807// items in "item_array".
1808
1810 bool can_create) {
1811 ValueObjectSP synthetic_child_sp;
1812 if (IsPointerType() || IsArrayType()) {
1813 std::string index_str = llvm::formatv("[{0}]", index);
1814 ConstString index_const_str(index_str);
1815 // Check if we have already created a synthetic array member in this valid
1816 // object. If we have we will re-use it.
1817 synthetic_child_sp = GetSyntheticChild(index_const_str);
1818 if (!synthetic_child_sp) {
1819 ValueObject *synthetic_child;
1820 // We haven't made a synthetic array member for INDEX yet, so lets make
1821 // one and cache it for any future reference.
1822 synthetic_child = CreateSyntheticArrayMember(index);
1823
1824 // Cache the value if we got one back...
1825 if (synthetic_child) {
1826 AddSyntheticChild(index_const_str, synthetic_child);
1827 synthetic_child_sp = synthetic_child->GetSP();
1828 synthetic_child_sp->SetName(ConstString(index_str));
1829 synthetic_child_sp->m_flags.m_is_array_item_for_pointer = true;
1830 }
1831 }
1832 }
1833 return synthetic_child_sp;
1834}
1835
1837 bool can_create) {
1838 ValueObjectSP synthetic_child_sp;
1839 if (IsScalarType()) {
1840 std::string index_str = llvm::formatv("[{0}-{1}]", from, to);
1841 ConstString index_const_str(index_str);
1842 // Check if we have already created a synthetic array member in this valid
1843 // object. If we have we will re-use it.
1844 synthetic_child_sp = GetSyntheticChild(index_const_str);
1845 if (!synthetic_child_sp) {
1846 uint32_t bit_field_size = to - from + 1;
1847 uint32_t bit_field_offset = from;
1848 if (GetDataExtractor().GetByteOrder() == eByteOrderBig)
1849 bit_field_offset =
1850 GetByteSize().value_or(0) * 8 - bit_field_size - bit_field_offset;
1851 // We haven't made a synthetic array member for INDEX yet, so lets make
1852 // one and cache it for any future reference.
1853 ValueObjectChild *synthetic_child = new ValueObjectChild(
1854 *this, GetCompilerType(), index_const_str, GetByteSize().value_or(0),
1855 0, bit_field_size, bit_field_offset, false, false,
1857
1858 // Cache the value if we got one back...
1859 if (synthetic_child) {
1860 AddSyntheticChild(index_const_str, synthetic_child);
1861 synthetic_child_sp = synthetic_child->GetSP();
1862 synthetic_child_sp->SetName(ConstString(index_str));
1863 synthetic_child_sp->m_flags.m_is_bitfield_for_scalar = true;
1864 }
1865 }
1866 }
1867 return synthetic_child_sp;
1868}
1869
1871 uint32_t offset, const CompilerType &type, bool can_create,
1872 ConstString name_const_str) {
1873
1874 ValueObjectSP synthetic_child_sp;
1875
1876 if (name_const_str.IsEmpty()) {
1877 name_const_str.SetString("@" + std::to_string(offset));
1878 }
1879
1880 // Check if we have already created a synthetic array member in this valid
1881 // object. If we have we will re-use it.
1882 synthetic_child_sp = GetSyntheticChild(name_const_str);
1883
1884 if (synthetic_child_sp.get())
1885 return synthetic_child_sp;
1886
1887 if (!can_create)
1888 return {};
1889
1891 std::optional<uint64_t> size =
1893 if (!size)
1894 return {};
1895 ValueObjectChild *synthetic_child =
1896 new ValueObjectChild(*this, type, name_const_str, *size, offset, 0, 0,
1897 false, false, eAddressTypeInvalid, 0);
1898 if (synthetic_child) {
1899 AddSyntheticChild(name_const_str, synthetic_child);
1900 synthetic_child_sp = synthetic_child->GetSP();
1901 synthetic_child_sp->SetName(name_const_str);
1902 synthetic_child_sp->m_flags.m_is_child_at_offset = true;
1903 }
1904 return synthetic_child_sp;
1905}
1906
1908 const CompilerType &type,
1909 bool can_create,
1910 ConstString name_const_str) {
1911 ValueObjectSP synthetic_child_sp;
1912
1913 if (name_const_str.IsEmpty()) {
1914 char name_str[128];
1915 snprintf(name_str, sizeof(name_str), "base%s@%i",
1916 type.GetTypeName().AsCString("<unknown>"), offset);
1917 name_const_str.SetCString(name_str);
1918 }
1919
1920 // Check if we have already created a synthetic array member in this valid
1921 // object. If we have we will re-use it.
1922 synthetic_child_sp = GetSyntheticChild(name_const_str);
1923
1924 if (synthetic_child_sp.get())
1925 return synthetic_child_sp;
1926
1927 if (!can_create)
1928 return {};
1929
1930 const bool is_base_class = true;
1931
1933 std::optional<uint64_t> size =
1935 if (!size)
1936 return {};
1937 ValueObjectChild *synthetic_child =
1938 new ValueObjectChild(*this, type, name_const_str, *size, offset, 0, 0,
1939 is_base_class, false, eAddressTypeInvalid, 0);
1940 if (synthetic_child) {
1941 AddSyntheticChild(name_const_str, synthetic_child);
1942 synthetic_child_sp = synthetic_child->GetSP();
1943 synthetic_child_sp->SetName(name_const_str);
1944 }
1945 return synthetic_child_sp;
1946}
1947
1948// your expression path needs to have a leading . or -> (unless it somehow
1949// "looks like" an array, in which case it has a leading [ symbol). while the [
1950// is meaningful and should be shown to the user, . and -> are just parser
1951// design, but by no means added information for the user.. strip them off
1952static const char *SkipLeadingExpressionPathSeparators(const char *expression) {
1953 if (!expression || !expression[0])
1954 return expression;
1955 if (expression[0] == '.')
1956 return expression + 1;
1957 if (expression[0] == '-' && expression[1] == '>')
1958 return expression + 2;
1959 return expression;
1960}
1961
1964 bool can_create) {
1965 ValueObjectSP synthetic_child_sp;
1966 ConstString name_const_string(expression);
1967 // Check if we have already created a synthetic array member in this valid
1968 // object. If we have we will re-use it.
1969 synthetic_child_sp = GetSyntheticChild(name_const_string);
1970 if (!synthetic_child_sp) {
1971 // We haven't made a synthetic array member for expression yet, so lets
1972 // make one and cache it for any future reference.
1973 synthetic_child_sp = GetValueForExpressionPath(
1974 expression, nullptr, nullptr,
1975 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(
1977 None));
1978
1979 // Cache the value if we got one back...
1980 if (synthetic_child_sp.get()) {
1981 // FIXME: this causes a "real" child to end up with its name changed to
1982 // the contents of expression
1983 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
1984 synthetic_child_sp->SetName(
1986 }
1987 }
1988 return synthetic_child_sp;
1989}
1990
1992 TargetSP target_sp(GetTargetSP());
1993 if (target_sp && !target_sp->GetEnableSyntheticValue()) {
1994 m_synthetic_value = nullptr;
1995 return;
1996 }
1997
1999
2001 return;
2002
2003 if (m_synthetic_children_sp.get() == nullptr)
2004 return;
2005
2006 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2007 return;
2008
2010}
2011
2013 if (use_dynamic == eNoDynamicValues)
2014 return;
2015
2016 if (!m_dynamic_value && !IsDynamic()) {
2018 Process *process = exe_ctx.GetProcessPtr();
2019 if (process && process->IsPossibleDynamicValue(*this)) {
2021 m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic);
2022 }
2023 }
2024}
2025
2027 if (use_dynamic == eNoDynamicValues)
2028 return ValueObjectSP();
2029
2030 if (!IsDynamic() && m_dynamic_value == nullptr) {
2031 CalculateDynamicValue(use_dynamic);
2032 }
2034 return m_dynamic_value->GetSP();
2035 else
2036 return ValueObjectSP();
2037}
2038
2041
2043 return m_synthetic_value->GetSP();
2044 else
2045 return ValueObjectSP();
2046}
2047
2050
2051 if (m_synthetic_children_sp.get() == nullptr)
2052 return false;
2053
2055
2056 return m_synthetic_value != nullptr;
2057}
2058
2060 if (GetParent()) {
2061 if (GetParent()->IsBaseClass())
2062 return GetParent()->GetNonBaseClassParent();
2063 else
2064 return GetParent();
2065 }
2066 return nullptr;
2067}
2068
2069bool ValueObject::IsBaseClass(uint32_t &depth) {
2070 if (!IsBaseClass()) {
2071 depth = 0;
2072 return false;
2073 }
2074 if (GetParent()) {
2075 GetParent()->IsBaseClass(depth);
2076 depth = depth + 1;
2077 return true;
2078 }
2079 // TODO: a base of no parent? weird..
2080 depth = 1;
2081 return true;
2082}
2083
2085 GetExpressionPathFormat epformat) {
2086 // synthetic children do not actually "exist" as part of the hierarchy, and
2087 // sometimes they are consed up in ways that don't make sense from an
2088 // underlying language/API standpoint. So, use a special code path here to
2089 // return something that can hopefully be used in expression
2092
2095 s.Printf("((%s)0x%" PRIx64 ")", GetTypeName().AsCString("void"),
2097 return;
2098 } else {
2099 uint64_t load_addr =
2101 if (load_addr != LLDB_INVALID_ADDRESS) {
2102 s.Printf("(*( (%s *)0x%" PRIx64 "))", GetTypeName().AsCString("void"),
2103 load_addr);
2104 return;
2105 }
2106 }
2107 }
2108
2109 if (CanProvideValue()) {
2110 s.Printf("((%s)%s)", GetTypeName().AsCString("void"),
2112 return;
2113 }
2114
2115 return;
2116 }
2117
2118 const bool is_deref_of_parent = IsDereferenceOfParent();
2119
2120 if (is_deref_of_parent &&
2122 // this is the original format of GetExpressionPath() producing code like
2123 // *(a_ptr).memberName, which is entirely fine, until you put this into
2124 // StackFrame::GetValueForVariableExpressionPath() which prefers to see
2125 // a_ptr->memberName. the eHonorPointers mode is meant to produce strings
2126 // in this latter format
2127 s.PutCString("*(");
2128 }
2129
2130 ValueObject *parent = GetParent();
2131
2132 if (parent)
2133 parent->GetExpressionPath(s, epformat);
2134
2135 // if we are a deref_of_parent just because we are synthetic array members
2136 // made up to allow ptr[%d] syntax to work in variable printing, then add our
2137 // name ([%d]) to the expression path
2141
2142 if (!IsBaseClass()) {
2143 if (!is_deref_of_parent) {
2144 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2145 if (non_base_class_parent &&
2146 !non_base_class_parent->GetName().IsEmpty()) {
2147 CompilerType non_base_class_parent_compiler_type =
2148 non_base_class_parent->GetCompilerType();
2149 if (non_base_class_parent_compiler_type) {
2150 if (parent && parent->IsDereferenceOfParent() &&
2152 s.PutCString("->");
2153 } else {
2154 const uint32_t non_base_class_parent_type_info =
2155 non_base_class_parent_compiler_type.GetTypeInfo();
2156
2157 if (non_base_class_parent_type_info & eTypeIsPointer) {
2158 s.PutCString("->");
2159 } else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2160 !(non_base_class_parent_type_info & eTypeIsArray)) {
2161 s.PutChar('.');
2162 }
2163 }
2164 }
2165 }
2166
2167 const char *name = GetName().GetCString();
2168 if (name)
2169 s.PutCString(name);
2170 }
2171 }
2172
2173 if (is_deref_of_parent &&
2175 s.PutChar(')');
2176 }
2177}
2178
2180 llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop,
2181 ExpressionPathEndResultType *final_value_type,
2182 const GetValueForExpressionPathOptions &options,
2183 ExpressionPathAftermath *final_task_on_target) {
2184
2185 ExpressionPathScanEndReason dummy_reason_to_stop =
2187 ExpressionPathEndResultType dummy_final_value_type =
2189 ExpressionPathAftermath dummy_final_task_on_target =
2191
2193 expression, reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2194 final_value_type ? final_value_type : &dummy_final_value_type, options,
2195 final_task_on_target ? final_task_on_target
2196 : &dummy_final_task_on_target);
2197
2198 if (!final_task_on_target ||
2199 *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
2200 return ret_val;
2201
2202 if (ret_val.get() &&
2203 ((final_value_type ? *final_value_type : dummy_final_value_type) ==
2204 eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress
2205 // of plain objects
2206 {
2207 if ((final_task_on_target ? *final_task_on_target
2208 : dummy_final_task_on_target) ==
2210 Status error;
2211 ValueObjectSP final_value = ret_val->Dereference(error);
2212 if (error.Fail() || !final_value.get()) {
2213 if (reason_to_stop)
2214 *reason_to_stop =
2216 if (final_value_type)
2218 return ValueObjectSP();
2219 } else {
2220 if (final_task_on_target)
2221 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2222 return final_value;
2223 }
2224 }
2225 if (*final_task_on_target ==
2227 Status error;
2228 ValueObjectSP final_value = ret_val->AddressOf(error);
2229 if (error.Fail() || !final_value.get()) {
2230 if (reason_to_stop)
2231 *reason_to_stop =
2233 if (final_value_type)
2235 return ValueObjectSP();
2236 } else {
2237 if (final_task_on_target)
2238 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2239 return final_value;
2240 }
2241 }
2242 }
2243 return ret_val; // final_task_on_target will still have its original value, so
2244 // you know I did not do it
2245}
2246
2248 llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop,
2249 ExpressionPathEndResultType *final_result,
2250 const GetValueForExpressionPathOptions &options,
2251 ExpressionPathAftermath *what_next) {
2252 ValueObjectSP root = GetSP();
2253
2254 if (!root)
2255 return nullptr;
2256
2257 llvm::StringRef remainder = expression;
2258
2259 while (true) {
2260 llvm::StringRef temp_expression = remainder;
2261
2262 CompilerType root_compiler_type = root->GetCompilerType();
2263 CompilerType pointee_compiler_type;
2264 Flags pointee_compiler_type_info;
2265
2266 Flags root_compiler_type_info(
2267 root_compiler_type.GetTypeInfo(&pointee_compiler_type));
2268 if (pointee_compiler_type)
2269 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
2270
2271 if (temp_expression.empty()) {
2273 return root;
2274 }
2275
2276 switch (temp_expression.front()) {
2277 case '-': {
2278 temp_expression = temp_expression.drop_front();
2279 if (options.m_check_dot_vs_arrow_syntax &&
2280 root_compiler_type_info.Test(eTypeIsPointer)) // if you are trying to
2281 // use -> on a
2282 // non-pointer and I
2283 // must catch the error
2284 {
2285 *reason_to_stop =
2288 return ValueObjectSP();
2289 }
2290 if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to
2291 // extract an ObjC IVar
2292 // when this is forbidden
2293 root_compiler_type_info.Test(eTypeIsPointer) &&
2294 options.m_no_fragile_ivar) {
2295 *reason_to_stop =
2298 return ValueObjectSP();
2299 }
2300 if (!temp_expression.starts_with(">")) {
2301 *reason_to_stop =
2304 return ValueObjectSP();
2305 }
2306 }
2307 [[fallthrough]];
2308 case '.': // or fallthrough from ->
2309 {
2310 if (options.m_check_dot_vs_arrow_syntax &&
2311 temp_expression.front() == '.' &&
2312 root_compiler_type_info.Test(eTypeIsPointer)) // if you are trying to
2313 // use . on a pointer
2314 // and I must catch the
2315 // error
2316 {
2317 *reason_to_stop =
2320 return nullptr;
2321 }
2322 temp_expression = temp_expression.drop_front(); // skip . or >
2323
2324 size_t next_sep_pos = temp_expression.find_first_of("-.[", 1);
2325 if (next_sep_pos == llvm::StringRef::npos) // if no other separator just
2326 // expand this last layer
2327 {
2328 llvm::StringRef child_name = temp_expression;
2329 ValueObjectSP child_valobj_sp =
2330 root->GetChildMemberWithName(child_name);
2331
2332 if (child_valobj_sp.get()) // we know we are done, so just return
2333 {
2334 *reason_to_stop =
2337 return child_valobj_sp;
2338 } else {
2339 switch (options.m_synthetic_children_traversal) {
2341 None:
2342 break;
2345 if (root->IsSynthetic()) {
2346 child_valobj_sp = root->GetNonSyntheticValue();
2347 if (child_valobj_sp.get())
2348 child_valobj_sp =
2349 child_valobj_sp->GetChildMemberWithName(child_name);
2350 }
2351 break;
2354 if (!root->IsSynthetic()) {
2355 child_valobj_sp = root->GetSyntheticValue();
2356 if (child_valobj_sp.get())
2357 child_valobj_sp =
2358 child_valobj_sp->GetChildMemberWithName(child_name);
2359 }
2360 break;
2362 Both:
2363 if (root->IsSynthetic()) {
2364 child_valobj_sp = root->GetNonSyntheticValue();
2365 if (child_valobj_sp.get())
2366 child_valobj_sp =
2367 child_valobj_sp->GetChildMemberWithName(child_name);
2368 } else {
2369 child_valobj_sp = root->GetSyntheticValue();
2370 if (child_valobj_sp.get())
2371 child_valobj_sp =
2372 child_valobj_sp->GetChildMemberWithName(child_name);
2373 }
2374 break;
2375 }
2376 }
2377
2378 // if we are here and options.m_no_synthetic_children is true,
2379 // child_valobj_sp is going to be a NULL SP, so we hit the "else"
2380 // branch, and return an error
2381 if (child_valobj_sp.get()) // if it worked, just return
2382 {
2383 *reason_to_stop =
2386 return child_valobj_sp;
2387 } else {
2388 *reason_to_stop =
2391 return nullptr;
2392 }
2393 } else // other layers do expand
2394 {
2395 llvm::StringRef next_separator = temp_expression.substr(next_sep_pos);
2396 llvm::StringRef child_name = temp_expression.slice(0, next_sep_pos);
2397
2398 ValueObjectSP child_valobj_sp =
2399 root->GetChildMemberWithName(child_name);
2400 if (child_valobj_sp.get()) // store the new root and move on
2401 {
2402 root = child_valobj_sp;
2403 remainder = next_separator;
2405 continue;
2406 } else {
2407 switch (options.m_synthetic_children_traversal) {
2409 None:
2410 break;
2413 if (root->IsSynthetic()) {
2414 child_valobj_sp = root->GetNonSyntheticValue();
2415 if (child_valobj_sp.get())
2416 child_valobj_sp =
2417 child_valobj_sp->GetChildMemberWithName(child_name);
2418 }
2419 break;
2422 if (!root->IsSynthetic()) {
2423 child_valobj_sp = root->GetSyntheticValue();
2424 if (child_valobj_sp.get())
2425 child_valobj_sp =
2426 child_valobj_sp->GetChildMemberWithName(child_name);
2427 }
2428 break;
2430 Both:
2431 if (root->IsSynthetic()) {
2432 child_valobj_sp = root->GetNonSyntheticValue();
2433 if (child_valobj_sp.get())
2434 child_valobj_sp =
2435 child_valobj_sp->GetChildMemberWithName(child_name);
2436 } else {
2437 child_valobj_sp = root->GetSyntheticValue();
2438 if (child_valobj_sp.get())
2439 child_valobj_sp =
2440 child_valobj_sp->GetChildMemberWithName(child_name);
2441 }
2442 break;
2443 }
2444 }
2445
2446 // if we are here and options.m_no_synthetic_children is true,
2447 // child_valobj_sp is going to be a NULL SP, so we hit the "else"
2448 // branch, and return an error
2449 if (child_valobj_sp.get()) // if it worked, move on
2450 {
2451 root = child_valobj_sp;
2452 remainder = next_separator;
2454 continue;
2455 } else {
2456 *reason_to_stop =
2459 return nullptr;
2460 }
2461 }
2462 break;
2463 }
2464 case '[': {
2465 if (!root_compiler_type_info.Test(eTypeIsArray) &&
2466 !root_compiler_type_info.Test(eTypeIsPointer) &&
2467 !root_compiler_type_info.Test(
2468 eTypeIsVector)) // if this is not a T[] nor a T*
2469 {
2470 if (!root_compiler_type_info.Test(
2471 eTypeIsScalar)) // if this is not even a scalar...
2472 {
2473 if (options.m_synthetic_children_traversal ==
2475 None) // ...only chance left is synthetic
2476 {
2477 *reason_to_stop =
2480 return ValueObjectSP();
2481 }
2482 } else if (!options.m_allow_bitfields_syntax) // if this is a scalar,
2483 // check that we can
2484 // expand bitfields
2485 {
2486 *reason_to_stop =
2489 return ValueObjectSP();
2490 }
2491 }
2492 if (temp_expression[1] ==
2493 ']') // if this is an unbounded range it only works for arrays
2494 {
2495 if (!root_compiler_type_info.Test(eTypeIsArray)) {
2496 *reason_to_stop =
2499 return nullptr;
2500 } else // even if something follows, we cannot expand unbounded ranges,
2501 // just let the caller do it
2502 {
2503 *reason_to_stop =
2505 *final_result =
2507 return root;
2508 }
2509 }
2510
2511 size_t close_bracket_position = temp_expression.find(']', 1);
2512 if (close_bracket_position ==
2513 llvm::StringRef::npos) // if there is no ], this is a syntax error
2514 {
2515 *reason_to_stop =
2518 return nullptr;
2519 }
2520
2521 llvm::StringRef bracket_expr =
2522 temp_expression.slice(1, close_bracket_position);
2523
2524 // If this was an empty expression it would have been caught by the if
2525 // above.
2526 assert(!bracket_expr.empty());
2527
2528 if (!bracket_expr.contains('-')) {
2529 // if no separator, this is of the form [N]. Note that this cannot be
2530 // an unbounded range of the form [], because that case was handled
2531 // above with an unconditional return.
2532 unsigned long index = 0;
2533 if (bracket_expr.getAsInteger(0, index)) {
2534 *reason_to_stop =
2537 return nullptr;
2538 }
2539
2540 // from here on we do have a valid index
2541 if (root_compiler_type_info.Test(eTypeIsArray)) {
2542 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index);
2543 if (!child_valobj_sp)
2544 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
2545 if (!child_valobj_sp)
2546 if (root->HasSyntheticValue() &&
2547 llvm::expectedToStdOptional(
2548 root->GetSyntheticValue()->GetNumChildren())
2549 .value_or(0) > index)
2550 child_valobj_sp =
2551 root->GetSyntheticValue()->GetChildAtIndex(index);
2552 if (child_valobj_sp) {
2553 root = child_valobj_sp;
2554 remainder =
2555 temp_expression.substr(close_bracket_position + 1); // skip ]
2557 continue;
2558 } else {
2559 *reason_to_stop =
2562 return nullptr;
2563 }
2564 } else if (root_compiler_type_info.Test(eTypeIsPointer)) {
2565 if (*what_next ==
2566 ValueObject::
2567 eExpressionPathAftermathDereference && // if this is a
2568 // ptr-to-scalar, I
2569 // am accessing it
2570 // by index and I
2571 // would have
2572 // deref'ed anyway,
2573 // then do it now
2574 // and use this as
2575 // a bitfield
2576 pointee_compiler_type_info.Test(eTypeIsScalar)) {
2577 Status error;
2578 root = root->Dereference(error);
2579 if (error.Fail() || !root) {
2580 *reason_to_stop =
2583 return nullptr;
2584 } else {
2586 continue;
2587 }
2588 } else {
2589 if (root->GetCompilerType().GetMinimumLanguage() ==
2591 pointee_compiler_type_info.AllClear(eTypeIsPointer) &&
2592 root->HasSyntheticValue() &&
2595 SyntheticChildrenTraversal::ToSynthetic ||
2598 SyntheticChildrenTraversal::Both)) {
2599 root = root->GetSyntheticValue()->GetChildAtIndex(index);
2600 } else
2601 root = root->GetSyntheticArrayMember(index, true);
2602 if (!root) {
2603 *reason_to_stop =
2606 return nullptr;
2607 } else {
2608 remainder =
2609 temp_expression.substr(close_bracket_position + 1); // skip ]
2611 continue;
2612 }
2613 }
2614 } else if (root_compiler_type_info.Test(eTypeIsScalar)) {
2615 root = root->GetSyntheticBitFieldChild(index, index, true);
2616 if (!root) {
2617 *reason_to_stop =
2620 return nullptr;
2621 } else // we do not know how to expand members of bitfields, so we
2622 // just return and let the caller do any further processing
2623 {
2624 *reason_to_stop = ValueObject::
2627 return root;
2628 }
2629 } else if (root_compiler_type_info.Test(eTypeIsVector)) {
2630 root = root->GetChildAtIndex(index);
2631 if (!root) {
2632 *reason_to_stop =
2635 return ValueObjectSP();
2636 } else {
2637 remainder =
2638 temp_expression.substr(close_bracket_position + 1); // skip ]
2640 continue;
2641 }
2642 } else if (options.m_synthetic_children_traversal ==
2644 SyntheticChildrenTraversal::ToSynthetic ||
2647 SyntheticChildrenTraversal::Both) {
2648 if (root->HasSyntheticValue())
2649 root = root->GetSyntheticValue();
2650 else if (!root->IsSynthetic()) {
2651 *reason_to_stop =
2654 return nullptr;
2655 }
2656 // if we are here, then root itself is a synthetic VO.. should be
2657 // good to go
2658
2659 if (!root) {
2660 *reason_to_stop =
2663 return nullptr;
2664 }
2665 root = root->GetChildAtIndex(index);
2666 if (!root) {
2667 *reason_to_stop =
2670 return nullptr;
2671 } else {
2672 remainder =
2673 temp_expression.substr(close_bracket_position + 1); // skip ]
2675 continue;
2676 }
2677 } else {
2678 *reason_to_stop =
2681 return nullptr;
2682 }
2683 } else {
2684 // we have a low and a high index
2685 llvm::StringRef sleft, sright;
2686 unsigned long low_index, high_index;
2687 std::tie(sleft, sright) = bracket_expr.split('-');
2688 if (sleft.getAsInteger(0, low_index) ||
2689 sright.getAsInteger(0, high_index)) {
2690 *reason_to_stop =
2693 return nullptr;
2694 }
2695
2696 if (low_index > high_index) // swap indices if required
2697 std::swap(low_index, high_index);
2698
2699 if (root_compiler_type_info.Test(
2700 eTypeIsScalar)) // expansion only works for scalars
2701 {
2702 root = root->GetSyntheticBitFieldChild(low_index, high_index, true);
2703 if (!root) {
2704 *reason_to_stop =
2707 return nullptr;
2708 } else {
2709 *reason_to_stop = ValueObject::
2712 return root;
2713 }
2714 } else if (root_compiler_type_info.Test(
2715 eTypeIsPointer) && // if this is a ptr-to-scalar, I am
2716 // accessing it by index and I would
2717 // have deref'ed anyway, then do it
2718 // now and use this as a bitfield
2719 *what_next ==
2721 pointee_compiler_type_info.Test(eTypeIsScalar)) {
2722 Status error;
2723 root = root->Dereference(error);
2724 if (error.Fail() || !root) {
2725 *reason_to_stop =
2728 return nullptr;
2729 } else {
2731 continue;
2732 }
2733 } else {
2734 *reason_to_stop =
2737 return root;
2738 }
2739 }
2740 break;
2741 }
2742 default: // some non-separator is in the way
2743 {
2744 *reason_to_stop =
2747 return nullptr;
2748 }
2749 }
2750 }
2751}
2752
2753llvm::Error ValueObject::Dump(Stream &s) {
2754 return Dump(s, DumpValueObjectOptions(*this));
2755}
2756
2758 const DumpValueObjectOptions &options) {
2759 ValueObjectPrinter printer(*this, &s, options);
2760 return printer.PrintValueObject();
2761}
2762
2764 ValueObjectSP valobj_sp;
2765
2766 if (UpdateValueIfNeeded(false) && m_error.Success()) {
2768
2769 DataExtractor data;
2772
2773 if (IsBitfield()) {
2775 m_error = v.GetValueAsData(&exe_ctx, data, GetModule().get());
2776 } else
2777 m_error = m_value.GetValueAsData(&exe_ctx, data, GetModule().get());
2778
2780 exe_ctx.GetBestExecutionContextScope(), GetCompilerType(), name, data,
2781 GetAddressOf());
2782 }
2783
2784 if (!valobj_sp) {
2788 }
2789 return valobj_sp;
2790}
2791
2793 lldb::DynamicValueType dynValue, bool synthValue) {
2794 ValueObjectSP result_sp;
2795 switch (dynValue) {
2798 if (!IsDynamic())
2799 result_sp = GetDynamicValue(dynValue);
2800 } break;
2802 if (IsDynamic())
2803 result_sp = GetStaticValue();
2804 } break;
2805 }
2806 if (!result_sp)
2807 result_sp = GetSP();
2808 assert(result_sp);
2809
2810 bool is_synthetic = result_sp->IsSynthetic();
2811 if (synthValue && !is_synthetic) {
2812 if (auto synth_sp = result_sp->GetSyntheticValue())
2813 return synth_sp;
2814 }
2815 if (!synthValue && is_synthetic) {
2816 if (auto non_synth_sp = result_sp->GetNonSyntheticValue())
2817 return non_synth_sp;
2818 }
2819
2820 return result_sp;
2821}
2822
2824 if (m_deref_valobj)
2825 return m_deref_valobj->GetSP();
2826
2827 const bool is_pointer_or_reference_type = IsPointerOrReferenceType();
2828 if (is_pointer_or_reference_type) {
2829 bool omit_empty_base_classes = true;
2830 bool ignore_array_bounds = false;
2831
2832 std::string child_name_str;
2833 uint32_t child_byte_size = 0;
2834 int32_t child_byte_offset = 0;
2835 uint32_t child_bitfield_bit_size = 0;
2836 uint32_t child_bitfield_bit_offset = 0;
2837 bool child_is_base_class = false;
2838 bool child_is_deref_of_parent = false;
2839 const bool transparent_pointers = false;
2840 CompilerType compiler_type = GetCompilerType();
2841 uint64_t language_flags = 0;
2842
2844
2845 CompilerType child_compiler_type;
2846 auto child_compiler_type_or_err = compiler_type.GetChildCompilerTypeAtIndex(
2847 &exe_ctx, 0, transparent_pointers, omit_empty_base_classes,
2848 ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset,
2849 child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
2850 child_is_deref_of_parent, this, language_flags);
2851 if (!child_compiler_type_or_err)
2853 child_compiler_type_or_err.takeError(),
2854 "could not find child: {0}");
2855 else
2856 child_compiler_type = *child_compiler_type_or_err;
2857
2858 if (child_compiler_type && child_byte_size) {
2859 ConstString child_name;
2860 if (!child_name_str.empty())
2861 child_name.SetCString(child_name_str.c_str());
2862
2864 *this, child_compiler_type, child_name, child_byte_size,
2865 child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset,
2866 child_is_base_class, child_is_deref_of_parent, eAddressTypeInvalid,
2867 language_flags);
2868 }
2869
2870 // In case of incomplete child compiler type, use the pointee type and try
2871 // to recreate a new ValueObjectChild using it.
2872 if (!m_deref_valobj) {
2873 // FIXME(#59012): C++ stdlib formatters break with incomplete types (e.g.
2874 // `std::vector<int> &`). Remove ObjC restriction once that's resolved.
2877 child_compiler_type = compiler_type.GetPointeeType();
2878
2879 if (child_compiler_type) {
2880 ConstString child_name;
2881 if (!child_name_str.empty())
2882 child_name.SetCString(child_name_str.c_str());
2883
2885 *this, child_compiler_type, child_name, child_byte_size,
2886 child_byte_offset, child_bitfield_bit_size,
2887 child_bitfield_bit_offset, child_is_base_class,
2888 child_is_deref_of_parent, eAddressTypeInvalid, language_flags);
2889 }
2890 }
2891 }
2892
2893 } else if (HasSyntheticValue()) {
2895 GetSyntheticValue()->GetChildMemberWithName("$$dereference$$").get();
2896 } else if (IsSynthetic()) {
2897 m_deref_valobj = GetChildMemberWithName("$$dereference$$").get();
2898 }
2899
2900 if (m_deref_valobj) {
2901 error.Clear();
2902 return m_deref_valobj->GetSP();
2903 } else {
2904 StreamString strm;
2905 GetExpressionPath(strm);
2906
2907 if (is_pointer_or_reference_type)
2909 "dereference failed: (%s) %s",
2910 GetTypeName().AsCString("<invalid type>"), strm.GetData());
2911 else
2913 "not a pointer or reference type: (%s) %s",
2914 GetTypeName().AsCString("<invalid type>"), strm.GetData());
2915 return ValueObjectSP();
2916 }
2917}
2918
2921 return m_addr_of_valobj_sp;
2922
2923 AddressType address_type = eAddressTypeInvalid;
2924 const bool scalar_is_load_address = false;
2925 addr_t addr = GetAddressOf(scalar_is_load_address, &address_type);
2926 error.Clear();
2927 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost) {
2928 switch (address_type) {
2929 case eAddressTypeInvalid: {
2930 StreamString expr_path_strm;
2931 GetExpressionPath(expr_path_strm);
2932 error = Status::FromErrorStringWithFormat("'%s' is not in memory",
2933 expr_path_strm.GetData());
2934 } break;
2935
2936 case eAddressTypeFile:
2937 case eAddressTypeLoad: {
2938 CompilerType compiler_type = GetCompilerType();
2939 if (compiler_type) {
2940 std::string name(1, '&');
2941 name.append(m_name.AsCString(""));
2945 compiler_type.GetPointerType(), ConstString(name.c_str()), addr,
2947 }
2948 } break;
2949 default:
2950 break;
2951 }
2952 } else {
2953 StreamString expr_path_strm;
2954 GetExpressionPath(expr_path_strm);
2956 "'%s' doesn't have a valid address", expr_path_strm.GetData());
2957 }
2958
2959 return m_addr_of_valobj_sp;
2960}
2961
2963 return ValueObjectCast::Create(*this, GetName(), compiler_type);
2964}
2965
2967 // Only allow casts if the original type is equal or larger than the cast
2968 // type, unless we know this is a load address. Getting the size wrong for
2969 // a host side storage could leak lldb memory, so we absolutely want to
2970 // prevent that. We may not always get the right value, for instance if we
2971 // have an expression result value that's copied into a storage location in
2972 // the target may not have copied enough memory. I'm not trying to fix that
2973 // here, I'm just making Cast from a smaller to a larger possible in all the
2974 // cases where that doesn't risk making a Value out of random lldb memory.
2975 // You have to check the ValueObject's Value for the address types, since
2976 // ValueObjects that use live addresses will tell you they fetch data from the
2977 // live address, but once they are made, they actually don't.
2978 // FIXME: Can we make ValueObject's with a live address fetch "more data" from
2979 // the live address if it is still valid?
2980
2981 Status error;
2982 CompilerType my_type = GetCompilerType();
2983
2984 ExecutionContextScope *exe_scope =
2986 if (compiler_type.GetByteSize(exe_scope) <=
2987 GetCompilerType().GetByteSize(exe_scope) ||
2989 return DoCast(compiler_type);
2990
2992 "Can only cast to a type that is equal to or smaller "
2993 "than the orignal type.");
2994
2996 ExecutionContext(GetExecutionContextRef()).GetBestExecutionContextScope(),
2997 std::move(error));
2998}
2999
3001 return ValueObjectCast::Create(*this, new_name, GetCompilerType());
3002}
3003
3005 CompilerType &compiler_type) {
3006 ValueObjectSP valobj_sp;
3007 AddressType address_type;
3008 addr_t ptr_value = GetPointerValue(&address_type);
3009
3010 if (ptr_value != LLDB_INVALID_ADDRESS) {
3011 Address ptr_addr(ptr_value);
3013 valobj_sp = ValueObjectMemory::Create(
3014 exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, compiler_type);
3015 }
3016 return valobj_sp;
3017}
3018
3020 ValueObjectSP valobj_sp;
3021 AddressType address_type;
3022 addr_t ptr_value = GetPointerValue(&address_type);
3023
3024 if (ptr_value != LLDB_INVALID_ADDRESS) {
3025 Address ptr_addr(ptr_value);
3027 valobj_sp = ValueObjectMemory::Create(
3028 exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, type_sp);
3029 }
3030 return valobj_sp;
3031}
3032
3035 if (auto target_sp = GetTargetSP()) {
3036 const bool scalar_is_load_address = true;
3037 AddressType addr_type;
3038 addr_value = GetAddressOf(scalar_is_load_address, &addr_type);
3039 if (addr_type == eAddressTypeFile) {
3040 lldb::ModuleSP module_sp(GetModule());
3041 if (!module_sp)
3042 addr_value = LLDB_INVALID_ADDRESS;
3043 else {
3044 Address tmp_addr;
3045 module_sp->ResolveFileAddress(addr_value, tmp_addr);
3046 addr_value = tmp_addr.GetLoadAddress(target_sp.get());
3047 }
3048 } else if (addr_type == eAddressTypeHost ||
3049 addr_type == eAddressTypeInvalid)
3050 addr_value = LLDB_INVALID_ADDRESS;
3051 }
3052 return addr_value;
3053}
3054
3055llvm::Expected<lldb::ValueObjectSP> ValueObject::CastDerivedToBaseType(
3056 CompilerType type, const llvm::ArrayRef<uint32_t> &base_type_indices) {
3057 // Make sure the starting type and the target type are both valid for this
3058 // type of cast; otherwise return the shared pointer to the original
3059 // (unchanged) ValueObject.
3060 if (!type.IsPointerType() && !type.IsReferenceType())
3061 return llvm::make_error<llvm::StringError>(
3062 "Invalid target type: should be a pointer or a reference",
3063 llvm::inconvertibleErrorCode());
3064
3065 CompilerType start_type = GetCompilerType();
3066 if (start_type.IsReferenceType())
3067 start_type = start_type.GetNonReferenceType();
3068
3069 auto target_record_type =
3070 type.IsPointerType() ? type.GetPointeeType() : type.GetNonReferenceType();
3071 auto start_record_type =
3072 start_type.IsPointerType() ? start_type.GetPointeeType() : start_type;
3073
3074 if (!target_record_type.IsRecordType() || !start_record_type.IsRecordType())
3075 return llvm::make_error<llvm::StringError>(
3076 "Underlying start & target types should be record types",
3077 llvm::inconvertibleErrorCode());
3078
3079 if (target_record_type.CompareTypes(start_record_type))
3080 return llvm::make_error<llvm::StringError>(
3081 "Underlying start & target types should be different",
3082 llvm::inconvertibleErrorCode());
3083
3084 if (base_type_indices.empty())
3085 return llvm::make_error<llvm::StringError>(
3086 "Children sequence must be non-empty", llvm::inconvertibleErrorCode());
3087
3088 // Both the starting & target types are valid for the cast, and the list of
3089 // base class indices is non-empty, so we can proceed with the cast.
3090
3091 lldb::TargetSP target = GetTargetSP();
3092 // The `value` can be a pointer, but GetChildAtIndex works for pointers too.
3093 lldb::ValueObjectSP inner_value = GetSP();
3094
3095 for (const uint32_t i : base_type_indices)
3096 // Create synthetic value if needed.
3097 inner_value =
3098 inner_value->GetChildAtIndex(i, /*can_create_synthetic*/ true);
3099
3100 // At this point type of `inner_value` should be the dereferenced target
3101 // type.
3102 CompilerType inner_value_type = inner_value->GetCompilerType();
3103 if (type.IsPointerType()) {
3104 if (!inner_value_type.CompareTypes(type.GetPointeeType()))
3105 return llvm::make_error<llvm::StringError>(
3106 "casted value doesn't match the desired type",
3107 llvm::inconvertibleErrorCode());
3108
3109 uintptr_t addr = inner_value->GetLoadAddress();
3110 llvm::StringRef name = "";
3111 ExecutionContext exe_ctx(target.get(), false);
3112 return ValueObject::CreateValueObjectFromAddress(name, addr, exe_ctx, type,
3113 /* do deref */ false);
3114 }
3115
3116 // At this point the target type should be a reference.
3117 if (!inner_value_type.CompareTypes(type.GetNonReferenceType()))
3118 return llvm::make_error<llvm::StringError>(
3119 "casted value doesn't match the desired type",
3120 llvm::inconvertibleErrorCode());
3121
3122 return lldb::ValueObjectSP(inner_value->Cast(type.GetNonReferenceType()));
3123}
3124
3125llvm::Expected<lldb::ValueObjectSP>
3127 // Make sure the starting type and the target type are both valid for this
3128 // type of cast; otherwise return the shared pointer to the original
3129 // (unchanged) ValueObject.
3130 if (!type.IsPointerType() && !type.IsReferenceType())
3131 return llvm::make_error<llvm::StringError>(
3132 "Invalid target type: should be a pointer or a reference",
3133 llvm::inconvertibleErrorCode());
3134
3135 CompilerType start_type = GetCompilerType();
3136 if (start_type.IsReferenceType())
3137 start_type = start_type.GetNonReferenceType();
3138
3139 auto target_record_type =
3140 type.IsPointerType() ? type.GetPointeeType() : type.GetNonReferenceType();
3141 auto start_record_type =
3142 start_type.IsPointerType() ? start_type.GetPointeeType() : start_type;
3143
3144 if (!target_record_type.IsRecordType() || !start_record_type.IsRecordType())
3145 return llvm::make_error<llvm::StringError>(
3146 "Underlying start & target types should be record types",
3147 llvm::inconvertibleErrorCode());
3148
3149 if (target_record_type.CompareTypes(start_record_type))
3150 return llvm::make_error<llvm::StringError>(
3151 "Underlying start & target types should be different",
3152 llvm::inconvertibleErrorCode());
3153
3154 CompilerType virtual_base;
3155 if (target_record_type.IsVirtualBase(start_record_type, &virtual_base)) {
3156 if (!virtual_base.IsValid())
3157 return llvm::make_error<llvm::StringError>(
3158 "virtual base should be valid", llvm::inconvertibleErrorCode());
3159 return llvm::make_error<llvm::StringError>(
3160 llvm::Twine("cannot cast " + start_type.TypeDescription() + " to " +
3161 type.TypeDescription() + " via virtual base " +
3162 virtual_base.TypeDescription()),
3163 llvm::inconvertibleErrorCode());
3164 }
3165
3166 // Both the starting & target types are valid for the cast, so we can
3167 // proceed with the cast.
3168
3169 lldb::TargetSP target = GetTargetSP();
3170 auto pointer_type =
3171 type.IsPointerType() ? type : type.GetNonReferenceType().GetPointerType();
3172
3173 uintptr_t addr =
3175
3176 llvm::StringRef name = "";
3177 ExecutionContext exe_ctx(target.get(), false);
3179 name, addr - offset, exe_ctx, pointer_type, /* do_deref */ false);
3180
3181 if (type.IsPointerType())
3182 return value;
3183
3184 // At this point the target type is a reference. Since `value` is a pointer,
3185 // it has to be dereferenced.
3186 Status error;
3187 return value->Dereference(error);
3188}
3189
3191 bool is_scalar = GetCompilerType().IsScalarType();
3192 bool is_enum = GetCompilerType().IsEnumerationType();
3193 bool is_pointer =
3195 bool is_float = GetCompilerType().IsFloat();
3196 bool is_integer = GetCompilerType().IsInteger();
3198
3199 if (!type.IsScalarType())
3202 Status::FromErrorString("target type must be a scalar"));
3203
3204 if (!is_scalar && !is_enum && !is_pointer)
3207 Status::FromErrorString("argument must be a scalar, enum, or pointer"));
3208
3209 lldb::TargetSP target = GetTargetSP();
3210 uint64_t type_byte_size = 0;
3211 uint64_t val_byte_size = 0;
3212 if (auto temp = type.GetByteSize(target.get()))
3213 type_byte_size = temp.value();
3214 if (auto temp = GetCompilerType().GetByteSize(target.get()))
3215 val_byte_size = temp.value();
3216
3217 if (is_pointer) {
3218 if (!type.IsInteger() && !type.IsBoolean())
3221 Status::FromErrorString("target type must be an integer or boolean"));
3222 if (!type.IsBoolean() && type_byte_size < val_byte_size)
3226 "target type cannot be smaller than the pointer type"));
3227 }
3228
3229 if (type.IsBoolean()) {
3230 if (!is_scalar || is_integer)
3232 target, GetValueAsUnsigned(0) != 0, "result");
3233 else if (is_scalar && is_float) {
3234 auto float_value_or_err = GetValueAsAPFloat();
3235 if (float_value_or_err)
3237 target, !float_value_or_err->isZero(), "result");
3238 else
3242 "cannot get value as APFloat: %s",
3243 llvm::toString(float_value_or_err.takeError()).c_str()));
3244 }
3245 }
3246
3247 if (type.IsInteger()) {
3248 if (!is_scalar || is_integer) {
3249 auto int_value_or_err = GetValueAsAPSInt();
3250 if (int_value_or_err) {
3251 // Get the value as APSInt and extend or truncate it to the requested
3252 // size.
3253 llvm::APSInt ext =
3254 int_value_or_err->extOrTrunc(type_byte_size * CHAR_BIT);
3255 return ValueObject::CreateValueObjectFromAPInt(target, ext, type,
3256 "result");
3257 } else
3261 "cannot get value as APSInt: %s",
3262 llvm::toString(int_value_or_err.takeError()).c_str()));
3263 } else if (is_scalar && is_float) {
3264 llvm::APSInt integer(type_byte_size * CHAR_BIT, !type.IsSigned());
3265 bool is_exact;
3266 auto float_value_or_err = GetValueAsAPFloat();
3267 if (float_value_or_err) {
3268 llvm::APFloatBase::opStatus status =
3269 float_value_or_err->convertToInteger(
3270 integer, llvm::APFloat::rmTowardZero, &is_exact);
3271
3272 // Casting floating point values that are out of bounds of the target
3273 // type is undefined behaviour.
3274 if (status & llvm::APFloatBase::opInvalidOp)
3278 "invalid type cast detected: %s",
3279 llvm::toString(float_value_or_err.takeError()).c_str()));
3281 "result");
3282 }
3283 }
3284 }
3285
3286 if (type.IsFloat()) {
3287 if (!is_scalar) {
3288 auto int_value_or_err = GetValueAsAPSInt();
3289 if (int_value_or_err) {
3290 llvm::APSInt ext =
3291 int_value_or_err->extOrTrunc(type_byte_size * CHAR_BIT);
3292 Scalar scalar_int(ext);
3293 llvm::APFloat f = scalar_int.CreateAPFloatFromAPSInt(
3295 return ValueObject::CreateValueObjectFromAPFloat(target, f, type,
3296 "result");
3297 } else {
3301 "cannot get value as APSInt: %s",
3302 llvm::toString(int_value_or_err.takeError()).c_str()));
3303 }
3304 } else {
3305 if (is_integer) {
3306 auto int_value_or_err = GetValueAsAPSInt();
3307 if (int_value_or_err) {
3308 Scalar scalar_int(*int_value_or_err);
3309 llvm::APFloat f = scalar_int.CreateAPFloatFromAPSInt(
3311 return ValueObject::CreateValueObjectFromAPFloat(target, f, type,
3312 "result");
3313 } else {
3317 "cannot get value as APSInt: %s",
3318 llvm::toString(int_value_or_err.takeError()).c_str()));
3319 }
3320 }
3321 if (is_float) {
3322 auto float_value_or_err = GetValueAsAPFloat();
3323 if (float_value_or_err) {
3324 Scalar scalar_float(*float_value_or_err);
3325 llvm::APFloat f = scalar_float.CreateAPFloatFromAPFloat(
3327 return ValueObject::CreateValueObjectFromAPFloat(target, f, type,
3328 "result");
3329 } else {
3333 "cannot get value as APFloat: %s",
3334 llvm::toString(float_value_or_err.takeError()).c_str()));
3335 }
3336 }
3337 }
3338 }
3339
3342 Status::FromErrorString("Unable to perform requested cast"));
3343}
3344
3346 bool is_enum = GetCompilerType().IsEnumerationType();
3347 bool is_integer = GetCompilerType().IsInteger();
3348 bool is_float = GetCompilerType().IsFloat();
3350
3351 if (!is_enum && !is_integer && !is_float)
3355 "argument must be an integer, a float, or an enum"));
3356
3357 if (!type.IsEnumerationType())
3360 Status::FromErrorString("target type must be an enum"));
3361
3362 lldb::TargetSP target = GetTargetSP();
3363 uint64_t byte_size = 0;
3364 if (auto temp = type.GetByteSize(target.get()))
3365 byte_size = temp.value();
3366
3367 if (is_float) {
3368 llvm::APSInt integer(byte_size * CHAR_BIT, !type.IsSigned());
3369 bool is_exact;
3370 auto value_or_err = GetValueAsAPFloat();
3371 if (value_or_err) {
3372 llvm::APFloatBase::opStatus status = value_or_err->convertToInteger(
3373 integer, llvm::APFloat::rmTowardZero, &is_exact);
3374
3375 // Casting floating point values that are out of bounds of the target
3376 // type is undefined behaviour.
3377 if (status & llvm::APFloatBase::opInvalidOp)
3381 "invalid type cast detected: %s",
3382 llvm::toString(value_or_err.takeError()).c_str()));
3384 "result");
3385 } else
3388 Status::FromErrorString("cannot get value as APFloat"));
3389 } else {
3390 // Get the value as APSInt and extend or truncate it to the requested size.
3391 auto value_or_err = GetValueAsAPSInt();
3392 if (value_or_err) {
3393 llvm::APSInt ext = value_or_err->extOrTrunc(byte_size * CHAR_BIT);
3394 return ValueObject::CreateValueObjectFromAPInt(target, ext, type,
3395 "result");
3396 } else
3400 "cannot get value as APSInt: %s",
3401 llvm::toString(value_or_err.takeError()).c_str()));
3402 }
3405 Status::FromErrorString("Cannot perform requested cast"));
3406}
3407
3408ValueObject::EvaluationPoint::EvaluationPoint() : m_mod_id(), m_exe_ctx_ref() {}
3409
3411 bool use_selected)
3412 : m_mod_id(), m_exe_ctx_ref() {
3413 ExecutionContext exe_ctx(exe_scope);
3414 TargetSP target_sp(exe_ctx.GetTargetSP());
3415 if (target_sp) {
3416 m_exe_ctx_ref.SetTargetSP(target_sp);
3417 ProcessSP process_sp(exe_ctx.GetProcessSP());
3418 if (!process_sp)
3419 process_sp = target_sp->GetProcessSP();
3420
3421 if (process_sp) {
3422 m_mod_id = process_sp->GetModID();
3423 m_exe_ctx_ref.SetProcessSP(process_sp);
3424
3425 ThreadSP thread_sp(exe_ctx.GetThreadSP());
3426
3427 if (!thread_sp) {
3428 if (use_selected)
3429 thread_sp = process_sp->GetThreadList().GetSelectedThread();
3430 }
3431
3432 if (thread_sp) {
3433 m_exe_ctx_ref.SetThreadSP(thread_sp);
3434
3435 StackFrameSP frame_sp(exe_ctx.GetFrameSP());
3436 if (!frame_sp) {
3437 if (use_selected)
3438 frame_sp = thread_sp->GetSelectedFrame(DoNoSelectMostRelevantFrame);
3439 }
3440 if (frame_sp)
3441 m_exe_ctx_ref.SetFrameSP(frame_sp);
3442 }
3443 }
3444 }
3445}
3446
3449 : m_mod_id(), m_exe_ctx_ref(rhs.m_exe_ctx_ref) {}
3450
3452
3453// This function checks the EvaluationPoint against the current process state.
3454// If the current state matches the evaluation point, or the evaluation point
3455// is already invalid, then we return false, meaning "no change". If the
3456// current state is different, we update our state, and return true meaning
3457// "yes, change". If we did see a change, we also set m_needs_update to true,
3458// so future calls to NeedsUpdate will return true. exe_scope will be set to
3459// the current execution context scope.
3460
3462 bool accept_invalid_exe_ctx) {
3463 // Start with the target, if it is NULL, then we're obviously not going to
3464 // get any further:
3465 const bool thread_and_frame_only_if_stopped = true;
3466 ExecutionContext exe_ctx(
3467 m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
3468
3469 if (exe_ctx.GetTargetPtr() == nullptr)
3470 return false;
3471
3472 // If we don't have a process nothing can change.
3473 Process *process = exe_ctx.GetProcessPtr();
3474 if (process == nullptr)
3475 return false;
3476
3477 // If our stop id is the current stop ID, nothing has changed:
3478 ProcessModID current_mod_id = process->GetModID();
3479
3480 // If the current stop id is 0, either we haven't run yet, or the process
3481 // state has been cleared. In either case, we aren't going to be able to sync
3482 // with the process state.
3483 if (current_mod_id.GetStopID() == 0)
3484 return false;
3485
3486 bool changed = false;
3487 const bool was_valid = m_mod_id.IsValid();
3488 if (was_valid) {
3489 if (m_mod_id == current_mod_id) {
3490 // Everything is already up to date in this object, no need to update the
3491 // execution context scope.
3492 changed = false;
3493 } else {
3494 m_mod_id = current_mod_id;
3495 m_needs_update = true;
3496 changed = true;
3497 }
3498 }
3499
3500 // Now re-look up the thread and frame in case the underlying objects have
3501 // gone away & been recreated. That way we'll be sure to return a valid
3502 // exe_scope. If we used to have a thread or a frame but can't find it
3503 // anymore, then mark ourselves as invalid.
3504
3505 if (!accept_invalid_exe_ctx) {
3506 if (m_exe_ctx_ref.HasThreadRef()) {
3507 ThreadSP thread_sp(m_exe_ctx_ref.GetThreadSP());
3508 if (thread_sp) {
3509 if (m_exe_ctx_ref.HasFrameRef()) {
3510 StackFrameSP frame_sp(m_exe_ctx_ref.GetFrameSP());
3511 if (!frame_sp) {
3512 // We used to have a frame, but now it is gone
3513 SetInvalid();
3514 changed = was_valid;
3515 }
3516 }
3517 } else {
3518 // We used to have a thread, but now it is gone
3519 SetInvalid();
3520 changed = was_valid;
3521 }
3522 }
3523 }
3524
3525 return changed;
3526}
3527
3529 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3530 if (process_sp)
3531 m_mod_id = process_sp->GetModID();
3532 m_needs_update = false;
3533}
3534
3535void ValueObject::ClearUserVisibleData(uint32_t clear_mask) {
3536 if ((clear_mask & eClearUserVisibleDataItemsValue) ==
3538 m_value_str.clear();
3539
3540 if ((clear_mask & eClearUserVisibleDataItemsLocation) ==
3542 m_location_str.clear();
3543
3544 if ((clear_mask & eClearUserVisibleDataItemsSummary) ==
3546 m_summary_str.clear();
3547
3548 if ((clear_mask & eClearUserVisibleDataItemsDescription) ==
3550 m_object_desc_str.clear();
3551
3555 m_synthetic_value = nullptr;
3556 }
3557}
3558
3560 if (m_parent) {
3563 }
3564 return nullptr;
3565}
3566
3569 llvm::StringRef expression,
3570 const ExecutionContext &exe_ctx) {
3571 return CreateValueObjectFromExpression(name, expression, exe_ctx,
3573}
3574
3576 llvm::StringRef name, llvm::StringRef expression,
3577 const ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options) {
3578 lldb::ValueObjectSP retval_sp;
3579 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
3580 if (!target_sp)
3581 return retval_sp;
3582 if (expression.empty())
3583 return retval_sp;
3584 target_sp->EvaluateExpression(expression, exe_ctx.GetFrameSP().get(),
3585 retval_sp, options);
3586 if (retval_sp && !name.empty())
3587 retval_sp->SetName(ConstString(name));
3588 return retval_sp;
3589}
3590
3592 llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx,
3593 CompilerType type, bool do_deref) {
3594 if (type) {
3595 CompilerType pointer_type(type.GetPointerType());
3596 if (!do_deref)
3597 pointer_type = type;
3598 if (pointer_type) {
3599 lldb::DataBufferSP buffer(
3600 new lldb_private::DataBufferHeap(&address, sizeof(lldb::addr_t)));
3602 exe_ctx.GetBestExecutionContextScope(), pointer_type,
3603 ConstString(name), buffer, exe_ctx.GetByteOrder(),
3604 exe_ctx.GetAddressByteSize()));
3605 if (ptr_result_valobj_sp) {
3606 if (do_deref)
3607 ptr_result_valobj_sp->GetValue().SetValueType(
3609 Status err;
3610 if (do_deref)
3611 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
3612 if (ptr_result_valobj_sp && !name.empty())
3613 ptr_result_valobj_sp->SetName(ConstString(name));
3614 }
3615 return ptr_result_valobj_sp;
3616 }
3617 }
3618 return lldb::ValueObjectSP();
3619}
3620
3622 llvm::StringRef name, const DataExtractor &data,
3623 const ExecutionContext &exe_ctx, CompilerType type) {
3624 lldb::ValueObjectSP new_value_sp;
3625 new_value_sp = ValueObjectConstResult::Create(
3626 exe_ctx.GetBestExecutionContextScope(), type, ConstString(name), data,
3628 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
3629 if (new_value_sp && !name.empty())
3630 new_value_sp->SetName(ConstString(name));
3631 return new_value_sp;
3632}
3633
3636 const llvm::APInt &v, CompilerType type,
3637 llvm::StringRef name) {
3638 ExecutionContext exe_ctx(target.get(), false);
3639 uint64_t byte_size = 0;
3640 if (auto temp = type.GetByteSize(target.get()))
3641 byte_size = temp.value();
3642 lldb::DataExtractorSP data_sp = std::make_shared<DataExtractor>(
3643 reinterpret_cast<const void *>(v.getRawData()), byte_size,
3644 exe_ctx.GetByteOrder(), exe_ctx.GetAddressByteSize());
3645 return ValueObject::CreateValueObjectFromData(name, *data_sp, exe_ctx, type);
3646}
3647
3649 lldb::TargetSP target, const llvm::APFloat &v, CompilerType type,
3650 llvm::StringRef name) {
3651 return CreateValueObjectFromAPInt(target, v.bitcastToAPInt(), type, name);
3652}
3653
3656 llvm::StringRef name) {
3657 CompilerType target_type;
3658 if (target) {
3659 for (auto type_system_sp : target->GetScratchTypeSystems())
3660 if (auto compiler_type =
3661 type_system_sp->GetBasicTypeFromAST(lldb::eBasicTypeBool)) {
3662 target_type = compiler_type;
3663 break;
3664 }
3665 }
3666 ExecutionContext exe_ctx(target.get(), false);
3667 uint64_t byte_size = 0;
3668 if (auto temp = target_type.GetByteSize(target.get()))
3669 byte_size = temp.value();
3670 lldb::DataExtractorSP data_sp = std::make_shared<DataExtractor>(
3671 reinterpret_cast<const void *>(&value), byte_size, exe_ctx.GetByteOrder(),
3672 exe_ctx.GetAddressByteSize());
3673 return ValueObject::CreateValueObjectFromData(name, *data_sp, exe_ctx,
3674 target_type);
3675}
3676
3678 lldb::TargetSP target, CompilerType type, llvm::StringRef name) {
3679 if (!type.IsNullPtrType()) {
3680 lldb::ValueObjectSP ret_val;
3681 return ret_val;
3682 }
3683 uintptr_t zero = 0;
3684 ExecutionContext exe_ctx(target.get(), false);
3685 uint64_t byte_size = 0;
3686 if (auto temp = type.GetByteSize(target.get()))
3687 byte_size = temp.value();
3688 lldb::DataExtractorSP data_sp = std::make_shared<DataExtractor>(
3689 reinterpret_cast<const void *>(zero), byte_size, exe_ctx.GetByteOrder(),
3690 exe_ctx.GetAddressByteSize());
3691 return ValueObject::CreateValueObjectFromData(name, *data_sp, exe_ctx, type);
3692}
3693
3695 ValueObject *root(GetRoot());
3696 if (root != this)
3697 return root->GetModule();
3698 return lldb::ModuleSP();
3699}
3700
3702 if (m_root)
3703 return m_root;
3704 return (m_root = FollowParentChain([](ValueObject *vo) -> bool {
3705 return (vo->m_parent != nullptr);
3706 }));
3707}
3708
3711 ValueObject *vo = this;
3712 while (vo) {
3713 if (!f(vo))
3714 break;
3715 vo = vo->m_parent;
3716 }
3717 return vo;
3718}
3719
3722 ValueObject *root(GetRoot());
3723 if (root != this)
3724 return root->GetAddressTypeOfChildren();
3725 }
3727}
3728
3730 ValueObject *with_dv_info = this;
3731 while (with_dv_info) {
3732 if (with_dv_info->HasDynamicValueTypeInfo())
3733 return with_dv_info->GetDynamicValueTypeImpl();
3734 with_dv_info = with_dv_info->m_parent;
3735 }
3737}
3738
3740 const ValueObject *with_fmt_info = this;
3741 while (with_fmt_info) {
3742 if (with_fmt_info->m_format != lldb::eFormatDefault)
3743 return with_fmt_info->m_format;
3744 with_fmt_info = with_fmt_info->m_parent;
3745 }
3746 return m_format;
3747}
3748
3752 if (GetRoot()) {
3753 if (GetRoot() == this) {
3754 if (StackFrameSP frame_sp = GetFrameSP()) {
3755 const SymbolContext &sc(
3756 frame_sp->GetSymbolContext(eSymbolContextCompUnit));
3757 if (CompileUnit *cu = sc.comp_unit)
3758 type = cu->GetLanguage();
3759 }
3760 } else {
3762 }
3763 }
3764 }
3765 return (m_preferred_display_language = type); // only compute it once
3766}
3767
3771}
3772
3774 // we need to support invalid types as providers of values because some bare-
3775 // board debugging scenarios have no notion of types, but still manage to
3776 // have raw numeric values for things like registers. sigh.
3778 return (!type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
3779}
3780
3782 if (!UpdateValueIfNeeded())
3783 return nullptr;
3784
3785 TargetSP target_sp(GetTargetSP());
3786 if (!target_sp)
3787 return nullptr;
3788
3789 PersistentExpressionState *persistent_state =
3790 target_sp->GetPersistentExpressionStateForLanguage(
3792
3793 if (!persistent_state)
3794 return nullptr;
3795
3796 ConstString name = persistent_state->GetNextPersistentVariableName();
3797
3798 ValueObjectSP const_result_sp =
3799 ValueObjectConstResult::Create(target_sp.get(), GetValue(), name);
3800
3801 ExpressionVariableSP persistent_var_sp =
3802 persistent_state->CreatePersistentVariable(const_result_sp);
3803 persistent_var_sp->m_live_sp = persistent_var_sp->m_frozen_sp;
3804 persistent_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference;
3805
3806 return persistent_var_sp->GetValueObject();
3807}
3808
3810 return ValueObjectVTable::Create(*this);
3811}
static llvm::raw_ostream & error(Stream &strm)
#define integer
#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
Definition: ValueObject.cpp:78
static const char * ConvertBoolean(lldb::LanguageType language_type, const char *value_str)
static bool CopyStringDataToBufferSP(const StreamString &source, lldb::WritableDataBufferSP &destination)
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:313
An architecture specification class.
Definition: ArchSpec.h:31
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition: ArchSpec.cpp:709
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Definition: ArchSpec.cpp:756
void ManageObject(T *new_object)
Definition: SharedCluster.h:33
A class that describes a compilation unit.
Definition: CompileUnit.h:43
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
bool IsEnumerationType(bool &is_signed) const
lldb::BasicType GetBasicTypeEnumeration() const
bool IsPossibleDynamicType(CompilerType *target_type, bool check_cplusplus, bool check_objc) const
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
lldb::Encoding GetEncoding(uint64_t &count) 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.
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
uint32_t GetIndexOfChildWithName(llvm::StringRef name, bool omit_empty_base_classes) const
Lookup a child given a name.
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.
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
bool CompareTypes(CompilerType rhs) const
CompilerType GetCanonicalType() 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.
Definition: ConstString.h:188
bool IsEmpty() const
Test for empty string.
Definition: ConstString.h:304
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:197
void SetString(llvm::StringRef s)
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
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.
Definition: DataExtractor.h:48
const uint8_t * PeekData(lldb::offset_t offset, lldb::offset_t length) const
Peek at a bytes at offset.
void SetByteOrder(lldb::ByteOrder byte_order)
Set the byte_order value.
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
uint64_t GetAddress(lldb::offset_t *offset_ptr) const
Extract an address from *offset_ptr.
void Checksum(llvm::SmallVectorImpl< uint8_t > &dest, uint64_t max_data=0)
const uint8_t * GetDataStart() const
Get the data start pointer.
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
void SetThreadSP(const lldb::ThreadSP &thread_sp)
Set accessor that creates a weak reference to the thread referenced in thread_sp.
void SetFrameSP(const lldb::StackFrameSP &frame_sp)
Set accessor that creates a weak reference to the frame referenced in frame_sp.
void SetTargetSP(const lldb::TargetSP &target_sp)
Set accessor that creates a weak reference to the target referenced in target_sp.
void SetProcessSP(const lldb::ProcessSP &process_sp)
Set accessor that creates a weak reference to the process referenced in process_sp.
"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:336
static bool LanguageIsObjC(lldb::LanguageType language)
Definition: Language.cpp:314
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:251
bool IsValid() const
Definition: Process.h:269
A plug-in interface definition class for debugging a process.
Definition: Process.h:343
ProcessModID GetModID() const
Get the Modification ID of the process.
Definition: Process.h:1447
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition: Process.cpp:1953
bool IsPossibleDynamicValue(ValueObject &in_value)
Definition: Process.cpp:1558
LanguageRuntime * GetLanguageRuntime(lldb::LanguageType language)
Definition: Process.cpp:1530
size_t WriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size, Status &error)
Write memory to a process.
Definition: Process.cpp:2275
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:2357
llvm::APFloat CreateAPFloatFromAPFloat(lldb::BasicType basic_type)
Definition: Scalar.cpp:833
llvm::APFloat CreateAPFloatFromAPSInt(lldb::BasicType basic_type)
Definition: Scalar.cpp:813
Status SetValueFromData(const DataExtractor &data, lldb::Encoding encoding, size_t byte_size)
Definition: Scalar.cpp:701
unsigned long long ULongLong(unsigned long long fail_value=0) const
Definition: Scalar.cpp:335
llvm::APFloat GetAPFloat() const
Definition: Scalar.h:186
bool GetData(DataExtractor &data, size_t limit_byte_size=UINT32_MAX) const
Definition: Scalar.cpp:85
long long SLongLong(long long fail_value=0) const
Definition: Scalar.cpp:331
bool ExtractBitfield(uint32_t bit_size, uint32_t bit_offset)
Definition: Scalar.cpp:796
Status SetValueFromCString(const char *s, lldb::Encoding encoding, size_t byte_size)
Definition: Scalar.cpp:631
bool IsValid() const
Definition: Scalar.h:107
llvm::APSInt GetAPSInt() const
Definition: Scalar.h:184
An error handling class.
Definition: Status.h:115
void Clear()
Clear the object state.
Definition: Status.cpp:215
Status Clone() const
Don't call this function in new code.
Definition: Status.h:171
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition: Status.cpp:106
static Status FromErrorString(const char *str)
Definition: Status.h:138
bool Fail() const
Test for error condition.
Definition: Status.cpp:270
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:195
bool Success() const
Test for success condition.
Definition: Status.cpp:280
const char * GetData() const
Definition: StreamString.h:45
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:209
"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.
Definition: SymbolContext.h:34
CompileUnit * comp_unit
The CompileUnit for a given query.
uint32_t GetMaximumSizeOfStringSummary() const
Definition: Target.cpp:4798
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)
Definition: Target.cpp:1956
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
Definition: TypeSummary.cpp:29
TypeSummaryOptions & SetLanguage(lldb::LanguageType)
Definition: TypeSummary.cpp:35
static lldb::ValueObjectSP Create(ValueObject &parent, ConstString name, const CompilerType &cast_type)
A child of another ValueObject.
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)
ValueObject * GetChildAtIndex(uint32_t idx)
Definition: ValueObject.h:880
void SetChildAtIndex(size_t idx, ValueObject *valobj)
Definition: ValueObject.h:886
bool SyncWithProcessState(bool accept_invalid_exe_ctx)
AddressType m_address_type_of_ptr_or_ref_children
Definition: ValueObject.h:971
void SetValueIsValid(bool valid)
Definition: ValueObject.h:1059
EvaluationPoint m_update_point
Stores both the stop id and the full context at which this value was last updated.
Definition: ValueObject.h:922
lldb::TypeSummaryImplSP GetSummaryFormat()
Definition: ValueObject.h:788
llvm::SmallVector< uint8_t, 16 > m_value_checksum
Definition: ValueObject.h:973
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()
Definition: ValueObject.h:424
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.
Definition: ValueObject.h:943
virtual bool IsInScope()
Definition: ValueObject.h:420
lldb::ValueObjectSP Cast(const CompilerType &compiler_type)
const EvaluationPoint & GetUpdatePoint() const
Definition: ValueObject.h:326
void AddSyntheticChild(ConstString key, ValueObject *valobj)
virtual uint64_t GetData(DataExtractor &data, Status &error)
uint32_t m_last_format_mgr_revision
Definition: ValueObject.h:966
friend class ValueObjectSynthetic
Definition: ValueObject.h:1010
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
Definition: ValueObject.h:958
virtual lldb::ValueObjectSP GetChildAtIndex(uint32_t idx, bool can_create=true)
virtual lldb::DynamicValueType GetDynamicValueTypeImpl()
Definition: ValueObject.h:1031
static lldb::ValueObjectSP CreateValueObjectFromBool(lldb::TargetSP target, bool value, llvm::StringRef name)
Create a value object containing the given boolean value.
lldb::addr_t GetPointerValue(AddressType *address_type=nullptr)
virtual bool GetIsConstant() const
Definition: ValueObject.h:764
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()
Definition: ValueObject.h:402
CompilerType GetCompilerType()
Definition: ValueObject.h:352
virtual ValueObject * CreateSyntheticArrayMember(size_t idx)
Should only be called by ValueObject::GetSyntheticArrayMember().
void SetValueFormat(lldb::TypeFormatImplSP format)
Definition: ValueObject.h:802
virtual void CalculateSyntheticValue()
void SetPreferredDisplayLanguage(lldb::LanguageType lt)
Definition: ValueObject.h:784
struct lldb_private::ValueObject::Bitflags m_flags
ValueObject(ExecutionContextScope *exe_scope, ValueObjectManager &manager, AddressType child_ptr_or_ref_addr_type=eAddressTypeLoad)
Use this constructor to create a "root variable object".
Definition: ValueObject.cpp:92
std::string m_summary_str
Cached summary string that will get cleared if/when the value is updated.
Definition: ValueObject.h:938
virtual lldb::ValueObjectSP DoCast(const CompilerType &compiler_type)
lldb::ValueObjectSP GetSP()
Definition: ValueObject.h:569
ChildrenManager m_children
Definition: ValueObject.h:953
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.
Definition: ValueObject.h:930
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....
Definition: ValueObject.h:951
lldb::ValueObjectSP GetSyntheticBitFieldChild(uint32_t from, uint32_t to, bool can_create)
lldb::ProcessSP GetProcessSP() const
Definition: ValueObject.h:338
lldb::ValueObjectSP GetSyntheticChild(ConstString key) const
@ eExpressionPathScanEndReasonArrowInsteadOfDot
-> used when . should be used.
Definition: ValueObject.h:135
@ eExpressionPathScanEndReasonDereferencingFailed
Impossible to apply * operator.
Definition: ValueObject.h:151
@ eExpressionPathScanEndReasonNoSuchChild
Child element not found.
Definition: ValueObject.h:127
@ eExpressionPathScanEndReasonDotInsteadOfArrow
. used when -> should be used.
Definition: ValueObject.h:133
@ eExpressionPathScanEndReasonEndOfString
Out of data to parse.
Definition: ValueObject.h:125
@ eExpressionPathScanEndReasonBitfieldRangeOperatorMet
[] is good for bitfields, but I cannot parse after it.
Definition: ValueObject.h:145
@ eExpressionPathScanEndReasonRangeOperatorNotAllowed
[] not allowed by options.
Definition: ValueObject.h:139
@ eExpressionPathScanEndReasonEmptyRangeNotAllowed
[] only allowed for arrays.
Definition: ValueObject.h:131
@ eExpressionPathScanEndReasonRangeOperatorInvalid
[] not valid on objects other than scalars, pointers or arrays.
Definition: ValueObject.h:141
@ eExpressionPathScanEndReasonUnexpectedSymbol
Something is malformed in he expression.
Definition: ValueObject.h:147
@ eExpressionPathScanEndReasonArrayRangeOperatorMet
[] is good for arrays, but I cannot parse it.
Definition: ValueObject.h:143
@ eExpressionPathScanEndReasonSyntheticValueMissing
getting the synthetic children failed.
Definition: ValueObject.h:155
@ eExpressionPathScanEndReasonTakingAddressFailed
Impossible to apply & operator.
Definition: ValueObject.h:149
@ eExpressionPathScanEndReasonFragileIVarNotAllowed
ObjC ivar expansion not allowed.
Definition: ValueObject.h:137
virtual bool UpdateValue()=0
lldb::Format GetFormat() const
virtual lldb::VariableSP GetVariable()
Definition: ValueObject.h:860
@ eExpressionPathAftermathNothing
Just return it.
Definition: ValueObject.h:175
@ eExpressionPathAftermathDereference
Dereference the target.
Definition: ValueObject.h:177
@ eExpressionPathAftermathTakeAddress
Take target's address.
Definition: ValueObject.h:179
lldb::ValueObjectSP CastToBasicType(CompilerType type)
virtual std::optional< uint64_t > GetByteSize()=0
virtual size_t GetIndexOfChildWithName(llvm::StringRef name)
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.
Definition: ValueObject.h:926
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 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 bool IsDynamic()
Definition: ValueObject.h:683
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
Definition: ValueObject.h:346
friend class ValueObjectChild
Definition: ValueObject.h:1006
lldb::ValueObjectSP GetChildAtNamePath(llvm::ArrayRef< llvm::StringRef > names)
void SetSummaryFormat(lldb::TypeSummaryImplSP format)
Definition: ValueObject.h:793
virtual bool IsRuntimeSupportValue()
virtual ConstString GetTypeName()
Definition: ValueObject.h:365
DataExtractor & GetDataExtractor()
static lldb::ValueObjectSP CreateValueObjectFromData(llvm::StringRef name, const DataExtractor &data, const ExecutionContext &exe_ctx, CompilerType type)
void SetValueDidChange(bool value_changed)
Definition: ValueObject.h:1055
ValueObject * m_root
The root of the hierarchy for this ValueObject (or nullptr if never calculated).
Definition: ValueObject.h:918
lldb::addr_t GetLoadAddress()
Return the target load address associated with this value object.
bool GetValueIsValid() const
Definition: ValueObject.h:559
virtual lldb::ModuleSP GetModule()
Return the module associated with this value object in case the value is from an executable file and ...
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
Definition: ValueObject.h:975
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr)
Definition: ValueObject.h:378
virtual llvm::Expected< uint32_t > CalculateNumChildren(uint32_t max=UINT32_MAX)=0
Should only be called by ValueObject::GetNumChildren().
lldb::LanguageType GetObjectRuntimeLanguage()
Definition: ValueObject.h:373
virtual lldb::ValueObjectSP CreateConstantValue(ConstString name)
virtual lldb::addr_t GetAddressOf(bool scalar_is_load_address=true, AddressType *address_type=nullptr)
virtual bool IsLogicalTrue(Status &error)
lldb::Format m_last_format
Definition: ValueObject.h:965
virtual SymbolContextScope * GetSymbolContextScope()
virtual bool HasDynamicValueTypeInfo()
Definition: ValueObject.h:1035
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
Definition: ValueObject.h:957
void SetNumChildren(uint32_t num_children)
ValueObject * m_parent
The parent value object, or nullptr if this has no parent.
Definition: ValueObject.h:915
virtual bool IsBaseClass()
Definition: ValueObject.h:398
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...
Definition: ValueObject.h:962
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
Definition: ValueObject.h:968
lldb::TargetSP GetTargetSP() const
Definition: ValueObject.h:334
@ eExpressionPathEndResultTypePlain
Anything but...
Definition: ValueObject.h:161
@ eExpressionPathEndResultTypeBoundedRange
A range [low-high].
Definition: ValueObject.h:165
@ eExpressionPathEndResultTypeBitfield
A bitfield.
Definition: ValueObject.h:163
@ eExpressionPathEndResultTypeUnboundedRange
A range [].
Definition: ValueObject.h:167
virtual lldb::ValueObjectSP Dereference(Status &error)
void SetPreferredDisplayLanguageIfNeeded(lldb::LanguageType)
virtual const char * GetValueAsCString()
bool HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display, lldb::Format custom_format)
virtual const char * GetLocationAsCString()
Definition: ValueObject.h:522
ConstString GetName() const
Definition: ValueObject.h:487
std::string m_location_str
Cached location string that will get cleared if/when the value is updated.
Definition: ValueObject.h:936
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()
Definition: ValueObject.h:604
lldb::ValueObjectSP Persist()
std::string m_object_desc_str
Cached result of the "object printer".
Definition: ValueObject.h:941
virtual ValueObject * GetParent()
Definition: ValueObject.h:828
virtual CompilerType MaybeCalculateCompleteType()
lldb::SyntheticChildrenSP m_synthetic_children_sp
Definition: ValueObject.h:969
virtual uint32_t GetBitfieldBitOffset()
Definition: ValueObject.h:426
llvm::Expected< std::string > GetObjectDescription()
std::string m_old_value_str
Cached old value string from the last time the value was gotten.
Definition: ValueObject.h:934
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)
@ eValueObjectRepresentationStyleLanguageSpecific
Definition: ValueObject.h:115
std::string m_value_str
Cached value string that will get cleared if/when the value is updated.
Definition: ValueObject.h:932
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)
Definition: ValueObject.h:812
ConstString m_name
The name of this object.
Definition: ValueObject.h:924
const char * GetLocationAsCStringImpl(const Value &value, const DataExtractor &data)
virtual void SetFormat(lldb::Format format)
Definition: ValueObject.h:776
ValueObject * m_dynamic_value
Definition: ValueObject.h:956
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()
Definition: ValueObject.h:612
std::map< ConstString, ValueObject * > m_synthetic_children
Definition: ValueObject.h:954
const ExecutionContextRef & GetExecutionContextRef() const
Definition: ValueObject.h:330
uint32_t GetNumChildrenIgnoringErrors(uint32_t max=UINT32_MAX)
Like GetNumChildren but returns 0 on error.
virtual bool CanProvideValue()
const Value & GetValue() const
Definition: ValueObject.h:511
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
Definition: Value.h:112
Status GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, Module *module)
Definition: Value.cpp:315
RegisterInfo * GetRegisterInfo() const
Definition: Value.cpp:140
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).
@ FileAddress
A file address value.
@ LoadAddress
A load address value.
@ Scalar
A raw scalar value.
ValueType GetValueType() const
Definition: Value.cpp:109
Scalar & ResolveValue(ExecutionContext *exe_ctx, Module *module=nullptr)
Definition: Value.cpp:582
@ RegisterInfo
RegisterInfo * (can be a scalar or a vector register).
ContextType GetContextType() const
Definition: Value.h:87
AddressType GetValueAddressType() const
Definition: Value.cpp:111
const CompilerType & GetCompilerType()
Definition: Value.cpp:239
uint8_t * GetBytes()
Get a pointer to the data.
Definition: DataBuffer.h:108
static bool ReadBufferAndDumpToStream(const ReadBufferAndDumpToStreamOptions &options)
#define UINT64_MAX
Definition: lldb-defines.h:23
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
#define UINT32_MAX
Definition: lldb-defines.h:19
@ DoNoSelectMostRelevantFrame
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.
const char * toString(AppleArm64ExceptionClass EC)
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
Definition: lldb-forward.h:424
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
Definition: lldb-forward.h:475
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:450
std::shared_ptr< lldb_private::TypeFormatImpl > TypeFormatImplSP
Definition: lldb-forward.h:472
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:484
std::shared_ptr< lldb_private::ExpressionVariable > ExpressionVariableSP
Definition: lldb-forward.h:351
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...
@ eFormatUnicode16
@ eFormatVectorOfUInt128
@ eFormatVectorOfUInt8
@ eFormatComplexFloat
@ eFormatVectorOfFloat32
@ eFormatVectorOfSInt32
@ eFormatUnicode32
@ eFormatVectorOfSInt8
@ eFormatVectorOfUInt16
@ eFormatHexUppercase
@ eFormatVectorOfFloat64
@ eFormatCharPrintable
Only printable characters, '.' if not printable.
@ eFormatComplexInteger
Integer complex type.
@ eFormatVectorOfSInt16
@ 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
Definition: lldb-forward.h:461
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:389
Encoding
Register encoding definitions.
@ eEncodingVector
vector registers
@ eByteOrderInvalid
std::shared_ptr< lldb_private::SyntheticChildren > SyntheticChildrenSP
Definition: lldb-forward.h:445
uint64_t user_id_t
Definition: lldb-types.h:82
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:336
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
Definition: lldb-forward.h:337
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:448
@ eDynamicDontRunTarget
@ eDynamicCanRunTarget
@ eNoDynamicValues
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
Definition: lldb-forward.h:338
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:373
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.