bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU monitor |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 4 | * Copyright (c) 2003-2004 Fabrice Bellard |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 5 | * |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 24 | #include <dirent.h> |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 25 | #include "hw/hw.h" |
Gerd Hoffmann | cae4956 | 2009-06-05 15:53:17 +0100 | [diff] [blame] | 26 | #include "hw/qdev.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 27 | #include "hw/usb.h" |
| 28 | #include "hw/pcmcia.h" |
| 29 | #include "hw/pc.h" |
| 30 | #include "hw/pci.h" |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 31 | #include "hw/watchdog.h" |
Gerd Hoffmann | 45a50b1 | 2009-10-01 16:42:33 +0200 | [diff] [blame] | 32 | #include "hw/loader.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 33 | #include "gdbstub.h" |
| 34 | #include "net.h" |
Mark McLoughlin | 68ac40d | 2009-11-25 18:48:54 +0000 | [diff] [blame] | 35 | #include "net/slirp.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 36 | #include "qemu-char.h" |
| 37 | #include "sysemu.h" |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 38 | #include "monitor.h" |
| 39 | #include "readline.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 40 | #include "console.h" |
| 41 | #include "block.h" |
| 42 | #include "audio/audio.h" |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 43 | #include "disas.h" |
aliguori | df751fa | 2008-12-04 20:19:35 +0000 | [diff] [blame] | 44 | #include "balloon.h" |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 45 | #include "qemu-timer.h" |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 46 | #include "migration.h" |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 47 | #include "kvm.h" |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 48 | #include "acl.h" |
Luiz Capitulino | f7188bb | 2009-08-28 15:27:10 -0300 | [diff] [blame] | 49 | #include "qint.h" |
Markus Armbruster | 3350a4d | 2010-01-25 14:23:03 +0100 | [diff] [blame] | 50 | #include "qfloat.h" |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 51 | #include "qlist.h" |
Luiz Capitulino | f7188bb | 2009-08-28 15:27:10 -0300 | [diff] [blame] | 52 | #include "qdict.h" |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 53 | #include "qbool.h" |
Luiz Capitulino | f7188bb | 2009-08-28 15:27:10 -0300 | [diff] [blame] | 54 | #include "qstring.h" |
Luiz Capitulino | 8204a91 | 2009-11-18 23:05:31 -0200 | [diff] [blame] | 55 | #include "qerror.h" |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 56 | #include "qjson.h" |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 57 | #include "json-streamer.h" |
| 58 | #include "json-parser.h" |
Blue Swirl | d08d6f0 | 2009-12-04 18:06:39 +0000 | [diff] [blame] | 59 | #include "osdep.h" |
ths | 6a5bd30 | 2007-12-03 17:05:38 +0000 | [diff] [blame] | 60 | |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 61 | //#define DEBUG |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 62 | //#define DEBUG_COMPLETION |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 63 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 64 | /* |
| 65 | * Supported types: |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 66 | * |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 67 | * 'F' filename |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 68 | * 'B' block device name |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 69 | * 's' string (accept optional quote) |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 70 | * 'i' 32 bit integer |
| 71 | * 'l' target long (32 or 64 bit) |
Markus Armbruster | 9fec543 | 2010-01-25 14:23:01 +0100 | [diff] [blame] | 72 | * 'M' just like 'l', except in user mode the value is |
| 73 | * multiplied by 2^20 (think Mebibyte) |
Markus Armbruster | 3350a4d | 2010-01-25 14:23:03 +0100 | [diff] [blame] | 74 | * 'b' double |
| 75 | * user mode accepts an optional G, g, M, m, K, k suffix, |
| 76 | * which multiplies the value by 2^30 for suffixes G and |
| 77 | * g, 2^20 for M and m, 2^10 for K and k |
Markus Armbruster | fccfb11e | 2010-01-25 14:23:06 +0100 | [diff] [blame] | 78 | * 'T' double |
| 79 | * user mode accepts an optional ms, us, ns suffix, |
| 80 | * which divides the value by 1e3, 1e6, 1e9, respectively |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 81 | * '/' optional gdb-like print format (like "/10x") |
| 82 | * |
Luiz Capitulino | fb46660 | 2009-08-28 15:27:27 -0300 | [diff] [blame] | 83 | * '?' optional type (for all types, except '/') |
| 84 | * '.' other form of optional type (for 'i' and 'l') |
| 85 | * '-' optional parameter (eg. '-f') |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 86 | * |
| 87 | */ |
| 88 | |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 89 | typedef struct MonitorCompletionData MonitorCompletionData; |
| 90 | struct MonitorCompletionData { |
| 91 | Monitor *mon; |
| 92 | void (*user_print)(Monitor *mon, const QObject *data); |
| 93 | }; |
| 94 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 95 | typedef struct mon_cmd_t { |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 96 | const char *name; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 97 | const char *args_type; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 98 | const char *params; |
| 99 | const char *help; |
Luiz Capitulino | a2876f5 | 2009-10-07 13:41:53 -0300 | [diff] [blame] | 100 | void (*user_print)(Monitor *mon, const QObject *data); |
Luiz Capitulino | 97536cf | 2010-02-10 23:49:47 -0200 | [diff] [blame] | 101 | int (*cmd_new_ret)(Monitor *mon, const QDict *params, QObject **ret_data); |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 102 | union { |
| 103 | void (*info)(Monitor *mon); |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 104 | void (*info_new)(Monitor *mon, QObject **ret_data); |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 105 | int (*info_async)(Monitor *mon, MonitorCompletion *cb, void *opaque); |
Luiz Capitulino | af4ce88 | 2009-10-07 13:41:52 -0300 | [diff] [blame] | 106 | void (*cmd)(Monitor *mon, const QDict *qdict); |
Luiz Capitulino | 13917be | 2009-10-07 13:41:54 -0300 | [diff] [blame] | 107 | void (*cmd_new)(Monitor *mon, const QDict *params, QObject **ret_data); |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 108 | int (*cmd_async)(Monitor *mon, const QDict *params, |
| 109 | MonitorCompletion *cb, void *opaque); |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 110 | } mhandler; |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 111 | int async; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 112 | } mon_cmd_t; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 113 | |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 114 | /* file descriptors passed via SCM_RIGHTS */ |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 115 | typedef struct mon_fd_t mon_fd_t; |
| 116 | struct mon_fd_t { |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 117 | char *name; |
| 118 | int fd; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 119 | QLIST_ENTRY(mon_fd_t) next; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 120 | }; |
| 121 | |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 122 | typedef struct MonitorControl { |
| 123 | QObject *id; |
Luiz Capitulino | 4a29a85 | 2009-11-26 22:59:05 -0200 | [diff] [blame] | 124 | int print_enabled; |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 125 | JSONMessageParser parser; |
Luiz Capitulino | 4a7e119 | 2010-02-04 18:10:05 -0200 | [diff] [blame] | 126 | int command_mode; |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 127 | } MonitorControl; |
| 128 | |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 129 | struct Monitor { |
| 130 | CharDriverState *chr; |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 131 | int mux_out; |
| 132 | int reset_seen; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 133 | int flags; |
| 134 | int suspend_cnt; |
| 135 | uint8_t outbuf[1024]; |
| 136 | int outbuf_index; |
| 137 | ReadLineState *rs; |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 138 | MonitorControl *mc; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 139 | CPUState *mon_cpu; |
| 140 | BlockDriverCompletionFunc *password_completion_cb; |
| 141 | void *password_opaque; |
Luiz Capitulino | 8204a91 | 2009-11-18 23:05:31 -0200 | [diff] [blame] | 142 | QError *error; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 143 | QLIST_HEAD(,mon_fd_t) fds; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 144 | QLIST_ENTRY(Monitor) entry; |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 145 | }; |
| 146 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 147 | static QLIST_HEAD(mon_list, Monitor) mon_list; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 148 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 149 | static const mon_cmd_t mon_cmds[]; |
| 150 | static const mon_cmd_t info_cmds[]; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 151 | |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 152 | Monitor *cur_mon = NULL; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 153 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 154 | static void monitor_command_cb(Monitor *mon, const char *cmdline, |
| 155 | void *opaque); |
aliguori | 83ab795 | 2008-08-19 14:44:22 +0000 | [diff] [blame] | 156 | |
Luiz Capitulino | 09069b1 | 2010-02-04 18:10:06 -0200 | [diff] [blame] | 157 | static inline int qmp_cmd_mode(const Monitor *mon) |
| 158 | { |
| 159 | return (mon->mc ? mon->mc->command_mode : 0); |
| 160 | } |
| 161 | |
Luiz Capitulino | 418173c | 2009-11-26 22:58:51 -0200 | [diff] [blame] | 162 | /* Return true if in control mode, false otherwise */ |
| 163 | static inline int monitor_ctrl_mode(const Monitor *mon) |
| 164 | { |
| 165 | return (mon->flags & MONITOR_USE_CONTROL); |
| 166 | } |
| 167 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 168 | static void monitor_read_command(Monitor *mon, int show_prompt) |
| 169 | { |
Luiz Capitulino | 183e6e5 | 2009-12-14 18:53:23 -0200 | [diff] [blame] | 170 | if (!mon->rs) |
| 171 | return; |
| 172 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 173 | readline_start(mon->rs, "(qemu) ", 0, monitor_command_cb, NULL); |
| 174 | if (show_prompt) |
| 175 | readline_show_prompt(mon->rs); |
| 176 | } |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 177 | |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 178 | static int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, |
| 179 | void *opaque) |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 180 | { |
Luiz Capitulino | 94171e1 | 2009-12-07 21:37:00 +0100 | [diff] [blame] | 181 | if (monitor_ctrl_mode(mon)) { |
| 182 | qemu_error_new(QERR_MISSING_PARAMETER, "password"); |
| 183 | return -EINVAL; |
| 184 | } else if (mon->rs) { |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 185 | readline_start(mon->rs, "Password: ", 1, readline_func, opaque); |
| 186 | /* prompt is printed on return from the command handler */ |
| 187 | return 0; |
| 188 | } else { |
| 189 | monitor_printf(mon, "terminal does not support password prompting\n"); |
| 190 | return -ENOTTY; |
| 191 | } |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 192 | } |
| 193 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 194 | void monitor_flush(Monitor *mon) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 195 | { |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 196 | if (mon && mon->outbuf_index != 0 && !mon->mux_out) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 197 | qemu_chr_write(mon->chr, mon->outbuf, mon->outbuf_index); |
| 198 | mon->outbuf_index = 0; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | |
| 202 | /* flush at every end of line or if the buffer is full */ |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 203 | static void monitor_puts(Monitor *mon, const char *str) |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 204 | { |
ths | 60fe76f | 2007-12-16 03:02:09 +0000 | [diff] [blame] | 205 | char c; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 206 | |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 207 | for(;;) { |
| 208 | c = *str++; |
| 209 | if (c == '\0') |
| 210 | break; |
bellard | 7ba1260 | 2006-07-14 20:26:42 +0000 | [diff] [blame] | 211 | if (c == '\n') |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 212 | mon->outbuf[mon->outbuf_index++] = '\r'; |
| 213 | mon->outbuf[mon->outbuf_index++] = c; |
| 214 | if (mon->outbuf_index >= (sizeof(mon->outbuf) - 1) |
| 215 | || c == '\n') |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 216 | monitor_flush(mon); |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 220 | void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 221 | { |
Luiz Capitulino | 2daa119 | 2009-12-14 18:53:24 -0200 | [diff] [blame] | 222 | if (!mon) |
| 223 | return; |
| 224 | |
Luiz Capitulino | 4a29a85 | 2009-11-26 22:59:05 -0200 | [diff] [blame] | 225 | if (mon->mc && !mon->mc->print_enabled) { |
| 226 | qemu_error_new(QERR_UNDEFINED_ERROR); |
| 227 | } else { |
| 228 | char buf[4096]; |
| 229 | vsnprintf(buf, sizeof(buf), fmt, ap); |
| 230 | monitor_puts(mon, buf); |
| 231 | } |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 232 | } |
| 233 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 234 | void monitor_printf(Monitor *mon, const char *fmt, ...) |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 235 | { |
| 236 | va_list ap; |
| 237 | va_start(ap, fmt); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 238 | monitor_vprintf(mon, fmt, ap); |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 239 | va_end(ap); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 240 | } |
| 241 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 242 | void monitor_print_filename(Monitor *mon, const char *filename) |
ths | fef3074 | 2006-12-22 14:11:32 +0000 | [diff] [blame] | 243 | { |
| 244 | int i; |
| 245 | |
| 246 | for (i = 0; filename[i]; i++) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 247 | switch (filename[i]) { |
| 248 | case ' ': |
| 249 | case '"': |
| 250 | case '\\': |
| 251 | monitor_printf(mon, "\\%c", filename[i]); |
| 252 | break; |
| 253 | case '\t': |
| 254 | monitor_printf(mon, "\\t"); |
| 255 | break; |
| 256 | case '\r': |
| 257 | monitor_printf(mon, "\\r"); |
| 258 | break; |
| 259 | case '\n': |
| 260 | monitor_printf(mon, "\\n"); |
| 261 | break; |
| 262 | default: |
| 263 | monitor_printf(mon, "%c", filename[i]); |
| 264 | break; |
| 265 | } |
ths | fef3074 | 2006-12-22 14:11:32 +0000 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 269 | static int monitor_fprintf(FILE *stream, const char *fmt, ...) |
| 270 | { |
| 271 | va_list ap; |
| 272 | va_start(ap, fmt); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 273 | monitor_vprintf((Monitor *)stream, fmt, ap); |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 274 | va_end(ap); |
| 275 | return 0; |
| 276 | } |
| 277 | |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 278 | static void monitor_user_noop(Monitor *mon, const QObject *data) { } |
| 279 | |
Luiz Capitulino | 13917be | 2009-10-07 13:41:54 -0300 | [diff] [blame] | 280 | static inline int monitor_handler_ported(const mon_cmd_t *cmd) |
| 281 | { |
| 282 | return cmd->user_print != NULL; |
| 283 | } |
| 284 | |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 285 | static inline bool monitor_handler_is_async(const mon_cmd_t *cmd) |
| 286 | { |
| 287 | return cmd->async != 0; |
| 288 | } |
| 289 | |
Luiz Capitulino | 8204a91 | 2009-11-18 23:05:31 -0200 | [diff] [blame] | 290 | static inline int monitor_has_error(const Monitor *mon) |
| 291 | { |
| 292 | return mon->error != NULL; |
| 293 | } |
| 294 | |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 295 | static void monitor_json_emitter(Monitor *mon, const QObject *data) |
| 296 | { |
| 297 | QString *json; |
| 298 | |
| 299 | json = qobject_to_json(data); |
| 300 | assert(json != NULL); |
| 301 | |
Luiz Capitulino | 4a29a85 | 2009-11-26 22:59:05 -0200 | [diff] [blame] | 302 | mon->mc->print_enabled = 1; |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 303 | monitor_printf(mon, "%s\n", qstring_get_str(json)); |
Luiz Capitulino | 4a29a85 | 2009-11-26 22:59:05 -0200 | [diff] [blame] | 304 | mon->mc->print_enabled = 0; |
| 305 | |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 306 | QDECREF(json); |
| 307 | } |
| 308 | |
Luiz Capitulino | 25b422e | 2009-11-26 22:58:59 -0200 | [diff] [blame] | 309 | static void monitor_protocol_emitter(Monitor *mon, QObject *data) |
| 310 | { |
| 311 | QDict *qmp; |
| 312 | |
| 313 | qmp = qdict_new(); |
| 314 | |
| 315 | if (!monitor_has_error(mon)) { |
| 316 | /* success response */ |
| 317 | if (data) { |
| 318 | qobject_incref(data); |
| 319 | qdict_put_obj(qmp, "return", data); |
| 320 | } else { |
Luiz Capitulino | 0abc657 | 2009-12-18 13:25:00 -0200 | [diff] [blame] | 321 | /* return an empty QDict by default */ |
| 322 | qdict_put(qmp, "return", qdict_new()); |
Luiz Capitulino | 25b422e | 2009-11-26 22:58:59 -0200 | [diff] [blame] | 323 | } |
| 324 | } else { |
| 325 | /* error response */ |
Markus Armbruster | 77e595e | 2009-12-07 21:37:16 +0100 | [diff] [blame] | 326 | qdict_put(mon->error->error, "desc", qerror_human(mon->error)); |
Luiz Capitulino | 25b422e | 2009-11-26 22:58:59 -0200 | [diff] [blame] | 327 | qdict_put(qmp, "error", mon->error->error); |
| 328 | QINCREF(mon->error->error); |
| 329 | QDECREF(mon->error); |
| 330 | mon->error = NULL; |
| 331 | } |
| 332 | |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 333 | if (mon->mc->id) { |
| 334 | qdict_put_obj(qmp, "id", mon->mc->id); |
| 335 | mon->mc->id = NULL; |
| 336 | } |
| 337 | |
Luiz Capitulino | 25b422e | 2009-11-26 22:58:59 -0200 | [diff] [blame] | 338 | monitor_json_emitter(mon, QOBJECT(qmp)); |
| 339 | QDECREF(qmp); |
| 340 | } |
| 341 | |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 342 | static void timestamp_put(QDict *qdict) |
| 343 | { |
| 344 | int err; |
| 345 | QObject *obj; |
Blue Swirl | d08d6f0 | 2009-12-04 18:06:39 +0000 | [diff] [blame] | 346 | qemu_timeval tv; |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 347 | |
Blue Swirl | d08d6f0 | 2009-12-04 18:06:39 +0000 | [diff] [blame] | 348 | err = qemu_gettimeofday(&tv); |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 349 | if (err < 0) |
| 350 | return; |
| 351 | |
| 352 | obj = qobject_from_jsonf("{ 'seconds': %" PRId64 ", " |
| 353 | "'microseconds': %" PRId64 " }", |
| 354 | (int64_t) tv.tv_sec, (int64_t) tv.tv_usec); |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 355 | qdict_put_obj(qdict, "timestamp", obj); |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * monitor_protocol_event(): Generate a Monitor event |
| 360 | * |
| 361 | * Event-specific data can be emitted through the (optional) 'data' parameter. |
| 362 | */ |
| 363 | void monitor_protocol_event(MonitorEvent event, QObject *data) |
| 364 | { |
| 365 | QDict *qmp; |
| 366 | const char *event_name; |
Adam Litke | f039a56 | 2010-01-15 08:34:02 -0600 | [diff] [blame] | 367 | Monitor *mon; |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 368 | |
Blue Swirl | 242cd00 | 2009-12-04 18:05:45 +0000 | [diff] [blame] | 369 | assert(event < QEVENT_MAX); |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 370 | |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 371 | switch (event) { |
Blue Swirl | 242cd00 | 2009-12-04 18:05:45 +0000 | [diff] [blame] | 372 | case QEVENT_DEBUG: |
Luiz Capitulino | b1a15e7 | 2009-11-26 22:59:04 -0200 | [diff] [blame] | 373 | event_name = "DEBUG"; |
| 374 | break; |
Blue Swirl | 242cd00 | 2009-12-04 18:05:45 +0000 | [diff] [blame] | 375 | case QEVENT_SHUTDOWN: |
Luiz Capitulino | b1a15e7 | 2009-11-26 22:59:04 -0200 | [diff] [blame] | 376 | event_name = "SHUTDOWN"; |
| 377 | break; |
Blue Swirl | 242cd00 | 2009-12-04 18:05:45 +0000 | [diff] [blame] | 378 | case QEVENT_RESET: |
Luiz Capitulino | b1a15e7 | 2009-11-26 22:59:04 -0200 | [diff] [blame] | 379 | event_name = "RESET"; |
| 380 | break; |
Blue Swirl | 242cd00 | 2009-12-04 18:05:45 +0000 | [diff] [blame] | 381 | case QEVENT_POWERDOWN: |
Luiz Capitulino | b1a15e7 | 2009-11-26 22:59:04 -0200 | [diff] [blame] | 382 | event_name = "POWERDOWN"; |
| 383 | break; |
Blue Swirl | 242cd00 | 2009-12-04 18:05:45 +0000 | [diff] [blame] | 384 | case QEVENT_STOP: |
Luiz Capitulino | b1a15e7 | 2009-11-26 22:59:04 -0200 | [diff] [blame] | 385 | event_name = "STOP"; |
| 386 | break; |
Luiz Capitulino | 586153d | 2010-01-14 14:50:57 -0200 | [diff] [blame] | 387 | case QEVENT_VNC_CONNECTED: |
| 388 | event_name = "VNC_CONNECTED"; |
| 389 | break; |
Luiz Capitulino | 0d2ed46 | 2010-01-14 14:50:59 -0200 | [diff] [blame] | 390 | case QEVENT_VNC_INITIALIZED: |
| 391 | event_name = "VNC_INITIALIZED"; |
| 392 | break; |
Luiz Capitulino | 0d72f3d | 2010-01-14 14:50:58 -0200 | [diff] [blame] | 393 | case QEVENT_VNC_DISCONNECTED: |
| 394 | event_name = "VNC_DISCONNECTED"; |
| 395 | break; |
Luiz Capitulino | aa1db6e | 2010-02-03 12:41:00 -0200 | [diff] [blame] | 396 | case QEVENT_BLOCK_IO_ERROR: |
| 397 | event_name = "BLOCK_IO_ERROR"; |
| 398 | break; |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 399 | default: |
| 400 | abort(); |
| 401 | break; |
| 402 | } |
| 403 | |
| 404 | qmp = qdict_new(); |
| 405 | timestamp_put(qmp); |
| 406 | qdict_put(qmp, "event", qstring_from_str(event_name)); |
Luiz Capitulino | 3d72f9a | 2010-01-08 16:45:53 -0200 | [diff] [blame] | 407 | if (data) { |
| 408 | qobject_incref(data); |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 409 | qdict_put_obj(qmp, "data", data); |
Luiz Capitulino | 3d72f9a | 2010-01-08 16:45:53 -0200 | [diff] [blame] | 410 | } |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 411 | |
Adam Litke | f039a56 | 2010-01-15 08:34:02 -0600 | [diff] [blame] | 412 | QLIST_FOREACH(mon, &mon_list, entry) { |
Luiz Capitulino | 09069b1 | 2010-02-04 18:10:06 -0200 | [diff] [blame] | 413 | if (monitor_ctrl_mode(mon) && qmp_cmd_mode(mon)) { |
Luiz Capitulino | 23fabed | 2010-01-20 10:37:59 -0200 | [diff] [blame] | 414 | monitor_json_emitter(mon, QOBJECT(qmp)); |
| 415 | } |
Adam Litke | f039a56 | 2010-01-15 08:34:02 -0600 | [diff] [blame] | 416 | } |
Luiz Capitulino | 0d1ea87 | 2009-11-26 22:59:03 -0200 | [diff] [blame] | 417 | QDECREF(qmp); |
| 418 | } |
| 419 | |
Luiz Capitulino | ef4b7ee | 2010-02-10 23:49:48 -0200 | [diff] [blame] | 420 | static int do_qmp_capabilities(Monitor *mon, const QDict *params, |
| 421 | QObject **ret_data) |
Luiz Capitulino | 4a7e119 | 2010-02-04 18:10:05 -0200 | [diff] [blame] | 422 | { |
| 423 | /* Will setup QMP capabilities in the future */ |
| 424 | if (monitor_ctrl_mode(mon)) { |
| 425 | mon->mc->command_mode = 1; |
| 426 | } |
Luiz Capitulino | ef4b7ee | 2010-02-10 23:49:48 -0200 | [diff] [blame] | 427 | |
| 428 | return 0; |
Luiz Capitulino | 4a7e119 | 2010-02-04 18:10:05 -0200 | [diff] [blame] | 429 | } |
| 430 | |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 431 | static int compare_cmd(const char *name, const char *list) |
| 432 | { |
| 433 | const char *p, *pstart; |
| 434 | int len; |
| 435 | len = strlen(name); |
| 436 | p = list; |
| 437 | for(;;) { |
| 438 | pstart = p; |
| 439 | p = strchr(p, '|'); |
| 440 | if (!p) |
| 441 | p = pstart + strlen(pstart); |
| 442 | if ((p - pstart) == len && !memcmp(pstart, name, len)) |
| 443 | return 1; |
| 444 | if (*p == '\0') |
| 445 | break; |
| 446 | p++; |
| 447 | } |
| 448 | return 0; |
| 449 | } |
| 450 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 451 | static void help_cmd_dump(Monitor *mon, const mon_cmd_t *cmds, |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 452 | const char *prefix, const char *name) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 453 | { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 454 | const mon_cmd_t *cmd; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 455 | |
| 456 | for(cmd = cmds; cmd->name != NULL; cmd++) { |
| 457 | if (!name || !strcmp(name, cmd->name)) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 458 | monitor_printf(mon, "%s%s %s -- %s\n", prefix, cmd->name, |
| 459 | cmd->params, cmd->help); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 463 | static void help_cmd(Monitor *mon, const char *name) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 464 | { |
| 465 | if (name && !strcmp(name, "info")) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 466 | help_cmd_dump(mon, info_cmds, "info ", NULL); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 467 | } else { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 468 | help_cmd_dump(mon, mon_cmds, "", name); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 469 | if (name && !strcmp(name, "log")) { |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 470 | const CPULogItem *item; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 471 | monitor_printf(mon, "Log items (comma separated):\n"); |
| 472 | monitor_printf(mon, "%-10s %s\n", "none", "remove all logs"); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 473 | for(item = cpu_log_items; item->mask != 0; item++) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 474 | monitor_printf(mon, "%-10s %s\n", item->name, item->help); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 475 | } |
| 476 | } |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 480 | static void do_help_cmd(Monitor *mon, const QDict *qdict) |
Luiz Capitulino | 3818318 | 2009-08-28 15:27:08 -0300 | [diff] [blame] | 481 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 482 | help_cmd(mon, qdict_get_try_str(qdict, "name")); |
Luiz Capitulino | 3818318 | 2009-08-28 15:27:08 -0300 | [diff] [blame] | 483 | } |
| 484 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 485 | static void do_commit(Monitor *mon, const QDict *qdict) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 486 | { |
Gerd Hoffmann | 751c6a1 | 2009-07-22 16:42:57 +0200 | [diff] [blame] | 487 | int all_devices; |
| 488 | DriveInfo *dinfo; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 489 | const char *device = qdict_get_str(qdict, "device"); |
balrog | 2dc7b60 | 2007-05-24 18:53:22 +0000 | [diff] [blame] | 490 | |
bellard | 7954c73 | 2006-08-01 15:52:40 +0000 | [diff] [blame] | 491 | all_devices = !strcmp(device, "all"); |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 492 | QTAILQ_FOREACH(dinfo, &drives, next) { |
Gerd Hoffmann | 751c6a1 | 2009-07-22 16:42:57 +0200 | [diff] [blame] | 493 | if (!all_devices) |
Luiz Capitulino | 73006d2 | 2009-07-31 15:15:41 -0300 | [diff] [blame] | 494 | if (strcmp(bdrv_get_device_name(dinfo->bdrv), device)) |
Gerd Hoffmann | 751c6a1 | 2009-07-22 16:42:57 +0200 | [diff] [blame] | 495 | continue; |
| 496 | bdrv_commit(dinfo->bdrv); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 500 | static void user_monitor_complete(void *opaque, QObject *ret_data) |
| 501 | { |
| 502 | MonitorCompletionData *data = (MonitorCompletionData *)opaque; |
| 503 | |
| 504 | if (ret_data) { |
| 505 | data->user_print(data->mon, ret_data); |
| 506 | } |
| 507 | monitor_resume(data->mon); |
| 508 | qemu_free(data); |
| 509 | } |
| 510 | |
| 511 | static void qmp_monitor_complete(void *opaque, QObject *ret_data) |
| 512 | { |
| 513 | monitor_protocol_emitter(opaque, ret_data); |
| 514 | } |
| 515 | |
| 516 | static void qmp_async_cmd_handler(Monitor *mon, const mon_cmd_t *cmd, |
| 517 | const QDict *params) |
| 518 | { |
| 519 | cmd->mhandler.cmd_async(mon, params, qmp_monitor_complete, mon); |
| 520 | } |
| 521 | |
| 522 | static void qmp_async_info_handler(Monitor *mon, const mon_cmd_t *cmd) |
| 523 | { |
| 524 | cmd->mhandler.info_async(mon, qmp_monitor_complete, mon); |
| 525 | } |
| 526 | |
| 527 | static void user_async_cmd_handler(Monitor *mon, const mon_cmd_t *cmd, |
| 528 | const QDict *params) |
| 529 | { |
| 530 | int ret; |
| 531 | |
| 532 | MonitorCompletionData *cb_data = qemu_malloc(sizeof(*cb_data)); |
| 533 | cb_data->mon = mon; |
| 534 | cb_data->user_print = cmd->user_print; |
| 535 | monitor_suspend(mon); |
| 536 | ret = cmd->mhandler.cmd_async(mon, params, |
| 537 | user_monitor_complete, cb_data); |
| 538 | if (ret < 0) { |
| 539 | monitor_resume(mon); |
| 540 | qemu_free(cb_data); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | static void user_async_info_handler(Monitor *mon, const mon_cmd_t *cmd) |
| 545 | { |
| 546 | int ret; |
| 547 | |
| 548 | MonitorCompletionData *cb_data = qemu_malloc(sizeof(*cb_data)); |
| 549 | cb_data->mon = mon; |
| 550 | cb_data->user_print = cmd->user_print; |
| 551 | monitor_suspend(mon); |
| 552 | ret = cmd->mhandler.info_async(mon, user_monitor_complete, cb_data); |
| 553 | if (ret < 0) { |
| 554 | monitor_resume(mon); |
| 555 | qemu_free(cb_data); |
| 556 | } |
| 557 | } |
| 558 | |
Luiz Capitulino | 4fdc94b | 2010-02-10 23:50:00 -0200 | [diff] [blame] | 559 | static int do_info(Monitor *mon, const QDict *qdict, QObject **ret_data) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 560 | { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 561 | const mon_cmd_t *cmd; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 562 | const char *item = qdict_get_try_str(qdict, "item"); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 563 | |
Luiz Capitulino | 956f1a0 | 2009-11-26 22:59:00 -0200 | [diff] [blame] | 564 | if (!item) { |
| 565 | assert(monitor_ctrl_mode(mon) == 0); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 566 | goto help; |
Luiz Capitulino | 956f1a0 | 2009-11-26 22:59:00 -0200 | [diff] [blame] | 567 | } |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 568 | |
| 569 | for (cmd = info_cmds; cmd->name != NULL; cmd++) { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 570 | if (compare_cmd(item, cmd->name)) |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 571 | break; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 572 | } |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 573 | |
Luiz Capitulino | 956f1a0 | 2009-11-26 22:59:00 -0200 | [diff] [blame] | 574 | if (cmd->name == NULL) { |
| 575 | if (monitor_ctrl_mode(mon)) { |
| 576 | qemu_error_new(QERR_COMMAND_NOT_FOUND, item); |
Luiz Capitulino | 4fdc94b | 2010-02-10 23:50:00 -0200 | [diff] [blame] | 577 | return -1; |
Luiz Capitulino | 956f1a0 | 2009-11-26 22:59:00 -0200 | [diff] [blame] | 578 | } |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 579 | goto help; |
Luiz Capitulino | 956f1a0 | 2009-11-26 22:59:00 -0200 | [diff] [blame] | 580 | } |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 581 | |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 582 | if (monitor_handler_is_async(cmd)) { |
| 583 | if (monitor_ctrl_mode(mon)) { |
| 584 | qmp_async_info_handler(mon, cmd); |
| 585 | } else { |
| 586 | user_async_info_handler(mon, cmd); |
| 587 | } |
| 588 | /* |
| 589 | * Indicate that this command is asynchronous and will not return any |
| 590 | * data (not even empty). Instead, the data will be returned via a |
| 591 | * completion callback. |
| 592 | */ |
| 593 | *ret_data = qobject_from_jsonf("{ '__mon_async': 'return' }"); |
| 594 | } else if (monitor_handler_ported(cmd)) { |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 595 | cmd->mhandler.info_new(mon, ret_data); |
Luiz Capitulino | 25b422e | 2009-11-26 22:58:59 -0200 | [diff] [blame] | 596 | |
| 597 | if (!monitor_ctrl_mode(mon)) { |
| 598 | /* |
| 599 | * User Protocol function is called here, Monitor Protocol is |
| 600 | * handled by monitor_call_handler() |
| 601 | */ |
| 602 | if (*ret_data) |
| 603 | cmd->user_print(mon, *ret_data); |
| 604 | } |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 605 | } else { |
Luiz Capitulino | 956f1a0 | 2009-11-26 22:59:00 -0200 | [diff] [blame] | 606 | if (monitor_ctrl_mode(mon)) { |
| 607 | /* handler not converted yet */ |
| 608 | qemu_error_new(QERR_COMMAND_NOT_FOUND, item); |
Luiz Capitulino | 4fdc94b | 2010-02-10 23:50:00 -0200 | [diff] [blame] | 609 | return -1; |
Luiz Capitulino | 956f1a0 | 2009-11-26 22:59:00 -0200 | [diff] [blame] | 610 | } else { |
| 611 | cmd->mhandler.info(mon); |
| 612 | } |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 613 | } |
| 614 | |
Luiz Capitulino | 4fdc94b | 2010-02-10 23:50:00 -0200 | [diff] [blame] | 615 | return 0; |
Luiz Capitulino | 13c7425 | 2009-10-07 13:41:55 -0300 | [diff] [blame] | 616 | |
| 617 | help: |
| 618 | help_cmd(mon, "info"); |
Luiz Capitulino | 4fdc94b | 2010-02-10 23:50:00 -0200 | [diff] [blame] | 619 | return 0; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 620 | } |
| 621 | |
Luiz Capitulino | 45e914c | 2009-12-10 17:15:58 -0200 | [diff] [blame] | 622 | static void do_info_version_print(Monitor *mon, const QObject *data) |
| 623 | { |
| 624 | QDict *qdict; |
| 625 | |
| 626 | qdict = qobject_to_qdict(data); |
| 627 | |
| 628 | monitor_printf(mon, "%s%s\n", qdict_get_str(qdict, "qemu"), |
| 629 | qdict_get_str(qdict, "package")); |
| 630 | } |
| 631 | |
Luiz Capitulino | ab2d318 | 2009-10-07 13:42:02 -0300 | [diff] [blame] | 632 | /** |
| 633 | * do_info_version(): Show QEMU version |
Luiz Capitulino | 45e914c | 2009-12-10 17:15:58 -0200 | [diff] [blame] | 634 | * |
| 635 | * Return a QDict with the following information: |
| 636 | * |
| 637 | * - "qemu": QEMU's version |
| 638 | * - "package": package's version |
| 639 | * |
| 640 | * Example: |
| 641 | * |
| 642 | * { "qemu": "0.11.50", "package": "" } |
Luiz Capitulino | ab2d318 | 2009-10-07 13:42:02 -0300 | [diff] [blame] | 643 | */ |
| 644 | static void do_info_version(Monitor *mon, QObject **ret_data) |
bellard | 9bc9d1c | 2004-10-10 15:15:51 +0000 | [diff] [blame] | 645 | { |
Luiz Capitulino | 45e914c | 2009-12-10 17:15:58 -0200 | [diff] [blame] | 646 | *ret_data = qobject_from_jsonf("{ 'qemu': %s, 'package': %s }", |
| 647 | QEMU_VERSION, QEMU_PKGVERSION); |
bellard | 9bc9d1c | 2004-10-10 15:15:51 +0000 | [diff] [blame] | 648 | } |
| 649 | |
Luiz Capitulino | e05486c | 2009-12-10 17:16:01 -0200 | [diff] [blame] | 650 | static void do_info_name_print(Monitor *mon, const QObject *data) |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 651 | { |
Luiz Capitulino | e05486c | 2009-12-10 17:16:01 -0200 | [diff] [blame] | 652 | QDict *qdict; |
| 653 | |
| 654 | qdict = qobject_to_qdict(data); |
| 655 | if (qdict_size(qdict) == 0) { |
| 656 | return; |
| 657 | } |
| 658 | |
| 659 | monitor_printf(mon, "%s\n", qdict_get_str(qdict, "name")); |
| 660 | } |
| 661 | |
| 662 | /** |
| 663 | * do_info_name(): Show VM name |
| 664 | * |
| 665 | * Return a QDict with the following information: |
| 666 | * |
| 667 | * - "name": VM's name (optional) |
| 668 | * |
| 669 | * Example: |
| 670 | * |
| 671 | * { "name": "qemu-name" } |
| 672 | */ |
| 673 | static void do_info_name(Monitor *mon, QObject **ret_data) |
| 674 | { |
| 675 | *ret_data = qemu_name ? qobject_from_jsonf("{'name': %s }", qemu_name) : |
| 676 | qobject_from_jsonf("{}"); |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 677 | } |
| 678 | |
Luiz Capitulino | 1a72867 | 2009-12-10 17:15:56 -0200 | [diff] [blame] | 679 | static QObject *get_cmd_dict(const char *name) |
| 680 | { |
| 681 | const char *p; |
| 682 | |
| 683 | /* Remove '|' from some commands */ |
| 684 | p = strchr(name, '|'); |
| 685 | if (p) { |
| 686 | p++; |
| 687 | } else { |
| 688 | p = name; |
| 689 | } |
| 690 | |
| 691 | return qobject_from_jsonf("{ 'name': %s }", p); |
| 692 | } |
| 693 | |
Luiz Capitulino | e3bba9d | 2009-11-26 22:58:56 -0200 | [diff] [blame] | 694 | /** |
| 695 | * do_info_commands(): List QMP available commands |
| 696 | * |
Luiz Capitulino | 1a72867 | 2009-12-10 17:15:56 -0200 | [diff] [blame] | 697 | * Each command is represented by a QDict, the returned QObject is a QList |
| 698 | * of all commands. |
| 699 | * |
| 700 | * The QDict contains: |
| 701 | * |
| 702 | * - "name": command's name |
| 703 | * |
| 704 | * Example: |
| 705 | * |
| 706 | * { [ { "name": "query-balloon" }, { "name": "system_powerdown" } ] } |
Luiz Capitulino | e3bba9d | 2009-11-26 22:58:56 -0200 | [diff] [blame] | 707 | */ |
| 708 | static void do_info_commands(Monitor *mon, QObject **ret_data) |
| 709 | { |
| 710 | QList *cmd_list; |
| 711 | const mon_cmd_t *cmd; |
| 712 | |
| 713 | cmd_list = qlist_new(); |
| 714 | |
| 715 | for (cmd = mon_cmds; cmd->name != NULL; cmd++) { |
| 716 | if (monitor_handler_ported(cmd) && !compare_cmd(cmd->name, "info")) { |
Luiz Capitulino | 1a72867 | 2009-12-10 17:15:56 -0200 | [diff] [blame] | 717 | qlist_append_obj(cmd_list, get_cmd_dict(cmd->name)); |
Luiz Capitulino | e3bba9d | 2009-11-26 22:58:56 -0200 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
| 721 | for (cmd = info_cmds; cmd->name != NULL; cmd++) { |
| 722 | if (monitor_handler_ported(cmd)) { |
| 723 | char buf[128]; |
| 724 | snprintf(buf, sizeof(buf), "query-%s", cmd->name); |
Luiz Capitulino | 1a72867 | 2009-12-10 17:15:56 -0200 | [diff] [blame] | 725 | qlist_append_obj(cmd_list, get_cmd_dict(buf)); |
Luiz Capitulino | e3bba9d | 2009-11-26 22:58:56 -0200 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | |
| 729 | *ret_data = QOBJECT(cmd_list); |
| 730 | } |
| 731 | |
aurel32 | bf4f74c | 2008-12-18 22:42:34 +0000 | [diff] [blame] | 732 | #if defined(TARGET_I386) |
Luiz Capitulino | 14f0720 | 2009-12-10 17:16:02 -0200 | [diff] [blame] | 733 | static void do_info_hpet_print(Monitor *mon, const QObject *data) |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 734 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 735 | monitor_printf(mon, "HPET is %s by QEMU\n", |
Luiz Capitulino | 14f0720 | 2009-12-10 17:16:02 -0200 | [diff] [blame] | 736 | qdict_get_bool(qobject_to_qdict(data), "enabled") ? |
| 737 | "enabled" : "disabled"); |
| 738 | } |
| 739 | |
| 740 | /** |
| 741 | * do_info_hpet(): Show HPET state |
| 742 | * |
| 743 | * Return a QDict with the following information: |
| 744 | * |
| 745 | * - "enabled": true if hpet if enabled, false otherwise |
| 746 | * |
| 747 | * Example: |
| 748 | * |
| 749 | * { "enabled": true } |
| 750 | */ |
| 751 | static void do_info_hpet(Monitor *mon, QObject **ret_data) |
| 752 | { |
| 753 | *ret_data = qobject_from_jsonf("{ 'enabled': %i }", !no_hpet); |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 754 | } |
aurel32 | bf4f74c | 2008-12-18 22:42:34 +0000 | [diff] [blame] | 755 | #endif |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 756 | |
Luiz Capitulino | 9603ceb | 2009-12-10 17:16:03 -0200 | [diff] [blame] | 757 | static void do_info_uuid_print(Monitor *mon, const QObject *data) |
blueswir1 | f1f23ad | 2008-09-18 18:30:20 +0000 | [diff] [blame] | 758 | { |
Luiz Capitulino | 9603ceb | 2009-12-10 17:16:03 -0200 | [diff] [blame] | 759 | monitor_printf(mon, "%s\n", qdict_get_str(qobject_to_qdict(data), "UUID")); |
| 760 | } |
| 761 | |
| 762 | /** |
| 763 | * do_info_uuid(): Show VM UUID |
| 764 | * |
| 765 | * Return a QDict with the following information: |
| 766 | * |
| 767 | * - "UUID": Universally Unique Identifier |
| 768 | * |
| 769 | * Example: |
| 770 | * |
| 771 | * { "UUID": "550e8400-e29b-41d4-a716-446655440000" } |
| 772 | */ |
| 773 | static void do_info_uuid(Monitor *mon, QObject **ret_data) |
| 774 | { |
| 775 | char uuid[64]; |
| 776 | |
| 777 | snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1], |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 778 | qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5], |
| 779 | qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9], |
| 780 | qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13], |
| 781 | qemu_uuid[14], qemu_uuid[15]); |
Luiz Capitulino | 9603ceb | 2009-12-10 17:16:03 -0200 | [diff] [blame] | 782 | *ret_data = qobject_from_jsonf("{ 'UUID': %s }", uuid); |
ths | a36e69d | 2007-12-02 05:18:19 +0000 | [diff] [blame] | 783 | } |
| 784 | |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 785 | /* get the current CPU defined by the user */ |
pbrook | 9596ebb | 2007-11-18 01:44:38 +0000 | [diff] [blame] | 786 | static int mon_set_cpu(int cpu_index) |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 787 | { |
| 788 | CPUState *env; |
| 789 | |
| 790 | for(env = first_cpu; env != NULL; env = env->next_cpu) { |
| 791 | if (env->cpu_index == cpu_index) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 792 | cur_mon->mon_cpu = env; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 793 | return 0; |
| 794 | } |
| 795 | } |
| 796 | return -1; |
| 797 | } |
| 798 | |
pbrook | 9596ebb | 2007-11-18 01:44:38 +0000 | [diff] [blame] | 799 | static CPUState *mon_get_cpu(void) |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 800 | { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 801 | if (!cur_mon->mon_cpu) { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 802 | mon_set_cpu(0); |
| 803 | } |
Avi Kivity | 4c0960c | 2009-08-17 23:19:53 +0300 | [diff] [blame] | 804 | cpu_synchronize_state(cur_mon->mon_cpu); |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 805 | return cur_mon->mon_cpu; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 806 | } |
| 807 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 808 | static void do_info_registers(Monitor *mon) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 809 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 810 | CPUState *env; |
| 811 | env = mon_get_cpu(); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 812 | #ifdef TARGET_I386 |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 813 | cpu_dump_state(env, (FILE *)mon, monitor_fprintf, |
bellard | d24b15a | 2005-07-03 21:28:00 +0000 | [diff] [blame] | 814 | X86_DUMP_FPU); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 815 | #else |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 816 | cpu_dump_state(env, (FILE *)mon, monitor_fprintf, |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 817 | 0); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 818 | #endif |
| 819 | } |
| 820 | |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 821 | static void print_cpu_iter(QObject *obj, void *opaque) |
| 822 | { |
| 823 | QDict *cpu; |
| 824 | int active = ' '; |
| 825 | Monitor *mon = opaque; |
| 826 | |
| 827 | assert(qobject_type(obj) == QTYPE_QDICT); |
| 828 | cpu = qobject_to_qdict(obj); |
| 829 | |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 830 | if (qdict_get_bool(cpu, "current")) { |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 831 | active = '*'; |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 832 | } |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 833 | |
| 834 | monitor_printf(mon, "%c CPU #%d: ", active, (int)qdict_get_int(cpu, "CPU")); |
| 835 | |
| 836 | #if defined(TARGET_I386) |
| 837 | monitor_printf(mon, "pc=0x" TARGET_FMT_lx, |
| 838 | (target_ulong) qdict_get_int(cpu, "pc")); |
| 839 | #elif defined(TARGET_PPC) |
| 840 | monitor_printf(mon, "nip=0x" TARGET_FMT_lx, |
| 841 | (target_long) qdict_get_int(cpu, "nip")); |
| 842 | #elif defined(TARGET_SPARC) |
| 843 | monitor_printf(mon, "pc=0x " TARGET_FMT_lx, |
| 844 | (target_long) qdict_get_int(cpu, "pc")); |
| 845 | monitor_printf(mon, "npc=0x" TARGET_FMT_lx, |
| 846 | (target_long) qdict_get_int(cpu, "npc")); |
| 847 | #elif defined(TARGET_MIPS) |
| 848 | monitor_printf(mon, "PC=0x" TARGET_FMT_lx, |
| 849 | (target_long) qdict_get_int(cpu, "PC")); |
| 850 | #endif |
| 851 | |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 852 | if (qdict_get_bool(cpu, "halted")) { |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 853 | monitor_printf(mon, " (halted)"); |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 854 | } |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 855 | |
| 856 | monitor_printf(mon, "\n"); |
| 857 | } |
| 858 | |
| 859 | static void monitor_print_cpus(Monitor *mon, const QObject *data) |
| 860 | { |
| 861 | QList *cpu_list; |
| 862 | |
| 863 | assert(qobject_type(data) == QTYPE_QLIST); |
| 864 | cpu_list = qobject_to_qlist(data); |
| 865 | qlist_iter(cpu_list, print_cpu_iter, mon); |
| 866 | } |
| 867 | |
| 868 | /** |
| 869 | * do_info_cpus(): Show CPU information |
| 870 | * |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 871 | * Return a QList. Each CPU is represented by a QDict, which contains: |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 872 | * |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 873 | * - "cpu": CPU index |
| 874 | * - "current": true if this is the current CPU, false otherwise |
| 875 | * - "halted": true if the cpu is halted, false otherwise |
| 876 | * - Current program counter. The key's name depends on the architecture: |
| 877 | * "pc": i386/x86)64 |
| 878 | * "nip": PPC |
| 879 | * "pc" and "npc": sparc |
| 880 | * "PC": mips |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 881 | * |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 882 | * Example: |
| 883 | * |
| 884 | * [ { "CPU": 0, "current": true, "halted": false, "pc": 3227107138 }, |
| 885 | * { "CPU": 1, "current": false, "halted": true, "pc": 7108165 } ] |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 886 | */ |
| 887 | static void do_info_cpus(Monitor *mon, QObject **ret_data) |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 888 | { |
| 889 | CPUState *env; |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 890 | QList *cpu_list; |
| 891 | |
| 892 | cpu_list = qlist_new(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 893 | |
| 894 | /* just to set the default cpu if not already done */ |
| 895 | mon_get_cpu(); |
| 896 | |
| 897 | for(env = first_cpu; env != NULL; env = env->next_cpu) { |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 898 | QDict *cpu; |
| 899 | QObject *obj; |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 900 | |
Avi Kivity | 4c0960c | 2009-08-17 23:19:53 +0300 | [diff] [blame] | 901 | cpu_synchronize_state(env); |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 902 | |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 903 | obj = qobject_from_jsonf("{ 'CPU': %d, 'current': %i, 'halted': %i }", |
| 904 | env->cpu_index, env == mon->mon_cpu, |
| 905 | env->halted); |
Luiz Capitulino | 55483ad | 2009-12-10 17:15:57 -0200 | [diff] [blame] | 906 | |
| 907 | cpu = qobject_to_qdict(obj); |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 908 | |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 909 | #if defined(TARGET_I386) |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 910 | qdict_put(cpu, "pc", qint_from_int(env->eip + env->segs[R_CS].base)); |
bellard | e80e1cc | 2005-11-23 22:05:28 +0000 | [diff] [blame] | 911 | #elif defined(TARGET_PPC) |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 912 | qdict_put(cpu, "nip", qint_from_int(env->nip)); |
bellard | ba3c64f | 2005-12-05 20:31:52 +0000 | [diff] [blame] | 913 | #elif defined(TARGET_SPARC) |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 914 | qdict_put(cpu, "pc", qint_from_int(env->pc)); |
| 915 | qdict_put(cpu, "npc", qint_from_int(env->npc)); |
ths | ead9360 | 2007-09-06 00:18:15 +0000 | [diff] [blame] | 916 | #elif defined(TARGET_MIPS) |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 917 | qdict_put(cpu, "PC", qint_from_int(env->active_tc.PC)); |
bellard | ce5232c | 2008-05-28 17:14:10 +0000 | [diff] [blame] | 918 | #endif |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 919 | |
| 920 | qlist_append(cpu_list, cpu); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 921 | } |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 922 | |
| 923 | *ret_data = QOBJECT(cpu_list); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 924 | } |
| 925 | |
Luiz Capitulino | 584cbdb | 2010-02-10 23:49:51 -0200 | [diff] [blame] | 926 | static int do_cpu_set(Monitor *mon, const QDict *qdict, QObject **ret_data) |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 927 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 928 | int index = qdict_get_int(qdict, "index"); |
Luiz Capitulino | 584cbdb | 2010-02-10 23:49:51 -0200 | [diff] [blame] | 929 | if (mon_set_cpu(index) < 0) { |
Markus Armbruster | cc0c418 | 2010-01-29 10:34:00 +0100 | [diff] [blame] | 930 | qemu_error_new(QERR_INVALID_PARAMETER, "index"); |
Luiz Capitulino | 584cbdb | 2010-02-10 23:49:51 -0200 | [diff] [blame] | 931 | return -1; |
| 932 | } |
| 933 | return 0; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 934 | } |
| 935 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 936 | static void do_info_jit(Monitor *mon) |
bellard | e3db722 | 2005-01-26 22:00:47 +0000 | [diff] [blame] | 937 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 938 | dump_exec_info((FILE *)mon, monitor_fprintf); |
bellard | e3db722 | 2005-01-26 22:00:47 +0000 | [diff] [blame] | 939 | } |
| 940 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 941 | static void do_info_history(Monitor *mon) |
bellard | aa45548 | 2004-04-04 13:07:25 +0000 | [diff] [blame] | 942 | { |
| 943 | int i; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 944 | const char *str; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 945 | |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 946 | if (!mon->rs) |
| 947 | return; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 948 | i = 0; |
| 949 | for(;;) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 950 | str = readline_get_history(mon->rs, i); |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 951 | if (!str) |
| 952 | break; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 953 | monitor_printf(mon, "%d: '%s'\n", i, str); |
bellard | 8e3a9fd | 2004-10-09 17:32:58 +0000 | [diff] [blame] | 954 | i++; |
bellard | aa45548 | 2004-04-04 13:07:25 +0000 | [diff] [blame] | 955 | } |
| 956 | } |
| 957 | |
j_mayer | 76a6625 | 2007-03-07 08:32:30 +0000 | [diff] [blame] | 958 | #if defined(TARGET_PPC) |
| 959 | /* XXX: not implemented in other targets */ |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 960 | static void do_info_cpu_stats(Monitor *mon) |
j_mayer | 76a6625 | 2007-03-07 08:32:30 +0000 | [diff] [blame] | 961 | { |
| 962 | CPUState *env; |
| 963 | |
| 964 | env = mon_get_cpu(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 965 | cpu_dump_statistics(env, (FILE *)mon, &monitor_fprintf, 0); |
j_mayer | 76a6625 | 2007-03-07 08:32:30 +0000 | [diff] [blame] | 966 | } |
| 967 | #endif |
| 968 | |
Luiz Capitulino | b223f35 | 2009-10-07 13:41:56 -0300 | [diff] [blame] | 969 | /** |
| 970 | * do_quit(): Quit QEMU execution |
| 971 | */ |
Luiz Capitulino | ef4b7ee | 2010-02-10 23:49:48 -0200 | [diff] [blame] | 972 | static int do_quit(Monitor *mon, const QDict *qdict, QObject **ret_data) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 973 | { |
| 974 | exit(0); |
Luiz Capitulino | ef4b7ee | 2010-02-10 23:49:48 -0200 | [diff] [blame] | 975 | return 0; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 976 | } |
| 977 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 978 | static int eject_device(Monitor *mon, BlockDriverState *bs, int force) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 979 | { |
| 980 | if (bdrv_is_inserted(bs)) { |
| 981 | if (!force) { |
| 982 | if (!bdrv_is_removable(bs)) { |
Markus Armbruster | 2c2a6bb | 2009-12-07 21:37:05 +0100 | [diff] [blame] | 983 | qemu_error_new(QERR_DEVICE_NOT_REMOVABLE, |
| 984 | bdrv_get_device_name(bs)); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 985 | return -1; |
| 986 | } |
| 987 | if (bdrv_is_locked(bs)) { |
Markus Armbruster | 2c2a6bb | 2009-12-07 21:37:05 +0100 | [diff] [blame] | 988 | qemu_error_new(QERR_DEVICE_LOCKED, bdrv_get_device_name(bs)); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 989 | return -1; |
| 990 | } |
| 991 | } |
| 992 | bdrv_close(bs); |
| 993 | } |
| 994 | return 0; |
| 995 | } |
| 996 | |
Luiz Capitulino | 9b9d4d9 | 2010-02-10 23:49:50 -0200 | [diff] [blame] | 997 | static int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 998 | { |
| 999 | BlockDriverState *bs; |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 1000 | int force = qdict_get_int(qdict, "force"); |
Luiz Capitulino | 78d714e | 2009-12-14 18:53:21 -0200 | [diff] [blame] | 1001 | const char *filename = qdict_get_str(qdict, "device"); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 1002 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1003 | bs = bdrv_find(filename); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 1004 | if (!bs) { |
Markus Armbruster | 2c2a6bb | 2009-12-07 21:37:05 +0100 | [diff] [blame] | 1005 | qemu_error_new(QERR_DEVICE_NOT_FOUND, filename); |
Luiz Capitulino | 9b9d4d9 | 2010-02-10 23:49:50 -0200 | [diff] [blame] | 1006 | return -1; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 1007 | } |
Luiz Capitulino | 9b9d4d9 | 2010-02-10 23:49:50 -0200 | [diff] [blame] | 1008 | return eject_device(mon, bs, force); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
Luiz Capitulino | ba85d35 | 2010-02-10 23:49:52 -0200 | [diff] [blame] | 1011 | static int do_block_set_passwd(Monitor *mon, const QDict *qdict, |
Luiz Capitulino | a3a55a2 | 2009-12-04 15:24:09 -0200 | [diff] [blame] | 1012 | QObject **ret_data) |
| 1013 | { |
| 1014 | BlockDriverState *bs; |
| 1015 | |
| 1016 | bs = bdrv_find(qdict_get_str(qdict, "device")); |
| 1017 | if (!bs) { |
| 1018 | qemu_error_new(QERR_DEVICE_NOT_FOUND, qdict_get_str(qdict, "device")); |
Luiz Capitulino | ba85d35 | 2010-02-10 23:49:52 -0200 | [diff] [blame] | 1019 | return -1; |
Luiz Capitulino | a3a55a2 | 2009-12-04 15:24:09 -0200 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | if (bdrv_set_key(bs, qdict_get_str(qdict, "password")) < 0) { |
| 1023 | qemu_error_new(QERR_INVALID_PASSWORD); |
Luiz Capitulino | ba85d35 | 2010-02-10 23:49:52 -0200 | [diff] [blame] | 1024 | return -1; |
Luiz Capitulino | a3a55a2 | 2009-12-04 15:24:09 -0200 | [diff] [blame] | 1025 | } |
Luiz Capitulino | ba85d35 | 2010-02-10 23:49:52 -0200 | [diff] [blame] | 1026 | |
| 1027 | return 0; |
Luiz Capitulino | a3a55a2 | 2009-12-04 15:24:09 -0200 | [diff] [blame] | 1028 | } |
| 1029 | |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1030 | static int do_change_block(Monitor *mon, const char *device, |
| 1031 | const char *filename, const char *fmt) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 1032 | { |
| 1033 | BlockDriverState *bs; |
aurel32 | 2ecea9b | 2008-06-18 22:10:01 +0000 | [diff] [blame] | 1034 | BlockDriver *drv = NULL; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 1035 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1036 | bs = bdrv_find(device); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 1037 | if (!bs) { |
Markus Armbruster | ec3b82a | 2009-12-07 21:37:09 +0100 | [diff] [blame] | 1038 | qemu_error_new(QERR_DEVICE_NOT_FOUND, device); |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1039 | return -1; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 1040 | } |
aurel32 | 2ecea9b | 2008-06-18 22:10:01 +0000 | [diff] [blame] | 1041 | if (fmt) { |
Markus Armbruster | eb85201 | 2009-10-27 18:41:44 +0100 | [diff] [blame] | 1042 | drv = bdrv_find_whitelisted_format(fmt); |
aurel32 | 2ecea9b | 2008-06-18 22:10:01 +0000 | [diff] [blame] | 1043 | if (!drv) { |
Markus Armbruster | ec3b82a | 2009-12-07 21:37:09 +0100 | [diff] [blame] | 1044 | qemu_error_new(QERR_INVALID_BLOCK_FORMAT, fmt); |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1045 | return -1; |
aurel32 | 2ecea9b | 2008-06-18 22:10:01 +0000 | [diff] [blame] | 1046 | } |
| 1047 | } |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1048 | if (eject_device(mon, bs, 0) < 0) { |
| 1049 | return -1; |
| 1050 | } |
| 1051 | if (bdrv_open2(bs, filename, BDRV_O_RDWR, drv) < 0) { |
| 1052 | return -1; |
| 1053 | } |
| 1054 | return monitor_read_bdrv_key_start(mon, bs, NULL, NULL); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1057 | static int change_vnc_password(const char *password) |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1058 | { |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1059 | if (vnc_display_password(NULL, password) < 0) { |
Markus Armbruster | ec3b82a | 2009-12-07 21:37:09 +0100 | [diff] [blame] | 1060 | qemu_error_new(QERR_SET_PASSWD_FAILED); |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1061 | return -1; |
| 1062 | } |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1063 | |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1064 | return 0; |
Markus Armbruster | 2895e07 | 2009-12-07 21:37:01 +0100 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | static void change_vnc_password_cb(Monitor *mon, const char *password, |
| 1068 | void *opaque) |
| 1069 | { |
Markus Armbruster | ec3b82a | 2009-12-07 21:37:09 +0100 | [diff] [blame] | 1070 | change_vnc_password(password); |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 1071 | monitor_read_command(mon, 1); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1074 | static int do_change_vnc(Monitor *mon, const char *target, const char *arg) |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 1075 | { |
ths | 7084851 | 2007-08-25 01:37:05 +0000 | [diff] [blame] | 1076 | if (strcmp(target, "passwd") == 0 || |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 1077 | strcmp(target, "password") == 0) { |
| 1078 | if (arg) { |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1079 | char password[9]; |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 1080 | strncpy(password, arg, sizeof(password)); |
| 1081 | password[sizeof(password) - 1] = '\0'; |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1082 | return change_vnc_password(password); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1083 | } else { |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1084 | return monitor_read_password(mon, change_vnc_password_cb, NULL); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1085 | } |
ths | 7084851 | 2007-08-25 01:37:05 +0000 | [diff] [blame] | 1086 | } else { |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1087 | if (vnc_display_open(NULL, target) < 0) { |
Markus Armbruster | ec3b82a | 2009-12-07 21:37:09 +0100 | [diff] [blame] | 1088 | qemu_error_new(QERR_VNC_SERVER_FAILED, target); |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1089 | return -1; |
| 1090 | } |
ths | 7084851 | 2007-08-25 01:37:05 +0000 | [diff] [blame] | 1091 | } |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1092 | |
| 1093 | return 0; |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
Markus Armbruster | ec3b82a | 2009-12-07 21:37:09 +0100 | [diff] [blame] | 1096 | /** |
| 1097 | * do_change(): Change a removable medium, or VNC configuration |
| 1098 | */ |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1099 | static int do_change(Monitor *mon, const QDict *qdict, QObject **ret_data) |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 1100 | { |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 1101 | const char *device = qdict_get_str(qdict, "device"); |
| 1102 | const char *target = qdict_get_str(qdict, "target"); |
| 1103 | const char *arg = qdict_get_try_str(qdict, "arg"); |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1104 | int ret; |
| 1105 | |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 1106 | if (strcmp(device, "vnc") == 0) { |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1107 | ret = do_change_vnc(mon, target, arg); |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 1108 | } else { |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1109 | ret = do_change_block(mon, device, target, arg); |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 1110 | } |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 1111 | |
| 1112 | return ret; |
ths | e25a582 | 2007-08-25 01:36:20 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1115 | static void do_screen_dump(Monitor *mon, const QDict *qdict) |
bellard | 59a983b | 2004-03-17 23:17:16 +0000 | [diff] [blame] | 1116 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1117 | vga_hw_screen_dump(qdict_get_str(qdict, "filename")); |
bellard | 59a983b | 2004-03-17 23:17:16 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1120 | static void do_logfile(Monitor *mon, const QDict *qdict) |
pbrook | e735b91 | 2007-06-30 13:53:24 +0000 | [diff] [blame] | 1121 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1122 | cpu_set_log_filename(qdict_get_str(qdict, "filename")); |
pbrook | e735b91 | 2007-06-30 13:53:24 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1125 | static void do_log(Monitor *mon, const QDict *qdict) |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 1126 | { |
| 1127 | int mask; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1128 | const char *items = qdict_get_str(qdict, "items"); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1129 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1130 | if (!strcmp(items, "none")) { |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 1131 | mask = 0; |
| 1132 | } else { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1133 | mask = cpu_str_to_log_mask(items); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 1134 | if (!mask) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1135 | help_cmd(mon, "log"); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 1136 | return; |
| 1137 | } |
| 1138 | } |
| 1139 | cpu_set_log(mask); |
| 1140 | } |
| 1141 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1142 | static void do_singlestep(Monitor *mon, const QDict *qdict) |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 1143 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1144 | const char *option = qdict_get_try_str(qdict, "option"); |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 1145 | if (!option || !strcmp(option, "on")) { |
| 1146 | singlestep = 1; |
| 1147 | } else if (!strcmp(option, "off")) { |
| 1148 | singlestep = 0; |
| 1149 | } else { |
| 1150 | monitor_printf(mon, "unexpected option %s\n", option); |
| 1151 | } |
| 1152 | } |
| 1153 | |
Luiz Capitulino | e0c97bd | 2009-10-07 13:41:57 -0300 | [diff] [blame] | 1154 | /** |
| 1155 | * do_stop(): Stop VM execution |
| 1156 | */ |
Luiz Capitulino | ef4b7ee | 2010-02-10 23:49:48 -0200 | [diff] [blame] | 1157 | static int do_stop(Monitor *mon, const QDict *qdict, QObject **ret_data) |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1158 | { |
| 1159 | vm_stop(EXCP_INTERRUPT); |
Luiz Capitulino | ef4b7ee | 2010-02-10 23:49:48 -0200 | [diff] [blame] | 1160 | return 0; |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1163 | static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs); |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 1164 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1165 | struct bdrv_iterate_context { |
| 1166 | Monitor *mon; |
| 1167 | int err; |
| 1168 | }; |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 1169 | |
Luiz Capitulino | a1f896a | 2009-10-07 13:42:00 -0300 | [diff] [blame] | 1170 | /** |
| 1171 | * do_cont(): Resume emulation. |
| 1172 | */ |
Luiz Capitulino | d5a7b38 | 2010-02-10 23:49:49 -0200 | [diff] [blame] | 1173 | static int do_cont(Monitor *mon, const QDict *qdict, QObject **ret_data) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1174 | { |
| 1175 | struct bdrv_iterate_context context = { mon, 0 }; |
| 1176 | |
| 1177 | bdrv_iterate(encrypted_bdrv_it, &context); |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 1178 | /* only resume the vm if all keys are set and valid */ |
Luiz Capitulino | d5a7b38 | 2010-02-10 23:49:49 -0200 | [diff] [blame] | 1179 | if (!context.err) { |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 1180 | vm_start(); |
Luiz Capitulino | d5a7b38 | 2010-02-10 23:49:49 -0200 | [diff] [blame] | 1181 | return 0; |
| 1182 | } else { |
| 1183 | return -1; |
| 1184 | } |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1187 | static void bdrv_key_cb(void *opaque, int err) |
| 1188 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1189 | Monitor *mon = opaque; |
| 1190 | |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1191 | /* another key was set successfully, retry to continue */ |
| 1192 | if (!err) |
Luiz Capitulino | a1f896a | 2009-10-07 13:42:00 -0300 | [diff] [blame] | 1193 | do_cont(mon, NULL, NULL); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs) |
| 1197 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1198 | struct bdrv_iterate_context *context = opaque; |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1199 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1200 | if (!context->err && bdrv_key_required(bs)) { |
| 1201 | context->err = -EBUSY; |
| 1202 | monitor_read_bdrv_key_start(context->mon, bs, bdrv_key_cb, |
| 1203 | context->mon); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1207 | static void do_gdbserver(Monitor *mon, const QDict *qdict) |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1208 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1209 | const char *device = qdict_get_try_str(qdict, "device"); |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 1210 | if (!device) |
| 1211 | device = "tcp::" DEFAULT_GDBSTUB_PORT; |
| 1212 | if (gdbserver_start(device) < 0) { |
| 1213 | monitor_printf(mon, "Could not open gdbserver on device '%s'\n", |
| 1214 | device); |
| 1215 | } else if (strcmp(device, "none") == 0) { |
aliguori | 36556b2 | 2009-03-28 18:05:53 +0000 | [diff] [blame] | 1216 | monitor_printf(mon, "Disabled gdbserver\n"); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1217 | } else { |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 1218 | monitor_printf(mon, "Waiting for gdb connection on device '%s'\n", |
| 1219 | device); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1220 | } |
| 1221 | } |
| 1222 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1223 | static void do_watchdog_action(Monitor *mon, const QDict *qdict) |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 1224 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1225 | const char *action = qdict_get_str(qdict, "action"); |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 1226 | if (select_watchdog_action(action) == -1) { |
| 1227 | monitor_printf(mon, "Unknown watchdog action '%s'\n", action); |
| 1228 | } |
| 1229 | } |
| 1230 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1231 | static void monitor_printc(Monitor *mon, int c) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1232 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1233 | monitor_printf(mon, "'"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1234 | switch(c) { |
| 1235 | case '\'': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1236 | monitor_printf(mon, "\\'"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1237 | break; |
| 1238 | case '\\': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1239 | monitor_printf(mon, "\\\\"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1240 | break; |
| 1241 | case '\n': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1242 | monitor_printf(mon, "\\n"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1243 | break; |
| 1244 | case '\r': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1245 | monitor_printf(mon, "\\r"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1246 | break; |
| 1247 | default: |
| 1248 | if (c >= 32 && c <= 126) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1249 | monitor_printf(mon, "%c", c); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1250 | } else { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1251 | monitor_printf(mon, "\\x%02x", c); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1252 | } |
| 1253 | break; |
| 1254 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1255 | monitor_printf(mon, "'"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1256 | } |
| 1257 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1258 | static void memory_dump(Monitor *mon, int count, int format, int wsize, |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1259 | target_phys_addr_t addr, int is_physical) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1260 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1261 | CPUState *env; |
Blue Swirl | 23842aa | 2010-01-12 20:27:43 +0000 | [diff] [blame] | 1262 | int l, line_size, i, max_digits, len; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1263 | uint8_t buf[16]; |
| 1264 | uint64_t v; |
| 1265 | |
| 1266 | if (format == 'i') { |
| 1267 | int flags; |
| 1268 | flags = 0; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1269 | env = mon_get_cpu(); |
Markus Armbruster | 09b9418 | 2010-01-20 13:07:30 +0100 | [diff] [blame] | 1270 | if (!is_physical) |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1271 | return; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1272 | #ifdef TARGET_I386 |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 1273 | if (wsize == 2) { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1274 | flags = 1; |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 1275 | } else if (wsize == 4) { |
| 1276 | flags = 0; |
| 1277 | } else { |
bellard | 6a15fd1 | 2006-04-12 21:07:07 +0000 | [diff] [blame] | 1278 | /* as default we use the current CS size */ |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 1279 | flags = 0; |
bellard | 6a15fd1 | 2006-04-12 21:07:07 +0000 | [diff] [blame] | 1280 | if (env) { |
| 1281 | #ifdef TARGET_X86_64 |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1282 | if ((env->efer & MSR_EFER_LMA) && |
bellard | 6a15fd1 | 2006-04-12 21:07:07 +0000 | [diff] [blame] | 1283 | (env->segs[R_CS].flags & DESC_L_MASK)) |
| 1284 | flags = 2; |
| 1285 | else |
| 1286 | #endif |
| 1287 | if (!(env->segs[R_CS].flags & DESC_B_MASK)) |
| 1288 | flags = 1; |
| 1289 | } |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 1290 | } |
| 1291 | #endif |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1292 | monitor_disas(mon, env, addr, count, is_physical, flags); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1293 | return; |
| 1294 | } |
| 1295 | |
| 1296 | len = wsize * count; |
| 1297 | if (wsize == 1) |
| 1298 | line_size = 8; |
| 1299 | else |
| 1300 | line_size = 16; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1301 | max_digits = 0; |
| 1302 | |
| 1303 | switch(format) { |
| 1304 | case 'o': |
| 1305 | max_digits = (wsize * 8 + 2) / 3; |
| 1306 | break; |
| 1307 | default: |
| 1308 | case 'x': |
| 1309 | max_digits = (wsize * 8) / 4; |
| 1310 | break; |
| 1311 | case 'u': |
| 1312 | case 'd': |
| 1313 | max_digits = (wsize * 8 * 10 + 32) / 33; |
| 1314 | break; |
| 1315 | case 'c': |
| 1316 | wsize = 1; |
| 1317 | break; |
| 1318 | } |
| 1319 | |
| 1320 | while (len > 0) { |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 1321 | if (is_physical) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1322 | monitor_printf(mon, TARGET_FMT_plx ":", addr); |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 1323 | else |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1324 | monitor_printf(mon, TARGET_FMT_lx ":", (target_ulong)addr); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1325 | l = len; |
| 1326 | if (l > line_size) |
| 1327 | l = line_size; |
| 1328 | if (is_physical) { |
| 1329 | cpu_physical_memory_rw(addr, buf, l, 0); |
| 1330 | } else { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1331 | env = mon_get_cpu(); |
aliguori | c8f79b6 | 2008-08-18 14:00:20 +0000 | [diff] [blame] | 1332 | if (cpu_memory_rw_debug(env, addr, buf, l, 0) < 0) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1333 | monitor_printf(mon, " Cannot access memory\n"); |
aliguori | c8f79b6 | 2008-08-18 14:00:20 +0000 | [diff] [blame] | 1334 | break; |
| 1335 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1336 | } |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1337 | i = 0; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1338 | while (i < l) { |
| 1339 | switch(wsize) { |
| 1340 | default: |
| 1341 | case 1: |
| 1342 | v = ldub_raw(buf + i); |
| 1343 | break; |
| 1344 | case 2: |
| 1345 | v = lduw_raw(buf + i); |
| 1346 | break; |
| 1347 | case 4: |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 1348 | v = (uint32_t)ldl_raw(buf + i); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1349 | break; |
| 1350 | case 8: |
| 1351 | v = ldq_raw(buf + i); |
| 1352 | break; |
| 1353 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1354 | monitor_printf(mon, " "); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1355 | switch(format) { |
| 1356 | case 'o': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1357 | monitor_printf(mon, "%#*" PRIo64, max_digits, v); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1358 | break; |
| 1359 | case 'x': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1360 | monitor_printf(mon, "0x%0*" PRIx64, max_digits, v); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1361 | break; |
| 1362 | case 'u': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1363 | monitor_printf(mon, "%*" PRIu64, max_digits, v); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1364 | break; |
| 1365 | case 'd': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1366 | monitor_printf(mon, "%*" PRId64, max_digits, v); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1367 | break; |
| 1368 | case 'c': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1369 | monitor_printc(mon, v); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1370 | break; |
| 1371 | } |
| 1372 | i += wsize; |
| 1373 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1374 | monitor_printf(mon, "\n"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1375 | addr += l; |
| 1376 | len -= l; |
| 1377 | } |
| 1378 | } |
| 1379 | |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1380 | static void do_memory_dump(Monitor *mon, const QDict *qdict) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1381 | { |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1382 | int count = qdict_get_int(qdict, "count"); |
| 1383 | int format = qdict_get_int(qdict, "format"); |
| 1384 | int size = qdict_get_int(qdict, "size"); |
| 1385 | target_long addr = qdict_get_int(qdict, "addr"); |
| 1386 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1387 | memory_dump(mon, count, format, size, addr, 0); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1390 | static void do_physical_memory_dump(Monitor *mon, const QDict *qdict) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1391 | { |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1392 | int count = qdict_get_int(qdict, "count"); |
| 1393 | int format = qdict_get_int(qdict, "format"); |
| 1394 | int size = qdict_get_int(qdict, "size"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1395 | target_phys_addr_t addr = qdict_get_int(qdict, "addr"); |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1396 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1397 | memory_dump(mon, count, format, size, addr, 1); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1400 | static void do_print(Monitor *mon, const QDict *qdict) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1401 | { |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1402 | int format = qdict_get_int(qdict, "format"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1403 | target_phys_addr_t val = qdict_get_int(qdict, "val"); |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1404 | |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 1405 | #if TARGET_PHYS_ADDR_BITS == 32 |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1406 | switch(format) { |
| 1407 | case 'o': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1408 | monitor_printf(mon, "%#o", val); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1409 | break; |
| 1410 | case 'x': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1411 | monitor_printf(mon, "%#x", val); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1412 | break; |
| 1413 | case 'u': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1414 | monitor_printf(mon, "%u", val); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1415 | break; |
| 1416 | default: |
| 1417 | case 'd': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1418 | monitor_printf(mon, "%d", val); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1419 | break; |
| 1420 | case 'c': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1421 | monitor_printc(mon, val); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1422 | break; |
| 1423 | } |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 1424 | #else |
| 1425 | switch(format) { |
| 1426 | case 'o': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1427 | monitor_printf(mon, "%#" PRIo64, val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 1428 | break; |
| 1429 | case 'x': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1430 | monitor_printf(mon, "%#" PRIx64, val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 1431 | break; |
| 1432 | case 'u': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1433 | monitor_printf(mon, "%" PRIu64, val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 1434 | break; |
| 1435 | default: |
| 1436 | case 'd': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1437 | monitor_printf(mon, "%" PRId64, val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 1438 | break; |
| 1439 | case 'c': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1440 | monitor_printc(mon, val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 1441 | break; |
| 1442 | } |
| 1443 | #endif |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1444 | monitor_printf(mon, "\n"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
Luiz Capitulino | 9869622 | 2010-02-10 23:49:58 -0200 | [diff] [blame] | 1447 | static int do_memory_save(Monitor *mon, const QDict *qdict, QObject **ret_data) |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1448 | { |
| 1449 | FILE *f; |
Luiz Capitulino | afe67ef | 2009-08-28 15:27:16 -0300 | [diff] [blame] | 1450 | uint32_t size = qdict_get_int(qdict, "size"); |
| 1451 | const char *filename = qdict_get_str(qdict, "filename"); |
| 1452 | target_long addr = qdict_get_int(qdict, "val"); |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1453 | uint32_t l; |
| 1454 | CPUState *env; |
| 1455 | uint8_t buf[1024]; |
Luiz Capitulino | 9869622 | 2010-02-10 23:49:58 -0200 | [diff] [blame] | 1456 | int ret = -1; |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1457 | |
| 1458 | env = mon_get_cpu(); |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1459 | |
| 1460 | f = fopen(filename, "wb"); |
| 1461 | if (!f) { |
Markus Armbruster | c34ed28 | 2010-01-20 13:07:32 +0100 | [diff] [blame] | 1462 | qemu_error_new(QERR_OPEN_FILE_FAILED, filename); |
Luiz Capitulino | 9869622 | 2010-02-10 23:49:58 -0200 | [diff] [blame] | 1463 | return -1; |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1464 | } |
| 1465 | while (size != 0) { |
| 1466 | l = sizeof(buf); |
| 1467 | if (l > size) |
| 1468 | l = size; |
| 1469 | cpu_memory_rw_debug(env, addr, buf, l, 0); |
Kirill A. Shutemov | 27e3ddd | 2010-01-20 00:56:19 +0100 | [diff] [blame] | 1470 | if (fwrite(buf, 1, l, f) != l) { |
| 1471 | monitor_printf(mon, "fwrite() error in do_memory_save\n"); |
| 1472 | goto exit; |
| 1473 | } |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1474 | addr += l; |
| 1475 | size -= l; |
| 1476 | } |
Luiz Capitulino | 9869622 | 2010-02-10 23:49:58 -0200 | [diff] [blame] | 1477 | |
| 1478 | ret = 0; |
| 1479 | |
Kirill A. Shutemov | 27e3ddd | 2010-01-20 00:56:19 +0100 | [diff] [blame] | 1480 | exit: |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1481 | fclose(f); |
Luiz Capitulino | 9869622 | 2010-02-10 23:49:58 -0200 | [diff] [blame] | 1482 | return ret; |
bellard | b371dc5 | 2007-01-03 15:20:39 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
Luiz Capitulino | fe38a32 | 2010-02-10 23:49:59 -0200 | [diff] [blame] | 1485 | static int do_physical_memory_save(Monitor *mon, const QDict *qdict, |
Luiz Capitulino | 18f5a8b | 2009-10-16 12:23:44 -0300 | [diff] [blame] | 1486 | QObject **ret_data) |
aurel32 | a8bdf7a | 2008-04-11 21:36:14 +0000 | [diff] [blame] | 1487 | { |
| 1488 | FILE *f; |
| 1489 | uint32_t l; |
| 1490 | uint8_t buf[1024]; |
Luiz Capitulino | afe67ef | 2009-08-28 15:27:16 -0300 | [diff] [blame] | 1491 | uint32_t size = qdict_get_int(qdict, "size"); |
| 1492 | const char *filename = qdict_get_str(qdict, "filename"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1493 | target_phys_addr_t addr = qdict_get_int(qdict, "val"); |
Luiz Capitulino | fe38a32 | 2010-02-10 23:49:59 -0200 | [diff] [blame] | 1494 | int ret = -1; |
aurel32 | a8bdf7a | 2008-04-11 21:36:14 +0000 | [diff] [blame] | 1495 | |
| 1496 | f = fopen(filename, "wb"); |
| 1497 | if (!f) { |
Markus Armbruster | 95fada8 | 2010-01-20 13:07:33 +0100 | [diff] [blame] | 1498 | qemu_error_new(QERR_OPEN_FILE_FAILED, filename); |
Luiz Capitulino | fe38a32 | 2010-02-10 23:49:59 -0200 | [diff] [blame] | 1499 | return -1; |
aurel32 | a8bdf7a | 2008-04-11 21:36:14 +0000 | [diff] [blame] | 1500 | } |
| 1501 | while (size != 0) { |
| 1502 | l = sizeof(buf); |
| 1503 | if (l > size) |
| 1504 | l = size; |
| 1505 | cpu_physical_memory_rw(addr, buf, l, 0); |
Kirill A. Shutemov | 27e3ddd | 2010-01-20 00:56:19 +0100 | [diff] [blame] | 1506 | if (fwrite(buf, 1, l, f) != l) { |
| 1507 | monitor_printf(mon, "fwrite() error in do_physical_memory_save\n"); |
| 1508 | goto exit; |
| 1509 | } |
aurel32 | a8bdf7a | 2008-04-11 21:36:14 +0000 | [diff] [blame] | 1510 | fflush(f); |
| 1511 | addr += l; |
| 1512 | size -= l; |
| 1513 | } |
Luiz Capitulino | fe38a32 | 2010-02-10 23:49:59 -0200 | [diff] [blame] | 1514 | |
| 1515 | ret = 0; |
| 1516 | |
Kirill A. Shutemov | 27e3ddd | 2010-01-20 00:56:19 +0100 | [diff] [blame] | 1517 | exit: |
aurel32 | a8bdf7a | 2008-04-11 21:36:14 +0000 | [diff] [blame] | 1518 | fclose(f); |
Luiz Capitulino | fe38a32 | 2010-02-10 23:49:59 -0200 | [diff] [blame] | 1519 | return ret; |
aurel32 | a8bdf7a | 2008-04-11 21:36:14 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 1522 | static void do_sum(Monitor *mon, const QDict *qdict) |
bellard | e4cf1ad | 2005-06-04 20:15:57 +0000 | [diff] [blame] | 1523 | { |
| 1524 | uint32_t addr; |
| 1525 | uint8_t buf[1]; |
| 1526 | uint16_t sum; |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 1527 | uint32_t start = qdict_get_int(qdict, "start"); |
| 1528 | uint32_t size = qdict_get_int(qdict, "size"); |
bellard | e4cf1ad | 2005-06-04 20:15:57 +0000 | [diff] [blame] | 1529 | |
| 1530 | sum = 0; |
| 1531 | for(addr = start; addr < (start + size); addr++) { |
| 1532 | cpu_physical_memory_rw(addr, buf, 1, 0); |
| 1533 | /* BSD sum algorithm ('sum' Unix command) */ |
| 1534 | sum = (sum >> 1) | (sum << 15); |
| 1535 | sum += buf[0]; |
| 1536 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1537 | monitor_printf(mon, "%05d\n", sum); |
bellard | e4cf1ad | 2005-06-04 20:15:57 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1540 | typedef struct { |
| 1541 | int keycode; |
| 1542 | const char *name; |
| 1543 | } KeyDef; |
| 1544 | |
| 1545 | static const KeyDef key_defs[] = { |
| 1546 | { 0x2a, "shift" }, |
| 1547 | { 0x36, "shift_r" }, |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1548 | |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1549 | { 0x38, "alt" }, |
| 1550 | { 0xb8, "alt_r" }, |
ths | 2ba27c7 | 2008-08-13 12:54:23 +0000 | [diff] [blame] | 1551 | { 0x64, "altgr" }, |
| 1552 | { 0xe4, "altgr_r" }, |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1553 | { 0x1d, "ctrl" }, |
| 1554 | { 0x9d, "ctrl_r" }, |
| 1555 | |
| 1556 | { 0xdd, "menu" }, |
| 1557 | |
| 1558 | { 0x01, "esc" }, |
| 1559 | |
| 1560 | { 0x02, "1" }, |
| 1561 | { 0x03, "2" }, |
| 1562 | { 0x04, "3" }, |
| 1563 | { 0x05, "4" }, |
| 1564 | { 0x06, "5" }, |
| 1565 | { 0x07, "6" }, |
| 1566 | { 0x08, "7" }, |
| 1567 | { 0x09, "8" }, |
| 1568 | { 0x0a, "9" }, |
| 1569 | { 0x0b, "0" }, |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1570 | { 0x0c, "minus" }, |
| 1571 | { 0x0d, "equal" }, |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1572 | { 0x0e, "backspace" }, |
| 1573 | |
| 1574 | { 0x0f, "tab" }, |
| 1575 | { 0x10, "q" }, |
| 1576 | { 0x11, "w" }, |
| 1577 | { 0x12, "e" }, |
| 1578 | { 0x13, "r" }, |
| 1579 | { 0x14, "t" }, |
| 1580 | { 0x15, "y" }, |
| 1581 | { 0x16, "u" }, |
| 1582 | { 0x17, "i" }, |
| 1583 | { 0x18, "o" }, |
| 1584 | { 0x19, "p" }, |
| 1585 | |
| 1586 | { 0x1c, "ret" }, |
| 1587 | |
| 1588 | { 0x1e, "a" }, |
| 1589 | { 0x1f, "s" }, |
| 1590 | { 0x20, "d" }, |
| 1591 | { 0x21, "f" }, |
| 1592 | { 0x22, "g" }, |
| 1593 | { 0x23, "h" }, |
| 1594 | { 0x24, "j" }, |
| 1595 | { 0x25, "k" }, |
| 1596 | { 0x26, "l" }, |
| 1597 | |
| 1598 | { 0x2c, "z" }, |
| 1599 | { 0x2d, "x" }, |
| 1600 | { 0x2e, "c" }, |
| 1601 | { 0x2f, "v" }, |
| 1602 | { 0x30, "b" }, |
| 1603 | { 0x31, "n" }, |
| 1604 | { 0x32, "m" }, |
aurel32 | 9155fc4 | 2008-10-01 21:46:15 +0000 | [diff] [blame] | 1605 | { 0x33, "comma" }, |
| 1606 | { 0x34, "dot" }, |
| 1607 | { 0x35, "slash" }, |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1608 | |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 1609 | { 0x37, "asterisk" }, |
| 1610 | |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1611 | { 0x39, "spc" }, |
bellard | 00ffa62 | 2004-06-04 13:25:15 +0000 | [diff] [blame] | 1612 | { 0x3a, "caps_lock" }, |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1613 | { 0x3b, "f1" }, |
| 1614 | { 0x3c, "f2" }, |
| 1615 | { 0x3d, "f3" }, |
| 1616 | { 0x3e, "f4" }, |
| 1617 | { 0x3f, "f5" }, |
| 1618 | { 0x40, "f6" }, |
| 1619 | { 0x41, "f7" }, |
| 1620 | { 0x42, "f8" }, |
| 1621 | { 0x43, "f9" }, |
| 1622 | { 0x44, "f10" }, |
bellard | 00ffa62 | 2004-06-04 13:25:15 +0000 | [diff] [blame] | 1623 | { 0x45, "num_lock" }, |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1624 | { 0x46, "scroll_lock" }, |
| 1625 | |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1626 | { 0xb5, "kp_divide" }, |
| 1627 | { 0x37, "kp_multiply" }, |
ths | 0cfec83 | 2007-06-23 16:02:43 +0000 | [diff] [blame] | 1628 | { 0x4a, "kp_subtract" }, |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1629 | { 0x4e, "kp_add" }, |
| 1630 | { 0x9c, "kp_enter" }, |
| 1631 | { 0x53, "kp_decimal" }, |
balrog | f2289cb | 2008-06-04 10:14:16 +0000 | [diff] [blame] | 1632 | { 0x54, "sysrq" }, |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1633 | |
| 1634 | { 0x52, "kp_0" }, |
| 1635 | { 0x4f, "kp_1" }, |
| 1636 | { 0x50, "kp_2" }, |
| 1637 | { 0x51, "kp_3" }, |
| 1638 | { 0x4b, "kp_4" }, |
| 1639 | { 0x4c, "kp_5" }, |
| 1640 | { 0x4d, "kp_6" }, |
| 1641 | { 0x47, "kp_7" }, |
| 1642 | { 0x48, "kp_8" }, |
| 1643 | { 0x49, "kp_9" }, |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1644 | |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1645 | { 0x56, "<" }, |
| 1646 | |
| 1647 | { 0x57, "f11" }, |
| 1648 | { 0x58, "f12" }, |
| 1649 | |
| 1650 | { 0xb7, "print" }, |
| 1651 | |
| 1652 | { 0xc7, "home" }, |
| 1653 | { 0xc9, "pgup" }, |
| 1654 | { 0xd1, "pgdn" }, |
| 1655 | { 0xcf, "end" }, |
| 1656 | |
| 1657 | { 0xcb, "left" }, |
| 1658 | { 0xc8, "up" }, |
| 1659 | { 0xd0, "down" }, |
| 1660 | { 0xcd, "right" }, |
| 1661 | |
| 1662 | { 0xd2, "insert" }, |
| 1663 | { 0xd3, "delete" }, |
blueswir1 | c0b5b10 | 2008-06-22 07:45:42 +0000 | [diff] [blame] | 1664 | #if defined(TARGET_SPARC) && !defined(TARGET_SPARC64) |
| 1665 | { 0xf0, "stop" }, |
| 1666 | { 0xf1, "again" }, |
| 1667 | { 0xf2, "props" }, |
| 1668 | { 0xf3, "undo" }, |
| 1669 | { 0xf4, "front" }, |
| 1670 | { 0xf5, "copy" }, |
| 1671 | { 0xf6, "open" }, |
| 1672 | { 0xf7, "paste" }, |
| 1673 | { 0xf8, "find" }, |
| 1674 | { 0xf9, "cut" }, |
| 1675 | { 0xfa, "lf" }, |
| 1676 | { 0xfb, "help" }, |
| 1677 | { 0xfc, "meta_l" }, |
| 1678 | { 0xfd, "meta_r" }, |
| 1679 | { 0xfe, "compose" }, |
| 1680 | #endif |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1681 | { 0, NULL }, |
| 1682 | }; |
| 1683 | |
| 1684 | static int get_keycode(const char *key) |
| 1685 | { |
| 1686 | const KeyDef *p; |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1687 | char *endp; |
| 1688 | int ret; |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1689 | |
| 1690 | for(p = key_defs; p->name != NULL; p++) { |
| 1691 | if (!strcmp(key, p->name)) |
| 1692 | return p->keycode; |
| 1693 | } |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 1694 | if (strstart(key, "0x", NULL)) { |
| 1695 | ret = strtoul(key, &endp, 0); |
| 1696 | if (*endp == '\0' && ret >= 0x01 && ret <= 0xff) |
| 1697 | return ret; |
| 1698 | } |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1699 | return -1; |
| 1700 | } |
| 1701 | |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1702 | #define MAX_KEYCODES 16 |
| 1703 | static uint8_t keycodes[MAX_KEYCODES]; |
| 1704 | static int nb_pending_keycodes; |
| 1705 | static QEMUTimer *key_timer; |
| 1706 | |
| 1707 | static void release_keys(void *opaque) |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1708 | { |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1709 | int keycode; |
| 1710 | |
| 1711 | while (nb_pending_keycodes > 0) { |
| 1712 | nb_pending_keycodes--; |
| 1713 | keycode = keycodes[nb_pending_keycodes]; |
| 1714 | if (keycode & 0x80) |
| 1715 | kbd_put_keycode(0xe0); |
| 1716 | kbd_put_keycode(keycode | 0x80); |
| 1717 | } |
| 1718 | } |
| 1719 | |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 1720 | static void do_sendkey(Monitor *mon, const QDict *qdict) |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1721 | { |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1722 | char keyname_buf[16]; |
| 1723 | char *separator; |
| 1724 | int keyname_len, keycode, i; |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 1725 | const char *string = qdict_get_str(qdict, "string"); |
| 1726 | int has_hold_time = qdict_haskey(qdict, "hold_time"); |
| 1727 | int hold_time = qdict_get_try_int(qdict, "hold_time", -1); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1728 | |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1729 | if (nb_pending_keycodes > 0) { |
| 1730 | qemu_del_timer(key_timer); |
| 1731 | release_keys(NULL); |
| 1732 | } |
| 1733 | if (!has_hold_time) |
| 1734 | hold_time = 100; |
| 1735 | i = 0; |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1736 | while (1) { |
| 1737 | separator = strchr(string, '-'); |
| 1738 | keyname_len = separator ? separator - string : strlen(string); |
| 1739 | if (keyname_len > 0) { |
| 1740 | pstrcpy(keyname_buf, sizeof(keyname_buf), string); |
| 1741 | if (keyname_len > sizeof(keyname_buf) - 1) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1742 | monitor_printf(mon, "invalid key: '%s...'\n", keyname_buf); |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1743 | return; |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1744 | } |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1745 | if (i == MAX_KEYCODES) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1746 | monitor_printf(mon, "too many keys\n"); |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1747 | return; |
| 1748 | } |
| 1749 | keyname_buf[keyname_len] = 0; |
| 1750 | keycode = get_keycode(keyname_buf); |
| 1751 | if (keycode < 0) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1752 | monitor_printf(mon, "unknown key: '%s'\n", keyname_buf); |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1753 | return; |
| 1754 | } |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1755 | keycodes[i++] = keycode; |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1756 | } |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1757 | if (!separator) |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1758 | break; |
balrog | 3401c0d | 2008-06-04 10:05:59 +0000 | [diff] [blame] | 1759 | string = separator + 1; |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1760 | } |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1761 | nb_pending_keycodes = i; |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1762 | /* key down events */ |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1763 | for (i = 0; i < nb_pending_keycodes; i++) { |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1764 | keycode = keycodes[i]; |
| 1765 | if (keycode & 0x80) |
| 1766 | kbd_put_keycode(0xe0); |
| 1767 | kbd_put_keycode(keycode & 0x7f); |
| 1768 | } |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 1769 | /* delayed key up events */ |
balrog | f227f17 | 2008-06-09 00:03:47 +0000 | [diff] [blame] | 1770 | qemu_mod_timer(key_timer, qemu_get_clock(vm_clock) + |
Juan Quintela | 6ee093c | 2009-09-10 03:04:26 +0200 | [diff] [blame] | 1771 | muldiv64(get_ticks_per_sec(), hold_time, 1000)); |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1772 | } |
| 1773 | |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1774 | static int mouse_button_state; |
| 1775 | |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 1776 | static void do_mouse_move(Monitor *mon, const QDict *qdict) |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1777 | { |
| 1778 | int dx, dy, dz; |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 1779 | const char *dx_str = qdict_get_str(qdict, "dx_str"); |
| 1780 | const char *dy_str = qdict_get_str(qdict, "dy_str"); |
| 1781 | const char *dz_str = qdict_get_try_str(qdict, "dz_str"); |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1782 | dx = strtol(dx_str, NULL, 0); |
| 1783 | dy = strtol(dy_str, NULL, 0); |
| 1784 | dz = 0; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1785 | if (dz_str) |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1786 | dz = strtol(dz_str, NULL, 0); |
| 1787 | kbd_mouse_event(dx, dy, dz, mouse_button_state); |
| 1788 | } |
| 1789 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1790 | static void do_mouse_button(Monitor *mon, const QDict *qdict) |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1791 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1792 | int button_state = qdict_get_int(qdict, "button_state"); |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 1793 | mouse_button_state = button_state; |
| 1794 | kbd_mouse_event(0, 0, 0, mouse_button_state); |
| 1795 | } |
| 1796 | |
Luiz Capitulino | aa93e39 | 2009-08-28 15:27:18 -0300 | [diff] [blame] | 1797 | static void do_ioport_read(Monitor *mon, const QDict *qdict) |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1798 | { |
Luiz Capitulino | aa93e39 | 2009-08-28 15:27:18 -0300 | [diff] [blame] | 1799 | int size = qdict_get_int(qdict, "size"); |
| 1800 | int addr = qdict_get_int(qdict, "addr"); |
| 1801 | int has_index = qdict_haskey(qdict, "index"); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1802 | uint32_t val; |
| 1803 | int suffix; |
| 1804 | |
| 1805 | if (has_index) { |
Luiz Capitulino | aa93e39 | 2009-08-28 15:27:18 -0300 | [diff] [blame] | 1806 | int index = qdict_get_int(qdict, "index"); |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1807 | cpu_outb(addr & IOPORTS_MASK, index & 0xff); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1808 | addr++; |
| 1809 | } |
| 1810 | addr &= 0xffff; |
| 1811 | |
| 1812 | switch(size) { |
| 1813 | default: |
| 1814 | case 1: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1815 | val = cpu_inb(addr); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1816 | suffix = 'b'; |
| 1817 | break; |
| 1818 | case 2: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1819 | val = cpu_inw(addr); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1820 | suffix = 'w'; |
| 1821 | break; |
| 1822 | case 4: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1823 | val = cpu_inl(addr); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1824 | suffix = 'l'; |
| 1825 | break; |
| 1826 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1827 | monitor_printf(mon, "port%c[0x%04x] = %#0*x\n", |
| 1828 | suffix, addr, size * 2, val); |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 1829 | } |
bellard | a3a91a3 | 2004-06-04 11:06:21 +0000 | [diff] [blame] | 1830 | |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1831 | static void do_ioport_write(Monitor *mon, const QDict *qdict) |
Jan Kiszka | f114784 | 2009-07-14 10:20:11 +0200 | [diff] [blame] | 1832 | { |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 1833 | int size = qdict_get_int(qdict, "size"); |
| 1834 | int addr = qdict_get_int(qdict, "addr"); |
| 1835 | int val = qdict_get_int(qdict, "val"); |
| 1836 | |
Jan Kiszka | f114784 | 2009-07-14 10:20:11 +0200 | [diff] [blame] | 1837 | addr &= IOPORTS_MASK; |
| 1838 | |
| 1839 | switch (size) { |
| 1840 | default: |
| 1841 | case 1: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1842 | cpu_outb(addr, val); |
Jan Kiszka | f114784 | 2009-07-14 10:20:11 +0200 | [diff] [blame] | 1843 | break; |
| 1844 | case 2: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1845 | cpu_outw(addr, val); |
Jan Kiszka | f114784 | 2009-07-14 10:20:11 +0200 | [diff] [blame] | 1846 | break; |
| 1847 | case 4: |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 1848 | cpu_outl(addr, val); |
Jan Kiszka | f114784 | 2009-07-14 10:20:11 +0200 | [diff] [blame] | 1849 | break; |
| 1850 | } |
| 1851 | } |
| 1852 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1853 | static void do_boot_set(Monitor *mon, const QDict *qdict) |
aurel32 | 0ecdffb | 2008-05-04 20:11:34 +0000 | [diff] [blame] | 1854 | { |
| 1855 | int res; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1856 | const char *bootdevice = qdict_get_str(qdict, "bootdevice"); |
aurel32 | 0ecdffb | 2008-05-04 20:11:34 +0000 | [diff] [blame] | 1857 | |
Jan Kiszka | 76e30d0 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1858 | res = qemu_boot_set(bootdevice); |
| 1859 | if (res == 0) { |
| 1860 | monitor_printf(mon, "boot device list now set to %s\n", bootdevice); |
| 1861 | } else if (res > 0) { |
| 1862 | monitor_printf(mon, "setting boot device list failed\n"); |
aurel32 | 0ecdffb | 2008-05-04 20:11:34 +0000 | [diff] [blame] | 1863 | } else { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1864 | monitor_printf(mon, "no function defined to set boot device list for " |
| 1865 | "this architecture\n"); |
aurel32 | 0ecdffb | 2008-05-04 20:11:34 +0000 | [diff] [blame] | 1866 | } |
| 1867 | } |
| 1868 | |
Luiz Capitulino | c80d259 | 2009-10-07 13:41:58 -0300 | [diff] [blame] | 1869 | /** |
| 1870 | * do_system_reset(): Issue a machine reset |
| 1871 | */ |
Luiz Capitulino | ef4b7ee | 2010-02-10 23:49:48 -0200 | [diff] [blame] | 1872 | static int do_system_reset(Monitor *mon, const QDict *qdict, |
| 1873 | QObject **ret_data) |
bellard | e4f9082 | 2004-06-20 12:35:44 +0000 | [diff] [blame] | 1874 | { |
| 1875 | qemu_system_reset_request(); |
Luiz Capitulino | ef4b7ee | 2010-02-10 23:49:48 -0200 | [diff] [blame] | 1876 | return 0; |
bellard | e4f9082 | 2004-06-20 12:35:44 +0000 | [diff] [blame] | 1877 | } |
| 1878 | |
Luiz Capitulino | 4307666 | 2009-10-07 13:41:59 -0300 | [diff] [blame] | 1879 | /** |
| 1880 | * do_system_powerdown(): Issue a machine powerdown |
| 1881 | */ |
Luiz Capitulino | ef4b7ee | 2010-02-10 23:49:48 -0200 | [diff] [blame] | 1882 | static int do_system_powerdown(Monitor *mon, const QDict *qdict, |
| 1883 | QObject **ret_data) |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 1884 | { |
| 1885 | qemu_system_powerdown_request(); |
Luiz Capitulino | ef4b7ee | 2010-02-10 23:49:48 -0200 | [diff] [blame] | 1886 | return 0; |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 1887 | } |
| 1888 | |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1889 | #if defined(TARGET_I386) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1890 | static void print_pte(Monitor *mon, uint32_t addr, uint32_t pte, uint32_t mask) |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1891 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1892 | monitor_printf(mon, "%08x: %08x %c%c%c%c%c%c%c%c\n", |
| 1893 | addr, |
| 1894 | pte & mask, |
| 1895 | pte & PG_GLOBAL_MASK ? 'G' : '-', |
| 1896 | pte & PG_PSE_MASK ? 'P' : '-', |
| 1897 | pte & PG_DIRTY_MASK ? 'D' : '-', |
| 1898 | pte & PG_ACCESSED_MASK ? 'A' : '-', |
| 1899 | pte & PG_PCD_MASK ? 'C' : '-', |
| 1900 | pte & PG_PWT_MASK ? 'T' : '-', |
| 1901 | pte & PG_USER_MASK ? 'U' : '-', |
| 1902 | pte & PG_RW_MASK ? 'W' : '-'); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1903 | } |
| 1904 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1905 | static void tlb_info(Monitor *mon) |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1906 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1907 | CPUState *env; |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1908 | int l1, l2; |
| 1909 | uint32_t pgd, pde, pte; |
| 1910 | |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1911 | env = mon_get_cpu(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1912 | |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1913 | if (!(env->cr[0] & CR0_PG_MASK)) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1914 | monitor_printf(mon, "PG disabled\n"); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1915 | return; |
| 1916 | } |
| 1917 | pgd = env->cr[3] & ~0xfff; |
| 1918 | for(l1 = 0; l1 < 1024; l1++) { |
| 1919 | cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4); |
| 1920 | pde = le32_to_cpu(pde); |
| 1921 | if (pde & PG_PRESENT_MASK) { |
| 1922 | if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1923 | print_pte(mon, (l1 << 22), pde, ~((1 << 20) - 1)); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1924 | } else { |
| 1925 | for(l2 = 0; l2 < 1024; l2++) { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1926 | cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1927 | (uint8_t *)&pte, 4); |
| 1928 | pte = le32_to_cpu(pte); |
| 1929 | if (pte & PG_PRESENT_MASK) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1930 | print_pte(mon, (l1 << 22) + (l2 << 12), |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1931 | pte & ~PG_PSE_MASK, |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1932 | ~0xfff); |
| 1933 | } |
| 1934 | } |
| 1935 | } |
| 1936 | } |
| 1937 | } |
| 1938 | } |
| 1939 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1940 | static void mem_print(Monitor *mon, uint32_t *pstart, int *plast_prot, |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1941 | uint32_t end, int prot) |
| 1942 | { |
bellard | 9746b15 | 2004-11-11 18:30:24 +0000 | [diff] [blame] | 1943 | int prot1; |
| 1944 | prot1 = *plast_prot; |
| 1945 | if (prot != prot1) { |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1946 | if (*pstart != -1) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1947 | monitor_printf(mon, "%08x-%08x %08x %c%c%c\n", |
| 1948 | *pstart, end, end - *pstart, |
| 1949 | prot1 & PG_USER_MASK ? 'u' : '-', |
| 1950 | 'r', |
| 1951 | prot1 & PG_RW_MASK ? 'w' : '-'); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1952 | } |
| 1953 | if (prot != 0) |
| 1954 | *pstart = end; |
| 1955 | else |
| 1956 | *pstart = -1; |
| 1957 | *plast_prot = prot; |
| 1958 | } |
| 1959 | } |
| 1960 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1961 | static void mem_info(Monitor *mon) |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1962 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1963 | CPUState *env; |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1964 | int l1, l2, prot, last_prot; |
| 1965 | uint32_t pgd, pde, pte, start, end; |
| 1966 | |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1967 | env = mon_get_cpu(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 1968 | |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1969 | if (!(env->cr[0] & CR0_PG_MASK)) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1970 | monitor_printf(mon, "PG disabled\n"); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1971 | return; |
| 1972 | } |
| 1973 | pgd = env->cr[3] & ~0xfff; |
| 1974 | last_prot = 0; |
| 1975 | start = -1; |
| 1976 | for(l1 = 0; l1 < 1024; l1++) { |
| 1977 | cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4); |
| 1978 | pde = le32_to_cpu(pde); |
| 1979 | end = l1 << 22; |
| 1980 | if (pde & PG_PRESENT_MASK) { |
| 1981 | if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { |
| 1982 | prot = pde & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1983 | mem_print(mon, &start, &last_prot, end, prot); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1984 | } else { |
| 1985 | for(l2 = 0; l2 < 1024; l2++) { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1986 | cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1987 | (uint8_t *)&pte, 4); |
| 1988 | pte = le32_to_cpu(pte); |
| 1989 | end = (l1 << 22) + (l2 << 12); |
| 1990 | if (pte & PG_PRESENT_MASK) { |
| 1991 | prot = pte & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK); |
| 1992 | } else { |
| 1993 | prot = 0; |
| 1994 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1995 | mem_print(mon, &start, &last_prot, end, prot); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 1996 | } |
| 1997 | } |
| 1998 | } else { |
| 1999 | prot = 0; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2000 | mem_print(mon, &start, &last_prot, end, prot); |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2001 | } |
| 2002 | } |
| 2003 | } |
| 2004 | #endif |
| 2005 | |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2006 | #if defined(TARGET_SH4) |
| 2007 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2008 | static void print_tlb(Monitor *mon, int idx, tlb_t *tlb) |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2009 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2010 | monitor_printf(mon, " tlb%i:\t" |
| 2011 | "asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t" |
| 2012 | "v=%hhu shared=%hhu cached=%hhu prot=%hhu " |
| 2013 | "dirty=%hhu writethrough=%hhu\n", |
| 2014 | idx, |
| 2015 | tlb->asid, tlb->vpn, tlb->ppn, tlb->sz, tlb->size, |
| 2016 | tlb->v, tlb->sh, tlb->c, tlb->pr, |
| 2017 | tlb->d, tlb->wt); |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2018 | } |
| 2019 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2020 | static void tlb_info(Monitor *mon) |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2021 | { |
| 2022 | CPUState *env = mon_get_cpu(); |
| 2023 | int i; |
| 2024 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2025 | monitor_printf (mon, "ITLB:\n"); |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2026 | for (i = 0 ; i < ITLB_SIZE ; i++) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2027 | print_tlb (mon, i, &env->itlb[i]); |
| 2028 | monitor_printf (mon, "UTLB:\n"); |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2029 | for (i = 0 ; i < UTLB_SIZE ; i++) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2030 | print_tlb (mon, i, &env->utlb[i]); |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2031 | } |
| 2032 | |
| 2033 | #endif |
| 2034 | |
Luiz Capitulino | 2af5ba7 | 2009-12-10 17:16:00 -0200 | [diff] [blame] | 2035 | static void do_info_kvm_print(Monitor *mon, const QObject *data) |
| 2036 | { |
| 2037 | QDict *qdict; |
| 2038 | |
| 2039 | qdict = qobject_to_qdict(data); |
| 2040 | |
| 2041 | monitor_printf(mon, "kvm support: "); |
| 2042 | if (qdict_get_bool(qdict, "present")) { |
| 2043 | monitor_printf(mon, "%s\n", qdict_get_bool(qdict, "enabled") ? |
| 2044 | "enabled" : "disabled"); |
| 2045 | } else { |
| 2046 | monitor_printf(mon, "not compiled\n"); |
| 2047 | } |
| 2048 | } |
| 2049 | |
| 2050 | /** |
| 2051 | * do_info_kvm(): Show KVM information |
| 2052 | * |
| 2053 | * Return a QDict with the following information: |
| 2054 | * |
| 2055 | * - "enabled": true if KVM support is enabled, false otherwise |
| 2056 | * - "present": true if QEMU has KVM support, false otherwise |
| 2057 | * |
| 2058 | * Example: |
| 2059 | * |
| 2060 | * { "enabled": true, "present": true } |
| 2061 | */ |
| 2062 | static void do_info_kvm(Monitor *mon, QObject **ret_data) |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 2063 | { |
| 2064 | #ifdef CONFIG_KVM |
Luiz Capitulino | 2af5ba7 | 2009-12-10 17:16:00 -0200 | [diff] [blame] | 2065 | *ret_data = qobject_from_jsonf("{ 'enabled': %i, 'present': true }", |
| 2066 | kvm_enabled()); |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 2067 | #else |
Luiz Capitulino | 2af5ba7 | 2009-12-10 17:16:00 -0200 | [diff] [blame] | 2068 | *ret_data = qobject_from_jsonf("{ 'enabled': false, 'present': false }"); |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 2069 | #endif |
| 2070 | } |
| 2071 | |
aliguori | 030ea37 | 2009-04-21 22:30:47 +0000 | [diff] [blame] | 2072 | static void do_info_numa(Monitor *mon) |
| 2073 | { |
aliguori | b28b623 | 2009-04-22 20:20:29 +0000 | [diff] [blame] | 2074 | int i; |
aliguori | 030ea37 | 2009-04-21 22:30:47 +0000 | [diff] [blame] | 2075 | CPUState *env; |
| 2076 | |
| 2077 | monitor_printf(mon, "%d nodes\n", nb_numa_nodes); |
| 2078 | for (i = 0; i < nb_numa_nodes; i++) { |
| 2079 | monitor_printf(mon, "node %d cpus:", i); |
| 2080 | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
| 2081 | if (env->numa_node == i) { |
| 2082 | monitor_printf(mon, " %d", env->cpu_index); |
| 2083 | } |
| 2084 | } |
| 2085 | monitor_printf(mon, "\n"); |
| 2086 | monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i, |
| 2087 | node_mem[i] >> 20); |
| 2088 | } |
| 2089 | } |
| 2090 | |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 2091 | #ifdef CONFIG_PROFILER |
| 2092 | |
Aurelien Jarno | e9a6625 | 2009-09-30 14:09:52 +0200 | [diff] [blame] | 2093 | int64_t qemu_time; |
| 2094 | int64_t dev_time; |
| 2095 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2096 | static void do_info_profile(Monitor *mon) |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 2097 | { |
| 2098 | int64_t total; |
| 2099 | total = qemu_time; |
| 2100 | if (total == 0) |
| 2101 | total = 1; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2102 | monitor_printf(mon, "async time %" PRId64 " (%0.3f)\n", |
Juan Quintela | 6ee093c | 2009-09-10 03:04:26 +0200 | [diff] [blame] | 2103 | dev_time, dev_time / (double)get_ticks_per_sec()); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2104 | monitor_printf(mon, "qemu time %" PRId64 " (%0.3f)\n", |
Juan Quintela | 6ee093c | 2009-09-10 03:04:26 +0200 | [diff] [blame] | 2105 | qemu_time, qemu_time / (double)get_ticks_per_sec()); |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 2106 | qemu_time = 0; |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 2107 | dev_time = 0; |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 2108 | } |
| 2109 | #else |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2110 | static void do_info_profile(Monitor *mon) |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 2111 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2112 | monitor_printf(mon, "Internal profiler not compiled\n"); |
bellard | 5f1ce94 | 2006-02-08 22:40:15 +0000 | [diff] [blame] | 2113 | } |
| 2114 | #endif |
| 2115 | |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2116 | /* Capture support */ |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2117 | static QLIST_HEAD (capture_list_head, CaptureState) capture_head; |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2118 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2119 | static void do_info_capture(Monitor *mon) |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2120 | { |
| 2121 | int i; |
| 2122 | CaptureState *s; |
| 2123 | |
| 2124 | for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2125 | monitor_printf(mon, "[%d]: ", i); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2126 | s->ops.info (s->opaque); |
| 2127 | } |
| 2128 | } |
| 2129 | |
Blue Swirl | 2313086 | 2009-06-06 08:22:04 +0000 | [diff] [blame] | 2130 | #ifdef HAS_AUDIO |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2131 | static void do_stop_capture(Monitor *mon, const QDict *qdict) |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2132 | { |
| 2133 | int i; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2134 | int n = qdict_get_int(qdict, "n"); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2135 | CaptureState *s; |
| 2136 | |
| 2137 | for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) { |
| 2138 | if (i == n) { |
| 2139 | s->ops.destroy (s->opaque); |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2140 | QLIST_REMOVE (s, entries); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2141 | qemu_free (s); |
| 2142 | return; |
| 2143 | } |
| 2144 | } |
| 2145 | } |
| 2146 | |
Luiz Capitulino | c192548 | 2009-08-28 15:27:19 -0300 | [diff] [blame] | 2147 | static void do_wav_capture(Monitor *mon, const QDict *qdict) |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2148 | { |
Luiz Capitulino | c192548 | 2009-08-28 15:27:19 -0300 | [diff] [blame] | 2149 | const char *path = qdict_get_str(qdict, "path"); |
| 2150 | int has_freq = qdict_haskey(qdict, "freq"); |
| 2151 | int freq = qdict_get_try_int(qdict, "freq", -1); |
| 2152 | int has_bits = qdict_haskey(qdict, "bits"); |
| 2153 | int bits = qdict_get_try_int(qdict, "bits", -1); |
| 2154 | int has_channels = qdict_haskey(qdict, "nchannels"); |
| 2155 | int nchannels = qdict_get_try_int(qdict, "nchannels", -1); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2156 | CaptureState *s; |
| 2157 | |
| 2158 | s = qemu_mallocz (sizeof (*s)); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2159 | |
| 2160 | freq = has_freq ? freq : 44100; |
| 2161 | bits = has_bits ? bits : 16; |
| 2162 | nchannels = has_channels ? nchannels : 2; |
| 2163 | |
| 2164 | if (wav_start_capture (s, path, freq, bits, nchannels)) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 2165 | monitor_printf(mon, "Faied to add wave capture\n"); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2166 | qemu_free (s); |
| 2167 | } |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2168 | QLIST_INSERT_HEAD (&capture_head, s, entries); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 2169 | } |
| 2170 | #endif |
| 2171 | |
aurel32 | dc1c0b7 | 2008-04-27 23:52:12 +0000 | [diff] [blame] | 2172 | #if defined(TARGET_I386) |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2173 | static void do_inject_nmi(Monitor *mon, const QDict *qdict) |
aurel32 | dc1c0b7 | 2008-04-27 23:52:12 +0000 | [diff] [blame] | 2174 | { |
| 2175 | CPUState *env; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2176 | int cpu_index = qdict_get_int(qdict, "cpu_index"); |
aurel32 | dc1c0b7 | 2008-04-27 23:52:12 +0000 | [diff] [blame] | 2177 | |
| 2178 | for (env = first_cpu; env != NULL; env = env->next_cpu) |
| 2179 | if (env->cpu_index == cpu_index) { |
| 2180 | cpu_interrupt(env, CPU_INTERRUPT_NMI); |
| 2181 | break; |
| 2182 | } |
| 2183 | } |
| 2184 | #endif |
| 2185 | |
Luiz Capitulino | c0e8520 | 2009-12-10 17:15:59 -0200 | [diff] [blame] | 2186 | static void do_info_status_print(Monitor *mon, const QObject *data) |
aurel32 | 6f9c5ee | 2008-12-18 22:43:56 +0000 | [diff] [blame] | 2187 | { |
Luiz Capitulino | c0e8520 | 2009-12-10 17:15:59 -0200 | [diff] [blame] | 2188 | QDict *qdict; |
| 2189 | |
| 2190 | qdict = qobject_to_qdict(data); |
| 2191 | |
| 2192 | monitor_printf(mon, "VM status: "); |
| 2193 | if (qdict_get_bool(qdict, "running")) { |
| 2194 | monitor_printf(mon, "running"); |
| 2195 | if (qdict_get_bool(qdict, "singlestep")) { |
| 2196 | monitor_printf(mon, " (single step mode)"); |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 2197 | } |
Luiz Capitulino | c0e8520 | 2009-12-10 17:15:59 -0200 | [diff] [blame] | 2198 | } else { |
| 2199 | monitor_printf(mon, "paused"); |
| 2200 | } |
| 2201 | |
| 2202 | monitor_printf(mon, "\n"); |
| 2203 | } |
| 2204 | |
| 2205 | /** |
| 2206 | * do_info_status(): VM status |
| 2207 | * |
| 2208 | * Return a QDict with the following information: |
| 2209 | * |
| 2210 | * - "running": true if the VM is running, or false if it is paused |
| 2211 | * - "singlestep": true if the VM is in single step mode, false otherwise |
| 2212 | * |
| 2213 | * Example: |
| 2214 | * |
| 2215 | * { "running": true, "singlestep": false } |
| 2216 | */ |
| 2217 | static void do_info_status(Monitor *mon, QObject **ret_data) |
| 2218 | { |
| 2219 | *ret_data = qobject_from_jsonf("{ 'running': %i, 'singlestep': %i }", |
| 2220 | vm_running, singlestep); |
aurel32 | 6f9c5ee | 2008-12-18 22:43:56 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
Adam Litke | 625a5be | 2010-01-26 14:17:35 -0600 | [diff] [blame] | 2223 | static void print_balloon_stat(const char *key, QObject *obj, void *opaque) |
Luiz Capitulino | cfdf2c4 | 2009-12-14 18:53:22 -0200 | [diff] [blame] | 2224 | { |
Adam Litke | 625a5be | 2010-01-26 14:17:35 -0600 | [diff] [blame] | 2225 | Monitor *mon = opaque; |
Luiz Capitulino | cfdf2c4 | 2009-12-14 18:53:22 -0200 | [diff] [blame] | 2226 | |
Adam Litke | 625a5be | 2010-01-26 14:17:35 -0600 | [diff] [blame] | 2227 | if (strcmp(key, "actual")) |
| 2228 | monitor_printf(mon, ",%s=%" PRId64, key, |
| 2229 | qint_get_int(qobject_to_qint(obj))); |
aliguori | df751fa | 2008-12-04 20:19:35 +0000 | [diff] [blame] | 2230 | } |
| 2231 | |
Luiz Capitulino | cc1d9c7 | 2009-10-07 13:42:03 -0300 | [diff] [blame] | 2232 | static void monitor_print_balloon(Monitor *mon, const QObject *data) |
| 2233 | { |
Luiz Capitulino | 7f17967 | 2009-12-10 17:15:55 -0200 | [diff] [blame] | 2234 | QDict *qdict; |
| 2235 | |
| 2236 | qdict = qobject_to_qdict(data); |
Adam Litke | 625a5be | 2010-01-26 14:17:35 -0600 | [diff] [blame] | 2237 | if (!qdict_haskey(qdict, "actual")) |
| 2238 | return; |
Luiz Capitulino | 7f17967 | 2009-12-10 17:15:55 -0200 | [diff] [blame] | 2239 | |
Adam Litke | 625a5be | 2010-01-26 14:17:35 -0600 | [diff] [blame] | 2240 | monitor_printf(mon, "balloon: actual=%" PRId64, |
| 2241 | qdict_get_int(qdict, "actual") >> 20); |
| 2242 | qdict_iter(qdict, print_balloon_stat, mon); |
| 2243 | monitor_printf(mon, "\n"); |
Luiz Capitulino | cc1d9c7 | 2009-10-07 13:42:03 -0300 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | /** |
| 2247 | * do_info_balloon(): Balloon information |
Luiz Capitulino | 7f17967 | 2009-12-10 17:15:55 -0200 | [diff] [blame] | 2248 | * |
Adam Litke | 625a5be | 2010-01-26 14:17:35 -0600 | [diff] [blame] | 2249 | * Make an asynchronous request for balloon info. When the request completes |
| 2250 | * a QDict will be returned according to the following specification: |
Luiz Capitulino | 7f17967 | 2009-12-10 17:15:55 -0200 | [diff] [blame] | 2251 | * |
Adam Litke | 625a5be | 2010-01-26 14:17:35 -0600 | [diff] [blame] | 2252 | * - "actual": current balloon value in bytes |
| 2253 | * The following fields may or may not be present: |
| 2254 | * - "mem_swapped_in": Amount of memory swapped in (bytes) |
| 2255 | * - "mem_swapped_out": Amount of memory swapped out (bytes) |
| 2256 | * - "major_page_faults": Number of major faults |
| 2257 | * - "minor_page_faults": Number of minor faults |
| 2258 | * - "free_mem": Total amount of free and unused memory (bytes) |
| 2259 | * - "total_mem": Total amount of available memory (bytes) |
Luiz Capitulino | 7f17967 | 2009-12-10 17:15:55 -0200 | [diff] [blame] | 2260 | * |
| 2261 | * Example: |
| 2262 | * |
Adam Litke | 625a5be | 2010-01-26 14:17:35 -0600 | [diff] [blame] | 2263 | * { "actual": 1073741824, "mem_swapped_in": 0, "mem_swapped_out": 0, |
| 2264 | * "major_page_faults": 142, "minor_page_faults": 239245, |
| 2265 | * "free_mem": 1014185984, "total_mem": 1044668416 } |
Luiz Capitulino | cc1d9c7 | 2009-10-07 13:42:03 -0300 | [diff] [blame] | 2266 | */ |
Adam Litke | 625a5be | 2010-01-26 14:17:35 -0600 | [diff] [blame] | 2267 | static int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque) |
aliguori | df751fa | 2008-12-04 20:19:35 +0000 | [diff] [blame] | 2268 | { |
Adam Litke | 625a5be | 2010-01-26 14:17:35 -0600 | [diff] [blame] | 2269 | int ret; |
aliguori | df751fa | 2008-12-04 20:19:35 +0000 | [diff] [blame] | 2270 | |
Adam Litke | 625a5be | 2010-01-26 14:17:35 -0600 | [diff] [blame] | 2271 | if (kvm_enabled() && !kvm_has_sync_mmu()) { |
| 2272 | qemu_error_new(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); |
| 2273 | return -1; |
Luiz Capitulino | cfdf2c4 | 2009-12-14 18:53:22 -0200 | [diff] [blame] | 2274 | } |
Adam Litke | 625a5be | 2010-01-26 14:17:35 -0600 | [diff] [blame] | 2275 | |
| 2276 | ret = qemu_balloon_status(cb, opaque); |
| 2277 | if (!ret) { |
| 2278 | qemu_error_new(QERR_DEVICE_NOT_ACTIVE, "balloon"); |
| 2279 | return -1; |
| 2280 | } |
| 2281 | |
| 2282 | return 0; |
| 2283 | } |
| 2284 | |
| 2285 | /** |
| 2286 | * do_balloon(): Request VM to change its memory allocation |
| 2287 | */ |
| 2288 | static int do_balloon(Monitor *mon, const QDict *params, |
| 2289 | MonitorCompletion cb, void *opaque) |
| 2290 | { |
| 2291 | int ret; |
| 2292 | |
| 2293 | if (kvm_enabled() && !kvm_has_sync_mmu()) { |
| 2294 | qemu_error_new(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); |
| 2295 | return -1; |
| 2296 | } |
| 2297 | |
| 2298 | ret = qemu_balloon(qdict_get_int(params, "value"), cb, opaque); |
| 2299 | if (ret == 0) { |
| 2300 | qemu_error_new(QERR_DEVICE_NOT_ACTIVE, "balloon"); |
| 2301 | return -1; |
| 2302 | } |
| 2303 | |
| 2304 | return 0; |
aliguori | df751fa | 2008-12-04 20:19:35 +0000 | [diff] [blame] | 2305 | } |
| 2306 | |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2307 | static qemu_acl *find_acl(Monitor *mon, const char *name) |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2308 | { |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2309 | qemu_acl *acl = qemu_acl_find(name); |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2310 | |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2311 | if (!acl) { |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2312 | monitor_printf(mon, "acl: unknown list '%s'\n", name); |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2313 | } |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2314 | return acl; |
| 2315 | } |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2316 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2317 | static void do_acl_show(Monitor *mon, const QDict *qdict) |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2318 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2319 | const char *aclname = qdict_get_str(qdict, "aclname"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2320 | qemu_acl *acl = find_acl(mon, aclname); |
| 2321 | qemu_acl_entry *entry; |
| 2322 | int i = 0; |
| 2323 | |
| 2324 | if (acl) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2325 | monitor_printf(mon, "policy: %s\n", |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2326 | acl->defaultDeny ? "deny" : "allow"); |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2327 | QTAILQ_FOREACH(entry, &acl->entries, next) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2328 | i++; |
| 2329 | monitor_printf(mon, "%d: %s %s\n", i, |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2330 | entry->deny ? "deny" : "allow", entry->match); |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2331 | } |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2335 | static void do_acl_reset(Monitor *mon, const QDict *qdict) |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2336 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2337 | const char *aclname = qdict_get_str(qdict, "aclname"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2338 | qemu_acl *acl = find_acl(mon, aclname); |
| 2339 | |
| 2340 | if (acl) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2341 | qemu_acl_reset(acl); |
| 2342 | monitor_printf(mon, "acl: removed all rules\n"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2343 | } |
| 2344 | } |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2345 | |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 2346 | static void do_acl_policy(Monitor *mon, const QDict *qdict) |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2347 | { |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 2348 | const char *aclname = qdict_get_str(qdict, "aclname"); |
| 2349 | const char *policy = qdict_get_str(qdict, "policy"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2350 | qemu_acl *acl = find_acl(mon, aclname); |
| 2351 | |
| 2352 | if (acl) { |
| 2353 | if (strcmp(policy, "allow") == 0) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2354 | acl->defaultDeny = 0; |
| 2355 | monitor_printf(mon, "acl: policy set to 'allow'\n"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2356 | } else if (strcmp(policy, "deny") == 0) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2357 | acl->defaultDeny = 1; |
| 2358 | monitor_printf(mon, "acl: policy set to 'deny'\n"); |
| 2359 | } else { |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2360 | monitor_printf(mon, "acl: unknown policy '%s', " |
| 2361 | "expected 'deny' or 'allow'\n", policy); |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2362 | } |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2363 | } |
| 2364 | } |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2365 | |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 2366 | static void do_acl_add(Monitor *mon, const QDict *qdict) |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2367 | { |
Luiz Capitulino | 1bd1442 | 2009-08-28 15:27:17 -0300 | [diff] [blame] | 2368 | const char *aclname = qdict_get_str(qdict, "aclname"); |
| 2369 | const char *match = qdict_get_str(qdict, "match"); |
| 2370 | const char *policy = qdict_get_str(qdict, "policy"); |
| 2371 | int has_index = qdict_haskey(qdict, "index"); |
| 2372 | int index = qdict_get_try_int(qdict, "index", -1); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2373 | qemu_acl *acl = find_acl(mon, aclname); |
| 2374 | int deny, ret; |
| 2375 | |
| 2376 | if (acl) { |
| 2377 | if (strcmp(policy, "allow") == 0) { |
| 2378 | deny = 0; |
| 2379 | } else if (strcmp(policy, "deny") == 0) { |
| 2380 | deny = 1; |
| 2381 | } else { |
| 2382 | monitor_printf(mon, "acl: unknown policy '%s', " |
| 2383 | "expected 'deny' or 'allow'\n", policy); |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2384 | return; |
| 2385 | } |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2386 | if (has_index) |
| 2387 | ret = qemu_acl_insert(acl, deny, match, index); |
| 2388 | else |
| 2389 | ret = qemu_acl_append(acl, deny, match); |
| 2390 | if (ret < 0) |
| 2391 | monitor_printf(mon, "acl: unable to add acl entry\n"); |
| 2392 | else |
| 2393 | monitor_printf(mon, "acl: added rule at position %d\n", ret); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2394 | } |
| 2395 | } |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2396 | |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 2397 | static void do_acl_remove(Monitor *mon, const QDict *qdict) |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2398 | { |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 2399 | const char *aclname = qdict_get_str(qdict, "aclname"); |
| 2400 | const char *match = qdict_get_str(qdict, "match"); |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2401 | qemu_acl *acl = find_acl(mon, aclname); |
| 2402 | int ret; |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2403 | |
Jan Kiszka | 15dfcd4 | 2009-06-25 08:22:08 +0200 | [diff] [blame] | 2404 | if (acl) { |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2405 | ret = qemu_acl_remove(acl, match); |
| 2406 | if (ret < 0) |
| 2407 | monitor_printf(mon, "acl: no matching acl entry\n"); |
| 2408 | else |
| 2409 | monitor_printf(mon, "acl: removed rule at position %d\n", ret); |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 2410 | } |
| 2411 | } |
| 2412 | |
Huang Ying | 79c4f6b | 2009-06-23 10:05:14 +0800 | [diff] [blame] | 2413 | #if defined(TARGET_I386) |
Luiz Capitulino | 37b7ad4 | 2009-08-28 15:27:21 -0300 | [diff] [blame] | 2414 | static void do_inject_mce(Monitor *mon, const QDict *qdict) |
Huang Ying | 79c4f6b | 2009-06-23 10:05:14 +0800 | [diff] [blame] | 2415 | { |
| 2416 | CPUState *cenv; |
Luiz Capitulino | 37b7ad4 | 2009-08-28 15:27:21 -0300 | [diff] [blame] | 2417 | int cpu_index = qdict_get_int(qdict, "cpu_index"); |
| 2418 | int bank = qdict_get_int(qdict, "bank"); |
| 2419 | uint64_t status = qdict_get_int(qdict, "status"); |
| 2420 | uint64_t mcg_status = qdict_get_int(qdict, "mcg_status"); |
| 2421 | uint64_t addr = qdict_get_int(qdict, "addr"); |
| 2422 | uint64_t misc = qdict_get_int(qdict, "misc"); |
Huang Ying | 79c4f6b | 2009-06-23 10:05:14 +0800 | [diff] [blame] | 2423 | |
| 2424 | for (cenv = first_cpu; cenv != NULL; cenv = cenv->next_cpu) |
| 2425 | if (cenv->cpu_index == cpu_index && cenv->mcg_cap) { |
| 2426 | cpu_inject_x86_mce(cenv, bank, status, mcg_status, addr, misc); |
| 2427 | break; |
| 2428 | } |
| 2429 | } |
| 2430 | #endif |
| 2431 | |
Luiz Capitulino | 6ad3ebd | 2010-02-10 23:49:53 -0200 | [diff] [blame] | 2432 | static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data) |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2433 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2434 | const char *fdname = qdict_get_str(qdict, "fdname"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2435 | mon_fd_t *monfd; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2436 | int fd; |
| 2437 | |
| 2438 | fd = qemu_chr_get_msgfd(mon->chr); |
| 2439 | if (fd == -1) { |
Markus Armbruster | 7cdfcfe | 2009-12-07 21:37:15 +0100 | [diff] [blame] | 2440 | qemu_error_new(QERR_FD_NOT_SUPPLIED); |
Luiz Capitulino | 6ad3ebd | 2010-02-10 23:49:53 -0200 | [diff] [blame] | 2441 | return -1; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | if (qemu_isdigit(fdname[0])) { |
Markus Armbruster | 7cdfcfe | 2009-12-07 21:37:15 +0100 | [diff] [blame] | 2445 | qemu_error_new(QERR_INVALID_PARAMETER, "fdname"); |
Luiz Capitulino | 6ad3ebd | 2010-02-10 23:49:53 -0200 | [diff] [blame] | 2446 | return -1; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | fd = dup(fd); |
| 2450 | if (fd == -1) { |
Markus Armbruster | 7cdfcfe | 2009-12-07 21:37:15 +0100 | [diff] [blame] | 2451 | if (errno == EMFILE) |
| 2452 | qemu_error_new(QERR_TOO_MANY_FILES); |
| 2453 | else |
| 2454 | qemu_error_new(QERR_UNDEFINED_ERROR); |
Luiz Capitulino | 6ad3ebd | 2010-02-10 23:49:53 -0200 | [diff] [blame] | 2455 | return -1; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2456 | } |
| 2457 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2458 | QLIST_FOREACH(monfd, &mon->fds, next) { |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2459 | if (strcmp(monfd->name, fdname) != 0) { |
| 2460 | continue; |
| 2461 | } |
| 2462 | |
| 2463 | close(monfd->fd); |
| 2464 | monfd->fd = fd; |
Luiz Capitulino | 6ad3ebd | 2010-02-10 23:49:53 -0200 | [diff] [blame] | 2465 | return 0; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2466 | } |
| 2467 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2468 | monfd = qemu_mallocz(sizeof(mon_fd_t)); |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2469 | monfd->name = qemu_strdup(fdname); |
| 2470 | monfd->fd = fd; |
| 2471 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2472 | QLIST_INSERT_HEAD(&mon->fds, monfd, next); |
Luiz Capitulino | 6ad3ebd | 2010-02-10 23:49:53 -0200 | [diff] [blame] | 2473 | return 0; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2474 | } |
| 2475 | |
Luiz Capitulino | aeb91c1 | 2010-02-10 23:49:54 -0200 | [diff] [blame] | 2476 | static int do_closefd(Monitor *mon, const QDict *qdict, QObject **ret_data) |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2477 | { |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2478 | const char *fdname = qdict_get_str(qdict, "fdname"); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2479 | mon_fd_t *monfd; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2480 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2481 | QLIST_FOREACH(monfd, &mon->fds, next) { |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2482 | if (strcmp(monfd->name, fdname) != 0) { |
| 2483 | continue; |
| 2484 | } |
| 2485 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2486 | QLIST_REMOVE(monfd, next); |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2487 | close(monfd->fd); |
| 2488 | qemu_free(monfd->name); |
| 2489 | qemu_free(monfd); |
Luiz Capitulino | aeb91c1 | 2010-02-10 23:49:54 -0200 | [diff] [blame] | 2490 | return 0; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2491 | } |
| 2492 | |
Markus Armbruster | 063c1a0 | 2009-12-07 21:37:11 +0100 | [diff] [blame] | 2493 | qemu_error_new(QERR_FD_NOT_FOUND, fdname); |
Luiz Capitulino | aeb91c1 | 2010-02-10 23:49:54 -0200 | [diff] [blame] | 2494 | return -1; |
Mark McLoughlin | f07918f | 2009-07-22 09:11:40 +0100 | [diff] [blame] | 2495 | } |
| 2496 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2497 | static void do_loadvm(Monitor *mon, const QDict *qdict) |
Juan Quintela | c8d41b2 | 2009-08-20 19:42:21 +0200 | [diff] [blame] | 2498 | { |
| 2499 | int saved_vm_running = vm_running; |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 2500 | const char *name = qdict_get_str(qdict, "name"); |
Juan Quintela | c8d41b2 | 2009-08-20 19:42:21 +0200 | [diff] [blame] | 2501 | |
| 2502 | vm_stop(0); |
| 2503 | |
Juan Quintela | 05f2401 | 2009-08-20 19:42:22 +0200 | [diff] [blame] | 2504 | if (load_vmstate(mon, name) >= 0 && saved_vm_running) |
Juan Quintela | c8d41b2 | 2009-08-20 19:42:21 +0200 | [diff] [blame] | 2505 | vm_start(); |
| 2506 | } |
| 2507 | |
Mark McLoughlin | 7768e04 | 2009-07-22 09:11:41 +0100 | [diff] [blame] | 2508 | int monitor_get_fd(Monitor *mon, const char *fdname) |
| 2509 | { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2510 | mon_fd_t *monfd; |
Mark McLoughlin | 7768e04 | 2009-07-22 09:11:41 +0100 | [diff] [blame] | 2511 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2512 | QLIST_FOREACH(monfd, &mon->fds, next) { |
Mark McLoughlin | 7768e04 | 2009-07-22 09:11:41 +0100 | [diff] [blame] | 2513 | int fd; |
| 2514 | |
| 2515 | if (strcmp(monfd->name, fdname) != 0) { |
| 2516 | continue; |
| 2517 | } |
| 2518 | |
| 2519 | fd = monfd->fd; |
| 2520 | |
| 2521 | /* caller takes ownership of fd */ |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2522 | QLIST_REMOVE(monfd, next); |
Mark McLoughlin | 7768e04 | 2009-07-22 09:11:41 +0100 | [diff] [blame] | 2523 | qemu_free(monfd->name); |
| 2524 | qemu_free(monfd); |
| 2525 | |
| 2526 | return fd; |
| 2527 | } |
| 2528 | |
| 2529 | return -1; |
| 2530 | } |
| 2531 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2532 | static const mon_cmd_t mon_cmds[] = { |
Blue Swirl | 2313086 | 2009-06-06 08:22:04 +0000 | [diff] [blame] | 2533 | #include "qemu-monitor.h" |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 2534 | { NULL, NULL, }, |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 2535 | }; |
| 2536 | |
Blue Swirl | 2313086 | 2009-06-06 08:22:04 +0000 | [diff] [blame] | 2537 | /* Please update qemu-monitor.hx when adding or changing commands */ |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2538 | static const mon_cmd_t info_cmds[] = { |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2539 | { |
| 2540 | .name = "version", |
| 2541 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2542 | .params = "", |
| 2543 | .help = "show the version of QEMU", |
Luiz Capitulino | 45e914c | 2009-12-10 17:15:58 -0200 | [diff] [blame] | 2544 | .user_print = do_info_version_print, |
Luiz Capitulino | ab2d318 | 2009-10-07 13:42:02 -0300 | [diff] [blame] | 2545 | .mhandler.info_new = do_info_version, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2546 | }, |
| 2547 | { |
Luiz Capitulino | e3bba9d | 2009-11-26 22:58:56 -0200 | [diff] [blame] | 2548 | .name = "commands", |
| 2549 | .args_type = "", |
| 2550 | .params = "", |
| 2551 | .help = "list QMP available commands", |
| 2552 | .user_print = monitor_user_noop, |
| 2553 | .mhandler.info_new = do_info_commands, |
| 2554 | }, |
| 2555 | { |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2556 | .name = "network", |
| 2557 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2558 | .params = "", |
| 2559 | .help = "show the network state", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2560 | .mhandler.info = do_info_network, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2561 | }, |
| 2562 | { |
| 2563 | .name = "chardev", |
| 2564 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2565 | .params = "", |
| 2566 | .help = "show the character devices", |
Luiz Capitulino | 588b383 | 2009-12-10 17:16:08 -0200 | [diff] [blame] | 2567 | .user_print = qemu_chr_info_print, |
| 2568 | .mhandler.info_new = qemu_chr_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2569 | }, |
| 2570 | { |
| 2571 | .name = "block", |
| 2572 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2573 | .params = "", |
| 2574 | .help = "show the block devices", |
Luiz Capitulino | d15e546 | 2009-12-10 17:16:06 -0200 | [diff] [blame] | 2575 | .user_print = bdrv_info_print, |
| 2576 | .mhandler.info_new = bdrv_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2577 | }, |
| 2578 | { |
| 2579 | .name = "blockstats", |
| 2580 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2581 | .params = "", |
| 2582 | .help = "show block device statistics", |
Luiz Capitulino | 218a536 | 2009-12-10 17:16:07 -0200 | [diff] [blame] | 2583 | .user_print = bdrv_stats_print, |
| 2584 | .mhandler.info_new = bdrv_info_stats, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2585 | }, |
| 2586 | { |
| 2587 | .name = "registers", |
| 2588 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2589 | .params = "", |
| 2590 | .help = "show the cpu registers", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2591 | .mhandler.info = do_info_registers, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2592 | }, |
| 2593 | { |
| 2594 | .name = "cpus", |
| 2595 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2596 | .params = "", |
| 2597 | .help = "show infos for each CPU", |
Luiz Capitulino | 8f3cec0 | 2009-10-07 13:42:04 -0300 | [diff] [blame] | 2598 | .user_print = monitor_print_cpus, |
| 2599 | .mhandler.info_new = do_info_cpus, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2600 | }, |
| 2601 | { |
| 2602 | .name = "history", |
| 2603 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2604 | .params = "", |
| 2605 | .help = "show the command line history", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2606 | .mhandler.info = do_info_history, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2607 | }, |
| 2608 | { |
| 2609 | .name = "irq", |
| 2610 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2611 | .params = "", |
| 2612 | .help = "show the interrupts statistics (if available)", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2613 | .mhandler.info = irq_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2614 | }, |
| 2615 | { |
| 2616 | .name = "pic", |
| 2617 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2618 | .params = "", |
| 2619 | .help = "show i8259 (PIC) state", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2620 | .mhandler.info = pic_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2621 | }, |
| 2622 | { |
| 2623 | .name = "pci", |
| 2624 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2625 | .params = "", |
| 2626 | .help = "show PCI info", |
Luiz Capitulino | 163c8a5 | 2010-01-21 19:15:40 -0200 | [diff] [blame] | 2627 | .user_print = do_pci_info_print, |
| 2628 | .mhandler.info_new = do_pci_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2629 | }, |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2630 | #if defined(TARGET_I386) || defined(TARGET_SH4) |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2631 | { |
| 2632 | .name = "tlb", |
| 2633 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2634 | .params = "", |
| 2635 | .help = "show virtual to physical memory mappings", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2636 | .mhandler.info = tlb_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2637 | }, |
aurel32 | 7c664e2 | 2009-03-03 06:12:22 +0000 | [diff] [blame] | 2638 | #endif |
| 2639 | #if defined(TARGET_I386) |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2640 | { |
| 2641 | .name = "mem", |
| 2642 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2643 | .params = "", |
| 2644 | .help = "show the active virtual memory mappings", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2645 | .mhandler.info = mem_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2646 | }, |
| 2647 | { |
| 2648 | .name = "hpet", |
| 2649 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2650 | .params = "", |
| 2651 | .help = "show state of HPET", |
Luiz Capitulino | 14f0720 | 2009-12-10 17:16:02 -0200 | [diff] [blame] | 2652 | .user_print = do_info_hpet_print, |
| 2653 | .mhandler.info_new = do_info_hpet, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2654 | }, |
bellard | b86bda5 | 2004-09-18 19:32:46 +0000 | [diff] [blame] | 2655 | #endif |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2656 | { |
| 2657 | .name = "jit", |
| 2658 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2659 | .params = "", |
| 2660 | .help = "show dynamic compiler info", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2661 | .mhandler.info = do_info_jit, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2662 | }, |
| 2663 | { |
| 2664 | .name = "kvm", |
| 2665 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2666 | .params = "", |
| 2667 | .help = "show KVM information", |
Luiz Capitulino | 2af5ba7 | 2009-12-10 17:16:00 -0200 | [diff] [blame] | 2668 | .user_print = do_info_kvm_print, |
| 2669 | .mhandler.info_new = do_info_kvm, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2670 | }, |
| 2671 | { |
| 2672 | .name = "numa", |
| 2673 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2674 | .params = "", |
| 2675 | .help = "show NUMA information", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2676 | .mhandler.info = do_info_numa, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2677 | }, |
| 2678 | { |
| 2679 | .name = "usb", |
| 2680 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2681 | .params = "", |
| 2682 | .help = "show guest USB devices", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2683 | .mhandler.info = usb_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2684 | }, |
| 2685 | { |
| 2686 | .name = "usbhost", |
| 2687 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2688 | .params = "", |
| 2689 | .help = "show host USB devices", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2690 | .mhandler.info = usb_host_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2691 | }, |
| 2692 | { |
| 2693 | .name = "profile", |
| 2694 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2695 | .params = "", |
| 2696 | .help = "show profiling information", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2697 | .mhandler.info = do_info_profile, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2698 | }, |
| 2699 | { |
| 2700 | .name = "capture", |
| 2701 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2702 | .params = "", |
| 2703 | .help = "show capture information", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2704 | .mhandler.info = do_info_capture, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2705 | }, |
| 2706 | { |
| 2707 | .name = "snapshots", |
| 2708 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2709 | .params = "", |
| 2710 | .help = "show the currently saved VM snapshots", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2711 | .mhandler.info = do_info_snapshots, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2712 | }, |
| 2713 | { |
| 2714 | .name = "status", |
| 2715 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2716 | .params = "", |
| 2717 | .help = "show the current VM status (running|paused)", |
Luiz Capitulino | c0e8520 | 2009-12-10 17:15:59 -0200 | [diff] [blame] | 2718 | .user_print = do_info_status_print, |
| 2719 | .mhandler.info_new = do_info_status, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2720 | }, |
| 2721 | { |
| 2722 | .name = "pcmcia", |
| 2723 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2724 | .params = "", |
| 2725 | .help = "show guest PCMCIA status", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2726 | .mhandler.info = pcmcia_info, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2727 | }, |
| 2728 | { |
| 2729 | .name = "mice", |
| 2730 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2731 | .params = "", |
| 2732 | .help = "show which guest mouse is receiving events", |
Luiz Capitulino | e78c48e | 2009-12-10 17:16:04 -0200 | [diff] [blame] | 2733 | .user_print = do_info_mice_print, |
| 2734 | .mhandler.info_new = do_info_mice, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2735 | }, |
| 2736 | { |
| 2737 | .name = "vnc", |
| 2738 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2739 | .params = "", |
| 2740 | .help = "show the vnc server status", |
Luiz Capitulino | d96fd29 | 2009-12-10 17:16:10 -0200 | [diff] [blame] | 2741 | .user_print = do_info_vnc_print, |
| 2742 | .mhandler.info_new = do_info_vnc, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2743 | }, |
| 2744 | { |
| 2745 | .name = "name", |
| 2746 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2747 | .params = "", |
| 2748 | .help = "show the current VM name", |
Luiz Capitulino | e05486c | 2009-12-10 17:16:01 -0200 | [diff] [blame] | 2749 | .user_print = do_info_name_print, |
| 2750 | .mhandler.info_new = do_info_name, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2751 | }, |
| 2752 | { |
| 2753 | .name = "uuid", |
| 2754 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2755 | .params = "", |
| 2756 | .help = "show the current VM UUID", |
Luiz Capitulino | 9603ceb | 2009-12-10 17:16:03 -0200 | [diff] [blame] | 2757 | .user_print = do_info_uuid_print, |
| 2758 | .mhandler.info_new = do_info_uuid, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2759 | }, |
j_mayer | 76a6625 | 2007-03-07 08:32:30 +0000 | [diff] [blame] | 2760 | #if defined(TARGET_PPC) |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2761 | { |
| 2762 | .name = "cpustats", |
| 2763 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2764 | .params = "", |
| 2765 | .help = "show CPU statistics", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2766 | .mhandler.info = do_info_cpu_stats, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2767 | }, |
j_mayer | 76a6625 | 2007-03-07 08:32:30 +0000 | [diff] [blame] | 2768 | #endif |
blueswir1 | 31a60e2 | 2007-10-26 18:42:59 +0000 | [diff] [blame] | 2769 | #if defined(CONFIG_SLIRP) |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2770 | { |
| 2771 | .name = "usernet", |
| 2772 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2773 | .params = "", |
| 2774 | .help = "show user network stack connection states", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2775 | .mhandler.info = do_info_usernet, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2776 | }, |
blueswir1 | 31a60e2 | 2007-10-26 18:42:59 +0000 | [diff] [blame] | 2777 | #endif |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2778 | { |
| 2779 | .name = "migrate", |
| 2780 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2781 | .params = "", |
| 2782 | .help = "show migration status", |
Luiz Capitulino | c86a668 | 2009-12-10 17:16:05 -0200 | [diff] [blame] | 2783 | .user_print = do_info_migrate_print, |
| 2784 | .mhandler.info_new = do_info_migrate, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2785 | }, |
| 2786 | { |
| 2787 | .name = "balloon", |
| 2788 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2789 | .params = "", |
| 2790 | .help = "show balloon information", |
Luiz Capitulino | cc1d9c7 | 2009-10-07 13:42:03 -0300 | [diff] [blame] | 2791 | .user_print = monitor_print_balloon, |
Adam Litke | 625a5be | 2010-01-26 14:17:35 -0600 | [diff] [blame] | 2792 | .mhandler.info_async = do_info_balloon, |
| 2793 | .async = 1, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2794 | }, |
| 2795 | { |
| 2796 | .name = "qtree", |
| 2797 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2798 | .params = "", |
| 2799 | .help = "show device tree", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2800 | .mhandler.info = do_info_qtree, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2801 | }, |
| 2802 | { |
| 2803 | .name = "qdm", |
| 2804 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2805 | .params = "", |
| 2806 | .help = "show qdev device model list", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2807 | .mhandler.info = do_info_qdm, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2808 | }, |
| 2809 | { |
| 2810 | .name = "roms", |
| 2811 | .args_type = "", |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2812 | .params = "", |
| 2813 | .help = "show roms", |
Luiz Capitulino | 910df89 | 2009-10-07 13:41:51 -0300 | [diff] [blame] | 2814 | .mhandler.info = do_info_roms, |
Luiz Capitulino | d7f9b68 | 2009-10-07 13:41:50 -0300 | [diff] [blame] | 2815 | }, |
| 2816 | { |
| 2817 | .name = NULL, |
| 2818 | }, |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 2819 | }; |
| 2820 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2821 | /*******************************************************************/ |
| 2822 | |
| 2823 | static const char *pch; |
| 2824 | static jmp_buf expr_env; |
| 2825 | |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2826 | #define MD_TLONG 0 |
| 2827 | #define MD_I32 1 |
| 2828 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2829 | typedef struct MonitorDef { |
| 2830 | const char *name; |
| 2831 | int offset; |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2832 | target_long (*get_value)(const struct MonitorDef *md, int val); |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2833 | int type; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2834 | } MonitorDef; |
| 2835 | |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2836 | #if defined(TARGET_I386) |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2837 | static target_long monitor_get_pc (const struct MonitorDef *md, int val) |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2838 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2839 | CPUState *env = mon_get_cpu(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2840 | return env->eip + env->segs[R_CS].base; |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2841 | } |
| 2842 | #endif |
| 2843 | |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2844 | #if defined(TARGET_PPC) |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2845 | static target_long monitor_get_ccr (const struct MonitorDef *md, int val) |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2846 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2847 | CPUState *env = mon_get_cpu(); |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2848 | unsigned int u; |
| 2849 | int i; |
| 2850 | |
| 2851 | u = 0; |
| 2852 | for (i = 0; i < 8; i++) |
aliguori | 28a76be | 2009-03-06 20:27:40 +0000 | [diff] [blame] | 2853 | u |= env->crf[i] << (32 - (4 * i)); |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2854 | |
| 2855 | return u; |
| 2856 | } |
| 2857 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2858 | static target_long monitor_get_msr (const struct MonitorDef *md, int val) |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2859 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2860 | CPUState *env = mon_get_cpu(); |
j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 2861 | return env->msr; |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2862 | } |
| 2863 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2864 | static target_long monitor_get_xer (const struct MonitorDef *md, int val) |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2865 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2866 | CPUState *env = mon_get_cpu(); |
aurel32 | 3d7b417 | 2008-10-21 11:28:46 +0000 | [diff] [blame] | 2867 | return env->xer; |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2868 | } |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2869 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2870 | static target_long monitor_get_decr (const struct MonitorDef *md, int val) |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2871 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2872 | CPUState *env = mon_get_cpu(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2873 | return cpu_ppc_load_decr(env); |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2874 | } |
| 2875 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2876 | static target_long monitor_get_tbu (const struct MonitorDef *md, int val) |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2877 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2878 | CPUState *env = mon_get_cpu(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2879 | return cpu_ppc_load_tbu(env); |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2880 | } |
| 2881 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2882 | static target_long monitor_get_tbl (const struct MonitorDef *md, int val) |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2883 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2884 | CPUState *env = mon_get_cpu(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2885 | return cpu_ppc_load_tbl(env); |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 2886 | } |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2887 | #endif |
| 2888 | |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2889 | #if defined(TARGET_SPARC) |
bellard | 7b936c0 | 2005-10-30 17:05:13 +0000 | [diff] [blame] | 2890 | #ifndef TARGET_SPARC64 |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2891 | static target_long monitor_get_psr (const struct MonitorDef *md, int val) |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2892 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2893 | CPUState *env = mon_get_cpu(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2894 | return GET_PSR(env); |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2895 | } |
bellard | 7b936c0 | 2005-10-30 17:05:13 +0000 | [diff] [blame] | 2896 | #endif |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2897 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2898 | static target_long monitor_get_reg(const struct MonitorDef *md, int val) |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2899 | { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2900 | CPUState *env = mon_get_cpu(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2901 | return env->regwptr[val]; |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 2902 | } |
| 2903 | #endif |
| 2904 | |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 2905 | static const MonitorDef monitor_defs[] = { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2906 | #ifdef TARGET_I386 |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2907 | |
| 2908 | #define SEG(name, seg) \ |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2909 | { name, offsetof(CPUState, segs[seg].selector), NULL, MD_I32 },\ |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2910 | { name ".base", offsetof(CPUState, segs[seg].base) },\ |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2911 | { name ".limit", offsetof(CPUState, segs[seg].limit), NULL, MD_I32 }, |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2912 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2913 | { "eax", offsetof(CPUState, regs[0]) }, |
| 2914 | { "ecx", offsetof(CPUState, regs[1]) }, |
| 2915 | { "edx", offsetof(CPUState, regs[2]) }, |
| 2916 | { "ebx", offsetof(CPUState, regs[3]) }, |
| 2917 | { "esp|sp", offsetof(CPUState, regs[4]) }, |
| 2918 | { "ebp|fp", offsetof(CPUState, regs[5]) }, |
| 2919 | { "esi", offsetof(CPUState, regs[6]) }, |
bellard | 01038d2 | 2004-09-13 21:36:46 +0000 | [diff] [blame] | 2920 | { "edi", offsetof(CPUState, regs[7]) }, |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 2921 | #ifdef TARGET_X86_64 |
| 2922 | { "r8", offsetof(CPUState, regs[8]) }, |
| 2923 | { "r9", offsetof(CPUState, regs[9]) }, |
| 2924 | { "r10", offsetof(CPUState, regs[10]) }, |
| 2925 | { "r11", offsetof(CPUState, regs[11]) }, |
| 2926 | { "r12", offsetof(CPUState, regs[12]) }, |
| 2927 | { "r13", offsetof(CPUState, regs[13]) }, |
| 2928 | { "r14", offsetof(CPUState, regs[14]) }, |
| 2929 | { "r15", offsetof(CPUState, regs[15]) }, |
| 2930 | #endif |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 2931 | { "eflags", offsetof(CPUState, eflags) }, |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2932 | { "eip", offsetof(CPUState, eip) }, |
| 2933 | SEG("cs", R_CS) |
| 2934 | SEG("ds", R_DS) |
| 2935 | SEG("es", R_ES) |
bellard | 01038d2 | 2004-09-13 21:36:46 +0000 | [diff] [blame] | 2936 | SEG("ss", R_SS) |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 2937 | SEG("fs", R_FS) |
| 2938 | SEG("gs", R_GS) |
| 2939 | { "pc", 0, monitor_get_pc, }, |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2940 | #elif defined(TARGET_PPC) |
j_mayer | ff937db | 2007-09-19 05:49:13 +0000 | [diff] [blame] | 2941 | /* General purpose registers */ |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 2942 | { "r0", offsetof(CPUState, gpr[0]) }, |
| 2943 | { "r1", offsetof(CPUState, gpr[1]) }, |
| 2944 | { "r2", offsetof(CPUState, gpr[2]) }, |
| 2945 | { "r3", offsetof(CPUState, gpr[3]) }, |
| 2946 | { "r4", offsetof(CPUState, gpr[4]) }, |
| 2947 | { "r5", offsetof(CPUState, gpr[5]) }, |
| 2948 | { "r6", offsetof(CPUState, gpr[6]) }, |
| 2949 | { "r7", offsetof(CPUState, gpr[7]) }, |
| 2950 | { "r8", offsetof(CPUState, gpr[8]) }, |
| 2951 | { "r9", offsetof(CPUState, gpr[9]) }, |
| 2952 | { "r10", offsetof(CPUState, gpr[10]) }, |
| 2953 | { "r11", offsetof(CPUState, gpr[11]) }, |
| 2954 | { "r12", offsetof(CPUState, gpr[12]) }, |
| 2955 | { "r13", offsetof(CPUState, gpr[13]) }, |
| 2956 | { "r14", offsetof(CPUState, gpr[14]) }, |
| 2957 | { "r15", offsetof(CPUState, gpr[15]) }, |
| 2958 | { "r16", offsetof(CPUState, gpr[16]) }, |
| 2959 | { "r17", offsetof(CPUState, gpr[17]) }, |
| 2960 | { "r18", offsetof(CPUState, gpr[18]) }, |
| 2961 | { "r19", offsetof(CPUState, gpr[19]) }, |
| 2962 | { "r20", offsetof(CPUState, gpr[20]) }, |
| 2963 | { "r21", offsetof(CPUState, gpr[21]) }, |
| 2964 | { "r22", offsetof(CPUState, gpr[22]) }, |
| 2965 | { "r23", offsetof(CPUState, gpr[23]) }, |
| 2966 | { "r24", offsetof(CPUState, gpr[24]) }, |
| 2967 | { "r25", offsetof(CPUState, gpr[25]) }, |
| 2968 | { "r26", offsetof(CPUState, gpr[26]) }, |
| 2969 | { "r27", offsetof(CPUState, gpr[27]) }, |
| 2970 | { "r28", offsetof(CPUState, gpr[28]) }, |
| 2971 | { "r29", offsetof(CPUState, gpr[29]) }, |
| 2972 | { "r30", offsetof(CPUState, gpr[30]) }, |
| 2973 | { "r31", offsetof(CPUState, gpr[31]) }, |
j_mayer | ff937db | 2007-09-19 05:49:13 +0000 | [diff] [blame] | 2974 | /* Floating point registers */ |
| 2975 | { "f0", offsetof(CPUState, fpr[0]) }, |
| 2976 | { "f1", offsetof(CPUState, fpr[1]) }, |
| 2977 | { "f2", offsetof(CPUState, fpr[2]) }, |
| 2978 | { "f3", offsetof(CPUState, fpr[3]) }, |
| 2979 | { "f4", offsetof(CPUState, fpr[4]) }, |
| 2980 | { "f5", offsetof(CPUState, fpr[5]) }, |
| 2981 | { "f6", offsetof(CPUState, fpr[6]) }, |
| 2982 | { "f7", offsetof(CPUState, fpr[7]) }, |
| 2983 | { "f8", offsetof(CPUState, fpr[8]) }, |
| 2984 | { "f9", offsetof(CPUState, fpr[9]) }, |
| 2985 | { "f10", offsetof(CPUState, fpr[10]) }, |
| 2986 | { "f11", offsetof(CPUState, fpr[11]) }, |
| 2987 | { "f12", offsetof(CPUState, fpr[12]) }, |
| 2988 | { "f13", offsetof(CPUState, fpr[13]) }, |
| 2989 | { "f14", offsetof(CPUState, fpr[14]) }, |
| 2990 | { "f15", offsetof(CPUState, fpr[15]) }, |
| 2991 | { "f16", offsetof(CPUState, fpr[16]) }, |
| 2992 | { "f17", offsetof(CPUState, fpr[17]) }, |
| 2993 | { "f18", offsetof(CPUState, fpr[18]) }, |
| 2994 | { "f19", offsetof(CPUState, fpr[19]) }, |
| 2995 | { "f20", offsetof(CPUState, fpr[20]) }, |
| 2996 | { "f21", offsetof(CPUState, fpr[21]) }, |
| 2997 | { "f22", offsetof(CPUState, fpr[22]) }, |
| 2998 | { "f23", offsetof(CPUState, fpr[23]) }, |
| 2999 | { "f24", offsetof(CPUState, fpr[24]) }, |
| 3000 | { "f25", offsetof(CPUState, fpr[25]) }, |
| 3001 | { "f26", offsetof(CPUState, fpr[26]) }, |
| 3002 | { "f27", offsetof(CPUState, fpr[27]) }, |
| 3003 | { "f28", offsetof(CPUState, fpr[28]) }, |
| 3004 | { "f29", offsetof(CPUState, fpr[29]) }, |
| 3005 | { "f30", offsetof(CPUState, fpr[30]) }, |
| 3006 | { "f31", offsetof(CPUState, fpr[31]) }, |
| 3007 | { "fpscr", offsetof(CPUState, fpscr) }, |
| 3008 | /* Next instruction pointer */ |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 3009 | { "nip|pc", offsetof(CPUState, nip) }, |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3010 | { "lr", offsetof(CPUState, lr) }, |
| 3011 | { "ctr", offsetof(CPUState, ctr) }, |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 3012 | { "decr", 0, &monitor_get_decr, }, |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3013 | { "ccr", 0, &monitor_get_ccr, }, |
j_mayer | ff937db | 2007-09-19 05:49:13 +0000 | [diff] [blame] | 3014 | /* Machine state register */ |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3015 | { "msr", 0, &monitor_get_msr, }, |
| 3016 | { "xer", 0, &monitor_get_xer, }, |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 3017 | { "tbu", 0, &monitor_get_tbu, }, |
| 3018 | { "tbl", 0, &monitor_get_tbl, }, |
j_mayer | ff937db | 2007-09-19 05:49:13 +0000 | [diff] [blame] | 3019 | #if defined(TARGET_PPC64) |
| 3020 | /* Address space register */ |
| 3021 | { "asr", offsetof(CPUState, asr) }, |
| 3022 | #endif |
| 3023 | /* Segment registers */ |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 3024 | { "sdr1", offsetof(CPUState, sdr1) }, |
| 3025 | { "sr0", offsetof(CPUState, sr[0]) }, |
| 3026 | { "sr1", offsetof(CPUState, sr[1]) }, |
| 3027 | { "sr2", offsetof(CPUState, sr[2]) }, |
| 3028 | { "sr3", offsetof(CPUState, sr[3]) }, |
| 3029 | { "sr4", offsetof(CPUState, sr[4]) }, |
| 3030 | { "sr5", offsetof(CPUState, sr[5]) }, |
| 3031 | { "sr6", offsetof(CPUState, sr[6]) }, |
| 3032 | { "sr7", offsetof(CPUState, sr[7]) }, |
| 3033 | { "sr8", offsetof(CPUState, sr[8]) }, |
| 3034 | { "sr9", offsetof(CPUState, sr[9]) }, |
| 3035 | { "sr10", offsetof(CPUState, sr[10]) }, |
| 3036 | { "sr11", offsetof(CPUState, sr[11]) }, |
| 3037 | { "sr12", offsetof(CPUState, sr[12]) }, |
| 3038 | { "sr13", offsetof(CPUState, sr[13]) }, |
| 3039 | { "sr14", offsetof(CPUState, sr[14]) }, |
| 3040 | { "sr15", offsetof(CPUState, sr[15]) }, |
| 3041 | /* Too lazy to put BATs and SPRs ... */ |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 3042 | #elif defined(TARGET_SPARC) |
| 3043 | { "g0", offsetof(CPUState, gregs[0]) }, |
| 3044 | { "g1", offsetof(CPUState, gregs[1]) }, |
| 3045 | { "g2", offsetof(CPUState, gregs[2]) }, |
| 3046 | { "g3", offsetof(CPUState, gregs[3]) }, |
| 3047 | { "g4", offsetof(CPUState, gregs[4]) }, |
| 3048 | { "g5", offsetof(CPUState, gregs[5]) }, |
| 3049 | { "g6", offsetof(CPUState, gregs[6]) }, |
| 3050 | { "g7", offsetof(CPUState, gregs[7]) }, |
| 3051 | { "o0", 0, monitor_get_reg }, |
| 3052 | { "o1", 1, monitor_get_reg }, |
| 3053 | { "o2", 2, monitor_get_reg }, |
| 3054 | { "o3", 3, monitor_get_reg }, |
| 3055 | { "o4", 4, monitor_get_reg }, |
| 3056 | { "o5", 5, monitor_get_reg }, |
| 3057 | { "o6", 6, monitor_get_reg }, |
| 3058 | { "o7", 7, monitor_get_reg }, |
| 3059 | { "l0", 8, monitor_get_reg }, |
| 3060 | { "l1", 9, monitor_get_reg }, |
| 3061 | { "l2", 10, monitor_get_reg }, |
| 3062 | { "l3", 11, monitor_get_reg }, |
| 3063 | { "l4", 12, monitor_get_reg }, |
| 3064 | { "l5", 13, monitor_get_reg }, |
| 3065 | { "l6", 14, monitor_get_reg }, |
| 3066 | { "l7", 15, monitor_get_reg }, |
| 3067 | { "i0", 16, monitor_get_reg }, |
| 3068 | { "i1", 17, monitor_get_reg }, |
| 3069 | { "i2", 18, monitor_get_reg }, |
| 3070 | { "i3", 19, monitor_get_reg }, |
| 3071 | { "i4", 20, monitor_get_reg }, |
| 3072 | { "i5", 21, monitor_get_reg }, |
| 3073 | { "i6", 22, monitor_get_reg }, |
| 3074 | { "i7", 23, monitor_get_reg }, |
| 3075 | { "pc", offsetof(CPUState, pc) }, |
| 3076 | { "npc", offsetof(CPUState, npc) }, |
| 3077 | { "y", offsetof(CPUState, y) }, |
bellard | 7b936c0 | 2005-10-30 17:05:13 +0000 | [diff] [blame] | 3078 | #ifndef TARGET_SPARC64 |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 3079 | { "psr", 0, &monitor_get_psr, }, |
| 3080 | { "wim", offsetof(CPUState, wim) }, |
bellard | 7b936c0 | 2005-10-30 17:05:13 +0000 | [diff] [blame] | 3081 | #endif |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 3082 | { "tbr", offsetof(CPUState, tbr) }, |
| 3083 | { "fsr", offsetof(CPUState, fsr) }, |
| 3084 | { "f0", offsetof(CPUState, fpr[0]) }, |
| 3085 | { "f1", offsetof(CPUState, fpr[1]) }, |
| 3086 | { "f2", offsetof(CPUState, fpr[2]) }, |
| 3087 | { "f3", offsetof(CPUState, fpr[3]) }, |
| 3088 | { "f4", offsetof(CPUState, fpr[4]) }, |
| 3089 | { "f5", offsetof(CPUState, fpr[5]) }, |
| 3090 | { "f6", offsetof(CPUState, fpr[6]) }, |
| 3091 | { "f7", offsetof(CPUState, fpr[7]) }, |
| 3092 | { "f8", offsetof(CPUState, fpr[8]) }, |
| 3093 | { "f9", offsetof(CPUState, fpr[9]) }, |
| 3094 | { "f10", offsetof(CPUState, fpr[10]) }, |
| 3095 | { "f11", offsetof(CPUState, fpr[11]) }, |
| 3096 | { "f12", offsetof(CPUState, fpr[12]) }, |
| 3097 | { "f13", offsetof(CPUState, fpr[13]) }, |
| 3098 | { "f14", offsetof(CPUState, fpr[14]) }, |
| 3099 | { "f15", offsetof(CPUState, fpr[15]) }, |
| 3100 | { "f16", offsetof(CPUState, fpr[16]) }, |
| 3101 | { "f17", offsetof(CPUState, fpr[17]) }, |
| 3102 | { "f18", offsetof(CPUState, fpr[18]) }, |
| 3103 | { "f19", offsetof(CPUState, fpr[19]) }, |
| 3104 | { "f20", offsetof(CPUState, fpr[20]) }, |
| 3105 | { "f21", offsetof(CPUState, fpr[21]) }, |
| 3106 | { "f22", offsetof(CPUState, fpr[22]) }, |
| 3107 | { "f23", offsetof(CPUState, fpr[23]) }, |
| 3108 | { "f24", offsetof(CPUState, fpr[24]) }, |
| 3109 | { "f25", offsetof(CPUState, fpr[25]) }, |
| 3110 | { "f26", offsetof(CPUState, fpr[26]) }, |
| 3111 | { "f27", offsetof(CPUState, fpr[27]) }, |
| 3112 | { "f28", offsetof(CPUState, fpr[28]) }, |
| 3113 | { "f29", offsetof(CPUState, fpr[29]) }, |
| 3114 | { "f30", offsetof(CPUState, fpr[30]) }, |
| 3115 | { "f31", offsetof(CPUState, fpr[31]) }, |
bellard | 7b936c0 | 2005-10-30 17:05:13 +0000 | [diff] [blame] | 3116 | #ifdef TARGET_SPARC64 |
| 3117 | { "f32", offsetof(CPUState, fpr[32]) }, |
| 3118 | { "f34", offsetof(CPUState, fpr[34]) }, |
| 3119 | { "f36", offsetof(CPUState, fpr[36]) }, |
| 3120 | { "f38", offsetof(CPUState, fpr[38]) }, |
| 3121 | { "f40", offsetof(CPUState, fpr[40]) }, |
| 3122 | { "f42", offsetof(CPUState, fpr[42]) }, |
| 3123 | { "f44", offsetof(CPUState, fpr[44]) }, |
| 3124 | { "f46", offsetof(CPUState, fpr[46]) }, |
| 3125 | { "f48", offsetof(CPUState, fpr[48]) }, |
| 3126 | { "f50", offsetof(CPUState, fpr[50]) }, |
| 3127 | { "f52", offsetof(CPUState, fpr[52]) }, |
| 3128 | { "f54", offsetof(CPUState, fpr[54]) }, |
| 3129 | { "f56", offsetof(CPUState, fpr[56]) }, |
| 3130 | { "f58", offsetof(CPUState, fpr[58]) }, |
| 3131 | { "f60", offsetof(CPUState, fpr[60]) }, |
| 3132 | { "f62", offsetof(CPUState, fpr[62]) }, |
| 3133 | { "asi", offsetof(CPUState, asi) }, |
| 3134 | { "pstate", offsetof(CPUState, pstate) }, |
| 3135 | { "cansave", offsetof(CPUState, cansave) }, |
| 3136 | { "canrestore", offsetof(CPUState, canrestore) }, |
| 3137 | { "otherwin", offsetof(CPUState, otherwin) }, |
| 3138 | { "wstate", offsetof(CPUState, wstate) }, |
| 3139 | { "cleanwin", offsetof(CPUState, cleanwin) }, |
| 3140 | { "fprs", offsetof(CPUState, fprs) }, |
| 3141 | #endif |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3142 | #endif |
| 3143 | { NULL }, |
| 3144 | }; |
| 3145 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3146 | static void expr_error(Monitor *mon, const char *msg) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 3147 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3148 | monitor_printf(mon, "%s\n", msg); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3149 | longjmp(expr_env, 1); |
| 3150 | } |
| 3151 | |
Markus Armbruster | 09b9418 | 2010-01-20 13:07:30 +0100 | [diff] [blame] | 3152 | /* return 0 if OK, -1 if not found */ |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3153 | static int get_monitor_def(target_long *pval, const char *name) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3154 | { |
blueswir1 | 8662d65 | 2008-10-02 18:32:44 +0000 | [diff] [blame] | 3155 | const MonitorDef *md; |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3156 | void *ptr; |
| 3157 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3158 | for(md = monitor_defs; md->name != NULL; md++) { |
| 3159 | if (compare_cmd(name, md->name)) { |
| 3160 | if (md->get_value) { |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 3161 | *pval = md->get_value(md, md->offset); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3162 | } else { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3163 | CPUState *env = mon_get_cpu(); |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3164 | ptr = (uint8_t *)env + md->offset; |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3165 | switch(md->type) { |
| 3166 | case MD_I32: |
| 3167 | *pval = *(int32_t *)ptr; |
| 3168 | break; |
| 3169 | case MD_TLONG: |
| 3170 | *pval = *(target_long *)ptr; |
| 3171 | break; |
| 3172 | default: |
| 3173 | *pval = 0; |
| 3174 | break; |
| 3175 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3176 | } |
| 3177 | return 0; |
| 3178 | } |
| 3179 | } |
| 3180 | return -1; |
| 3181 | } |
| 3182 | |
| 3183 | static void next(void) |
| 3184 | { |
Blue Swirl | 660f11b | 2009-07-31 21:16:51 +0000 | [diff] [blame] | 3185 | if (*pch != '\0') { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3186 | pch++; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3187 | while (qemu_isspace(*pch)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3188 | pch++; |
| 3189 | } |
| 3190 | } |
| 3191 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3192 | static int64_t expr_sum(Monitor *mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3193 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3194 | static int64_t expr_unary(Monitor *mon) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3195 | { |
blueswir1 | c2efc95 | 2007-09-25 17:28:42 +0000 | [diff] [blame] | 3196 | int64_t n; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3197 | char *p; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3198 | int ret; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3199 | |
| 3200 | switch(*pch) { |
| 3201 | case '+': |
| 3202 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3203 | n = expr_unary(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3204 | break; |
| 3205 | case '-': |
| 3206 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3207 | n = -expr_unary(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3208 | break; |
| 3209 | case '~': |
| 3210 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3211 | n = ~expr_unary(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3212 | break; |
| 3213 | case '(': |
| 3214 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3215 | n = expr_sum(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3216 | if (*pch != ')') { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3217 | expr_error(mon, "')' expected"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3218 | } |
| 3219 | next(); |
| 3220 | break; |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3221 | case '\'': |
| 3222 | pch++; |
| 3223 | if (*pch == '\0') |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3224 | expr_error(mon, "character constant expected"); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3225 | n = *pch; |
| 3226 | pch++; |
| 3227 | if (*pch != '\'') |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3228 | expr_error(mon, "missing terminating \' character"); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3229 | next(); |
| 3230 | break; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3231 | case '$': |
| 3232 | { |
| 3233 | char buf[128], *q; |
ths | 69b3497 | 2007-12-17 03:15:52 +0000 | [diff] [blame] | 3234 | target_long reg=0; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3235 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3236 | pch++; |
| 3237 | q = buf; |
| 3238 | while ((*pch >= 'a' && *pch <= 'z') || |
| 3239 | (*pch >= 'A' && *pch <= 'Z') || |
| 3240 | (*pch >= '0' && *pch <= '9') || |
bellard | 57206fd | 2004-04-25 18:54:52 +0000 | [diff] [blame] | 3241 | *pch == '_' || *pch == '.') { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3242 | if ((q - buf) < sizeof(buf) - 1) |
| 3243 | *q++ = *pch; |
| 3244 | pch++; |
| 3245 | } |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3246 | while (qemu_isspace(*pch)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3247 | pch++; |
| 3248 | *q = 0; |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 3249 | ret = get_monitor_def(®, buf); |
Markus Armbruster | 09b9418 | 2010-01-20 13:07:30 +0100 | [diff] [blame] | 3250 | if (ret < 0) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3251 | expr_error(mon, "unknown register"); |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 3252 | n = reg; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3253 | } |
| 3254 | break; |
| 3255 | case '\0': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3256 | expr_error(mon, "unexpected end of expression"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3257 | n = 0; |
| 3258 | break; |
| 3259 | default: |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 3260 | #if TARGET_PHYS_ADDR_BITS > 32 |
bellard | 4f4fbf7 | 2006-06-25 18:28:12 +0000 | [diff] [blame] | 3261 | n = strtoull(pch, &p, 0); |
| 3262 | #else |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3263 | n = strtoul(pch, &p, 0); |
bellard | 4f4fbf7 | 2006-06-25 18:28:12 +0000 | [diff] [blame] | 3264 | #endif |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3265 | if (pch == p) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3266 | expr_error(mon, "invalid char in expression"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3267 | } |
| 3268 | pch = p; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3269 | while (qemu_isspace(*pch)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3270 | pch++; |
| 3271 | break; |
| 3272 | } |
| 3273 | return n; |
| 3274 | } |
| 3275 | |
| 3276 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3277 | static int64_t expr_prod(Monitor *mon) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3278 | { |
blueswir1 | c2efc95 | 2007-09-25 17:28:42 +0000 | [diff] [blame] | 3279 | int64_t val, val2; |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3280 | int op; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3281 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3282 | val = expr_unary(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3283 | for(;;) { |
| 3284 | op = *pch; |
| 3285 | if (op != '*' && op != '/' && op != '%') |
| 3286 | break; |
| 3287 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3288 | val2 = expr_unary(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3289 | switch(op) { |
| 3290 | default: |
| 3291 | case '*': |
| 3292 | val *= val2; |
| 3293 | break; |
| 3294 | case '/': |
| 3295 | case '%': |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3296 | if (val2 == 0) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3297 | expr_error(mon, "division by zero"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3298 | if (op == '/') |
| 3299 | val /= val2; |
| 3300 | else |
| 3301 | val %= val2; |
| 3302 | break; |
| 3303 | } |
| 3304 | } |
| 3305 | return val; |
| 3306 | } |
| 3307 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3308 | static int64_t expr_logic(Monitor *mon) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3309 | { |
blueswir1 | c2efc95 | 2007-09-25 17:28:42 +0000 | [diff] [blame] | 3310 | int64_t val, val2; |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3311 | int op; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3312 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3313 | val = expr_prod(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3314 | for(;;) { |
| 3315 | op = *pch; |
| 3316 | if (op != '&' && op != '|' && op != '^') |
| 3317 | break; |
| 3318 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3319 | val2 = expr_prod(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3320 | switch(op) { |
| 3321 | default: |
| 3322 | case '&': |
| 3323 | val &= val2; |
| 3324 | break; |
| 3325 | case '|': |
| 3326 | val |= val2; |
| 3327 | break; |
| 3328 | case '^': |
| 3329 | val ^= val2; |
| 3330 | break; |
| 3331 | } |
| 3332 | } |
| 3333 | return val; |
| 3334 | } |
| 3335 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3336 | static int64_t expr_sum(Monitor *mon) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3337 | { |
blueswir1 | c2efc95 | 2007-09-25 17:28:42 +0000 | [diff] [blame] | 3338 | int64_t val, val2; |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3339 | int op; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3340 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3341 | val = expr_logic(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3342 | for(;;) { |
| 3343 | op = *pch; |
| 3344 | if (op != '+' && op != '-') |
| 3345 | break; |
| 3346 | next(); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3347 | val2 = expr_logic(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3348 | if (op == '+') |
| 3349 | val += val2; |
| 3350 | else |
| 3351 | val -= val2; |
| 3352 | } |
| 3353 | return val; |
| 3354 | } |
| 3355 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3356 | static int get_expr(Monitor *mon, int64_t *pval, const char **pp) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3357 | { |
| 3358 | pch = *pp; |
| 3359 | if (setjmp(expr_env)) { |
| 3360 | *pp = pch; |
| 3361 | return -1; |
| 3362 | } |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3363 | while (qemu_isspace(*pch)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3364 | pch++; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3365 | *pval = expr_sum(mon); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3366 | *pp = pch; |
| 3367 | return 0; |
| 3368 | } |
| 3369 | |
Markus Armbruster | 3350a4d | 2010-01-25 14:23:03 +0100 | [diff] [blame] | 3370 | static int get_double(Monitor *mon, double *pval, const char **pp) |
| 3371 | { |
| 3372 | const char *p = *pp; |
| 3373 | char *tailp; |
| 3374 | double d; |
| 3375 | |
| 3376 | d = strtod(p, &tailp); |
| 3377 | if (tailp == p) { |
| 3378 | monitor_printf(mon, "Number expected\n"); |
| 3379 | return -1; |
| 3380 | } |
| 3381 | if (d != d || d - d != 0) { |
| 3382 | /* NaN or infinity */ |
| 3383 | monitor_printf(mon, "Bad number\n"); |
| 3384 | return -1; |
| 3385 | } |
| 3386 | *pval = d; |
| 3387 | *pp = tailp; |
| 3388 | return 0; |
| 3389 | } |
| 3390 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3391 | static int get_str(char *buf, int buf_size, const char **pp) |
| 3392 | { |
| 3393 | const char *p; |
| 3394 | char *q; |
| 3395 | int c; |
| 3396 | |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3397 | q = buf; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3398 | p = *pp; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3399 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3400 | p++; |
| 3401 | if (*p == '\0') { |
| 3402 | fail: |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3403 | *q = '\0'; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3404 | *pp = p; |
| 3405 | return -1; |
| 3406 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3407 | if (*p == '\"') { |
| 3408 | p++; |
| 3409 | while (*p != '\0' && *p != '\"') { |
| 3410 | if (*p == '\\') { |
| 3411 | p++; |
| 3412 | c = *p++; |
| 3413 | switch(c) { |
| 3414 | case 'n': |
| 3415 | c = '\n'; |
| 3416 | break; |
| 3417 | case 'r': |
| 3418 | c = '\r'; |
| 3419 | break; |
| 3420 | case '\\': |
| 3421 | case '\'': |
| 3422 | case '\"': |
| 3423 | break; |
| 3424 | default: |
| 3425 | qemu_printf("unsupported escape code: '\\%c'\n", c); |
| 3426 | goto fail; |
| 3427 | } |
| 3428 | if ((q - buf) < buf_size - 1) { |
| 3429 | *q++ = c; |
| 3430 | } |
| 3431 | } else { |
| 3432 | if ((q - buf) < buf_size - 1) { |
| 3433 | *q++ = *p; |
| 3434 | } |
| 3435 | p++; |
| 3436 | } |
| 3437 | } |
| 3438 | if (*p != '\"') { |
bellard | 5b60212 | 2004-05-22 21:41:05 +0000 | [diff] [blame] | 3439 | qemu_printf("unterminated string\n"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3440 | goto fail; |
| 3441 | } |
| 3442 | p++; |
| 3443 | } else { |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3444 | while (*p != '\0' && !qemu_isspace(*p)) { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3445 | if ((q - buf) < buf_size - 1) { |
| 3446 | *q++ = *p; |
| 3447 | } |
| 3448 | p++; |
| 3449 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3450 | } |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3451 | *q = '\0'; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3452 | *pp = p; |
| 3453 | return 0; |
| 3454 | } |
| 3455 | |
Luiz Capitulino | 4590fd8 | 2009-06-09 18:21:30 -0300 | [diff] [blame] | 3456 | /* |
| 3457 | * Store the command-name in cmdname, and return a pointer to |
| 3458 | * the remaining of the command string. |
| 3459 | */ |
| 3460 | static const char *get_command_name(const char *cmdline, |
| 3461 | char *cmdname, size_t nlen) |
| 3462 | { |
| 3463 | size_t len; |
| 3464 | const char *p, *pstart; |
| 3465 | |
| 3466 | p = cmdline; |
| 3467 | while (qemu_isspace(*p)) |
| 3468 | p++; |
| 3469 | if (*p == '\0') |
| 3470 | return NULL; |
| 3471 | pstart = p; |
| 3472 | while (*p != '\0' && *p != '/' && !qemu_isspace(*p)) |
| 3473 | p++; |
| 3474 | len = p - pstart; |
| 3475 | if (len > nlen - 1) |
| 3476 | len = nlen - 1; |
| 3477 | memcpy(cmdname, pstart, len); |
| 3478 | cmdname[len] = '\0'; |
| 3479 | return p; |
| 3480 | } |
| 3481 | |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3482 | /** |
| 3483 | * Read key of 'type' into 'key' and return the current |
| 3484 | * 'type' pointer. |
| 3485 | */ |
| 3486 | static char *key_get_info(const char *type, char **key) |
| 3487 | { |
| 3488 | size_t len; |
| 3489 | char *p, *str; |
| 3490 | |
| 3491 | if (*type == ',') |
| 3492 | type++; |
| 3493 | |
| 3494 | p = strchr(type, ':'); |
| 3495 | if (!p) { |
| 3496 | *key = NULL; |
| 3497 | return NULL; |
| 3498 | } |
| 3499 | len = p - type; |
| 3500 | |
| 3501 | str = qemu_malloc(len + 1); |
| 3502 | memcpy(str, type, len); |
| 3503 | str[len] = '\0'; |
| 3504 | |
| 3505 | *key = str; |
| 3506 | return ++p; |
| 3507 | } |
| 3508 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3509 | static int default_fmt_format = 'x'; |
| 3510 | static int default_fmt_size = 4; |
| 3511 | |
| 3512 | #define MAX_ARGS 16 |
| 3513 | |
lirans@il.ibm.com | fbc3d96 | 2009-11-02 15:41:13 +0200 | [diff] [blame] | 3514 | static int is_valid_option(const char *c, const char *typestr) |
| 3515 | { |
| 3516 | char option[3]; |
| 3517 | |
| 3518 | option[0] = '-'; |
| 3519 | option[1] = *c; |
| 3520 | option[2] = '\0'; |
| 3521 | |
| 3522 | typestr = strstr(typestr, option); |
| 3523 | return (typestr != NULL); |
| 3524 | } |
| 3525 | |
Luiz Capitulino | 7fd669a | 2009-11-26 22:58:54 -0200 | [diff] [blame] | 3526 | static const mon_cmd_t *monitor_find_command(const char *cmdname) |
| 3527 | { |
| 3528 | const mon_cmd_t *cmd; |
| 3529 | |
| 3530 | for (cmd = mon_cmds; cmd->name != NULL; cmd++) { |
| 3531 | if (compare_cmd(cmdname, cmd->name)) { |
| 3532 | return cmd; |
| 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | return NULL; |
| 3537 | } |
| 3538 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 3539 | static const mon_cmd_t *monitor_parse_command(Monitor *mon, |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3540 | const char *cmdline, |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3541 | QDict *qdict) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3542 | { |
Luiz Capitulino | 4590fd8 | 2009-06-09 18:21:30 -0300 | [diff] [blame] | 3543 | const char *p, *typestr; |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 3544 | int c; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 3545 | const mon_cmd_t *cmd; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3546 | char cmdname[256]; |
| 3547 | char buf[1024]; |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3548 | char *key; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 3549 | |
| 3550 | #ifdef DEBUG |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3551 | monitor_printf(mon, "command='%s'\n", cmdline); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 3552 | #endif |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3553 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3554 | /* extract the command name */ |
Luiz Capitulino | 4590fd8 | 2009-06-09 18:21:30 -0300 | [diff] [blame] | 3555 | p = get_command_name(cmdline, cmdname, sizeof(cmdname)); |
| 3556 | if (!p) |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3557 | return NULL; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3558 | |
Luiz Capitulino | 7fd669a | 2009-11-26 22:58:54 -0200 | [diff] [blame] | 3559 | cmd = monitor_find_command(cmdname); |
| 3560 | if (!cmd) { |
Luiz Capitulino | d91d9bf | 2009-06-09 18:21:54 -0300 | [diff] [blame] | 3561 | monitor_printf(mon, "unknown command: '%s'\n", cmdname); |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3562 | return NULL; |
Luiz Capitulino | d91d9bf | 2009-06-09 18:21:54 -0300 | [diff] [blame] | 3563 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3564 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3565 | /* parse the parameters */ |
| 3566 | typestr = cmd->args_type; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3567 | for(;;) { |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3568 | typestr = key_get_info(typestr, &key); |
| 3569 | if (!typestr) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3570 | break; |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3571 | c = *typestr; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3572 | typestr++; |
| 3573 | switch(c) { |
| 3574 | case 'F': |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3575 | case 'B': |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3576 | case 's': |
| 3577 | { |
| 3578 | int ret; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3579 | |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3580 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3581 | p++; |
| 3582 | if (*typestr == '?') { |
| 3583 | typestr++; |
| 3584 | if (*p == '\0') { |
| 3585 | /* no optional string: NULL argument */ |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 3586 | break; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3587 | } |
| 3588 | } |
| 3589 | ret = get_str(buf, sizeof(buf), &p); |
| 3590 | if (ret < 0) { |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3591 | switch(c) { |
| 3592 | case 'F': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3593 | monitor_printf(mon, "%s: filename expected\n", |
| 3594 | cmdname); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3595 | break; |
| 3596 | case 'B': |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3597 | monitor_printf(mon, "%s: block device name expected\n", |
| 3598 | cmdname); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3599 | break; |
| 3600 | default: |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3601 | monitor_printf(mon, "%s: string expected\n", cmdname); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3602 | break; |
| 3603 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3604 | goto fail; |
| 3605 | } |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 3606 | qdict_put(qdict, key, qstring_from_str(buf)); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3607 | } |
| 3608 | break; |
| 3609 | case '/': |
| 3610 | { |
| 3611 | int count, format, size; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3612 | |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3613 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3614 | p++; |
| 3615 | if (*p == '/') { |
| 3616 | /* format found */ |
| 3617 | p++; |
| 3618 | count = 1; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3619 | if (qemu_isdigit(*p)) { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3620 | count = 0; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3621 | while (qemu_isdigit(*p)) { |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3622 | count = count * 10 + (*p - '0'); |
| 3623 | p++; |
| 3624 | } |
| 3625 | } |
| 3626 | size = -1; |
| 3627 | format = -1; |
| 3628 | for(;;) { |
| 3629 | switch(*p) { |
| 3630 | case 'o': |
| 3631 | case 'd': |
| 3632 | case 'u': |
| 3633 | case 'x': |
| 3634 | case 'i': |
| 3635 | case 'c': |
| 3636 | format = *p++; |
| 3637 | break; |
| 3638 | case 'b': |
| 3639 | size = 1; |
| 3640 | p++; |
| 3641 | break; |
| 3642 | case 'h': |
| 3643 | size = 2; |
| 3644 | p++; |
| 3645 | break; |
| 3646 | case 'w': |
| 3647 | size = 4; |
| 3648 | p++; |
| 3649 | break; |
| 3650 | case 'g': |
| 3651 | case 'L': |
| 3652 | size = 8; |
| 3653 | p++; |
| 3654 | break; |
| 3655 | default: |
| 3656 | goto next; |
| 3657 | } |
| 3658 | } |
| 3659 | next: |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3660 | if (*p != '\0' && !qemu_isspace(*p)) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3661 | monitor_printf(mon, "invalid char in format: '%c'\n", |
| 3662 | *p); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3663 | goto fail; |
| 3664 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3665 | if (format < 0) |
| 3666 | format = default_fmt_format; |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 3667 | if (format != 'i') { |
| 3668 | /* for 'i', not specifying a size gives -1 as size */ |
| 3669 | if (size < 0) |
| 3670 | size = default_fmt_size; |
aurel32 | e90f009 | 2008-10-01 21:45:51 +0000 | [diff] [blame] | 3671 | default_fmt_size = size; |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 3672 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3673 | default_fmt_format = format; |
| 3674 | } else { |
| 3675 | count = 1; |
| 3676 | format = default_fmt_format; |
bellard | 4c27ba2 | 2004-04-25 18:05:08 +0000 | [diff] [blame] | 3677 | if (format != 'i') { |
| 3678 | size = default_fmt_size; |
| 3679 | } else { |
| 3680 | size = -1; |
| 3681 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3682 | } |
Luiz Capitulino | f7188bb | 2009-08-28 15:27:10 -0300 | [diff] [blame] | 3683 | qdict_put(qdict, "count", qint_from_int(count)); |
| 3684 | qdict_put(qdict, "format", qint_from_int(format)); |
| 3685 | qdict_put(qdict, "size", qint_from_int(size)); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3686 | } |
| 3687 | break; |
| 3688 | case 'i': |
bellard | 92a31b1 | 2005-02-10 22:00:52 +0000 | [diff] [blame] | 3689 | case 'l': |
Luiz Capitulino | b6e098d | 2009-12-18 13:25:04 -0200 | [diff] [blame] | 3690 | case 'M': |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3691 | { |
blueswir1 | c2efc95 | 2007-09-25 17:28:42 +0000 | [diff] [blame] | 3692 | int64_t val; |
blueswir1 | 7743e58 | 2007-09-24 18:39:04 +0000 | [diff] [blame] | 3693 | |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3694 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3695 | p++; |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 3696 | if (*typestr == '?' || *typestr == '.') { |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 3697 | if (*typestr == '?') { |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 3698 | if (*p == '\0') { |
| 3699 | typestr++; |
| 3700 | break; |
| 3701 | } |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 3702 | } else { |
| 3703 | if (*p == '.') { |
| 3704 | p++; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3705 | while (qemu_isspace(*p)) |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 3706 | p++; |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 3707 | } else { |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 3708 | typestr++; |
| 3709 | break; |
bellard | 3440557 | 2004-06-08 00:55:58 +0000 | [diff] [blame] | 3710 | } |
| 3711 | } |
bellard | 13224a8 | 2006-07-14 22:03:35 +0000 | [diff] [blame] | 3712 | typestr++; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3713 | } |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3714 | if (get_expr(mon, &val, &p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3715 | goto fail; |
Luiz Capitulino | 675ebef | 2009-08-28 15:27:26 -0300 | [diff] [blame] | 3716 | /* Check if 'i' is greater than 32-bit */ |
| 3717 | if ((c == 'i') && ((val >> 32) & 0xffffffff)) { |
| 3718 | monitor_printf(mon, "\'%s\' has failed: ", cmdname); |
| 3719 | monitor_printf(mon, "integer is for 32-bit values\n"); |
| 3720 | goto fail; |
Luiz Capitulino | b6e098d | 2009-12-18 13:25:04 -0200 | [diff] [blame] | 3721 | } else if (c == 'M') { |
| 3722 | val <<= 20; |
Luiz Capitulino | 675ebef | 2009-08-28 15:27:26 -0300 | [diff] [blame] | 3723 | } |
Luiz Capitulino | 5377358 | 2009-08-28 15:27:25 -0300 | [diff] [blame] | 3724 | qdict_put(qdict, key, qint_from_int(val)); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3725 | } |
| 3726 | break; |
Markus Armbruster | 3350a4d | 2010-01-25 14:23:03 +0100 | [diff] [blame] | 3727 | case 'b': |
Markus Armbruster | fccfb11e | 2010-01-25 14:23:06 +0100 | [diff] [blame] | 3728 | case 'T': |
Markus Armbruster | 3350a4d | 2010-01-25 14:23:03 +0100 | [diff] [blame] | 3729 | { |
| 3730 | double val; |
| 3731 | |
| 3732 | while (qemu_isspace(*p)) |
| 3733 | p++; |
| 3734 | if (*typestr == '?') { |
| 3735 | typestr++; |
| 3736 | if (*p == '\0') { |
| 3737 | break; |
| 3738 | } |
| 3739 | } |
| 3740 | if (get_double(mon, &val, &p) < 0) { |
| 3741 | goto fail; |
| 3742 | } |
Markus Armbruster | fccfb11e | 2010-01-25 14:23:06 +0100 | [diff] [blame] | 3743 | if (c == 'b' && *p) { |
Markus Armbruster | 3350a4d | 2010-01-25 14:23:03 +0100 | [diff] [blame] | 3744 | switch (*p) { |
| 3745 | case 'K': case 'k': |
| 3746 | val *= 1 << 10; p++; break; |
| 3747 | case 'M': case 'm': |
| 3748 | val *= 1 << 20; p++; break; |
| 3749 | case 'G': case 'g': |
| 3750 | val *= 1 << 30; p++; break; |
| 3751 | } |
| 3752 | } |
Markus Armbruster | fccfb11e | 2010-01-25 14:23:06 +0100 | [diff] [blame] | 3753 | if (c == 'T' && p[0] && p[1] == 's') { |
| 3754 | switch (*p) { |
| 3755 | case 'm': |
| 3756 | val /= 1e3; p += 2; break; |
| 3757 | case 'u': |
| 3758 | val /= 1e6; p += 2; break; |
| 3759 | case 'n': |
| 3760 | val /= 1e9; p += 2; break; |
| 3761 | } |
| 3762 | } |
Markus Armbruster | 3350a4d | 2010-01-25 14:23:03 +0100 | [diff] [blame] | 3763 | if (*p && !qemu_isspace(*p)) { |
| 3764 | monitor_printf(mon, "Unknown unit suffix\n"); |
| 3765 | goto fail; |
| 3766 | } |
| 3767 | qdict_put(qdict, key, qfloat_from_double(val)); |
| 3768 | } |
| 3769 | break; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3770 | case '-': |
| 3771 | { |
lirans@il.ibm.com | fbc3d96 | 2009-11-02 15:41:13 +0200 | [diff] [blame] | 3772 | const char *tmp = p; |
| 3773 | int has_option, skip_key = 0; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3774 | /* option */ |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3775 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3776 | c = *typestr++; |
| 3777 | if (c == '\0') |
| 3778 | goto bad_type; |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3779 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3780 | p++; |
| 3781 | has_option = 0; |
| 3782 | if (*p == '-') { |
| 3783 | p++; |
lirans@il.ibm.com | fbc3d96 | 2009-11-02 15:41:13 +0200 | [diff] [blame] | 3784 | if(c != *p) { |
| 3785 | if(!is_valid_option(p, typestr)) { |
| 3786 | |
| 3787 | monitor_printf(mon, "%s: unsupported option -%c\n", |
| 3788 | cmdname, *p); |
| 3789 | goto fail; |
| 3790 | } else { |
| 3791 | skip_key = 1; |
| 3792 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3793 | } |
lirans@il.ibm.com | fbc3d96 | 2009-11-02 15:41:13 +0200 | [diff] [blame] | 3794 | if(skip_key) { |
| 3795 | p = tmp; |
| 3796 | } else { |
| 3797 | p++; |
| 3798 | has_option = 1; |
| 3799 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3800 | } |
Luiz Capitulino | f7188bb | 2009-08-28 15:27:10 -0300 | [diff] [blame] | 3801 | qdict_put(qdict, key, qint_from_int(has_option)); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3802 | } |
| 3803 | break; |
| 3804 | default: |
| 3805 | bad_type: |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3806 | monitor_printf(mon, "%s: unknown type '%c'\n", cmdname, c); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3807 | goto fail; |
| 3808 | } |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3809 | qemu_free(key); |
| 3810 | key = NULL; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3811 | } |
| 3812 | /* check that all arguments were parsed */ |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 3813 | while (qemu_isspace(*p)) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3814 | p++; |
| 3815 | if (*p != '\0') { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3816 | monitor_printf(mon, "%s: extraneous characters at the end of line\n", |
| 3817 | cmdname); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 3818 | goto fail; |
| 3819 | } |
| 3820 | |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3821 | return cmd; |
Gerd Hoffmann | ac7531e | 2009-08-14 10:36:06 +0200 | [diff] [blame] | 3822 | |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3823 | fail: |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 3824 | qemu_free(key); |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3825 | return NULL; |
| 3826 | } |
| 3827 | |
Luiz Capitulino | 8204a91 | 2009-11-18 23:05:31 -0200 | [diff] [blame] | 3828 | static void monitor_print_error(Monitor *mon) |
| 3829 | { |
| 3830 | qerror_print(mon->error); |
| 3831 | QDECREF(mon->error); |
| 3832 | mon->error = NULL; |
| 3833 | } |
| 3834 | |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 3835 | static int is_async_return(const QObject *data) |
| 3836 | { |
Luiz Capitulino | 82617d7 | 2010-01-27 18:01:17 -0200 | [diff] [blame] | 3837 | if (data && qobject_type(data) == QTYPE_QDICT) { |
| 3838 | return qdict_haskey(qobject_to_qdict(data), "__mon_async"); |
| 3839 | } |
| 3840 | |
| 3841 | return 0; |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 3842 | } |
| 3843 | |
Luiz Capitulino | 99e2fc1 | 2009-11-26 22:58:53 -0200 | [diff] [blame] | 3844 | static void monitor_call_handler(Monitor *mon, const mon_cmd_t *cmd, |
| 3845 | const QDict *params) |
| 3846 | { |
| 3847 | QObject *data = NULL; |
| 3848 | |
Luiz Capitulino | 97536cf | 2010-02-10 23:49:47 -0200 | [diff] [blame] | 3849 | if (cmd->cmd_new_ret) { |
| 3850 | cmd->cmd_new_ret(mon, params, &data); |
| 3851 | } else { |
| 3852 | cmd->mhandler.cmd_new(mon, params, &data); |
| 3853 | } |
Luiz Capitulino | 25b422e | 2009-11-26 22:58:59 -0200 | [diff] [blame] | 3854 | |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 3855 | if (is_async_return(data)) { |
| 3856 | /* |
| 3857 | * Asynchronous commands have no initial return data but they can |
| 3858 | * generate errors. Data is returned via the async completion handler. |
| 3859 | */ |
| 3860 | if (monitor_ctrl_mode(mon) && monitor_has_error(mon)) { |
| 3861 | monitor_protocol_emitter(mon, NULL); |
| 3862 | } |
| 3863 | } else if (monitor_ctrl_mode(mon)) { |
Luiz Capitulino | 25b422e | 2009-11-26 22:58:59 -0200 | [diff] [blame] | 3864 | /* Monitor Protocol */ |
| 3865 | monitor_protocol_emitter(mon, data); |
| 3866 | } else { |
| 3867 | /* User Protocol */ |
| 3868 | if (data) |
| 3869 | cmd->user_print(mon, data); |
| 3870 | } |
Luiz Capitulino | 99e2fc1 | 2009-11-26 22:58:53 -0200 | [diff] [blame] | 3871 | |
| 3872 | qobject_decref(data); |
| 3873 | } |
| 3874 | |
Luiz Capitulino | f3c157c | 2009-11-26 22:58:55 -0200 | [diff] [blame] | 3875 | static void handle_user_command(Monitor *mon, const char *cmdline) |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3876 | { |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3877 | QDict *qdict; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 3878 | const mon_cmd_t *cmd; |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3879 | |
| 3880 | qdict = qdict_new(); |
| 3881 | |
Luiz Capitulino | 590fb3b | 2009-08-28 15:27:24 -0300 | [diff] [blame] | 3882 | cmd = monitor_parse_command(mon, cmdline, qdict); |
Luiz Capitulino | 13917be | 2009-10-07 13:41:54 -0300 | [diff] [blame] | 3883 | if (!cmd) |
| 3884 | goto out; |
| 3885 | |
| 3886 | qemu_errors_to_mon(mon); |
| 3887 | |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 3888 | if (monitor_handler_is_async(cmd)) { |
| 3889 | user_async_cmd_handler(mon, cmd, qdict); |
| 3890 | } else if (monitor_handler_ported(cmd)) { |
Luiz Capitulino | 99e2fc1 | 2009-11-26 22:58:53 -0200 | [diff] [blame] | 3891 | monitor_call_handler(mon, cmd, qdict); |
Luiz Capitulino | 13917be | 2009-10-07 13:41:54 -0300 | [diff] [blame] | 3892 | } else { |
Luiz Capitulino | af4ce88 | 2009-10-07 13:41:52 -0300 | [diff] [blame] | 3893 | cmd->mhandler.cmd(mon, qdict); |
Luiz Capitulino | 55f81d9 | 2009-08-28 15:27:22 -0300 | [diff] [blame] | 3894 | } |
| 3895 | |
Luiz Capitulino | 8204a91 | 2009-11-18 23:05:31 -0200 | [diff] [blame] | 3896 | if (monitor_has_error(mon)) |
| 3897 | monitor_print_error(mon); |
| 3898 | |
| 3899 | qemu_errors_to_previous(); |
Luiz Capitulino | 13917be | 2009-10-07 13:41:54 -0300 | [diff] [blame] | 3900 | |
| 3901 | out: |
Luiz Capitulino | f7188bb | 2009-08-28 15:27:10 -0300 | [diff] [blame] | 3902 | QDECREF(qdict); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 3903 | } |
| 3904 | |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3905 | static void cmd_completion(const char *name, const char *list) |
| 3906 | { |
| 3907 | const char *p, *pstart; |
| 3908 | char cmd[128]; |
| 3909 | int len; |
| 3910 | |
| 3911 | p = list; |
| 3912 | for(;;) { |
| 3913 | pstart = p; |
| 3914 | p = strchr(p, '|'); |
| 3915 | if (!p) |
| 3916 | p = pstart + strlen(pstart); |
| 3917 | len = p - pstart; |
| 3918 | if (len > sizeof(cmd) - 2) |
| 3919 | len = sizeof(cmd) - 2; |
| 3920 | memcpy(cmd, pstart, len); |
| 3921 | cmd[len] = '\0'; |
| 3922 | if (name[0] == '\0' || !strncmp(name, cmd, strlen(name))) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3923 | readline_add_completion(cur_mon->rs, cmd); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3924 | } |
| 3925 | if (*p == '\0') |
| 3926 | break; |
| 3927 | p++; |
| 3928 | } |
| 3929 | } |
| 3930 | |
| 3931 | static void file_completion(const char *input) |
| 3932 | { |
| 3933 | DIR *ffs; |
| 3934 | struct dirent *d; |
| 3935 | char path[1024]; |
| 3936 | char file[1024], file_prefix[1024]; |
| 3937 | int input_path_len; |
| 3938 | const char *p; |
| 3939 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3940 | p = strrchr(input, '/'); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3941 | if (!p) { |
| 3942 | input_path_len = 0; |
| 3943 | pstrcpy(file_prefix, sizeof(file_prefix), input); |
blueswir1 | 363a37d | 2008-08-21 17:58:08 +0000 | [diff] [blame] | 3944 | pstrcpy(path, sizeof(path), "."); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3945 | } else { |
| 3946 | input_path_len = p - input + 1; |
| 3947 | memcpy(path, input, input_path_len); |
| 3948 | if (input_path_len > sizeof(path) - 1) |
| 3949 | input_path_len = sizeof(path) - 1; |
| 3950 | path[input_path_len] = '\0'; |
| 3951 | pstrcpy(file_prefix, sizeof(file_prefix), p + 1); |
| 3952 | } |
| 3953 | #ifdef DEBUG_COMPLETION |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 3954 | monitor_printf(cur_mon, "input='%s' path='%s' prefix='%s'\n", |
| 3955 | input, path, file_prefix); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3956 | #endif |
| 3957 | ffs = opendir(path); |
| 3958 | if (!ffs) |
| 3959 | return; |
| 3960 | for(;;) { |
| 3961 | struct stat sb; |
| 3962 | d = readdir(ffs); |
| 3963 | if (!d) |
| 3964 | break; |
| 3965 | if (strstart(d->d_name, file_prefix, NULL)) { |
| 3966 | memcpy(file, input, input_path_len); |
blueswir1 | 363a37d | 2008-08-21 17:58:08 +0000 | [diff] [blame] | 3967 | if (input_path_len < sizeof(file)) |
| 3968 | pstrcpy(file + input_path_len, sizeof(file) - input_path_len, |
| 3969 | d->d_name); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3970 | /* stat the file to find out if it's a directory. |
| 3971 | * In that case add a slash to speed up typing long paths |
| 3972 | */ |
| 3973 | stat(file, &sb); |
| 3974 | if(S_ISDIR(sb.st_mode)) |
blueswir1 | 363a37d | 2008-08-21 17:58:08 +0000 | [diff] [blame] | 3975 | pstrcat(file, sizeof(file), "/"); |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3976 | readline_add_completion(cur_mon->rs, file); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3977 | } |
| 3978 | } |
| 3979 | closedir(ffs); |
| 3980 | } |
| 3981 | |
aliguori | 51de976 | 2009-03-05 23:00:43 +0000 | [diff] [blame] | 3982 | static void block_completion_it(void *opaque, BlockDriverState *bs) |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3983 | { |
aliguori | 51de976 | 2009-03-05 23:00:43 +0000 | [diff] [blame] | 3984 | const char *name = bdrv_get_device_name(bs); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3985 | const char *input = opaque; |
| 3986 | |
| 3987 | if (input[0] == '\0' || |
| 3988 | !strncmp(name, (char *)input, strlen(input))) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 3989 | readline_add_completion(cur_mon->rs, name); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 3990 | } |
| 3991 | } |
| 3992 | |
| 3993 | /* NOTE: this parser is an approximate form of the real command parser */ |
| 3994 | static void parse_cmdline(const char *cmdline, |
| 3995 | int *pnb_args, char **args) |
| 3996 | { |
| 3997 | const char *p; |
| 3998 | int nb_args, ret; |
| 3999 | char buf[1024]; |
| 4000 | |
| 4001 | p = cmdline; |
| 4002 | nb_args = 0; |
| 4003 | for(;;) { |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 4004 | while (qemu_isspace(*p)) |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4005 | p++; |
| 4006 | if (*p == '\0') |
| 4007 | break; |
| 4008 | if (nb_args >= MAX_ARGS) |
| 4009 | break; |
| 4010 | ret = get_str(buf, sizeof(buf), &p); |
| 4011 | args[nb_args] = qemu_strdup(buf); |
| 4012 | nb_args++; |
| 4013 | if (ret < 0) |
| 4014 | break; |
| 4015 | } |
| 4016 | *pnb_args = nb_args; |
| 4017 | } |
| 4018 | |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 4019 | static const char *next_arg_type(const char *typestr) |
| 4020 | { |
| 4021 | const char *p = strchr(typestr, ':'); |
| 4022 | return (p != NULL ? ++p : typestr); |
| 4023 | } |
| 4024 | |
aliguori | 4c36ba3 | 2009-03-05 23:01:37 +0000 | [diff] [blame] | 4025 | static void monitor_find_completion(const char *cmdline) |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4026 | { |
| 4027 | const char *cmdname; |
| 4028 | char *args[MAX_ARGS]; |
| 4029 | int nb_args, i, len; |
| 4030 | const char *ptype, *str; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 4031 | const mon_cmd_t *cmd; |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 4032 | const KeyDef *key; |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4033 | |
| 4034 | parse_cmdline(cmdline, &nb_args, args); |
| 4035 | #ifdef DEBUG_COMPLETION |
| 4036 | for(i = 0; i < nb_args; i++) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4037 | monitor_printf(cur_mon, "arg%d = '%s'\n", i, (char *)args[i]); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4038 | } |
| 4039 | #endif |
| 4040 | |
| 4041 | /* if the line ends with a space, it means we want to complete the |
| 4042 | next arg */ |
| 4043 | len = strlen(cmdline); |
blueswir1 | cd39008 | 2008-11-16 13:53:32 +0000 | [diff] [blame] | 4044 | if (len > 0 && qemu_isspace(cmdline[len - 1])) { |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4045 | if (nb_args >= MAX_ARGS) |
| 4046 | return; |
| 4047 | args[nb_args++] = qemu_strdup(""); |
| 4048 | } |
| 4049 | if (nb_args <= 1) { |
| 4050 | /* command completion */ |
| 4051 | if (nb_args == 0) |
| 4052 | cmdname = ""; |
| 4053 | else |
| 4054 | cmdname = args[0]; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4055 | readline_set_completion_index(cur_mon->rs, strlen(cmdname)); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4056 | for(cmd = mon_cmds; cmd->name != NULL; cmd++) { |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4057 | cmd_completion(cmdname, cmd->name); |
| 4058 | } |
| 4059 | } else { |
| 4060 | /* find the command */ |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4061 | for(cmd = mon_cmds; cmd->name != NULL; cmd++) { |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4062 | if (compare_cmd(args[0], cmd->name)) |
| 4063 | goto found; |
| 4064 | } |
| 4065 | return; |
| 4066 | found: |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 4067 | ptype = next_arg_type(cmd->args_type); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4068 | for(i = 0; i < nb_args - 2; i++) { |
| 4069 | if (*ptype != '\0') { |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 4070 | ptype = next_arg_type(ptype); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4071 | while (*ptype == '?') |
Luiz Capitulino | 4d76d2b | 2009-08-28 15:27:09 -0300 | [diff] [blame] | 4072 | ptype = next_arg_type(ptype); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4073 | } |
| 4074 | } |
| 4075 | str = args[nb_args - 1]; |
Blue Swirl | 2a1704a | 2009-08-23 20:10:28 +0000 | [diff] [blame] | 4076 | if (*ptype == '-' && ptype[1] != '\0') { |
| 4077 | ptype += 2; |
| 4078 | } |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4079 | switch(*ptype) { |
| 4080 | case 'F': |
| 4081 | /* file completion */ |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4082 | readline_set_completion_index(cur_mon->rs, strlen(str)); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4083 | file_completion(str); |
| 4084 | break; |
| 4085 | case 'B': |
| 4086 | /* block device name completion */ |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4087 | readline_set_completion_index(cur_mon->rs, strlen(str)); |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4088 | bdrv_iterate(block_completion_it, (void *)str); |
| 4089 | break; |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 4090 | case 's': |
| 4091 | /* XXX: more generic ? */ |
| 4092 | if (!strcmp(cmd->name, "info")) { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4093 | readline_set_completion_index(cur_mon->rs, strlen(str)); |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 4094 | for(cmd = info_cmds; cmd->name != NULL; cmd++) { |
| 4095 | cmd_completion(str, cmd->name); |
| 4096 | } |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 4097 | } else if (!strcmp(cmd->name, "sendkey")) { |
blueswir1 | e600d1e | 2009-03-08 17:42:02 +0000 | [diff] [blame] | 4098 | char *sep = strrchr(str, '-'); |
| 4099 | if (sep) |
| 4100 | str = sep + 1; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4101 | readline_set_completion_index(cur_mon->rs, strlen(str)); |
bellard | 64866c3 | 2006-05-07 18:03:31 +0000 | [diff] [blame] | 4102 | for(key = key_defs; key->name != NULL; key++) { |
| 4103 | cmd_completion(str, key->name); |
| 4104 | } |
Jan Kiszka | f3353c6 | 2009-06-25 08:22:02 +0200 | [diff] [blame] | 4105 | } else if (!strcmp(cmd->name, "help|?")) { |
| 4106 | readline_set_completion_index(cur_mon->rs, strlen(str)); |
| 4107 | for (cmd = mon_cmds; cmd->name != NULL; cmd++) { |
| 4108 | cmd_completion(str, cmd->name); |
| 4109 | } |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 4110 | } |
| 4111 | break; |
bellard | 81d0912 | 2004-07-14 17:21:37 +0000 | [diff] [blame] | 4112 | default: |
| 4113 | break; |
| 4114 | } |
| 4115 | } |
| 4116 | for(i = 0; i < nb_args; i++) |
| 4117 | qemu_free(args[i]); |
| 4118 | } |
| 4119 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4120 | static int monitor_can_read(void *opaque) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 4121 | { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4122 | Monitor *mon = opaque; |
| 4123 | |
Jan Kiszka | c62313b | 2009-12-04 14:05:29 +0100 | [diff] [blame] | 4124 | return (mon->suspend_cnt == 0) ? 1 : 0; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 4125 | } |
| 4126 | |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4127 | typedef struct CmdArgs { |
| 4128 | QString *name; |
| 4129 | int type; |
| 4130 | int flag; |
| 4131 | int optional; |
| 4132 | } CmdArgs; |
| 4133 | |
| 4134 | static int check_opt(const CmdArgs *cmd_args, const char *name, QDict *args) |
| 4135 | { |
| 4136 | if (!cmd_args->optional) { |
| 4137 | qemu_error_new(QERR_MISSING_PARAMETER, name); |
| 4138 | return -1; |
| 4139 | } |
| 4140 | |
| 4141 | if (cmd_args->type == '-') { |
| 4142 | /* handlers expect a value, they need to be changed */ |
| 4143 | qdict_put(args, name, qint_from_int(0)); |
| 4144 | } |
| 4145 | |
| 4146 | return 0; |
| 4147 | } |
| 4148 | |
| 4149 | static int check_arg(const CmdArgs *cmd_args, QDict *args) |
| 4150 | { |
| 4151 | QObject *value; |
| 4152 | const char *name; |
| 4153 | |
| 4154 | name = qstring_get_str(cmd_args->name); |
| 4155 | |
| 4156 | if (!args) { |
| 4157 | return check_opt(cmd_args, name, args); |
| 4158 | } |
| 4159 | |
| 4160 | value = qdict_get(args, name); |
| 4161 | if (!value) { |
| 4162 | return check_opt(cmd_args, name, args); |
| 4163 | } |
| 4164 | |
| 4165 | switch (cmd_args->type) { |
| 4166 | case 'F': |
| 4167 | case 'B': |
| 4168 | case 's': |
| 4169 | if (qobject_type(value) != QTYPE_QSTRING) { |
| 4170 | qemu_error_new(QERR_INVALID_PARAMETER_TYPE, name, "string"); |
| 4171 | return -1; |
| 4172 | } |
| 4173 | break; |
| 4174 | case '/': { |
| 4175 | int i; |
| 4176 | const char *keys[] = { "count", "format", "size", NULL }; |
| 4177 | |
| 4178 | for (i = 0; keys[i]; i++) { |
| 4179 | QObject *obj = qdict_get(args, keys[i]); |
| 4180 | if (!obj) { |
| 4181 | qemu_error_new(QERR_MISSING_PARAMETER, name); |
| 4182 | return -1; |
| 4183 | } |
| 4184 | if (qobject_type(obj) != QTYPE_QINT) { |
| 4185 | qemu_error_new(QERR_INVALID_PARAMETER_TYPE, name, "int"); |
| 4186 | return -1; |
| 4187 | } |
| 4188 | } |
| 4189 | break; |
| 4190 | } |
| 4191 | case 'i': |
| 4192 | case 'l': |
Luiz Capitulino | b6e098d | 2009-12-18 13:25:04 -0200 | [diff] [blame] | 4193 | case 'M': |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4194 | if (qobject_type(value) != QTYPE_QINT) { |
| 4195 | qemu_error_new(QERR_INVALID_PARAMETER_TYPE, name, "int"); |
| 4196 | return -1; |
| 4197 | } |
| 4198 | break; |
Markus Armbruster | 3350a4d | 2010-01-25 14:23:03 +0100 | [diff] [blame] | 4199 | case 'b': |
Markus Armbruster | fccfb11e | 2010-01-25 14:23:06 +0100 | [diff] [blame] | 4200 | case 'T': |
Markus Armbruster | 3350a4d | 2010-01-25 14:23:03 +0100 | [diff] [blame] | 4201 | if (qobject_type(value) != QTYPE_QINT && qobject_type(value) != QTYPE_QFLOAT) { |
| 4202 | qemu_error_new(QERR_INVALID_PARAMETER_TYPE, name, "number"); |
| 4203 | return -1; |
| 4204 | } |
| 4205 | break; |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4206 | case '-': |
| 4207 | if (qobject_type(value) != QTYPE_QINT && |
| 4208 | qobject_type(value) != QTYPE_QBOOL) { |
| 4209 | qemu_error_new(QERR_INVALID_PARAMETER_TYPE, name, "bool"); |
| 4210 | return -1; |
| 4211 | } |
| 4212 | if (qobject_type(value) == QTYPE_QBOOL) { |
| 4213 | /* handlers expect a QInt, they need to be changed */ |
| 4214 | qdict_put(args, name, |
| 4215 | qint_from_int(qbool_get_int(qobject_to_qbool(value)))); |
| 4216 | } |
| 4217 | break; |
| 4218 | default: |
| 4219 | /* impossible */ |
| 4220 | abort(); |
| 4221 | } |
| 4222 | |
| 4223 | return 0; |
| 4224 | } |
| 4225 | |
| 4226 | static void cmd_args_init(CmdArgs *cmd_args) |
| 4227 | { |
| 4228 | cmd_args->name = qstring_new(); |
| 4229 | cmd_args->type = cmd_args->flag = cmd_args->optional = 0; |
| 4230 | } |
| 4231 | |
| 4232 | /* |
| 4233 | * This is not trivial, we have to parse Monitor command's argument |
| 4234 | * type syntax to be able to check the arguments provided by clients. |
| 4235 | * |
| 4236 | * In the near future we will be using an array for that and will be |
| 4237 | * able to drop all this parsing... |
| 4238 | */ |
| 4239 | static int monitor_check_qmp_args(const mon_cmd_t *cmd, QDict *args) |
| 4240 | { |
| 4241 | int err; |
| 4242 | const char *p; |
| 4243 | CmdArgs cmd_args; |
| 4244 | |
Blue Swirl | dd5121b | 2009-12-04 20:52:02 +0000 | [diff] [blame] | 4245 | if (cmd->args_type == NULL) { |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4246 | return (qdict_size(args) == 0 ? 0 : -1); |
| 4247 | } |
| 4248 | |
| 4249 | err = 0; |
| 4250 | cmd_args_init(&cmd_args); |
| 4251 | |
| 4252 | for (p = cmd->args_type;; p++) { |
| 4253 | if (*p == ':') { |
| 4254 | cmd_args.type = *++p; |
| 4255 | p++; |
| 4256 | if (cmd_args.type == '-') { |
| 4257 | cmd_args.flag = *p++; |
| 4258 | cmd_args.optional = 1; |
| 4259 | } else if (*p == '?') { |
| 4260 | cmd_args.optional = 1; |
| 4261 | p++; |
| 4262 | } |
| 4263 | |
| 4264 | assert(*p == ',' || *p == '\0'); |
| 4265 | err = check_arg(&cmd_args, args); |
| 4266 | |
| 4267 | QDECREF(cmd_args.name); |
| 4268 | cmd_args_init(&cmd_args); |
| 4269 | |
| 4270 | if (err < 0) { |
| 4271 | break; |
| 4272 | } |
| 4273 | } else { |
| 4274 | qstring_append_chr(cmd_args.name, *p); |
| 4275 | } |
| 4276 | |
| 4277 | if (*p == '\0') { |
| 4278 | break; |
| 4279 | } |
| 4280 | } |
| 4281 | |
| 4282 | QDECREF(cmd_args.name); |
| 4283 | return err; |
| 4284 | } |
| 4285 | |
Luiz Capitulino | 09069b1 | 2010-02-04 18:10:06 -0200 | [diff] [blame] | 4286 | static int invalid_qmp_mode(const Monitor *mon, const char *cmd_name) |
| 4287 | { |
| 4288 | int is_cap = compare_cmd(cmd_name, "qmp_capabilities"); |
| 4289 | return (qmp_cmd_mode(mon) ? is_cap : !is_cap); |
| 4290 | } |
| 4291 | |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4292 | static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) |
| 4293 | { |
| 4294 | int err; |
| 4295 | QObject *obj; |
| 4296 | QDict *input, *args; |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4297 | const mon_cmd_t *cmd; |
| 4298 | Monitor *mon = cur_mon; |
Luiz Capitulino | 5e23f48 | 2009-11-26 22:59:02 -0200 | [diff] [blame] | 4299 | const char *cmd_name, *info_item; |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4300 | |
| 4301 | args = NULL; |
| 4302 | qemu_errors_to_mon(mon); |
| 4303 | |
| 4304 | obj = json_parser_parse(tokens, NULL); |
| 4305 | if (!obj) { |
| 4306 | // FIXME: should be triggered in json_parser_parse() |
| 4307 | qemu_error_new(QERR_JSON_PARSING); |
| 4308 | goto err_out; |
| 4309 | } else if (qobject_type(obj) != QTYPE_QDICT) { |
| 4310 | qemu_error_new(QERR_QMP_BAD_INPUT_OBJECT, "object"); |
| 4311 | qobject_decref(obj); |
| 4312 | goto err_out; |
| 4313 | } |
| 4314 | |
| 4315 | input = qobject_to_qdict(obj); |
| 4316 | |
| 4317 | mon->mc->id = qdict_get(input, "id"); |
| 4318 | qobject_incref(mon->mc->id); |
| 4319 | |
| 4320 | obj = qdict_get(input, "execute"); |
| 4321 | if (!obj) { |
| 4322 | qemu_error_new(QERR_QMP_BAD_INPUT_OBJECT, "execute"); |
| 4323 | goto err_input; |
| 4324 | } else if (qobject_type(obj) != QTYPE_QSTRING) { |
| 4325 | qemu_error_new(QERR_QMP_BAD_INPUT_OBJECT, "string"); |
| 4326 | goto err_input; |
| 4327 | } |
| 4328 | |
| 4329 | cmd_name = qstring_get_str(qobject_to_qstring(obj)); |
Luiz Capitulino | 5e23f48 | 2009-11-26 22:59:02 -0200 | [diff] [blame] | 4330 | |
Luiz Capitulino | 09069b1 | 2010-02-04 18:10:06 -0200 | [diff] [blame] | 4331 | if (invalid_qmp_mode(mon, cmd_name)) { |
| 4332 | qemu_error_new(QERR_COMMAND_NOT_FOUND, cmd_name); |
| 4333 | goto err_input; |
| 4334 | } |
| 4335 | |
Luiz Capitulino | 5e23f48 | 2009-11-26 22:59:02 -0200 | [diff] [blame] | 4336 | /* |
| 4337 | * XXX: We need this special case until we get info handlers |
| 4338 | * converted into 'query-' commands |
| 4339 | */ |
| 4340 | if (compare_cmd(cmd_name, "info")) { |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4341 | qemu_error_new(QERR_COMMAND_NOT_FOUND, cmd_name); |
| 4342 | goto err_input; |
Luiz Capitulino | 5e23f48 | 2009-11-26 22:59:02 -0200 | [diff] [blame] | 4343 | } else if (strstart(cmd_name, "query-", &info_item)) { |
| 4344 | cmd = monitor_find_command("info"); |
| 4345 | qdict_put_obj(input, "arguments", |
| 4346 | qobject_from_jsonf("{ 'item': %s }", info_item)); |
| 4347 | } else { |
| 4348 | cmd = monitor_find_command(cmd_name); |
Luiz Capitulino | 43e713c | 2009-12-18 13:24:59 -0200 | [diff] [blame] | 4349 | if (!cmd || !monitor_handler_ported(cmd)) { |
Luiz Capitulino | 5e23f48 | 2009-11-26 22:59:02 -0200 | [diff] [blame] | 4350 | qemu_error_new(QERR_COMMAND_NOT_FOUND, cmd_name); |
| 4351 | goto err_input; |
| 4352 | } |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4353 | } |
| 4354 | |
| 4355 | obj = qdict_get(input, "arguments"); |
| 4356 | if (!obj) { |
| 4357 | args = qdict_new(); |
| 4358 | } else { |
| 4359 | args = qobject_to_qdict(obj); |
| 4360 | QINCREF(args); |
| 4361 | } |
| 4362 | |
| 4363 | QDECREF(input); |
| 4364 | |
| 4365 | err = monitor_check_qmp_args(cmd, args); |
| 4366 | if (err < 0) { |
| 4367 | goto err_out; |
| 4368 | } |
| 4369 | |
Adam Litke | 940cc30 | 2010-01-25 12:18:44 -0600 | [diff] [blame] | 4370 | if (monitor_handler_is_async(cmd)) { |
| 4371 | qmp_async_cmd_handler(mon, cmd, args); |
| 4372 | } else { |
| 4373 | monitor_call_handler(mon, cmd, args); |
| 4374 | } |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4375 | goto out; |
| 4376 | |
| 4377 | err_input: |
| 4378 | QDECREF(input); |
| 4379 | err_out: |
| 4380 | monitor_protocol_emitter(mon, NULL); |
| 4381 | out: |
| 4382 | QDECREF(args); |
| 4383 | qemu_errors_to_previous(); |
| 4384 | } |
| 4385 | |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 4386 | /** |
| 4387 | * monitor_control_read(): Read and handle QMP input |
| 4388 | */ |
| 4389 | static void monitor_control_read(void *opaque, const uint8_t *buf, int size) |
| 4390 | { |
| 4391 | Monitor *old_mon = cur_mon; |
| 4392 | |
| 4393 | cur_mon = opaque; |
| 4394 | |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4395 | json_message_parser_feed(&cur_mon->mc->parser, (const char *) buf, size); |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 4396 | |
| 4397 | cur_mon = old_mon; |
| 4398 | } |
| 4399 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4400 | static void monitor_read(void *opaque, const uint8_t *buf, int size) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 4401 | { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4402 | Monitor *old_mon = cur_mon; |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 4403 | int i; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4404 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4405 | cur_mon = opaque; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 4406 | |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 4407 | if (cur_mon->rs) { |
| 4408 | for (i = 0; i < size; i++) |
| 4409 | readline_handle_byte(cur_mon->rs, buf[i]); |
| 4410 | } else { |
| 4411 | if (size == 0 || buf[size - 1] != 0) |
| 4412 | monitor_printf(cur_mon, "corrupted command\n"); |
| 4413 | else |
Luiz Capitulino | f3c157c | 2009-11-26 22:58:55 -0200 | [diff] [blame] | 4414 | handle_user_command(cur_mon, (char *)buf); |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 4415 | } |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4416 | |
| 4417 | cur_mon = old_mon; |
| 4418 | } |
aliguori | d8f4460 | 2008-10-06 13:52:44 +0000 | [diff] [blame] | 4419 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4420 | static void monitor_command_cb(Monitor *mon, const char *cmdline, void *opaque) |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 4421 | { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4422 | monitor_suspend(mon); |
Luiz Capitulino | f3c157c | 2009-11-26 22:58:55 -0200 | [diff] [blame] | 4423 | handle_user_command(mon, cmdline); |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4424 | monitor_resume(mon); |
aliguori | d8f4460 | 2008-10-06 13:52:44 +0000 | [diff] [blame] | 4425 | } |
| 4426 | |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 4427 | int monitor_suspend(Monitor *mon) |
aliguori | d8f4460 | 2008-10-06 13:52:44 +0000 | [diff] [blame] | 4428 | { |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 4429 | if (!mon->rs) |
| 4430 | return -ENOTTY; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4431 | mon->suspend_cnt++; |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 4432 | return 0; |
aliguori | d8f4460 | 2008-10-06 13:52:44 +0000 | [diff] [blame] | 4433 | } |
| 4434 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4435 | void monitor_resume(Monitor *mon) |
aliguori | d8f4460 | 2008-10-06 13:52:44 +0000 | [diff] [blame] | 4436 | { |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 4437 | if (!mon->rs) |
| 4438 | return; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4439 | if (--mon->suspend_cnt == 0) |
| 4440 | readline_show_prompt(mon->rs); |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 4441 | } |
| 4442 | |
Luiz Capitulino | ca9567e | 2010-02-04 18:10:04 -0200 | [diff] [blame] | 4443 | static QObject *get_qmp_greeting(void) |
| 4444 | { |
| 4445 | QObject *ver; |
| 4446 | |
| 4447 | do_info_version(NULL, &ver); |
| 4448 | return qobject_from_jsonf("{'QMP':{'version': %p,'capabilities': []}}",ver); |
| 4449 | } |
| 4450 | |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 4451 | /** |
| 4452 | * monitor_control_event(): Print QMP gretting |
| 4453 | */ |
| 4454 | static void monitor_control_event(void *opaque, int event) |
| 4455 | { |
Luiz Capitulino | 47116d1 | 2010-02-08 17:01:30 -0200 | [diff] [blame] | 4456 | QObject *data; |
| 4457 | Monitor *mon = opaque; |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 4458 | |
Luiz Capitulino | 47116d1 | 2010-02-08 17:01:30 -0200 | [diff] [blame] | 4459 | switch (event) { |
| 4460 | case CHR_EVENT_OPENED: |
Luiz Capitulino | 4a7e119 | 2010-02-04 18:10:05 -0200 | [diff] [blame] | 4461 | mon->mc->command_mode = 0; |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4462 | json_message_parser_init(&mon->mc->parser, handle_qmp_command); |
Luiz Capitulino | ca9567e | 2010-02-04 18:10:04 -0200 | [diff] [blame] | 4463 | data = get_qmp_greeting(); |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 4464 | monitor_json_emitter(mon, data); |
| 4465 | qobject_decref(data); |
Luiz Capitulino | 47116d1 | 2010-02-08 17:01:30 -0200 | [diff] [blame] | 4466 | break; |
| 4467 | case CHR_EVENT_CLOSED: |
| 4468 | json_message_parser_destroy(&mon->mc->parser); |
| 4469 | break; |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 4470 | } |
| 4471 | } |
| 4472 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4473 | static void monitor_event(void *opaque, int event) |
ths | 86e94de | 2007-01-05 22:01:59 +0000 | [diff] [blame] | 4474 | { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4475 | Monitor *mon = opaque; |
| 4476 | |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 4477 | switch (event) { |
| 4478 | case CHR_EVENT_MUX_IN: |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 4479 | mon->mux_out = 0; |
| 4480 | if (mon->reset_seen) { |
| 4481 | readline_restart(mon->rs); |
| 4482 | monitor_resume(mon); |
| 4483 | monitor_flush(mon); |
| 4484 | } else { |
| 4485 | mon->suspend_cnt = 0; |
| 4486 | } |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 4487 | break; |
ths | 86e94de | 2007-01-05 22:01:59 +0000 | [diff] [blame] | 4488 | |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 4489 | case CHR_EVENT_MUX_OUT: |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 4490 | if (mon->reset_seen) { |
| 4491 | if (mon->suspend_cnt == 0) { |
| 4492 | monitor_printf(mon, "\n"); |
| 4493 | } |
| 4494 | monitor_flush(mon); |
| 4495 | monitor_suspend(mon); |
| 4496 | } else { |
| 4497 | mon->suspend_cnt++; |
| 4498 | } |
| 4499 | mon->mux_out = 1; |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 4500 | break; |
| 4501 | |
Amit Shah | b6b8df5 | 2009-10-07 18:31:16 +0530 | [diff] [blame] | 4502 | case CHR_EVENT_OPENED: |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 4503 | monitor_printf(mon, "QEMU %s monitor - type 'help' for more " |
| 4504 | "information\n", QEMU_VERSION); |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 4505 | if (!mon->mux_out) { |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 4506 | readline_show_prompt(mon->rs); |
Gerd Hoffmann | a7aec5d | 2009-09-10 10:58:54 +0200 | [diff] [blame] | 4507 | } |
| 4508 | mon->reset_seen = 1; |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 4509 | break; |
| 4510 | } |
ths | 86e94de | 2007-01-05 22:01:59 +0000 | [diff] [blame] | 4511 | } |
| 4512 | |
aliguori | 76655d6 | 2009-03-06 20:27:37 +0000 | [diff] [blame] | 4513 | |
| 4514 | /* |
| 4515 | * Local variables: |
| 4516 | * c-indent-level: 4 |
| 4517 | * c-basic-offset: 4 |
| 4518 | * tab-width: 8 |
| 4519 | * End: |
| 4520 | */ |
| 4521 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4522 | void monitor_init(CharDriverState *chr, int flags) |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 4523 | { |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4524 | static int is_first_init = 1; |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 4525 | Monitor *mon; |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 4526 | |
| 4527 | if (is_first_init) { |
balrog | c8256f9 | 2008-06-08 22:45:01 +0000 | [diff] [blame] | 4528 | key_timer = qemu_new_timer(vm_clock, release_keys, NULL); |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 4529 | is_first_init = 0; |
| 4530 | } |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 4531 | |
| 4532 | mon = qemu_mallocz(sizeof(*mon)); |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 4533 | |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 4534 | mon->chr = chr; |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4535 | mon->flags = flags; |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 4536 | if (flags & MONITOR_USE_READLINE) { |
| 4537 | mon->rs = readline_init(mon, monitor_find_completion); |
| 4538 | monitor_read_command(mon, 0); |
| 4539 | } |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 4540 | |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 4541 | if (monitor_ctrl_mode(mon)) { |
Luiz Capitulino | 5fa737a | 2009-11-26 22:59:01 -0200 | [diff] [blame] | 4542 | mon->mc = qemu_mallocz(sizeof(MonitorControl)); |
Luiz Capitulino | 9b57c02 | 2009-11-26 22:58:58 -0200 | [diff] [blame] | 4543 | /* Control mode requires special handlers */ |
| 4544 | qemu_chr_add_handlers(chr, monitor_can_read, monitor_control_read, |
| 4545 | monitor_control_event, mon); |
| 4546 | } else { |
| 4547 | qemu_chr_add_handlers(chr, monitor_can_read, monitor_read, |
| 4548 | monitor_event, mon); |
| 4549 | } |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 4550 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 4551 | QLIST_INSERT_HEAD(&mon_list, mon, entry); |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4552 | if (!cur_mon || (flags & MONITOR_IS_DEFAULT)) |
aliguori | 8712716 | 2009-03-05 23:01:29 +0000 | [diff] [blame] | 4553 | cur_mon = mon; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 4554 | } |
| 4555 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4556 | static void bdrv_password_cb(Monitor *mon, const char *password, void *opaque) |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 4557 | { |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 4558 | BlockDriverState *bs = opaque; |
| 4559 | int ret = 0; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 4560 | |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 4561 | if (bdrv_set_key(bs, password) != 0) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4562 | monitor_printf(mon, "invalid password\n"); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 4563 | ret = -EPERM; |
bellard | 7e2515e | 2004-08-01 21:52:19 +0000 | [diff] [blame] | 4564 | } |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4565 | if (mon->password_completion_cb) |
| 4566 | mon->password_completion_cb(mon->password_opaque, ret); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 4567 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4568 | monitor_read_command(mon, 1); |
bellard | 9dc39cb | 2004-03-14 21:38:27 +0000 | [diff] [blame] | 4569 | } |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 4570 | |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 4571 | int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, |
| 4572 | BlockDriverCompletionFunc *completion_cb, |
| 4573 | void *opaque) |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 4574 | { |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 4575 | int err; |
| 4576 | |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 4577 | if (!bdrv_key_required(bs)) { |
| 4578 | if (completion_cb) |
| 4579 | completion_cb(opaque, 0); |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 4580 | return 0; |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 4581 | } |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 4582 | |
Luiz Capitulino | 94171e1 | 2009-12-07 21:37:00 +0100 | [diff] [blame] | 4583 | if (monitor_ctrl_mode(mon)) { |
| 4584 | qemu_error_new(QERR_DEVICE_ENCRYPTED, bdrv_get_device_name(bs)); |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 4585 | return -1; |
Luiz Capitulino | 94171e1 | 2009-12-07 21:37:00 +0100 | [diff] [blame] | 4586 | } |
| 4587 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 4588 | monitor_printf(mon, "%s (%s) is encrypted.\n", bdrv_get_device_name(bs), |
| 4589 | bdrv_get_encrypted_filename(bs)); |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 4590 | |
aliguori | 731b036 | 2009-03-05 23:01:42 +0000 | [diff] [blame] | 4591 | mon->password_completion_cb = completion_cb; |
| 4592 | mon->password_opaque = opaque; |
aliguori | bb5fc20 | 2009-03-05 23:01:15 +0000 | [diff] [blame] | 4593 | |
aliguori | cde76ee | 2009-03-05 23:01:51 +0000 | [diff] [blame] | 4594 | err = monitor_read_password(mon, bdrv_password_cb, bs); |
| 4595 | |
| 4596 | if (err && completion_cb) |
| 4597 | completion_cb(opaque, err); |
Luiz Capitulino | 0bbc47b | 2010-02-10 23:50:01 -0200 | [diff] [blame^] | 4598 | |
| 4599 | return err; |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 4600 | } |
Gerd Hoffmann | ac7531e | 2009-08-14 10:36:06 +0200 | [diff] [blame] | 4601 | |
| 4602 | typedef struct QemuErrorSink QemuErrorSink; |
| 4603 | struct QemuErrorSink { |
| 4604 | enum { |
| 4605 | ERR_SINK_FILE, |
| 4606 | ERR_SINK_MONITOR, |
| 4607 | } dest; |
| 4608 | union { |
| 4609 | FILE *fp; |
| 4610 | Monitor *mon; |
| 4611 | }; |
| 4612 | QemuErrorSink *previous; |
| 4613 | }; |
| 4614 | |
Blue Swirl | 528e93a | 2009-08-31 15:14:40 +0000 | [diff] [blame] | 4615 | static QemuErrorSink *qemu_error_sink; |
Gerd Hoffmann | ac7531e | 2009-08-14 10:36:06 +0200 | [diff] [blame] | 4616 | |
| 4617 | void qemu_errors_to_file(FILE *fp) |
| 4618 | { |
| 4619 | QemuErrorSink *sink; |
| 4620 | |
| 4621 | sink = qemu_mallocz(sizeof(*sink)); |
| 4622 | sink->dest = ERR_SINK_FILE; |
| 4623 | sink->fp = fp; |
| 4624 | sink->previous = qemu_error_sink; |
| 4625 | qemu_error_sink = sink; |
| 4626 | } |
| 4627 | |
| 4628 | void qemu_errors_to_mon(Monitor *mon) |
| 4629 | { |
| 4630 | QemuErrorSink *sink; |
| 4631 | |
| 4632 | sink = qemu_mallocz(sizeof(*sink)); |
| 4633 | sink->dest = ERR_SINK_MONITOR; |
| 4634 | sink->mon = mon; |
| 4635 | sink->previous = qemu_error_sink; |
| 4636 | qemu_error_sink = sink; |
| 4637 | } |
| 4638 | |
| 4639 | void qemu_errors_to_previous(void) |
| 4640 | { |
| 4641 | QemuErrorSink *sink; |
| 4642 | |
| 4643 | assert(qemu_error_sink != NULL); |
| 4644 | sink = qemu_error_sink; |
| 4645 | qemu_error_sink = sink->previous; |
| 4646 | qemu_free(sink); |
| 4647 | } |
| 4648 | |
| 4649 | void qemu_error(const char *fmt, ...) |
| 4650 | { |
| 4651 | va_list args; |
| 4652 | |
| 4653 | assert(qemu_error_sink != NULL); |
| 4654 | switch (qemu_error_sink->dest) { |
| 4655 | case ERR_SINK_FILE: |
| 4656 | va_start(args, fmt); |
| 4657 | vfprintf(qemu_error_sink->fp, fmt, args); |
| 4658 | va_end(args); |
| 4659 | break; |
| 4660 | case ERR_SINK_MONITOR: |
| 4661 | va_start(args, fmt); |
| 4662 | monitor_vprintf(qemu_error_sink->mon, fmt, args); |
| 4663 | va_end(args); |
| 4664 | break; |
| 4665 | } |
| 4666 | } |
Luiz Capitulino | 8204a91 | 2009-11-18 23:05:31 -0200 | [diff] [blame] | 4667 | |
| 4668 | void qemu_error_internal(const char *file, int linenr, const char *func, |
| 4669 | const char *fmt, ...) |
| 4670 | { |
| 4671 | va_list va; |
| 4672 | QError *qerror; |
| 4673 | |
| 4674 | assert(qemu_error_sink != NULL); |
| 4675 | |
| 4676 | va_start(va, fmt); |
| 4677 | qerror = qerror_from_info(file, linenr, func, fmt, &va); |
| 4678 | va_end(va); |
| 4679 | |
| 4680 | switch (qemu_error_sink->dest) { |
| 4681 | case ERR_SINK_FILE: |
| 4682 | qerror_print(qerror); |
| 4683 | QDECREF(qerror); |
| 4684 | break; |
| 4685 | case ERR_SINK_MONITOR: |
Luiz Capitulino | 27a749f | 2010-02-08 17:01:29 -0200 | [diff] [blame] | 4686 | /* report only the first error */ |
| 4687 | if (!qemu_error_sink->mon->error) { |
| 4688 | qemu_error_sink->mon->error = qerror; |
| 4689 | } else { |
| 4690 | /* XXX: warn the programmer */ |
| 4691 | QDECREF(qerror); |
| 4692 | } |
Luiz Capitulino | 8204a91 | 2009-11-18 23:05:31 -0200 | [diff] [blame] | 4693 | break; |
| 4694 | } |
| 4695 | } |