Skip to content

Commit

Permalink
monitor: report entirety of hmp command on error
Browse files Browse the repository at this point in the history
When a user incorrectly provides an hmp command, an error response will be
printed that prompts the user to try "help <command name>". However, when
the command contains multiple parts e.g. "info uuid xyz", only the last
whitespace delimited string will be reported (in this example "info" will
be dropped and the message will read "Try "help uuid" for more information",
which is incorrect).

Let's correct this by capturing the entirety of the command from the command
line -- excluding any extraneous characters.

Reported-by: Mikhail Fokin <fokin@de.ibm.com>
Signed-off-by: Collin Walling <walling@linux.ibm.com>
Message-Id: <ee680f5e-ac9a-479d-f65e-9f8ae9cfe5d4@linux.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
  • Loading branch information
collinwalling authored and dagrh committed Jun 21, 2018
1 parent 46012db commit 317c52c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions monitor.c
Expand Up @@ -3431,6 +3431,7 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline)
{
QDict *qdict;
const mon_cmd_t *cmd;
const char *cmd_start = cmdline;

trace_handle_hmp_command(mon, cmdline);

Expand All @@ -3447,8 +3448,11 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline)

qdict = monitor_parse_arguments(mon, &cmdline, cmd);
if (!qdict) {
monitor_printf(mon, "Try \"help %s\" for more information\n",
cmd->name);
while (cmdline > cmd_start && qemu_isspace(cmdline[-1])) {
cmdline--;
}
monitor_printf(mon, "Try \"help %.*s\" for more information\n",
(int)(cmdline - cmd_start), cmd_start);
return;
}

Expand Down

0 comments on commit 317c52c

Please sign in to comment.