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