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 ConstString 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 = ConstString("<invalid type>");
288 }
289
290 if (type_name) {
291 std::string type_name_str(type_name.GetCString());
292 if (m_options.m_hide_pointer_value) {
293 for (auto iter = type_name_str.find(" *"); iter != std::string::npos;
294 iter = type_name_str.find(" *")) {
295 type_name_str.erase(iter, 2);
296 }
297 }
298 typeName << type_name_str.c_str();
299 }
300 }
301
302 StreamString varName;
303
304 if (ShouldShowName()) {
305 if (m_options.m_flat_output)
306 valobj.GetExpressionPath(varName);
307 else
308 varName << GetRootNameForDisplay();
309 }
310
311 bool decl_printed = false;
312 if (!m_options.m_decl_printing_helper) {
313 // if the user didn't give us a custom helper, pick one based upon the
314 // language, either the one that this printer is bound to, or the preferred
315 // one for the ValueObject
316 lldb::LanguageType lang_type =
317 (m_options.m_varformat_language == lldb::eLanguageTypeUnknown)
319 : m_options.m_varformat_language;
320 if (Language *lang_plugin = Language::FindPlugin(lang_type)) {
321 m_options.m_decl_printing_helper = lang_plugin->GetDeclPrintingHelper();
322 }
323 }
324
325 if (m_options.m_decl_printing_helper) {
326 ConstString type_name_cstr(typeName.GetString());
327 ConstString var_name_cstr(varName.GetString());
328
329 DumpValueObjectOptions decl_print_options = m_options;
330 // Pass printing helpers an option object that indicates whether the name
331 // should be shown or hidden.
332 decl_print_options.SetHideName(!ShouldShowName());
333
334 StreamString dest_stream;
335 if (m_options.m_decl_printing_helper(type_name_cstr, var_name_cstr,
336 decl_print_options, dest_stream)) {
337 decl_printed = true;
338 m_stream->PutCString(dest_stream.GetString());
339 }
340 }
341
342 // if the helper failed, or there is none, do a default thing
343 if (!decl_printed) {
344 if (!typeName.Empty())
345 m_stream->Printf("(%s) ", typeName.GetData());
346 if (!varName.Empty())
347 m_stream->Printf("%s =", varName.GetData());
348 else if (ShouldShowName())
349 m_stream->Printf(" =");
350 }
351}
352
354 if (m_options.m_scope_already_checked)
355 return true;
357}
358
360 if (!m_summary_formatter.second) {
361 TypeSummaryImpl *entry =
362 m_options.m_summary_sp
363 ? m_options.m_summary_sp.get()
365
366 if (m_options.m_omit_summary_depth > 0)
367 entry = nullptr;
368 m_summary_formatter.first = entry;
369 m_summary_formatter.second = true;
370 }
371 if (m_options.m_omit_summary_depth > 0 && null_if_omitted)
372 return nullptr;
373 return m_summary_formatter.first;
374}
375
376static bool IsPointerValue(const CompilerType &type) {
377 Flags type_flags(type.GetTypeInfo());
378 if (type_flags.AnySet(eTypeInstanceIsPointer | eTypeIsPointer))
379 return type_flags.AllClear(eTypeIsBuiltIn);
380 return false;
381}
382
384 std::string &summary,
385 std::string &error) {
386 lldb::Format format = m_options.m_format;
388 // if I am printing synthetized elements, apply the format to those elements
389 // only
390 if (m_options.m_pointer_as_array)
392 else if (format != eFormatDefault && format != valobj.GetFormat())
393 valobj.GetValueAsCString(format, value);
394 else {
395 const char *val_cstr = valobj.GetValueAsCString();
396 if (val_cstr)
397 value.assign(val_cstr);
398 }
399 const char *err_cstr = valobj.GetError().AsCString();
400 if (err_cstr)
401 error.assign(err_cstr);
402
404 return;
405
406 if (IsNil()) {
407 lldb::LanguageType lang_type =
408 (m_options.m_varformat_language == lldb::eLanguageTypeUnknown)
410 : m_options.m_varformat_language;
411 if (Language *lang_plugin = Language::FindPlugin(lang_type)) {
412 summary.assign(lang_plugin->GetNilReferenceSummaryString().str());
413 } else {
414 // We treat C as the fallback language rather than as a separate Language
415 // plugin.
416 summary.assign("NULL");
417 }
418 } else if (IsUninitialized()) {
419 summary.assign("<uninitialized>");
420 } else if (m_options.m_omit_summary_depth == 0) {
422 if (entry) {
423 valobj.GetSummaryAsCString(entry, summary,
424 m_options.m_varformat_language);
425 } else {
426 const char *sum_cstr =
427 valobj.GetSummaryAsCString(m_options.m_varformat_language);
428 if (sum_cstr)
429 summary.assign(sum_cstr);
430 }
431 }
432}
433
435 bool &summary_printed) {
436 bool error_printed = false;
438 if (!CheckScopeIfNeeded())
439 m_error.assign("out of scope");
440 if (m_error.empty()) {
442 }
443 if (m_error.size()) {
444 // we need to support scenarios in which it is actually fine for a value
445 // to have no type but - on the other hand - if we get an error *AND*
446 // have no type, we try to get out gracefully, since most often that
447 // combination means "could not resolve a type" and the default failure
448 // mode is quite ugly
449 if (!m_compiler_type.IsValid()) {
450 m_stream->Printf(" <could not resolve type>");
451 return false;
452 }
453
454 error_printed = true;
455 m_stream->Printf(" <%s>\n", m_error.c_str());
456 } else {
457 // Make sure we have a value and make sure the summary didn't specify
458 // that the value should not be printed - and do not print the value if
459 // this thing is nil (but show the value if the user passes a format
460 // explicitly)
463 const bool has_nil_or_uninitialized_summary =
464 (IsNil() || IsUninitialized()) && !m_summary.empty();
465 if (!has_nil_or_uninitialized_summary && !m_value.empty() &&
466 (entry == nullptr ||
467 (entry->DoesPrintValue(&valobj) ||
468 m_options.m_format != eFormatDefault) ||
469 m_summary.empty()) &&
470 !m_options.m_hide_value) {
471 if (m_options.m_hide_pointer_value &&
473 } else {
474 if (auto stripped = valobj.GetStrippedPointerValue(
475 valobj.GetPointerValue().address))
476 m_stream->Printf(" (actual=0x%" PRIx64 ")", *stripped);
477 if (ShouldShowName())
478 m_stream->PutChar(' ');
479 m_stream->PutCString(m_value);
480 value_printed = true;
481 }
482 }
483
484 if (m_summary.size()) {
485 if (ShouldShowName() || value_printed)
486 m_stream->PutChar(' ');
487 m_stream->PutCString(m_summary);
488 summary_printed = true;
489 }
490 }
491 }
492 return !error_printed;
493}
494
496 std::optional<std::string> object_desc) {
497 if (!object_desc)
498 return;
499
500 if (!m_options.m_hide_value || ShouldShowName())
501 *m_stream << ' ';
502 *m_stream << *object_desc << maybeNewline(*object_desc);
503}
504
508
510 DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
511 const bool is_ref = IsRef();
512 const bool is_ptr = IsPtr();
513 const bool is_uninit = IsUninitialized();
514
515 if (is_uninit)
516 return false;
517
518 // If we have reached the maximum depth we shouldn't print any more children.
520 return false;
521
522 // if the user has specified an element count, always print children as it is
523 // explicit user demand being honored
524 if (m_options.m_pointer_as_array)
525 return true;
526
527 if (m_options.m_use_object_desc)
528 return false;
529
530 bool print_children = true;
532 if (TypeSummaryImpl *type_summary = GetSummaryFormatter())
533 print_children = type_summary->DoesPrintChildren(&valobj);
534
535 // We will show children for all concrete types. We won't show pointer
536 // contents unless a pointer depth has been specified. We won't reference
537 // contents unless the reference is the root object (depth of zero).
538
539 // Use a new temporary pointer depth in case we override the current
540 // pointer depth below...
541
542 if (is_ptr || is_ref) {
543 // We have a pointer or reference whose value is an address. Make sure
544 // that address is not NULL
545 if (valobj.GetPointerValue().address == 0)
546 return false;
547
548 const bool is_root_level = m_curr_depth == 0;
549 const bool is_expanded_ptr =
550 is_ptr && m_type_flags.Test(m_options.m_expand_ptr_type_flags);
551
552 if ((is_ref || is_expanded_ptr) && is_root_level && print_children) {
553 // If this is the root object (depth is zero) that we are showing and it
554 // is either a reference or a preferred type of pointer, then print it.
555 // Don't do this at deeper depths otherwise we can end up with infinite
556 // recursion...
557 return true;
558 }
559
560 return curr_ptr_depth.CanAllowExpansion();
561 }
562
563 return print_children || m_summary.empty();
564}
565
568
569 if (!entry)
570 return true;
571
572 return entry->DoesPrintEmptyAggregates();
573}
574
578
580 bool summary_printed) {
581 if (m_options.m_flat_output) {
583 m_stream->EOL();
584 } else {
586 if (IsRef()) {
587 m_stream->PutCString(": ");
588 } else if (value_printed || summary_printed || ShouldShowName()) {
589 m_stream->PutChar(' ');
590 }
591 m_stream->PutCString("{\n");
592 }
593 m_stream->IndentMore();
594 }
595}
596
598 ValueObjectSP child_sp,
599 const DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
600 const uint32_t consumed_summary_depth = m_options.m_pointer_as_array ? 0 : 1;
601 const bool does_consume_ptr_depth =
602 ((IsPtr() && !m_options.m_pointer_as_array) || IsRef());
603
604 DumpValueObjectOptions child_options(m_options);
605 child_options.SetFormat(m_options.m_format)
606 .SetSummary()
608 child_options.SetScopeChecked(true)
609 .SetHideName(m_options.m_hide_name)
610 .SetHideValue(m_options.m_hide_value)
612 ? child_options.m_omit_summary_depth -
613 consumed_summary_depth
614 : 0)
615 .SetElementCount(0);
616
617 if (child_sp.get()) {
618 auto ptr_depth = curr_ptr_depth;
619 if (does_consume_ptr_depth)
620 ptr_depth = curr_ptr_depth.Decremented();
621
622 ValueObjectPrinter child_printer(*(child_sp.get()), m_stream, child_options,
623 ptr_depth, m_curr_depth + 1,
625 llvm::Error error = child_printer.PrintValueObject();
626 if (error) {
627 if (m_stream)
628 *m_stream << "error: " << toString(std::move(error));
629 else
630 llvm::consumeError(std::move(error));
631 }
632 }
633}
634
635llvm::Expected<uint32_t>
638
639 if (m_options.m_pointer_as_array)
640 return m_options.m_pointer_as_array.m_element_count;
641
642 const uint32_t max_num_children =
643 m_options.m_ignore_cap ? UINT32_MAX
645 .GetTargetSP()
646 ->GetMaximumNumberOfChildrenToDisplay();
647 // Ask for one more child than the maximum to see if we should print "...".
648 auto num_children_or_err = synth_valobj.GetNumChildren(
649 llvm::SaturatingAdd(max_num_children, uint32_t(1)));
650 if (!num_children_or_err)
651 return num_children_or_err;
652 if (*num_children_or_err > max_num_children) {
653 print_dotdotdot = true;
654 return max_num_children;
655 }
656 return num_children_or_err;
657}
658
660 if (!m_options.m_flat_output) {
661 if (print_dotdotdot) {
663 .GetTargetSP()
664 ->GetDebugger()
665 .GetCommandInterpreter()
666 .ChildrenTruncated();
667 m_stream->Indent("...\n");
668 }
669 m_stream->IndentLess();
670 m_stream->Indent("}\n");
671 }
672}
673
675 bool summary_printed) {
677
678 if (!IsAggregate())
679 return false;
680
681 if (!m_options.m_reveal_empty_aggregates) {
682 if (value_printed || summary_printed)
683 return false;
684 }
685
686 if (synth_valobj.MightHaveChildren())
687 return true;
688
690 return false;
691
692 return true;
693}
694
695static constexpr size_t PhysicalIndexForLogicalIndex(size_t base, size_t stride,
696 size_t logical) {
697 return base + logical * stride;
698}
699
701 size_t idx) {
702 if (m_options.m_pointer_as_array) {
703 // if generating pointer-as-array children, use GetSyntheticArrayMember
704 return synth_valobj.GetSyntheticArrayMember(
706 m_options.m_pointer_as_array.m_base_element,
707 m_options.m_pointer_as_array.m_stride, idx),
708 true);
709 } else {
710 // otherwise, do the usual thing
711 return synth_valobj.GetChildAtIndex(idx);
712 }
713}
714
716 bool value_printed, bool summary_printed,
717 const DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
719
720 bool print_dotdotdot = false;
721 auto num_children_or_err = GetMaxNumChildrenToPrint(print_dotdotdot);
722 if (!num_children_or_err) {
723 *m_stream << " <" << llvm::toString(num_children_or_err.takeError()) << '>';
724 return;
725 }
726 uint32_t num_children = *num_children_or_err;
727 if (num_children) {
728 bool any_children_printed = false;
729
730 for (size_t idx = 0; idx < num_children; ++idx) {
731 if (ValueObjectSP child_sp = GenerateChild(synth_valobj, idx)) {
732 if (m_options.m_child_printing_decider &&
733 !m_options.m_child_printing_decider(child_sp->GetName()))
734 continue;
735 if (!any_children_printed) {
736 PrintChildrenPreamble(value_printed, summary_printed);
737 any_children_printed = true;
738 }
739 PrintChild(child_sp, curr_ptr_depth);
740 }
741 }
742
743 if (any_children_printed)
744 PrintChildrenPostamble(print_dotdotdot);
745 else {
746 if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) {
748 m_stream->PutCString(" {}\n");
749 else
750 m_stream->EOL();
751 } else
752 m_stream->EOL();
753 }
754 } else if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) {
755 // Aggregate, no children...
757 // if it has a synthetic value, then don't print {}, the synthetic
758 // children are probably only being used to vend a value
759 if (GetMostSpecializedValue().DoesProvideSyntheticValue() ||
761 m_stream->PutCString("\n");
762 else
763 m_stream->PutCString(" {}\n");
764 }
765 } else {
767 m_stream->EOL();
768 }
769}
770
773
774 bool print_dotdotdot = false;
775 auto num_children_or_err = GetMaxNumChildrenToPrint(print_dotdotdot);
776 if (!num_children_or_err) {
777 *m_stream << '<' << llvm::toString(num_children_or_err.takeError()) << '>';
778 return true;
779 }
780 uint32_t num_children = *num_children_or_err;
781
782 if (num_children) {
783 m_stream->PutChar('(');
784
785 bool did_print_children = false;
786 for (uint32_t idx = 0; idx < num_children; ++idx) {
787 lldb::ValueObjectSP child_sp(synth_valobj.GetChildAtIndex(idx));
788 if (child_sp)
789 child_sp = child_sp->GetQualifiedRepresentationIfAvailable(
790 m_options.m_use_dynamic, m_options.m_use_synthetic);
791 if (child_sp) {
792 if (m_options.m_child_printing_decider &&
793 !m_options.m_child_printing_decider(child_sp->GetName()))
794 continue;
795 if (idx && did_print_children)
796 m_stream->PutCString(", ");
797 did_print_children = true;
798 if (!hide_names) {
799 const char *name = child_sp.get()->GetName().AsCString();
800 if (name && *name) {
801 m_stream->PutCString(name);
802 m_stream->PutCString(" = ");
803 }
804 }
805 child_sp->DumpPrintableRepresentation(
807 m_options.m_format,
809 }
810 }
811
812 if (print_dotdotdot)
813 m_stream->PutCString(", ...)");
814 else
815 m_stream->PutChar(')');
816 }
817 return true;
818}
819
820llvm::Error ValueObjectPrinter::PrintChildrenIfNeeded(bool value_printed,
821 bool summary_printed) {
822
824
826 const bool print_children = ShouldPrintChildren(curr_ptr_depth);
827 const bool print_oneline =
828 (curr_ptr_depth.CanAllowExpansion() || m_options.m_show_types ||
829 !m_options.m_allow_oneliner_mode || m_options.m_flat_output ||
830 (m_options.m_pointer_as_array) || m_options.m_show_location)
831 ? false
833 if (print_children && IsInstancePointer()) {
834 uint64_t instance_ptr_value = valobj.GetValueAsUnsigned(0);
835 if (m_printed_instance_pointers->count(instance_ptr_value)) {
836 // We already printed this instance-is-pointer thing, so don't expand it.
837 m_stream->PutCString(" {...}\n");
838 return llvm::Error::success();
839 } else {
840 // Remember this guy for future reference.
841 m_printed_instance_pointers->emplace(instance_ptr_value);
842 }
843 }
844
845 if (print_children) {
846 if (print_oneline) {
847 m_stream->PutChar(' ');
849 m_stream->EOL();
850 } else
851 PrintChildren(value_printed, summary_printed, curr_ptr_depth);
852 } else if (HasReachedMaximumDepth() && IsAggregate() &&
854 m_stream->PutCString(" {...}\n");
855 // The maximum child depth has been reached. If `m_max_depth` is the default
856 // (i.e. the user has _not_ customized it), then lldb presents a warning to
857 // the user. The warning tells the user that the limit has been reached, but
858 // more importantly tells them how to expand the limit if desired.
859 if (m_options.m_max_depth_is_default)
860 valobj.GetTargetSP()
861 ->GetDebugger()
862 .GetCommandInterpreter()
863 .SetReachedMaximumDepth();
864 } else
865 m_stream->EOL();
866 return llvm::Error::success();
867}
868
872
874 if (m_curr_depth == 0)
875 return !m_options.m_hide_root_name && !m_options.m_hide_name;
876 return !m_options.m_hide_name;
877}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:399
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
A uniqued constant string class.
Definition ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
const char * GetCString() 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:84
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:332
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.