]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: new setting to disable progress bars
authorAndrew Burgess <aburgess@redhat.com>
Fri, 5 Dec 2025 11:33:29 +0000 (11:33 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Mon, 15 Dec 2025 14:56:46 +0000 (14:56 +0000)
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 <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
gdb/NEWS
gdb/cli-out.c
gdb/doc/gdb.texinfo
gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp
gdb/testsuite/gdb.debuginfod/corefile-mapped-file.exp
gdb/testsuite/gdb.debuginfod/crc_mismatch.exp
gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp
gdb/testsuite/gdb.debuginfod/solib-with-soname.exp

index 0eff1d551a3d46bc043f0185f86b3cfd3d997dc3..ba37dc89f763214dc37294eb621dd2b25180a7dc 100644 (file)
--- 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
index 5aa13a64271db06c6c8e9a9359f76cf60a1d0b9c..c39494654904347fcb1f1911f610c87064fd30ca 100644 (file)
@@ -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);
+}
index bd5d0250483515aa56d27744a955c0cedcb0d4eb..4c012393ff48e6620198ab6e875d617abf9bc9d7 100644 (file)
@@ -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
index 7a0cfda627c3c415095e0c0b4c282254fc245766..eb4d0589478aec96528dbdb510388c4239f63c1c 100644 (file)
@@ -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
index 83472f00bb02ffd9f041190e94dde1a13e54e109..df84a1dcb9813748ccfe6044b3349a97c9ae8cf7 100644 (file)
@@ -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" \
index e44748f82052f34e29efaf8f04e78e3d852601d2..92de3ee21670e1a9306eacf114a448e682f7d664 100644 (file)
@@ -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"
 
index 9078068c8fe9eb52513e9f13746e76336410b295..e3d9c36777ba4d608691b2c39f5f2bd54a1f6984 100644 (file)
@@ -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"
 
index a22fa5976025c2252f009a5074dc194991914eb3..5ff65e8f769b4e25df16f1efb25173f6434b78b2 100644 (file)
@@ -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