diff options
author | Gabriel Krisman Bertazi <gabriel@krisman.be> | 2014-09-07 20:12:19 -0300 |
---|---|---|
committer | Gabriel Krisman Bertazi <gabriel@krisman.be> | 2014-09-07 20:12:19 -0300 |
commit | a9f116cbf2fb9892ddbc46478b85ebfa99b0074f (patch) | |
tree | 9af6dfb3fe79fea2eef868d09d1538d48eeaa2a9 /gdb/cli | |
parent | c75bd3a23915c3122070a95e1974e323543ffbe4 (diff) | |
download | gdb-a9f116cbf2fb9892ddbc46478b85ebfa99b0074f.zip gdb-a9f116cbf2fb9892ddbc46478b85ebfa99b0074f.tar.gz gdb-a9f116cbf2fb9892ddbc46478b85ebfa99b0074f.tar.bz2 |
Fix PR gdb/17035: "show user" doesn't list user-defined commands that
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`.
Diffstat (limited to 'gdb/cli')
-rw-r--r-- | gdb/cli/cli-cmds.c | 5 | ||||
-rw-r--r-- | gdb/cli/cli-decode.c | 7 | ||||
-rw-r--r-- | gdb/cli/cli-decode.h | 5 | ||||
-rw-r--r-- | gdb/cli/cli-script.c | 4 |
4 files changed, 16 insertions, 5 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index b415267..b0f1bdf 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -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); } } diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index 7bc51a1..79d56db 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -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)); +} diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h index 5920559..5ed5fcd 100644 --- a/gdb/cli/cli-decode.h +++ b/gdb/cli/cli-decode.h @@ -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) */ 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); } |