+
+/* Set callback for "set debuginfod enabled". */
+
+static void
+set_debuginfod_enabled (const char *value)
+{
+#if defined(HAVE_LIBDEBUGINFOD)
+ debuginfod_enabled = value;
+#else
+ /* Disabling debuginfod when gdb is not built with it is a no-op. */
+ if (value != debuginfod_off)
+ error (NO_IMPL);
+#endif
+}
+
+/* Get callback for "set debuginfod enabled". */
+
+static const char *
+get_debuginfod_enabled ()
+{
+ return debuginfod_enabled;
+}
+
+/* Show callback for "set debuginfod enabled". */
+
+static void
+show_debuginfod_enabled (ui_file *file, int from_tty, cmd_list_element *cmd,
+ const char *value)
+{
+ gdb_printf (file,
+ _("Debuginfod functionality is currently set to "
+ "\"%s\".\n"), debuginfod_enabled);
+}
+
+/* Set callback for "set debuginfod urls". */
+
+static void
+set_debuginfod_urls (const std::string &urls)
+{
+#if defined(HAVE_LIBDEBUGINFOD)
+ if (setenv (DEBUGINFOD_URLS_ENV_VAR, urls.c_str (), 1) != 0)
+ warning (_("Unable to set debuginfod URLs: %s"), safe_strerror (errno));
+#else
+ error (NO_IMPL);
+#endif
+}
+
+/* Get callback for "set debuginfod urls". */
+
+static const std::string&
+get_debuginfod_urls ()
+{
+ static std::string urls;
+#if defined(HAVE_LIBDEBUGINFOD)
+ const char *envvar = getenv (DEBUGINFOD_URLS_ENV_VAR);
+
+ if (envvar != nullptr)
+ urls = envvar;
+ else
+ urls.clear ();
+#endif
+
+ return urls;
+}
+
+/* Show callback for "set debuginfod urls". */
+
+static void
+show_debuginfod_urls (ui_file *file, int from_tty, cmd_list_element *cmd,
+ const char *value)
+{
+ if (value[0] == '\0')
+ gdb_printf (file, _("Debuginfod URLs have not been set.\n"));
+ else
+ gdb_printf (file, _("Debuginfod URLs are currently set to:\n%s\n"),
+ value);
+}
+
+/* Show callback for "set debuginfod verbose". */
+
+static void
+show_debuginfod_verbose_command (ui_file *file, int from_tty,
+ cmd_list_element *cmd, const char *value)
+{
+ gdb_printf (file, _("Debuginfod verbose output is set to %s.\n"),
+ value);
+}
+
+/* Register debuginfod commands. */
+
+void _initialize_debuginfod ();
+void
+_initialize_debuginfod ()
+{
+ /* set/show debuginfod */
+ add_setshow_prefix_cmd ("debuginfod", class_run,
+ _("Set debuginfod options."),
+ _("Show debuginfod options."),
+ &set_debuginfod_prefix_list,
+ &show_debuginfod_prefix_list,
+ &setlist, &showlist);
+
+ add_setshow_enum_cmd ("enabled", class_run, debuginfod_enabled_enum,
+ _("Set whether to use debuginfod."),
+ _("Show whether to use debuginfod."),
+ _("\
+When on, enable the use of debuginfod to download missing debug info and\n\
+source files."),
+ set_debuginfod_enabled,
+ get_debuginfod_enabled,
+ show_debuginfod_enabled,
+ &set_debuginfod_prefix_list,
+ &show_debuginfod_prefix_list);
+
+ /* set/show debuginfod urls */
+ add_setshow_string_noescape_cmd ("urls", class_run, _("\
+Set the list of debuginfod server URLs."), _("\
+Show the list of debuginfod server URLs."), _("\
+Manage the space-separated list of debuginfod server URLs that GDB will query \
+when missing debuginfo, executables or source files.\nThe default value is \
+copied from the DEBUGINFOD_URLS environment variable."),
+ set_debuginfod_urls,
+ get_debuginfod_urls,
+ show_debuginfod_urls,
+ &set_debuginfod_prefix_list,
+ &show_debuginfod_prefix_list);
+
+ /* set/show debuginfod verbose */
+ add_setshow_zuinteger_cmd ("verbose", class_support,
+ &debuginfod_verbose, _("\
+Set verbosity of debuginfod output."), _("\
+Show debuginfod debugging."), _("\
+When set to a non-zero value, display verbose output for each debuginfod \
+query.\nTo disable, set to zero. Verbose output is displayed by default."),
+ nullptr,
+ show_debuginfod_verbose_command,
+ &set_debuginfod_prefix_list,
+ &show_debuginfod_prefix_list);
+}