From 5a9a34d769abd73a5b68f0895488c94c1c883739 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Darche?= Date: Mon, 29 Sep 2025 09:47:59 -0400 Subject: [PATCH] gdb: use getter/setter command styles for "set tdesc filename" 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 Change-Id: I2a87c65c9931ec91d15f854b32ac8279fe7077be Approved-By: Andrew Burgess --- gdb/target-descriptions.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index dc5fbacfebd..5a5d03ec5d8 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -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 = ¤t_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 = ¤t_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); -- 2.47.3