Blame SOURCES/gdb-rhbz2068280-debuginfod-unavailable-size.patch

79b363
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
79b363
From: Kevin Buettner <kevinb@redhat.com>
79b363
Date: Wed, 30 Mar 2022 13:28:26 -0700
79b363
Subject: gdb-rhbz2068280-debuginfod-unavailable-size.patch
79b363
79b363
;; Backport upstream patch from Aaron Merey which suppresses debuginfod
79b363
;; progress messages when size is zero.  (RH BZ 2068280).
79b363
79b363
Remove download size from debuginfod progress messages if unavailable
79b363
79b363
Currently debuginfod progress update messages include the size of
79b363
each download:
79b363
79b363
  Downloading 7.5 MB separate debug info for /lib/libxyz.so.0
79b363
79b363
This value originates from the Content-Length HTTP header of the
79b363
transfer.  However this header is not guaranteed to be present for
79b363
each download.  This can happen when debuginfod servers compress files
79b363
on-the-fly at the time of transfer.  In this case gdb wrongly prints
79b363
"-0.00 MB" as the size.
79b363
79b363
This patch removes download sizes from progress messages when they are
79b363
not available.  It also removes usage of the progress bar until
79b363
a more thorough reworking of progress updating is implemented. [1]
79b363
79b363
[1] https://sourceware.org/pipermail/gdb-patches/2022-February/185798.html
79b363
79b363
diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
79b363
--- a/gdb/debuginfod-support.c
79b363
+++ b/gdb/debuginfod-support.c
79b363
@@ -81,12 +81,12 @@ debuginfod_debuginfo_query (const unsigned char *build_id,
79b363
 struct user_data
79b363
 {
79b363
   user_data (const char *desc, const char *fname)
79b363
-    : desc (desc), fname (fname)
79b363
+    : desc (desc), fname (fname), has_printed (false)
79b363
   { }
79b363
 
79b363
   const char * const desc;
79b363
   const char * const fname;
79b363
-  gdb::optional<ui_out::progress_meter> meter;
79b363
+  bool has_printed;
79b363
 };
79b363
 
79b363
 /* Deleter for a debuginfod_client.  */
79b363
@@ -116,24 +116,32 @@ progressfn (debuginfod_client *c, long cur, long total)
79b363
       return 1;
79b363
     }
79b363
 
79b363
-  if (total == 0)
79b363
-    return 0;
79b363
-
79b363
-  if (!data->meter.has_value ())
79b363
+  if (!data->has_printed)
79b363
     {
79b363
-      float size_in_mb = 1.0f * total / (1024 * 1024);
79b363
-      string_file styled_filename (current_uiout->can_emit_style_escape ());
79b363
-      fprintf_styled (&styled_filename,
79b363
-		      file_name_style.style (),
79b363
-		      "%s",
79b363
-		      data->fname);
79b363
-      std::string message
79b363
-	= string_printf ("Downloading %.2f MB %s %s", size_in_mb, data->desc,
79b363
-			 styled_filename.c_str());
79b363
-      data->meter.emplace (current_uiout, message, 1);
79b363
-    }
79b363
+      /* Include the transfer size, if available.  */
79b363
+      if (total > 0)
79b363
+	{
79b363
+	  float size = 1.0f * total / 1024;
79b363
+	  const char *unit = "KB";
79b363
+
79b363
+	  /* If size is greater than 0.01 MB, set unit to MB.  */
79b363
+	  if (size > 10.24)
79b363
+	    {
79b363
+	      size /= 1024;
79b363
+	      unit = "MB";
79b363
+	    }
79b363
+
79b363
+	  printf_filtered ("Downloading %.2f %s %s %ps...\n",
79b363
+			   size, unit, data->desc,
79b363
+			   styled_string (file_name_style.style (),
79b363
+					  data->fname));
79b363
+	}
79b363
+      else
79b363
+	printf_filtered ("Downloading %s %ps...\n", data->desc,
79b363
+			 styled_string (file_name_style.style (), data->fname));
79b363
 
79b363
-  current_uiout->progress ((double)cur / (double)total);
79b363
+      data->has_printed = true;
79b363
+    }
79b363
 
79b363
   return 0;
79b363
 }