aboutsummaryrefslogtreecommitdiff
path: root/monitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'monitor.c')
-rw-r--r--monitor.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/monitor.c b/monitor.c
index 3b9dbfbe6a..50ad7d15f2 100644
--- a/monitor.c
+++ b/monitor.c
@@ -186,6 +186,8 @@ typedef struct MonitorEventState {
QObject *data; /* Event pending delayed dispatch */
} MonitorEventState;
+typedef void MonitorErrorPrintFn(struct Monitor *mon, const char *fmt, ...);
+
struct Monitor {
CharDriverState *chr;
int mux_out;
@@ -204,6 +206,7 @@ struct Monitor {
QError *error;
const char *prompt;
const char *banner;
+ MonitorErrorPrintFn *print_error;
QLIST_HEAD(,mon_fd_t) fds;
QLIST_ENTRY(Monitor) entry;
};
@@ -3797,15 +3800,16 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
if (ret < 0) {
switch(c) {
case 'F':
- monitor_printf(mon, "%s: filename expected\n",
- cmdname);
+ mon->print_error(mon, "%s: filename expected\n",
+ cmdname);
break;
case 'B':
- monitor_printf(mon, "%s: block device name expected\n",
- cmdname);
+ mon->print_error(mon,
+ "%s: block device name expected\n",
+ cmdname);
break;
default:
- monitor_printf(mon, "%s: string expected\n", cmdname);
+ mon->print_error(mon, "%s: string expected\n", cmdname);
break;
}
goto fail;
@@ -3890,8 +3894,8 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
}
next:
if (*p != '\0' && !qemu_isspace(*p)) {
- monitor_printf(mon, "invalid char in format: '%c'\n",
- *p);
+ mon->print_error(mon, "invalid char in format: '%c'\n",
+ *p);
goto fail;
}
if (format < 0)
@@ -3947,12 +3951,12 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
goto fail;
/* Check if 'i' is greater than 32-bit */
if ((c == 'i') && ((val >> 32) & 0xffffffff)) {
- monitor_printf(mon, "\'%s\' has failed: ", cmdname);
- monitor_printf(mon, "integer is for 32-bit values\n");
+ mon->print_error(mon, "\'%s\' has failed: ", cmdname);
+ mon->print_error(mon, "integer is for 32-bit values\n");
goto fail;
} else if (c == 'M') {
if (val < 0) {
- monitor_printf(mon, "enter a positive value\n");
+ mon->print_error(mon, "enter a positive value\n");
goto fail;
}
val <<= 20;
@@ -3976,7 +3980,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
}
val = strtosz(p, &end);
if (val < 0) {
- monitor_printf(mon, "invalid size\n");
+ mon->print_error(mon, "invalid size\n");
goto fail;
}
qdict_put(qdict, key, qint_from_int(val));
@@ -4009,7 +4013,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
}
}
if (*p && !qemu_isspace(*p)) {
- monitor_printf(mon, "Unknown unit suffix\n");
+ mon->print_error(mon, "Unknown unit suffix\n");
goto fail;
}
qdict_put(qdict, key, qfloat_from_double(val));
@@ -4032,7 +4036,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
} else if (p - beg == 3 && !memcmp(beg, "off", p - beg)) {
val = 0;
} else {
- monitor_printf(mon, "Expected 'on' or 'off'\n");
+ mon->print_error(mon, "Expected 'on' or 'off'\n");
goto fail;
}
qdict_put(qdict, key, qbool_from_int(val));
@@ -4053,9 +4057,9 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
p++;
if(c != *p) {
if(!is_valid_option(p, typestr)) {
-
- monitor_printf(mon, "%s: unsupported option -%c\n",
- cmdname, *p);
+ mon->print_error(mon,
+ "%s: unsupported option -%c\n",
+ cmdname, *p);
goto fail;
} else {
skip_key = 1;
@@ -4088,8 +4092,8 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
}
len = strlen(p);
if (len <= 0) {
- monitor_printf(mon, "%s: string expected\n",
- cmdname);
+ mon->print_error(mon, "%s: string expected\n",
+ cmdname);
break;
}
qdict_put(qdict, key, qstring_from_str(p));
@@ -4098,7 +4102,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
break;
default:
bad_type:
- monitor_printf(mon, "%s: unknown type '%c'\n", cmdname, c);
+ mon->print_error(mon, "%s: unknown type '%c'\n", cmdname, c);
goto fail;
}
g_free(key);
@@ -4108,8 +4112,8 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
while (qemu_isspace(*p))
p++;
if (*p != '\0') {
- monitor_printf(mon, "%s: extraneous characters at the end of line\n",
- cmdname);
+ mon->print_error(mon, "%s: extraneous characters at the end of line\n",
+ cmdname);
goto fail;
}
@@ -5201,11 +5205,13 @@ void monitor_init(CharDriverState *chr, int flags)
mon->prompt = "(qemu) ";
mon->banner =
"QEMU " QEMU_VERSION " monitor - type 'help' for more information";
+ mon->print_error = monitor_printf;
if (flags & MONITOR_ANDROID_CONSOLE) {
mon->cmd_table = android_cmds;
mon->prompt = "";
mon->banner = "Android Console: type 'help' for a list of commands";
+ mon->print_error = android_monitor_print_error;
}
mon->chr = chr;