Blame SOURCES/gdb-rhbz202487-rework-set-debuginfod.patch

79b363
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
79b363
From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= <ahajkova@redhat.com>
79b363
Date: Tue, 11 Jan 2022 12:46:05 +0100
79b363
Subject: gdb-rhbz202487-rework-set-debuginfod.patch
79b363
79b363
;;Backport upstream commit from  Simon Marchi
79b363
;;333f35b6315 gdb: pass/return setting setter/getter
79b363
;;scalar values by value
79b363
79b363
gdb: rework "set debuginfod" commands
79b363
79b363
As discussed here [1], do some re-work in the "set debuginfod commands".
79b363
79b363
First, use "set debuginfod enabled on/off/ask" instead of "set
79b363
debuginfod on/off/ask".  This is more MI-friendly, and it gives an
79b363
output that makes more sense in "info set", for example.
79b363
79b363
Then, make the show commands not call "error" when debuginfod support is
79b363
not compiled in.  This makes the commands "show" and "show debuginfod"
79b363
stop early, breaking gdb.base/default.exp:
79b363
79b363
    Running /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.base/default.exp ...
79b363
    FAIL: gdb.base/default.exp: info set
79b363
    FAIL: gdb.base/default.exp: show
79b363
79b363
 - Make the "debuginfod enabled" setting default to "off" when debuginfod
79b363
   support is not compiled in, and "ask" otherwise.
79b363
 - Make the setter of "debuginfod enabled" error out when debuginfod
79b363
   support is not compiled in, so that "debuginfod enabled" will always
79b363
   remain "off" in that case.
79b363
 - Make the setter of "debuginfod verbose" work in any case.  I don't
79b363
   see the harm in letting the user change that setting, since the user will
79b363
   hit an error if they try to enable the use of debuginfod.
79b363
 - I would do the same for the "debuginfod urls" setter, but because
79b363
   this one needs to see the DEBUGINFOD_URLS_ENV_VAR macro, provided by
79b363
   libdebuginfod, I made that one error out as well if debuginfod
79b363
   support is not compiled it (otherwise, I would have left it like
79b363
   "debuginfod verbose".  Alternatively, we could hard-code
79b363
   "DEBUGINFOD_URLS" in the code (in fact, it was prior to this patch,
79b363
   but I think it was an oversight, as other spots use
79b363
   DEBUGINFOD_URLS_ENV_VAR), or use a dummy string to store the setting,
79b363
   but I don't really see the value in that.
79b363
79b363
Rename debuginfod_enable to debuginfod_enabled, just so it matches the
79b363
setting name.
79b363
79b363
[1] https://sourceware.org/pipermail/gdb-patches/2021-October/182937.html
79b363
79b363
Change-Id: I45fdb2993f668226a5639228951362b7800f09d5
79b363
Co-Authored-By: Aaron Merey <amerey@redhat.com>
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
@@ -32,8 +32,22 @@ static const char debuginfod_on[] = "on";
79b363
 static const char debuginfod_off[] = "off";
79b363
 static const char debuginfod_ask[] = "ask";
79b363
 
79b363
-static const char *debuginfod_enable = debuginfod_ask;
79b363
-static unsigned debuginfod_verbose = 1;
79b363
+static const char *debuginfod_enabled_enum[] =
79b363
+{
79b363
+  debuginfod_on,
79b363
+  debuginfod_off,
79b363
+  debuginfod_ask,
79b363
+  nullptr
79b363
+};
79b363
+
79b363
+static const char *debuginfod_enabled =
79b363
+#if defined(HAVE_LIBDEBUGINFOD)
79b363
+  debuginfod_ask;
79b363
+#else
79b363
+  debuginfod_off;
79b363
+#endif
79b363
+
79b363
+static unsigned int debuginfod_verbose = 1;
79b363
 
79b363
 /* This is never actually used.  URLs are always pulled from the
79b363
    environment.  */
79b363
@@ -60,64 +74,6 @@ debuginfod_debuginfo_query (const unsigned char *build_id,
79b363
 
79b363
 #define NO_IMPL _("Support for debuginfod is not compiled into GDB.")
79b363
 
79b363
-/* Stub set/show commands that indicate debuginfod is not supported.  */
79b363
-
79b363
-static void
79b363
-set_debuginfod_on_command (const char *args, int from_tty)
79b363
-{
79b363
-  error (NO_IMPL);
79b363
-  debuginfod_enable = debuginfod_off;
79b363
-}
79b363
-
79b363
-static void
79b363
-set_debuginfod_off_command (const char *args, int from_tty)
79b363
-{
79b363
-  error (NO_IMPL);
79b363
-  debuginfod_enable = debuginfod_off;
79b363
-}
79b363
-
79b363
-static void
79b363
-set_debuginfod_ask_command (const char *args, int from_tty)
79b363
-{
79b363
-  error (NO_IMPL);
79b363
-  debuginfod_enable = debuginfod_off;
79b363
-}
79b363
-
79b363
-static void
79b363
-show_debuginfod_status_command (const char *args, int from_tty)
79b363
-{
79b363
-  error (NO_IMPL);
79b363
-}
79b363
-
79b363
-static void
79b363
-set_debuginfod_urls_command (const char *ignore, int from_tty,
79b363
-                             struct cmd_list_element *c)
79b363
-{
79b363
-  error (NO_IMPL);
79b363
-}
79b363
-
79b363
-static void
79b363
-show_debuginfod_urls_command (struct ui_file *file, int from_tty,
79b363
-			      struct cmd_list_element *cmd, const char *value)
79b363
-{
79b363
-  error (NO_IMPL);
79b363
-}
79b363
-
79b363
-static void
79b363
-set_debuginfod_verbose_command (const char *args, int from_tty,
79b363
-				struct cmd_list_element *c)
79b363
-{
79b363
-  error (NO_IMPL);
79b363
-  debuginfod_verbose = 0;
79b363
-}
79b363
-
79b363
-static void
79b363
-show_debuginfod_verbose_command (struct ui_file *file, int from_tty,
79b363
-				 struct cmd_list_element *cmd,
79b363
-				 const char *value)
79b363
-{
79b363
-  error (NO_IMPL);
79b363
-}
79b363
 #else
79b363
 #include <elfutils/debuginfod.h>
79b363
 
79b363
@@ -145,82 +101,6 @@ struct debuginfod_client_deleter
79b363
 using debuginfod_client_up
79b363
   = std::unique_ptr<debuginfod_client, debuginfod_client_deleter>;
79b363
 
79b363
-/* Enable debuginfod.  */
79b363
-
79b363
-static void
79b363
-set_debuginfod_on_command (const char *args, int from_tty)
79b363
-{
79b363
-  debuginfod_enable = debuginfod_on;
79b363
-}
79b363
-
79b363
-/* Disable debuginfod.  */
79b363
-
79b363
-static void
79b363
-set_debuginfod_off_command (const char *args, int from_tty)
79b363
-{
79b363
-  debuginfod_enable = debuginfod_off;
79b363
-}
79b363
-
79b363
-/* Before next query, ask user whether to enable debuginfod.  */
79b363
-
79b363
-static void
79b363
-set_debuginfod_ask_command (const char *args, int from_tty)
79b363
-{
79b363
-  debuginfod_enable = debuginfod_ask;
79b363
-}
79b363
-
79b363
-/* Show whether debuginfod is enabled.  */
79b363
-
79b363
-static void
79b363
-show_debuginfod_status_command (const char *args, int from_tty)
79b363
-{
79b363
-  printf_unfiltered (_("Debuginfod functionality is currently set to " \
79b363
-		     "\"%s\".\n"), debuginfod_enable);
79b363
-}
79b363
-
79b363
-/* Set the URLs that debuginfod will query.  */
79b363
-
79b363
-static void
79b363
-set_debuginfod_urls_command (const char *ignore, int from_tty,
79b363
-                             struct cmd_list_element *c)
79b363
-{
79b363
-  gdb_assert (debuginfod_urls != nullptr);
79b363
-  if (setenv ("DEBUGINFOD_URLS", debuginfod_urls, 1) != 0)
79b363
-    warning (_("Unable to set debuginfod URLs: %s"), safe_strerror (errno));
79b363
-}
79b363
-
79b363
-/* Show the URLs that debuginfod will query.  */
79b363
-
79b363
-static void
79b363
-show_debuginfod_urls_command (struct ui_file *file, int from_tty,
79b363
-			      struct cmd_list_element *cmd, const char *value)
79b363
-{
79b363
-  if (value == nullptr || value[0] == '\0')
79b363
-    fprintf_unfiltered (file, _("Debuginfod URLs have not been set.\n"));
79b363
-  else
79b363
-    fprintf_filtered (file, _("Debuginfod URLs are currently set to:\n%s\n"),
79b363
-		      value);
79b363
-}
79b363
-
79b363
-/* No-op setter used for compatibility when gdb is built without debuginfod.  */
79b363
-
79b363
-static void
79b363
-set_debuginfod_verbose_command (const char *args, int from_tty,
79b363
-				struct cmd_list_element *c)
79b363
-{
79b363
-  return;
79b363
-}
79b363
-
79b363
-/* Show verbosity.  */
79b363
-
79b363
-static void
79b363
-show_debuginfod_verbose_command (struct ui_file *file, int from_tty,
79b363
-				 struct cmd_list_element *cmd, const char *value)
79b363
-{
79b363
-  fprintf_filtered (file, _("Debuginfod verbose output is set to %s.\n"),
79b363
-		    value);
79b363
-}
79b363
-
79b363
 static int
79b363
 progressfn (debuginfod_client *c, long cur, long total)
79b363
 {
79b363
@@ -277,15 +157,15 @@ get_debuginfod_client ()
79b363
    whether to enable debuginfod.  */
79b363
 
79b363
 static bool
79b363
-debuginfod_enabled ()
79b363
+debuginfod_is_enabled ()
79b363
 {
79b363
   const char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR);
79b363
 
79b363
   if (urls == nullptr || urls[0] == '\0'
79b363
-      || debuginfod_enable == debuginfod_off)
79b363
+      || debuginfod_enabled == debuginfod_off)
79b363
     return false;
79b363
 
79b363
-  if (debuginfod_enable == debuginfod_ask)
79b363
+  if (debuginfod_enabled == debuginfod_ask)
79b363
     {
79b363
       int resp = nquery (_("\nThis GDB supports auto-downloading debuginfo " \
79b363
 			   "from the following URLs:\n%s\nEnable debuginfod " \
79b363
@@ -294,16 +174,16 @@ debuginfod_enabled ()
79b363
       if (!resp)
79b363
 	{
79b363
 	  printf_filtered (_("Debuginfod has been disabled.\nTo make this " \
79b363
-			     "setting permanent, add \'set debuginfod off\' " \
79b363
-			     "to .gdbinit.\n"));
79b363
-	  debuginfod_enable = debuginfod_off;
79b363
+			     "setting permanent, add \'set debuginfod " \
79b363
+			     "enabled off\' to .gdbinit.\n"));
79b363
+	  debuginfod_enabled = debuginfod_off;
79b363
 	  return false;
79b363
 	}
79b363
 
79b363
       printf_filtered (_("Debuginfod has been enabled.\nTo make this " \
79b363
-			 "setting permanent, add \'set debuginfod on\' " \
79b363
-			 "to .gdbinit.\n"));
79b363
-      debuginfod_enable = debuginfod_on;
79b363
+			 "setting permanent, add \'set debuginfod enabled " \
79b363
+			 "on\' to .gdbinit.\n"));
79b363
+      debuginfod_enabled = debuginfod_on;
79b363
     }
79b363
 
79b363
   return true;
79b363
@@ -317,7 +197,7 @@ debuginfod_source_query (const unsigned char *build_id,
79b363
 			 const char *srcpath,
79b363
 			 gdb::unique_xmalloc_ptr<char> *destname)
79b363
 {
79b363
-  if (!debuginfod_enabled ())
79b363
+  if (!debuginfod_is_enabled ())
79b363
     return scoped_fd (-ENOSYS);
79b363
 
79b363
   debuginfod_client *c = get_debuginfod_client ();
79b363
@@ -354,7 +234,7 @@ debuginfod_debuginfo_query (const unsigned char *build_id,
79b363
 			    const char *filename,
79b363
 			    gdb::unique_xmalloc_ptr<char> *destname)
79b363
 {
79b363
-  if (!debuginfod_enabled ())
79b363
+  if (!debuginfod_is_enabled ())
79b363
     return scoped_fd (-ENOSYS);
79b363
 
79b363
   debuginfod_client *c = get_debuginfod_client ();
79b363
@@ -382,6 +262,67 @@ debuginfod_debuginfo_query (const unsigned char *build_id,
79b363
 }
79b363
 #endif
79b363
 
79b363
+/* Set callback for "set debuginfod enabled".  */
79b363
+
79b363
+static void
79b363
+set_debuginfod_enabled (const char *args, int from_tty,
79b363
+                        struct cmd_list_element *c)
79b363
+{
79b363
+#if defined(HAVE_LIBDEBUGINFOD)
79b363
+  /* Value is already set.  */
79b363
+#else
79b363
+  error (NO_IMPL);
79b363
+#endif
79b363
+}
79b363
+
79b363
+/* Show callback for "set debuginfod enabled".  */
79b363
+
79b363
+static void
79b363
+show_debuginfod_enabled (ui_file *file, int from_tty, cmd_list_element *cmd,
79b363
+			 const char *value)
79b363
+{
79b363
+  printf_unfiltered (_("Debuginfod functionality is currently set to "
79b363
+		       "\"%s\".\n"), debuginfod_enabled);
79b363
+}
79b363
+
79b363
+/* Set callback for "set debuginfod urls".  */
79b363
+
79b363
+static void
79b363
+set_debuginfod_urls (const char *args, int from_tty,
79b363
+                     struct cmd_list_element *c)
79b363
+{
79b363
+#if defined(HAVE_LIBDEBUGINFOD)
79b363
+  gdb_assert (debuginfod_urls != nullptr);
79b363
+  if (setenv (DEBUGINFOD_URLS_ENV_VAR, debuginfod_urls, 1) != 0)
79b363
+    warning (_("Unable to set debuginfod URLs: %s"), safe_strerror (errno));
79b363
+#else
79b363
+  error (NO_IMPL);
79b363
+#endif
79b363
+}
79b363
+
79b363
+/* Show callback for "set debuginfod urls".  */
79b363
+
79b363
+static void
79b363
+show_debuginfod_urls (ui_file *file, int from_tty, cmd_list_element *cmd,
79b363
+		      const char *value)
79b363
+{
79b363
+  if (value[0] == '\0')
79b363
+    fprintf_unfiltered (file, _("Debuginfod URLs have not been set.\n"));
79b363
+  else
79b363
+    fprintf_filtered (file, _("Debuginfod URLs are currently set to:\n%s\n"),
79b363
+		      value);
79b363
+}
79b363
+
79b363
+/* Show callback for "set debuginfod verbose".  */
79b363
+
79b363
+static void
79b363
+show_debuginfod_verbose_command (ui_file *file, int from_tty,
79b363
+				 cmd_list_element *cmd, const char *value)
79b363
+{
79b363
+  fprintf_filtered (file, _("Debuginfod verbose output is set to %s.\n"),
79b363
+		    value);
79b363
+}
79b363
+
79b363
 /* Register debuginfod commands.  */
79b363
 
79b363
 void _initialize_debuginfod ();
79b363
@@ -397,23 +338,17 @@ _initialize_debuginfod ()
79b363
                        _("Show debuginfod option."),
79b363
                        &show_debuginfod_prefix_list, 0, &showlist);
79b363
 
79b363
-  /* set debuginfod on */
79b363
-  add_cmd ("on", class_run, set_debuginfod_on_command,
79b363
-	   _("Enable debuginfod."), &set_debuginfod_prefix_list);
79b363
-
79b363
-  /* set debuginfod off */
79b363
-  add_cmd ("off", class_run, set_debuginfod_off_command,
79b363
-	   _("Disable debuginfod."), &set_debuginfod_prefix_list);
79b363
-
79b363
-  /* set debuginfod ask */
79b363
-  add_cmd ("ask", class_run, set_debuginfod_ask_command, _("\
79b363
-Ask the user whether to enable debuginfod before performing the next query."),
79b363
-	   &set_debuginfod_prefix_list);
79b363
-
79b363
-  /* show debuginfod status */
79b363
-  add_cmd ("status", class_run, show_debuginfod_status_command,
79b363
-	   _("Show whether debuginfod is set to \"on\", \"off\" or \"ask\"."),
79b363
-	   &show_debuginfod_prefix_list);
79b363
+  add_setshow_enum_cmd ("enabled", class_run, debuginfod_enabled_enum,
79b363
+                        &debuginfod_enabled,
79b363
+			_("Set whether to use debuginfod."),
79b363
+			_("Show whether to use debuginfod."),
79b363
+			_("\
79b363
+When on, enable the use of debuginfod to download missing debug info and\n\
79b363
+source files."),
79b363
+			set_debuginfod_enabled,
79b363
+			show_debuginfod_enabled,
79b363
+			&set_debuginfod_prefix_list,
79b363
+			&show_debuginfod_prefix_list);
79b363
 
79b363
   /* set/show debuginfod urls */
79b363
   add_setshow_string_noescape_cmd ("urls", class_run, &debuginfod_urls, _("\
79b363
@@ -422,8 +357,8 @@ Show the list of debuginfod server URLs."), _("\
79b363
 Manage the space-separated list of debuginfod server URLs that GDB will query \
79b363
 when missing debuginfo, executables or source files.\nThe default value is \
79b363
 copied from the DEBUGINFOD_URLS environment variable."),
79b363
-				   set_debuginfod_urls_command,
79b363
-				   show_debuginfod_urls_command,
79b363
+				   set_debuginfod_urls,
79b363
+				   show_debuginfod_urls,
79b363
 				   &set_debuginfod_prefix_list,
79b363
 				   &show_debuginfod_prefix_list);
79b363
   if (getenv ("DEBUGINFOD_URLS") != nullptr)
79b363
@@ -436,7 +371,7 @@ Set verbosity of debuginfod output."), _("\
79b363
 Show debuginfod debugging."), _("\
79b363
 When set to a non-zero value, display verbose output for each debuginfod \
79b363
 query.\nTo disable, set to zero.  Verbose output is displayed by default."),
79b363
-			     set_debuginfod_verbose_command,
79b363
+			     nullptr,
79b363
 			     show_debuginfod_verbose_command,
79b363
 			     &set_debuginfod_prefix_list,
79b363
 			     &show_debuginfod_prefix_list);
79b363
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
79b363
--- a/gdb/doc/gdb.texinfo
79b363
+++ b/gdb/doc/gdb.texinfo
79b363
@@ -47046,27 +47046,28 @@ regarding @code{debuginfod}.
79b363
 @value{GDBN} provides the following commands for configuring @code{debuginfod}.
79b363
 
79b363
 @table @code
79b363
-@kindex set debuginfod
79b363
-@anchor{set debuginfod}
79b363
-@item set debuginfod
79b363
-@itemx set debuginfod on
79b363
+@kindex set debuginfod enabled
79b363
+@anchor{set debuginfod enabled}
79b363
+@item set debuginfod enabled
79b363
+@itemx set debuginfod enabled on
79b363
 @cindex enable debuginfod
79b363
 @value{GDBN} will attempt to query @code{debuginfod} servers when missing debug
79b363
 info or source files.
79b363
 
79b363
-@item set debuginfod off
79b363
+@item set debuginfod enabled off
79b363
 @value{GDBN} will not attempt to query @code{debuginfod} servers when missing
79b363
-debug info or source files.  By default, @code{debuginfod} is set to @code{off}
79b363
-for non-interactive sessions.
79b363
+debug info or source files.  By default, @code{debuginfod enabled} is set to
79b363
+@code{off} for non-interactive sessions.
79b363
 
79b363
-@item set debuginfod ask
79b363
+@item set debuginfod enabled ask
79b363
 @value{GDBN} will prompt the user to enable or disable @code{debuginfod} before
79b363
-attempting to perform the next query.  By default, @code{debuginfod} is set to
79b363
-@code{ask} for interactive sessions.
79b363
+attempting to perform the next query.  By default, @code{debuginfod enabled}
79b363
+is set to @code{ask} for interactive sessions.
79b363
 
79b363
-@kindex show debuginfod status
79b363
-@item show debuginfod status
79b363
-Show whether @code{debuginfod} is set to @code{on}, @code{off} or @code{ask}.
79b363
+@kindex show debuginfod enabled
79b363
+@item show debuginfod enabled
79b363
+Display whether @code{debuginfod enabled} is set to @code{on}, @code{off} or
79b363
+@code{ask}.
79b363
 
79b363
 @kindex set debuginfod urls
79b363
 @cindex configure debuginfod URLs
79b363
diff --git a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp
79b363
--- a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp
79b363
+++ b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp
79b363
@@ -236,7 +236,7 @@ proc local_url { } {
79b363
     clean_restart
79b363
     gdb_test "file $binfile" ".*No debugging symbols.*" \
79b363
 	"file [file tail $binfile] cmd"
79b363
-    gdb_test_no_output "set debuginfod off"
79b363
+    gdb_test_no_output "set debuginfod enabled off"
79b363
     gdb_test_no_output "set debuginfod urls http://127.0.0.1:$port"
79b363
 
79b363
     # gdb shouldn't find the debuginfo since debuginfod has been disabled
79b363
@@ -244,7 +244,7 @@ proc local_url { } {
79b363
 	"file [file tail $binfile] cmd off"
79b363
 
79b363
     # Enable debuginfod and fetch the debuginfo
79b363
-    gdb_test_no_output "set debuginfod on"
79b363
+    gdb_test_no_output "set debuginfod enabled on"
79b363
     gdb_test "file $binfile" ".*Reading symbols from.*debuginfo.*" \
79b363
 	"file [file tail $binfile] cmd on"
79b363
 }