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

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