PR cli/21688: Detect aliases when issuing python/compile/guile commands (and fix...
authorSergio Durigan Junior <sergiodj@redhat.com>
Fri, 30 Jun 2017 12:27:29 +0000 (08:27 -0400)
committerSergio Durigan Junior <sergiodj@redhat.com>
Fri, 30 Jun 2017 13:31:21 +0000 (09:31 -0400)
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 variable 'inline_cmd'.
Adjust 'if' clauses for "python", "compile" and "guile" to use
'command_name_equals' and check for '!inline_cmd'.

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
gdb/cli/cli-script.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-cmd.exp

index 4cd7aadd10fc7a337dfce3d60e2e15186a044347..708025694cc366c3f086b6ad09dddf080aa48d7c 100644 (file)
@@ -1,3 +1,12 @@
+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 variable 'inline_cmd'.
+       Adjust 'if' clauses for "python", "compile" and "guile" to use
+       'command_name_equals' and check for '!inline_cmd'.
+
 2017-06-30  Sergio Durigan Junior  <sergiodj@redhat.com>
 
        PR cli/21688
index 72f316f86b825499f43da66d947375a17e2325a6..5674404cb623c04607cef09918b16ed7e9868ef0 100644 (file)
@@ -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);
+      cmd_name = skip_spaces_const (cmd_name);
+      bool inline_cmd = *cmd_name != '\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, "");
index 06bf5a4490554882400583a8d00e4d6dd24f3eda..6160c4b398b9bd29b0b9b00ea14b31d24c2b0f52 100644 (file)
@@ -1,3 +1,9 @@
+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
index 39bb7850c398b17d9d0153710a660fcbc20d15c5..953d52af4d146a18a42b3ba820ce3c4bcced9954 100644 (file)
@@ -187,6 +187,8 @@ gdb_test "complete expr_test bar\." \
 # This proc tests PR cli/21688.  The PR is not language-specific, but
 # the easiest way is just to test with Python.
 proc test_python_inline_or_multiline { } {
+    global gdb_prompt
+
     set define_cmd_not_inline {
        { "if 1"                 " >$"            "multi-line if 1" }
        { "python"               " >$"            "multi-line python command" }
@@ -194,12 +196,43 @@ 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_alias_foo_not_inline {
+       { "alias foo=python"     "\r\n"           "multi-line alias foo" }
+       { "if 1"                 " >$"            "multi-line if 1 alias foo" }
+       { "foo    "              " >$"            "multi-line python command alias foo" }
+       { "print ('hello')"      "  >$"           "multi-line print alias foo" }
+       { "end"                  " >$"            "multi-line first end alias foo" }
+       { "end"                  "hello\r\n"      "multi-line last end alias foo" } }
+
     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" } }
+
+    set define_cmd_alias_foo_inline {
+       { "if 1"                      " >$"          "inline if 1 alias foo" }
+       { "foo print ('hello')"       " >$"          "inline python command alias foo" }
+       { "end"                       "hello\r\n"    "inline end alias foo" } }
+
+    foreach t [list $define_cmd_not_inline \
+              $define_cmd_alias_not_inline \
+              $define_cmd_alias_foo_not_inline \
+              $define_cmd_inline \
+              $define_cmd_alias_inline \
+              $define_cmd_alias_foo_inline] {
        foreach l $t {
            lassign $l command regex testmsg
            gdb_test_multiple "$command" "$testmsg" {
This page took 0.035051 seconds and 4 git commands to generate.