public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 1/5] gdb: cleanup command creation in infcmd.c
Date: Tue,  4 Apr 2023 13:45:27 +0100	[thread overview]
Message-ID: <92f0e49903b9824179feb87b0060ab4a1b4beb96.1680608960.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1680608960.git.aburgess@redhat.com>

In infcmd.c, in order to add command completion to some of the 'set'
commands, we are currently creating the command, then looking up the
command by calling lookup_cmd.

This is no longer necessary, we already return the relevant
cmd_list_element object when the set/show command is created, and we
can use that to set the command completion callback.

I don't know if there's actually any tests for completion of these
commands, but I manually checked, and each command still appears to
offer the expected filename completion.

There should be no user visible changes after this commit.
---
 gdb/infcmd.c | 59 +++++++++++++++++++++++-----------------------------
 1 file changed, 26 insertions(+), 33 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index a68611538f2..dd5808b17e7 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -3138,55 +3138,48 @@ _initialize_infcmd ()
 {
   static struct cmd_list_element *info_proc_cmdlist;
   struct cmd_list_element *c = nullptr;
-  const char *cmd_name;
 
   /* Add the filename of the terminal connected to inferior I/O.  */
-  add_setshow_optional_filename_cmd ("inferior-tty", class_run,
-				     &inferior_io_terminal_scratch, _("\
-Set terminal for future runs of program being debugged."), _("\
+  auto tty_set_show =
+    add_setshow_optional_filename_cmd ("inferior-tty", class_run,
+				       &inferior_io_terminal_scratch, _("\
+Set terminal for future runs of program being debugged."), _("		\
 Show terminal for future runs of program being debugged."), _("\
 Usage: set inferior-tty [TTY]\n\n\
 If TTY is omitted, the default behavior of using the same terminal as GDB\n\
 is restored."),
-				     set_inferior_tty_command,
-				     show_inferior_tty_command,
-				     &setlist, &showlist);
-  cmd_name = "inferior-tty";
-  c = lookup_cmd (&cmd_name, setlist, "", nullptr, -1, 1);
-  gdb_assert (c != nullptr);
-  add_alias_cmd ("tty", c, class_run, 0, &cmdlist);
-
-  cmd_name = "args";
-  add_setshow_string_noescape_cmd (cmd_name, class_run,
-				   &inferior_args_scratch, _("\
+				       set_inferior_tty_command,
+				       show_inferior_tty_command,
+				       &setlist, &showlist);
+  add_alias_cmd ("tty", tty_set_show.set, class_run, 0, &cmdlist);
+
+  auto args_set_show
+    = add_setshow_string_noescape_cmd ("args", class_run,
+				       &inferior_args_scratch, _("\
 Set argument list to give program being debugged when it is started."), _("\
 Show argument list to give program being debugged when it is started."), _("\
 Follow this command with any number of args, to be passed to the program."),
-				   set_args_command,
-				   show_args_command,
-				   &setlist, &showlist);
-  c = lookup_cmd (&cmd_name, setlist, "", nullptr, -1, 1);
-  gdb_assert (c != nullptr);
-  set_cmd_completer (c, filename_completer);
-
-  cmd_name = "cwd";
-  add_setshow_string_noescape_cmd (cmd_name, class_run,
-				   &inferior_cwd_scratch, _("\
+				       set_args_command,
+				       show_args_command,
+				       &setlist, &showlist);
+  set_cmd_completer (args_set_show.set, filename_completer);
+
+  auto cwd_set_show =
+    add_setshow_string_noescape_cmd ("cwd", class_run,
+				     &inferior_cwd_scratch, _("\
 Set the current working directory to be used when the inferior is started.\n\
 Changing this setting does not have any effect on inferiors that are\n\
 already running."),
-				   _("\
+				     _("\
 Show the current working directory that is used when the inferior is started."),
-				   _("\
+				     _("\
 Use this command to change the current working directory that will be used\n\
 when the inferior is started.  This setting does not affect GDB's current\n\
 working directory."),
-				   set_cwd_command,
-				   show_cwd_command,
-				   &setlist, &showlist);
-  c = lookup_cmd (&cmd_name, setlist, "", nullptr, -1, 1);
-  gdb_assert (c != nullptr);
-  set_cmd_completer (c, filename_completer);
+				     set_cwd_command,
+				     show_cwd_command,
+				     &setlist, &showlist);
+  set_cmd_completer (cwd_set_show.set, filename_completer);
 
   c = add_cmd ("environment", no_class, environment_info, _("\
 The environment to give the program, or one variable's value.\n\
-- 
2.25.4


  reply	other threads:[~2023-04-04 12:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-04 12:45 [PATCH 0/5] Fixes for per-inferior settings and $_gdb_setting_str() Andrew Burgess
2023-04-04 12:45 ` Andrew Burgess [this message]
2023-04-17 16:27   ` [PATCH 1/5] gdb: cleanup command creation in infcmd.c Tom Tromey
2023-04-04 12:45 ` [PATCH 2/5] gdb: make set/show args work with $_gdb_setting_str Andrew Burgess
2023-04-17 16:37   ` Tom Tromey
2023-04-17 18:04     ` Simon Marchi
2023-04-04 12:45 ` [PATCH 3/5] gdb: make set/show cwd " Andrew Burgess
2023-04-04 12:45 ` [PATCH 4/5] gdb: make set/show inferior-tty " Andrew Burgess
2023-04-04 12:45 ` [PATCH 5/5] gdb: make deprecated_show_value_hack static Andrew Burgess
2023-04-17 16:41   ` Tom Tromey
2023-04-28 14:57     ` Andrew Burgess
2023-07-10 17:25       ` Tom Tromey
2023-04-17 16:42 ` [PATCH 0/5] Fixes for per-inferior settings and $_gdb_setting_str() Tom Tromey
2023-04-17 18:09 ` Simon Marchi
2023-04-17 18:21   ` Simon Marchi
2023-04-28 21:53     ` Andrew Burgess
2023-04-28 16:43   ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=92f0e49903b9824179feb87b0060ab4a1b4beb96.1680608960.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).