]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Remove download size from debuginfod progress messages if unavailable
authorAaron Merey <amerey@redhat.com>
Wed, 23 Mar 2022 00:01:54 +0000 (20:01 -0400)
committerAaron Merey <amerey@redhat.com>
Thu, 24 Mar 2022 18:51:22 +0000 (14:51 -0400)
Currently debuginfod progress update messages include the size of
each download:

  Downloading 7.5 MB separate debug info for /lib/libxyz.so.0

This value originates from the Content-Length HTTP header of the
transfer.  However this header is not guaranteed to be present for
each download.  This can happen when debuginfod servers compress files
on-the-fly at the time of transfer.  In this case gdb wrongly prints
"-0.00 MB" as the size.

This patch removes download sizes from progress messages when they are
not available.  It also removes usage of the progress bar until
a more thorough reworking of progress updating is implemented. [1]

[1] https://sourceware.org/pipermail/gdb-patches/2022-February/185798.html

gdb/debuginfod-support.c

index 3614ff23882042d21995acaa28d104c598caa2ae..d5d023ff7bba45d822c2a2ddd80828dace2fc0f0 100644 (file)
@@ -86,12 +86,12 @@ debuginfod_exec_query (const unsigned char *build_id,
 struct user_data
 {
   user_data (const char *desc, const char *fname)
-    : desc (desc), fname (fname)
+    : desc (desc), fname (fname), has_printed (false)
   { }
 
   const char * const desc;
   const char * const fname;
-  gdb::optional<ui_out::progress_meter> meter;
+  bool has_printed;
 };
 
 /* Deleter for a debuginfod_client.  */
@@ -121,24 +121,32 @@ progressfn (debuginfod_client *c, long cur, long total)
       return 1;
     }
 
-  if (total == 0)
-    return 0;
-
-  if (!data->meter.has_value ())
+  if (!data->has_printed)
     {
-      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);
-    }
+      /* Include the transfer size, if available.  */
+      if (total > 0)
+       {
+         float size = 1.0f * total / 1024;
+         const char *unit = "KB";
+
+         /* If size is greater than 0.01 MB, set unit to MB.  */
+         if (size > 10.24)
+           {
+             size /= 1024;
+             unit = "MB";
+           }
+
+         printf_filtered ("Downloading %.2f %s %s %ps...\n",
+                          size, unit, data->desc,
+                          styled_string (file_name_style.style (),
+                                         data->fname));
+       }
+      else
+       printf_filtered ("Downloading %s %ps...\n", data->desc,
+                        styled_string (file_name_style.style (), data->fname));
 
-  data->meter->progress ((double)cur / (double)total);
+      data->has_printed = true;
+    }
 
   return 0;
 }