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

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