18#include "llvm/Support/Error.h"
19#include "llvm/Support/MathExtras.h"
31 Init(valobj, s, options,
m_options.m_max_ptr_depth, 0,
nullptr);
37 Init(valobj, s, options,
m_options.m_max_ptr_depth, 0,
nullptr);
45 Init(valobj, s, options, ptr_depth, curr_depth, printed_instance_pointers);
57 assert(
m_stream &&
"cannot print to a NULL Stream");
71 ? printed_instance_pointers
72 : std::make_shared<InstancePointersSet>();
78 if (s.empty() || s.back() !=
'\n')
96 std::optional<std::string> object_desc;
102 llvm::Expected<std::string> object_desc_or_err =
104 if (!object_desc_or_err) {
105 *
m_stream <<
"warning: `po` was unsuccessful, running `p` instead\n";
107 object_desc_or_err.takeError(),
108 "Object description fallback due to error: {0}");
113 object_desc = *object_desc_or_err;
124 bool value_printed =
false;
125 bool summary_printed =
false;
136 return llvm::Error::success();
140 assert(
m_cached_valobj &&
"ValueObjectPrinter must have a valid ValueObject");
145 bool update_success =
m_orig_valobj.UpdateValueIfNeeded(
true);
149 if (update_success) {
183 "SetupMostSpecialized value must compute a valid ValueObject");
187 const char *root_valobj_name =
191 return root_valobj_name ? root_valobj_name :
"";
242 eTypeInstanceIsPointer) != 0
259 bool show_type =
true;
280 type_name =
m_options.m_use_type_display_name
291 std::string type_name_str(type_name.
GetCString());
293 for (
auto iter = type_name_str.find(
" *"); iter != std::string::npos;
294 iter = type_name_str.find(
" *")) {
295 type_name_str.erase(iter, 2);
298 typeName << type_name_str.c_str();
311 bool decl_printed =
false;
321 m_options.m_decl_printing_helper = lang_plugin->GetDeclPrintingHelper();
335 if (
m_options.m_decl_printing_helper(type_name_cstr, var_name_cstr,
336 decl_print_options, dest_stream)) {
344 if (!typeName.
Empty())
346 if (!varName.
Empty())
371 if (
m_options.m_omit_summary_depth > 0 && null_if_omitted)
378 if (type_flags.
AnySet(eTypeInstanceIsPointer | eTypeIsPointer))
379 return type_flags.
AllClear(eTypeIsBuiltIn);
384 std::string &summary,
385 std::string &
error) {
397 value.assign(val_cstr);
401 error.assign(err_cstr);
412 summary.assign(lang_plugin->GetNilReferenceSummaryString().str());
416 summary.assign(
"NULL");
419 summary.assign(
"<uninitialized>");
420 }
else if (
m_options.m_omit_summary_depth == 0) {
426 const char *sum_cstr =
429 summary.assign(sum_cstr);
435 bool &summary_printed) {
436 bool error_printed =
false;
439 m_error.assign(
"out of scope");
450 m_stream->Printf(
" <could not resolve type>");
454 error_printed =
true;
463 const bool has_nil_or_uninitialized_summary =
465 if (!has_nil_or_uninitialized_summary && !
m_value.empty() &&
476 m_stream->Printf(
" (actual=0x%" PRIx64
")", *stripped);
480 value_printed =
true;
488 summary_printed =
true;
492 return !error_printed;
496 std::optional<std::string> object_desc) {
511 const bool is_ref =
IsRef();
512 const bool is_ptr =
IsPtr();
530 bool print_children =
true;
533 print_children = type_summary->DoesPrintChildren(&valobj);
542 if (is_ptr || is_ref) {
549 const bool is_expanded_ptr =
552 if ((is_ref || is_expanded_ptr) && is_root_level && print_children) {
563 return print_children ||
m_summary.empty();
580 bool summary_printed) {
588 }
else if (value_printed || summary_printed ||
ShouldShowName()) {
600 const uint32_t consumed_summary_depth =
m_options.m_pointer_as_array ? 0 : 1;
601 const bool does_consume_ptr_depth =
613 consumed_summary_depth
617 if (child_sp.get()) {
618 auto ptr_depth = curr_ptr_depth;
619 if (does_consume_ptr_depth)
630 llvm::consumeError(std::move(
error));
635llvm::Expected<uint32_t>
640 return m_options.m_pointer_as_array.m_element_count;
642 const uint32_t max_num_children =
646 ->GetMaximumNumberOfChildrenToDisplay();
649 llvm::SaturatingAdd(max_num_children, uint32_t(1)));
650 if (!num_children_or_err)
651 return num_children_or_err;
652 if (*num_children_or_err > max_num_children) {
653 print_dotdotdot =
true;
654 return max_num_children;
656 return num_children_or_err;
661 if (print_dotdotdot) {
665 .GetCommandInterpreter()
666 .ChildrenTruncated();
675 bool summary_printed) {
681 if (!
m_options.m_reveal_empty_aggregates) {
682 if (value_printed || summary_printed)
697 return base + logical * stride;
706 m_options.m_pointer_as_array.m_base_element,
707 m_options.m_pointer_as_array.m_stride, idx),
716 bool value_printed,
bool summary_printed,
720 bool print_dotdotdot =
false;
722 if (!num_children_or_err) {
723 *
m_stream <<
" <" << llvm::toString(num_children_or_err.takeError()) <<
'>';
726 uint32_t num_children = *num_children_or_err;
728 bool any_children_printed =
false;
730 for (
size_t idx = 0; idx < num_children; ++idx) {
732 if (
m_options.m_child_printing_decider &&
733 !
m_options.m_child_printing_decider(child_sp->GetName()))
735 if (!any_children_printed) {
737 any_children_printed =
true;
743 if (any_children_printed)
774 bool print_dotdotdot =
false;
776 if (!num_children_or_err) {
777 *
m_stream <<
'<' << llvm::toString(num_children_or_err.takeError()) <<
'>';
780 uint32_t num_children = *num_children_or_err;
785 bool did_print_children =
false;
786 for (uint32_t idx = 0; idx < num_children; ++idx) {
789 child_sp = child_sp->GetQualifiedRepresentationIfAvailable(
792 if (
m_options.m_child_printing_decider &&
793 !
m_options.m_child_printing_decider(child_sp->GetName()))
795 if (idx && did_print_children)
797 did_print_children =
true;
799 const char *name = child_sp.get()->GetName().AsCString();
805 child_sp->DumpPrintableRepresentation(
821 bool summary_printed) {
827 const bool print_oneline =
838 return llvm::Error::success();
845 if (print_children) {
851 PrintChildren(value_printed, summary_printed, curr_ptr_depth);
862 .GetCommandInterpreter()
863 .SetReachedMaximumDepth();
866 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.
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
CompilerType GetCompilerType()
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)
std::optional< lldb::addr_t > GetStrippedPointerValue(lldb::addr_t address)
Remove ptrauth bits from address if the type has a ptrauth qualifier.
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.
std::string toString(FormatterBytecode::OpCodes op)
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