]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: use getter/setter command styles for "set tdesc filename"
authorSébastien Darche <sdarche@efficios.com>
Mon, 29 Sep 2025 13:47:59 +0000 (09:47 -0400)
committerSébastien Darche <sdarche@efficios.com>
Wed, 8 Oct 2025 20:00:33 +0000 (16:00 -0400)
The target description filename command pair ("(set|get) tdesc
filename") uses a rather indirect way to set the variable for the
inferior, using a scratch variable to pass the value. While most other
inferior-specific parameters were updated to the more direct
getter/setter style functions, I believe this parameter was an
oversight.

This patch removes the intermediate string and directly accesses the
tdesc filename for the current inferior.

Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I2a87c65c9931ec91d15f854b32ac8279fe7077be
Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/target-descriptions.c

index dc5fbacfebd11a4a653cce9037e0f524552a74db..5a5d03ec5d86e6ed723e98e227a872ef3ab94cc6 100644 (file)
@@ -453,10 +453,6 @@ get_arch_data (struct gdbarch *gdbarch)
   return result;
 }
 
-/* The string manipulated by the "set tdesc filename ..." command.  */
-
-static std::string tdesc_filename_cmd_string;
-
 /* Fetch the current target's description, and switch the current
    architecture to one which incorporates that description.  */
 
@@ -1208,27 +1204,34 @@ set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi)
 static struct cmd_list_element *tdesc_set_cmdlist, *tdesc_show_cmdlist;
 static struct cmd_list_element *tdesc_unset_cmdlist;
 
-/* Helper functions for the CLI commands.  */
+/* Setter for the "tdesc filename" setting.  */
 
 static void
-set_tdesc_filename_cmd (const char *args, int from_tty,
-                       struct cmd_list_element *c)
+set_tdesc_filename (const std::string &value)
 {
   target_desc_info *tdesc_info = &current_inferior ()->tdesc_info;
 
-  tdesc_info->filename = tdesc_filename_cmd_string;
+  tdesc_info->filename = value;
 
   target_clear_description ();
   target_find_description ();
 }
 
+/* Getter for the "tdesc filename" setting.  */
+
+static const std::string &
+get_tdesc_filename ()
+{
+  target_desc_info *tdesc_info = &current_inferior ()->tdesc_info;
+
+  return tdesc_info->filename;
+}
+
 static void
 show_tdesc_filename_cmd (struct ui_file *file, int from_tty,
                         struct cmd_list_element *c,
                         const char *value)
 {
-  value = current_inferior ()->tdesc_info.filename.data ();
-
   if (value != NULL && *value != '\0')
     gdb_printf (file,
                _("The target description will be read from \"%ps\".\n"),
@@ -1896,13 +1899,13 @@ Unset target description specific variables."),
                        0 /* allow-unknown */, &unsetlist);
 
   add_setshow_filename_cmd ("filename", class_obscure,
-                           &tdesc_filename_cmd_string,
                            _("\
 Set the file to read for an XML target description."), _("\
 Show the file to read for an XML target description."), _("\
 When set, GDB will read the target description from a local\n\
 file instead of querying the remote target."),
-                           set_tdesc_filename_cmd,
+                           set_tdesc_filename,
+                           get_tdesc_filename,
                            show_tdesc_filename_cmd,
                            &tdesc_set_cmdlist, &tdesc_show_cmdlist);