1 //===-- ValueObjectPrinter.cpp --------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/DataFormatters/ValueObjectPrinter.h" 10 11 #include "lldb/Core/ValueObject.h" 12 #include "lldb/DataFormatters/DataVisualization.h" 13 #include "lldb/Interpreter/CommandInterpreter.h" 14 #include "lldb/Target/Language.h" 15 #include "lldb/Target/Target.h" 16 #include "lldb/Utility/Stream.h" 17 18 using namespace lldb; 19 using namespace lldb_private; 20 21 ValueObjectPrinter::ValueObjectPrinter(ValueObject *valobj, Stream *s) { 22 if (valobj) { 23 DumpValueObjectOptions options(*valobj); 24 Init(valobj, s, options, m_options.m_max_ptr_depth, 0, nullptr); 25 } else { 26 DumpValueObjectOptions options; 27 Init(valobj, s, options, m_options.m_max_ptr_depth, 0, nullptr); 28 } 29 } 30 31 ValueObjectPrinter::ValueObjectPrinter(ValueObject *valobj, Stream *s, 32 const DumpValueObjectOptions &options) { 33 Init(valobj, s, options, m_options.m_max_ptr_depth, 0, nullptr); 34 } 35 36 ValueObjectPrinter::ValueObjectPrinter( 37 ValueObject *valobj, Stream *s, const DumpValueObjectOptions &options, 38 const DumpValueObjectOptions::PointerDepth &ptr_depth, uint32_t curr_depth, 39 InstancePointersSetSP printed_instance_pointers) { 40 Init(valobj, s, options, ptr_depth, curr_depth, printed_instance_pointers); 41 } 42 43 void ValueObjectPrinter::Init( 44 ValueObject *valobj, Stream *s, const DumpValueObjectOptions &options, 45 const DumpValueObjectOptions::PointerDepth &ptr_depth, uint32_t curr_depth, 46 InstancePointersSetSP printed_instance_pointers) { 47 m_orig_valobj = valobj; 48 m_valobj = nullptr; 49 m_stream = s; 50 m_options = options; 51 m_ptr_depth = ptr_depth; 52 m_curr_depth = curr_depth; 53 assert(m_orig_valobj && "cannot print a NULL ValueObject"); 54 assert(m_stream && "cannot print to a NULL Stream"); 55 m_should_print = eLazyBoolCalculate; 56 m_is_nil = eLazyBoolCalculate; 57 m_is_uninit = eLazyBoolCalculate; 58 m_is_ptr = eLazyBoolCalculate; 59 m_is_ref = eLazyBoolCalculate; 60 m_is_aggregate = eLazyBoolCalculate; 61 m_is_instance_ptr = eLazyBoolCalculate; 62 m_summary_formatter = {nullptr, false}; 63 m_value.assign(""); 64 m_summary.assign(""); 65 m_error.assign(""); 66 m_val_summary_ok = false; 67 m_printed_instance_pointers = 68 printed_instance_pointers 69 ? printed_instance_pointers 70 : InstancePointersSetSP(new InstancePointersSet()); 71 } 72 73 bool ValueObjectPrinter::PrintValueObject() { 74 if (!GetMostSpecializedValue() || m_valobj == nullptr) 75 return false; 76 77 if (ShouldPrintValueObject()) { 78 PrintLocationIfNeeded(); 79 m_stream->Indent(); 80 81 PrintDecl(); 82 } 83 84 bool value_printed = false; 85 bool summary_printed = false; 86 87 m_val_summary_ok = 88 PrintValueAndSummaryIfNeeded(value_printed, summary_printed); 89 90 if (m_val_summary_ok) 91 PrintChildrenIfNeeded(value_printed, summary_printed); 92 else 93 m_stream->EOL(); 94 95 return true; 96 } 97 98 bool ValueObjectPrinter::GetMostSpecializedValue() { 99 if (m_valobj) 100 return true; 101 bool update_success = m_orig_valobj->UpdateValueIfNeeded(true); 102 if (!update_success) { 103 m_valobj = m_orig_valobj; 104 } else { 105 if (m_orig_valobj->IsDynamic()) { 106 if (m_options.m_use_dynamic == eNoDynamicValues) { 107 ValueObject *static_value = m_orig_valobj->GetStaticValue().get(); 108 if (static_value) 109 m_valobj = static_value; 110 else 111 m_valobj = m_orig_valobj; 112 } else 113 m_valobj = m_orig_valobj; 114 } else { 115 if (m_options.m_use_dynamic != eNoDynamicValues) { 116 ValueObject *dynamic_value = 117 m_orig_valobj->GetDynamicValue(m_options.m_use_dynamic).get(); 118 if (dynamic_value) 119 m_valobj = dynamic_value; 120 else 121 m_valobj = m_orig_valobj; 122 } else 123 m_valobj = m_orig_valobj; 124 } 125 126 if (m_valobj->IsSynthetic()) { 127 if (!m_options.m_use_synthetic) { 128 ValueObject *non_synthetic = m_valobj->GetNonSyntheticValue().get(); 129 if (non_synthetic) 130 m_valobj = non_synthetic; 131 } 132 } else { 133 if (m_options.m_use_synthetic) { 134 ValueObject *synthetic = m_valobj->GetSyntheticValue().get(); 135 if (synthetic) 136 m_valobj = synthetic; 137 } 138 } 139 } 140 m_compiler_type = m_valobj->GetCompilerType(); 141 m_type_flags = m_compiler_type.GetTypeInfo(); 142 return true; 143 } 144 145 const char *ValueObjectPrinter::GetDescriptionForDisplay() { 146 const char *str = m_valobj->GetObjectDescription(); 147 if (!str) 148 str = m_valobj->GetSummaryAsCString(); 149 if (!str) 150 str = m_valobj->GetValueAsCString(); 151 return str; 152 } 153 154 const char *ValueObjectPrinter::GetRootNameForDisplay(const char *if_fail) { 155 const char *root_valobj_name = m_options.m_root_valobj_name.empty() 156 ? m_valobj->GetName().AsCString() 157 : m_options.m_root_valobj_name.c_str(); 158 return root_valobj_name ? root_valobj_name : if_fail; 159 } 160 161 bool ValueObjectPrinter::ShouldPrintValueObject() { 162 if (m_should_print == eLazyBoolCalculate) 163 m_should_print = 164 (!m_options.m_flat_output || m_type_flags.Test(eTypeHasValue)) 165 ? eLazyBoolYes 166 : eLazyBoolNo; 167 return m_should_print == eLazyBoolYes; 168 } 169 170 bool ValueObjectPrinter::IsNil() { 171 if (m_is_nil == eLazyBoolCalculate) 172 m_is_nil = m_valobj->IsNilReference() ? eLazyBoolYes : eLazyBoolNo; 173 return m_is_nil == eLazyBoolYes; 174 } 175 176 bool ValueObjectPrinter::IsUninitialized() { 177 if (m_is_uninit == eLazyBoolCalculate) 178 m_is_uninit = 179 m_valobj->IsUninitializedReference() ? eLazyBoolYes : eLazyBoolNo; 180 return m_is_uninit == eLazyBoolYes; 181 } 182 183 bool ValueObjectPrinter::IsPtr() { 184 if (m_is_ptr == eLazyBoolCalculate) 185 m_is_ptr = m_type_flags.Test(eTypeIsPointer) ? eLazyBoolYes : eLazyBoolNo; 186 return m_is_ptr == eLazyBoolYes; 187 } 188 189 bool ValueObjectPrinter::IsRef() { 190 if (m_is_ref == eLazyBoolCalculate) 191 m_is_ref = m_type_flags.Test(eTypeIsReference) ? eLazyBoolYes : eLazyBoolNo; 192 return m_is_ref == eLazyBoolYes; 193 } 194 195 bool ValueObjectPrinter::IsAggregate() { 196 if (m_is_aggregate == eLazyBoolCalculate) 197 m_is_aggregate = 198 m_type_flags.Test(eTypeHasChildren) ? eLazyBoolYes : eLazyBoolNo; 199 return m_is_aggregate == eLazyBoolYes; 200 } 201 202 bool ValueObjectPrinter::IsInstancePointer() { 203 // you need to do this check on the value's clang type 204 if (m_is_instance_ptr == eLazyBoolCalculate) 205 m_is_instance_ptr = (m_valobj->GetValue().GetCompilerType().GetTypeInfo() & 206 eTypeInstanceIsPointer) != 0 207 ? eLazyBoolYes 208 : eLazyBoolNo; 209 if ((eLazyBoolYes == m_is_instance_ptr) && m_valobj->IsBaseClass()) 210 m_is_instance_ptr = eLazyBoolNo; 211 return m_is_instance_ptr == eLazyBoolYes; 212 } 213 214 bool ValueObjectPrinter::PrintLocationIfNeeded() { 215 if (m_options.m_show_location) { 216 m_stream->Printf("%s: ", m_valobj->GetLocationAsCString()); 217 return true; 218 } 219 return false; 220 } 221 222 void ValueObjectPrinter::PrintDecl() { 223 bool show_type = true; 224 // if we are at the root-level and been asked to hide the root's type, then 225 // hide it 226 if (m_curr_depth == 0 && m_options.m_hide_root_type) 227 show_type = false; 228 else 229 // otherwise decide according to the usual rules (asked to show types - 230 // always at the root level) 231 show_type = m_options.m_show_types || 232 (m_curr_depth == 0 && !m_options.m_flat_output); 233 234 StreamString typeName; 235 236 // always show the type at the root level if it is invalid 237 if (show_type) { 238 // Some ValueObjects don't have types (like registers sets). Only print the 239 // type if there is one to print 240 ConstString type_name; 241 if (m_compiler_type.IsValid()) { 242 if (m_options.m_use_type_display_name) 243 type_name = m_valobj->GetDisplayTypeName(); 244 else 245 type_name = m_valobj->GetQualifiedTypeName(); 246 } else { 247 // only show an invalid type name if the user explicitly triggered 248 // show_type 249 if (m_options.m_show_types) 250 type_name = ConstString("<invalid type>"); 251 else 252 type_name.Clear(); 253 } 254 255 if (type_name) { 256 std::string type_name_str(type_name.GetCString()); 257 if (m_options.m_hide_pointer_value) { 258 for (auto iter = type_name_str.find(" *"); iter != std::string::npos; 259 iter = type_name_str.find(" *")) { 260 type_name_str.erase(iter, 2); 261 } 262 } 263 typeName.Printf("%s", type_name_str.c_str()); 264 } 265 } 266 267 StreamString varName; 268 269 if (!m_options.m_hide_name) { 270 if (m_options.m_flat_output) 271 m_valobj->GetExpressionPath(varName); 272 else { 273 const char *name_cstr = GetRootNameForDisplay(""); 274 varName.Printf("%s", name_cstr); 275 } 276 } 277 278 bool decl_printed = false; 279 if (!m_options.m_decl_printing_helper) { 280 // if the user didn't give us a custom helper, pick one based upon the 281 // language, either the one that this printer is bound to, or the preferred 282 // one for the ValueObject 283 lldb::LanguageType lang_type = 284 (m_options.m_varformat_language == lldb::eLanguageTypeUnknown) 285 ? m_valobj->GetPreferredDisplayLanguage() 286 : m_options.m_varformat_language; 287 if (Language *lang_plugin = Language::FindPlugin(lang_type)) { 288 m_options.m_decl_printing_helper = lang_plugin->GetDeclPrintingHelper(); 289 } 290 } 291 292 if (m_options.m_decl_printing_helper) { 293 ConstString type_name_cstr(typeName.GetString()); 294 ConstString var_name_cstr(varName.GetString()); 295 296 StreamString dest_stream; 297 if (m_options.m_decl_printing_helper(type_name_cstr, var_name_cstr, 298 m_options, dest_stream)) { 299 decl_printed = true; 300 m_stream->PutCString(dest_stream.GetString()); 301 } 302 } 303 304 // if the helper failed, or there is none, do a default thing 305 if (!decl_printed) { 306 if (!typeName.Empty()) 307 m_stream->Printf("(%s) ", typeName.GetData()); 308 if (!varName.Empty()) 309 m_stream->Printf("%s =", varName.GetData()); 310 else if (!m_options.m_hide_name) 311 m_stream->Printf(" ="); 312 } 313 } 314 315 bool ValueObjectPrinter::CheckScopeIfNeeded() { 316 if (m_options.m_scope_already_checked) 317 return true; 318 return m_valobj->IsInScope(); 319 } 320 321 TypeSummaryImpl *ValueObjectPrinter::GetSummaryFormatter(bool null_if_omitted) { 322 if (!m_summary_formatter.second) { 323 TypeSummaryImpl *entry = m_options.m_summary_sp 324 ? m_options.m_summary_sp.get() 325 : m_valobj->GetSummaryFormat().get(); 326 327 if (m_options.m_omit_summary_depth > 0) 328 entry = nullptr; 329 m_summary_formatter.first = entry; 330 m_summary_formatter.second = true; 331 } 332 if (m_options.m_omit_summary_depth > 0 && null_if_omitted) 333 return nullptr; 334 return m_summary_formatter.first; 335 } 336 337 static bool IsPointerValue(const CompilerType &type) { 338 Flags type_flags(type.GetTypeInfo()); 339 if (type_flags.AnySet(eTypeInstanceIsPointer | eTypeIsPointer)) 340 return type_flags.AllClear(eTypeIsBuiltIn); 341 return false; 342 } 343 344 void ValueObjectPrinter::GetValueSummaryError(std::string &value, 345 std::string &summary, 346 std::string &error) { 347 lldb::Format format = m_options.m_format; 348 // if I am printing synthetized elements, apply the format to those elements 349 // only 350 if (m_options.m_pointer_as_array) 351 m_valobj->GetValueAsCString(lldb::eFormatDefault, value); 352 else if (format != eFormatDefault && format != m_valobj->GetFormat()) 353 m_valobj->GetValueAsCString(format, value); 354 else { 355 const char *val_cstr = m_valobj->GetValueAsCString(); 356 if (val_cstr) 357 value.assign(val_cstr); 358 } 359 const char *err_cstr = m_valobj->GetError().AsCString(); 360 if (err_cstr) 361 error.assign(err_cstr); 362 363 if (ShouldPrintValueObject()) { 364 if (IsNil()) 365 summary.assign("nil"); 366 else if (IsUninitialized()) 367 summary.assign("<uninitialized>"); 368 else if (m_options.m_omit_summary_depth == 0) { 369 TypeSummaryImpl *entry = GetSummaryFormatter(); 370 if (entry) 371 m_valobj->GetSummaryAsCString(entry, summary, 372 m_options.m_varformat_language); 373 else { 374 const char *sum_cstr = 375 m_valobj->GetSummaryAsCString(m_options.m_varformat_language); 376 if (sum_cstr) 377 summary.assign(sum_cstr); 378 } 379 } 380 } 381 } 382 383 bool ValueObjectPrinter::PrintValueAndSummaryIfNeeded(bool &value_printed, 384 bool &summary_printed) { 385 bool error_printed = false; 386 if (ShouldPrintValueObject()) { 387 if (!CheckScopeIfNeeded()) 388 m_error.assign("out of scope"); 389 if (m_error.empty()) { 390 GetValueSummaryError(m_value, m_summary, m_error); 391 } 392 if (m_error.size()) { 393 // we need to support scenarios in which it is actually fine for a value 394 // to have no type but - on the other hand - if we get an error *AND* 395 // have no type, we try to get out gracefully, since most often that 396 // combination means "could not resolve a type" and the default failure 397 // mode is quite ugly 398 if (!m_compiler_type.IsValid()) { 399 m_stream->Printf(" <could not resolve type>"); 400 return false; 401 } 402 403 error_printed = true; 404 m_stream->Printf(" <%s>\n", m_error.c_str()); 405 } else { 406 // Make sure we have a value and make sure the summary didn't specify 407 // that the value should not be printed - and do not print the value if 408 // this thing is nil (but show the value if the user passes a format 409 // explicitly) 410 TypeSummaryImpl *entry = GetSummaryFormatter(); 411 if (!IsNil() && !IsUninitialized() && !m_value.empty() && 412 (entry == nullptr || 413 (entry->DoesPrintValue(m_valobj) || 414 m_options.m_format != eFormatDefault) || 415 m_summary.empty()) && 416 !m_options.m_hide_value) { 417 if (m_options.m_hide_pointer_value && 418 IsPointerValue(m_valobj->GetCompilerType())) { 419 } else { 420 m_stream->Printf(" %s", m_value.c_str()); 421 value_printed = true; 422 } 423 } 424 425 if (m_summary.size()) { 426 m_stream->Printf(" %s", m_summary.c_str()); 427 summary_printed = true; 428 } 429 } 430 } 431 return !error_printed; 432 } 433 434 bool ValueObjectPrinter::PrintObjectDescriptionIfNeeded(bool value_printed, 435 bool summary_printed) { 436 if (ShouldPrintValueObject()) { 437 // let's avoid the overly verbose no description error for a nil thing 438 if (m_options.m_use_objc && !IsNil() && !IsUninitialized() && 439 (!m_options.m_pointer_as_array)) { 440 if (!m_options.m_hide_value || !m_options.m_hide_name) 441 m_stream->Printf(" "); 442 const char *object_desc = nullptr; 443 if (value_printed || summary_printed) 444 object_desc = m_valobj->GetObjectDescription(); 445 else 446 object_desc = GetDescriptionForDisplay(); 447 if (object_desc && *object_desc) { 448 // If the description already ends with a \n don't add another one. 449 size_t object_end = strlen(object_desc) - 1; 450 if (object_desc[object_end] == '\n') 451 m_stream->Printf("%s", object_desc); 452 else 453 m_stream->Printf("%s\n", object_desc); 454 return true; 455 } else if (!value_printed && !summary_printed) 456 return true; 457 else 458 return false; 459 } 460 } 461 return true; 462 } 463 464 bool DumpValueObjectOptions::PointerDepth::CanAllowExpansion() const { 465 switch (m_mode) { 466 case Mode::Always: 467 case Mode::Default: 468 return m_count > 0; 469 case Mode::Never: 470 return false; 471 } 472 return false; 473 } 474 475 bool ValueObjectPrinter::ShouldPrintChildren( 476 bool is_failed_description, 477 DumpValueObjectOptions::PointerDepth &curr_ptr_depth) { 478 const bool is_ref = IsRef(); 479 const bool is_ptr = IsPtr(); 480 const bool is_uninit = IsUninitialized(); 481 482 if (is_uninit) 483 return false; 484 485 // if the user has specified an element count, always print children as it is 486 // explicit user demand being honored 487 if (m_options.m_pointer_as_array) 488 return true; 489 490 TypeSummaryImpl *entry = GetSummaryFormatter(); 491 492 if (m_options.m_use_objc) 493 return false; 494 495 if (is_failed_description || m_curr_depth < m_options.m_max_depth) { 496 // We will show children for all concrete types. We won't show pointer 497 // contents unless a pointer depth has been specified. We won't reference 498 // contents unless the reference is the root object (depth of zero). 499 500 // Use a new temporary pointer depth in case we override the current 501 // pointer depth below... 502 503 if (is_ptr || is_ref) { 504 // We have a pointer or reference whose value is an address. Make sure 505 // that address is not NULL 506 AddressType ptr_address_type; 507 if (m_valobj->GetPointerValue(&ptr_address_type) == 0) 508 return false; 509 510 const bool is_root_level = m_curr_depth == 0; 511 512 if (is_ref && is_root_level) { 513 // If this is the root object (depth is zero) that we are showing and 514 // it is a reference, and no pointer depth has been supplied print out 515 // what it references. Don't do this at deeper depths otherwise we can 516 // end up with infinite recursion... 517 return true; 518 } 519 520 return curr_ptr_depth.CanAllowExpansion(); 521 } 522 523 return (!entry || entry->DoesPrintChildren(m_valobj) || m_summary.empty()); 524 } 525 return false; 526 } 527 528 bool ValueObjectPrinter::ShouldExpandEmptyAggregates() { 529 TypeSummaryImpl *entry = GetSummaryFormatter(); 530 531 if (!entry) 532 return true; 533 534 return entry->DoesPrintEmptyAggregates(); 535 } 536 537 ValueObject *ValueObjectPrinter::GetValueObjectForChildrenGeneration() { 538 return m_valobj; 539 } 540 541 void ValueObjectPrinter::PrintChildrenPreamble() { 542 if (m_options.m_flat_output) { 543 if (ShouldPrintValueObject()) 544 m_stream->EOL(); 545 } else { 546 if (ShouldPrintValueObject()) 547 m_stream->PutCString(IsRef() ? ": {\n" : " {\n"); 548 m_stream->IndentMore(); 549 } 550 } 551 552 void ValueObjectPrinter::PrintChild( 553 ValueObjectSP child_sp, 554 const DumpValueObjectOptions::PointerDepth &curr_ptr_depth) { 555 const uint32_t consumed_depth = (!m_options.m_pointer_as_array) ? 1 : 0; 556 const bool does_consume_ptr_depth = 557 ((IsPtr() && !m_options.m_pointer_as_array) || IsRef()); 558 559 DumpValueObjectOptions child_options(m_options); 560 child_options.SetFormat(m_options.m_format) 561 .SetSummary() 562 .SetRootValueObjectName(); 563 child_options.SetScopeChecked(true) 564 .SetHideName(m_options.m_hide_name) 565 .SetHideValue(m_options.m_hide_value) 566 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 567 ? child_options.m_omit_summary_depth - 568 consumed_depth 569 : 0) 570 .SetElementCount(0); 571 572 if (child_sp.get()) { 573 ValueObjectPrinter child_printer( 574 child_sp.get(), m_stream, child_options, 575 does_consume_ptr_depth ? --curr_ptr_depth : curr_ptr_depth, 576 m_curr_depth + consumed_depth, m_printed_instance_pointers); 577 child_printer.PrintValueObject(); 578 } 579 } 580 581 uint32_t ValueObjectPrinter::GetMaxNumChildrenToPrint(bool &print_dotdotdot) { 582 ValueObject *synth_m_valobj = GetValueObjectForChildrenGeneration(); 583 584 if (m_options.m_pointer_as_array) 585 return m_options.m_pointer_as_array.m_element_count; 586 587 size_t num_children = synth_m_valobj->GetNumChildren(); 588 print_dotdotdot = false; 589 if (num_children) { 590 const size_t max_num_children = 591 m_valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay(); 592 593 if (num_children > max_num_children && !m_options.m_ignore_cap) { 594 print_dotdotdot = true; 595 return max_num_children; 596 } 597 } 598 return num_children; 599 } 600 601 void ValueObjectPrinter::PrintChildrenPostamble(bool print_dotdotdot) { 602 if (!m_options.m_flat_output) { 603 if (print_dotdotdot) { 604 m_valobj->GetTargetSP() 605 ->GetDebugger() 606 .GetCommandInterpreter() 607 .ChildrenTruncated(); 608 m_stream->Indent("...\n"); 609 } 610 m_stream->IndentLess(); 611 m_stream->Indent("}\n"); 612 } 613 } 614 615 bool ValueObjectPrinter::ShouldPrintEmptyBrackets(bool value_printed, 616 bool summary_printed) { 617 ValueObject *synth_m_valobj = GetValueObjectForChildrenGeneration(); 618 619 if (!IsAggregate()) 620 return false; 621 622 if (!m_options.m_reveal_empty_aggregates) { 623 if (value_printed || summary_printed) 624 return false; 625 } 626 627 if (synth_m_valobj->MightHaveChildren()) 628 return true; 629 630 if (m_val_summary_ok) 631 return false; 632 633 return true; 634 } 635 636 static constexpr size_t PhysicalIndexForLogicalIndex(size_t base, size_t stride, 637 size_t logical) { 638 return base + logical * stride; 639 } 640 641 ValueObjectSP ValueObjectPrinter::GenerateChild(ValueObject *synth_valobj, 642 size_t idx) { 643 if (m_options.m_pointer_as_array) { 644 // if generating pointer-as-array children, use GetSyntheticArrayMember 645 return synth_valobj->GetSyntheticArrayMember( 646 PhysicalIndexForLogicalIndex( 647 m_options.m_pointer_as_array.m_base_element, 648 m_options.m_pointer_as_array.m_stride, idx), 649 true); 650 } else { 651 // otherwise, do the usual thing 652 return synth_valobj->GetChildAtIndex(idx, true); 653 } 654 } 655 656 void ValueObjectPrinter::PrintChildren( 657 bool value_printed, bool summary_printed, 658 const DumpValueObjectOptions::PointerDepth &curr_ptr_depth) { 659 ValueObject *synth_m_valobj = GetValueObjectForChildrenGeneration(); 660 661 bool print_dotdotdot = false; 662 size_t num_children = GetMaxNumChildrenToPrint(print_dotdotdot); 663 if (num_children) { 664 bool any_children_printed = false; 665 666 for (size_t idx = 0; idx < num_children; ++idx) { 667 if (ValueObjectSP child_sp = GenerateChild(synth_m_valobj, idx)) { 668 if (!any_children_printed) { 669 PrintChildrenPreamble(); 670 any_children_printed = true; 671 } 672 PrintChild(child_sp, curr_ptr_depth); 673 } 674 } 675 676 if (any_children_printed) 677 PrintChildrenPostamble(print_dotdotdot); 678 else { 679 if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) { 680 if (ShouldPrintValueObject()) 681 m_stream->PutCString(" {}\n"); 682 else 683 m_stream->EOL(); 684 } else 685 m_stream->EOL(); 686 } 687 } else if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) { 688 // Aggregate, no children... 689 if (ShouldPrintValueObject()) { 690 // if it has a synthetic value, then don't print {}, the synthetic 691 // children are probably only being used to vend a value 692 if (m_valobj->DoesProvideSyntheticValue() || 693 !ShouldExpandEmptyAggregates()) 694 m_stream->PutCString("\n"); 695 else 696 m_stream->PutCString(" {}\n"); 697 } 698 } else { 699 if (ShouldPrintValueObject()) 700 m_stream->EOL(); 701 } 702 } 703 704 bool ValueObjectPrinter::PrintChildrenOneLiner(bool hide_names) { 705 if (!GetMostSpecializedValue() || m_valobj == nullptr) 706 return false; 707 708 ValueObject *synth_m_valobj = GetValueObjectForChildrenGeneration(); 709 710 bool print_dotdotdot = false; 711 size_t num_children = GetMaxNumChildrenToPrint(print_dotdotdot); 712 713 if (num_children) { 714 m_stream->PutChar('('); 715 716 for (uint32_t idx = 0; idx < num_children; ++idx) { 717 lldb::ValueObjectSP child_sp(synth_m_valobj->GetChildAtIndex(idx, true)); 718 if (child_sp) 719 child_sp = child_sp->GetQualifiedRepresentationIfAvailable( 720 m_options.m_use_dynamic, m_options.m_use_synthetic); 721 if (child_sp) { 722 if (idx) 723 m_stream->PutCString(", "); 724 if (!hide_names) { 725 const char *name = child_sp.get()->GetName().AsCString(); 726 if (name && *name) { 727 m_stream->PutCString(name); 728 m_stream->PutCString(" = "); 729 } 730 } 731 child_sp->DumpPrintableRepresentation( 732 *m_stream, ValueObject::eValueObjectRepresentationStyleSummary, 733 m_options.m_format, 734 ValueObject::PrintableRepresentationSpecialCases::eDisable); 735 } 736 } 737 738 if (print_dotdotdot) 739 m_stream->PutCString(", ...)"); 740 else 741 m_stream->PutChar(')'); 742 } 743 return true; 744 } 745 746 void ValueObjectPrinter::PrintChildrenIfNeeded(bool value_printed, 747 bool summary_printed) { 748 // This flag controls whether we tried to display a description for this 749 // object and failed if that happens, we want to display the children if any. 750 bool is_failed_description = 751 !PrintObjectDescriptionIfNeeded(value_printed, summary_printed); 752 753 DumpValueObjectOptions::PointerDepth curr_ptr_depth = m_ptr_depth; 754 const bool print_children = 755 ShouldPrintChildren(is_failed_description, curr_ptr_depth); 756 const bool print_oneline = 757 (curr_ptr_depth.CanAllowExpansion() || m_options.m_show_types || 758 !m_options.m_allow_oneliner_mode || m_options.m_flat_output || 759 (m_options.m_pointer_as_array) || m_options.m_show_location) 760 ? false 761 : DataVisualization::ShouldPrintAsOneLiner(*m_valobj); 762 if (print_children && IsInstancePointer()) { 763 uint64_t instance_ptr_value = m_valobj->GetValueAsUnsigned(0); 764 if (m_printed_instance_pointers->count(instance_ptr_value)) { 765 // We already printed this instance-is-pointer thing, so don't expand it. 766 m_stream->PutCString(" {...}\n"); 767 return; 768 } else { 769 // Remember this guy for future reference. 770 m_printed_instance_pointers->emplace(instance_ptr_value); 771 } 772 } 773 774 if (print_children) { 775 if (print_oneline) { 776 m_stream->PutChar(' '); 777 PrintChildrenOneLiner(false); 778 m_stream->EOL(); 779 } else 780 PrintChildren(value_printed, summary_printed, curr_ptr_depth); 781 } else if (m_curr_depth >= m_options.m_max_depth && IsAggregate() && 782 ShouldPrintValueObject()) { 783 m_stream->PutCString("{...}\n"); 784 } else 785 m_stream->EOL(); 786 } 787