1435933ddSDimitry Andric //===-- ValueObjectPrinter.cpp -----------------------------------*- C++-*-===//
235617911SEd Maste //
335617911SEd Maste // The LLVM Compiler Infrastructure
435617911SEd Maste //
535617911SEd Maste // This file is distributed under the University of Illinois Open Source
635617911SEd Maste // License. See LICENSE.TXT for details.
735617911SEd Maste //
835617911SEd Maste //===----------------------------------------------------------------------===//
935617911SEd Maste
1035617911SEd Maste #include "lldb/DataFormatters/ValueObjectPrinter.h"
1135617911SEd Maste
129f2f44ceSEd Maste #include "lldb/Core/ValueObject.h"
1335617911SEd Maste #include "lldb/DataFormatters/DataVisualization.h"
1435617911SEd Maste #include "lldb/Interpreter/CommandInterpreter.h"
159f2f44ceSEd Maste #include "lldb/Target/Language.h"
1635617911SEd Maste #include "lldb/Target/Target.h"
17f678e45dSDimitry Andric #include "lldb/Utility/Stream.h"
1835617911SEd Maste
1935617911SEd Maste using namespace lldb;
2035617911SEd Maste using namespace lldb_private;
2135617911SEd Maste
ValueObjectPrinter(ValueObject * valobj,Stream * s)22435933ddSDimitry Andric ValueObjectPrinter::ValueObjectPrinter(ValueObject *valobj, Stream *s) {
23435933ddSDimitry Andric if (valobj) {
241c3bbb01SEd Maste DumpValueObjectOptions options(*valobj);
259f2f44ceSEd Maste Init(valobj, s, options, m_options.m_max_ptr_depth, 0, nullptr);
26435933ddSDimitry Andric } else {
271c3bbb01SEd Maste DumpValueObjectOptions options;
289f2f44ceSEd Maste Init(valobj, s, options, m_options.m_max_ptr_depth, 0, nullptr);
291c3bbb01SEd Maste }
301c3bbb01SEd Maste }
311c3bbb01SEd Maste
ValueObjectPrinter(ValueObject * valobj,Stream * s,const DumpValueObjectOptions & options)32435933ddSDimitry Andric ValueObjectPrinter::ValueObjectPrinter(ValueObject *valobj, Stream *s,
33435933ddSDimitry Andric const DumpValueObjectOptions &options) {
349f2f44ceSEd Maste Init(valobj, s, options, m_options.m_max_ptr_depth, 0, nullptr);
3535617911SEd Maste }
3635617911SEd Maste
ValueObjectPrinter(ValueObject * valobj,Stream * s,const DumpValueObjectOptions & options,const DumpValueObjectOptions::PointerDepth & ptr_depth,uint32_t curr_depth,InstancePointersSetSP printed_instance_pointers)37435933ddSDimitry Andric ValueObjectPrinter::ValueObjectPrinter(
38435933ddSDimitry Andric ValueObject *valobj, Stream *s, const DumpValueObjectOptions &options,
39435933ddSDimitry Andric const DumpValueObjectOptions::PointerDepth &ptr_depth, uint32_t curr_depth,
40435933ddSDimitry Andric InstancePointersSetSP printed_instance_pointers) {
419f2f44ceSEd Maste Init(valobj, s, options, ptr_depth, curr_depth, printed_instance_pointers);
4235617911SEd Maste }
4335617911SEd Maste
Init(ValueObject * valobj,Stream * s,const DumpValueObjectOptions & options,const DumpValueObjectOptions::PointerDepth & ptr_depth,uint32_t curr_depth,InstancePointersSetSP printed_instance_pointers)44435933ddSDimitry Andric void ValueObjectPrinter::Init(
45435933ddSDimitry Andric ValueObject *valobj, Stream *s, const DumpValueObjectOptions &options,
46435933ddSDimitry Andric const DumpValueObjectOptions::PointerDepth &ptr_depth, uint32_t curr_depth,
47435933ddSDimitry Andric InstancePointersSetSP printed_instance_pointers) {
4835617911SEd Maste m_orig_valobj = valobj;
4935617911SEd Maste m_valobj = nullptr;
5035617911SEd Maste m_stream = s;
519f2f44ceSEd Maste m_options = options;
5235617911SEd Maste m_ptr_depth = ptr_depth;
5335617911SEd Maste m_curr_depth = curr_depth;
5435617911SEd Maste assert(m_orig_valobj && "cannot print a NULL ValueObject");
5535617911SEd Maste assert(m_stream && "cannot print to a NULL Stream");
5635617911SEd Maste m_should_print = eLazyBoolCalculate;
5735617911SEd Maste m_is_nil = eLazyBoolCalculate;
589f2f44ceSEd Maste m_is_uninit = eLazyBoolCalculate;
5935617911SEd Maste m_is_ptr = eLazyBoolCalculate;
6035617911SEd Maste m_is_ref = eLazyBoolCalculate;
6135617911SEd Maste m_is_aggregate = eLazyBoolCalculate;
629f2f44ceSEd Maste m_is_instance_ptr = eLazyBoolCalculate;
6335617911SEd Maste m_summary_formatter = {nullptr, false};
6435617911SEd Maste m_value.assign("");
6535617911SEd Maste m_summary.assign("");
6635617911SEd Maste m_error.assign("");
679f2f44ceSEd Maste m_val_summary_ok = false;
68435933ddSDimitry Andric m_printed_instance_pointers =
69435933ddSDimitry Andric printed_instance_pointers
70435933ddSDimitry Andric ? printed_instance_pointers
71435933ddSDimitry Andric : InstancePointersSetSP(new InstancePointersSet());
7235617911SEd Maste }
7335617911SEd Maste
PrintValueObject()74435933ddSDimitry Andric bool ValueObjectPrinter::PrintValueObject() {
757aa51b79SEd Maste if (!GetMostSpecializedValue() || m_valobj == nullptr)
7635617911SEd Maste return false;
7735617911SEd Maste
78435933ddSDimitry Andric if (ShouldPrintValueObject()) {
797aa51b79SEd Maste PrintValidationMarkerIfNeeded();
807aa51b79SEd Maste
8135617911SEd Maste PrintLocationIfNeeded();
8235617911SEd Maste m_stream->Indent();
8335617911SEd Maste
849f2f44ceSEd Maste PrintDecl();
8535617911SEd Maste }
8635617911SEd Maste
8735617911SEd Maste bool value_printed = false;
8835617911SEd Maste bool summary_printed = false;
8935617911SEd Maste
90435933ddSDimitry Andric m_val_summary_ok =
91435933ddSDimitry Andric PrintValueAndSummaryIfNeeded(value_printed, summary_printed);
9235617911SEd Maste
939f2f44ceSEd Maste if (m_val_summary_ok)
9435617911SEd Maste PrintChildrenIfNeeded(value_printed, summary_printed);
9535617911SEd Maste else
9635617911SEd Maste m_stream->EOL();
9735617911SEd Maste
987aa51b79SEd Maste PrintValidationErrorIfNeeded();
997aa51b79SEd Maste
10035617911SEd Maste return true;
10135617911SEd Maste }
10235617911SEd Maste
GetMostSpecializedValue()103435933ddSDimitry Andric bool ValueObjectPrinter::GetMostSpecializedValue() {
10435617911SEd Maste if (m_valobj)
10535617911SEd Maste return true;
10635617911SEd Maste bool update_success = m_orig_valobj->UpdateValueIfNeeded(true);
107435933ddSDimitry Andric if (!update_success) {
10835617911SEd Maste m_valobj = m_orig_valobj;
109435933ddSDimitry Andric } else {
110435933ddSDimitry Andric if (m_orig_valobj->IsDynamic()) {
111435933ddSDimitry Andric if (m_options.m_use_dynamic == eNoDynamicValues) {
11235617911SEd Maste ValueObject *static_value = m_orig_valobj->GetStaticValue().get();
11335617911SEd Maste if (static_value)
11435617911SEd Maste m_valobj = static_value;
11535617911SEd Maste else
11635617911SEd Maste m_valobj = m_orig_valobj;
117435933ddSDimitry Andric } else
11835617911SEd Maste m_valobj = m_orig_valobj;
119435933ddSDimitry Andric } else {
120435933ddSDimitry Andric if (m_options.m_use_dynamic != eNoDynamicValues) {
121435933ddSDimitry Andric ValueObject *dynamic_value =
122435933ddSDimitry Andric m_orig_valobj->GetDynamicValue(m_options.m_use_dynamic).get();
12335617911SEd Maste if (dynamic_value)
12435617911SEd Maste m_valobj = dynamic_value;
12535617911SEd Maste else
12635617911SEd Maste m_valobj = m_orig_valobj;
127435933ddSDimitry Andric } else
12835617911SEd Maste m_valobj = m_orig_valobj;
12935617911SEd Maste }
1307aa51b79SEd Maste
131435933ddSDimitry Andric if (m_valobj->IsSynthetic()) {
132*b5893f02SDimitry Andric if (!m_options.m_use_synthetic) {
1337aa51b79SEd Maste ValueObject *non_synthetic = m_valobj->GetNonSyntheticValue().get();
1347aa51b79SEd Maste if (non_synthetic)
1357aa51b79SEd Maste m_valobj = non_synthetic;
1367aa51b79SEd Maste }
137435933ddSDimitry Andric } else {
138*b5893f02SDimitry Andric if (m_options.m_use_synthetic) {
1397aa51b79SEd Maste ValueObject *synthetic = m_valobj->GetSyntheticValue().get();
1407aa51b79SEd Maste if (synthetic)
1417aa51b79SEd Maste m_valobj = synthetic;
1427aa51b79SEd Maste }
1437aa51b79SEd Maste }
14435617911SEd Maste }
1459f2f44ceSEd Maste m_compiler_type = m_valobj->GetCompilerType();
1469f2f44ceSEd Maste m_type_flags = m_compiler_type.GetTypeInfo();
14735617911SEd Maste return true;
14835617911SEd Maste }
14935617911SEd Maste
GetDescriptionForDisplay()150435933ddSDimitry Andric const char *ValueObjectPrinter::GetDescriptionForDisplay() {
15135617911SEd Maste const char *str = m_valobj->GetObjectDescription();
15235617911SEd Maste if (!str)
15335617911SEd Maste str = m_valobj->GetSummaryAsCString();
15435617911SEd Maste if (!str)
15535617911SEd Maste str = m_valobj->GetValueAsCString();
15635617911SEd Maste return str;
15735617911SEd Maste }
15835617911SEd Maste
GetRootNameForDisplay(const char * if_fail)159435933ddSDimitry Andric const char *ValueObjectPrinter::GetRootNameForDisplay(const char *if_fail) {
160435933ddSDimitry Andric const char *root_valobj_name = m_options.m_root_valobj_name.empty()
161435933ddSDimitry Andric ? m_valobj->GetName().AsCString()
162435933ddSDimitry Andric : m_options.m_root_valobj_name.c_str();
16335617911SEd Maste return root_valobj_name ? root_valobj_name : if_fail;
16435617911SEd Maste }
16535617911SEd Maste
ShouldPrintValueObject()166435933ddSDimitry Andric bool ValueObjectPrinter::ShouldPrintValueObject() {
16735617911SEd Maste if (m_should_print == eLazyBoolCalculate)
168435933ddSDimitry Andric m_should_print =
169*b5893f02SDimitry Andric (!m_options.m_flat_output || m_type_flags.Test(eTypeHasValue))
170435933ddSDimitry Andric ? eLazyBoolYes
171435933ddSDimitry Andric : eLazyBoolNo;
17235617911SEd Maste return m_should_print == eLazyBoolYes;
17335617911SEd Maste }
17435617911SEd Maste
IsNil()175435933ddSDimitry Andric bool ValueObjectPrinter::IsNil() {
17635617911SEd Maste if (m_is_nil == eLazyBoolCalculate)
1779f2f44ceSEd Maste m_is_nil = m_valobj->IsNilReference() ? eLazyBoolYes : eLazyBoolNo;
17835617911SEd Maste return m_is_nil == eLazyBoolYes;
17935617911SEd Maste }
18035617911SEd Maste
IsUninitialized()181435933ddSDimitry Andric bool ValueObjectPrinter::IsUninitialized() {
1829f2f44ceSEd Maste if (m_is_uninit == eLazyBoolCalculate)
183435933ddSDimitry Andric m_is_uninit =
184435933ddSDimitry Andric m_valobj->IsUninitializedReference() ? eLazyBoolYes : eLazyBoolNo;
1859f2f44ceSEd Maste return m_is_uninit == eLazyBoolYes;
1869f2f44ceSEd Maste }
1879f2f44ceSEd Maste
IsPtr()188435933ddSDimitry Andric bool ValueObjectPrinter::IsPtr() {
18935617911SEd Maste if (m_is_ptr == eLazyBoolCalculate)
1907aa51b79SEd Maste m_is_ptr = m_type_flags.Test(eTypeIsPointer) ? eLazyBoolYes : eLazyBoolNo;
19135617911SEd Maste return m_is_ptr == eLazyBoolYes;
19235617911SEd Maste }
19335617911SEd Maste
IsRef()194435933ddSDimitry Andric bool ValueObjectPrinter::IsRef() {
19535617911SEd Maste if (m_is_ref == eLazyBoolCalculate)
1967aa51b79SEd Maste m_is_ref = m_type_flags.Test(eTypeIsReference) ? eLazyBoolYes : eLazyBoolNo;
19735617911SEd Maste return m_is_ref == eLazyBoolYes;
19835617911SEd Maste }
19935617911SEd Maste
IsAggregate()200435933ddSDimitry Andric bool ValueObjectPrinter::IsAggregate() {
20135617911SEd Maste if (m_is_aggregate == eLazyBoolCalculate)
202435933ddSDimitry Andric m_is_aggregate =
203435933ddSDimitry Andric m_type_flags.Test(eTypeHasChildren) ? eLazyBoolYes : eLazyBoolNo;
20435617911SEd Maste return m_is_aggregate == eLazyBoolYes;
20535617911SEd Maste }
20635617911SEd Maste
IsInstancePointer()207435933ddSDimitry Andric bool ValueObjectPrinter::IsInstancePointer() {
2089f2f44ceSEd Maste // you need to do this check on the value's clang type
2099f2f44ceSEd Maste if (m_is_instance_ptr == eLazyBoolCalculate)
210435933ddSDimitry Andric m_is_instance_ptr = (m_valobj->GetValue().GetCompilerType().GetTypeInfo() &
211435933ddSDimitry Andric eTypeInstanceIsPointer) != 0
212435933ddSDimitry Andric ? eLazyBoolYes
213435933ddSDimitry Andric : eLazyBoolNo;
2149f2f44ceSEd Maste if ((eLazyBoolYes == m_is_instance_ptr) && m_valobj->IsBaseClass())
2159f2f44ceSEd Maste m_is_instance_ptr = eLazyBoolNo;
2169f2f44ceSEd Maste return m_is_instance_ptr == eLazyBoolYes;
2179f2f44ceSEd Maste }
2189f2f44ceSEd Maste
PrintLocationIfNeeded()219435933ddSDimitry Andric bool ValueObjectPrinter::PrintLocationIfNeeded() {
220435933ddSDimitry Andric if (m_options.m_show_location) {
22135617911SEd Maste m_stream->Printf("%s: ", m_valobj->GetLocationAsCString());
22235617911SEd Maste return true;
22335617911SEd Maste }
22435617911SEd Maste return false;
22535617911SEd Maste }
22635617911SEd Maste
PrintDecl()227435933ddSDimitry Andric void ValueObjectPrinter::PrintDecl() {
22835617911SEd Maste bool show_type = true;
229435933ddSDimitry Andric // if we are at the root-level and been asked to hide the root's type, then
230435933ddSDimitry Andric // hide it
2319f2f44ceSEd Maste if (m_curr_depth == 0 && m_options.m_hide_root_type)
23235617911SEd Maste show_type = false;
23335617911SEd Maste else
234435933ddSDimitry Andric // otherwise decide according to the usual rules (asked to show types -
235435933ddSDimitry Andric // always at the root level)
236435933ddSDimitry Andric show_type = m_options.m_show_types ||
237435933ddSDimitry Andric (m_curr_depth == 0 && !m_options.m_flat_output);
23835617911SEd Maste
2399f2f44ceSEd Maste StreamString typeName;
2409f2f44ceSEd Maste
2419f2f44ceSEd Maste // always show the type at the root level if it is invalid
242435933ddSDimitry Andric if (show_type) {
2434ba319b5SDimitry Andric // Some ValueObjects don't have types (like registers sets). Only print the
2444ba319b5SDimitry Andric // type if there is one to print
2457aa51b79SEd Maste ConstString type_name;
246435933ddSDimitry Andric if (m_compiler_type.IsValid()) {
2479f2f44ceSEd Maste if (m_options.m_use_type_display_name)
2487aa51b79SEd Maste type_name = m_valobj->GetDisplayTypeName();
2490127ef0fSEd Maste else
2507aa51b79SEd Maste type_name = m_valobj->GetQualifiedTypeName();
251435933ddSDimitry Andric } else {
252435933ddSDimitry Andric // only show an invalid type name if the user explicitly triggered
253435933ddSDimitry Andric // show_type
2549f2f44ceSEd Maste if (m_options.m_show_types)
2559f2f44ceSEd Maste type_name = ConstString("<invalid type>");
2569f2f44ceSEd Maste else
2579f2f44ceSEd Maste type_name.Clear();
25835617911SEd Maste }
25935617911SEd Maste
260435933ddSDimitry Andric if (type_name) {
2619f2f44ceSEd Maste std::string type_name_str(type_name.GetCString());
262435933ddSDimitry Andric if (m_options.m_hide_pointer_value) {
263435933ddSDimitry Andric for (auto iter = type_name_str.find(" *"); iter != std::string::npos;
264435933ddSDimitry Andric iter = type_name_str.find(" *")) {
2659f2f44ceSEd Maste type_name_str.erase(iter, 2);
2669f2f44ceSEd Maste }
2679f2f44ceSEd Maste }
2689f2f44ceSEd Maste typeName.Printf("%s", type_name_str.c_str());
2699f2f44ceSEd Maste }
2709f2f44ceSEd Maste }
2719f2f44ceSEd Maste
2729f2f44ceSEd Maste StreamString varName;
2739f2f44ceSEd Maste
274435933ddSDimitry Andric if (m_options.m_flat_output) {
27535617911SEd Maste // If we are showing types, also qualify the C++ base classes
27635617911SEd Maste const bool qualify_cxx_base_classes = show_type;
277435933ddSDimitry Andric if (!m_options.m_hide_name) {
2789f2f44ceSEd Maste m_valobj->GetExpressionPath(varName, qualify_cxx_base_classes);
27935617911SEd Maste }
280435933ddSDimitry Andric } else if (!m_options.m_hide_name) {
28135617911SEd Maste const char *name_cstr = GetRootNameForDisplay("");
2829f2f44ceSEd Maste varName.Printf("%s", name_cstr);
28335617911SEd Maste }
2849f2f44ceSEd Maste
2859f2f44ceSEd Maste bool decl_printed = false;
286435933ddSDimitry Andric if (!m_options.m_decl_printing_helper) {
287435933ddSDimitry Andric // if the user didn't give us a custom helper, pick one based upon the
288435933ddSDimitry Andric // language, either the one that this printer is bound to, or the preferred
289435933ddSDimitry Andric // one for the ValueObject
290435933ddSDimitry Andric lldb::LanguageType lang_type =
291435933ddSDimitry Andric (m_options.m_varformat_language == lldb::eLanguageTypeUnknown)
292435933ddSDimitry Andric ? m_valobj->GetPreferredDisplayLanguage()
293435933ddSDimitry Andric : m_options.m_varformat_language;
294435933ddSDimitry Andric if (Language *lang_plugin = Language::FindPlugin(lang_type)) {
2959f2f44ceSEd Maste m_options.m_decl_printing_helper = lang_plugin->GetDeclPrintingHelper();
2969f2f44ceSEd Maste }
2979f2f44ceSEd Maste }
2989f2f44ceSEd Maste
299435933ddSDimitry Andric if (m_options.m_decl_printing_helper) {
300435933ddSDimitry Andric ConstString type_name_cstr(typeName.GetString());
301435933ddSDimitry Andric ConstString var_name_cstr(varName.GetString());
3029f2f44ceSEd Maste
3039f2f44ceSEd Maste StreamString dest_stream;
304435933ddSDimitry Andric if (m_options.m_decl_printing_helper(type_name_cstr, var_name_cstr,
305435933ddSDimitry Andric m_options, dest_stream)) {
3069f2f44ceSEd Maste decl_printed = true;
307435933ddSDimitry Andric m_stream->PutCString(dest_stream.GetString());
3089f2f44ceSEd Maste }
3099f2f44ceSEd Maste }
3109f2f44ceSEd Maste
3119f2f44ceSEd Maste // if the helper failed, or there is none, do a default thing
312435933ddSDimitry Andric if (!decl_printed) {
313435933ddSDimitry Andric if (!typeName.Empty())
3149f2f44ceSEd Maste m_stream->Printf("(%s) ", typeName.GetData());
315435933ddSDimitry Andric if (!varName.Empty())
3169f2f44ceSEd Maste m_stream->Printf("%s =", varName.GetData());
3179f2f44ceSEd Maste else if (!m_options.m_hide_name)
3189f2f44ceSEd Maste m_stream->Printf(" =");
3199f2f44ceSEd Maste }
32035617911SEd Maste }
32135617911SEd Maste
CheckScopeIfNeeded()322435933ddSDimitry Andric bool ValueObjectPrinter::CheckScopeIfNeeded() {
3239f2f44ceSEd Maste if (m_options.m_scope_already_checked)
32435617911SEd Maste return true;
32535617911SEd Maste return m_valobj->IsInScope();
32635617911SEd Maste }
32735617911SEd Maste
GetSummaryFormatter(bool null_if_omitted)328435933ddSDimitry Andric TypeSummaryImpl *ValueObjectPrinter::GetSummaryFormatter(bool null_if_omitted) {
329*b5893f02SDimitry Andric if (!m_summary_formatter.second) {
330435933ddSDimitry Andric TypeSummaryImpl *entry = m_options.m_summary_sp
331435933ddSDimitry Andric ? m_options.m_summary_sp.get()
332435933ddSDimitry Andric : m_valobj->GetSummaryFormat().get();
33335617911SEd Maste
3349f2f44ceSEd Maste if (m_options.m_omit_summary_depth > 0)
33535617911SEd Maste entry = NULL;
33635617911SEd Maste m_summary_formatter.first = entry;
33735617911SEd Maste m_summary_formatter.second = true;
33835617911SEd Maste }
3399f2f44ceSEd Maste if (m_options.m_omit_summary_depth > 0 && null_if_omitted)
3409f2f44ceSEd Maste return nullptr;
34135617911SEd Maste return m_summary_formatter.first;
34235617911SEd Maste }
34335617911SEd Maste
IsPointerValue(const CompilerType & type)344435933ddSDimitry Andric static bool IsPointerValue(const CompilerType &type) {
3459f2f44ceSEd Maste Flags type_flags(type.GetTypeInfo());
3469f2f44ceSEd Maste if (type_flags.AnySet(eTypeInstanceIsPointer | eTypeIsPointer))
3479f2f44ceSEd Maste return type_flags.AllClear(eTypeIsBuiltIn);
3489f2f44ceSEd Maste return false;
3499f2f44ceSEd Maste }
3509f2f44ceSEd Maste
GetValueSummaryError(std::string & value,std::string & summary,std::string & error)351435933ddSDimitry Andric void ValueObjectPrinter::GetValueSummaryError(std::string &value,
35235617911SEd Maste std::string &summary,
353435933ddSDimitry Andric std::string &error) {
3544bb0738eSEd Maste lldb::Format format = m_options.m_format;
355435933ddSDimitry Andric // if I am printing synthetized elements, apply the format to those elements
356435933ddSDimitry Andric // only
357435933ddSDimitry Andric if (m_options.m_pointer_as_array)
3584bb0738eSEd Maste m_valobj->GetValueAsCString(lldb::eFormatDefault, value);
3594bb0738eSEd Maste else if (format != eFormatDefault && format != m_valobj->GetFormat())
3604bb0738eSEd Maste m_valobj->GetValueAsCString(format, value);
361435933ddSDimitry Andric else {
36235617911SEd Maste const char *val_cstr = m_valobj->GetValueAsCString();
36335617911SEd Maste if (val_cstr)
36435617911SEd Maste value.assign(val_cstr);
36535617911SEd Maste }
36635617911SEd Maste const char *err_cstr = m_valobj->GetError().AsCString();
36735617911SEd Maste if (err_cstr)
36835617911SEd Maste error.assign(err_cstr);
36935617911SEd Maste
370435933ddSDimitry Andric if (ShouldPrintValueObject()) {
37135617911SEd Maste if (IsNil())
37235617911SEd Maste summary.assign("nil");
3739f2f44ceSEd Maste else if (IsUninitialized())
3749f2f44ceSEd Maste summary.assign("<uninitialized>");
375435933ddSDimitry Andric else if (m_options.m_omit_summary_depth == 0) {
37635617911SEd Maste TypeSummaryImpl *entry = GetSummaryFormatter();
37735617911SEd Maste if (entry)
378435933ddSDimitry Andric m_valobj->GetSummaryAsCString(entry, summary,
379435933ddSDimitry Andric m_options.m_varformat_language);
380435933ddSDimitry Andric else {
381435933ddSDimitry Andric const char *sum_cstr =
382435933ddSDimitry Andric m_valobj->GetSummaryAsCString(m_options.m_varformat_language);
38335617911SEd Maste if (sum_cstr)
38435617911SEd Maste summary.assign(sum_cstr);
38535617911SEd Maste }
38635617911SEd Maste }
38735617911SEd Maste }
38835617911SEd Maste }
38935617911SEd Maste
PrintValueAndSummaryIfNeeded(bool & value_printed,bool & summary_printed)390435933ddSDimitry Andric bool ValueObjectPrinter::PrintValueAndSummaryIfNeeded(bool &value_printed,
391435933ddSDimitry Andric bool &summary_printed) {
39235617911SEd Maste bool error_printed = false;
393435933ddSDimitry Andric if (ShouldPrintValueObject()) {
39435617911SEd Maste if (!CheckScopeIfNeeded())
39535617911SEd Maste m_error.assign("out of scope");
396435933ddSDimitry Andric if (m_error.empty()) {
39735617911SEd Maste GetValueSummaryError(m_value, m_summary, m_error);
39835617911SEd Maste }
399435933ddSDimitry Andric if (m_error.size()) {
400435933ddSDimitry Andric // we need to support scenarios in which it is actually fine for a value
4014ba319b5SDimitry Andric // to have no type but - on the other hand - if we get an error *AND*
4024ba319b5SDimitry Andric // have no type, we try to get out gracefully, since most often that
4034ba319b5SDimitry Andric // combination means "could not resolve a type" and the default failure
4044ba319b5SDimitry Andric // mode is quite ugly
405435933ddSDimitry Andric if (!m_compiler_type.IsValid()) {
4069f2f44ceSEd Maste m_stream->Printf(" <could not resolve type>");
4079f2f44ceSEd Maste return false;
4089f2f44ceSEd Maste }
4099f2f44ceSEd Maste
41035617911SEd Maste error_printed = true;
41135617911SEd Maste m_stream->Printf(" <%s>\n", m_error.c_str());
412435933ddSDimitry Andric } else {
4134ba319b5SDimitry Andric // Make sure we have a value and make sure the summary didn't specify
4144ba319b5SDimitry Andric // that the value should not be printed - and do not print the value if
4154ba319b5SDimitry Andric // this thing is nil (but show the value if the user passes a format
4164ba319b5SDimitry Andric // explicitly)
41735617911SEd Maste TypeSummaryImpl *entry = GetSummaryFormatter();
418435933ddSDimitry Andric if (!IsNil() && !IsUninitialized() && !m_value.empty() &&
419435933ddSDimitry Andric (entry == NULL || (entry->DoesPrintValue(m_valobj) ||
420435933ddSDimitry Andric m_options.m_format != eFormatDefault) ||
421435933ddSDimitry Andric m_summary.empty()) &&
422435933ddSDimitry Andric !m_options.m_hide_value) {
423435933ddSDimitry Andric if (m_options.m_hide_pointer_value &&
424435933ddSDimitry Andric IsPointerValue(m_valobj->GetCompilerType())) {
425435933ddSDimitry Andric } else {
42635617911SEd Maste m_stream->Printf(" %s", m_value.c_str());
42735617911SEd Maste value_printed = true;
42835617911SEd Maste }
4299f2f44ceSEd Maste }
43035617911SEd Maste
431435933ddSDimitry Andric if (m_summary.size()) {
43235617911SEd Maste m_stream->Printf(" %s", m_summary.c_str());
43335617911SEd Maste summary_printed = true;
43435617911SEd Maste }
43535617911SEd Maste }
43635617911SEd Maste }
43735617911SEd Maste return !error_printed;
43835617911SEd Maste }
43935617911SEd Maste
PrintObjectDescriptionIfNeeded(bool value_printed,bool summary_printed)440435933ddSDimitry Andric bool ValueObjectPrinter::PrintObjectDescriptionIfNeeded(bool value_printed,
441435933ddSDimitry Andric bool summary_printed) {
442435933ddSDimitry Andric if (ShouldPrintValueObject()) {
44335617911SEd Maste // let's avoid the overly verbose no description error for a nil thing
444435933ddSDimitry Andric if (m_options.m_use_objc && !IsNil() && !IsUninitialized() &&
445435933ddSDimitry Andric (!m_options.m_pointer_as_array)) {
4469f2f44ceSEd Maste if (!m_options.m_hide_value || !m_options.m_hide_name)
44735617911SEd Maste m_stream->Printf(" ");
44835617911SEd Maste const char *object_desc = nullptr;
44935617911SEd Maste if (value_printed || summary_printed)
45035617911SEd Maste object_desc = m_valobj->GetObjectDescription();
45135617911SEd Maste else
45235617911SEd Maste object_desc = GetDescriptionForDisplay();
453435933ddSDimitry Andric if (object_desc && *object_desc) {
454f678e45dSDimitry Andric // If the description already ends with a \n don't add another one.
455f678e45dSDimitry Andric size_t object_end = strlen(object_desc) - 1;
456f678e45dSDimitry Andric if (object_desc[object_end] == '\n')
457f678e45dSDimitry Andric m_stream->Printf("%s", object_desc);
458f678e45dSDimitry Andric else
45935617911SEd Maste m_stream->Printf("%s\n", object_desc);
46035617911SEd Maste return true;
461*b5893f02SDimitry Andric } else if (!value_printed && !summary_printed)
46235617911SEd Maste return true;
46335617911SEd Maste else
46435617911SEd Maste return false;
46535617911SEd Maste }
46635617911SEd Maste }
46735617911SEd Maste return true;
46835617911SEd Maste }
46935617911SEd Maste
CanAllowExpansion() const470435933ddSDimitry Andric bool DumpValueObjectOptions::PointerDepth::CanAllowExpansion() const {
471435933ddSDimitry Andric switch (m_mode) {
4729f2f44ceSEd Maste case Mode::Always:
4739f2f44ceSEd Maste case Mode::Default:
474f678e45dSDimitry Andric return m_count > 0;
4759f2f44ceSEd Maste case Mode::Never:
4769f2f44ceSEd Maste return false;
4779f2f44ceSEd Maste }
4789f2f44ceSEd Maste return false;
4799f2f44ceSEd Maste }
4809f2f44ceSEd Maste
ShouldPrintChildren(bool is_failed_description,DumpValueObjectOptions::PointerDepth & curr_ptr_depth)481435933ddSDimitry Andric bool ValueObjectPrinter::ShouldPrintChildren(
482435933ddSDimitry Andric bool is_failed_description,
483435933ddSDimitry Andric DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
48435617911SEd Maste const bool is_ref = IsRef();
48535617911SEd Maste const bool is_ptr = IsPtr();
4869f2f44ceSEd Maste const bool is_uninit = IsUninitialized();
48735617911SEd Maste
4889f2f44ceSEd Maste if (is_uninit)
4899f2f44ceSEd Maste return false;
4909f2f44ceSEd Maste
4914ba319b5SDimitry Andric // if the user has specified an element count, always print children as it is
4924ba319b5SDimitry Andric // explicit user demand being honored
493435933ddSDimitry Andric if (m_options.m_pointer_as_array)
4944bb0738eSEd Maste return true;
4954bb0738eSEd Maste
4969f2f44ceSEd Maste TypeSummaryImpl *entry = GetSummaryFormatter();
4979f2f44ceSEd Maste
4989f2f44ceSEd Maste if (m_options.m_use_objc)
4999f2f44ceSEd Maste return false;
5009f2f44ceSEd Maste
501435933ddSDimitry Andric if (is_failed_description || m_curr_depth < m_options.m_max_depth) {
5024ba319b5SDimitry Andric // We will show children for all concrete types. We won't show pointer
5034ba319b5SDimitry Andric // contents unless a pointer depth has been specified. We won't reference
5044ba319b5SDimitry Andric // contents unless the reference is the root object (depth of zero).
50535617911SEd Maste
5064ba319b5SDimitry Andric // Use a new temporary pointer depth in case we override the current
5074ba319b5SDimitry Andric // pointer depth below...
50835617911SEd Maste
509435933ddSDimitry Andric if (is_ptr || is_ref) {
5104ba319b5SDimitry Andric // We have a pointer or reference whose value is an address. Make sure
5114ba319b5SDimitry Andric // that address is not NULL
51235617911SEd Maste AddressType ptr_address_type;
51335617911SEd Maste if (m_valobj->GetPointerValue(&ptr_address_type) == 0)
51435617911SEd Maste return false;
51535617911SEd Maste
5169f2f44ceSEd Maste const bool is_root_level = m_curr_depth == 0;
5179f2f44ceSEd Maste
518435933ddSDimitry Andric if (is_ref && is_root_level) {
5194ba319b5SDimitry Andric // If this is the root object (depth is zero) that we are showing and
5204ba319b5SDimitry Andric // it is a reference, and no pointer depth has been supplied print out
5214ba319b5SDimitry Andric // what it references. Don't do this at deeper depths otherwise we can
5224ba319b5SDimitry Andric // end up with infinite recursion...
5239f2f44ceSEd Maste return true;
52435617911SEd Maste }
52535617911SEd Maste
526f678e45dSDimitry Andric return curr_ptr_depth.CanAllowExpansion();
52735617911SEd Maste }
52835617911SEd Maste
5290127ef0fSEd Maste return (!entry || entry->DoesPrintChildren(m_valobj) || m_summary.empty());
53035617911SEd Maste }
53135617911SEd Maste return false;
53235617911SEd Maste }
53335617911SEd Maste
ShouldExpandEmptyAggregates()534435933ddSDimitry Andric bool ValueObjectPrinter::ShouldExpandEmptyAggregates() {
5359f2f44ceSEd Maste TypeSummaryImpl *entry = GetSummaryFormatter();
5369f2f44ceSEd Maste
5379f2f44ceSEd Maste if (!entry)
5389f2f44ceSEd Maste return true;
5399f2f44ceSEd Maste
5409f2f44ceSEd Maste return entry->DoesPrintEmptyAggregates();
5419f2f44ceSEd Maste }
5429f2f44ceSEd Maste
GetValueObjectForChildrenGeneration()543435933ddSDimitry Andric ValueObject *ValueObjectPrinter::GetValueObjectForChildrenGeneration() {
5447aa51b79SEd Maste return m_valobj;
54535617911SEd Maste }
54635617911SEd Maste
PrintChildrenPreamble()547435933ddSDimitry Andric void ValueObjectPrinter::PrintChildrenPreamble() {
548435933ddSDimitry Andric if (m_options.m_flat_output) {
54935617911SEd Maste if (ShouldPrintValueObject())
55035617911SEd Maste m_stream->EOL();
551435933ddSDimitry Andric } else {
55235617911SEd Maste if (ShouldPrintValueObject())
55335617911SEd Maste m_stream->PutCString(IsRef() ? ": {\n" : " {\n");
55435617911SEd Maste m_stream->IndentMore();
55535617911SEd Maste }
55635617911SEd Maste }
55735617911SEd Maste
PrintChild(ValueObjectSP child_sp,const DumpValueObjectOptions::PointerDepth & curr_ptr_depth)558435933ddSDimitry Andric void ValueObjectPrinter::PrintChild(
559435933ddSDimitry Andric ValueObjectSP child_sp,
560435933ddSDimitry Andric const DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
561435933ddSDimitry Andric const uint32_t consumed_depth = (!m_options.m_pointer_as_array) ? 1 : 0;
562435933ddSDimitry Andric const bool does_consume_ptr_depth =
563435933ddSDimitry Andric ((IsPtr() && !m_options.m_pointer_as_array) || IsRef());
5644bb0738eSEd Maste
5659f2f44ceSEd Maste DumpValueObjectOptions child_options(m_options);
566435933ddSDimitry Andric child_options.SetFormat(m_options.m_format)
567435933ddSDimitry Andric .SetSummary()
568435933ddSDimitry Andric .SetRootValueObjectName();
569435933ddSDimitry Andric child_options.SetScopeChecked(true)
570435933ddSDimitry Andric .SetHideName(m_options.m_hide_name)
571435933ddSDimitry Andric .SetHideValue(m_options.m_hide_value)
572435933ddSDimitry Andric .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1
573435933ddSDimitry Andric ? child_options.m_omit_summary_depth -
574435933ddSDimitry Andric consumed_depth
575435933ddSDimitry Andric : 0)
5764bb0738eSEd Maste .SetElementCount(0);
5779f2f44ceSEd Maste
578435933ddSDimitry Andric if (child_sp.get()) {
579435933ddSDimitry Andric ValueObjectPrinter child_printer(
580435933ddSDimitry Andric child_sp.get(), m_stream, child_options,
5814bb0738eSEd Maste does_consume_ptr_depth ? --curr_ptr_depth : curr_ptr_depth,
582435933ddSDimitry Andric m_curr_depth + consumed_depth, m_printed_instance_pointers);
58335617911SEd Maste child_printer.PrintValueObject();
58435617911SEd Maste }
58535617911SEd Maste }
58635617911SEd Maste
GetMaxNumChildrenToPrint(bool & print_dotdotdot)587435933ddSDimitry Andric uint32_t ValueObjectPrinter::GetMaxNumChildrenToPrint(bool &print_dotdotdot) {
58835617911SEd Maste ValueObject *synth_m_valobj = GetValueObjectForChildrenGeneration();
58935617911SEd Maste
590435933ddSDimitry Andric if (m_options.m_pointer_as_array)
591435933ddSDimitry Andric return m_options.m_pointer_as_array.m_element_count;
5924bb0738eSEd Maste
59335617911SEd Maste size_t num_children = synth_m_valobj->GetNumChildren();
59435617911SEd Maste print_dotdotdot = false;
595435933ddSDimitry Andric if (num_children) {
596435933ddSDimitry Andric const size_t max_num_children =
597435933ddSDimitry Andric m_valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
59835617911SEd Maste
599435933ddSDimitry Andric if (num_children > max_num_children && !m_options.m_ignore_cap) {
60035617911SEd Maste print_dotdotdot = true;
60135617911SEd Maste return max_num_children;
60235617911SEd Maste }
60335617911SEd Maste }
60435617911SEd Maste return num_children;
60535617911SEd Maste }
60635617911SEd Maste
PrintChildrenPostamble(bool print_dotdotdot)607435933ddSDimitry Andric void ValueObjectPrinter::PrintChildrenPostamble(bool print_dotdotdot) {
608435933ddSDimitry Andric if (!m_options.m_flat_output) {
609435933ddSDimitry Andric if (print_dotdotdot) {
610435933ddSDimitry Andric m_valobj->GetTargetSP()
611435933ddSDimitry Andric ->GetDebugger()
612435933ddSDimitry Andric .GetCommandInterpreter()
613435933ddSDimitry Andric .ChildrenTruncated();
61435617911SEd Maste m_stream->Indent("...\n");
61535617911SEd Maste }
61635617911SEd Maste m_stream->IndentLess();
61735617911SEd Maste m_stream->Indent("}\n");
61835617911SEd Maste }
61935617911SEd Maste }
62035617911SEd Maste
ShouldPrintEmptyBrackets(bool value_printed,bool summary_printed)621435933ddSDimitry Andric bool ValueObjectPrinter::ShouldPrintEmptyBrackets(bool value_printed,
622435933ddSDimitry Andric bool summary_printed) {
6239f2f44ceSEd Maste ValueObject *synth_m_valobj = GetValueObjectForChildrenGeneration();
6249f2f44ceSEd Maste
6259f2f44ceSEd Maste if (!IsAggregate())
6269f2f44ceSEd Maste return false;
6279f2f44ceSEd Maste
628*b5893f02SDimitry Andric if (!m_options.m_reveal_empty_aggregates) {
6299f2f44ceSEd Maste if (value_printed || summary_printed)
6309f2f44ceSEd Maste return false;
6319f2f44ceSEd Maste }
6329f2f44ceSEd Maste
6339f2f44ceSEd Maste if (synth_m_valobj->MightHaveChildren())
6349f2f44ceSEd Maste return true;
6359f2f44ceSEd Maste
6369f2f44ceSEd Maste if (m_val_summary_ok)
6379f2f44ceSEd Maste return false;
6389f2f44ceSEd Maste
6399f2f44ceSEd Maste return true;
6409f2f44ceSEd Maste }
6419f2f44ceSEd Maste
PhysicalIndexForLogicalIndex(size_t base,size_t stride,size_t logical)642435933ddSDimitry Andric static constexpr size_t PhysicalIndexForLogicalIndex(size_t base, size_t stride,
643435933ddSDimitry Andric size_t logical) {
644435933ddSDimitry Andric return base + logical * stride;
6454bb0738eSEd Maste }
646435933ddSDimitry Andric
GenerateChild(ValueObject * synth_valobj,size_t idx)647435933ddSDimitry Andric ValueObjectSP ValueObjectPrinter::GenerateChild(ValueObject *synth_valobj,
648435933ddSDimitry Andric size_t idx) {
649435933ddSDimitry Andric if (m_options.m_pointer_as_array) {
650435933ddSDimitry Andric // if generating pointer-as-array children, use GetSyntheticArrayMember
651435933ddSDimitry Andric return synth_valobj->GetSyntheticArrayMember(
652435933ddSDimitry Andric PhysicalIndexForLogicalIndex(
653435933ddSDimitry Andric m_options.m_pointer_as_array.m_base_element,
654435933ddSDimitry Andric m_options.m_pointer_as_array.m_stride, idx),
655435933ddSDimitry Andric true);
656435933ddSDimitry Andric } else {
6574bb0738eSEd Maste // otherwise, do the usual thing
6584bb0738eSEd Maste return synth_valobj->GetChildAtIndex(idx, true);
6594bb0738eSEd Maste }
6604bb0738eSEd Maste }
6614bb0738eSEd Maste
PrintChildren(bool value_printed,bool summary_printed,const DumpValueObjectOptions::PointerDepth & curr_ptr_depth)662435933ddSDimitry Andric void ValueObjectPrinter::PrintChildren(
663435933ddSDimitry Andric bool value_printed, bool summary_printed,
664435933ddSDimitry Andric const DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
66535617911SEd Maste ValueObject *synth_m_valobj = GetValueObjectForChildrenGeneration();
66635617911SEd Maste
66735617911SEd Maste bool print_dotdotdot = false;
66835617911SEd Maste size_t num_children = GetMaxNumChildrenToPrint(print_dotdotdot);
669435933ddSDimitry Andric if (num_children) {
6709f2f44ceSEd Maste bool any_children_printed = false;
67135617911SEd Maste
672435933ddSDimitry Andric for (size_t idx = 0; idx < num_children; ++idx) {
673435933ddSDimitry Andric if (ValueObjectSP child_sp = GenerateChild(synth_m_valobj, idx)) {
674435933ddSDimitry Andric if (!any_children_printed) {
6759f2f44ceSEd Maste PrintChildrenPreamble();
6769f2f44ceSEd Maste any_children_printed = true;
6779f2f44ceSEd Maste }
67835617911SEd Maste PrintChild(child_sp, curr_ptr_depth);
67935617911SEd Maste }
68035617911SEd Maste }
6819f2f44ceSEd Maste
6829f2f44ceSEd Maste if (any_children_printed)
6839f2f44ceSEd Maste PrintChildrenPostamble(print_dotdotdot);
684435933ddSDimitry Andric else {
685435933ddSDimitry Andric if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) {
6869f2f44ceSEd Maste if (ShouldPrintValueObject())
6879f2f44ceSEd Maste m_stream->PutCString(" {}\n");
6889f2f44ceSEd Maste else
6899f2f44ceSEd Maste m_stream->EOL();
690435933ddSDimitry Andric } else
6919f2f44ceSEd Maste m_stream->EOL();
6929f2f44ceSEd Maste }
693435933ddSDimitry Andric } else if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) {
69435617911SEd Maste // Aggregate, no children...
695435933ddSDimitry Andric if (ShouldPrintValueObject()) {
696435933ddSDimitry Andric // if it has a synthetic value, then don't print {}, the synthetic
697435933ddSDimitry Andric // children are probably only being used to vend a value
698435933ddSDimitry Andric if (m_valobj->DoesProvideSyntheticValue() ||
699435933ddSDimitry Andric !ShouldExpandEmptyAggregates())
7007aa51b79SEd Maste m_stream->PutCString("\n");
7017aa51b79SEd Maste else
70235617911SEd Maste m_stream->PutCString(" {}\n");
70335617911SEd Maste }
704435933ddSDimitry Andric } else {
70535617911SEd Maste if (ShouldPrintValueObject())
70635617911SEd Maste m_stream->EOL();
70735617911SEd Maste }
70835617911SEd Maste }
70935617911SEd Maste
PrintChildrenOneLiner(bool hide_names)710435933ddSDimitry Andric bool ValueObjectPrinter::PrintChildrenOneLiner(bool hide_names) {
7117aa51b79SEd Maste if (!GetMostSpecializedValue() || m_valobj == nullptr)
71235617911SEd Maste return false;
71335617911SEd Maste
71435617911SEd Maste ValueObject *synth_m_valobj = GetValueObjectForChildrenGeneration();
71535617911SEd Maste
71635617911SEd Maste bool print_dotdotdot = false;
71735617911SEd Maste size_t num_children = GetMaxNumChildrenToPrint(print_dotdotdot);
71835617911SEd Maste
719435933ddSDimitry Andric if (num_children) {
72035617911SEd Maste m_stream->PutChar('(');
72135617911SEd Maste
722435933ddSDimitry Andric for (uint32_t idx = 0; idx < num_children; ++idx) {
72335617911SEd Maste lldb::ValueObjectSP child_sp(synth_m_valobj->GetChildAtIndex(idx, true));
7247aa51b79SEd Maste if (child_sp)
725435933ddSDimitry Andric child_sp = child_sp->GetQualifiedRepresentationIfAvailable(
726435933ddSDimitry Andric m_options.m_use_dynamic, m_options.m_use_synthetic);
727435933ddSDimitry Andric if (child_sp) {
72835617911SEd Maste if (idx)
72935617911SEd Maste m_stream->PutCString(", ");
730435933ddSDimitry Andric if (!hide_names) {
73135617911SEd Maste const char *name = child_sp.get()->GetName().AsCString();
732435933ddSDimitry Andric if (name && *name) {
73335617911SEd Maste m_stream->PutCString(name);
73435617911SEd Maste m_stream->PutCString(" = ");
73535617911SEd Maste }
73635617911SEd Maste }
737435933ddSDimitry Andric child_sp->DumpPrintableRepresentation(
738435933ddSDimitry Andric *m_stream, ValueObject::eValueObjectRepresentationStyleSummary,
7399f2f44ceSEd Maste m_options.m_format,
740435933ddSDimitry Andric ValueObject::PrintableRepresentationSpecialCases::eDisable);
74135617911SEd Maste }
74235617911SEd Maste }
74335617911SEd Maste
74435617911SEd Maste if (print_dotdotdot)
74535617911SEd Maste m_stream->PutCString(", ...)");
74635617911SEd Maste else
74735617911SEd Maste m_stream->PutChar(')');
74835617911SEd Maste }
74935617911SEd Maste return true;
75035617911SEd Maste }
75135617911SEd Maste
PrintChildrenIfNeeded(bool value_printed,bool summary_printed)752435933ddSDimitry Andric void ValueObjectPrinter::PrintChildrenIfNeeded(bool value_printed,
753435933ddSDimitry Andric bool summary_printed) {
754435933ddSDimitry Andric // this flag controls whether we tried to display a description for this
7554ba319b5SDimitry Andric // object and failed if that happens, we want to display the children, if any
756435933ddSDimitry Andric bool is_failed_description =
757435933ddSDimitry Andric !PrintObjectDescriptionIfNeeded(value_printed, summary_printed);
75835617911SEd Maste
7599f2f44ceSEd Maste auto curr_ptr_depth = m_ptr_depth;
760435933ddSDimitry Andric bool print_children =
761435933ddSDimitry Andric ShouldPrintChildren(is_failed_description, curr_ptr_depth);
762435933ddSDimitry Andric bool print_oneline =
763435933ddSDimitry Andric (curr_ptr_depth.CanAllowExpansion() || m_options.m_show_types ||
764435933ddSDimitry Andric !m_options.m_allow_oneliner_mode || m_options.m_flat_output ||
765435933ddSDimitry Andric (m_options.m_pointer_as_array) || m_options.m_show_location)
766435933ddSDimitry Andric ? false
767435933ddSDimitry Andric : DataVisualization::ShouldPrintAsOneLiner(*m_valobj);
7689f2f44ceSEd Maste bool is_instance_ptr = IsInstancePointer();
7699f2f44ceSEd Maste uint64_t instance_ptr_value = LLDB_INVALID_ADDRESS;
7709f2f44ceSEd Maste
771435933ddSDimitry Andric if (print_children && is_instance_ptr) {
7729f2f44ceSEd Maste instance_ptr_value = m_valobj->GetValueAsUnsigned(0);
773435933ddSDimitry Andric if (m_printed_instance_pointers->count(instance_ptr_value)) {
7749f2f44ceSEd Maste // we already printed this instance-is-pointer thing, so don't expand it
7759f2f44ceSEd Maste m_stream->PutCString(" {...}\n");
7769f2f44ceSEd Maste
7779f2f44ceSEd Maste // we're done here - get out fast
7789f2f44ceSEd Maste return;
779435933ddSDimitry Andric } else
780435933ddSDimitry Andric m_printed_instance_pointers->emplace(
781435933ddSDimitry Andric instance_ptr_value); // remember this guy for future reference
7829f2f44ceSEd Maste }
78335617911SEd Maste
784435933ddSDimitry Andric if (print_children) {
785435933ddSDimitry Andric if (print_oneline) {
78635617911SEd Maste m_stream->PutChar(' ');
78735617911SEd Maste PrintChildrenOneLiner(false);
78835617911SEd Maste m_stream->EOL();
789435933ddSDimitry Andric } else
7909f2f44ceSEd Maste PrintChildren(value_printed, summary_printed, curr_ptr_depth);
791435933ddSDimitry Andric } else if (m_curr_depth >= m_options.m_max_depth && IsAggregate() &&
792435933ddSDimitry Andric ShouldPrintValueObject()) {
79335617911SEd Maste m_stream->PutCString("{...}\n");
794435933ddSDimitry Andric } else
79535617911SEd Maste m_stream->EOL();
79635617911SEd Maste }
7977aa51b79SEd Maste
ShouldPrintValidation()798435933ddSDimitry Andric bool ValueObjectPrinter::ShouldPrintValidation() {
7999f2f44ceSEd Maste return m_options.m_run_validator;
8007aa51b79SEd Maste }
8017aa51b79SEd Maste
PrintValidationMarkerIfNeeded()802435933ddSDimitry Andric bool ValueObjectPrinter::PrintValidationMarkerIfNeeded() {
8037aa51b79SEd Maste if (!ShouldPrintValidation())
8047aa51b79SEd Maste return false;
8057aa51b79SEd Maste
8067aa51b79SEd Maste m_validation = m_valobj->GetValidationStatus();
8077aa51b79SEd Maste
808435933ddSDimitry Andric if (TypeValidatorResult::Failure == m_validation.first) {
8097aa51b79SEd Maste m_stream->Printf("! ");
8107aa51b79SEd Maste return true;
8117aa51b79SEd Maste }
8127aa51b79SEd Maste
8137aa51b79SEd Maste return false;
8147aa51b79SEd Maste }
8157aa51b79SEd Maste
PrintValidationErrorIfNeeded()816435933ddSDimitry Andric bool ValueObjectPrinter::PrintValidationErrorIfNeeded() {
8177aa51b79SEd Maste if (!ShouldPrintValidation())
8187aa51b79SEd Maste return false;
8197aa51b79SEd Maste
8207aa51b79SEd Maste if (TypeValidatorResult::Success == m_validation.first)
8217aa51b79SEd Maste return false;
8227aa51b79SEd Maste
8237aa51b79SEd Maste if (m_validation.second.empty())
8247aa51b79SEd Maste m_validation.second.assign("unknown error");
8257aa51b79SEd Maste
8267aa51b79SEd Maste m_stream->Printf(" ! validation error: %s", m_validation.second.c_str());
8277aa51b79SEd Maste m_stream->EOL();
8287aa51b79SEd Maste
8297aa51b79SEd Maste return true;
8307aa51b79SEd Maste }
831