From: Andrew Burgess Date: Fri, 5 Dec 2025 11:33:29 +0000 (+0000) Subject: gdb: new setting to disable progress bars X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=255a9c42709958d0925d1d0d1d39d262972fd2a6;p=thirdparty%2Fbinutils-gdb.git gdb: new setting to disable progress bars Two commits ago, in the commit titled: gdb: make get_chars_per_line return an unsigned value A bodge was added in cli-out.c so that progress bars (as seen when debuginfod downloads a file) would be disabled when the output terminal had unlimited width. The hack was added because this previous commit fixed a bug such that progress bars could now be displayed in very wide, or even on unlimited width output terminals. By fixing this bug, progress bars were now being displayed when running the testsuite, as the testsuite sets the output terminal to unlimited width. To avoid breaking the tests, this previous commit added a bodge such that on unlimited width output terminals, progress bars would always be disabled. This got the tests passing again, but isn't an ideal solution. This commit cleans things up. We now have a new setting: set progress-bars enabled on|off show progress-bars enabled This setting allows progress bars to be turned off. The tests are then updated to explicitly turn off progress bars. The bodge from the earlier commit is then removed. Now, progress bars should display correctly on any width of output terminal over 50 characters, the minimum required. And the debuginfod tests should all pass as they turn off progress bars. Reviewed-By: Eli Zaretskii Approved-By: Tom Tromey --- diff --git a/gdb/NEWS b/gdb/NEWS index 0eff1d551a3..ba37dc89f76 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -69,6 +69,12 @@ maintenance test-remote-args ARGS Test splitting and joining of inferior arguments ARGS as they would be split and joined when being passed to a remote target. +set progress-bars enabled on|off +show progress-bars enabled + Allows the progress bars, used when debuginfod is downloading + content, to be disabled (the set command), or to see if + progress-bars are currently enabled or not (the show command). + * Changed commands maintenance info program-spaces diff --git a/gdb/cli-out.c b/gdb/cli-out.c index 5aa13a64271..c3949465490 100644 --- a/gdb/cli-out.c +++ b/gdb/cli-out.c @@ -26,6 +26,7 @@ #include "readline/readline.h" #include "cli/cli-style.h" #include "ui.h" +#include "cli/cli-cmds.h" /* These are the CLI output functions */ @@ -275,6 +276,31 @@ cli_ui_out::do_progress_start () #define MIN_CHARS_PER_LINE 50 #define MAX_CHARS_PER_LINE 4096 +/* When this is false no progress bars will be displayed. When true, + progress bars can be displayed if the output stream supports them. */ + +static bool progress_bars_enabled = true; + +/* The "show progress-bars enabled" command. */ + +static void +show_progress_bars_enabled (struct ui_file *file, int from_tty, + struct cmd_list_element *c, + const char *value) +{ + if (progress_bars_enabled && get_chars_per_line () < MIN_CHARS_PER_LINE) + gdb_printf (file, _("Progress bars are currently \"off\". " + "The terminal is too narrow.\n")); + else if (progress_bars_enabled && (!gdb_stdout->isatty () + || !current_ui->input_interactive_p ())) + gdb_printf (file, _("Progress bars are currently \"off\". " + "The terminal doesn't support them.\n")); + else + gdb_printf (file, + _("Progress bars are currently \"%s\".\n"), + value); +} + /* Print a progress update. MSG is a string to be printed on the line above the progress bar. TOTAL is the size of the download whose progress is being displayed. UNIT should be the unit of TOTAL (ex. "K"). If HOWMUCH @@ -307,7 +333,7 @@ cli_ui_out::do_progress_notify (const std::string &msg, if (stream->isatty () && current_ui->input_interactive_p () && chars_per_line >= MIN_CHARS_PER_LINE - && chars_per_line != UINT_MAX) + && progress_bars_enabled) { gdb_printf (stream, "%s\n", msg.c_str ()); info.state = progress_update::BAR; @@ -393,7 +419,7 @@ cli_ui_out::clear_progress_notify () if (!stream->isatty () || !current_ui->input_interactive_p () || chars_per_line < MIN_CHARS_PER_LINE - || chars_per_line == UINT_MAX) + || !progress_bars_enabled) return; if (chars_per_line > MAX_CHARS_PER_LINE) @@ -542,3 +568,37 @@ cli_display_match_list (char **matches, int len, int max) gdb_display_match_list (matches, len, max, &displayer); rl_forced_update_display (); } + +/* Set/show progress-bars commands. */ +static cmd_list_element *set_progress_bars_prefix_list; +static cmd_list_element *show_progress_bars_prefix_list; + +/* Initialization for this file. */ + +INIT_GDB_FILE (cli_out) +{ + /* set/show debuginfod */ + add_setshow_prefix_cmd ("progress-bars", class_obscure, + _("Set progress-bars options."), + _("Show progress-bars options."), + &set_progress_bars_prefix_list, + &show_progress_bars_prefix_list, + &setlist, &showlist); + + /* Adds 'set|show progress-bars enabled'. */ + add_setshow_boolean_cmd ("enabled", class_obscure, + &progress_bars_enabled, _("\ +Set whether progress bars should be displayed."), _("\ +Show whether progress bars should be displayed."),_("\ +During some slow operations, for example, fetching debug information\n\ +from debuginfod, GDB will display an animated progress bar when this\n\ +setting is \"on\". When this setting is \"off\", no progress bars\n\ +will be displayed.\n\ +\n\ +Even when \"on\", progress bars can be disabled if the output terminal\n\ +doesn't support them."), + nullptr, + show_progress_bars_enabled, + &set_progress_bars_prefix_list, + &show_progress_bars_prefix_list); +} diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index bd5d0250483..4c012393ff4 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -51349,6 +51349,21 @@ default. @item show debuginfod verbose Show the current verbosity setting. +@kindex set progress-bars enabled +@cindex progress bars, disabling +@item set progress-bars enabled @r{[}on@r{|}off@r{]} +Set whether @value{GDBN} can display a progress bar when downloading a +file from debuginfod. When @value{off}, @value{GDBN} will not display +a progress bar. When @value{on}, @value{GDBN} will display a progress +bar if @value{GDBN}'s output console supports it. + +@kindex show progress-bars enabled +@item show progress-bars enabled +Shows whether progress bars are currently enabled or not. Progress +bars can be automatically disabled if @value{GDBN}'s output console +doesn't support them, or if the terminal width is too small +(@pxref{Screen Size,,@kbd{set width} command}). + @end table @node Man Pages diff --git a/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp b/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp index 7a0cfda627c..eb4d0589478 100644 --- a/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp +++ b/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp @@ -132,6 +132,7 @@ proc_with_prefix local_debuginfod { } { # Enable debuginfod and fetch the debuginfo. gdb_test_no_output "set debuginfod enabled on" + gdb_test_no_output "set progress-bars enabled off" # "separate debug info file has no debug info" warning should not be # reported now because the correct debuginfo should be fetched from diff --git a/gdb/testsuite/gdb.debuginfod/corefile-mapped-file.exp b/gdb/testsuite/gdb.debuginfod/corefile-mapped-file.exp index 83472f00bb0..df84a1dcb98 100644 --- a/gdb/testsuite/gdb.debuginfod/corefile-mapped-file.exp +++ b/gdb/testsuite/gdb.debuginfod/corefile-mapped-file.exp @@ -371,6 +371,7 @@ with_debuginfod_env $cache { clean_restart gdb_test_no_output "set debuginfod enabled on" \ "enabled debuginfod for initial test" + gdb_test_no_output "set progress-bars enabled off" gdb_load $binfile load_core_file "load corefile, download library from debuginfod" \ diff --git a/gdb/testsuite/gdb.debuginfod/crc_mismatch.exp b/gdb/testsuite/gdb.debuginfod/crc_mismatch.exp index e44748f8205..92de3ee2167 100644 --- a/gdb/testsuite/gdb.debuginfod/crc_mismatch.exp +++ b/gdb/testsuite/gdb.debuginfod/crc_mismatch.exp @@ -113,6 +113,7 @@ proc_with_prefix local_debuginfod { } { # Enable debuginfod and fetch the debuginfo. gdb_test_no_output "set debuginfod enabled on" + gdb_test_no_output "set progress-bars enabled off" gdb_test "file $binfile" ".*Reading symbols from.*debuginfo.*" \ "file [file tail $binfile] cmd on" diff --git a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp index 9078068c8fe..e3d9c36777b 100644 --- a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp +++ b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp @@ -218,6 +218,7 @@ proc_with_prefix local_url { } { clean_restart gdb_test_no_output "set debuginfod enabled on" \ "enabled debuginfod for initial test" + gdb_test_no_output "set progress-bars enabled off" gdb_load $binfile gdb_test_no_output "set substitute-path $outputdir /dev/null" \ "set substitute-path" @@ -243,11 +244,13 @@ proc_with_prefix local_url { } { set enable_debuginfod_question \ "Enable debuginfod for this session. \\(y or \\\[n\\\]\\) " clean_restart + gdb_test_no_output -nopass "set progress-bars enabled off" gdb_test "core $::corefile" ".*return 0.*" "file [file tail $::corefile]" \ $enable_debuginfod_question "y" # GDB should now find the debugaltlink file. clean_restart + gdb_test_no_output -nopass "set progress-bars enabled off" gdb_test "file ${binfile}_alt.o" \ ".*Downloading.*separate debug info.*" \ "file [file tail ${binfile}_alt.o]" \ @@ -269,6 +272,7 @@ proc_with_prefix local_url { } { # Enable debuginfod and fetch the debuginfo. gdb_test_no_output "set debuginfod enabled on" + gdb_test_no_output -nopass "set progress-bars enabled off" gdb_test "file $binfile" ".*Reading symbols from.*debuginfo.*" \ "file [file tail $binfile] cmd on" diff --git a/gdb/testsuite/gdb.debuginfod/solib-with-soname.exp b/gdb/testsuite/gdb.debuginfod/solib-with-soname.exp index a22fa597602..5ff65e8f769 100644 --- a/gdb/testsuite/gdb.debuginfod/solib-with-soname.exp +++ b/gdb/testsuite/gdb.debuginfod/solib-with-soname.exp @@ -281,6 +281,7 @@ with_debuginfod_env $cache { save_vars { GDBFLAGS } { append GDBFLAGS " -ex \"set debuginfod enabled on\"" + append GDBFLAGS " -ex \"set progress-bars enabled off\"" # Reload the executable and core file. GDB should download # the file libfoo_1.so using debuginfod during the mapped file