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();
511 const bool is_ref = IsRef();
512 const bool is_ptr = IsPtr();
513 const bool is_uninit = IsUninitialized();
519 if (HasReachedMaximumDepth())
524 if (m_options.m_pointer_as_array)
527 if (m_options.m_use_objc)
530 bool print_children =
true;
533 print_children = type_summary->DoesPrintChildren(&valobj);
542 if (is_ptr || is_ref) {
549 const bool is_root_level = m_curr_depth == 0;
551 if (is_ref && is_root_level && print_children) {
562 return print_children || m_summary.empty();
575 return GetMostSpecializedValue();
579 bool summary_printed) {
580 if (m_options.m_flat_output) {
581 if (ShouldPrintValueObject())
584 if (ShouldPrintValueObject()) {
586 m_stream->PutCString(
": ");
587 }
else if (value_printed || summary_printed || ShouldShowName()) {
588 m_stream->PutChar(
' ');
590 m_stream->PutCString(
"{\n");
592 m_stream->IndentMore();
599 const uint32_t consumed_summary_depth = m_options.m_pointer_as_array ? 0 : 1;
600 const bool does_consume_ptr_depth =
601 ((IsPtr() && !m_options.m_pointer_as_array) || IsRef());
604 child_options.
SetFormat(m_options.m_format)
612 consumed_summary_depth
616 if (child_sp.get()) {
617 auto ptr_depth = curr_ptr_depth;
618 if (does_consume_ptr_depth)
622 ptr_depth, m_curr_depth + 1,
623 m_printed_instance_pointers);
629 llvm::consumeError(std::move(
error));
634llvm::Expected<uint32_t>
636 ValueObject &synth_valobj = GetValueObjectForChildrenGeneration();
638 if (m_options.m_pointer_as_array)
639 return m_options.m_pointer_as_array.m_element_count;
641 const uint32_t max_num_children =
643 : GetMostSpecializedValue()
645 ->GetMaximumNumberOfChildrenToDisplay();
648 llvm::SaturatingAdd(max_num_children, uint32_t(1)));
649 if (!num_children_or_err)
650 return num_children_or_err;
651 if (*num_children_or_err > max_num_children) {
652 print_dotdotdot =
true;
653 return max_num_children;
655 return num_children_or_err;
659 if (!m_options.m_flat_output) {
660 if (print_dotdotdot) {
661 GetMostSpecializedValue()
664 .GetCommandInterpreter()
665 .ChildrenTruncated();
666 m_stream->Indent(
"...\n");
668 m_stream->IndentLess();
669 m_stream->Indent(
"}\n");
674 bool summary_printed) {
675 ValueObject &synth_valobj = GetValueObjectForChildrenGeneration();
680 if (!m_options.m_reveal_empty_aggregates) {
681 if (value_printed || summary_printed)
688 if (m_val_summary_ok)
696 return base + logical * stride;
701 if (m_options.m_pointer_as_array) {
705 m_options.m_pointer_as_array.m_base_element,
706 m_options.m_pointer_as_array.m_stride, idx),
715 bool value_printed,
bool summary_printed,
717 ValueObject &synth_valobj = GetValueObjectForChildrenGeneration();
719 bool print_dotdotdot =
false;
720 auto num_children_or_err = GetMaxNumChildrenToPrint(print_dotdotdot);
721 if (!num_children_or_err) {
722 *m_stream <<
" <" << llvm::toString(num_children_or_err.takeError()) <<
'>';
725 uint32_t num_children = *num_children_or_err;
727 bool any_children_printed =
false;
729 for (
size_t idx = 0; idx < num_children; ++idx) {
730 if (
ValueObjectSP child_sp = GenerateChild(synth_valobj, idx)) {
731 if (m_options.m_child_printing_decider &&
732 !m_options.m_child_printing_decider(child_sp->GetName()))
734 if (!any_children_printed) {
735 PrintChildrenPreamble(value_printed, summary_printed);
736 any_children_printed =
true;
738 PrintChild(child_sp, curr_ptr_depth);
742 if (any_children_printed)
743 PrintChildrenPostamble(print_dotdotdot);
745 if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) {
746 if (ShouldPrintValueObject())
747 m_stream->PutCString(
" {}\n");
753 }
else if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) {
755 if (ShouldPrintValueObject()) {
758 if (GetMostSpecializedValue().DoesProvideSyntheticValue() ||
759 !ShouldExpandEmptyAggregates())
760 m_stream->PutCString(
"\n");
762 m_stream->PutCString(
" {}\n");
765 if (ShouldPrintValueObject())
771 ValueObject &synth_valobj = GetValueObjectForChildrenGeneration();
773 bool print_dotdotdot =
false;
774 auto num_children_or_err = GetMaxNumChildrenToPrint(print_dotdotdot);
775 if (!num_children_or_err) {
776 *m_stream <<
'<' << llvm::toString(num_children_or_err.takeError()) <<
'>';
779 uint32_t num_children = *num_children_or_err;
782 m_stream->PutChar(
'(');
784 bool did_print_children =
false;
785 for (uint32_t idx = 0; idx < num_children; ++idx) {
788 child_sp = child_sp->GetQualifiedRepresentationIfAvailable(
789 m_options.m_use_dynamic, m_options.m_use_synthetic);
791 if (m_options.m_child_printing_decider &&
792 !m_options.m_child_printing_decider(child_sp->GetName()))
794 if (idx && did_print_children)
795 m_stream->PutCString(
", ");
796 did_print_children =
true;
798 const char *name = child_sp.get()->GetName().AsCString();
800 m_stream->PutCString(name);
801 m_stream->PutCString(
" = ");
804 child_sp->DumpPrintableRepresentation(
812 m_stream->PutCString(
", ...)");
814 m_stream->PutChar(
')');
820 bool summary_printed) {
821 auto error = PrintObjectDescriptionIfNeeded(value_printed, summary_printed);
828 const bool print_children = ShouldPrintChildren(curr_ptr_depth);
829 const bool print_oneline =
831 !m_options.m_allow_oneliner_mode || m_options.m_flat_output ||
832 (m_options.m_pointer_as_array) || m_options.m_show_location)
835 if (print_children && IsInstancePointer()) {
837 if (m_printed_instance_pointers->count(instance_ptr_value)) {
839 m_stream->PutCString(
" {...}\n");
840 return llvm::Error::success();
843 m_printed_instance_pointers->emplace(instance_ptr_value);
847 if (print_children) {
849 m_stream->PutChar(
' ');
850 PrintChildrenOneLiner(
false);
853 PrintChildren(value_printed, summary_printed, curr_ptr_depth);
854 }
else if (HasReachedMaximumDepth() && IsAggregate() &&
855 ShouldPrintValueObject()) {
856 m_stream->PutCString(
"{...}\n");
861 if (m_options.m_max_depth_is_default)
864 .GetCommandInterpreter()
865 .SetReachedMaximumDepth();
868 return llvm::Error::success();
872 return m_curr_depth >= m_options.m_max_depth;
876 if (m_curr_depth == 0)
877 return !m_options.m_hide_root_name && !m_options.m_hide_name;
878 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
FIXME: Replace all uses with takeError() instead.
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.
PointerDepth Decremented() const
bool CanAllowExpansion() const