#include "readline/readline.h"
#include "cli/cli-style.h"
#include "ui.h"
+#include "cli/cli-cmds.h"
/* These are the CLI output functions */
#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
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;
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)
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);
+}
@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
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"
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]" \
# 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"