Fix PR gdb/17035: "show user" doesn't list user-defined commands that
authorGabriel Krisman Bertazi <gabriel@krisman.be>
Sun, 7 Sep 2014 23:12:19 +0000 (20:12 -0300)
committerGabriel Krisman Bertazi <gabriel@krisman.be>
Sun, 7 Sep 2014 23:12:19 +0000 (20:12 -0300)
have empty bodies.

User-defined commands that have empty bodies weren't being shown because
the print function returned too soon.  Now, it prints the command's name
before checking if it has any body at all.  This also fixes the same
problem on "show user <myemptycommand>", which wasn't being printed due
to a similar reason.

gdb/Changelog:

* cli/cli-cmds.c (show_user): Use cli_user_command_p to
decide whether we display the command on "show user".
* cli/cli-script.c (show_user_1): Only verify cmdlines after
printing command name.
* cli/cli-decode.h (cli_user_command_p): Declare new function.
* cli/cli-decode.c (cli_user_command_p): Create helper function
to verify whether cmd_list_element is a user-defined command.

gdb/testsuite/Changelog:

* gdb.base/commands.exp: Add tests to verify user-defined
commands with empty bodies.
* gdb.python/py-cmd.exp: Test that we don't show user-defined
python commands in `show user command`.
* gdb.python/scm-cmd.exp: Test that we don't show user-defined
scheme commands in `show user command`.

gdb/ChangeLog
gdb/cli/cli-cmds.c
gdb/cli/cli-decode.c
gdb/cli/cli-decode.h
gdb/cli/cli-script.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/commands.exp
gdb/testsuite/gdb.guile/scm-cmd.exp
gdb/testsuite/gdb.python/py-cmd.exp

index eb36ec5a9d1bc4dcb7e44327b40a16de823a3b69..59536c61a91e02ac22d0cdb0bcbe76135dd4e0f9 100644 (file)
@@ -1,3 +1,14 @@
+2014-09-07  Gabriel Krisman Bertazi  <gabriel@krisman.be>
+
+       PR gdb/17035
+       * cli/cli-cmds.c (show_user): Use cli_user_command_p to
+       decide whether we display the command on "show user".
+       * cli/cli-script.c (show_user_1): Only verify cmdlines after
+       printing command name.
+       * cli/cli-decode.h (cli_user_command_p): Declare new function.
+       * cli/cli-decode.c (cli_user_command_p): Create helper function
+       to verify whether cmd_list_element is a user-defined command.
+
 2014-09-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        PR python/17355
index b415267d888fcb2efe890c5a20b5ace65b4cb892..b0f1bdfa4d0168b2a09d1fdb18627e7d6e6cc019 100644 (file)
@@ -1245,8 +1245,7 @@ show_user (char *args, int from_tty)
       const char *comname = args;
 
       c = lookup_cmd (&comname, cmdlist, "", 0, 1);
-      /* c->user_commands would be NULL if it's a python/scheme command.  */
-      if (c->class != class_user || !c->user_commands)
+      if (!cli_user_command_p (c))
        error (_("Not a user command."));
       show_user_1 (c, "", args, gdb_stdout);
     }
@@ -1254,7 +1253,7 @@ show_user (char *args, int from_tty)
     {
       for (c = cmdlist; c; c = c->next)
        {
-         if (c->class == class_user || c->prefixlist != NULL)
+         if (cli_user_command_p (c) || c->prefixlist != NULL)
            show_user_1 (c, "", c->name, gdb_stdout);
        }
     }
index 7bc51a1b4d11e18bd00cbaa5f5f820f3be914e36..79d56db3a33d08d9180a655e8f4af9bea84ea83a 100644 (file)
@@ -1894,3 +1894,10 @@ cmd_func (struct cmd_list_element *cmd, char *args, int from_tty)
   else
     error (_("Invalid command"));
 }
+
+int
+cli_user_command_p (struct cmd_list_element *cmd)
+{
+  return (cmd->class == class_user
+         && (cmd->func == do_cfunc || cmd->func == do_sfunc));
+}
index 59205596ef947770e2519b3657076fae347299ad..5ed5fcd16d8b0fce0438c09aa7de264c30ab58a6 100644 (file)
@@ -242,4 +242,9 @@ extern void print_doc_line (struct ui_file *, const char *);
 
 extern const char * const auto_boolean_enums[];
 
+/* Verify whether a given cmd_list_element is a user-defined command.
+   Return 1 if it is user-defined.  Return 0 otherwise.  */
+
+extern int cli_user_command_p (struct cmd_list_element *);
+
 #endif /* !defined (CLI_DECODE_H) */
index 0f0a97e1be1c8c0accfeb83f5a3a57ec18e7963c..37cb82a45b256c4754f6de2c34d79c0d2e4a7911 100644 (file)
@@ -1717,10 +1717,10 @@ show_user_1 (struct cmd_list_element *c, const char *prefix, const char *name,
     }
 
   cmdlines = c->user_commands;
-  if (!cmdlines)
-    return;
   fprintf_filtered (stream, "User command \"%s%s\":\n", prefix, name);
 
+  if (!cmdlines)
+    return;
   print_command_lines (current_uiout, cmdlines, 1);
   fputs_filtered ("\n", stream);
 }
index a83d2b2955b301441c420f88e3f3cf825acac6b0..4d674590ea08474fe12378b92f2c7b4f3b07a313 100644 (file)
@@ -1,3 +1,13 @@
+2014-09-07  Gabriel Krisman Bertazi  <gabriel@krisman.be>
+
+       PR gdb/17035
+       * gdb.base/commands.exp: Add tests to verify user-defined
+       commands with empty bodies.
+       * gdb.python/py-cmd.exp: Test that we don't show user-defined
+       python commands in `show user command`.
+       * gdb.python/scm-cmd.exp: Test that we don't show user-defined
+       scheme commands in `show user command`.
+
 2014-09-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        PR python/17355
index 7363420af47a642102798b1e018023e160e6d51b..74eb3063e8595f59acca8d7a9296fa5aff61235b 100644 (file)
@@ -243,6 +243,28 @@ proc user_defined_command_test {} {
    gdb_test "show user mycommand" \
        "  while \\\$arg0.*set.*    if \\\(\\\$arg0.*p/x.*    else\[^\n\].*p/x.*    end\[^\n\].*  end\[^\n\].*" \
           "display user command in user_defined_command_test"
+
+    # Create and test a user-defined command with an empty body.
+    gdb_test_multiple "define myemptycommand" \
+       "define myemptycommand in user_defined_command_test" {
+           -re "End with"  {
+               pass "define myemptycommand in user_defined_command_test"
+           }
+       }
+    gdb_test "end" \
+       "" \
+       "end definition of user-defined command with empty body"
+
+    gdb_test_no_output "myemptycommand" \
+       "execute user-defined empty command in user_defined_command_test"
+
+    gdb_test "show user" \
+       "User command \"myemptycommand.*" \
+       "display empty command in command list in user_defined_command_test"
+
+    gdb_test "show user myemptycommand" \
+       "User command \"myemptycommand.*" \
+       "display user-defined empty command in user_defined_command_test"
 }
 
 proc watchpoint_command_test {} {
index a407f63c2cdcfe9282470dfb1faad9c2394b7d19..13ce9c2644d302574b899e2987d8aae6fc199ada 100644 (file)
@@ -134,6 +134,10 @@ gdb_test "help user-defined" \
     "User-defined commands.\[\r\n\]+The commands in this class are those defined by the user.\[\r\n\]+Use the \"define\" command to define a command.\[\r\n\]+List of commands:\[\r\n\]+test-help -- Docstring\[\r\n\]+Type \"help\" followed by command name for full documentation.\[\r\n\]+Type \"apropos word\" to search for commands related to \"word\".\[\r\n\]+Command name abbreviations are allowed if unambiguous.\[\r\n\]+" \
     "see user-defined command in `help user-defined`"
 
+# Make sure the command does not show up in `show user`.
+gdb_test "show user test-help" "Not a user command\." \
+    "don't show user-defined scheme command in `show user command`"
+
 # Test expression completion on fields.
 
 gdb_test_multiline "expression completion command" \
index a87aecba7a22d67fcf8bedebe1631c90c6a83c23..c84401f16edd6ac40265fe8776b043ecb670e38f 100644 (file)
@@ -161,6 +161,10 @@ gdb_test "test_help ugh" "test_cmd output, arg = ugh" "call simple user-defined
 # Make sure the command shows up in `help user-defined`.
 gdb_test "help user-defined" "User-defined commands.\[\r\n\]+The commands in this class are those defined by the user.\[\r\n\]+Use the \"define\" command to define a command.\[\r\n\]+\[\r\n\]+List of commands:\[\r\n\]+\[\r\n\]+test_help -- Docstring\[\r\n\]+\[\r\n\]+Type \"help\" followed by command name for full documentation.\[\r\n\]+Type \"apropos word\" to search for commands related to \"word\".\[\r\n\]+Command name abbreviations are allowed if unambiguous.\[\r\n\]+" "see user-defined command in `help user-defined`"
 
+# Make sure the command does not show up in `show user`.
+gdb_test "show user test_help" "Not a user command\." \
+    "don't show user-defined python command in `show user command`"
+
 # Test expression completion on fields
 gdb_py_test_multiple "expression completion command" \
   "python" "" \
This page took 0.036538 seconds and 4 git commands to generate.