17#include "llvm/Support/MathExtras.h"
24 : m_orig_valobj(valobj) {
31 : m_orig_valobj(valobj) {
39 : m_orig_valobj(valobj) {
40 Init(valobj, s, options, ptr_depth, curr_depth, printed_instance_pointers);
52 assert(
m_stream &&
"cannot print to a NULL Stream");
66 printed_instance_pointers
67 ? printed_instance_pointers
87 bool value_printed =
false;
88 bool summary_printed =
false;
97 return llvm::Error::success();
101 assert(
m_cached_valobj &&
"ValueObjectPrinter must have a valid ValueObject");
110 if (update_success) {
144 "SetupMostSpecialized value must compute a valid ValueObject");
153 const char *str =
nullptr;
161 llvm::consumeError(maybe_str.takeError());
166 const char *root_valobj_name =
170 return root_valobj_name ? root_valobj_name :
"";
221 eTypeInstanceIsPointer) != 0
238 bool show_type =
true;
270 std::string type_name_str(type_name.
GetCString());
272 for (
auto iter = type_name_str.find(
" *"); iter != std::string::npos;
273 iter = type_name_str.find(
" *")) {
274 type_name_str.erase(iter, 2);
277 typeName << type_name_str.c_str();
290 bool decl_printed =
false;
315 decl_print_options, dest_stream)) {
323 if (!typeName.
Empty())
325 if (!varName.
Empty())
357 if (type_flags.
AnySet(eTypeInstanceIsPointer | eTypeIsPointer))
358 return type_flags.
AllClear(eTypeIsBuiltIn);
363 std::string &summary,
364 std::string &
error) {
376 value.assign(val_cstr);
380 error.assign(err_cstr);
391 summary.assign(lang_plugin->GetNilReferenceSummaryString().str());
395 summary.assign(
"NULL");
398 summary.assign(
"<uninitialized>");
405 const char *sum_cstr =
408 summary.assign(sum_cstr);
414 bool &summary_printed) {
415 bool error_printed =
false;
418 m_error.assign(
"out of scope");
433 error_printed =
true;
442 const bool has_nil_or_uninitialized_summary =
444 if (!has_nil_or_uninitialized_summary && !
m_value.empty() &&
456 value_printed =
true;
464 summary_printed =
true;
468 return !error_printed;
473 bool summary_printed) {
480 llvm::Expected<std::string> object_desc =
481 (value_printed || summary_printed)
486 if (!value_printed && !summary_printed)
487 return object_desc.takeError();
491 *
m_stream <<
"warning: no object description available\n";
492 llvm::consumeError(object_desc.takeError());
496 if (object_desc->empty() || object_desc->back() !=
'\n')
499 return llvm::Error::success();
502 return llvm::Error::success();
518 const bool is_ref = IsRef();
519 const bool is_ptr = IsPtr();
520 const bool is_uninit = IsUninitialized();
526 if (HasReachedMaximumDepth())
531 if (m_options.m_pointer_as_array)
534 if (m_options.m_use_objc)
537 bool print_children =
true;
540 print_children = type_summary->DoesPrintChildren(&valobj);
549 if (is_ptr || is_ref) {
556 const bool is_root_level = m_curr_depth == 0;
558 if (is_ref && is_root_level && print_children) {
569 return print_children || m_summary.empty();
582 return GetMostSpecializedValue();
586 bool summary_printed) {
587 if (m_options.m_flat_output) {
588 if (ShouldPrintValueObject())
591 if (ShouldPrintValueObject()) {
593 m_stream->PutCString(
": ");
594 }
else if (value_printed || summary_printed || ShouldShowName()) {
595 m_stream->PutChar(
' ');
597 m_stream->PutCString(
"{\n");
599 m_stream->IndentMore();
606 const uint32_t consumed_summary_depth = m_options.m_pointer_as_array ? 0 : 1;
607 const bool does_consume_ptr_depth =
608 ((IsPtr() && !m_options.m_pointer_as_array) || IsRef());
611 child_options.
SetFormat(m_options.m_format)
619 consumed_summary_depth
623 if (child_sp.get()) {
624 auto ptr_depth = curr_ptr_depth;
625 if (does_consume_ptr_depth)
629 ptr_depth, m_curr_depth + 1,
630 m_printed_instance_pointers);
636 llvm::consumeError(std::move(
error));
641llvm::Expected<uint32_t>
643 ValueObject &synth_valobj = GetValueObjectForChildrenGeneration();
645 if (m_options.m_pointer_as_array)
646 return m_options.m_pointer_as_array.m_element_count;
648 const uint32_t max_num_children =
650 : GetMostSpecializedValue()
652 ->GetMaximumNumberOfChildrenToDisplay();
655 llvm::SaturatingAdd(max_num_children, uint32_t(1)));
656 if (!num_children_or_err)
657 return num_children_or_err;
658 if (*num_children_or_err > max_num_children) {
659 print_dotdotdot =
true;
660 return max_num_children;
662 return num_children_or_err;
666 if (!m_options.m_flat_output) {
667 if (print_dotdotdot) {
668 GetMostSpecializedValue()
671 .GetCommandInterpreter()
672 .ChildrenTruncated();
673 m_stream->Indent(
"...\n");
675 m_stream->IndentLess();
676 m_stream->Indent(
"}\n");
681 bool summary_printed) {
682 ValueObject &synth_valobj = GetValueObjectForChildrenGeneration();
687 if (!m_options.m_reveal_empty_aggregates) {
688 if (value_printed || summary_printed)
695 if (m_val_summary_ok)
703 return base + logical * stride;
708 if (m_options.m_pointer_as_array) {
712 m_options.m_pointer_as_array.m_base_element,
713 m_options.m_pointer_as_array.m_stride, idx),
722 bool value_printed,
bool summary_printed,
724 ValueObject &synth_valobj = GetValueObjectForChildrenGeneration();
726 bool print_dotdotdot =
false;
727 auto num_children_or_err = GetMaxNumChildrenToPrint(print_dotdotdot);
728 if (!num_children_or_err) {
729 *m_stream <<
" <" << llvm::toString(num_children_or_err.takeError()) <<
'>';
732 uint32_t num_children = *num_children_or_err;
734 bool any_children_printed =
false;
736 for (
size_t idx = 0; idx < num_children; ++idx) {
737 if (
ValueObjectSP child_sp = GenerateChild(synth_valobj, idx)) {
738 if (m_options.m_child_printing_decider &&
739 !m_options.m_child_printing_decider(child_sp->GetName()))
741 if (!any_children_printed) {
742 PrintChildrenPreamble(value_printed, summary_printed);
743 any_children_printed =
true;
745 PrintChild(child_sp, curr_ptr_depth);
749 if (any_children_printed)
750 PrintChildrenPostamble(print_dotdotdot);
752 if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) {
753 if (ShouldPrintValueObject())
754 m_stream->PutCString(
" {}\n");
760 }
else if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) {
762 if (ShouldPrintValueObject()) {
765 if (GetMostSpecializedValue().DoesProvideSyntheticValue() ||
766 !ShouldExpandEmptyAggregates())
767 m_stream->PutCString(
"\n");
769 m_stream->PutCString(
" {}\n");
772 if (ShouldPrintValueObject())
778 ValueObject &synth_valobj = GetValueObjectForChildrenGeneration();
780 bool print_dotdotdot =
false;
781 auto num_children_or_err = GetMaxNumChildrenToPrint(print_dotdotdot);
782 if (!num_children_or_err) {
783 *m_stream <<
'<' << llvm::toString(num_children_or_err.takeError()) <<
'>';
786 uint32_t num_children = *num_children_or_err;
789 m_stream->PutChar(
'(');
791 bool did_print_children =
false;
792 for (uint32_t idx = 0; idx < num_children; ++idx) {
795 child_sp = child_sp->GetQualifiedRepresentationIfAvailable(
796 m_options.m_use_dynamic, m_options.m_use_synthetic);
798 if (m_options.m_child_printing_decider &&
799 !m_options.m_child_printing_decider(child_sp->GetName()))
801 if (idx && did_print_children)
802 m_stream->PutCString(
", ");
803 did_print_children =
true;
805 const char *name = child_sp.get()->GetName().AsCString();
807 m_stream->PutCString(name);
808 m_stream->PutCString(
" = ");
811 child_sp->DumpPrintableRepresentation(
819 m_stream->PutCString(
", ...)");
821 m_stream->PutChar(
')');
827 bool summary_printed) {
828 auto error = PrintObjectDescriptionIfNeeded(value_printed, summary_printed);
835 const bool print_children = ShouldPrintChildren(curr_ptr_depth);
836 const bool print_oneline =
838 !m_options.m_allow_oneliner_mode || m_options.m_flat_output ||
839 (m_options.m_pointer_as_array) || m_options.m_show_location)
842 if (print_children && IsInstancePointer()) {
844 if (m_printed_instance_pointers->count(instance_ptr_value)) {
846 m_stream->PutCString(
" {...}\n");
847 return llvm::Error::success();
850 m_printed_instance_pointers->emplace(instance_ptr_value);
854 if (print_children) {
856 m_stream->PutChar(
' ');
857 PrintChildrenOneLiner(
false);
860 PrintChildren(value_printed, summary_printed, curr_ptr_depth);
861 }
else if (HasReachedMaximumDepth() && IsAggregate() &&
862 ShouldPrintValueObject()) {
863 m_stream->PutCString(
"{...}\n");
868 if (m_options.m_max_depth_is_default)
871 .GetCommandInterpreter()
872 .SetReachedMaximumDepth();
875 return llvm::Error::success();
879 return m_curr_depth >= m_options.m_max_depth;
883 if (m_curr_depth == 0)
884 return !m_options.m_hide_root_name && !m_options.m_hide_name;
885 return !m_options.m_hide_name;
static llvm::raw_ostream & error(Stream &strm)
static bool IsPointerValue(const CompilerType &type)
static constexpr size_t PhysicalIndexForLogicalIndex(size_t base, size_t stride, size_t logical)
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.
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)
uint32_t m_omit_summary_depth
lldb::DynamicValueType m_use_dynamic
DumpValueObjectOptions & SetSummary(lldb::TypeSummaryImplSP summary=lldb::TypeSummaryImplSP())
bool m_hide_pointer_value
std::string m_root_valobj_name
bool m_use_type_display_name
bool m_scope_already_checked
PointerDepth m_max_ptr_depth
DumpValueObjectOptions & SetOmitSummaryDepth(uint32_t depth=0)
PointerAsArraySettings m_pointer_as_array
DumpValueObjectOptions & SetRootValueObjectName(const char *name=nullptr)
DumpValueObjectOptions & SetFormat(lldb::Format format=lldb::eFormatDefault)
DumpValueObjectOptions & SetScopeChecked(bool check=true)
lldb::TypeSummaryImplSP m_summary_sp
DeclPrintingHelper m_decl_printing_helper
DumpValueObjectOptions & SetHideValue(bool hide_value=false)
lldb::LanguageType m_varformat_language
DumpValueObjectOptions & SetElementCount(uint32_t element_count=0)
bool AllClear(ValueType mask) const
Test if all bits in mask are clear.
bool Test(ValueType bit) const
Test a single flag bit.
bool AnySet(ValueType mask) const
Test one or more flags.
static Language * FindPlugin(lldb::LanguageType language)
llvm::Error ToError() const
bool Fail() const
Test for error condition.
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
const char * GetData() const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
size_t EOL()
Output and End of Line character to the stream.
virtual bool DoesPrintEmptyAggregates() const
virtual bool DoesPrintValue(ValueObject *valobj) const
llvm::Expected< std::string > GetDescriptionForDisplay()
void PrintChildrenPreamble(bool value_printed, bool summary_printed)
std::shared_ptr< InstancePointersSet > InstancePointersSetSP
ValueObject & m_orig_valobj
ValueObjectPrinter(ValueObject &valobj, Stream *s)
The ValueObjectPrinter is a one-shot printer for ValueObjects.
LazyBool m_is_instance_ptr
bool ShouldPrintValueObject()
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 HasReachedMaximumDepth()
DumpValueObjectOptions m_options
llvm::Error PrintObjectDescriptionIfNeeded(bool value_printed, bool summary_printed)
bool ShouldPrintChildren(DumpValueObjectOptions::PointerDepth &curr_ptr_depth)
bool ShouldShowName() const
DumpValueObjectOptions::PointerDepth m_ptr_depth
void SetupMostSpecializedValue()
ValueObject & GetValueObjectForChildrenGeneration()
void PrintChildrenPostamble(bool print_dotdotdot)
CompilerType m_compiler_type
llvm::Error PrintChildrenIfNeeded(bool value_printed, bool summary_printed)
bool ShouldExpandEmptyAggregates()
bool CheckScopeIfNeeded()
llvm::Error PrintValueObject()
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 ...
bool PrintLocationIfNeeded()
void PrintChildren(bool value_printed, bool summary_printed, const DumpValueObjectOptions::PointerDepth &curr_ptr_depth)
const char * GetRootNameForDisplay()
bool PrintChildrenOneLiner(bool hide_names)
ValueObject * m_cached_valobj
Cache the current "most specialized" value.
std::set< uint64_t > InstancePointersSet
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)
lldb::addr_t GetPointerValue(AddressType *address_type=nullptr)
virtual bool MightHaveChildren()
Find out if a ValueObject might have children.
CompilerType GetCompilerType()
lldb::ValueObjectSP GetSyntheticValue()
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 lldb::ValueObjectSP GetDynamicValue(lldb::DynamicValueType valueType)
virtual ConstString GetDisplayTypeName()
virtual bool IsBaseClass()
bool IsUninitializedReference()
bool UpdateValueIfNeeded(bool update_format=true)
const Status & GetError()
lldb::TargetSP GetTargetSP() const
virtual const char * GetValueAsCString()
ConstString GetName() const
virtual lldb::ValueObjectSP GetStaticValue()
virtual ConstString GetQualifiedTypeName()
llvm::Expected< std::string > GetObjectDescription()
virtual lldb::ValueObjectSP GetNonSyntheticValue()
const char * GetSummaryAsCString(lldb::LanguageType lang=lldb::eLanguageTypeUnknown)
@ eValueObjectRepresentationStyleSummary
lldb::ValueObjectSP GetSyntheticArrayMember(size_t index, bool can_create)
virtual bool IsSynthetic()
const Value & GetValue() const
virtual lldb::LanguageType GetPreferredDisplayLanguage()
const CompilerType & GetCompilerType()
A class that represents a running process on the host machine.
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.
enum lldb_private::DumpValueObjectOptions::PointerDepth::Mode m_mode
PointerDepth Decremented() const
bool CanAllowExpansion() const