[Lldb-commits] [lldb] [lldb] Fix output of `help format` (PR #190409)
Sergei Barannikov via lldb-commits
lldb-commits at lists.llvm.org
Fri Apr 3 15:15:28 PDT 2026
https://github.com/s-barannikov updated https://github.com/llvm/llvm-project/pull/190409
>From 8e57d2573f9ac72e94eeaaccbbf1e16327f08f24 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov <barannikov88 at gmail.com>
Date: Sat, 4 Apr 2026 00:14:55 +0300
Subject: [PATCH 1/2] [lldb] Fix output of `help format`
The output currently contains
```
"unicode32"
'u' or "unsigned decimal"
'p' or
"pointer"
"char[]"
"int8_t[]"
```
The 'p' and "pointer" are supposed to appear on the same line. When
we're about to print "pointer," we check whether it would exceed the
column limit (in which case, we insert a line feed). This check only
checks for spaces as separators, but in the case of `help format`, the
"words" are separated by newlines. Look for them as well.
---
lldb/source/Interpreter/CommandInterpreter.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index eeb1ae0ff3eb8..b1baab3272968 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -3174,7 +3174,7 @@ void CommandInterpreter::OutputHelpText(Stream &strm, llvm::StringRef word_text,
uint32_t chars_left = max_columns;
auto nextWordLength = [](llvm::StringRef S) {
- size_t pos = S.find(' ');
+ size_t pos = S.find_first_of(" \n");
return pos == llvm::StringRef::npos ? S.size() : pos;
};
>From 2964268f4361cb8d5d9e43ad7b2d84353c3c0066 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov <barannikov88 at gmail.com>
Date: Sat, 4 Apr 2026 01:13:18 +0300
Subject: [PATCH 2/2] Better fix and test
---
lldb/source/Interpreter/CommandInterpreter.cpp | 6 +++---
lldb/test/API/commands/help/TestHelp.py | 17 ++++++++++++++---
2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index b1baab3272968..a467a9cc57f0c 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -3173,14 +3173,14 @@ void CommandInterpreter::OutputHelpText(Stream &strm, llvm::StringRef word_text,
uint32_t chars_left = max_columns;
- auto nextWordLength = [](llvm::StringRef S) {
- size_t pos = S.find_first_of(" \n");
+ auto nextChunkLength = [](llvm::StringRef S) {
+ size_t pos = S.find_first_of(" \n", S.find_first_not_of(' '));
return pos == llvm::StringRef::npos ? S.size() : pos;
};
while (!text.empty()) {
if (text.front() == '\n' ||
- (text.front() == ' ' && nextWordLength(text.ltrim(' ')) > chars_left)) {
+ (text.front() == ' ' && nextChunkLength(text) > chars_left)) {
strm.EOL();
strm.Indent();
chars_left = max_columns - indent_size;
diff --git a/lldb/test/API/commands/help/TestHelp.py b/lldb/test/API/commands/help/TestHelp.py
index 8423d410ca306..e5256840dea30 100644
--- a/lldb/test/API/commands/help/TestHelp.py
+++ b/lldb/test/API/commands/help/TestHelp.py
@@ -239,7 +239,7 @@ def test_help_unknown_flag(self):
def test_help_format_output(self):
"""Test that help output reaches TerminalWidth and wraps to the next
line if needed."""
- self.runCmd("settings set term-width 118")
+ self.runCmd("settings set term-width 105")
self.expect(
"help format",
matching=True,
@@ -249,9 +249,9 @@ def test_help_format_output(self):
],
)
- # The length of the first line will not be exactly 108 because we split
+ # The length of the first line will not be exactly 105 because we split
# at the last whitespace point before the limit.
- self.runCmd("settings set term-width 108")
+ self.runCmd("settings set term-width 104")
self.expect(
"help format",
matching=True,
@@ -271,6 +271,17 @@ def test_help_format_output(self):
],
)
+ # Check that line splitting works with newline characters too. The raw input after the word "pointer" does not
+ # contain spaces among the more than one hundred subsequent characters, the words are separated with newlines.
+ self.runCmd("settings set term-width 80")
+ self.expect(
+ "help format",
+ matching=True,
+ substrs=[
+ "'p' or \"pointer\""
+ ],
+ )
+
@no_debug_info_test
def test_help_option_group_format_options_usage(self):
"""Test that help on commands that use OptionGroupFormat options provide relevant help specific to that command."""
More information about the lldb-commits
mailing list