diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index b415267..4f624f2 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -1245,8 +1245,9 @@ 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) + /* c->function.cfunc would be NULL if it's a python/scheme + command. */ + if (c->class != class_user || c->function.cfunc == NULL) error (_("Not a user command.")); show_user_1 (c, "", args, gdb_stdout); } @@ -1254,7 +1255,8 @@ show_user (char *args, int from_tty) { for (c = cmdlist; c; c = c->next) { - if (c->class == class_user || c->prefixlist != NULL) + if ((c->class == class_user && c->function.cfunc != NULL) + || c->prefixlist != NULL) show_user_1 (c, "", c->name, gdb_stdout); } } diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 0f0a97e..37cb82a 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -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); } diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp index 7363420..b2d1c76 100644 --- a/gdb/testsuite/gdb.base/commands.exp +++ b/gdb/testsuite/gdb.base/commands.exp @@ -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 an 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 emtpy command in user_defined_command_test" } proc watchpoint_command_test {} { diff --git a/gdb/testsuite/gdb.guile/scm-cmd.exp b/gdb/testsuite/gdb.guile/scm-cmd.exp index a407f63..36ef03d 100644 --- a/gdb/testsuite/gdb.guile/scm-cmd.exp +++ b/gdb/testsuite/gdb.guile/scm-cmd.exp @@ -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" \ diff --git a/gdb/testsuite/gdb.python/py-cmd.exp b/gdb/testsuite/gdb.python/py-cmd.exp index a87aecb..3ae4053 100644 --- a/gdb/testsuite/gdb.python/py-cmd.exp +++ b/gdb/testsuite/gdb.python/py-cmd.exp @@ -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" "" \