aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2024-09-24 13:26:15 +0200
committerTom de Vries <tdevries@suse.de>2024-09-24 13:26:15 +0200
commit7ba8082f030c44b15616336f7dee7ee1df74ba21 (patch)
tree094d3f8937dfc9da30ef7f9ab3cd666e3d45080a
parente1863c7d7cf84e3a5ef4eaa880f024c94202eb84 (diff)
downloadgdb-7ba8082f030c44b15616336f7dee7ee1df74ba21.zip
gdb-7ba8082f030c44b15616336f7dee7ee1df74ba21.tar.gz
gdb-7ba8082f030c44b15616336f7dee7ee1df74ba21.tar.bz2
[gdb/cli] Show readline wrapping mode for maint info screen
With the same trigger patch adding "set horizontal-scroll-mode on" to INPUTRC as used in commit 250f1bbaf33 ("[gdb/testsuite] Fix gdb.tui/wrap-line.exp with wrapping disabled"), we can easily reproduce a failure in gdb.tui/wrap-line.exp mentioned in PR testsuite/31201: ... (gdb) 78901234567890123456789012345678901234567890123456789012345678901234567^M<890123456789012345678901234567890123456789012345678 ^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H9WFAIL: gdb.base/wrap-line.exp: term=ansi: width-hard-coded: wrap (timeout) ... The test-case expects wrapping, but that's disabled by horizontal-scroll-mode. Add a new line to "maint info screen", that describes the current readline wrapping mode, and use it in the test-case to handle the different cases. The reported values for the wrapping mode are as follows. Unsupported because of running in batch mode: ... $ gdb -q -batch -ex "maint info screen" Readline wrapping mode: unsupported (gdb batch mode). ... Unsupported because the terminal is not capable to move the cursor up: ... $ TERM=dumb gdb -q -ex "maint info screen" -ex q Readline wrapping mode: unsupported (terminal is not Cursor Up capable). ... Disabled by horizontal-scroll-mode: ... $ grep horizontal-scroll-mode ~/.inputrc set horizontal-scroll-mode on $ gdb -q -ex "maint info screen" -ex q Readline wrapping mode: disabled (horizontal-scroll-mode). ... Wrap done by readline because terminal is not auto wrap capable: ... $ TERM=ansi gdb -q -ex "maint info screen" -ex q Readline wrapping mode: readline (terminal is not auto wrap capable, last column reserved). ... Wrap done by terminal autowrap: ... $ TERM=xterm gdb -q -ex "maint info screen" -ex q Readline wrapping mode: terminal (terminal is auto wrap capable). ... Tested on x86_64-linux. Co-Authored-By: Bernd Edlinger <bernd.edlinger@hotmail.de> Approved-By: Tom Tromey <tom@tromey.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31201
-rw-r--r--gdb/testsuite/gdb.base/wrap-line.exp28
-rw-r--r--gdb/utils.c48
2 files changed, 70 insertions, 6 deletions
diff --git a/gdb/testsuite/gdb.base/wrap-line.exp b/gdb/testsuite/gdb.base/wrap-line.exp
index b0931a3..323cd6c 100644
--- a/gdb/testsuite/gdb.base/wrap-line.exp
+++ b/gdb/testsuite/gdb.base/wrap-line.exp
@@ -19,8 +19,10 @@
# build == host.
require {!is_remote host}
-# Test both ansi (no auto-wrap) and xterm (auto-wrap).
-set terms {ansi xterm}
+# Test both ansi (no auto-wrap) and xterm (auto-wrap). Also test dumb, which
+# shows the effective behaviour on stub-termcap systems, regardless of the
+# TERM setting.
+set terms {ansi xterm dumb}
# Fill line, assuming we start after the gdb prompt.
proc fill_line { width } {
@@ -44,9 +46,11 @@ proc get_screen_width { } {
upvar gdb_width gdb_width
upvar readline_width readline_width
upvar env_width env_width
+ upvar wrap_mode wrap_mode
set gdb_width 0
set readline_width 0
set env_width 0
+ set wrap_mode ""
set re1 "Number of characters gdb thinks are in a line is ($::decimal)\[^\r\n\]*\\."
set re2 \
"Number of characters readline reports are in a line is ($::decimal)\[^\r\n\]*\\."
@@ -54,6 +58,7 @@ proc get_screen_width { } {
"Number of characters curses thinks are in a line is $::decimal\\."
set re4 \
"Number of characters environment thinks are in a line is ($::decimal) \\(COLUMNS\\)."
+ set re5 [string cat "Readline wrapping mode: (\[^\r\n]*\)\\."]
set cmd "maint info screen"
set re \
[multi_line \
@@ -61,12 +66,14 @@ proc get_screen_width { } {
$re2 \
"(?:$re3" \
")?$re4" \
- .*]
+ .* \
+ $re5]
gdb_test_multiple $cmd "" {
-re -wrap $re {
set gdb_width $expect_out(1,string)
set readline_width $expect_out(2,string)
set env_width $expect_out(3,string)
+ set wrap_mode $expect_out(4,string)
pass $gdb_test_name
}
}
@@ -79,10 +86,16 @@ proc test_wrap { width_auto_detected } {
get_screen_width
- if { $::term == "xterm" } {
+ set wrap_mode_terminal "terminal (terminal is auto wrap capable)"
+ set wrap_mode_readline \
+ "readline (terminal is not auto wrap capable, last column reserved)"
+ set have_wrap 1
+ if { $wrap_mode == $wrap_mode_terminal } {
gdb_assert { $gdb_width == $readline_width }
- } else {
+ } elseif { $wrap_mode == $wrap_mode_readline } {
gdb_assert { $gdb_width == [expr $readline_width + 1] }
+ } else {
+ set have_wrap 0
}
gdb_assert { $gdb_width == $env_width } "width"
@@ -113,7 +126,10 @@ proc test_wrap { width_auto_detected } {
gdb_test_multiple "" "wrap" {
-re $re {
- pass $gdb_test_name
+ gdb_assert {$have_wrap} $gdb_test_name
+ }
+ -re "\r<.*" {
+ gdb_assert {!$have_wrap} $gdb_test_name
}
}
diff --git a/gdb/utils.c b/gdb/utils.c
index 07c5d3c..c503ff7 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1282,6 +1282,14 @@ set_screen_width_and_height (int width, int height)
set_width ();
}
+/* Import termcap variable UP (instead of readline private variable
+ _rl_term_up, which we're trying to avoid, see PR build/10723). The UP
+ variable doesn't seem be part of the regular termcap interface, but rather
+ curses-specific. But if it's missing in the termcap library, then readline
+ provides a fallback version. Let's assume the fallback is not part of the
+ private readline interface. */
+extern "C" char *UP;
+
/* Implement "maint info screen". */
static void
@@ -1340,6 +1348,46 @@ maintenance_info_screen (const char *args, int from_tty)
_("Number of lines environment thinks "
"are in a page is %s (LINES).\n"),
getenv ("LINES"));
+
+ bool have_up = UP != nullptr && *UP != '\0';
+
+ /* Fetch value of readline variable horizontal-scroll-mode. */
+ const char *horizontal_scroll_mode_value
+ = rl_variable_value ("horizontal-scroll-mode");
+ bool force_horizontal_scroll_mode
+ = (horizontal_scroll_mode_value != nullptr
+ && strcmp (horizontal_scroll_mode_value, "on") == 0);
+
+ const char *mode = nullptr;
+ const char *reason = nullptr;
+ if (batch_flag)
+ {
+ mode = "unsupported";
+ reason = "gdb batch mode";
+ }
+ else if (!have_up)
+ {
+ mode = "unsupported";
+ reason = "terminal is not Cursor Up capable";
+ }
+ else if (force_horizontal_scroll_mode)
+ {
+ mode = "disabled";
+ reason = "horizontal-scroll-mode";
+ }
+ else if (readline_hidden_cols)
+ {
+ mode = "readline";
+ reason = "terminal is not auto wrap capable, last column reserved";
+ }
+ else
+ {
+ mode = "terminal";
+ reason = "terminal is auto wrap capable";
+ }
+
+ gdb_printf (gdb_stdout, _("Readline wrapping mode: %s (%s).\n"), mode,
+ reason);
}
void