Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Sergio Durigan Junior <sergiodj@redhat.com>
To: GDB Patches <gdb-patches@sourceware.org>
Cc: Pedro Alves <palves@redhat.com>,
	Simon Marchi <simon.marchi@polymtl.ca>,
	Jerome Guitton <guitton@adacore.com>,
	Sergio Durigan Junior <sergiodj@redhat.com>
Subject: [PATCH] PR cli/21688: Detect aliases when issuing python/compile/guile commands (and fix last commit)
Date: Fri, 30 Jun 2017 12:34:00 -0000	[thread overview]
Message-ID: <20170630123426.2124-1-sergiodj@redhat.com> (raw)
In-Reply-To: <2f8ebe75-29a9-71bb-008a-d4272441acac@redhat.com>

My last commit fixed a regression that happened when using
inline/multi-line commands for Python/Compile/Guile, but introduced
another regression: it is now not possible to use aliases for the
commands mentioned above.  The fix is to almost revert the change I've
made and go back to using the 'struct cmd_list_element *', but at the
same time make sure that we advance the 'cmd_name' variable past all
the whitespace characters after the command name.  If, after skipping
the whitespace, we encounter a '\0', it means that the command is not
inline.  Otherwise, it is.

This patch also expands the testcase in order to check for aliases and
for trailing whitespace after the command name.

gdb/ChangeLog:
2017-06-30  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	PR cli/21688
	* cli/cli-script.c (command_name_equals_not_inline): Remove function.
	(process_next_line): New variables 'lookup_cmd' and 'inline'.
	Adjust 'if' clauses for "python", "compile" and "guile" to use
	'command_name_equals' and check for '!inline'.

gdb/testsuite/ChangeLog:
2017-06-30  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR cli/21688
	* gdb.python/py-cmd.exp (test_python_inline_or_multiline): Add new
	tests for alias commands and trailing whitespace.
---
 gdb/ChangeLog                       |  9 +++++++++
 gdb/cli/cli-script.c                | 22 +++++-----------------
 gdb/testsuite/ChangeLog             |  6 ++++++
 gdb/testsuite/gdb.python/py-cmd.exp | 15 ++++++++++++++-
 4 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4cd7aad..b103438 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,4 +1,13 @@
 2017-06-30  Sergio Durigan Junior  <sergiodj@redhat.com>
+	    Pedro Alves  <palves@redhat.com>
+
+	PR cli/21688
+	* cli/cli-script.c (command_name_equals_not_inline): Remove function.
+	(process_next_line): New variables 'lookup_cmd' and 'inline'.
+	Adjust 'if' clauses for "python", "compile" and "guile" to use
+	'command_name_equals' and check for '!inline'.
+
+2017-06-30  Sergio Durigan Junior  <sergiodj@redhat.com>
 
 	PR cli/21688
 	* cli/cli-script.c (command_name_equals_not_inline): New function.
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 72f316f..7d5731c 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -900,20 +900,6 @@ command_name_equals (struct cmd_list_element *cmd, const char *name)
 	  && strcmp (cmd->name, name) == 0);
 }
 
-/* Return true if NAME is the only command between COMMAND_START and
-   COMMAND_END.  This is useful when we want to know whether the
-   command is inline (i.e., has arguments like 'python command1') or
-   is the start of a multi-line command block.  */
-
-static bool
-command_name_equals_not_inline (const char *command_start,
-				const char *command_end,
-				const char *name)
-{
-  return (command_end - command_start == strlen (name)
-	  && startswith (command_start, name));
-}
-
 /* Given an input line P, skip the command and return a pointer to the
    first argument.  */
 
@@ -966,6 +952,8 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
       const char *cmd_name = p;
       struct cmd_list_element *cmd
 	= lookup_cmd_1 (&cmd_name, cmdlist, NULL, 1);
+      const char *lookup_cmd = skip_spaces_const (cmd_name);
+      bool inline_cmd = *lookup_cmd != '\0';
 
       /* If commands are parsed, we skip initial spaces.  Otherwise,
 	 which is the case for Python commands and documentation
@@ -1011,20 +999,20 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
 	{
 	  *command = build_command_line (commands_control, line_first_arg (p));
 	}
-      else if (command_name_equals_not_inline (p_start, p_end, "python"))
+      else if (command_name_equals (cmd, "python") && !inline_cmd)
 	{
 	  /* Note that we ignore the inline "python command" form
 	     here.  */
 	  *command = build_command_line (python_control, "");
 	}
-      else if (command_name_equals_not_inline (p_start, p_end, "compile"))
+      else if (command_name_equals (cmd, "compile") && !inline_cmd)
 	{
 	  /* Note that we ignore the inline "compile command" form
 	     here.  */
 	  *command = build_command_line (compile_control, "");
 	  (*command)->control_u.compile.scope = COMPILE_I_INVALID_SCOPE;
 	}
-      else if (command_name_equals_not_inline (p_start, p_end, "guile"))
+      else if (command_name_equals (cmd, "guile") && !inline_cmd)
 	{
 	  /* Note that we ignore the inline "guile command" form here.  */
 	  *command = build_command_line (guile_control, "");
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 06bf5a4..6160c4b 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,6 +1,12 @@
 2017-06-30  Sergio Durigan Junior  <sergiodj@redhat.com>
 
 	PR cli/21688
+	* gdb.python/py-cmd.exp (test_python_inline_or_multiline): Add new
+	tests for alias commands and trailing whitespace.
+
+2017-06-30  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+	PR cli/21688
 	* gdb.python/py-cmd.exp (test_python_inline_or_multiline): New
 	procedure.  Call it.
 
diff --git a/gdb/testsuite/gdb.python/py-cmd.exp b/gdb/testsuite/gdb.python/py-cmd.exp
index 39bb785..287ecda 100644
--- a/gdb/testsuite/gdb.python/py-cmd.exp
+++ b/gdb/testsuite/gdb.python/py-cmd.exp
@@ -194,12 +194,25 @@ proc test_python_inline_or_multiline { } {
 	{ "end"                  " >$"            "multi-line first end" }
 	{ "end"                  "hello\r\n"      "multi-line last end" } }
 
+    # This also tests trailing whitespace on the command.
+    set define_cmd_alias_not_inline {
+	{ "if 1"                 " >$"            "multi-line if 1 alias" }
+	{ "py    "               " >$"            "multi-line python command alias" }
+	{ "print ('hello')"      "  >$"           "multi-line print alias" }
+	{ "end"                  " >$"            "multi-line first end alias" }
+	{ "end"                  "hello\r\n"      "multi-line last end alias" } }
+
     set define_cmd_inline {
 	{ "if 1"                      " >$"          "inline if 1" }
 	{ "python print ('hello')"    " >$"          "inline python command" }
 	{ "end"                       "hello\r\n"    "inline end" } }
 
-    foreach t [list $define_cmd_not_inline $define_cmd_inline] {
+    set define_cmd_alias_inline {
+	{ "if 1"                      " >$"          "inline if 1 alias" }
+	{ "py print ('hello')"    " >$"          "inline python command alias" }
+	{ "end"                       "hello\r\n"    "inline end alias" } }
+
+    foreach t [list $define_cmd_not_inline $define_cmd_alias_not_inline $define_cmd_inline $define_cmd_alias_inline] {
 	foreach l $t {
 	    lassign $l command regex testmsg
 	    gdb_test_multiple "$command" "$testmsg" {
-- 
2.9.3


  parent reply	other threads:[~2017-06-30 12:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-29  2:05 [PATCH] PR cli/21688: Fix multi-line/inline command differentiation Sergio Durigan Junior
2017-06-29 12:51 ` Jerome Guitton
2017-06-29 19:08 ` Simon Marchi
2017-06-29 19:48   ` Sergio Durigan Junior
2017-06-29 21:06     ` Simon Marchi
2017-06-29 22:21       ` Sergio Durigan Junior
2017-06-30  7:01         ` Simon Marchi
2017-06-30 11:16           ` Sergio Durigan Junior
2017-06-30 11:14         ` Pedro Alves
2017-06-30 11:24           ` Sergio Durigan Junior
2017-06-30 11:30             ` Pedro Alves
2017-06-30 12:33               ` Sergio Durigan Junior
2017-06-30 12:34               ` Sergio Durigan Junior [this message]
2017-06-30 13:02                 ` [PATCH] PR cli/21688: Detect aliases when issuing python/compile/guile commands (and fix last commit) Pedro Alves
2017-06-30 13:33                   ` Sergio Durigan Junior
2017-06-30 13:49                     ` Pedro Alves
2017-06-30 13:51                       ` Sergio Durigan Junior

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=20170630123426.2124-1-sergiodj@redhat.com \
    --to=sergiodj@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=guitton@adacore.com \
    --cc=palves@redhat.com \
    --cc=simon.marchi@polymtl.ca \
    /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