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

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