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 true;
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.Printf("%s @ %s", GetTypeName().AsCString(),
1562 str = strm.GetString();
1563 } else
1564 str = GetValueAsCString();
1565 }
1566 }
1567
1568 if (!str.empty())
1569 s << str;
1570 else {
1571 // We checked for errors at the start, but do it again here in case
1572 // realizing the value for dumping produced an error.
1573 if (m_error.Fail()) {
1574 if (do_dump_error)
1575 s.Printf("<%s>", m_error.AsCString());
1576 else
1577 return false;
1578 } else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1579 s.PutCString("<no summary available>");
1580 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1581 s.PutCString("<no value available>");
1582 else if (val_obj_display ==
1584 s.PutCString("<not a valid Objective-C object>"); // edit this if we
1585 // have other runtimes
1586 // that support a
1587 // description
1588 else
1589 s.PutCString("<no printable representation>");
1590 }
1591
1592 // we should only return false here if we could not do *anything* even if
1593 // we have an error message as output, that's a success from our callers'
1594 // perspective, so return true
1595 var_success = true;
1596
1597 if (custom_format != eFormatInvalid)
1599 }
1600
1601 return var_success;
1602}
1603
1605ValueObject::GetAddressOf(bool scalar_is_load_address) {
1606 // Can't take address of a bitfield
1607 if (IsBitfield())
1608 return {};
1609
1610 if (!UpdateValueIfNeeded(false))
1611 return {};
1612
1613 switch (m_value.GetValueType()) {
1615 return {};
1617 if (scalar_is_load_address) {
1618 return {m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS),
1620 }
1621 return {};
1622
1625 return {m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS),
1626 m_value.GetValueAddressType()};
1628 return {LLDB_INVALID_ADDRESS, m_value.GetValueAddressType()};
1629 }
1630 llvm_unreachable("Unhandled value type!");
1631}
1632
1633std::optional<addr_t> ValueObject::GetStrippedPointerValue(addr_t address) {
1634 if (GetCompilerType().HasPointerAuthQualifier()) {
1636 if (Process *process = exe_ctx.GetProcessPtr())
1637 if (ABISP abi_sp = process->GetABI())
1638 return abi_sp->FixCodeAddress(address);
1639 }
1640 return std::nullopt;
1641}
1642
1644 if (!UpdateValueIfNeeded(false))
1645 return {};
1646
1647 switch (m_value.GetValueType()) {
1649 return {};
1651 return {m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS),
1653
1657 lldb::offset_t data_offset = 0;
1658 return {m_data.GetAddress(&data_offset), GetAddressTypeOfChildren()};
1659 }
1660 }
1661
1662 llvm_unreachable("Unhandled value type!");
1663}
1664
1665static const char *ConvertBoolean(lldb::LanguageType language_type,
1666 const char *value_str) {
1667 if (Language *language = Language::FindPlugin(language_type))
1668 if (auto boolean = language->GetBooleanFromString(value_str))
1669 return *boolean ? "1" : "0";
1670
1671 return llvm::StringSwitch<const char *>(value_str)
1672 .Case("true", "1")
1673 .Case("false", "0")
1674 .Default(value_str);
1675}
1676
1677bool ValueObject::SetValueFromCString(const char *value_str, Status &error) {
1678 error.Clear();
1679 // Make sure our value is up to date first so that our location and location
1680 // type is valid.
1681 if (!UpdateValueIfNeeded(false)) {
1682 error = Status::FromErrorString("unable to read value");
1683 return false;
1684 }
1685
1686 const Encoding encoding = GetCompilerType().GetEncoding();
1687
1688 const size_t byte_size = llvm::expectedToOptional(GetByteSize()).value_or(0);
1689
1690 Value::ValueType value_type = m_value.GetValueType();
1691
1692 if (value_type == Value::ValueType::Scalar) {
1693 // If the value is already a scalar, then let the scalar change itself:
1694 m_value.GetScalar().SetValueFromCString(value_str, encoding, byte_size);
1695 } else if (byte_size <= 16) {
1696 if (GetCompilerType().IsBoolean())
1697 value_str = ConvertBoolean(GetObjectRuntimeLanguage(), value_str);
1698
1699 // If the value fits in a scalar, then make a new scalar and again let the
1700 // scalar code do the conversion, then figure out where to put the new
1701 // value.
1702 Scalar new_scalar;
1703 error = new_scalar.SetValueFromCString(value_str, encoding, byte_size);
1704 if (error.Success()) {
1705 switch (value_type) {
1707 // If it is a load address, then the scalar value is the storage
1708 // location of the data, and we have to shove this value down to that
1709 // load location.
1711 Process *process = exe_ctx.GetProcessPtr();
1712 if (process) {
1713 addr_t target_addr =
1714 m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1715 size_t bytes_written = process->WriteScalarToMemory(
1716 target_addr, new_scalar, byte_size, error);
1717 if (!error.Success())
1718 return false;
1719 if (bytes_written != byte_size) {
1720 error = Status::FromErrorString("unable to write value to memory");
1721 return false;
1722 }
1723 }
1724 } break;
1726 // If it is a host address, then we stuff the scalar as a DataBuffer
1727 // into the Value's data.
1728 DataExtractor new_data;
1729 new_data.SetByteOrder(m_data.GetByteOrder());
1730
1731 DataBufferSP buffer_sp(new DataBufferHeap(byte_size, 0));
1732 m_data.SetData(buffer_sp, 0);
1733 bool success = new_scalar.GetData(new_data);
1734 if (success) {
1735 new_data.CopyByteOrderedData(
1736 0, byte_size, const_cast<uint8_t *>(m_data.GetDataStart()),
1737 byte_size, m_data.GetByteOrder());
1738 }
1739 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1740
1741 } break;
1743 error = Status::FromErrorString("invalid location");
1744 return false;
1747 break;
1748 }
1749 } else {
1750 return false;
1751 }
1752 } else {
1753 // We don't support setting things bigger than a scalar at present.
1754 error = Status::FromErrorString("unable to write aggregate data type");
1755 return false;
1756 }
1757
1758 // If we have reached this point, then we have successfully changed the
1759 // value.
1761 return true;
1762}
1763
1765 decl.Clear();
1766 return false;
1767}
1768
1772
1774 ValueObjectSP synthetic_child_sp;
1775 std::map<ConstString, ValueObject *>::const_iterator pos =
1776 m_synthetic_children.find(key);
1777 if (pos != m_synthetic_children.end())
1778 synthetic_child_sp = pos->second->GetSP();
1779 return synthetic_child_sp;
1780}
1781
1784 Process *process = exe_ctx.GetProcessPtr();
1785 if (process)
1786 return process->IsPossibleDynamicValue(*this);
1787 else
1788 return GetCompilerType().IsPossibleDynamicType(nullptr, true, true);
1789}
1790
1792 Process *process(GetProcessSP().get());
1793 if (!process)
1794 return false;
1795
1796 // We trust that the compiler did the right thing and marked runtime support
1797 // values as artificial.
1798 if (!GetVariable() || !GetVariable()->IsArtificial())
1799 return false;
1800
1801 if (auto *runtime = process->GetLanguageRuntime(GetVariable()->GetLanguage()))
1802 if (runtime->IsAllowedRuntimeValue(GetName()))
1803 return false;
1804
1805 return true;
1806}
1807
1810 return language->IsNilReference(*this);
1811 }
1812 return false;
1813}
1814
1817 return language->IsUninitializedReference(*this);
1818 }
1819 return false;
1820}
1821
1822// This allows you to create an array member using and index that doesn't not
1823// fall in the normal bounds of the array. Many times structure can be defined
1824// as: struct Collection {
1825// uint32_t item_count;
1826// Item item_array[0];
1827// };
1828// The size of the "item_array" is 1, but many times in practice there are more
1829// items in "item_array".
1830
1832 bool can_create) {
1833 ValueObjectSP synthetic_child_sp;
1834 if (IsPointerType() || IsArrayType()) {
1835 std::string index_str = llvm::formatv("[{0}]", index);
1836 ConstString index_const_str(index_str);
1837 // Check if we have already created a synthetic array member in this valid
1838 // object. If we have we will re-use it.
1839 synthetic_child_sp = GetSyntheticChild(index_const_str);
1840 if (!synthetic_child_sp) {
1841 ValueObject *synthetic_child;
1842 // We haven't made a synthetic array member for INDEX yet, so lets make
1843 // one and cache it for any future reference.
1844 synthetic_child = CreateSyntheticArrayMember(index);
1845
1846 // Cache the value if we got one back...
1847 if (synthetic_child) {
1848 AddSyntheticChild(index_const_str, synthetic_child);
1849 synthetic_child_sp = synthetic_child->GetSP();
1850 synthetic_child_sp->SetName(ConstString(index_str));
1851 synthetic_child_sp->m_flags.m_is_array_item_for_pointer = true;
1852 }
1853 }
1854 }
1855 return synthetic_child_sp;
1856}
1857
1859 bool can_create) {
1860 ValueObjectSP synthetic_child_sp;
1861 if (IsScalarType()) {
1862 std::string index_str = llvm::formatv("[{0}-{1}]", from, to);
1863 ConstString index_const_str(index_str);
1864 // Check if we have already created a synthetic array member in this valid
1865 // object. If we have we will re-use it.
1866 synthetic_child_sp = GetSyntheticChild(index_const_str);
1867 if (!synthetic_child_sp) {
1868 uint32_t bit_field_size = to - from + 1;
1869 uint32_t bit_field_offset = from;
1870 if (GetDataExtractor().GetByteOrder() == eByteOrderBig)
1871 bit_field_offset =
1872 llvm::expectedToOptional(GetByteSize()).value_or(0) * 8 -
1873 bit_field_size - bit_field_offset;
1874 // We haven't made a synthetic array member for INDEX yet, so lets make
1875 // one and cache it for any future reference.
1876 ValueObjectChild *synthetic_child = new ValueObjectChild(
1877 *this, GetCompilerType(), index_const_str,
1878 llvm::expectedToOptional(GetByteSize()).value_or(0), 0,
1879 bit_field_size, bit_field_offset, false, false, eAddressTypeInvalid,
1880 0);
1881
1882 // Cache the value if we got one back...
1883 if (synthetic_child) {
1884 AddSyntheticChild(index_const_str, synthetic_child);
1885 synthetic_child_sp = synthetic_child->GetSP();
1886 synthetic_child_sp->SetName(ConstString(index_str));
1887 synthetic_child_sp->m_flags.m_is_bitfield_for_scalar = true;
1888 }
1889 }
1890 }
1891 return synthetic_child_sp;
1892}
1893
1895 uint32_t offset, const CompilerType &type, bool can_create,
1896 ConstString name_const_str) {
1897
1898 ValueObjectSP synthetic_child_sp;
1899
1900 if (name_const_str.IsEmpty()) {
1901 name_const_str.SetString("@" + std::to_string(offset));
1902 }
1903
1904 // Check if we have already created a synthetic array member in this valid
1905 // object. If we have we will re-use it.
1906 synthetic_child_sp = GetSyntheticChild(name_const_str);
1907
1908 if (synthetic_child_sp.get())
1909 return synthetic_child_sp;
1910
1911 if (!can_create)
1912 return {};
1913
1915 std::optional<uint64_t> size = llvm::expectedToOptional(
1917 if (!size)
1918 return {};
1919 ValueObjectChild *synthetic_child =
1920 new ValueObjectChild(*this, type, name_const_str, *size, offset, 0, 0,
1921 false, false, eAddressTypeInvalid, 0);
1922 if (synthetic_child) {
1923 AddSyntheticChild(name_const_str, synthetic_child);
1924 synthetic_child_sp = synthetic_child->GetSP();
1925 synthetic_child_sp->SetName(name_const_str);
1926 synthetic_child_sp->m_flags.m_is_child_at_offset = true;
1927 }
1928 return synthetic_child_sp;
1929}
1930
1932 const CompilerType &type,
1933 bool can_create,
1934 ConstString name_const_str) {
1935 ValueObjectSP synthetic_child_sp;
1936
1937 if (name_const_str.IsEmpty()) {
1938 char name_str[128];
1939 snprintf(name_str, sizeof(name_str), "base%s@%i",
1940 type.GetTypeName().AsCString("<unknown>"), offset);
1941 name_const_str.SetCString(name_str);
1942 }
1943
1944 // Check if we have already created a synthetic array member in this valid
1945 // object. If we have we will re-use it.
1946 synthetic_child_sp = GetSyntheticChild(name_const_str);
1947
1948 if (synthetic_child_sp.get())
1949 return synthetic_child_sp;
1950
1951 if (!can_create)
1952 return {};
1953
1954 const bool is_base_class = true;
1955
1957 std::optional<uint64_t> size = llvm::expectedToOptional(
1959 if (!size)
1960 return {};
1961 ValueObjectChild *synthetic_child =
1962 new ValueObjectChild(*this, type, name_const_str, *size, offset, 0, 0,
1963 is_base_class, false, eAddressTypeInvalid, 0);
1964 if (synthetic_child) {
1965 AddSyntheticChild(name_const_str, synthetic_child);
1966 synthetic_child_sp = synthetic_child->GetSP();
1967 synthetic_child_sp->SetName(name_const_str);
1968 }
1969 return synthetic_child_sp;
1970}
1971
1972// your expression path needs to have a leading . or -> (unless it somehow
1973// "looks like" an array, in which case it has a leading [ symbol). while the [
1974// is meaningful and should be shown to the user, . and -> are just parser
1975// design, but by no means added information for the user.. strip them off
1976static const char *SkipLeadingExpressionPathSeparators(const char *expression) {
1977 if (!expression || !expression[0])
1978 return expression;
1979 if (expression[0] == '.')
1980 return expression + 1;
1981 if (expression[0] == '-' && expression[1] == '>')
1982 return expression + 2;
1983 return expression;
1984}
1985
1988 bool can_create) {
1989 ValueObjectSP synthetic_child_sp;
1990 ConstString name_const_string(expression);
1991 // Check if we have already created a synthetic array member in this valid
1992 // object. If we have we will re-use it.
1993 synthetic_child_sp = GetSyntheticChild(name_const_string);
1994 if (!synthetic_child_sp) {
1995 // We haven't made a synthetic array member for expression yet, so lets
1996 // make one and cache it for any future reference.
1997 synthetic_child_sp = GetValueForExpressionPath(
1998 expression, nullptr, nullptr,
1999 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(
2001 None));
2002
2003 // Cache the value if we got one back...
2004 if (synthetic_child_sp.get()) {
2005 // FIXME: this causes a "real" child to end up with its name changed to
2006 // the contents of expression
2007 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
2008 synthetic_child_sp->SetName(
2010 }
2011 }
2012 return synthetic_child_sp;
2013}
2014
2016 TargetSP target_sp(GetTargetSP());
2017 if (target_sp && !target_sp->GetEnableSyntheticValue()) {
2018 m_synthetic_value = nullptr;
2019 return;
2020 }
2021
2023
2025 return;
2026
2027 if (m_synthetic_children_sp.get() == nullptr)
2028 return;
2029
2030 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2031 return;
2032
2034}
2035
2037 if (use_dynamic == eNoDynamicValues)
2038 return;
2039
2040 if (!m_dynamic_value && !IsDynamic()) {
2042 Process *process = exe_ctx.GetProcessPtr();
2043 if (process && process->IsPossibleDynamicValue(*this)) {
2045 m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic);
2046 }
2047 }
2048}
2049
2051 if (use_dynamic == eNoDynamicValues)
2052 return ValueObjectSP();
2053
2054 if (!IsDynamic() && m_dynamic_value == nullptr) {
2055 CalculateDynamicValue(use_dynamic);
2056 }
2057 if (m_dynamic_value && m_dynamic_value->GetError().Success())
2058 return m_dynamic_value->GetSP();
2059 else
2060 return ValueObjectSP();
2061}
2062
2065
2067 return m_synthetic_value->GetSP();
2068 else
2069 return ValueObjectSP();
2070}
2071
2074
2075 if (m_synthetic_children_sp.get() == nullptr)
2076 return false;
2077
2079
2080 return m_synthetic_value != nullptr;
2081}
2082
2084 if (GetParent()) {
2085 if (GetParent()->IsBaseClass())
2086 return GetParent()->GetNonBaseClassParent();
2087 else
2088 return GetParent();
2089 }
2090 return nullptr;
2091}
2092
2093bool ValueObject::IsBaseClass(uint32_t &depth) {
2094 if (!IsBaseClass()) {
2095 depth = 0;
2096 return false;
2097 }
2098 if (GetParent()) {
2099 GetParent()->IsBaseClass(depth);
2100 depth = depth + 1;
2101 return true;
2102 }
2103 // TODO: a base of no parent? weird..
2104 depth = 1;
2105 return true;
2106}
2107
2109 GetExpressionPathFormat epformat) {
2110 // synthetic children do not actually "exist" as part of the hierarchy, and
2111 // sometimes they are consed up in ways that don't make sense from an
2112 // underlying language/API standpoint. So, use a special code path here to
2113 // return something that can hopefully be used in expression
2114 if (m_flags.m_is_synthetic_children_generated) {
2116
2117 if (m_value.GetValueType() == Value::ValueType::LoadAddress) {
2119 s.Printf("((%s)0x%" PRIx64 ")", GetTypeName().AsCString("void"),
2121 return;
2122 } else {
2123 uint64_t load_addr =
2124 m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2125 if (load_addr != LLDB_INVALID_ADDRESS) {
2126 s.Printf("(*( (%s *)0x%" PRIx64 "))", GetTypeName().AsCString("void"),
2127 load_addr);
2128 return;
2129 }
2130 }
2131 }
2132
2133 if (CanProvideValue()) {
2134 s.Printf("((%s)%s)", GetTypeName().AsCString("void"),
2136 return;
2137 }
2138
2139 return;
2140 }
2141
2142 const bool is_deref_of_parent = IsDereferenceOfParent();
2143
2144 if (is_deref_of_parent &&
2146 // this is the original format of GetExpressionPath() producing code like
2147 // *(a_ptr).memberName, which is entirely fine, until you put this into
2148 // StackFrame::GetValueForVariableExpressionPath() which prefers to see
2149 // a_ptr->memberName. the eHonorPointers mode is meant to produce strings
2150 // in this latter format
2151 s.PutCString("*(");
2152 }
2153
2154 ValueObject *parent = GetParent();
2155
2156 if (parent) {
2157 parent->GetExpressionPath(s, epformat);
2158 const CompilerType parentType = parent->GetCompilerType();
2159 if (parentType.IsPointerType() &&
2160 parentType.GetPointeeType().IsArrayType(nullptr, nullptr, nullptr)) {
2161 // When the parent is a pointer to an array, then we have to:
2162 // - follow the expression path of the parent with "[0]"
2163 // (that will indicate dereferencing the pointer to the array)
2164 // - and then follow that with this ValueObject's name
2165 // (which will be something like "[i]" to indicate
2166 // the i-th element of the array)
2167 s.PutCString("[0]");
2168 s.PutCString(GetName().GetCString());
2169 return;
2170 }
2171 }
2172
2173 // if we are a deref_of_parent just because we are synthetic array members
2174 // made up to allow ptr[%d] syntax to work in variable printing, then add our
2175 // name ([%d]) to the expression path
2176 if (m_flags.m_is_array_item_for_pointer &&
2178 s.PutCString(m_name.GetStringRef());
2179
2180 if (!IsBaseClass()) {
2181 if (!is_deref_of_parent) {
2182 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2183 if (non_base_class_parent &&
2184 !non_base_class_parent->GetName().IsEmpty()) {
2185 CompilerType non_base_class_parent_compiler_type =
2186 non_base_class_parent->GetCompilerType();
2187 if (non_base_class_parent_compiler_type) {
2188 if (parent && parent->IsDereferenceOfParent() &&
2190 s.PutCString("->");
2191 } else {
2192 const uint32_t non_base_class_parent_type_info =
2193 non_base_class_parent_compiler_type.GetTypeInfo();
2194
2195 if (non_base_class_parent_type_info & eTypeIsPointer) {
2196 s.PutCString("->");
2197 } else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2198 !(non_base_class_parent_type_info & eTypeIsArray)) {
2199 s.PutChar('.');
2200 }
2201 }
2202 }
2203 }
2204
2205 const char *name = GetName().GetCString();
2206 if (name)
2207 s.PutCString(name);
2208 }
2209 }
2210
2211 if (is_deref_of_parent &&
2213 s.PutChar(')');
2214 }
2215}
2216
2217// Return the alternate value (synthetic if the input object is non-synthetic
2218// and otherwise) this is permitted by the expression path options.
2220 ValueObject &valobj,
2222 synth_traversal) {
2223 using SynthTraversal =
2225
2226 if (valobj.IsSynthetic()) {
2227 if (synth_traversal == SynthTraversal::FromSynthetic ||
2228 synth_traversal == SynthTraversal::Both)
2229 return valobj.GetNonSyntheticValue();
2230 } else {
2231 if (synth_traversal == SynthTraversal::ToSynthetic ||
2232 synth_traversal == SynthTraversal::Both)
2233 return valobj.GetSyntheticValue();
2234 }
2235 return nullptr;
2236}
2237
2238// Dereference the provided object or the alternate value, if permitted by the
2239// expression path options.
2241 ValueObject &valobj,
2243 synth_traversal,
2244 Status &error) {
2245 error.Clear();
2246 ValueObjectSP result = valobj.Dereference(error);
2247 if (!result || error.Fail()) {
2248 if (ValueObjectSP alt_obj = GetAlternateValue(valobj, synth_traversal)) {
2249 error.Clear();
2250 result = alt_obj->Dereference(error);
2251 }
2252 }
2253 return result;
2254}
2255
2257 llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop,
2258 ExpressionPathEndResultType *final_value_type,
2259 const GetValueForExpressionPathOptions &options,
2260 ExpressionPathAftermath *final_task_on_target) {
2261
2262 ExpressionPathScanEndReason dummy_reason_to_stop =
2264 ExpressionPathEndResultType dummy_final_value_type =
2266 ExpressionPathAftermath dummy_final_task_on_target =
2268
2270 expression, reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2271 final_value_type ? final_value_type : &dummy_final_value_type, options,
2272 final_task_on_target ? final_task_on_target
2273 : &dummy_final_task_on_target);
2274
2275 if (!final_task_on_target ||
2276 *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
2277 return ret_val;
2278
2279 if (ret_val.get() &&
2280 ((final_value_type ? *final_value_type : dummy_final_value_type) ==
2281 eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress
2282 // of plain objects
2283 {
2284 if ((final_task_on_target ? *final_task_on_target
2285 : dummy_final_task_on_target) ==
2287 Status error;
2289 *ret_val, options.m_synthetic_children_traversal, error);
2290 if (error.Fail() || !final_value.get()) {
2291 if (reason_to_stop)
2292 *reason_to_stop =
2294 if (final_value_type)
2296 return ValueObjectSP();
2297 } else {
2298 if (final_task_on_target)
2299 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2300 return final_value;
2301 }
2302 }
2303 if (*final_task_on_target ==
2305 Status error;
2306 ValueObjectSP final_value = ret_val->AddressOf(error);
2307 if (error.Fail() || !final_value.get()) {
2308 if (reason_to_stop)
2309 *reason_to_stop =
2311 if (final_value_type)
2313 return ValueObjectSP();
2314 } else {
2315 if (final_task_on_target)
2316 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2317 return final_value;
2318 }
2319 }
2320 }
2321 return ret_val; // final_task_on_target will still have its original value, so
2322 // you know I did not do it
2323}
2324
2326 llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop,
2327 ExpressionPathEndResultType *final_result,
2328 const GetValueForExpressionPathOptions &options,
2329 ExpressionPathAftermath *what_next) {
2330 ValueObjectSP root = GetSP();
2331
2332 if (!root)
2333 return nullptr;
2334
2335 llvm::StringRef remainder = expression;
2336
2337 while (true) {
2338 llvm::StringRef temp_expression = remainder;
2339
2340 CompilerType root_compiler_type = root->GetCompilerType();
2341 CompilerType pointee_compiler_type;
2342 Flags pointee_compiler_type_info;
2343
2344 Flags root_compiler_type_info(
2345 root_compiler_type.GetTypeInfo(&pointee_compiler_type));
2346 if (pointee_compiler_type)
2347 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
2348
2349 if (temp_expression.empty()) {
2351 return root;
2352 }
2353
2354 switch (temp_expression.front()) {
2355 case '-': {
2356 temp_expression = temp_expression.drop_front();
2357 if (options.m_check_dot_vs_arrow_syntax &&
2358 root_compiler_type_info.Test(eTypeIsPointer)) // if you are trying to
2359 // use -> on a
2360 // non-pointer and I
2361 // must catch the error
2362 {
2363 *reason_to_stop =
2366 return ValueObjectSP();
2367 }
2368 if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to
2369 // extract an ObjC IVar
2370 // when this is forbidden
2371 root_compiler_type_info.Test(eTypeIsPointer) &&
2372 options.m_no_fragile_ivar) {
2373 *reason_to_stop =
2376 return ValueObjectSP();
2377 }
2378 if (!temp_expression.starts_with(">")) {
2379 *reason_to_stop =
2382 return ValueObjectSP();
2383 }
2384 }
2385 [[fallthrough]];
2386 case '.': // or fallthrough from ->
2387 {
2388 if (options.m_check_dot_vs_arrow_syntax &&
2389 temp_expression.front() == '.' &&
2390 root_compiler_type_info.Test(eTypeIsPointer)) // if you are trying to
2391 // use . on a pointer
2392 // and I must catch the
2393 // error
2394 {
2395 *reason_to_stop =
2398 return nullptr;
2399 }
2400 temp_expression = temp_expression.drop_front(); // skip . or >
2401
2402 size_t next_sep_pos = temp_expression.find_first_of("-.[", 1);
2403 if (next_sep_pos == llvm::StringRef::npos) {
2404 // if no other separator just expand this last layer
2405 llvm::StringRef child_name = temp_expression;
2406 ValueObjectSP child_valobj_sp =
2407 root->GetChildMemberWithName(child_name);
2408 if (!child_valobj_sp) {
2409 if (ValueObjectSP altroot = GetAlternateValue(
2410 *root, options.m_synthetic_children_traversal))
2411 child_valobj_sp = altroot->GetChildMemberWithName(child_name);
2412 }
2413 if (child_valobj_sp) {
2414 *reason_to_stop =
2417 return child_valobj_sp;
2418 }
2421 return nullptr;
2422 }
2423
2424 llvm::StringRef next_separator = temp_expression.substr(next_sep_pos);
2425 llvm::StringRef child_name = temp_expression.slice(0, next_sep_pos);
2426
2427 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name);
2428 if (!child_valobj_sp) {
2429 if (ValueObjectSP altroot = GetAlternateValue(
2430 *root, options.m_synthetic_children_traversal))
2431 child_valobj_sp = altroot->GetChildMemberWithName(child_name);
2432 }
2433 if (child_valobj_sp) {
2434 root = child_valobj_sp;
2435 remainder = next_separator;
2437 continue;
2438 }
2441 return nullptr;
2442 }
2443 case '[': {
2444 if (!root_compiler_type_info.Test(eTypeIsArray) &&
2445 !root_compiler_type_info.Test(eTypeIsPointer) &&
2446 !root_compiler_type_info.Test(
2447 eTypeIsVector)) // if this is not a T[] nor a T*
2448 {
2449 if (!root_compiler_type_info.Test(
2450 eTypeIsScalar)) // if this is not even a scalar...
2451 {
2452 if (options.m_synthetic_children_traversal ==
2454 None) // ...only chance left is synthetic
2455 {
2456 *reason_to_stop =
2459 return ValueObjectSP();
2460 }
2461 } else if (!options.m_allow_bitfields_syntax) // if this is a scalar,
2462 // check that we can
2463 // expand bitfields
2464 {
2465 *reason_to_stop =
2468 return ValueObjectSP();
2469 }
2470 }
2471 if (temp_expression[1] ==
2472 ']') // if this is an unbounded range it only works for arrays
2473 {
2474 if (!root_compiler_type_info.Test(eTypeIsArray)) {
2475 *reason_to_stop =
2478 return nullptr;
2479 } else // even if something follows, we cannot expand unbounded ranges,
2480 // just let the caller do it
2481 {
2482 *reason_to_stop =
2484 *final_result =
2486 return root;
2487 }
2488 }
2489
2490 size_t close_bracket_position = temp_expression.find(']', 1);
2491 if (close_bracket_position ==
2492 llvm::StringRef::npos) // if there is no ], this is a syntax error
2493 {
2494 *reason_to_stop =
2497 return nullptr;
2498 }
2499
2500 llvm::StringRef bracket_expr =
2501 temp_expression.slice(1, close_bracket_position);
2502
2503 // If this was an empty expression it would have been caught by the if
2504 // above.
2505 assert(!bracket_expr.empty());
2506
2507 if (!bracket_expr.contains('-')) {
2508 // if no separator, this is of the form [N]. Note that this cannot be
2509 // an unbounded range of the form [], because that case was handled
2510 // above with an unconditional return.
2511 unsigned long index = 0;
2512 if (bracket_expr.getAsInteger(0, index)) {
2513 *reason_to_stop =
2516 return nullptr;
2517 }
2518
2519 // from here on we do have a valid index
2520 if (root_compiler_type_info.Test(eTypeIsArray)) {
2521 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index);
2522 if (!child_valobj_sp)
2523 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
2524 if (!child_valobj_sp)
2525 if (root->HasSyntheticValue() &&
2526 llvm::expectedToStdOptional(
2527 root->GetSyntheticValue()->GetNumChildren())
2528 .value_or(0) > index)
2529 child_valobj_sp =
2530 root->GetSyntheticValue()->GetChildAtIndex(index);
2531 if (child_valobj_sp) {
2532 root = child_valobj_sp;
2533 remainder =
2534 temp_expression.substr(close_bracket_position + 1); // skip ]
2536 continue;
2537 } else {
2538 *reason_to_stop =
2541 return nullptr;
2542 }
2543 } else if (root_compiler_type_info.Test(eTypeIsPointer)) {
2544 if (*what_next ==
2545 ValueObject::
2546 eExpressionPathAftermathDereference && // if this is a
2547 // ptr-to-scalar, I
2548 // am accessing it
2549 // by index and I
2550 // would have
2551 // deref'ed anyway,
2552 // then do it now
2553 // and use this as
2554 // a bitfield
2555 pointee_compiler_type_info.Test(eTypeIsScalar)) {
2556 Status error;
2558 *root, options.m_synthetic_children_traversal, error);
2559 if (error.Fail() || !root) {
2560 *reason_to_stop =
2563 return nullptr;
2564 } else {
2566 continue;
2567 }
2568 } else {
2569 if (root->GetCompilerType().GetMinimumLanguage() ==
2571 pointee_compiler_type_info.AllClear(eTypeIsPointer) &&
2572 root->HasSyntheticValue() &&
2575 SyntheticChildrenTraversal::ToSynthetic ||
2578 SyntheticChildrenTraversal::Both)) {
2579 root = root->GetSyntheticValue()->GetChildAtIndex(index);
2580 } else
2581 root = root->GetSyntheticArrayMember(index, true);
2582 if (!root) {
2583 *reason_to_stop =
2586 return nullptr;
2587 } else {
2588 remainder =
2589 temp_expression.substr(close_bracket_position + 1); // skip ]
2591 continue;
2592 }
2593 }
2594 } else if (root_compiler_type_info.Test(eTypeIsScalar)) {
2595 root = root->GetSyntheticBitFieldChild(index, index, true);
2596 if (!root) {
2597 *reason_to_stop =
2600 return nullptr;
2601 } else // we do not know how to expand members of bitfields, so we
2602 // just return and let the caller do any further processing
2603 {
2604 *reason_to_stop = ValueObject::
2605 eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2607 return root;
2608 }
2609 } else if (root_compiler_type_info.Test(eTypeIsVector)) {
2610 root = root->GetChildAtIndex(index);
2611 if (!root) {
2612 *reason_to_stop =
2615 return ValueObjectSP();
2616 } else {
2617 remainder =
2618 temp_expression.substr(close_bracket_position + 1); // skip ]
2620 continue;
2621 }
2622 } else if (options.m_synthetic_children_traversal ==
2624 SyntheticChildrenTraversal::ToSynthetic ||
2627 SyntheticChildrenTraversal::Both) {
2628 if (root->HasSyntheticValue())
2629 root = root->GetSyntheticValue();
2630 else if (!root->IsSynthetic()) {
2631 *reason_to_stop =
2634 return nullptr;
2635 }
2636 // if we are here, then root itself is a synthetic VO.. should be
2637 // good to go
2638
2639 if (!root) {
2640 *reason_to_stop =
2643 return nullptr;
2644 }
2645 root = root->GetChildAtIndex(index);
2646 if (!root) {
2647 *reason_to_stop =
2650 return nullptr;
2651 } else {
2652 remainder =
2653 temp_expression.substr(close_bracket_position + 1); // skip ]
2655 continue;
2656 }
2657 } else {
2658 *reason_to_stop =
2661 return nullptr;
2662 }
2663 } else {
2664 // we have a low and a high index
2665 llvm::StringRef sleft, sright;
2666 unsigned long low_index, high_index;
2667 std::tie(sleft, sright) = bracket_expr.split('-');
2668 if (sleft.getAsInteger(0, low_index) ||
2669 sright.getAsInteger(0, high_index)) {
2670 *reason_to_stop =
2673 return nullptr;
2674 }
2675
2676 if (low_index > high_index) // swap indices if required
2677 std::swap(low_index, high_index);
2678
2679 if (root_compiler_type_info.Test(
2680 eTypeIsScalar)) // expansion only works for scalars
2681 {
2682 root = root->GetSyntheticBitFieldChild(low_index, high_index, true);
2683 if (!root) {
2684 *reason_to_stop =
2687 return nullptr;
2688 } else {
2689 *reason_to_stop = ValueObject::
2690 eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2692 return root;
2693 }
2694 } else if (root_compiler_type_info.Test(
2695 eTypeIsPointer) && // if this is a ptr-to-scalar, I am
2696 // accessing it by index and I would
2697 // have deref'ed anyway, then do it
2698 // now and use this as a bitfield
2699 *what_next ==
2701 pointee_compiler_type_info.Test(eTypeIsScalar)) {
2702 Status error;
2704 *root, options.m_synthetic_children_traversal, error);
2705 if (error.Fail() || !root) {
2706 *reason_to_stop =
2709 return nullptr;
2710 } else {
2712 continue;
2713 }
2714 } else {
2715 *reason_to_stop =
2718 return root;
2719 }
2720 }
2721 break;
2722 }
2723 default: // some non-separator is in the way
2724 {
2725 *reason_to_stop =
2728 return nullptr;
2729 }
2730 }
2731 }
2732}
2733
2734llvm::Error ValueObject::Dump(Stream &s) {
2735 return Dump(s, DumpValueObjectOptions(*this));
2736}
2737
2739 const DumpValueObjectOptions &options) {
2740 ValueObjectPrinter printer(*this, &s, options);
2741 return printer.PrintValueObject();
2742}
2743
2745 ValueObjectSP valobj_sp;
2746
2747 if (UpdateValueIfNeeded(false) && m_error.Success()) {
2749
2750 DataExtractor data;
2751 data.SetByteOrder(m_data.GetByteOrder());
2752 data.SetAddressByteSize(m_data.GetAddressByteSize());
2753
2754 if (IsBitfield()) {
2756 m_error = v.GetValueAsData(&exe_ctx, data, GetModule().get());
2757 } else
2758 m_error = m_value.GetValueAsData(&exe_ctx, data, GetModule().get());
2759
2761 exe_ctx.GetBestExecutionContextScope(), GetCompilerType(), name, data,
2762 GetAddressOf().address);
2763 }
2764
2765 if (!valobj_sp) {
2768 exe_ctx.GetBestExecutionContextScope(), m_error.Clone());
2769 }
2770 return valobj_sp;
2771}
2772
2774 lldb::DynamicValueType dynValue, bool synthValue) {
2775 ValueObjectSP result_sp;
2776 switch (dynValue) {
2779 if (!IsDynamic())
2780 result_sp = GetDynamicValue(dynValue);
2781 } break;
2783 if (IsDynamic())
2784 result_sp = GetStaticValue();
2785 } break;
2786 }
2787 if (!result_sp)
2788 result_sp = GetSP();
2789 assert(result_sp);
2790
2791 bool is_synthetic = result_sp->IsSynthetic();
2792 if (synthValue && !is_synthetic) {
2793 if (auto synth_sp = result_sp->GetSyntheticValue())
2794 return synth_sp;
2795 }
2796 if (!synthValue && is_synthetic) {
2797 if (auto non_synth_sp = result_sp->GetNonSyntheticValue())
2798 return non_synth_sp;
2799 }
2800
2801 return result_sp;
2802}
2803
2805 if (m_deref_valobj)
2806 return m_deref_valobj->GetSP();
2807
2808 std::string deref_name_str;
2809 uint32_t deref_byte_size = 0;
2810 int32_t deref_byte_offset = 0;
2811 CompilerType compiler_type = GetCompilerType();
2812 uint64_t language_flags = 0;
2813
2815
2816 CompilerType deref_compiler_type;
2817 auto deref_compiler_type_or_err = compiler_type.GetDereferencedType(
2818 &exe_ctx, deref_name_str, deref_byte_size, deref_byte_offset, this,
2819 language_flags);
2820
2821 std::string deref_error;
2822 if (deref_compiler_type_or_err) {
2823 deref_compiler_type = *deref_compiler_type_or_err;
2824 } else {
2825 deref_error = llvm::toString(deref_compiler_type_or_err.takeError());
2826 LLDB_LOG(GetLog(LLDBLog::Types), "could not find child: {0}", deref_error);
2827 }
2828
2829 if (deref_compiler_type && deref_byte_size) {
2830 ConstString deref_name;
2831 if (!deref_name_str.empty())
2832 deref_name.SetCString(deref_name_str.c_str());
2833
2835 new ValueObjectChild(*this, deref_compiler_type, deref_name,
2836 deref_byte_size, deref_byte_offset, 0, 0, false,
2837 true, eAddressTypeInvalid, language_flags);
2838 }
2839
2840 // In case of incomplete deref compiler type, use the pointee type and try
2841 // to recreate a new ValueObjectChild using it.
2842 if (!m_deref_valobj) {
2843 // FIXME(#59012): C++ stdlib formatters break with incomplete types (e.g.
2844 // `std::vector<int> &`). Remove ObjC restriction once that's resolved.
2847 deref_compiler_type = compiler_type.GetPointeeType();
2848
2849 if (deref_compiler_type) {
2850 ConstString deref_name;
2851 if (!deref_name_str.empty())
2852 deref_name.SetCString(deref_name_str.c_str());
2853
2855 *this, deref_compiler_type, deref_name, deref_byte_size,
2856 deref_byte_offset, 0, 0, false, true, eAddressTypeInvalid,
2857 language_flags);
2858 }
2859 }
2860 }
2861
2862 if (!m_deref_valobj && IsSynthetic())
2863 m_deref_valobj = GetChildMemberWithName("$$dereference$$").get();
2864
2865 if (m_deref_valobj) {
2866 error.Clear();
2867 return m_deref_valobj->GetSP();
2868 } else {
2869 StreamString strm;
2870 GetExpressionPath(strm);
2871
2872 if (deref_error.empty())
2874 "dereference failed: (%s) %s",
2875 GetTypeName().AsCString("<invalid type>"), strm.GetData());
2876 else
2878 "dereference failed: %s: (%s) %s", deref_error.c_str(),
2879 GetTypeName().AsCString("<invalid type>"), strm.GetData());
2880 return ValueObjectSP();
2881 }
2882}
2883
2886 return m_addr_of_valobj_sp;
2887
2888 auto [addr, address_type] = GetAddressOf(/*scalar_is_load_address=*/false);
2889 error.Clear();
2890 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost) {
2891 switch (address_type) {
2892 case eAddressTypeInvalid: {
2893 StreamString expr_path_strm;
2894 GetExpressionPath(expr_path_strm);
2895 error = Status::FromErrorStringWithFormat("'%s' is not in memory",
2896 expr_path_strm.GetData());
2897 } break;
2898
2899 case eAddressTypeFile:
2900 case eAddressTypeLoad: {
2901 CompilerType compiler_type = GetCompilerType();
2902 if (compiler_type) {
2903 std::string name(1, '&');
2904 name.append(m_name.AsCString(""));
2906
2907 lldb::DataBufferSP buffer(
2908 new lldb_private::DataBufferHeap(&addr, sizeof(lldb::addr_t)));
2911 compiler_type.GetPointerType(), ConstString(name.c_str()), buffer,
2913 }
2914 } break;
2915 default:
2916 break;
2917 }
2918 } else {
2919 StreamString expr_path_strm;
2920 GetExpressionPath(expr_path_strm);
2922 "'%s' doesn't have a valid address", expr_path_strm.GetData());
2923 }
2924
2925 return m_addr_of_valobj_sp;
2926}
2927
2929 return ValueObjectCast::Create(*this, GetName(), compiler_type);
2930}
2931
2933 // Only allow casts if the original type is equal or larger than the cast
2934 // type, unless we know this is a load address. Getting the size wrong for
2935 // a host side storage could leak lldb memory, so we absolutely want to
2936 // prevent that. We may not always get the right value, for instance if we
2937 // have an expression result value that's copied into a storage location in
2938 // the target may not have copied enough memory. I'm not trying to fix that
2939 // here, I'm just making Cast from a smaller to a larger possible in all the
2940 // cases where that doesn't risk making a Value out of random lldb memory.
2941 // You have to check the ValueObject's Value for the address types, since
2942 // ValueObjects that use live addresses will tell you they fetch data from the
2943 // live address, but once they are made, they actually don't.
2944 // FIXME: Can we make ValueObject's with a live address fetch "more data" from
2945 // the live address if it is still valid?
2946
2947 Status error;
2948 CompilerType my_type = GetCompilerType();
2949
2950 ExecutionContextScope *exe_scope =
2952 if (llvm::expectedToOptional(compiler_type.GetByteSize(exe_scope))
2953 .value_or(0) <=
2954 llvm::expectedToOptional(GetCompilerType().GetByteSize(exe_scope))
2955 .value_or(0) ||
2956 m_value.GetValueType() == Value::ValueType::LoadAddress)
2957 return DoCast(compiler_type);
2958
2960 "Can only cast to a type that is equal to or smaller "
2961 "than the orignal type.");
2962
2964 ExecutionContext(GetExecutionContextRef()).GetBestExecutionContextScope(),
2965 std::move(error));
2966}
2967
2971
2973 CompilerType &compiler_type) {
2974 ValueObjectSP valobj_sp;
2975 addr_t ptr_value = GetPointerValue().address;
2976
2977 if (ptr_value != LLDB_INVALID_ADDRESS) {
2978 Address ptr_addr(ptr_value);
2980 valobj_sp = ValueObjectMemory::Create(
2981 exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, compiler_type);
2982 }
2983 return valobj_sp;
2984}
2985
2987 ValueObjectSP valobj_sp;
2988 addr_t ptr_value = GetPointerValue().address;
2989
2990 if (ptr_value != LLDB_INVALID_ADDRESS) {
2991 Address ptr_addr(ptr_value);
2993 valobj_sp = ValueObjectMemory::Create(
2994 exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, type_sp);
2995 }
2996 return valobj_sp;
2997}
2998
3000 if (auto target_sp = GetTargetSP()) {
3001 const bool scalar_is_load_address = true;
3002 auto [addr_value, addr_type] = GetAddressOf(scalar_is_load_address);
3003 if (addr_type == eAddressTypeFile) {
3004 lldb::ModuleSP module_sp(GetModule());
3005 if (!module_sp)
3006 addr_value = LLDB_INVALID_ADDRESS;
3007 else {
3008 Address tmp_addr;
3009 module_sp->ResolveFileAddress(addr_value, tmp_addr);
3010 addr_value = tmp_addr.GetLoadAddress(target_sp.get());
3011 }
3012 } else if (addr_type == eAddressTypeHost ||
3013 addr_type == eAddressTypeInvalid)
3014 addr_value = LLDB_INVALID_ADDRESS;
3015 return addr_value;
3016 }
3017 return LLDB_INVALID_ADDRESS;
3018}
3019
3020llvm::Expected<lldb::ValueObjectSP> ValueObject::CastDerivedToBaseType(
3021 CompilerType type, const llvm::ArrayRef<uint32_t> &base_type_indices) {
3022 // Make sure the starting type and the target type are both valid for this
3023 // type of cast; otherwise return the shared pointer to the original
3024 // (unchanged) ValueObject.
3025 if (!type.IsPointerType() && !type.IsReferenceType())
3026 return llvm::createStringError(
3027 "Invalid target type: should be a pointer or a reference");
3028
3029 CompilerType start_type = GetCompilerType();
3030 if (start_type.IsReferenceType())
3031 start_type = start_type.GetNonReferenceType();
3032
3033 auto target_record_type =
3034 type.IsPointerType() ? type.GetPointeeType() : type.GetNonReferenceType();
3035 auto start_record_type =
3036 start_type.IsPointerType() ? start_type.GetPointeeType() : start_type;
3037
3038 if (!target_record_type.IsRecordType() || !start_record_type.IsRecordType())
3039 return llvm::createStringError(
3040 "Underlying start & target types should be record types");
3041
3042 if (target_record_type.CompareTypes(start_record_type))
3043 return llvm::createStringError(
3044 "Underlying start & target types should be different");
3045
3046 if (base_type_indices.empty())
3047 return llvm::createStringError("Children sequence must be non-empty");
3048
3049 // Both the starting & target types are valid for the cast, and the list of
3050 // base class indices is non-empty, so we can proceed with the cast.
3051
3052 lldb::TargetSP target = GetTargetSP();
3053 // The `value` can be a pointer, but GetChildAtIndex works for pointers too.
3054 lldb::ValueObjectSP inner_value = GetSP();
3055
3056 for (const uint32_t i : base_type_indices)
3057 // Create synthetic value if needed.
3058 inner_value =
3059 inner_value->GetChildAtIndex(i, /*can_create_synthetic*/ true);
3060
3061 // At this point type of `inner_value` should be the dereferenced target
3062 // type.
3063 CompilerType inner_value_type = inner_value->GetCompilerType();
3064 if (type.IsPointerType()) {
3065 if (!inner_value_type.CompareTypes(type.GetPointeeType()))
3066 return llvm::createStringError(
3067 "casted value doesn't match the desired type");
3068
3069 uintptr_t addr = inner_value->GetLoadAddress();
3070 llvm::StringRef name = "";
3071 ExecutionContext exe_ctx(target.get(), false);
3072 return ValueObject::CreateValueObjectFromAddress(name, addr, exe_ctx, type,
3073 /* do deref */ false);
3074 }
3075
3076 // At this point the target type should be a reference.
3077 if (!inner_value_type.CompareTypes(type.GetNonReferenceType()))
3078 return llvm::createStringError(
3079 "casted value doesn't match the desired type");
3080
3081 return lldb::ValueObjectSP(inner_value->Cast(type.GetNonReferenceType()));
3082}
3083
3084llvm::Expected<lldb::ValueObjectSP>
3086 // Make sure the starting type and the target type are both valid for this
3087 // type of cast; otherwise return the shared pointer to the original
3088 // (unchanged) ValueObject.
3089 if (!type.IsPointerType() && !type.IsReferenceType())
3090 return llvm::createStringError(
3091 "Invalid target type: should be a pointer or a reference");
3092
3093 CompilerType start_type = GetCompilerType();
3094 if (start_type.IsReferenceType())
3095 start_type = start_type.GetNonReferenceType();
3096
3097 auto target_record_type =
3098 type.IsPointerType() ? type.GetPointeeType() : type.GetNonReferenceType();
3099 auto start_record_type =
3100 start_type.IsPointerType() ? start_type.GetPointeeType() : start_type;
3101
3102 if (!target_record_type.IsRecordType() || !start_record_type.IsRecordType())
3103 return llvm::createStringError(
3104 "Underlying start & target types should be record types");
3105
3106 if (target_record_type.CompareTypes(start_record_type))
3107 return llvm::createStringError(
3108 "Underlying start & target types should be different");
3109
3110 CompilerType virtual_base;
3111 if (target_record_type.IsVirtualBase(start_record_type, &virtual_base)) {
3112 if (!virtual_base.IsValid())
3113 return llvm::createStringError("virtual base should be valid");
3114 return llvm::createStringError(
3115 llvm::Twine("cannot cast " + start_type.TypeDescription() + " to " +
3116 type.TypeDescription() + " via virtual base " +
3117 virtual_base.TypeDescription())
3118 .str());
3119 }
3120
3121 // Both the starting & target types are valid for the cast, so we can
3122 // proceed with the cast.
3123
3124 lldb::TargetSP target = GetTargetSP();
3125 auto pointer_type =
3126 type.IsPointerType() ? type : type.GetNonReferenceType().GetPointerType();
3127
3128 uintptr_t addr =
3130
3131 llvm::StringRef name = "";
3132 ExecutionContext exe_ctx(target.get(), false);
3134 name, addr - offset, exe_ctx, pointer_type, /* do_deref */ false);
3135
3136 if (type.IsPointerType())
3137 return value;
3138
3139 // At this point the target type is a reference. Since `value` is a pointer,
3140 // it has to be dereferenced.
3141 Status error;
3142 return value->Dereference(error);
3143}
3144
3146 bool is_scalar = GetCompilerType().IsScalarType();
3147 bool is_enum = GetCompilerType().IsEnumerationType();
3148 bool is_pointer =
3150 bool is_float = HasFloatingRepresentation(GetCompilerType());
3151 bool is_integer = GetCompilerType().IsInteger();
3153
3154 if (!type.IsScalarType())
3157 Status::FromErrorString("target type must be a scalar"));
3158
3159 if (!is_scalar && !is_enum && !is_pointer)
3162 Status::FromErrorString("argument must be a scalar, enum, or pointer"));
3163
3164 lldb::TargetSP target = GetTargetSP();
3165 uint64_t type_byte_size = 0;
3166 uint64_t val_byte_size = 0;
3167 if (auto temp = llvm::expectedToOptional(type.GetByteSize(target.get())))
3168 type_byte_size = temp.value();
3169 if (auto temp =
3170 llvm::expectedToOptional(GetCompilerType().GetByteSize(target.get())))
3171 val_byte_size = temp.value();
3172
3173 if (is_pointer) {
3174 if (!type.IsInteger() && !type.IsBoolean())
3177 Status::FromErrorString("target type must be an integer or boolean"));
3178 if (!type.IsBoolean() && type_byte_size < val_byte_size)
3182 "target type cannot be smaller than the pointer type"));
3183 }
3184
3185 if (type.IsBoolean()) {
3186 if (!is_scalar || is_integer)
3188 exe_ctx, type.GetTypeSystem().GetSharedPointer(),
3189 GetValueAsUnsigned(0) != 0, "result");
3190 else if (is_scalar && is_float) {
3191 auto float_value_or_err = GetValueAsAPFloat();
3192 if (float_value_or_err)
3194 exe_ctx, type.GetTypeSystem().GetSharedPointer(),
3195 !float_value_or_err->isZero(), "result");
3196 else
3200 "cannot get value as APFloat: %s",
3201 llvm::toString(float_value_or_err.takeError()).c_str()));
3202 }
3203 }
3204
3205 if (type.IsInteger()) {
3206 if (!is_scalar || is_integer) {
3207 auto int_value_or_err = GetValueAsAPSInt();
3208 if (int_value_or_err) {
3209 // Get the value as APSInt and extend or truncate it to the requested
3210 // size.
3211 llvm::APSInt ext =
3212 int_value_or_err->extOrTrunc(type_byte_size * CHAR_BIT);
3213 return ValueObject::CreateValueObjectFromAPInt(exe_ctx, ext, type,
3214 "result");
3215 } else
3219 "cannot get value as APSInt: %s",
3220 llvm::toString(int_value_or_err.takeError()).c_str()));
3221 } else if (is_scalar && is_float) {
3222 llvm::APSInt integer(type_byte_size * CHAR_BIT, !type.IsSigned());
3223 bool is_exact;
3224 auto float_value_or_err = GetValueAsAPFloat();
3225 if (float_value_or_err) {
3226 llvm::APFloatBase::opStatus status =
3227 float_value_or_err->convertToInteger(
3228 integer, llvm::APFloat::rmTowardZero, &is_exact);
3229
3230 // Casting floating point values that are out of bounds of the target
3231 // type is undefined behaviour.
3232 if (status & llvm::APFloatBase::opInvalidOp)
3236 "invalid type cast detected: %s",
3237 llvm::toString(float_value_or_err.takeError()).c_str()));
3239 "result");
3240 }
3241 }
3242 }
3243
3244 if (HasFloatingRepresentation(type)) {
3245 if (!is_scalar) {
3246 auto int_value_or_err = GetValueAsAPSInt();
3247 if (int_value_or_err) {
3248 llvm::APSInt ext =
3249 int_value_or_err->extOrTrunc(type_byte_size * CHAR_BIT);
3250 Scalar scalar_int(ext);
3251 llvm::APFloat f =
3253 return ValueObject::CreateValueObjectFromAPFloat(exe_ctx, f, type,
3254 "result");
3255 } else {
3259 "cannot get value as APSInt: %s",
3260 llvm::toString(int_value_or_err.takeError()).c_str()));
3261 }
3262 } else {
3263 if (is_integer) {
3264 auto int_value_or_err = GetValueAsAPSInt();
3265 if (int_value_or_err) {
3266 Scalar scalar_int(*int_value_or_err);
3267 llvm::APFloat f = scalar_int.CreateAPFloatFromAPSInt(
3269 return ValueObject::CreateValueObjectFromAPFloat(exe_ctx, f, type,
3270 "result");
3271 } else {
3275 "cannot get value as APSInt: %s",
3276 llvm::toString(int_value_or_err.takeError()).c_str()));
3277 }
3278 }
3279 if (is_float) {
3280 auto float_value_or_err = GetValueAsAPFloat();
3281 if (float_value_or_err) {
3282 Scalar scalar_float(*float_value_or_err);
3283 llvm::APFloat f = scalar_float.CreateAPFloatFromAPFloat(
3285 return ValueObject::CreateValueObjectFromAPFloat(exe_ctx, f, type,
3286 "result");
3287 } else {
3291 "cannot get value as APFloat: %s",
3292 llvm::toString(float_value_or_err.takeError()).c_str()));
3293 }
3294 }
3295 }
3296 }
3297
3300 Status::FromErrorString("Unable to perform requested cast"));
3301}
3302
3304 bool is_enum = GetCompilerType().IsEnumerationType();
3305 bool is_integer = GetCompilerType().IsInteger();
3306 bool is_float = HasFloatingRepresentation(GetCompilerType());
3308
3309 if (!is_enum && !is_integer && !is_float)
3313 "argument must be an integer, a float, or an enum"));
3314
3315 if (!type.IsEnumerationType())
3318 Status::FromErrorString("target type must be an enum"));
3319
3320 lldb::TargetSP target = GetTargetSP();
3321 uint64_t byte_size = 0;
3322 if (auto temp = llvm::expectedToOptional(type.GetByteSize(target.get())))
3323 byte_size = temp.value();
3324
3325 if (is_float) {
3326 llvm::APSInt integer(byte_size * CHAR_BIT, !type.IsSigned());
3327 bool is_exact;
3328 auto value_or_err = GetValueAsAPFloat();
3329 if (value_or_err) {
3330 llvm::APFloatBase::opStatus status = value_or_err->convertToInteger(
3331 integer, llvm::APFloat::rmTowardZero, &is_exact);
3332
3333 // Casting floating point values that are out of bounds of the target
3334 // type is undefined behaviour.
3335 if (status & llvm::APFloatBase::opInvalidOp)
3339 "invalid type cast detected: %s",
3340 llvm::toString(value_or_err.takeError()).c_str()));
3342 "result");
3343 } else
3346 Status::FromErrorString("cannot get value as APFloat"));
3347 } else {
3348 // Get the value as APSInt and extend or truncate it to the requested size.
3349 auto value_or_err = GetValueAsAPSInt();
3350 if (value_or_err) {
3351 llvm::APSInt ext = value_or_err->extOrTrunc(byte_size * CHAR_BIT);
3352 return ValueObject::CreateValueObjectFromAPInt(exe_ctx, ext, type,
3353 "result");
3354 } else
3358 "cannot get value as APSInt: %s",
3359 llvm::toString(value_or_err.takeError()).c_str()));
3360 }
3363 Status::FromErrorString("Cannot perform requested cast"));
3364}
3365
3367
3369 bool use_selected)
3370 : m_mod_id(), m_exe_ctx_ref() {
3371 ExecutionContext exe_ctx(exe_scope);
3372 TargetSP target_sp(exe_ctx.GetTargetSP());
3373 if (target_sp) {
3374 m_exe_ctx_ref.SetTargetSP(target_sp);
3375 ProcessSP process_sp(exe_ctx.GetProcessSP());
3376 if (!process_sp)
3377 process_sp = target_sp->GetProcessSP();
3378
3379 if (process_sp) {
3380 m_mod_id = process_sp->GetModID();
3381 m_exe_ctx_ref.SetProcessSP(process_sp);
3382
3383 ThreadSP thread_sp(exe_ctx.GetThreadSP());
3384
3385 if (!thread_sp) {
3386 if (use_selected)
3387 thread_sp = process_sp->GetThreadList().GetSelectedThread();
3388 }
3389
3390 if (thread_sp) {
3391 m_exe_ctx_ref.SetThreadSP(thread_sp);
3392
3393 StackFrameSP frame_sp(exe_ctx.GetFrameSP());
3394 if (!frame_sp) {
3395 if (use_selected)
3396 frame_sp = thread_sp->GetSelectedFrame(DoNoSelectMostRelevantFrame);
3397 }
3398 if (frame_sp)
3399 m_exe_ctx_ref.SetFrameSP(frame_sp);
3400 }
3401 }
3402 }
3403}
3404
3408
3410
3411// This function checks the EvaluationPoint against the current process state.
3412// If the current state matches the evaluation point, or the evaluation point
3413// is already invalid, then we return false, meaning "no change". If the
3414// current state is different, we update our state, and return true meaning
3415// "yes, change". If we did see a change, we also set m_needs_update to true,
3416// so future calls to NeedsUpdate will return true. exe_scope will be set to
3417// the current execution context scope.
3418
3420 bool accept_invalid_exe_ctx) {
3421 // Start with the target, if it is NULL, then we're obviously not going to
3422 // get any further:
3423 const bool thread_and_frame_only_if_stopped = true;
3424 ExecutionContext exe_ctx(
3425 m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
3426
3427 if (exe_ctx.GetTargetPtr() == nullptr)
3428 return false;
3429
3430 // If we don't have a process nothing can change.
3431 Process *process = exe_ctx.GetProcessPtr();
3432 if (process == nullptr)
3433 return false;
3434
3435 // If our stop id is the current stop ID, nothing has changed:
3436 ProcessModID current_mod_id = process->GetModID();
3437
3438 // If the current stop id is 0, either we haven't run yet, or the process
3439 // state has been cleared. In either case, we aren't going to be able to sync
3440 // with the process state.
3441 if (current_mod_id.GetStopID() == 0)
3442 return false;
3443
3444 bool changed = false;
3445 const bool was_valid = m_mod_id.IsValid();
3446 if (was_valid) {
3447 if (m_mod_id == current_mod_id) {
3448 // Everything is already up to date in this object, no need to update the
3449 // execution context scope.
3450 changed = false;
3451 } else {
3452 m_mod_id = current_mod_id;
3453 m_needs_update = true;
3454 changed = true;
3455 }
3456 }
3457
3458 // Now re-look up the thread and frame in case the underlying objects have
3459 // gone away & been recreated. That way we'll be sure to return a valid
3460 // exe_scope. If we used to have a thread or a frame but can't find it
3461 // anymore, then mark ourselves as invalid.
3462
3463 if (!accept_invalid_exe_ctx) {
3464 if (m_exe_ctx_ref.HasThreadRef()) {
3465 ThreadSP thread_sp(m_exe_ctx_ref.GetThreadSP());
3466 if (thread_sp) {
3467 if (m_exe_ctx_ref.HasFrameRef()) {
3468 StackFrameSP frame_sp(m_exe_ctx_ref.GetFrameSP());
3469 if (!frame_sp) {
3470 // We used to have a frame, but now it is gone
3471 SetInvalid();
3472 changed = was_valid;
3473 }
3474 }
3475 } else {
3476 // We used to have a thread, but now it is gone
3477 SetInvalid();
3478 changed = was_valid;
3479 }
3480 }
3481 }
3482
3483 return changed;
3484}
3485
3487 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3488 if (process_sp)
3489 m_mod_id = process_sp->GetModID();
3490 m_needs_update = false;
3491}
3492
3493void ValueObject::ClearUserVisibleData(uint32_t clear_mask) {
3494 if ((clear_mask & eClearUserVisibleDataItemsValue) ==
3496 m_value_str.clear();
3497
3498 if ((clear_mask & eClearUserVisibleDataItemsLocation) ==
3500 m_location_str.clear();
3501
3502 if ((clear_mask & eClearUserVisibleDataItemsSummary) ==
3504 m_summary_str.clear();
3505
3506 if ((clear_mask & eClearUserVisibleDataItemsDescription) ==
3508 m_object_desc_str.clear();
3509
3513 m_synthetic_value = nullptr;
3514 }
3515}
3516
3518 if (m_parent) {
3519 if (!m_parent->IsPointerOrReferenceType())
3520 return m_parent->GetSymbolContextScope();
3521 }
3522 return nullptr;
3523}
3524
3527 llvm::StringRef expression,
3528 const ExecutionContext &exe_ctx) {
3529 return CreateValueObjectFromExpression(name, expression, exe_ctx,
3531}
3532
3534 llvm::StringRef name, llvm::StringRef expression,
3535 const ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options) {
3536 lldb::ValueObjectSP retval_sp;
3537 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
3538 if (!target_sp)
3539 return retval_sp;
3540 if (expression.empty())
3541 return retval_sp;
3542 target_sp->EvaluateExpression(expression, exe_ctx.GetFrameSP().get(),
3543 retval_sp, options);
3544 if (retval_sp && !name.empty())
3545 retval_sp->SetName(ConstString(name));
3546 return retval_sp;
3547}
3548
3550 llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx,
3551 CompilerType type, bool do_deref) {
3552 if (type) {
3553 CompilerType pointer_type(type.GetPointerType());
3554 if (!do_deref)
3555 pointer_type = type;
3556 if (pointer_type) {
3557 lldb::DataBufferSP buffer(
3558 new lldb_private::DataBufferHeap(&address, sizeof(lldb::addr_t)));
3560 exe_ctx.GetBestExecutionContextScope(), pointer_type,
3561 ConstString(name), buffer, exe_ctx.GetByteOrder(),
3562 exe_ctx.GetAddressByteSize()));
3563 if (ptr_result_valobj_sp) {
3564 if (do_deref)
3565 ptr_result_valobj_sp->GetValue().SetValueType(
3567 Status err;
3568 if (do_deref)
3569 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
3570 if (ptr_result_valobj_sp && !name.empty())
3571 ptr_result_valobj_sp->SetName(ConstString(name));
3572 }
3573 return ptr_result_valobj_sp;
3574 }
3575 }
3576 return lldb::ValueObjectSP();
3577}
3578
3580 llvm::StringRef name, const DataExtractor &data,
3581 const ExecutionContext &exe_ctx, CompilerType type) {
3582 lldb::ValueObjectSP new_value_sp;
3583 new_value_sp = ValueObjectConstResult::Create(
3584 exe_ctx.GetBestExecutionContextScope(), type, ConstString(name), data,
3586 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
3587 if (new_value_sp && !name.empty())
3588 new_value_sp->SetName(ConstString(name));
3589 return new_value_sp;
3590}
3591
3594 const llvm::APInt &v, CompilerType type,
3595 llvm::StringRef name) {
3596 uint64_t byte_size =
3597 llvm::expectedToOptional(
3599 .value_or(0);
3600 lldb::DataExtractorSP data_sp = std::make_shared<DataExtractor>(
3601 reinterpret_cast<const void *>(v.getRawData()), byte_size,
3602 exe_ctx.GetByteOrder(), exe_ctx.GetAddressByteSize());
3603 return ValueObject::CreateValueObjectFromData(name, *data_sp, exe_ctx, type);
3604}
3605
3607 const ExecutionContext &exe_ctx, const llvm::APFloat &v, CompilerType type,
3608 llvm::StringRef name) {
3609 return CreateValueObjectFromAPInt(exe_ctx, v.bitcastToAPInt(), type, name);
3610}
3611
3614 Scalar &s, CompilerType type,
3615 llvm::StringRef name) {
3617 type, s, ConstString(name));
3618}
3619
3622 TypeSystemSP typesystem_sp, bool value,
3623 llvm::StringRef name) {
3624 CompilerType type = typesystem_sp->GetBasicTypeFromAST(lldb::eBasicTypeBool);
3626 uint64_t byte_size =
3627 llvm::expectedToOptional(type.GetByteSize(exe_scope)).value_or(0);
3628 lldb::DataExtractorSP data_sp = std::make_shared<DataExtractor>(
3629 reinterpret_cast<const void *>(&value), byte_size, exe_ctx.GetByteOrder(),
3630 exe_ctx.GetAddressByteSize());
3631 return ValueObject::CreateValueObjectFromData(name, *data_sp, exe_ctx, type);
3632}
3633
3635 const ExecutionContext &exe_ctx, CompilerType type, llvm::StringRef name) {
3636 if (!type.IsNullPtrType()) {
3637 lldb::ValueObjectSP ret_val;
3638 return ret_val;
3639 }
3640 uintptr_t zero = 0;
3641 uint64_t byte_size = 0;
3642 if (auto temp = llvm::expectedToOptional(
3644 byte_size = temp.value();
3645 lldb::DataExtractorSP data_sp = std::make_shared<DataExtractor>(
3646 reinterpret_cast<const void *>(zero), byte_size, exe_ctx.GetByteOrder(),
3647 exe_ctx.GetAddressByteSize());
3648 return ValueObject::CreateValueObjectFromData(name, *data_sp, exe_ctx, type);
3649}
3650
3652 ValueObject *root(GetRoot());
3653 if (root != this)
3654 return root->GetModule();
3655 return lldb::ModuleSP();
3656}
3657
3659 if (m_root)
3660 return m_root;
3661 return (m_root = FollowParentChain([](ValueObject *vo) -> bool {
3662 return (vo->m_parent != nullptr);
3663 }));
3664}
3665
3668 ValueObject *vo = this;
3669 while (vo) {
3670 if (!f(vo))
3671 break;
3672 vo = vo->m_parent;
3673 }
3674 return vo;
3675}
3676
3685
3687 ValueObject *with_dv_info = this;
3688 while (with_dv_info) {
3689 if (with_dv_info->HasDynamicValueTypeInfo())
3690 return with_dv_info->GetDynamicValueTypeImpl();
3691 with_dv_info = with_dv_info->m_parent;
3692 }
3694}
3695
3697 const ValueObject *with_fmt_info = this;
3698 while (with_fmt_info) {
3699 if (with_fmt_info->m_format != lldb::eFormatDefault)
3700 return with_fmt_info->m_format;
3701 with_fmt_info = with_fmt_info->m_parent;
3702 }
3703 return m_format;
3704}
3705
3709 if (GetRoot()) {
3710 if (GetRoot() == this) {
3711 if (StackFrameSP frame_sp = GetFrameSP()) {
3712 const SymbolContext &sc(
3713 frame_sp->GetSymbolContext(eSymbolContextCompUnit));
3714 if (CompileUnit *cu = sc.comp_unit)
3715 type = cu->GetLanguage();
3716 }
3717 } else {
3719 }
3720 }
3721 }
3722 return (m_preferred_display_language = type); // only compute it once
3723}
3724
3729
3731 // we need to support invalid types as providers of values because some bare-
3732 // board debugging scenarios have no notion of types, but still manage to
3733 // have raw numeric values for things like registers. sigh.
3735 return (!type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
3736}
3737
3739 if (!UpdateValueIfNeeded())
3740 return nullptr;
3741
3742 TargetSP target_sp(GetTargetSP());
3743 if (!target_sp)
3744 return nullptr;
3745
3746 PersistentExpressionState *persistent_state =
3747 target_sp->GetPersistentExpressionStateForLanguage(
3749
3750 if (!persistent_state)
3751 return nullptr;
3752
3753 ConstString name = persistent_state->GetNextPersistentVariableName();
3754
3755 ValueObjectSP const_result_sp =
3756 ValueObjectConstResult::Create(target_sp.get(), GetValue(), name);
3757
3758 ExpressionVariableSP persistent_var_sp =
3759 persistent_state->CreatePersistentVariable(const_result_sp);
3760 persistent_var_sp->m_live_sp = persistent_var_sp->m_frozen_sp;
3761 persistent_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference;
3762
3763 return persistent_var_sp->GetValueObject();
3764}
3765
3769
3771 lldb::DynamicValueType use_dynamic, bool use_synthetic,
3772 const char *name)
3773 : m_use_dynamic(use_dynamic), m_use_synthetic(use_synthetic), m_name(name) {
3774 if (in_valobj_sp) {
3775 if ((m_valobj_sp = in_valobj_sp->GetQualifiedRepresentationIfAvailable(
3776 lldb::eNoDynamicValues, false))) {
3777 if (!m_name.IsEmpty())
3778 m_valobj_sp->SetName(m_name);
3779 }
3780 }
3781}
3782
3784 if (this != &rhs) {
3788 m_name = rhs.m_name;
3789 }
3790 return *this;
3791}
3792
3794 if (m_valobj_sp.get() == nullptr)
3795 return false;
3796
3797 // FIXME: This check is necessary but not sufficient. We for sure don't
3798 // want to touch SBValues whose owning
3799 // targets have gone away. This check is a little weak in that it
3800 // enforces that restriction when you call IsValid, but since IsValid
3801 // doesn't lock the target, you have no guarantee that the SBValue won't
3802 // go invalid after you call this... Also, an SBValue could depend on
3803 // data from one of the modules in the target, and those could go away
3804 // independently of the target, for instance if a module is unloaded.
3805 // But right now, neither SBValues nor ValueObjects know which modules
3806 // they depend on. So I have no good way to make that check without
3807 // tracking that in all the ValueObject subclasses.
3808 TargetSP target_sp = m_valobj_sp->GetTargetSP();
3809 return target_sp && target_sp->IsValid();
3810}
3811
3814 std::unique_lock<std::recursive_mutex> &lock, Status &error) {
3815 if (!m_valobj_sp) {
3816 error = Status::FromErrorString("invalid value object");
3817 return m_valobj_sp;
3818 }
3819
3821
3822 Target *target = value_sp->GetTargetSP().get();
3823 // If this ValueObject holds an error, then it is valuable for that.
3824 if (value_sp->GetError().Fail())
3825 return value_sp;
3826
3827 if (!target)
3828 return ValueObjectSP();
3829
3830 lock = std::unique_lock<std::recursive_mutex>(target->GetAPIMutex());
3831
3832 ProcessSP process_sp(value_sp->GetProcessSP());
3833 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock())) {
3834 // We don't allow people to play around with ValueObject if the process
3835 // is running. If you want to look at values, pause the process, then
3836 // look.
3837 error = Status::FromErrorString("process must be stopped.");
3838 return ValueObjectSP();
3839 }
3840
3842 ValueObjectSP dynamic_sp = value_sp->GetDynamicValue(m_use_dynamic);
3843 if (dynamic_sp)
3844 value_sp = dynamic_sp;
3845 }
3846
3847 if (m_use_synthetic) {
3848 ValueObjectSP synthetic_sp = value_sp->GetSyntheticValue();
3849 if (synthetic_sp)
3850 value_sp = synthetic_sp;
3851 }
3852
3853 if (!value_sp)
3854 error = Status::FromErrorString("invalid value object");
3855 if (!m_name.IsEmpty())
3856 value_sp->SetName(m_name);
3857
3858 return value_sp;
3859}
static llvm::raw_ostream & error(Stream &strm)
#define integer
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:369
#define LLDB_LOG_ERRORV(log, error,...)
Definition Log.h:415
#define LLDB_LOGF(log,...)
Definition Log.h:383
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:399
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.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
bool IsEmpty() const
Test for empty string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
void SetString(llvm::StringRef s)
const char * GetCString() const
Get the string value as a C string.
A subclass of DataBuffer that stores a data buffer on the heap.
lldb::offset_t SetByteSize(lldb::offset_t byte_size)
Set the number of bytes in the data buffer.
void CopyData(const void *src, lldb::offset_t src_len)
Makes a copy of the src_len bytes in src.
An data extractor class.
virtual const uint8_t * PeekData(lldb::offset_t offset, lldb::offset_t length) const
Peek at a bytes at offset.
virtual uint64_t GetByteSize() const
Get the number of bytes contained in this object.
void SetByteOrder(lldb::ByteOrder byte_order)
Set the byte_order value.
const uint8_t * GetDataStart() const
Get the data start pointer.
virtual lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
uint32_t GetAddressByteSize() const
Get the current address size.
lldb::ByteOrder GetByteOrder() const
Get the current byte order value.
void SetAddressByteSize(uint32_t addr_size)
Set the address byte size.
lldb::offset_t CopyByteOrderedData(lldb::offset_t src_offset, lldb::offset_t src_len, void *dst, lldb::offset_t dst_len, lldb::ByteOrder dst_byte_order) const
Copy dst_len bytes from *offset_ptr and ensure the copied data is treated as a value that can be swap...
const char * PeekCStr(lldb::offset_t offset) const
Peek at a C string at offset.
static lldb::TypeSummaryImplSP GetSummaryFormat(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
static lldb::TypeFormatImplSP GetFormat(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
static lldb::SyntheticChildrenSP GetSyntheticChildren(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
A class that describes the declaration location of a lldb object.
Definition Declaration.h:24
void Clear()
Clear the object's state.
Definition Declaration.h:57
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
virtual lldb::TargetSP CalculateTarget()=0
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
const lldb::ProcessSP & GetProcessSP() const
Get accessor to get the process shared pointer.
lldb::ByteOrder GetByteOrder() const
const lldb::StackFrameSP & GetFrameSP() const
Get accessor to get the frame shared pointer.
Target * GetTargetPtr() const
Returns a pointer to the target object.
const lldb::ThreadSP & GetThreadSP() const
Get accessor to get the thread shared pointer.
Process * GetProcessPtr() const
Returns a pointer to the process object.
@ EVIsProgramReference
This variable is a reference to a (possibly invalid) area managed by the target program.
A class to manage flags.
Definition Flags.h:22
bool AllClear(ValueType mask) const
Test if all bits in mask are clear.
Definition Flags.h:103
void Reset(ValueType flags)
Set accessor for all flags.
Definition Flags.h:52
bool Test(ValueType bit) const
Test a single flag bit.
Definition Flags.h:96
bool AnySet(ValueType mask) const
Test one or more flags.
Definition Flags.h:90
static lldb::Format GetSingleItemFormat(lldb::Format vector_format)
static Language * FindPlugin(lldb::LanguageType language)
Definition Language.cpp:84
static bool LanguageIsCFamily(lldb::LanguageType language)
Equivalent to LanguageIsC||LanguageIsObjC||LanguageIsCPlusPlus.
Definition Language.cpp:379
static bool LanguageIsObjC(lldb::LanguageType language)
Definition Language.cpp:357
virtual lldb::ExpressionVariableSP CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp)=0
virtual ConstString GetNextPersistentVariableName(bool is_error=false)=0
Return a new persistent variable name with the specified prefix.
uint32_t GetStopID() const
Definition Process.h:250
A plug-in interface definition class for debugging a process.
Definition Process.h:354
ProcessModID GetModID() const
Get the Modification ID of the process.
Definition Process.h:1451
ProcessRunLock::ProcessRunLocker StopLocker
Definition Process.h:393
bool IsPossibleDynamicValue(ValueObject &in_value)
Definition Process.cpp:1506
LanguageRuntime * GetLanguageRuntime(lldb::LanguageType language)
Definition Process.cpp:1478
size_t WriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size, Status &error)
Write memory to a process.
Definition Process.cpp:2365
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:2446
llvm::APFloat CreateAPFloatFromAPFloat(lldb::BasicType basic_type)
Definition Scalar.cpp:850
llvm::APFloat CreateAPFloatFromAPSInt(lldb::BasicType basic_type)
Definition Scalar.cpp:830
unsigned long long ULongLong(unsigned long long fail_value=0) const
Definition Scalar.cpp:365
llvm::APFloat GetAPFloat() const
Definition Scalar.h:190
long long SLongLong(long long fail_value=0) const
Definition Scalar.cpp:361
bool ExtractBitfield(uint32_t bit_size, uint32_t bit_offset)
Definition Scalar.cpp:813
Status SetValueFromCString(const char *s, lldb::Encoding encoding, size_t byte_size)
Definition Scalar.cpp:648
bool GetData(DataExtractor &data) const
Get data with a byte size of GetByteSize().
Definition Scalar.cpp:85
bool IsValid() const
Definition Scalar.h:111
llvm::APSInt GetAPSInt() const
Definition Scalar.h:188
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:194
bool Success() const
Test for success condition.
Definition Status.cpp:303
const char * GetData() const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:65
size_t PutChar(char ch)
Definition Stream.cpp:131
Basic RAII class to increment the summary count when the call is complete.
Definition Statistics.h:256
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
Defines a symbol context baton that can be handed other debug core functions.
CompileUnit * comp_unit
The CompileUnit for a given query.
uint32_t GetMaximumSizeOfStringSummary() const
Definition Target.cpp:4995
std::recursive_mutex & GetAPIMutex()
Definition Target.cpp:5347
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:1999
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:332
std::shared_ptr< SummaryStatistics > SummaryStatisticsSP
Definition Statistics.h:33
@ eAddressTypeFile
Address is an address as found in an object or symbol file.
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
@ eAddressTypeHost
Address is an address in the process that is running this code.
std::string toString(FormatterBytecode::OpCodes op)
std::shared_ptr< lldb_private::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.