Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] RFC: gdb: redo whitespace-stripping from commands
@ 2025-05-29 12:51 Kartik K. Agaram
  2025-05-29 13:36 ` Tom Tromey
  2025-06-01  1:17 ` Kartik K. Agaram
  0 siblings, 2 replies; 14+ messages in thread
From: Kartik K. Agaram @ 2025-05-29 12:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: guinevere, Kartik K. Agaram

Before this patch, trailing whitespace was not stripped:
  - from 'set'/'show' commands
  - from 'complete' commands

Now I've added the 'with' commands to that list because it contains a
'complete' subcommand. To accomplish this, I'm trying to fix a TODO to
provide a per-command flag controlling whitespace-stripping.

I've also cleaned up some seemingly TODOs that are either fixed by this
patch or obsolete.

Open question: This patch stops stripping trailing whitespace from all
'with' commands. Might that create issues with other 'with' commands
besides 'with ... -- complete'?

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29784
---
 gdb/cli/cli-cmds.c   | 12 +++++-------
 gdb/cli/cli-cmds.h   |  4 ----
 gdb/cli/cli-decode.h |  8 ++++----
 gdb/top.c            | 12 +-----------
 4 files changed, 10 insertions(+), 26 deletions(-)

diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 9a5021f9d08..2cb7471dda8 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -427,12 +427,6 @@ complete_command (const char *arg, int from_tty)
     }
 }
 
-int
-is_complete_command (struct cmd_list_element *c)
-{
-  return cmd_simple_func_eq (c, complete_command);
-}
-
 static void
 show_version (const char *args, int from_tty)
 {
@@ -2702,14 +2696,17 @@ Generic command for showing things about the program being debugged."),
   add_com_alias ("i", info_cmd, class_info, 1);
   add_com_alias ("inf", info_cmd, class_info, 1);
 
-  add_com ("complete", class_obscure, complete_command,
+  cmd_list_element *complete_cmd
+    = add_com ("complete", class_obscure, complete_command,
 	   _("List the completions for the rest of the line as a command."));
+  complete_cmd->strip_trailing_white_space_p = 0;
 
   c = add_show_prefix_cmd ("show", class_info, _("\
 Generic command for showing things about the debugger."),
 			   &showlist, 0, &cmdlist);
   /* Another way to get at the same thing.  */
   add_alias_cmd ("set", c, class_info, 0, &infolist);
+  c->strip_trailing_white_space_p = 0;
 
   cmd_list_element *with_cmd
     = add_com ("with", class_vars, with_command, _("\
@@ -2726,6 +2723,7 @@ E.g.:\n\
 You can change multiple settings using nested with, and use\n\
 abbreviations for commands and/or values.  E.g.:\n\
   w la p -- w p el u -- p obj"));
+  with_cmd->strip_trailing_white_space_p = 0;
   set_cmd_completer_handle_brkchars (with_cmd, with_command_completer);
   add_com_alias ("w", with_cmd, class_vars, 1);
 
diff --git a/gdb/cli/cli-cmds.h b/gdb/cli/cli-cmds.h
index 33d13fb8563..c3004a8e857 100644
--- a/gdb/cli/cli-cmds.h
+++ b/gdb/cli/cli-cmds.h
@@ -149,10 +149,6 @@ extern struct cmd_list_element *showsourcelist;
 
 extern unsigned int max_user_call_depth;
 
-/* Exported to gdb/top.c */
-
-int is_complete_command (struct cmd_list_element *cmd);
-
 /* Exported to gdb/main.c */
 
 extern void cd_command (const char *, int);
diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h
index 9be446fb641..f794e3c45f6 100644
--- a/gdb/cli/cli-decode.h
+++ b/gdb/cli/cli-decode.h
@@ -60,6 +60,7 @@ struct cmd_list_element
       allow_unknown (0),
       abbrev_flag (0),
       type (not_set_cmd),
+      strip_trailing_white_space_p (1),
       doc (doc_)
   {
     gdb_assert (name != nullptr);
@@ -175,11 +176,10 @@ struct cmd_list_element
      or "show").  */
   ENUM_BITFIELD (cmd_types) type : 2;
 
+  unsigned int strip_trailing_white_space_p : 1;
+
   /* Function definition of this command.  NULL for command class
-     names and for help topics that are not really commands.  NOTE:
-     cagney/2002-02-02: This function signature is evolving.  For
-     the moment suggest sticking with either set_cmd_cfunc() or
-     set_cmd_sfunc().  */
+     names and for help topics that are not really commands.  */
   cmd_func_ftype *func;
 
   /* The command's real callback.  At present func() bounces through
diff --git a/gdb/top.c b/gdb/top.c
index 6adef467b90..8a1e586b4c1 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -503,20 +503,10 @@ execute_command (const char *p, int from_tty)
 	  arg = *p == '\0' ? nullptr : p;
 	}
 
-      /* FIXME: cagney/2002-02-02: The c->type test is pretty dodgy
-	 while the is_complete_command(cfunc) test is just plain
-	 bogus.  They should both be replaced by a test of the form
-	 c->strip_trailing_white_space_p.  */
-      /* NOTE: cagney/2002-02-02: The function.cfunc in the below
-	 can't be replaced with func.  This is because it is the
-	 cfunc, and not the func, that has the value that the
-	 is_complete_command hack is testing for.  */
       /* Clear off trailing whitespace, except for set and complete
 	 command.  */
       std::string without_whitespace;
-      if (arg
-	  && c->type != set_cmd
-	  && !is_complete_command (c))
+      if (arg && c->strip_trailing_white_space_p)
 	{
 	  const char *old_end = arg + strlen (arg) - 1;
 	  p = old_end;
-- 
2.49.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-07-08  9:29 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-29 12:51 [PATCH] RFC: gdb: redo whitespace-stripping from commands Kartik K. Agaram
2025-05-29 13:36 ` Tom Tromey
2025-05-29 13:53   ` Kartik Agaram
2025-05-29 13:53   ` Guinevere Larsen
2025-05-29 13:59     ` Kartik Agaram
2025-05-29 15:35     ` Tom Tromey
2025-06-01  1:17 ` Kartik K. Agaram
2025-06-01  1:17   ` [PATCH] " Kartik K. Agaram
2025-06-02 16:30     ` Guinevere Larsen
2025-06-02 16:42       ` Kartik Agaram
2025-06-02 23:39     ` [PATCH v3] " Kartik K. Agaram
2025-06-06 16:10       ` [PATCH v4] " Kartik K. Agaram
2025-07-07 17:59         ` Kartik Agaram
2025-07-08  9:27         ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox