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

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