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