Author: Adrian Prantl
Date: 2026-03-06T10:07:08-08:00
New Revision: 70509b5e19645bcfd81d382d2cdb560eeb187da1

URL: 
https://github.com/llvm/llvm-project/commit/70509b5e19645bcfd81d382d2cdb560eeb187da1
DIFF: 
https://github.com/llvm/llvm-project/commit/70509b5e19645bcfd81d382d2cdb560eeb187da1.diff

LOG: [LLDB] Allow one-line summaries in the presence of synthetic child 
providers (#184926)

This is driven by the Swift language. In Swift many data types such as
Int, and String are structs, and LLDB provides summary formatters and
synthetic child providers for them. For String, for example, a summary
formatter pulls out the string data from the implementation, while a
synthetic child provider hides the implementation details from users, so
strings don't expand their children.

rdar://171646109

Added: 
    
lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/Makefile
    
lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/MyStringFormatter.py
    
lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/TestSyntheticOneLineSummaries.py
    lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/main.c

Modified: 
    lldb/source/DataFormatters/FormatManager.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/DataFormatters/FormatManager.cpp 
b/lldb/source/DataFormatters/FormatManager.cpp
index 6d3faa5742d63..301b924a5625d 100644
--- a/lldb/source/DataFormatters/FormatManager.cpp
+++ b/lldb/source/DataFormatters/FormatManager.cpp
@@ -526,7 +526,7 @@ bool FormatManager::ShouldPrintAsOneLiner(ValueObject 
&valobj) {
       if (!synth_sp->MightHaveChildren() &&
           synth_sp->DoesProvideSyntheticValue())
         is_synth_val = true;
-      else
+      else if (synth_sp->MightHaveChildren())
         return false;
     }
 

diff  --git 
a/lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/Makefile 
b/lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/Makefile
new file mode 100644
index 0000000000000..10495940055b6
--- /dev/null
+++ 
b/lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules

diff  --git 
a/lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/MyStringFormatter.py
 
b/lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/MyStringFormatter.py
new file mode 100644
index 0000000000000..938194ee78146
--- /dev/null
+++ 
b/lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/MyStringFormatter.py
@@ -0,0 +1,12 @@
+import lldb
+
+
+class MyStringSynthProvider:
+    def __init__(self, valobj, dict):
+        self.valobj = valobj
+
+    def num_children(self, max_num_children):
+        return 0
+
+    def has_children(self):
+        return False

diff  --git 
a/lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/TestSyntheticOneLineSummaries.py
 
b/lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/TestSyntheticOneLineSummaries.py
new file mode 100644
index 0000000000000..4cada6efcca85
--- /dev/null
+++ 
b/lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/TestSyntheticOneLineSummaries.py
@@ -0,0 +1,21 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class SyntheticOneLineSummariesTestCase(TestBase):
+    def test(self):
+        """Test that the presence of a synthetic child provider doesn't 
prevent one-line-summaries."""
+        self.build()
+        lldbutil.run_to_source_breakpoint(self, "break here", 
lldb.SBFileSpec("main.c"))
+
+        # set up the synthetic children provider
+        self.runCmd("script from MyStringFormatter import *")
+        self.runCmd("type synth add -l MyStringSynthProvider MyString")
+        self.runCmd('type summary add --summary-string "${var.guts}" MyString')
+
+        self.expect(
+            "frame variable s",
+            substrs=['a = "hello", b = "world"'],
+        )

diff  --git 
a/lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/main.c 
b/lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/main.c
new file mode 100644
index 0000000000000..947be634f5b9b
--- /dev/null
+++ 
b/lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/main.c
@@ -0,0 +1,16 @@
+struct MyString {
+  const char *guts;
+};
+
+struct S {
+  struct MyString a;
+  struct MyString b;
+};
+void stop() {}
+int main() {
+  struct S s;
+  s.a.guts = "hello";
+  s.b.guts = "world";
+  stop(); // break here
+  return 0;
+}


        
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to