https://github.com/adrian-prantl updated https://github.com/llvm/llvm-project/pull/184926
>From b1ef0ccaa846e61ae3b57595efbf86a71e419b5b Mon Sep 17 00:00:00 2001 From: Adrian Prantl <[email protected]> Date: Thu, 5 Mar 2026 17:12:56 -0800 Subject: [PATCH] [LLDB] Allow one-line summaries in the presence of synthetic child providers 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 --- lldb/source/DataFormatters/FormatManager.cpp | 2 +- .../synth_oneline_summaries/Makefile | 3 +++ .../MyStringFormatter.py | 12 +++++++++++ .../TestSyntheticOneLineSummaries.py | 21 +++++++++++++++++++ .../synth_oneline_summaries/main.c | 16 ++++++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/Makefile create mode 100644 lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/MyStringFormatter.py create mode 100644 lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/TestSyntheticOneLineSummaries.py create mode 100644 lldb/test/API/functionalities/data-formatter/synth_oneline_summaries/main.c 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
