LLDB mainline
ValueObjectPrinter.cpp
Go to the documentation of this file.
1//===-- ValueObjectPrinter.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
14#include "lldb/Target/Target.h"
15#include "lldb/Utility/Log.h"
16#include "lldb/Utility/Stream.h"
18#include "llvm/Support/Error.h"
19#include "llvm/Support/MathExtras.h"
20#include <cinttypes>
21#include <cstdint>
22#include <memory>
23#include <optional>
24
25using namespace lldb;
26using namespace lldb_private;
27
29 : m_orig_valobj(valobj) {
30 DumpValueObjectOptions options(valobj);
31 Init(valobj, s, options, m_options.m_max_ptr_depth, 0, nullptr);
32}
33
35 const DumpValueObjectOptions &options)
36 : m_orig_valobj(valobj) {
37 Init(valobj, s, options, m_options.m_max_ptr_depth, 0, nullptr);
38}
39
41 ValueObject &valobj, Stream *s, const DumpValueObjectOptions &options,
42 const DumpValueObjectOptions::PointerDepth &ptr_depth, uint32_t curr_depth,
43 InstancePointersSetSP printed_instance_pointers)
44 : m_orig_valobj(valobj) {
45 Init(valobj, s, options, ptr_depth, curr_depth, printed_instance_pointers);
46}
47
49 ValueObject &valobj, Stream *s, const DumpValueObjectOptions &options,
50 const DumpValueObjectOptions::PointerDepth &ptr_depth, uint32_t curr_depth,
51 InstancePointersSetSP printed_instance_pointers) {
52 m_cached_valobj = nullptr;
53 m_stream = s;
54 m_options = options;
55 m_ptr_depth = ptr_depth;
56 m_curr_depth = curr_depth;
57 assert(m_stream && "cannot print to a NULL Stream");
65 m_summary_formatter = {nullptr, false};
66 m_value.assign("");
67 m_summary.assign("");
68 m_error.assign("");
69 m_val_summary_ok = false;
70 m_printed_instance_pointers = printed_instance_pointers
71 ? printed_instance_pointers
72 : std::make_shared<InstancePointersSet>();
74}
75
76static const char *maybeNewline(const std::string &s) {
77 // If the string already ends with a \n don't add another one.
78 if (s.empty() || s.back() != '\n')
79 return "\n";
80 return "";
81}
82
84 return ShouldPrintValueObject() && m_options.m_use_object_desc && !IsNil() &&
85 !IsUninitialized() && !m_options.m_pointer_as_array;
86}
87
89 // If the incoming ValueObject is in an error state, the best we're going to
90 // get out of it is its type. But if we don't even have that, just print
91 // the error and exit early.
92 if (m_orig_valobj.GetError().Fail() &&
93 !m_orig_valobj.GetCompilerType().IsValid())
94 return m_orig_valobj.GetError().ToError();
95
96 std::optional<std::string> object_desc;
98 // The object description is invoked now, but not printed until after
99 // value/summary. Calling GetObjectDescription at the outset of printing
100 // allows for early discovery of errors. In the case of an error, the value
101 // object is printed normally.
102 llvm::Expected<std::string> object_desc_or_err =
104 if (!object_desc_or_err) {
105 *m_stream << "warning: `po` was unsuccessful, running `p` instead\n";
107 object_desc_or_err.takeError(),
108 "Object description fallback due to error: {0}");
109
110 // Print the value object directly.
111 m_options.DisableObjectDescription();
112 } else {
113 object_desc = *object_desc_or_err;
114 }
115 }
116
119 m_stream->Indent();
120
121 PrintDecl();
122 }
123
124 bool value_printed = false;
125 bool summary_printed = false;
126
128 PrintValueAndSummaryIfNeeded(value_printed, summary_printed);
129
130 if (m_val_summary_ok) {
132 return PrintChildrenIfNeeded(value_printed, summary_printed);
133 }
134 m_stream->EOL();
135
136 return llvm::Error::success();
137}
138
140 assert(m_cached_valobj && "ValueObjectPrinter must have a valid ValueObject");
141 return *m_cached_valobj;
142}
143
145 bool update_success = m_orig_valobj.UpdateValueIfNeeded(true);
146 // If we can't find anything better, we'll fall back on the original
147 // ValueObject.
149 if (update_success) {
150 if (m_orig_valobj.IsDynamic()) {
151 if (m_options.m_use_dynamic == eNoDynamicValues) {
152 ValueObject *static_value = m_orig_valobj.GetStaticValue().get();
153 if (static_value)
154 m_cached_valobj = static_value;
155 }
156 } else {
157 if (m_options.m_use_dynamic != eNoDynamicValues) {
158 ValueObject *dynamic_value =
159 m_orig_valobj.GetDynamicValue(m_options.m_use_dynamic).get();
160 if (dynamic_value)
161 m_cached_valobj = dynamic_value;
162 }
163 }
164
165 if (m_cached_valobj->IsSynthetic()) {
166 if (!m_options.m_use_synthetic) {
167 ValueObject *non_synthetic =
168 m_cached_valobj->GetNonSyntheticValue().get();
169 if (non_synthetic)
170 m_cached_valobj = non_synthetic;
171 }
172 } else {
173 if (m_options.m_use_synthetic) {
174 ValueObject *synthetic = m_cached_valobj->GetSyntheticValue().get();
175 if (synthetic)
176 m_cached_valobj = synthetic;
177 }
178 }
179 }
180 m_compiler_type = m_cached_valobj->GetCompilerType();
181 m_type_flags = m_compiler_type.GetTypeInfo();
182 assert(m_cached_valobj &&
183 "SetupMostSpecialized value must compute a valid ValueObject");
184}
185
187 const char *root_valobj_name =
188 m_options.m_root_valobj_name.empty()
190 : m_options.m_root_valobj_name.c_str();
191 return root_valobj_name ? root_valobj_name : "";
192}
193
197 (!m_options.m_flat_output || m_type_flags.Test(eTypeHasValue))
199 : eLazyBoolNo;
201}
202
209
217
220 m_is_ptr = m_type_flags.Test(eTypeIsPointer) ? eLazyBoolYes : eLazyBoolNo;
221 return m_is_ptr == eLazyBoolYes;
222}
223
226 m_is_ref = m_type_flags.Test(eTypeIsReference) ? eLazyBoolYes : eLazyBoolNo;
227 return m_is_ref == eLazyBoolYes;
228}
229
236
238 // you need to do this check on the value's clang type
241 m_is_instance_ptr = (valobj.GetValue().GetCompilerType().GetTypeInfo() &
242 eTypeInstanceIsPointer) != 0
244 : eLazyBoolNo;
245 if ((eLazyBoolYes == m_is_instance_ptr) && valobj.IsBaseClass())
248}
249
251 if (m_options.m_show_location) {
252 m_stream->Printf("%s: ", GetMostSpecializedValue().GetLocationAsCString());
253 return true;
254 }
255 return false;
256}
257
259 bool show_type = true;
260 // if we are at the root-level and been asked to hide the root's type, then
261 // hide it
262 if (m_curr_depth == 0 && m_options.m_hide_root_type)
263 show_type = false;
264 else
265 // otherwise decide according to the usual rules (asked to show types -
266 // always at the root level)
267 show_type = m_options.m_show_types ||
268 (m_curr_depth == 0 && !m_options.m_flat_output);
269
270 StreamString typeName;
271 // Figure out which ValueObject we're acting on
273
274 // always show the type at the root level if it is invalid
275 if (show_type) {
276 // Some ValueObjects don't have types (like registers sets). Only print the
277 // type if there is one to print
278 llvm::StringRef type_name;
279 if (m_compiler_type.IsValid()) {
280 type_name = m_options.m_use_type_display_name
281 ? valobj.GetDisplayTypeName()
282 : valobj.GetQualifiedTypeName();
283 } else {
284 // only show an invalid type name if the user explicitly triggered
285 // show_type
286 if (m_options.m_show_types)
287 type_name = "<invalid type>";
288 }
289
290 if (!type_name.empty()) {
291 if (m_options.m_hide_pointer_value) {
292 while (type_name.starts_with(" *")) {
293 type_name = type_name.drop_front(2);
294 }
295 }
296 typeName << type_name;
297 }
298 }
299
300 StreamString varName;
301
302 if (ShouldShowName()) {
303 if (m_options.m_flat_output)
304 valobj.GetExpressionPath(varName);
305 else
306 varName << GetRootNameForDisplay();
307 }
308
309 bool decl_printed = false;
310 if (!m_options.m_decl_printing_helper) {
311 // if the user didn't give us a custom helper, pick one based upon the
312 // language, either the one that this printer is bound to, or the preferred
313 // one for the ValueObject
314 lldb::LanguageType lang_type =
315 (m_options.m_varformat_language == lldb::eLanguageTypeUnknown)
317 : m_options.m_varformat_language;
318 if (Language *lang_plugin = Language::FindPlugin(lang_type)) {
319 m_options.m_decl_printing_helper = lang_plugin->GetDeclPrintingHelper();
320 }
321 }
322
323 if (m_options.m_decl_printing_helper) {
324 llvm::StringRef type_name(typeName.GetString());
325 llvm::StringRef var_name(varName.GetString());
326
327 DumpValueObjectOptions decl_print_options = m_options;
328 // Pass printing helpers an option object that indicates whether the name
329 // should be shown or hidden.
330 decl_print_options.SetHideName(!ShouldShowName());
331
332 StreamString dest_stream;
333 if (m_options.m_decl_printing_helper(type_name, var_name,
334 decl_print_options, dest_stream)) {
335 decl_printed = true;
336 m_stream->PutCString(dest_stream.GetString());
337 }
338 }
339
340 // if the helper failed, or there is none, do a default thing
341 if (!decl_printed) {
342 if (!typeName.Empty())
343 m_stream->Printf("(%s) ", typeName.GetData());
344 if (!varName.Empty())
345 m_stream->Printf("%s =", varName.GetData());
346 else if (ShouldShowName())
347 m_stream->PutCString(" =");
348 }
349}
350
352 if (m_options.m_scope_already_checked)
353 return true;
355}
356
358 if (!m_summary_formatter.second) {
359 TypeSummaryImpl *entry =
360 m_options.m_summary_sp
361 ? m_options.m_summary_sp.get()
363
364 if (m_options.m_omit_summary_depth > 0)
365 entry = nullptr;
366 m_summary_formatter.first = entry;
367 m_summary_formatter.second = true;
368 }
369 if (m_options.m_omit_summary_depth > 0 && null_if_omitted)
370 return nullptr;
371 return m_summary_formatter.first;
372}
373
374static bool IsPointerValue(const CompilerType &type) {
375 Flags type_flags(type.GetTypeInfo());
376 if (type_flags.AnySet(eTypeInstanceIsPointer | eTypeIsPointer))
377 return type_flags.AllClear(eTypeIsBuiltIn);
378 return false;
379}
380
382 std::string &summary,
383 std::string &error) {
384 lldb::Format format = m_options.m_format;
386 // if I am printing synthetized elements, apply the format to those elements
387 // only
388 if (m_options.m_pointer_as_array)
390 else if (format != eFormatDefault && format != valobj.GetFormat())
391 valobj.GetValueAsCString(format, value);
392 else {
393 const char *val_cstr = valobj.GetValueAsCString();
394 if (val_cstr)
395 value.assign(val_cstr);
396 }
397 const char *err_cstr = valobj.GetError().AsCString();
398 if (err_cstr)
399 error.assign(err_cstr);
400
402 return;
403
404 if (IsNil()) {
405 lldb::LanguageType lang_type =
406 (m_options.m_varformat_language == lldb::eLanguageTypeUnknown)
408 : m_options.m_varformat_language;
409 if (Language *lang_plugin = Language::FindPlugin(lang_type)) {
410 summary.assign(lang_plugin->GetNilReferenceSummaryString().str());
411 } else {
412 // We treat C as the fallback language rather than as a separate Language
413 // plugin.
414 summary.assign("NULL");
415 }
416 } else if (IsUninitialized()) {
417 summary.assign("<uninitialized>");
418 } else if (m_options.m_omit_summary_depth == 0) {
420 if (entry) {
421 valobj.GetSummaryAsCString(entry, summary,
422 m_options.m_varformat_language);
423 } else {
424 const char *sum_cstr =
425 valobj.GetSummaryAsCString(m_options.m_varformat_language);
426 if (sum_cstr)
427 summary.assign(sum_cstr);
428 }
429 }
430}
431
433 bool &summary_printed) {
434 bool error_printed = false;
436 if (!CheckScopeIfNeeded())
437 m_error.assign("out of scope");
438 if (m_error.empty()) {
440 }
441 if (m_error.size()) {
442 // we need to support scenarios in which it is actually fine for a value
443 // to have no type but - on the other hand - if we get an error *AND*
444 // have no type, we try to get out gracefully, since most often that
445 // combination means "could not resolve a type" and the default failure
446 // mode is quite ugly
447 if (!m_compiler_type.IsValid()) {
448 m_stream->PutCString(" <could not resolve type>");
449 return false;
450 }
451
452 error_printed = true;
453 m_stream->Printf(" <%s>", m_error.c_str());
454 } else {
455 // Make sure we have a value and make sure the summary didn't specify
456 // that the value should not be printed - and do not print the value if
457 // this thing is nil (but show the value if the user passes a format
458 // explicitly)
461 const bool has_nil_or_uninitialized_summary =
462 (IsNil() || IsUninitialized()) && !m_summary.empty();
463 if (!has_nil_or_uninitialized_summary && !m_value.empty() &&
464 (entry == nullptr ||
465 (entry->DoesPrintValue(&valobj) ||
466 m_options.m_format != eFormatDefault) ||
467 m_summary.empty()) &&
468 !m_options.m_hide_value) {
469 if (m_options.m_hide_pointer_value &&
471 } else {
472 if (auto stripped = valobj.GetStrippedPointerValue(
473 valobj.GetPointerValue().address))
474 m_stream->Printf(" (actual=0x%" PRIx64 ")", *stripped);
475 if (ShouldShowName())
476 m_stream->PutChar(' ');
477 m_stream->PutCString(m_value);
478 value_printed = true;
479 }
480 }
481
482 if (m_summary.size()) {
483 if (ShouldShowName() || value_printed)
484 m_stream->PutChar(' ');
485 m_stream->PutCString(m_summary);
486 summary_printed = true;
487 }
488 }
489 }
490 return !error_printed;
491}
492
494 std::optional<std::string> object_desc) {
495 if (!object_desc)
496 return;
497
498 if (!m_options.m_hide_value || ShouldShowName())
499 *m_stream << ' ';
500 *m_stream << *object_desc << maybeNewline(*object_desc);
501}
502
506
508 DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
509 const bool is_ref = IsRef();
510 const bool is_ptr = IsPtr();
511 const bool is_uninit = IsUninitialized();
512
513 if (is_uninit)
514 return false;
515
516 // If we have reached the maximum depth we shouldn't print any more children.
518 return false;
519
520 // if the user has specified an element count, always print children as it is
521 // explicit user demand being honored
522 if (m_options.m_pointer_as_array)
523 return true;
524
525 if (m_options.m_use_object_desc)
526 return false;
527
528 bool print_children = true;
530 if (TypeSummaryImpl *type_summary = GetSummaryFormatter())
531 print_children = type_summary->DoesPrintChildren(&valobj);
532
533 // We will show children for all concrete types. We won't show pointer
534 // contents unless a pointer depth has been specified. We won't reference
535 // contents unless the reference is the root object (depth of zero).
536
537 // Use a new temporary pointer depth in case we override the current
538 // pointer depth below...
539
540 if (is_ptr || is_ref) {
541 // We have a pointer or reference whose value is an address. Make sure
542 // that address is not NULL
543 if (valobj.GetPointerValue().address == 0)
544 return false;
545
546 const bool is_root_level = m_curr_depth == 0;
547 const bool is_expanded_ptr =
548 is_ptr && m_type_flags.Test(m_options.m_expand_ptr_type_flags);
549
550 if ((is_ref || is_expanded_ptr) && is_root_level && print_children) {
551 // If this is the root object (depth is zero) that we are showing and it
552 // is either a reference or a preferred type of pointer, then print it.
553 // Don't do this at deeper depths otherwise we can end up with infinite
554 // recursion...
555 return true;
556 }
557
558 return curr_ptr_depth.CanAllowExpansion();
559 }
560
561 return print_children || m_summary.empty();
562}
563
566
567 if (!entry)
568 return true;
569
570 return entry->DoesPrintEmptyAggregates();
571}
572
576
578 bool summary_printed) {
579 if (m_options.m_flat_output) {
581 m_stream->EOL();
582 } else {
584 if (IsRef()) {
585 m_stream->PutCString(": ");
586 } else if (value_printed || summary_printed || ShouldShowName()) {
587 m_stream->PutChar(' ');
588 }
589 m_stream->PutCString("{\n");
590 }
591 m_stream->IndentMore();
592 }
593}
594
596 ValueObjectSP child_sp,
597 const DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
598 const uint32_t consumed_summary_depth = m_options.m_pointer_as_array ? 0 : 1;
599 const bool does_consume_ptr_depth =
600 ((IsPtr() && !m_options.m_pointer_as_array) || IsRef());
601
602 DumpValueObjectOptions child_options(m_options);
603 child_options.SetFormat(m_options.m_format)
604 .SetSummary()
606 child_options.SetScopeChecked(true)
607 .SetHideName(m_options.m_hide_name)
608 .SetHideValue(m_options.m_hide_value)
610 ? child_options.m_omit_summary_depth -
611 consumed_summary_depth
612 : 0)
613 .SetElementCount(0);
614
615 if (child_sp.get()) {
616 auto ptr_depth = curr_ptr_depth;
617 if (does_consume_ptr_depth)
618 ptr_depth = curr_ptr_depth.Decremented();
619
620 ValueObjectPrinter child_printer(*(child_sp.get()), m_stream, child_options,
621 ptr_depth, m_curr_depth + 1,
623 llvm::Error error = child_printer.PrintValueObject();
624 if (error) {
625 if (m_stream)
626 *m_stream << "error: " << toString(std::move(error));
627 else
628 llvm::consumeError(std::move(error));
629 }
630 }
631}
632
633llvm::Expected<uint32_t>
636
637 if (m_options.m_pointer_as_array)
638 return m_options.m_pointer_as_array.m_element_count;
639
640 const uint32_t max_num_children =
641 m_options.m_ignore_cap ? UINT32_MAX
643 .GetTargetSP()
644 ->GetMaximumNumberOfChildrenToDisplay();
645 // Ask for one more child than the maximum to see if we should print "...".
646 auto num_children_or_err = synth_valobj.GetNumChildren(
647 llvm::SaturatingAdd(max_num_children, uint32_t(1)));
648 if (!num_children_or_err)
649 return num_children_or_err;
650 if (*num_children_or_err > max_num_children) {
651 print_dotdotdot = true;
652 return max_num_children;
653 }
654 return num_children_or_err;
655}
656
658 if (!m_options.m_flat_output) {
659 if (print_dotdotdot) {
661 .GetTargetSP()
662 ->GetDebugger()
663 .GetCommandInterpreter()
664 .ChildrenTruncated();
665 m_stream->Indent("...\n");
666 }
667 m_stream->IndentLess();
668 m_stream->Indent("}\n");
669 }
670}
671
673 bool summary_printed) {
675
676 if (!IsAggregate())
677 return false;
678
679 if (!m_options.m_reveal_empty_aggregates) {
680 if (value_printed || summary_printed)
681 return false;
682 }
683
684 if (synth_valobj.MightHaveChildren())
685 return true;
686
688 return false;
689
690 return true;
691}
692
693static constexpr size_t PhysicalIndexForLogicalIndex(size_t base, size_t stride,
694 size_t logical) {
695 return base + logical * stride;
696}
697
699 size_t idx) {
700 if (m_options.m_pointer_as_array) {
701 // if generating pointer-as-array children, use GetSyntheticArrayMember
702 return synth_valobj.GetSyntheticArrayMember(
704 m_options.m_pointer_as_array.m_base_element,
705 m_options.m_pointer_as_array.m_stride, idx),
706 true);
707 } else {
708 // otherwise, do the usual thing
709 return synth_valobj.GetChildAtIndex(idx);
710 }
711}
712
714 bool value_printed, bool summary_printed,
715 const DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
717
718 bool print_dotdotdot = false;
719 auto num_children_or_err = GetMaxNumChildrenToPrint(print_dotdotdot);
720 if (!num_children_or_err) {
721 *m_stream << " <" << llvm::toString(num_children_or_err.takeError()) << '>';
722 return;
723 }
724 uint32_t num_children = *num_children_or_err;
725 if (num_children) {
726 bool any_children_printed = false;
727
728 for (size_t idx = 0; idx < num_children; ++idx) {
729 if (ValueObjectSP child_sp = GenerateChild(synth_valobj, idx)) {
730 if (m_options.m_child_printing_decider &&
731 !m_options.m_child_printing_decider(child_sp->GetName()))
732 continue;
733 if (!any_children_printed) {
734 PrintChildrenPreamble(value_printed, summary_printed);
735 any_children_printed = true;
736 }
737 PrintChild(child_sp, curr_ptr_depth);
738 }
739 }
740
741 if (any_children_printed)
742 PrintChildrenPostamble(print_dotdotdot);
743 else {
744 if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) {
746 m_stream->PutCString(" {}\n");
747 else
748 m_stream->EOL();
749 } else
750 m_stream->EOL();
751 }
752 } else if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) {
753 // Aggregate, no children...
755 // if it has a synthetic value, then don't print {}, the synthetic
756 // children are probably only being used to vend a value
757 if (GetMostSpecializedValue().DoesProvideSyntheticValue() ||
759 m_stream->PutCString("\n");
760 else
761 m_stream->PutCString(" {}\n");
762 }
763 } else {
765 m_stream->EOL();
766 }
767}
768
771
772 bool print_dotdotdot = false;
773 auto num_children_or_err = GetMaxNumChildrenToPrint(print_dotdotdot);
774 if (!num_children_or_err) {
775 *m_stream << '<' << llvm::toString(num_children_or_err.takeError()) << '>';
776 return true;
777 }
778 uint32_t num_children = *num_children_or_err;
779
780 if (num_children) {
781 m_stream->PutChar('(');
782
783 bool did_print_children = false;
784 for (uint32_t idx = 0; idx < num_children; ++idx) {
785 lldb::ValueObjectSP child_sp(synth_valobj.GetChildAtIndex(idx));
786 if (child_sp)
787 child_sp = child_sp->GetQualifiedRepresentationIfAvailable(
788 m_options.m_use_dynamic, m_options.m_use_synthetic);
789 if (child_sp) {
790 if (m_options.m_child_printing_decider &&
791 !m_options.m_child_printing_decider(child_sp->GetName()))
792 continue;
793 if (idx && did_print_children)
794 m_stream->PutCString(", ");
795 did_print_children = true;
796 if (!hide_names) {
797 llvm::StringRef name = child_sp.get()->GetName().GetStringRef();
798 if (!name.empty()) {
799 m_stream->PutCString(name);
800 m_stream->PutCString(" = ");
801 }
802 }
803 child_sp->DumpPrintableRepresentation(
805 m_options.m_format,
807 }
808 }
809
810 if (print_dotdotdot)
811 m_stream->PutCString(", ...)");
812 else
813 m_stream->PutChar(')');
814 }
815 return true;
816}
817
818llvm::Error ValueObjectPrinter::PrintChildrenIfNeeded(bool value_printed,
819 bool summary_printed) {
820
822
824 const bool print_children = ShouldPrintChildren(curr_ptr_depth);
825 const bool print_oneline =
826 (curr_ptr_depth.CanAllowExpansion() || m_options.m_show_types ||
827 !m_options.m_allow_oneliner_mode || m_options.m_flat_output ||
828 (m_options.m_pointer_as_array) || m_options.m_show_location)
829 ? false
831 if (print_children && IsInstancePointer()) {
832 uint64_t instance_ptr_value = valobj.GetValueAsUnsigned(0);
833 if (m_printed_instance_pointers->count(instance_ptr_value)) {
834 // We already printed this instance-is-pointer thing, so don't expand it.
835 m_stream->PutCString(" {...}\n");
836 return llvm::Error::success();
837 } else {
838 // Remember this guy for future reference.
839 m_printed_instance_pointers->emplace(instance_ptr_value);
840 }
841 }
842
843 if (print_children) {
844 if (print_oneline) {
845 m_stream->PutChar(' ');
847 m_stream->EOL();
848 } else
849 PrintChildren(value_printed, summary_printed, curr_ptr_depth);
850 } else if (HasReachedMaximumDepth() && IsAggregate() &&
852 m_stream->PutCString(" {...}\n");
853 // The maximum child depth has been reached. If `m_max_depth` is the default
854 // (i.e. the user has _not_ customized it), then lldb presents a warning to
855 // the user. The warning tells the user that the limit has been reached, but
856 // more importantly tells them how to expand the limit if desired.
857 if (m_options.m_max_depth_is_default)
858 valobj.GetTargetSP()
859 ->GetDebugger()
860 .GetCommandInterpreter()
861 .SetReachedMaximumDepth();
862 } else
863 m_stream->EOL();
864 return llvm::Error::success();
865}
866
870
872 if (m_curr_depth == 0)
873 return !m_options.m_hide_root_name && !m_options.m_hide_name;
874 return !m_options.m_hide_name;
875}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:405
static bool IsPointerValue(const CompilerType &type)
static constexpr size_t PhysicalIndexForLogicalIndex(size_t base, size_t stride, size_t logical)
static const char * maybeNewline(const std::string &s)
Generic representation of a type in a programming language.
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
static bool ShouldPrintAsOneLiner(ValueObject &valobj)
DumpValueObjectOptions & SetHideName(bool hide_name=false)
DumpValueObjectOptions & SetSummary(lldb::TypeSummaryImplSP summary=lldb::TypeSummaryImplSP())
DumpValueObjectOptions & SetOmitSummaryDepth(uint32_t depth=0)
DumpValueObjectOptions & SetRootValueObjectName(const char *name=nullptr)
DumpValueObjectOptions & SetFormat(lldb::Format format=lldb::eFormatDefault)
DumpValueObjectOptions & SetScopeChecked(bool check=true)
DumpValueObjectOptions & SetHideValue(bool hide_value=false)
DumpValueObjectOptions & SetElementCount(uint32_t element_count=0)
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
bool AnySet(ValueType mask) const
Test one or more flags.
Definition Flags.h:90
static Language * FindPlugin(lldb::LanguageType language)
Definition Language.cpp:86
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:194
const char * GetData() const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
virtual bool DoesPrintEmptyAggregates() const
virtual bool DoesPrintValue(ValueObject *valobj) const
void PrintChildrenPreamble(bool value_printed, bool summary_printed)
std::shared_ptr< InstancePointersSet > InstancePointersSetSP
ValueObjectPrinter(ValueObject &valobj, Stream *s)
The ValueObjectPrinter is a one-shot printer for ValueObjects.
std::pair< TypeSummaryImpl *, bool > m_summary_formatter
void PrintChild(lldb::ValueObjectSP child_sp, const DumpValueObjectOptions::PointerDepth &curr_ptr_depth)
TypeSummaryImpl * GetSummaryFormatter(bool null_if_omitted=true)
ValueObject & GetMostSpecializedValue()
Cache the ValueObject we are actually going to print.
bool ShouldPrintChildren(DumpValueObjectOptions::PointerDepth &curr_ptr_depth)
DumpValueObjectOptions::PointerDepth m_ptr_depth
void PrintChildrenPostamble(bool print_dotdotdot)
llvm::Error PrintChildrenIfNeeded(bool value_printed, bool summary_printed)
lldb::ValueObjectSP GenerateChild(ValueObject &synth_valobj, size_t idx)
InstancePointersSetSP m_printed_instance_pointers
void Init(ValueObject &valobj, Stream *s, const DumpValueObjectOptions &options, const DumpValueObjectOptions::PointerDepth &ptr_depth, uint32_t curr_depth, InstancePointersSetSP printed_instance_pointers)
Ee should actually be using delegating constructors here but some versions of GCC still have trouble ...
void PrintChildren(bool value_printed, bool summary_printed, const DumpValueObjectOptions::PointerDepth &curr_ptr_depth)
void PrintObjectDescriptionIfNeeded(std::optional< std::string > object_desc)
bool PrintChildrenOneLiner(bool hide_names)
ValueObject * m_cached_valobj
Cache the current "most specialized" value.
void GetValueSummaryError(std::string &value, std::string &summary, std::string &error)
bool PrintValueAndSummaryIfNeeded(bool &value_printed, bool &summary_printed)
llvm::Expected< uint32_t > GetMaxNumChildrenToPrint(bool &print_dotdotdot)
bool ShouldPrintEmptyBrackets(bool value_printed, bool summary_printed)
lldb::TypeSummaryImplSP GetSummaryFormat()
virtual lldb::ValueObjectSP GetChildAtIndex(uint32_t idx, bool can_create=true)
virtual bool MightHaveChildren()
Find out if a ValueObject might have children.
lldb::Format GetFormat() const
virtual uint64_t GetValueAsUnsigned(uint64_t fail_value, bool *success=nullptr)
llvm::Expected< uint32_t > GetNumChildren(uint32_t max=UINT32_MAX)
virtual void GetExpressionPath(Stream &s, GetExpressionPathFormat=eGetExpressionPathFormatDereferencePointers)
virtual ConstString GetDisplayTypeName()
virtual bool IsBaseClass()
const Status & GetError()
lldb::TargetSP GetTargetSP() const
CompilerType GetCompilerType()
virtual const char * GetValueAsCString()
ConstString GetName() const
virtual ConstString GetQualifiedTypeName()
llvm::Expected< std::string > GetObjectDescription()
const char * GetSummaryAsCString(lldb::LanguageType lang=lldb::eLanguageTypeUnknown)
lldb::ValueObjectSP GetSyntheticArrayMember(size_t index, bool can_create)
std::optional< lldb::addr_t > GetStrippedPointerValue(lldb::addr_t address)
Remove ptrauth bits from address if the type has a ptrauth qualifier.
const Value & GetValue() const
virtual lldb::LanguageType GetPreferredDisplayLanguage()
#define UINT32_MAX
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:338
std::string toString(FormatterBytecode::OpCodes op)
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Format
Display format definitions.
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.