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