[binutils-gdb] [gdb] Print progress for debuginfod
Tom de Vries
vries@sourceware.org
Wed Dec 16 17:18:54 GMT 2020
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d6f26c9d2852286c0ff8053a1b6e688ae1ba0793
commit d6f26c9d2852286c0ff8053a1b6e688ae1ba0793
Author: Martin Liska <mliska@suse.cz>
Date: Wed Dec 16 18:18:40 2020 +0100
[gdb] Print progress for debuginfod
Prints progress like:
Downloading 4.89 MB separate debug info for /usr/lib64/libgcrypt.so.20.
Downloading 1.10 MB separate debug info for /usr/lib64/liblzma.so.5.
Downloading 1.31 MB separate debug info for /usr/lib64/liblz4.so.1.
Downloading 0.96 MB separate debug info for /usr/lib64/libsmime3.so.
[### ]
Tested on x86_64-linux.
ChangeLog:
2020-12-16 Martin Liska <mliska@suse.cz>
Tom de Vries <tdevries@suse.de>
* gdb/debuginfod-support.c (struct user_data): Remove has_printed
field. Add meter field.
(progressfn): Print progress using meter.
Diff:
---
ChangeLog | 7 +++++++
gdb/cli-out.c | 4 ++--
gdb/debuginfod-support.c | 27 +++++++++++++++++++--------
3 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 715ae893807..4629d15a305 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-12-16 Martin Liska <mliska@suse.cz>
+ Tom de Vries <tdevries@suse.de>
+
+ * gdb/debuginfod-support.c (struct user_data): Remove has_printed
+ field. Add meter field.
+ (progressfn): Print progress using meter.
+
2020-12-02 Enze Li <lienze2010@hotmail.com>
* .gitignore: Add gnu global outputs.
diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index 7722ecc4fec..b342be48cfe 100644
--- a/gdb/cli-out.c
+++ b/gdb/cli-out.c
@@ -272,7 +272,7 @@ cli_ui_out::do_redirect (ui_file *outstream)
- printed for tty, SHOULD_PRINT == false:
<>
- printed for not-a-tty:
- <NAME...done.
+ <NAME...
>
*/
@@ -348,7 +348,7 @@ cli_ui_out::do_progress_end ()
if (!stream->isatty ())
{
- fprintf_unfiltered (stream, "done.\n");
+ fprintf_unfiltered (stream, "\n");
gdb_flush (stream);
}
else if (meter.printing == PROGRESS)
diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
index e21b2f40cae..e9b2dcd5bed 100644
--- a/gdb/debuginfod-support.c
+++ b/gdb/debuginfod-support.c
@@ -21,6 +21,7 @@
#include "cli/cli-style.h"
#include "gdbsupport/scoped_fd.h"
#include "debuginfod-support.h"
+#include "gdbsupport/gdb_optional.h"
#ifndef HAVE_LIBDEBUGINFOD
scoped_fd
@@ -46,12 +47,12 @@ debuginfod_debuginfo_query (const unsigned char *build_id,
struct user_data
{
user_data (const char *desc, const char *fname)
- : desc (desc), fname (fname), has_printed (false)
+ : desc (desc), fname (fname)
{ }
const char * const desc;
const char * const fname;
- bool has_printed;
+ gdb::optional<ui_out::progress_meter> meter;
};
/* Deleter for a debuginfod_client. */
@@ -80,15 +81,25 @@ progressfn (debuginfod_client *c, long cur, long total)
return 1;
}
- if (!data->has_printed && total != 0)
+ if (total == 0)
+ return 0;
+
+ if (!data->meter.has_value ())
{
- /* Print this message only once. */
- data->has_printed = true;
- printf_filtered ("Downloading %s %ps...\n",
- data->desc,
- styled_string (file_name_style.style (), data->fname));
+ float size_in_mb = 1.0f * total / (1024 * 1024);
+ string_file styled_filename (current_uiout->can_emit_style_escape ());
+ fprintf_styled (&styled_filename,
+ file_name_style.style (),
+ "%s",
+ data->fname);
+ std::string message
+ = string_printf ("Downloading %.2f MB %s %s", size_in_mb, data->desc,
+ styled_filename.c_str());
+ data->meter.emplace (current_uiout, message, 1);
}
+ current_uiout->progress ((double)cur / (double)total);
+
return 0;
}
More information about the Binutils-cvs
mailing list