[lldb-dev] Patch for ValueObjectPrinter::PrintChildrenIfNeeded

Nat! via lldb-dev lldb-dev at lists.llvm.org
Wed Mar 6 06:46:47 PST 2019


I couldn't figure out how to post a patch to reviews.llvm.org, so here 
it is per email, with the hope that someone adopts it :)

Basically it's just moving the `bool print_oneline` out of the execution 
path, if no children are

printed, since this value is then never used. This may not seem like a 
big deal, but solves a big

problem in my debugger :)



```

void ValueObjectPrinter::PrintChildrenIfNeeded(bool value_printed,
                                                bool summary_printed) {
   // this flag controls whether we tried to display a description for this
   // object and failed if that happens, we want to display the 
children, if any
   bool is_failed_description =
       !PrintObjectDescriptionIfNeeded(value_printed, summary_printed);

   auto curr_ptr_depth = m_ptr_depth;
   bool print_children =
       ShouldPrintChildren(is_failed_description, curr_ptr_depth);

   //
   // DataVisualization::ShouldPrintAsOneLiner is often called for
   // print_oneline (see below) and it is very expensive, so use an
   // early exit, if we are not printing children (also easier to read)
   //
   if (!print_children) {
     if (m_curr_depth >= m_options.m_max_depth && IsAggregate() &&
                ShouldPrintValueObject()) {
       m_stream->PutCString("{...}\n");
     } else
       m_stream->EOL();
     return;
   }

   //
   // TODO: maybe move the bool print_oneline line to #1#, but its 
unclear to
   // me if DataVisualization::ShouldPrintAsOneLiner can modify 
*m_valobj or not
   //
   bool print_oneline =
       (curr_ptr_depth.CanAllowExpansion() || m_options.m_show_types ||
        !m_options.m_allow_oneliner_mode || m_options.m_flat_output ||
        (m_options.m_pointer_as_array) || m_options.m_show_location)
           ? false
           : DataVisualization::ShouldPrintAsOneLiner(*m_valobj);

   bool is_instance_ptr = IsInstancePointer();
   uint64_t instance_ptr_value = LLDB_INVALID_ADDRESS;

   if (is_instance_ptr) {
     instance_ptr_value = m_valobj->GetValueAsUnsigned(0);
     if (m_printed_instance_pointers->count(instance_ptr_value)) {
       // we already printed this instance-is-pointer thing, so don't 
expand it
       m_stream->PutCString(" {...}\n");

       // we're done here - get out fast
       return;
     } else
       m_printed_instance_pointers->emplace(
           instance_ptr_value); // remember this guy for future reference
   }

   // #1#
   if (print_oneline) {
     m_stream->PutChar(' ');
     PrintChildrenOneLiner(false);
     m_stream->EOL();
   } else
     PrintChildren(value_printed, summary_printed, curr_ptr_depth);
}

```


Ciao

    Nat!



More information about the lldb-dev mailing list