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