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

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