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

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