From: Aaron Merey Date: Wed, 11 May 2022 18:14:35 +0000 (-0400) Subject: Merge with master branch X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=040720bbf786b8deb72aabd81d7b0e16a34d1ec5;p=thirdparty%2Fbinutils-gdb.git Merge with master branch --- 040720bbf786b8deb72aabd81d7b0e16a34d1ec5 diff --cc gdb/cli-out.c index ca1071ac31a,e0802df352b..51531d9eda2 --- a/gdb/cli-out.c +++ b/gdb/cli-out.c @@@ -296,104 -274,69 +293,104 @@@ cli_ui_out::do_progress_start ( */ void -cli_ui_out::do_progress_start (const std::string &name, bool should_print) +cli_ui_out::do_progress_notify (const std::string &msg, double howmuch) { struct ui_file *stream = m_streams.back (); - cli_progress_info meter; + cli_progress_info &info (m_progress_info.back ()); - meter.last_value = 0; - meter.name = name; - if (!stream->isatty ()) + if (info.state == progress_update::START) { - gdb_printf (stream, "%s...", meter.name.c_str ()); + if (!stream->isatty ()) + { - fprintf_unfiltered (stream, "%s...\n", msg.c_str ()); ++ gdb_printf (stream, "%s...\n", msg.c_str ()); + info.state = progress_update::WORKING; + } + else + { - fprintf_unfiltered (stream, "%s\n", msg.c_str ()); ++ gdb_printf (stream, "%s\n", msg.c_str ()); + info.state = progress_update::BAR; + } + } + + int chars_per_line = get_chars_per_line (); + if (chars_per_line > MAX_CHARS_PER_LINE) + chars_per_line = MAX_CHARS_PER_LINE; + + if (chars_per_line <= 0 + || info.state == progress_update::WORKING + || !stream->isatty ()) + return; - /* ++ + if (howmuch >= 0) + { + int width = chars_per_line - 3; + int max = width * howmuch; + - fprintf_unfiltered (stream, "\r["); ++ gdb_printf (stream, "\r["); + for (int i = 0; i < width; ++i) - fprintf_unfiltered (stream, i < max ? "#" : " "); - fprintf_unfiltered (stream, "]"); ++ gdb_printf (stream, i < max ? "#" : " "); ++ gdb_printf (stream, "]"); gdb_flush (stream); - meter.printing = WORKING; } else { - /* Don't actually emit anything until the first call notifies us - of progress. This makes it so a second progress message can - be started before the first one has been notified, without - messy output. */ - meter.printing = should_print ? START : NO_PRINT; + using namespace std::chrono; + milliseconds diff = duration_cast + (steady_clock::now () - info.last_update); + - * Advance the progress indicator at a rate of 1 tick every - every 0.5 seconds. * ++ /* Advance the progress indicator at a rate of 1 tick every ++ every 0.5 seconds. */ + if (diff.count () >= 500) + { + int width = chars_per_line - 3; + - fprintf_unfiltered (stream, "\r["); ++ gdb_printf (stream, "\r["); + + for (int i = 0; i < width; ++i) + { + if (i >= info.pos % width + && i < (info.pos + 3) % width) - fprintf_unfiltered (stream, "#"); ++ gdb_printf (stream, "#"); + else - fprintf_unfiltered (stream, " "); ++ gdb_printf (stream, " "); + } + - fprintf_unfiltered (stream, "]"); ++ gdb_printf (stream, "]"); + gdb_flush (stream); + info.last_update = steady_clock::now (); + info.pos++; + } } - */ + - m_meters.push_back (std::move (meter)); + return; } +/* Clear the current line of the most recent progress update. Overwrites + the current line with whitespace. */ + void -cli_ui_out::do_progress_notify (double howmuch) +cli_ui_out::clear_current_line () { struct ui_file *stream = m_streams.back (); - cli_progress_info &meter (m_meters.back ()); - - if (meter.printing == NO_PRINT) - return; - - if (meter.printing == START) - { - gdb_printf (stream, "%s\n", meter.name.c_str ()); - gdb_flush (stream); - meter.printing = WORKING; - } + int chars_per_line = get_chars_per_line (); - if (meter.printing == WORKING && howmuch >= 1.0) - return; + if (chars_per_line <= 0 + || chars_per_line > MAX_CHARS_PER_LINE) + chars_per_line = MAX_CHARS_PER_LINE; - if (!stream->isatty ()) - return; + int width = chars_per_line; - fprintf_unfiltered (stream, "\r"); - int chars_per_line = get_chars_per_line (); - if (chars_per_line > 0) - { - int i, max; - int width = chars_per_line - 3; ++ gdb_printf (stream, "\r"); + for (int i = 0; i < width; ++i) - fprintf_unfiltered (stream, " "); - fprintf_unfiltered (stream, "\r"); ++ gdb_printf (stream, " "); ++ gdb_printf (stream, "\r"); - max = width * howmuch; - gdb_printf (stream, "\r["); - for (i = 0; i < width; ++i) - gdb_printf (stream, i < max ? "#" : " "); - gdb_printf (stream, "]"); - gdb_flush (stream); - meter.printing = PROGRESS; - } + gdb_flush (stream); } +/* Remove the most recent progress update from the stack and + overwrite the current line with whitespace. */ + void cli_ui_out::do_progress_end () { diff --cc gdb/debuginfod-support.c index 2d227ba4350,f2a31ea1952..92aca018954 --- a/gdb/debuginfod-support.c +++ b/gdb/debuginfod-support.c @@@ -78,13 -86,13 +88,13 @@@ debuginfod_exec_query (const unsigned c struct user_data { - user_data (const char *desc, std::string &fname) + user_data (const char *desc, const char *fname) - : desc (desc), fname (fname), has_printed (false) + : desc (desc), fname (fname) { } const char * const desc; - std::string & fname; - const char * const fname; - bool has_printed; ++ const char * fname; + ui_out::progress_update progress; }; /* Deleter for a debuginfod_client. */ @@@ -125,16 -114,11 +135,16 @@@ progressfn (debuginfod_client *c, long user_data *data = static_cast (debuginfod_get_user_data (c)); gdb_assert (data != nullptr); + string_file styled_fname (current_uiout->can_emit_style_escape ()); + fprintf_styled (&styled_fname, file_name_style.style (), "%s", - data->fname.c_str ()); ++ data->fname); + if (check_quit_flag ()) { + current_uiout->do_progress_end (); ///? + - printf_filtered ("Cancelled download of %s %s\n", - data->desc, styled_fname.c_str ()); + gdb_printf ("Cancelling download of %s %ps...\n", - data->desc, - styled_string (file_name_style.style (), data->fname)); ++ data->desc, styled_fname.c_str ()); return 1; } @@@ -219,43 -233,6 +258,43 @@@ debuginfod_is_enabled ( return true; } +/* Print the result of the most recent attempted download. */ + +static void +print_outcome (user_data &data, int fd) +{ + /* Clears the current line of progress output. */ + current_uiout->do_progress_end (); + + string_file styled_fname (current_uiout->can_emit_style_escape ()); + fprintf_styled (&styled_fname, file_name_style.style (), "%s", - data.fname.c_str ()); ++ data.fname); + + if (debuginfod_verbose > 1 && fd >= 0) + { + struct stat s; + + if (fstat (fd, &s) == 0) + { + double size = (double)s.st_size; + const char *unit = ""; + + get_size_and_unit (&size, &unit); - printf_filtered (_("Retrieved %.02f %s %s %s\n"), size, unit, - data.desc, styled_fname.c_str ()); ++ gdb_printf (_("Retrieved %.02f %s %s %s\n"), size, unit, ++ data.desc, styled_fname.c_str ()); + } + else + warning (_("Retrieved %s %s but size cannot be read: %s\n"), + data.desc, styled_fname.c_str (), + safe_strerror (errno)); + } - else if (debuginfod_verbose > 0 && fd < 0 && fd != -ENOENT) - printf_filtered (_("Download failed: %s. " \ - "Continuing without %s %s.\n"), - safe_strerror (-fd), data.desc, - styled_fname.c_str ()); ++ else if (fd < 0 && fd != -ENOENT) ++ gdb_printf (_("Download failed: %s. " \ ++ "Continuing without %s %s.\n"), ++ safe_strerror (-fd), data.desc, ++ styled_fname.c_str ()); +} + /* See debuginfod-support.h */ scoped_fd diff --cc gdb/mi/mi-out.c index e5c4e3b8534,567ef83de9b..6b3e932ffa4 --- a/gdb/mi/mi-out.c +++ b/gdb/mi/mi-out.c @@@ -258,30 -258,6 +258,30 @@@ mi_ui_out::main_stream ( return (string_file *) m_streams.back (); } +void +mi_ui_out::do_progress_start () +{ + mi_progress_info info; + + info.state = progress_update::START; + m_progress_info.push_back (std::move (info)); +} + +/* Indicate that a task described by NAME is in progress. */ + +void +mi_ui_out::do_progress_notify (const std::string &msg, double howmuch) +{ + mi_progress_info &info (m_progress_info.back ()); + + if (info.state == progress_update::START) + { + struct ui_file *stream = gdb_stdout; - fprintf_unfiltered (stream, "%s\n", msg.c_str ()); ++ gdb_printf (stream, "%s\n", msg.c_str ()); + info.state = progress_update::WORKING; + } +} + /* Clear the buffer. */ void diff --cc gdb/ui-out.h index 175ff5fb156,9e6ff9a29bf..21e7a2bfbe7 --- a/gdb/ui-out.h +++ b/gdb/ui-out.h @@@ -280,38 -277,34 +277,45 @@@ class ui_ou escapes. */ virtual bool can_emit_style_escape () const = 0; - /* An object that starts and finishes a progress meter. */ - class progress_meter + /* An object that starts and finishes displaying progress updates. */ + class progress_update { public: + /* Represents the printing state of a progress update. */ + enum state + { + /* Printing will start with the next update. */ + START, + /* Printing has already started. */ + WORKING, + /* Progress bar printing has already started. */ + BAR, + /* Printing should not be done. */ + NO_PRINT + }; + /* SHOULD_PRINT indicates whether something should be printed for a tty. */ - progress_meter (struct ui_out *uiout, const std::string &name, - bool should_print) - : m_uiout (uiout) + progress_update () { - m_uiout->do_progress_start (name, should_print); + m_uiout = current_uiout; + m_uiout->do_progress_start (); } - ~progress_meter () + ~progress_update () { - m_uiout->do_progress_notify (1.0); - m_uiout->do_progress_end (); + } - progress_meter (const progress_meter &) = delete; - progress_meter &operator= (const progress_meter &) = delete; + progress_update (const progress_update &) = delete; + progress_update &operator= (const progress_update &) = delete; + /* Emit some progress for this progress meter. HOWMUCH may range + from 0.0 to 1.0. */ - void progress (double howmuch) ++ void progress (const std::string& msg, double howmuch) + { - m_uiout->do_progress_notify (howmuch); ++ m_uiout->do_progress_notify (msg, howmuch); + } + private: struct ui_out *m_uiout;