Skip to content

Commit 182443f

Browse files
committed
[lldb] Fix value printing for a specific case
Fixes printing of spaces in cases where the following are true: 1. Persistent results are disabled 2. The type has a summary string As reported by @jgorbe in D146783, two spaces were being printed before the summary string, and no spaces were printed after. Differential Revision: https://reviews.llvm.org/D147006 (cherry picked from commit 51dd8a2)
1 parent 58245be commit 182443f

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

lldb/include/lldb/DataFormatters/ValueObjectPrinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class ValueObjectPrinter {
9898

9999
ValueObject *GetValueObjectForChildrenGeneration();
100100

101-
void PrintChildrenPreamble();
101+
void PrintChildrenPreamble(bool value_printed, bool summary_printed);
102102

103103
void PrintChildrenPostamble(bool print_dotdotdot);
104104

lldb/source/DataFormatters/ValueObjectPrinter.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,9 @@ bool ValueObjectPrinter::PrintValueAndSummaryIfNeeded(bool &value_printed,
445445
}
446446

447447
if (m_summary.size()) {
448-
m_stream->Printf(" %s", m_summary.c_str());
448+
if (ShouldShowName() || value_printed)
449+
m_stream->PutChar(' ');
450+
m_stream->PutCString(m_summary);
449451
summary_printed = true;
450452
}
451453
}
@@ -582,15 +584,16 @@ ValueObject *ValueObjectPrinter::GetValueObjectForChildrenGeneration() {
582584
return m_valobj;
583585
}
584586

585-
void ValueObjectPrinter::PrintChildrenPreamble() {
587+
void ValueObjectPrinter::PrintChildrenPreamble(bool value_printed,
588+
bool summary_printed) {
586589
if (m_options.m_flat_output) {
587590
if (ShouldPrintValueObject())
588591
m_stream->EOL();
589592
} else {
590593
if (ShouldPrintValueObject()) {
591594
if (IsRef()) {
592595
m_stream->PutCString(": ");
593-
} else if (ShouldShowName()) {
596+
} else if (value_printed || summary_printed || ShouldShowName()) {
594597
m_stream->PutChar(' ');
595598
}
596599
m_stream->PutCString("{\n");
@@ -716,7 +719,7 @@ void ValueObjectPrinter::PrintChildren(
716719
for (size_t idx = 0; idx < num_children; ++idx) {
717720
if (ValueObjectSP child_sp = GenerateChild(synth_m_valobj, idx)) {
718721
if (!any_children_printed) {
719-
PrintChildrenPreamble();
722+
PrintChildrenPreamble(value_printed, summary_printed);
720723
any_children_printed = true;
721724
}
722725
PrintChild(child_sp, curr_ptr_depth);

lldb/test/API/commands/dwim-print/TestDWIMPrint.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,12 @@ def test_nested_values(self):
120120
self.runCmd("settings set auto-one-line-summaries false")
121121
self._expect_cmd(f"dwim-print s", "frame variable")
122122
self._expect_cmd(f"dwim-print (struct Structure)s", "expression")
123+
124+
def test_summary_strings(self):
125+
"""Test dwim-print with nested values (structs, etc)."""
126+
self.build()
127+
lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.c"))
128+
self.runCmd("settings set auto-one-line-summaries false")
129+
self.runCmd("type summary add -e -s 'stub summary' Structure")
130+
self._expect_cmd(f"dwim-print s", "frame variable")
131+
self._expect_cmd(f"dwim-print (struct Structure)s", "expression")

0 commit comments

Comments
 (0)