public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFAv3 4/4] Document define-prefix command and the use of . in command names.
  2019-11-28 20:09 [RFAv3 0/4] More flexible user-defined commands prefixing and naming Philippe Waroquiers
@ 2019-11-28 20:09 ` Philippe Waroquiers
  2019-11-28 20:09 ` [RFAv3 2/4] Test define-prefix Philippe Waroquiers
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Philippe Waroquiers @ 2019-11-28 20:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

gdb/ChangeLog
YYYY-MM-DD  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
	* NEWS:  Mention define-prefix.  Tell that command names can now
	contain a . character.

gdb/doc/ChangeLog
YYYY-MM-DD  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.texinfo (Define): Indicate that user-defined prefix can
	be used in 'define' command.  Document 'define-prefix' command.
---
 gdb/NEWS            |  9 +++++++++
 gdb/doc/gdb.texinfo | 45 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index d9014075b4..e477986d5f 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -33,6 +33,12 @@
   provide the exitcode or exit status of the shell commands launched by
   GDB commands such as "shell", "pipe" and "make".
 
+* The command define-prefix can now define user defined prefix commands.
+  User defined commands can now be defined using these user defined prefix
+  commands.
+
+* Command names can now use the . character.
+
 * The RX port now supports XML target descriptions.
 
 * GDB now shows the Ada task names at more places, e.g. in task switching
@@ -100,6 +106,9 @@ pipe -d DELIM COMMAND DELIM SHELL_COMMAND
   With no COMMAND, repeat the last executed command
   and send its output to SHELL_COMMAND.
 
+define-prefix COMMAND
+  Define or mark a command as a user-defined prefix command.
+  
 with SETTING [VALUE] [-- COMMAND]
 w SETTING [VALUE] [-- COMMAND]
   Temporarily set SETTING, run COMMAND, and restore SETTING.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 478c95b643..2c30ea657e 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -26525,8 +26525,9 @@ end
 Define a command named @var{commandname}.  If there is already a command
 by that name, you are asked to confirm that you want to redefine it.
 The argument @var{commandname} may be a bare command name consisting of letters,
-numbers, dashes, and underscores.  It may also start with any predefined
-prefix command.  For example, @samp{define target my-target} creates
+numbers, dashes, dots, and underscores.  It may also start with any
+predefined or user-defined prefix command.
+For example, @samp{define target my-target} creates
 a user-defined @samp{target my-target} command.
 
 The definition of the command is made up of other @value{GDBN} command lines,
@@ -26547,6 +26548,46 @@ You may use the @code{document} command again to change the
 documentation of a command.  Redefining the command with @code{define}
 does not change the documentation.
 
+@kindex define-prefix
+@item define-prefix @var{commandname}
+Define or mark the command @var{commandname} as a user-defined prefix
+command.  Once marked, @var{commandname} can be used as prefix command
+by the  @code{define} command.
+Note that @code{define-prefix} can be used with a not yet defined
+@var{commandname}.  In such a case, @var{commandname} is defined as
+an empty user-defined command.
+In case you redefine a command that was marked as a user-defined
+prefix command, the subcommands of the redefined command are kept
+(and @value{GDBN} indicates so to the user).
+
+Example:
+@example
+(gdb) define-prefix abc
+(gdb) define-prefix abc def
+(gdb) define abc def
+Type commands for definition of "abc def".
+End with a line saying just "end".
+>echo command initial def\n
+>end
+(gdb) define abc def ghi
+Type commands for definition of "abc def ghi".
+End with a line saying just "end".
+>echo command ghi\n
+>end
+(gdb) define abc def
+Keeping subcommands of prefix command "def".
+Redefine command "def"? (y or n) y
+Type commands for definition of "abc def".
+End with a line saying just "end".
+>echo command def\n
+>end
+(gdb) abc def ghi
+command ghi
+(gdb) abc def
+command def
+(gdb)
+@end example
+
 @kindex dont-repeat
 @cindex don't repeat command
 @item dont-repeat
-- 
2.20.1

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

* [RFAv3 2/4] Test define-prefix.
  2019-11-28 20:09 [RFAv3 0/4] More flexible user-defined commands prefixing and naming Philippe Waroquiers
  2019-11-28 20:09 ` [RFAv3 4/4] Document define-prefix command and the use of . in command names Philippe Waroquiers
@ 2019-11-28 20:09 ` Philippe Waroquiers
  2019-11-28 20:09 ` [RFAv3 1/4] Implement user defined prefix Philippe Waroquiers
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Philippe Waroquiers @ 2019-11-28 20:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

Adds a test testing the new define-prefix command.

2019-11-27  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/define-prefix.exp: New file.
---
 gdb/testsuite/gdb.base/define-prefix.exp | 164 +++++++++++++++++++++++
 1 file changed, 164 insertions(+)
 create mode 100644 gdb/testsuite/gdb.base/define-prefix.exp

diff --git a/gdb/testsuite/gdb.base/define-prefix.exp b/gdb/testsuite/gdb.base/define-prefix.exp
new file mode 100644
index 0000000000..b04c5959c0
--- /dev/null
+++ b/gdb/testsuite/gdb.base/define-prefix.exp
@@ -0,0 +1,164 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2019 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+# This test verifies the "define-prefix" command.
+
+gdb_start
+
+####################
+# Verify the definition of user defined prefix commands.
+# Test the definition of a command using these prefixes.
+
+# Define an empty prefix command.
+gdb_test_no_output "define-prefix abc-prefix"
+
+# Verify an empty prefix command cannot be used as a command.
+gdb_test "abc-prefix" \
+    "\"abc-prefix\" must be followed by the name of a subcommand.*" \
+    "execute prefix command not followed by subcommand"
+
+# Define a sub-prefix command.
+gdb_test_no_output "define-prefix abc-prefix def-prefix"
+
+# Define ghi-cmd using the prefixes.
+gdb_test_multiple "define abc-prefix def-prefix ghi-cmd" \
+    "define user command: abc-prefix def-prefix ghi-cmd" {
+	-re "Type commands for definition of \"abc-prefix def-prefix ghi-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+	    gdb_test "echo command ghi-cmd\\n\nend" "" \
+		"define user command: ghi-cmd"
+	}
+    }
+# Verify ghi-cmd works.
+gdb_test "abc-prefix def-prefix ghi-cmd" \
+    "command ghi-cmd" \
+    "use user command: ghi-cmd"
+
+
+####################
+# Verify an existing (empty) command can be marked as a prefix command.
+# Then verify an empty prefix command can be transformed into an executable command.
+
+# Define ghi-prefix-cmd as an empty command.
+gdb_test_multiple "define abc-prefix def-prefix ghi-prefix-cmd" \
+    "define user command: abc-prefix def-prefix ghi-prefix-cmd" {
+	-re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+	    gdb_test "end" "" \
+		"define user command: ghi-prefix-cmd"
+	}
+    }
+gdb_test_no_output "define-prefix abc-prefix def-prefix ghi-prefix-cmd"
+
+# Verify a sequence ending with an empty prefix command cannot be used as
+# a command.
+gdb_test "abc-prefix def-prefix ghi-prefix-cmd" \
+    "\"abc-prefix def-prefix ghi-prefix-cmd\" must be followed by the name of a subcommand.*" \
+    "execute sequence of prefix commands not followed by a subcommand"
+
+# Define jkl-cmd command.
+gdb_test_multiple "define abc-prefix def-prefix ghi-prefix-cmd jkl-cmd" \
+    "define user command: abc-prefix def-prefix ghi-prefix-cmd jkl-cmd" {
+	-re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd jkl-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+	    gdb_test "echo command jkl-cmd\\n\nend" "" \
+		"define user command: jkl-cmd"
+	}
+    }
+# Verify jkl-cmd command works.
+gdb_test "abc-prefix def-prefix ghi-prefix-cmd jkl-cmd" \
+    "command jkl-cmd" \
+    "use user command: jkl-cmd"
+
+# Define alternate-jkl-cmd and check it works.
+# Define alternate-jkl-cmd command.
+gdb_test_multiple "define abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd" \
+    "define user command: abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd" {
+	-re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+	    gdb_test "echo command alternate-jkl-cmd\\n\nend" "" \
+		"define user command: alternate-jkl-cmd"
+	}
+    }
+# Verify alternate-jkl-cmd command works.
+gdb_test "abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd" \
+    "command alternate-jkl-cmd" \
+    "use user command: alternate-jkl-cmd"
+
+
+
+# Now define ghi-prefix-cmd as a real command, and check it is working.
+send_gdb "define abc-prefix def-prefix ghi-prefix-cmd\n"
+gdb_expect {
+    -re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+	send_gdb "echo defined command ghi-prefix-cmd\\n\nend\n"
+	gdb_expect {
+	    -re "$gdb_prompt $" {pass "define user command: ghi-prefix-cmd"}
+	    timeout {fail "(timeout) define user command: ghi-prefix-cmd"}
+	}
+    }
+    timeout {fail "(timeout) define user command: ghi-prefix-cmd"}
+}
+
+# Verify ghi-prefix-cmd command works.
+gdb_test "abc-prefix def-prefix ghi-prefix-cmd" \
+    "defined command ghi-prefix-cmd" \
+    "use defined user command: ghi-prefix-cmd"
+
+# Now redefine ghi-prefix-cmd, and check it is working.
+send_gdb "define abc-prefix def-prefix ghi-prefix-cmd\n"
+gdb_expect {
+    -re "Keeping subcommands of prefix command \"ghi-prefix-cmd\"\.\r\nRedefine command \"ghi-prefix-cmd\".*y or n. $" {
+	send_gdb "y\n"
+	gdb_expect {
+	    -re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+		send_gdb "echo redefined command ghi-prefix-cmd\\n\nend\n"
+		gdb_expect {
+		    -re "$gdb_prompt $" {pass "redefine user command: ghi-prefix-cmd"}
+		    timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
+		}
+	    }
+	    timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
+	}
+    }
+    -re "$gdb_prompt $" {fail "redefine user command: ghi-prefix-cmd"}
+    timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
+}
+
+# Verify redefined ghi-prefix-cmd command works.
+gdb_test "abc-prefix def-prefix ghi-prefix-cmd" \
+    "redefined command ghi-prefix-cmd" \
+    "use redefined user command: ghi-prefix-cmd"
+
+# Check jkl-cmd still works.
+gdb_test "abc-prefix def-prefix ghi-prefix-cmd jkl-cmd" \
+    "command jkl-cmd" \
+    "use user command after redefining ghi-prefix-cmd: jkl-cmd"
+
+# Check alternate-jkl-cmd still works.
+gdb_test "abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd" \
+    "command alternate-jkl-cmd" \
+    "use user command after redefining ghi-prefix-cmd: alternate-jkl-cmd"
+
+####################
+# Check error behaviour.
+
+gdb_test "define-prefix print" ".* is built-in.*"
+
+gdb_test "define-prefix something-not-existing something-else" \
+    "Undefined command: \"something-not-existing\".*"
+
+gdb_test "define-prefix abc-prefix something-not-existing something-else" \
+    "Undefined abc-prefix command: \"something-not-existing\".*"
+
-- 
2.20.1

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

* [RFAv3 3/4] Allow . character as part of command names.
  2019-11-28 20:09 [RFAv3 0/4] More flexible user-defined commands prefixing and naming Philippe Waroquiers
                   ` (2 preceding siblings ...)
  2019-11-28 20:09 ` [RFAv3 1/4] Implement user defined prefix Philippe Waroquiers
@ 2019-11-28 20:09 ` Philippe Waroquiers
  2019-11-30  3:36 ` [RFAv3 0/4] More flexible user-defined commands prefixing and naming Simon Marchi
  4 siblings, 0 replies; 8+ messages in thread
From: Philippe Waroquiers @ 2019-11-28 20:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

This patch adds . as an allowed character for user defined commands.
Combined with 'define-prefix', this allows to e.g. define a set of Valgrind
specific user command corresponding to the Valgrind monitor commands
(such as check_memory, v.info, v.set, ...).

gdb/ChangeLog
YYYY-MM-DD  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* command.h (valid_cmd_char_p): Declare.
	* cli/cli-decode.c (valid_cmd_char_p): New function factorizing
	the check of valid command char.
	(find_command_name_length, valid_user_defined_cmd_name_p): Use
	valid_cmd_char_p.
	* cli/cli-script.c (validate_comname): Likewise.
	* completer.c (gdb_completer_command_word_break_characters):
	Do not remove . from the word break char, update comments.
	(complete_line_internal_1): Use valid_cmd_char_p.
	* guile/scm-cmd.c (gdbscm_parse_command_name): Likewise.
	* python/py-cmd.c (gdbpy_parse_command_name): Likewise.

gdb/testsuite/ChangeLog
YYYY-MM-DD  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/define.exp: Test . in command names.
	* gdb.base/setshow.exp: Update test, as . is now part of
	command name.
---
 gdb/cli/cli-decode.c               | 24 ++++++++++++++----------
 gdb/cli/cli-script.c               |  2 +-
 gdb/command.h                      |  8 ++++++++
 gdb/completer.c                    | 10 +++++-----
 gdb/guile/scm-cmd.c                |  5 +----
 gdb/python/py-cmd.c                |  5 +----
 gdb/testsuite/gdb.base/define.exp  | 25 +++++++++++++++++++++++++
 gdb/testsuite/gdb.base/setshow.exp |  2 +-
 8 files changed, 56 insertions(+), 25 deletions(-)

diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 7ace72fb7e..307fd1e826 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -1372,7 +1372,7 @@ find_command_name_length (const char *text)
   if (*p == '!' || *p == '|')
     return 1;
 
-  while (isalnum (*p) || *p == '-' || *p == '_'
+  while (valid_cmd_char_p (*p)
 	 /* Characters used by TUI specific commands.  */
 	 || *p == '+' || *p == '<' || *p == '>' || *p == '$')
     p++;
@@ -1380,9 +1380,18 @@ find_command_name_length (const char *text)
   return p - text;
 }
 
-/* Return TRUE if NAME is a valid user-defined command name.
-   This is a stricter subset of all gdb commands,
-   see find_command_name_length.  */
+/* See command.h.  */
+
+bool
+valid_cmd_char_p (int c)
+{
+  /* Alas "42" is a legitimate user-defined command.
+     In the interests of not breaking anything we preserve that.  */
+
+  return isalnum (c) || c == '-' || c == '_' || c == '.';
+}
+
+/* See command.h.  */
 
 bool
 valid_user_defined_cmd_name_p (const char *name)
@@ -1392,14 +1401,9 @@ valid_user_defined_cmd_name_p (const char *name)
   if (*name == '\0')
     return false;
 
-  /* Alas "42" is a legitimate user-defined command.
-     In the interests of not breaking anything we preserve that.  */
-
   for (p = name; *p != '\0'; ++p)
     {
-      if (isalnum (*p)
-	  || *p == '-'
-	  || *p == '_')
+      if (valid_cmd_char_p (*p))
 	; /* Ok.  */
       else
 	return false;
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 066a596fdc..6900f5c9ee 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -1342,7 +1342,7 @@ validate_comname (const char **comname)
   p = *comname;
   while (*p)
     {
-      if (!isalnum (*p) && *p != '-' && *p != '_')
+      if (!valid_cmd_char_p (*p))
 	error (_("Junk in argument list: \"%s\""), p);
       p++;
     }
diff --git a/gdb/command.h b/gdb/command.h
index cf190ef649..5384a0a674 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -133,8 +133,16 @@ extern struct cli_suppress_notification cli_suppress_notification;
 
 /* API to the manipulation of command lists.  */
 
+/* Return TRUE if NAME is a valid user-defined command name.
+   This is a stricter subset of all gdb commands,
+   see find_command_name_length.  */
+
 extern bool valid_user_defined_cmd_name_p (const char *name);
 
+/* Return TRUE if C is a valid command character.  */
+
+extern bool valid_cmd_char_p (int c);
+
 /* Const-correct variant of the above.  */
 
 extern struct cmd_list_element *add_cmd (const char *, enum command_class,
diff --git a/gdb/completer.c b/gdb/completer.c
index b34b7762c6..6658da6d7f 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -102,13 +102,13 @@ enum explicit_location_match_type
 
 /* Variables which are necessary for fancy command line editing.  */
 
-/* When completing on command names, we remove '-' from the list of
+/* When completing on command names, we remove '-' and '.' from the list of
    word break characters, since we use it in command names.  If the
    readline library sees one in any of the current completion strings,
    it thinks that the string needs to be quoted and automatically
    supplies a leading quote.  */
 static const char gdb_completer_command_word_break_characters[] =
-" \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
+" \t\n!@#$%^&*()+=|~`}{[]\"';:?/><,";
 
 /* When completing on file names, we remove from the list of word
    break characters any characters that are commonly used in file
@@ -1284,7 +1284,7 @@ complete_line_internal_1 (completion_tracker &tracker,
      on command strings (as opposed to strings supplied by the
      individual command completer functions, which can be any string)
      then we will switch to the special word break set for command
-     strings, which leaves out the '-' character used in some
+     strings, which leaves out the '-' and '.' character used in some
      commands.  */
   set_rl_completer_word_break_characters
     (current_language->la_word_break_characters());
@@ -1347,7 +1347,7 @@ complete_line_internal_1 (completion_tracker &tracker,
       /* lookup_cmd_1 advances p up to the first ambiguous thing, but
 	 doesn't advance over that thing itself.  Do so now.  */
       q = p;
-      while (*q && (isalnum (*q) || *q == '-' || *q == '_'))
+      while (valid_cmd_char_p (*q))
 	++q;
       if (q != tmp_command + point)
 	{
@@ -1435,7 +1435,7 @@ complete_line_internal_1 (completion_tracker &tracker,
 	      q = p;
 	      while (q > tmp_command)
 		{
-		  if (isalnum (q[-1]) || q[-1] == '-' || q[-1] == '_')
+		  if (valid_cmd_char_p (q[-1]))
 		    --q;
 		  else
 		    break;
diff --git a/gdb/guile/scm-cmd.c b/gdb/guile/scm-cmd.c
index f2fa40e453..3b8195b8b4 100644
--- a/gdb/guile/scm-cmd.c
+++ b/gdb/guile/scm-cmd.c
@@ -492,10 +492,7 @@ gdbscm_parse_command_name (const char *name,
   lastchar = i;
 
   /* Find first character of the final word.  */
-  for (; i > 0 && (isalnum (name[i - 1])
-		   || name[i - 1] == '-'
-		   || name[i - 1] == '_');
-       --i)
+  for (; i > 0 && valid_cmd_char_p (name[i - 1]); --i)
     ;
   result = (char *) xmalloc (lastchar - i + 2);
   memcpy (result, &name[i], lastchar - i + 1);
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 38973401a8..8d6f01b78f 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -372,10 +372,7 @@ gdbpy_parse_command_name (const char *name,
   lastchar = i;
 
   /* Find first character of the final word.  */
-  for (; i > 0 && (isalnum (name[i - 1])
-		   || name[i - 1] == '-'
-		   || name[i - 1] == '_');
-       --i)
+  for (; i > 0 && valid_cmd_char_p (name[i - 1]); --i)
     ;
   result = (char *) xmalloc (lastchar - i + 2);
   memcpy (result, &name[i], lastchar - i + 1);
diff --git a/gdb/testsuite/gdb.base/define.exp b/gdb/testsuite/gdb.base/define.exp
index d7d4fd03ba..b5183eceec 100644
--- a/gdb/testsuite/gdb.base/define.exp
+++ b/gdb/testsuite/gdb.base/define.exp
@@ -130,6 +130,31 @@ gdb_test "help nextwhere" \
     "   A next command that first shows you where you're stepping from.*" \
     "preserve whitespace in help string"
 
+# Verify that GDB allows a user to use . in a command name.
+#
+gdb_test_multiple "define dot.command" "define user command: dot.command" {
+    -re "Type commands for definition of \"dot.command\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+	gdb_test "echo dot command\\n\nend" "" \
+	    "define user command: dot.command"
+    }
+}
+
+# Verify that dot.command works.
+#
+gdb_test "dot.command" \
+    "dot command" \
+    "full name dot.command"
+gdb_test "dot" \
+    "dot command" \
+    "partial name dot"
+gdb_test "dot." \
+    "dot command" \
+    "partial name dot."
+gdb_test "dot.c" \
+    "dot command" \
+    "partial name dot.c"
+
+
 # Verify that the command parser doesn't require a space after an 'if'
 # command in a user defined function.
 #
diff --git a/gdb/testsuite/gdb.base/setshow.exp b/gdb/testsuite/gdb.base/setshow.exp
index 717bcc3270..394967babf 100644
--- a/gdb/testsuite/gdb.base/setshow.exp
+++ b/gdb/testsuite/gdb.base/setshow.exp
@@ -355,7 +355,7 @@ gdb_test_no_output "set verbose off" "set verbose off"
 gdb_test "show verbose" "Verbosity is off..*" "show verbose (off)" 
 #test argument must be preceded by space
 foreach x {"history file" "solib-search-path" "data-directory"} {
-    foreach y {"/home/" "." "~/home" "=home"} {
+    foreach y {"/home/" "~/home" "=home"} {
         gdb_test "set $x$y" "Argument must be preceded by space." \
             "$x is not set to $y"
     }
-- 
2.20.1

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

* [RFAv3 0/4] More flexible user-defined commands prefixing and naming.
@ 2019-11-28 20:09 Philippe Waroquiers
  2019-11-28 20:09 ` [RFAv3 4/4] Document define-prefix command and the use of . in command names Philippe Waroquiers
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Philippe Waroquiers @ 2019-11-28 20:09 UTC (permalink / raw)
  To: gdb-patches

More flexible user-defined commands prefixing and naming.

This is the third version of the patch series.
The only modification is to ensure that GDB does not ask the question:
   Keeping subcommands of prefix command "xxxx".
   Redefine command "xxxx"? (y or n)
if xxxx was only defined as a prefix.
Test and doc updated accordingly.

To ease the review, the diff between v2 and v3 is given below.

This patch series improves the way a user can define user commands
using CLI sequences of commands.

Currently, a user can define a command after an existing command prefix
e.g.  define target mycommand
but cannot define a prefix to define command such as:
      define mytargetprefix mycommand.

This patch series adds the command 'define-prefix to allow
user commands to be prefix commands.

Also, this patch series adds . as an allowed character for user
defined commands.
This can e.g. be used to define a set of Valgrind specific user command
corresponding to the Valgrind monitor commands (such as check_memory,
v.info, v.set, ...).

This then allows to use GDB completion and expression evaluation
for sending monitor commands e.g. to Valgrind;

For example, for the Valgrind monitor 'check_memory' command:
  check_memory [addressable|defined] <addr> [<len>]
        check that <len> (or 1) bytes at <addr> have the given accessibility
            and outputs a description of <addr>
we can now define some new GDB commands such as:
(gdb) define-prefix Vmonitor
(gdb) define-prefix Vmonitor check_memory
(gdb) define Vmonitor check_memory addressable
eval "monitor check_memory addressable %#lx %d", $arg0, $arg1
end
(gdb) define Vmonitor check_memory defined
eval "monitor check_memory defined %#lx %d", $arg0, $arg1
end
(gdb)

Compared to the 'raw' monitor command, the new GDB commands provide completion
and evaluation of expressions.

Second version of the patch series was:
Compared to the first version, this handles the comments of Simon.
2 changes worth mentionning here:
  * The command name was changed to define-prefix.
  * In case the user redefines a command that is also a prefix command,
    the confirmation message is now:
       (gdb) define-prefix xxxx
       (gdb) define xxxx
       Keeping subcommands of prefix command "xxxx".
       Redefine command "xxxx"? (y or n) 
    This reminds the user that the subcommands of the prefix command xxxx
    are kept even when xxxx is redefined.

diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 79c499a4c2..6900f5c9ee 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -1397,11 +1397,13 @@ do_define_command (const char *comname, int from_tty,
 
       if (c->theclass == class_user || c->theclass == class_alias)
 	{
-	  /* if C is a prefix command, tell the user its subcommands will
-	     be kept, and ask if ok to redefine the command.  */
+	  /* if C is a prefix command that was previously defined,
+	     tell the user its subcommands will be kept, and ask
+	     if ok to redefine the command.  */
 	  if (c->prefixlist != nullptr)
-	    q = query (_("Keeping subcommands of prefix command \"%s\".\n"
-			 "Redefine command \"%s\"? "), c->name, c->name);
+	    q = c->user_commands.get () == nullptr
+	      || query (_("Keeping subcommands of prefix command \"%s\".\n"
+			  "Redefine command \"%s\"? "), c->name, c->name);
 	  else
 	    q = query (_("Redefine command \"%s\"? "), c->name);
 	}
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 17f357832c..2c30ea657e 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -26564,6 +26564,11 @@ Example:
 @example
 (gdb) define-prefix abc
 (gdb) define-prefix abc def
+(gdb) define abc def
+Type commands for definition of "abc def".
+End with a line saying just "end".
+>echo command initial def\n
+>end
 (gdb) define abc def ghi
 Type commands for definition of "abc def ghi".
 End with a line saying just "end".
diff --git a/gdb/testsuite/gdb.base/define-prefix.exp b/gdb/testsuite/gdb.base/define-prefix.exp
index e8f4c3c4e4..b04c5959c0 100644
--- a/gdb/testsuite/gdb.base/define-prefix.exp
+++ b/gdb/testsuite/gdb.base/define-prefix.exp
@@ -98,27 +98,45 @@ gdb_test "abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd" \
 
 
 
-# Now redefine ghi-prefix-cmd as a real command, and check it is working.
+# Now define ghi-prefix-cmd as a real command, and check it is working.
+send_gdb "define abc-prefix def-prefix ghi-prefix-cmd\n"
+gdb_expect {
+    -re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+	send_gdb "echo defined command ghi-prefix-cmd\\n\nend\n"
+	gdb_expect {
+	    -re "$gdb_prompt $" {pass "define user command: ghi-prefix-cmd"}
+	    timeout {fail "(timeout) define user command: ghi-prefix-cmd"}
+	}
+    }
+    timeout {fail "(timeout) define user command: ghi-prefix-cmd"}
+}
+
+# Verify ghi-prefix-cmd command works.
+gdb_test "abc-prefix def-prefix ghi-prefix-cmd" \
+    "defined command ghi-prefix-cmd" \
+    "use defined user command: ghi-prefix-cmd"
+
+# Now redefine ghi-prefix-cmd, and check it is working.
 send_gdb "define abc-prefix def-prefix ghi-prefix-cmd\n"
 gdb_expect {
     -re "Keeping subcommands of prefix command \"ghi-prefix-cmd\"\.\r\nRedefine command \"ghi-prefix-cmd\".*y or n. $" {
 	send_gdb "y\n"
-	    gdb_expect {
-		-re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
-		    send_gdb "echo redefined command ghi-prefix-cmd\\n\nend\n"
-		    gdb_expect {
-			-re "$gdb_prompt $" {pass "redefine user command: ghi-prefix-cmd"}
-			timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
-		    }
+	gdb_expect {
+	    -re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+		send_gdb "echo redefined command ghi-prefix-cmd\\n\nend\n"
+		gdb_expect {
+		    -re "$gdb_prompt $" {pass "redefine user command: ghi-prefix-cmd"}
+		    timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
 		}
-		timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
 	    }
+	    timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
+	}
     }
-    -re "$gdb_prompt $"	{fail "redefine user command: ghi-prefix-cmd"}
+    -re "$gdb_prompt $" {fail "redefine user command: ghi-prefix-cmd"}
     timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
 }
 
-# Verify ghi-prefix-cmd command works.
+# Verify redefined ghi-prefix-cmd command works.
 gdb_test "abc-prefix def-prefix ghi-prefix-cmd" \
     "redefined command ghi-prefix-cmd" \
     "use redefined user command: ghi-prefix-cmd"



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

* [RFAv3 1/4] Implement user defined prefix.
  2019-11-28 20:09 [RFAv3 0/4] More flexible user-defined commands prefixing and naming Philippe Waroquiers
  2019-11-28 20:09 ` [RFAv3 4/4] Document define-prefix command and the use of . in command names Philippe Waroquiers
  2019-11-28 20:09 ` [RFAv3 2/4] Test define-prefix Philippe Waroquiers
@ 2019-11-28 20:09 ` Philippe Waroquiers
  2019-11-30  4:09   ` Simon Marchi
  2019-11-28 20:09 ` [RFAv3 3/4] Allow . character as part of command names Philippe Waroquiers
  2019-11-30  3:36 ` [RFAv3 0/4] More flexible user-defined commands prefixing and naming Simon Marchi
  4 siblings, 1 reply; 8+ messages in thread
From: Philippe Waroquiers @ 2019-11-28 20:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

This patch adds the new 'define-prefix' command that creates (or mark an
existing user defined command) as a prefix command.
This approach was preferred compared to add a -prefix option to
'define' command : with define-prefix, a command can be defined and
afterwards marked as a prefix.  Also, it is easier to define a
'prefix' only command in one operation.

This patch also adds completers for the 'define' and 'document' commands.
This makes it easier for the user to type the prefixes for 'define'
and type the documented command name for 'document'.

gdb/ChangeLog
YYYY-MM-DD  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-script.c (do_define_command): Ensure a redefined
	prefix command is kept as a prefix command.
	(define_prefix_command): New function.
	(show_user_1): Report user defined prefixes.
	(_initialize_cli_script):  Create the new 'define-prefix' command.
	Add completers for 'define' and 'document'.
	* top.c (execute_command):  If command is a user-defined prefix only
	command, report the list of commands for this prefix command.
---
 gdb/cli/cli-script.c | 126 +++++++++++++++++++++++++++++++++++++------
 gdb/top.c            |  12 +++++
 2 files changed, 123 insertions(+), 15 deletions(-)

diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 06cdcd6bfe..066a596fdc 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -29,6 +29,7 @@
 #include "cli/cli-cmds.h"
 #include "cli/cli-decode.h"
 #include "cli/cli-script.h"
+#include "cli/cli-style.h"
 
 #include "extension.h"
 #include "interps.h"
@@ -1395,7 +1396,17 @@ do_define_command (const char *comname, int from_tty,
       int q;
 
       if (c->theclass == class_user || c->theclass == class_alias)
-	q = query (_("Redefine command \"%s\"? "), c->name);
+	{
+	  /* if C is a prefix command that was previously defined,
+	     tell the user its subcommands will be kept, and ask
+	     if ok to redefine the command.  */
+	  if (c->prefixlist != nullptr)
+	    q = c->user_commands.get () == nullptr
+	      || query (_("Keeping subcommands of prefix command \"%s\".\n"
+			  "Redefine command \"%s\"? "), c->name, c->name);
+	  else
+	    q = query (_("Redefine command \"%s\"? "), c->name);
+	}
       else
 	q = query (_("Really redefine built-in command \"%s\"? "), c->name);
       if (!q)
@@ -1446,10 +1457,27 @@ do_define_command (const char *comname, int from_tty,
   else
     cmds = *commands;
 
-  newc = add_cmd (comname, class_user, user_defined_command,
-		  (c && c->theclass == class_user)
-		  ? c->doc : xstrdup ("User-defined."), list);
-  newc->user_commands = std::move (cmds);
+  {
+    struct cmd_list_element **c_prefixlist
+      = c == nullptr ? nullptr : c->prefixlist;
+    const char *c_prefixname = c == nullptr ? nullptr : c->prefixname;
+
+    newc = add_cmd (comname, class_user, user_defined_command,
+		    (c != nullptr && c->theclass == class_user)
+		    ? c->doc : xstrdup ("User-defined."), list);
+    newc->user_commands = std::move (cmds);
+
+    /* If we define or re-define a command that was previously defined
+       as a prefix, keep the prefix information.  */
+    if (c_prefixlist != nullptr)
+      {
+	newc->prefixlist = c_prefixlist;
+	newc->prefixname = c_prefixname;
+	/* allow_unknown: see explanation in equivalent logic in
+	   define_prefix_command ().  */
+	newc->allow_unknown = newc->user_commands.get () != nullptr;
+    }
+  }
 
   /* If this new command is a hook, then mark both commands as being
      tied.  */
@@ -1524,6 +1552,54 @@ document_command (const char *comname, int from_tty)
     c->doc = doc;
   }
 }
+
+/* Implementation of the "define-prefix" command.  */
+
+static void
+define_prefix_command (const char *comname, int from_tty)
+{
+  struct cmd_list_element *c, **list;
+  const char *tem;
+  const char *comfull;
+
+  comfull = comname;
+  list = validate_comname (&comname);
+
+  /* Look it up, and verify that we got an exact match.  */
+  tem = comname;
+  c = lookup_cmd (&tem, *list, "", -1, 1);
+  if (c != nullptr && strcmp (comname, c->name) != 0)
+    c = nullptr;
+
+  if (c != nullptr && c->theclass != class_user)
+    error (_("Command \"%s\" is built-in."), comfull);
+
+  if (c != nullptr && c->prefixlist != nullptr)
+    {
+      /* c is already a user defined prefix command.  */
+      return;
+    }
+
+  /* If the command does not exist at all, create it.  */
+  if (c == nullptr)
+    {
+      comname = xstrdup (comname);
+      c = add_cmd (comname, class_user, user_defined_command,
+		   xstrdup ("User-defined."), list);
+    }
+
+  /* Allocate the c->prefixlist, which marks the command as a prefix
+     command.  */
+  c->prefixlist = new struct cmd_list_element*;
+  *(c->prefixlist) = nullptr;
+  c->prefixname = xstrprintf ("%s ", comfull);
+  /* If the prefix command C is not a command, then it must be followed
+     by known subcommands.  Otherwise, if C is also a normal command,
+     it can be followed by C args that must not cause a 'subcommand'
+     not recognised error, and thus we must allow unknown.  */
+  c->allow_unknown = c->user_commands.get () != nullptr;
+}
+
 \f
 /* Used to implement source_command.  */
 
@@ -1564,7 +1640,21 @@ void
 show_user_1 (struct cmd_list_element *c, const char *prefix, const char *name,
 	     struct ui_file *stream)
 {
-  struct command_line *cmdlines;
+  if (cli_user_command_p (c))
+    {
+      struct command_line *cmdlines = c->user_commands.get ();
+
+      fprintf_filtered (stream, "User %scommand \"",
+			c->prefixlist == NULL ? "" : "prefix ");
+      fprintf_styled (stream, title_style.style (), "%s%s",
+		      prefix, name);
+      fprintf_filtered (stream, "\":\n");
+      if (cmdlines)
+	{
+	  print_command_lines (current_uiout, cmdlines, 1);
+	  fputs_filtered ("\n", stream);
+	}
+    }
 
   if (c->prefixlist != NULL)
     {
@@ -1573,25 +1663,23 @@ show_user_1 (struct cmd_list_element *c, const char *prefix, const char *name,
       for (c = *c->prefixlist; c != NULL; c = c->next)
 	if (c->theclass == class_user || c->prefixlist != NULL)
 	  show_user_1 (c, prefixname, c->name, gdb_stdout);
-      return;
     }
 
-  cmdlines = c->user_commands.get ();
-  fprintf_filtered (stream, "User command \"%s%s\":\n", prefix, name);
-
-  if (!cmdlines)
-    return;
-  print_command_lines (current_uiout, cmdlines, 1);
-  fputs_filtered ("\n", stream);
 }
 
 void
 _initialize_cli_script (void)
 {
-  add_com ("document", class_support, document_command, _("\
+  struct cmd_list_element *c;
+
+  /* "document", "define" and "define-prefix" use command_completer,
+     as this helps the user to either type the command name and/or
+     its prefixes.  */
+  c = add_com ("document", class_support, document_command, _("\
 Document a user-defined command.\n\
 Give command name as argument.  Give documentation on following lines.\n\
 End with a line of just \"end\"."));
+  set_cmd_completer (c, command_completer);
   define_cmd_element = add_com ("define", class_support, define_command, _("\
 Define a new command name.  Command name is argument.\n\
 Definition appears on following lines, one command per line.\n\
@@ -1600,6 +1688,14 @@ Use the \"document\" command to give documentation for the new command.\n\
 Commands defined in this way may accept an unlimited number of arguments\n\
 accessed via $arg0 .. $argN.  $argc tells how many arguments have\n\
 been passed."));
+  set_cmd_completer (define_cmd_element, command_completer);
+  c = add_com ("define-prefix", class_support, define_prefix_command,
+	   _("\
+Define or mark a command as a user-defined prefix command.\n\
+User defined prefix commands can be used as prefix commands for\n\
+other user defined commands.\n\
+If the command already exists, it is changed to a prefix command."));
+  set_cmd_completer (c, command_completer);
 
   while_cmd_element = add_com ("while", class_support, while_command, _("\
 Execute nested commands WHILE the conditional expression is non zero.\n\
diff --git a/gdb/top.c b/gdb/top.c
index 2953eac819..e8ed3b2747 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -627,6 +627,18 @@ execute_command (const char *p, int from_tty)
       /* c->user_commands would be NULL in the case of a python command.  */
       if (c->theclass == class_user && c->user_commands)
 	execute_user_command (c, arg);
+      else if (c->theclass == class_user
+	       && c->prefixlist && !c->allow_unknown)
+	/* If this is a user defined prefix that does not allow unknown
+	   (in other words, C is a prefix command and not a command
+	   that can be followed by its args), report the list of
+	   subcommands.  */
+	{
+	  printf_unfiltered
+	    ("\"%.*s\" must be followed by the name of a subcommand.\n",
+	     (int) strlen (c->prefixname) - 1, c->prefixname);
+	  help_list (*c->prefixlist, c->prefixname, all_commands, gdb_stdout);
+	}
       else if (c->type == set_cmd)
 	do_set_command (arg, from_tty, c);
       else if (c->type == show_cmd)
-- 
2.20.1

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

* Re: [RFAv3 0/4] More flexible user-defined commands prefixing and naming.
  2019-11-28 20:09 [RFAv3 0/4] More flexible user-defined commands prefixing and naming Philippe Waroquiers
                   ` (3 preceding siblings ...)
  2019-11-28 20:09 ` [RFAv3 3/4] Allow . character as part of command names Philippe Waroquiers
@ 2019-11-30  3:36 ` Simon Marchi
  2019-11-30  8:55   ` Philippe Waroquiers
  4 siblings, 1 reply; 8+ messages in thread
From: Simon Marchi @ 2019-11-30  3:36 UTC (permalink / raw)
  To: Philippe Waroquiers, gdb-patches

On 2019-11-28 3:08 p.m., Philippe Waroquiers wrote:
> More flexible user-defined commands prefixing and naming.
> 
> This is the third version of the patch series.
> The only modification is to ensure that GDB does not ask the question:
>    Keeping subcommands of prefix command "xxxx".
>    Redefine command "xxxx"? (y or n)
> if xxxx was only defined as a prefix.
> Test and doc updated accordingly.
> 
> To ease the review, the diff between v2 and v3 is given below.
> 
> This patch series improves the way a user can define user commands
> using CLI sequences of commands.
> 
> Currently, a user can define a command after an existing command prefix
> e.g.  define target mycommand
> but cannot define a prefix to define command such as:
>       define mytargetprefix mycommand.
> 
> This patch series adds the command 'define-prefix to allow
> user commands to be prefix commands.
> 
> Also, this patch series adds . as an allowed character for user
> defined commands.
> This can e.g. be used to define a set of Valgrind specific user command
> corresponding to the Valgrind monitor commands (such as check_memory,
> v.info, v.set, ...).
> 
> This then allows to use GDB completion and expression evaluation
> for sending monitor commands e.g. to Valgrind;
> 
> For example, for the Valgrind monitor 'check_memory' command:
>   check_memory [addressable|defined] <addr> [<len>]
>         check that <len> (or 1) bytes at <addr> have the given accessibility
>             and outputs a description of <addr>
> we can now define some new GDB commands such as:
> (gdb) define-prefix Vmonitor
> (gdb) define-prefix Vmonitor check_memory
> (gdb) define Vmonitor check_memory addressable
> eval "monitor check_memory addressable %#lx %d", $arg0, $arg1
> end
> (gdb) define Vmonitor check_memory defined
> eval "monitor check_memory defined %#lx %d", $arg0, $arg1
> end
> (gdb)
> 
> Compared to the 'raw' monitor command, the new GDB commands provide completion
> and evaluation of expressions.
> 
> Second version of the patch series was:
> Compared to the first version, this handles the comments of Simon.
> 2 changes worth mentionning here:
>   * The command name was changed to define-prefix.
>   * In case the user redefines a command that is also a prefix command,
>     the confirmation message is now:
>        (gdb) define-prefix xxxx
>        (gdb) define xxxx
>        Keeping subcommands of prefix command "xxxx".
>        Redefine command "xxxx"? (y or n) 
>     This reminds the user that the subcommands of the prefix command xxxx
>     are kept even when xxxx is redefined.
> 
> diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
> index 79c499a4c2..6900f5c9ee 100644
> --- a/gdb/cli/cli-script.c
> +++ b/gdb/cli/cli-script.c
> @@ -1397,11 +1397,13 @@ do_define_command (const char *comname, int from_tty,
>  
>        if (c->theclass == class_user || c->theclass == class_alias)
>  	{
> -	  /* if C is a prefix command, tell the user its subcommands will
> -	     be kept, and ask if ok to redefine the command.  */
> +	  /* if C is a prefix command that was previously defined,
> +	     tell the user its subcommands will be kept, and ask
> +	     if ok to redefine the command.  */
>  	  if (c->prefixlist != nullptr)
> -	    q = query (_("Keeping subcommands of prefix command \"%s\".\n"
> -			 "Redefine command \"%s\"? "), c->name, c->name);
> +	    q = c->user_commands.get () == nullptr
> +	      || query (_("Keeping subcommands of prefix command \"%s\".\n"
> +			  "Redefine command \"%s\"? "), c->name, c->name);
>  	  else
>  	    q = query (_("Redefine command \"%s\"? "), c->name);
>  	}
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 17f357832c..2c30ea657e 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -26564,6 +26564,11 @@ Example:
>  @example
>  (gdb) define-prefix abc
>  (gdb) define-prefix abc def
> +(gdb) define abc def
> +Type commands for definition of "abc def".
> +End with a line saying just "end".
> +>echo command initial def\n
> +>end
>  (gdb) define abc def ghi
>  Type commands for definition of "abc def ghi".
>  End with a line saying just "end".
> diff --git a/gdb/testsuite/gdb.base/define-prefix.exp b/gdb/testsuite/gdb.base/define-prefix.exp
> index e8f4c3c4e4..b04c5959c0 100644
> --- a/gdb/testsuite/gdb.base/define-prefix.exp
> +++ b/gdb/testsuite/gdb.base/define-prefix.exp
> @@ -98,27 +98,45 @@ gdb_test "abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd" \
>  
>  
>  
> -# Now redefine ghi-prefix-cmd as a real command, and check it is working.
> +# Now define ghi-prefix-cmd as a real command, and check it is working.
> +send_gdb "define abc-prefix def-prefix ghi-prefix-cmd\n"
> +gdb_expect {
> +    -re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
> +	send_gdb "echo defined command ghi-prefix-cmd\\n\nend\n"
> +	gdb_expect {
> +	    -re "$gdb_prompt $" {pass "define user command: ghi-prefix-cmd"}
> +	    timeout {fail "(timeout) define user command: ghi-prefix-cmd"}
> +	}
> +    }
> +    timeout {fail "(timeout) define user command: ghi-prefix-cmd"}
> +}
> +
> +# Verify ghi-prefix-cmd command works.
> +gdb_test "abc-prefix def-prefix ghi-prefix-cmd" \
> +    "defined command ghi-prefix-cmd" \
> +    "use defined user command: ghi-prefix-cmd"
> +
> +# Now redefine ghi-prefix-cmd, and check it is working.
>  send_gdb "define abc-prefix def-prefix ghi-prefix-cmd\n"
>  gdb_expect {
>      -re "Keeping subcommands of prefix command \"ghi-prefix-cmd\"\.\r\nRedefine command \"ghi-prefix-cmd\".*y or n. $" {
>  	send_gdb "y\n"
> -	    gdb_expect {
> -		-re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
> -		    send_gdb "echo redefined command ghi-prefix-cmd\\n\nend\n"
> -		    gdb_expect {
> -			-re "$gdb_prompt $" {pass "redefine user command: ghi-prefix-cmd"}
> -			timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
> -		    }
> +	gdb_expect {
> +	    -re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
> +		send_gdb "echo redefined command ghi-prefix-cmd\\n\nend\n"
> +		gdb_expect {
> +		    -re "$gdb_prompt $" {pass "redefine user command: ghi-prefix-cmd"}
> +		    timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
>  		}
> -		timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
>  	    }
> +	    timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
> +	}
>      }
> -    -re "$gdb_prompt $"	{fail "redefine user command: ghi-prefix-cmd"}
> +    -re "$gdb_prompt $" {fail "redefine user command: ghi-prefix-cmd"}
>      timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
>  }
>  
> -# Verify ghi-prefix-cmd command works.
> +# Verify redefined ghi-prefix-cmd command works.
>  gdb_test "abc-prefix def-prefix ghi-prefix-cmd" \
>      "redefined command ghi-prefix-cmd" \
>      "use redefined user command: ghi-prefix-cmd"
> 
> 
> 

Thanks, this version of the series LGTM.  You can push it, if others have
comments about the naming or behavior of the command, there's still time
to complain before the release.

Simon

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

* Re: [RFAv3 1/4] Implement user defined prefix.
  2019-11-28 20:09 ` [RFAv3 1/4] Implement user defined prefix Philippe Waroquiers
@ 2019-11-30  4:09   ` Simon Marchi
  0 siblings, 0 replies; 8+ messages in thread
From: Simon Marchi @ 2019-11-30  4:09 UTC (permalink / raw)
  To: Philippe Waroquiers, gdb-patches

On 2019-11-28 3:08 p.m., Philippe Waroquiers wrote:
> diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
> index 06cdcd6bfe..066a596fdc 100644
> --- a/gdb/cli/cli-script.c
> +++ b/gdb/cli/cli-script.c
> @@ -29,6 +29,7 @@
>  #include "cli/cli-cmds.h"
>  #include "cli/cli-decode.h"
>  #include "cli/cli-script.h"
> +#include "cli/cli-style.h"
>  
>  #include "extension.h"
>  #include "interps.h"
> @@ -1395,7 +1396,17 @@ do_define_command (const char *comname, int from_tty,
>        int q;
>  
>        if (c->theclass == class_user || c->theclass == class_alias)
> -	q = query (_("Redefine command \"%s\"? "), c->name);
> +	{
> +	  /* if C is a prefix command that was previously defined,
> +	     tell the user its subcommands will be kept, and ask
> +	     if ok to redefine the command.  */
> +	  if (c->prefixlist != nullptr)
> +	    q = c->user_commands.get () == nullptr
> +	      || query (_("Keeping subcommands of prefix command \"%s\".\n"
> +			  "Redefine command \"%s\"? "), c->name, c->name);

Just a nit here before you push, format the multi-line expression line like this, with
a parenthesis:

	    q = (c->user_commands.get () == nullptr
		 || query (_("Keeping subcommands of prefix command \"%s\".\n"
			     "Redefine command \"%s\"? "), c->name, c->name));

Simon

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

* Re: [RFAv3 0/4] More flexible user-defined commands prefixing and naming.
  2019-11-30  3:36 ` [RFAv3 0/4] More flexible user-defined commands prefixing and naming Simon Marchi
@ 2019-11-30  8:55   ` Philippe Waroquiers
  0 siblings, 0 replies; 8+ messages in thread
From: Philippe Waroquiers @ 2019-11-30  8:55 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On Fri, 2019-11-29 at 22:36 -0500, Simon Marchi wrote:
> Thanks, this version of the series LGTM.  You can push it, if others have
> comments about the naming or behavior of the command, there's still time
> to complain before the release.
Pushed after fixing the formatting comment and retest.
Thanks for the reviews
Philippe



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

end of thread, other threads:[~2019-11-30  8:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-28 20:09 [RFAv3 0/4] More flexible user-defined commands prefixing and naming Philippe Waroquiers
2019-11-28 20:09 ` [RFAv3 4/4] Document define-prefix command and the use of . in command names Philippe Waroquiers
2019-11-28 20:09 ` [RFAv3 2/4] Test define-prefix Philippe Waroquiers
2019-11-28 20:09 ` [RFAv3 1/4] Implement user defined prefix Philippe Waroquiers
2019-11-30  4:09   ` Simon Marchi
2019-11-28 20:09 ` [RFAv3 3/4] Allow . character as part of command names Philippe Waroquiers
2019-11-30  3:36 ` [RFAv3 0/4] More flexible user-defined commands prefixing and naming Simon Marchi
2019-11-30  8:55   ` Philippe Waroquiers

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).