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