18#include "llvm/Support/Error.h"
19#include "llvm/Support/MathExtras.h"
30 Init(valobj, s, options,
m_options.m_max_ptr_depth, 0,
nullptr);
36 Init(valobj, s, options,
m_options.m_max_ptr_depth, 0,
nullptr);
44 Init(valobj, s, options, ptr_depth, curr_depth, printed_instance_pointers);
56 assert(
m_stream &&
"cannot print to a NULL Stream");
70 ? printed_instance_pointers
71 : std::make_shared<InstancePointersSet>();
77 if (s.empty() || s.back() !=
'\n')
95 std::optional<std::string> object_desc;
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}");
112 object_desc = *object_desc_or_err;
123 bool value_printed =
false;
124 bool summary_printed =
false;
135 return llvm::Error::success();
139 assert(
m_cached_valobj &&
"ValueObjectPrinter must have a valid ValueObject");
144 bool update_success =
m_orig_valobj.UpdateValueIfNeeded(
true);
148 if (update_success) {
182 "SetupMostSpecialized value must compute a valid ValueObject");
186 const char *root_valobj_name =
190 return root_valobj_name ? root_valobj_name :
"";
241 eTypeInstanceIsPointer) != 0
258 bool show_type =
true;
279 type_name =
m_options.m_use_type_display_name
290 std::string type_name_str(type_name.
GetCString());
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);
297 typeName << type_name_str.c_str();
310 bool decl_printed =
false;
320 m_options.m_decl_printing_helper = lang_plugin->GetDeclPrintingHelper();
334 if (
m_options.m_decl_printing_helper(type_name_cstr, var_name_cstr,
335 decl_print_options, dest_stream)) {
343 if (!typeName.
Empty())
345 if (!varName.
Empty())
370 if (
m_options.m_omit_summary_depth > 0 && null_if_omitted)
377 if (type_flags.
AnySet(eTypeInstanceIsPointer | eTypeIsPointer))
378 return type_flags.
AllClear(eTypeIsBuiltIn);
383 std::string &summary,
384 std::string &
error) {
396 value.assign(val_cstr);
400 error.assign(err_cstr);
411 summary.assign(lang_plugin->GetNilReferenceSummaryString().str());
415 summary.assign(
"NULL");
418 summary.assign(
"<uninitialized>");
419 }
else if (
m_options.m_omit_summary_depth == 0) {
425 const char *sum_cstr =
428 summary.assign(sum_cstr);
434 bool &summary_printed) {
435 bool error_printed =
false;
438 m_error.assign(
"out of scope");
449 m_stream->Printf(
" <could not resolve type>");
453 error_printed =
true;
462 const bool has_nil_or_uninitialized_summary =
464 if (!has_nil_or_uninitialized_summary && !
m_value.empty() &&
476 value_printed =
true;
484 summary_printed =
true;
488 return !error_printed;
492 std::optional<std::string> object_desc) {
507 const bool is_ref =
IsRef();
508 const bool is_ptr =
IsPtr();
526 bool print_children =
true;
529 print_children = type_summary->DoesPrintChildren(&valobj);
538 if (is_ptr || is_ref) {
545 const bool is_expanded_ptr =
548 if ((is_ref || is_expanded_ptr) && is_root_level && print_children) {
559 return print_children ||
m_summary.empty();
576 bool summary_printed) {
584 }
else if (value_printed || summary_printed ||
ShouldShowName()) {
596 const uint32_t consumed_summary_depth =
m_options.m_pointer_as_array ? 0 : 1;
597 const bool does_consume_ptr_depth =
609 consumed_summary_depth
613 if (child_sp.get()) {
614 auto ptr_depth = curr_ptr_depth;
615 if (does_consume_ptr_depth)
626 llvm::consumeError(std::move(
error));
631llvm::Expected<uint32_t>
636 return m_options.m_pointer_as_array.m_element_count;
638 const uint32_t max_num_children =
642 ->GetMaximumNumberOfChildrenToDisplay();
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;
652 return num_children_or_err;
657 if (print_dotdotdot) {
661 .GetCommandInterpreter()
662 .ChildrenTruncated();
671 bool summary_printed) {
677 if (!
m_options.m_reveal_empty_aggregates) {
678 if (value_printed || summary_printed)
693 return base + logical * stride;
702 m_options.m_pointer_as_array.m_base_element,
703 m_options.m_pointer_as_array.m_stride, idx),
712 bool value_printed,
bool summary_printed,
716 bool print_dotdotdot =
false;
718 if (!num_children_or_err) {
719 *
m_stream <<
" <" << llvm::toString(num_children_or_err.takeError()) <<
'>';
722 uint32_t num_children = *num_children_or_err;
724 bool any_children_printed =
false;
726 for (
size_t idx = 0; idx < num_children; ++idx) {
728 if (
m_options.m_child_printing_decider &&
729 !
m_options.m_child_printing_decider(child_sp->GetName()))
731 if (!any_children_printed) {
733 any_children_printed =
true;
739 if (any_children_printed)
770 bool print_dotdotdot =
false;
772 if (!num_children_or_err) {
773 *
m_stream <<
'<' << llvm::toString(num_children_or_err.takeError()) <<
'>';
776 uint32_t num_children = *num_children_or_err;
781 bool did_print_children =
false;
782 for (uint32_t idx = 0; idx < num_children; ++idx) {
785 child_sp = child_sp->GetQualifiedRepresentationIfAvailable(
788 if (
m_options.m_child_printing_decider &&
789 !
m_options.m_child_printing_decider(child_sp->GetName()))
791 if (idx && did_print_children)
793 did_print_children =
true;
795 const char *name = child_sp.get()->GetName().AsCString();
801 child_sp->DumpPrintableRepresentation(
817 bool summary_printed) {
823 const bool print_oneline =
834 return llvm::Error::success();
841 if (print_children) {
847 PrintChildren(value_printed, summary_printed, curr_ptr_depth);
858 .GetCommandInterpreter()
859 .SetReachedMaximumDepth();
862 return llvm::Error::success();
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG_ERROR(log, error,...)
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.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
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