17#include "llvm/Support/Error.h"
18#include "llvm/Support/MathExtras.h"
29 Init(valobj, s, options,
m_options.m_max_ptr_depth, 0,
nullptr);
35 Init(valobj, s, options,
m_options.m_max_ptr_depth, 0,
nullptr);
43 Init(valobj, s, options, ptr_depth, curr_depth, printed_instance_pointers);
55 assert(
m_stream &&
"cannot print to a NULL Stream");
69 ? printed_instance_pointers
70 : std::make_shared<InstancePointersSet>();
76 if (s.empty() || s.back() !=
'\n')
94 std::optional<std::string> object_desc;
100 llvm::Expected<std::string> object_desc_or_err =
102 if (!object_desc_or_err) {
103 auto error_msg =
toString(object_desc_or_err.takeError());
109 object_desc = *object_desc_or_err;
120 bool value_printed =
false;
121 bool summary_printed =
false;
132 return llvm::Error::success();
136 assert(
m_cached_valobj &&
"ValueObjectPrinter must have a valid ValueObject");
141 bool update_success =
m_orig_valobj.UpdateValueIfNeeded(
true);
145 if (update_success) {
179 "SetupMostSpecialized value must compute a valid ValueObject");
183 const char *root_valobj_name =
187 return root_valobj_name ? root_valobj_name :
"";
238 eTypeInstanceIsPointer) != 0
255 bool show_type =
true;
276 type_name =
m_options.m_use_type_display_name
287 std::string type_name_str(type_name.
GetCString());
289 for (
auto iter = type_name_str.find(
" *"); iter != std::string::npos;
290 iter = type_name_str.find(
" *")) {
291 type_name_str.erase(iter, 2);
294 typeName << type_name_str.c_str();
307 bool decl_printed =
false;
317 m_options.m_decl_printing_helper = lang_plugin->GetDeclPrintingHelper();
331 if (
m_options.m_decl_printing_helper(type_name_cstr, var_name_cstr,
332 decl_print_options, dest_stream)) {
340 if (!typeName.
Empty())
342 if (!varName.
Empty())
367 if (
m_options.m_omit_summary_depth > 0 && null_if_omitted)
374 if (type_flags.
AnySet(eTypeInstanceIsPointer | eTypeIsPointer))
375 return type_flags.
AllClear(eTypeIsBuiltIn);
380 std::string &summary,
381 std::string &
error) {
393 value.assign(val_cstr);
397 error.assign(err_cstr);
408 summary.assign(lang_plugin->GetNilReferenceSummaryString().str());
412 summary.assign(
"NULL");
415 summary.assign(
"<uninitialized>");
416 }
else if (
m_options.m_omit_summary_depth == 0) {
422 const char *sum_cstr =
425 summary.assign(sum_cstr);
431 bool &summary_printed) {
432 bool error_printed =
false;
435 m_error.assign(
"out of scope");
446 m_stream->Printf(
" <could not resolve type>");
450 error_printed =
true;
459 const bool has_nil_or_uninitialized_summary =
461 if (!has_nil_or_uninitialized_summary && !
m_value.empty() &&
473 value_printed =
true;
481 summary_printed =
true;
485 return !error_printed;
489 std::optional<std::string> object_desc) {
504 const bool is_ref =
IsRef();
505 const bool is_ptr =
IsPtr();
523 bool print_children =
true;
526 print_children = type_summary->DoesPrintChildren(&valobj);
535 if (is_ptr || is_ref) {
542 const bool is_expanded_ptr =
545 if ((is_ref || is_expanded_ptr) && is_root_level && print_children) {
556 return print_children ||
m_summary.empty();
573 bool summary_printed) {
581 }
else if (value_printed || summary_printed ||
ShouldShowName()) {
593 const uint32_t consumed_summary_depth =
m_options.m_pointer_as_array ? 0 : 1;
594 const bool does_consume_ptr_depth =
606 consumed_summary_depth
610 if (child_sp.get()) {
611 auto ptr_depth = curr_ptr_depth;
612 if (does_consume_ptr_depth)
623 llvm::consumeError(std::move(
error));
628llvm::Expected<uint32_t>
633 return m_options.m_pointer_as_array.m_element_count;
635 const uint32_t max_num_children =
639 ->GetMaximumNumberOfChildrenToDisplay();
642 llvm::SaturatingAdd(max_num_children, uint32_t(1)));
643 if (!num_children_or_err)
644 return num_children_or_err;
645 if (*num_children_or_err > max_num_children) {
646 print_dotdotdot =
true;
647 return max_num_children;
649 return num_children_or_err;
654 if (print_dotdotdot) {
658 .GetCommandInterpreter()
659 .ChildrenTruncated();
668 bool summary_printed) {
674 if (!
m_options.m_reveal_empty_aggregates) {
675 if (value_printed || summary_printed)
690 return base + logical * stride;
699 m_options.m_pointer_as_array.m_base_element,
700 m_options.m_pointer_as_array.m_stride, idx),
709 bool value_printed,
bool summary_printed,
713 bool print_dotdotdot =
false;
715 if (!num_children_or_err) {
716 *
m_stream <<
" <" << llvm::toString(num_children_or_err.takeError()) <<
'>';
719 uint32_t num_children = *num_children_or_err;
721 bool any_children_printed =
false;
723 for (
size_t idx = 0; idx < num_children; ++idx) {
725 if (
m_options.m_child_printing_decider &&
726 !
m_options.m_child_printing_decider(child_sp->GetName()))
728 if (!any_children_printed) {
730 any_children_printed =
true;
736 if (any_children_printed)
767 bool print_dotdotdot =
false;
769 if (!num_children_or_err) {
770 *
m_stream <<
'<' << llvm::toString(num_children_or_err.takeError()) <<
'>';
773 uint32_t num_children = *num_children_or_err;
778 bool did_print_children =
false;
779 for (uint32_t idx = 0; idx < num_children; ++idx) {
782 child_sp = child_sp->GetQualifiedRepresentationIfAvailable(
785 if (
m_options.m_child_printing_decider &&
786 !
m_options.m_child_printing_decider(child_sp->GetName()))
788 if (idx && did_print_children)
790 did_print_children =
true;
792 const char *name = child_sp.get()->GetName().AsCString();
798 child_sp->DumpPrintableRepresentation(
814 bool summary_printed) {
820 const bool print_oneline =
831 return llvm::Error::success();
838 if (print_children) {
844 PrintChildren(value_printed, summary_printed, curr_ptr_depth);
855 .GetCommandInterpreter()
856 .SetReachedMaximumDepth();
859 return llvm::Error::success();
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)
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.
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
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)
bool AllClear(ValueType mask) const
Test if all bits in mask are clear.
bool AnySet(ValueType mask) const
Test one or more flags.
static Language * FindPlugin(lldb::LanguageType language)
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.
virtual bool DoesPrintEmptyAggregates() const
virtual bool DoesPrintValue(ValueObject *valobj) const
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
bool ShouldPrintChildren(DumpValueObjectOptions::PointerDepth &curr_ptr_depth)
bool ShouldShowName() const
DumpValueObjectOptions::PointerDepth m_ptr_depth
void SetupMostSpecializedValue()
ValueObject & GetValueObjectForChildrenGeneration()
bool ShouldPrintObjectDescription()
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)
void PrintObjectDescriptionIfNeeded(std::optional< std::string > object_desc)
const char * GetRootNameForDisplay()
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()
bool IsUninitializedReference()
const Status & GetError()
lldb::TargetSP GetTargetSP() const
virtual const char * GetValueAsCString()
AddrAndType GetPointerValue()
ConstString GetName() const
virtual ConstString GetQualifiedTypeName()
llvm::Expected< std::string > GetObjectDescription()
const char * GetSummaryAsCString(lldb::LanguageType lang=lldb::eLanguageTypeUnknown)
@ eValueObjectRepresentationStyleSummary
lldb::ValueObjectSP GetSyntheticArrayMember(size_t index, bool can_create)
const Value & GetValue() const
virtual lldb::LanguageType GetPreferredDisplayLanguage()
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