]>
Commit | Line | Data |
---|---|---|
9dc39cba FB |
1 | /* |
2 | * QEMU monitor | |
5fafdf24 | 3 | * |
9dc39cba | 4 | * Copyright (c) 2003-2004 Fabrice Bellard |
5fafdf24 | 5 | * |
9dc39cba FB |
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 | */ | |
511d2b14 | 24 | #include <dirent.h> |
87ecb68b | 25 | #include "hw/hw.h" |
b4a42f81 | 26 | #include "monitor/qdev.h" |
87ecb68b | 27 | #include "hw/usb.h" |
0d09e41a | 28 | #include "hw/i386/pc.h" |
a2cb15b0 | 29 | #include "hw/pci/pci.h" |
0d09e41a | 30 | #include "sysemu/watchdog.h" |
45a50b16 | 31 | #include "hw/loader.h" |
022c62cb | 32 | #include "exec/gdbstub.h" |
1422e32d | 33 | #include "net/net.h" |
68ac40d2 | 34 | #include "net/slirp.h" |
dccfcd0e | 35 | #include "sysemu/char.h" |
7572150c | 36 | #include "ui/qemu-spice.h" |
9c17d615 | 37 | #include "sysemu/sysemu.h" |
e35704ba | 38 | #include "sysemu/numa.h" |
83c9089e | 39 | #include "monitor/monitor.h" |
0150cd81 | 40 | #include "qemu/readline.h" |
28ecbaee | 41 | #include "ui/console.h" |
c751a74a | 42 | #include "ui/input.h" |
9c17d615 | 43 | #include "sysemu/blockdev.h" |
87ecb68b | 44 | #include "audio/audio.h" |
76cad711 | 45 | #include "disas/disas.h" |
9c17d615 | 46 | #include "sysemu/balloon.h" |
1de7afc9 | 47 | #include "qemu/timer.h" |
caf71f86 | 48 | #include "migration/migration.h" |
9c17d615 | 49 | #include "sysemu/kvm.h" |
1de7afc9 | 50 | #include "qemu/acl.h" |
bdee56f5 | 51 | #include "sysemu/tpm.h" |
7b1b5d19 PB |
52 | #include "qapi/qmp/qint.h" |
53 | #include "qapi/qmp/qfloat.h" | |
54 | #include "qapi/qmp/qlist.h" | |
55 | #include "qapi/qmp/qbool.h" | |
56 | #include "qapi/qmp/qstring.h" | |
57 | #include "qapi/qmp/qjson.h" | |
58 | #include "qapi/qmp/json-streamer.h" | |
59 | #include "qapi/qmp/json-parser.h" | |
1094fd3a | 60 | #include <qom/object_interfaces.h> |
1de7afc9 | 61 | #include "qemu/osdep.h" |
2b41f10e | 62 | #include "cpu.h" |
89bd820a | 63 | #include "trace.h" |
31965ae2 | 64 | #include "trace/control.h" |
6d8a764e | 65 | #ifdef CONFIG_TRACE_SIMPLE |
31965ae2 | 66 | #include "trace/simple.h" |
22890ab5 | 67 | #endif |
022c62cb | 68 | #include "exec/memory.h" |
f08b6170 | 69 | #include "exec/cpu_ldst.h" |
48a32bed AL |
70 | #include "qmp-commands.h" |
71 | #include "hmp.h" | |
1de7afc9 | 72 | #include "qemu/thread.h" |
b21631f3 | 73 | #include "block/qapi.h" |
43a14cfc WX |
74 | #include "qapi/qmp-event.h" |
75 | #include "qapi-event.h" | |
5560625b | 76 | #include "sysemu/block-backend.h" |
6a5bd307 | 77 | |
1ce6be24 | 78 | /* for hmp_info_irq/pic */ |
661f1929 | 79 | #if defined(TARGET_SPARC) |
0d09e41a | 80 | #include "hw/sparc/sun4m.h" |
661f1929 | 81 | #endif |
0d09e41a | 82 | #include "hw/lm32/lm32_pic.h" |
661f1929 | 83 | |
9307c4c1 FB |
84 | /* |
85 | * Supported types: | |
5fafdf24 | 86 | * |
9307c4c1 | 87 | * 'F' filename |
81d0912d | 88 | * 'B' block device name |
9307c4c1 | 89 | * 's' string (accept optional quote) |
129be006 | 90 | * 'S' it just appends the rest of the string (accept optional quote) |
361127df MA |
91 | * 'O' option string of the form NAME=VALUE,... |
92 | * parsed according to QemuOptsList given by its name | |
93 | * Example: 'device:O' uses qemu_device_opts. | |
94 | * Restriction: only lists with empty desc are supported | |
95 | * TODO lift the restriction | |
92a31b1f FB |
96 | * 'i' 32 bit integer |
97 | * 'l' target long (32 or 64 bit) | |
91162849 LC |
98 | * 'M' Non-negative target long (32 or 64 bit), in user mode the |
99 | * value is multiplied by 2^20 (think Mebibyte) | |
dbc0c67f | 100 | * 'o' octets (aka bytes) |
5e00984a KW |
101 | * user mode accepts an optional E, e, P, p, T, t, G, g, M, m, |
102 | * K, k suffix, which multiplies the value by 2^60 for suffixes E | |
103 | * and e, 2^50 for suffixes P and p, 2^40 for suffixes T and t, | |
104 | * 2^30 for suffixes G and g, 2^20 for M and m, 2^10 for K and k | |
fccfb11e MA |
105 | * 'T' double |
106 | * user mode accepts an optional ms, us, ns suffix, | |
107 | * which divides the value by 1e3, 1e6, 1e9, respectively | |
9307c4c1 FB |
108 | * '/' optional gdb-like print format (like "/10x") |
109 | * | |
fb46660e LC |
110 | * '?' optional type (for all types, except '/') |
111 | * '.' other form of optional type (for 'i' and 'l') | |
942cd1f2 MA |
112 | * 'b' boolean |
113 | * user mode accepts "on" or "off" | |
fb46660e | 114 | * '-' optional parameter (eg. '-f') |
9307c4c1 FB |
115 | * |
116 | */ | |
117 | ||
c227f099 | 118 | typedef struct mon_cmd_t { |
9dc39cba | 119 | const char *name; |
9307c4c1 | 120 | const char *args_type; |
9dc39cba FB |
121 | const char *params; |
122 | const char *help; | |
910df89d | 123 | union { |
af4ce882 | 124 | void (*cmd)(Monitor *mon, const QDict *qdict); |
261394db | 125 | int (*cmd_new)(Monitor *mon, const QDict *params, QObject **ret_data); |
910df89d | 126 | } mhandler; |
5f3d335f WX |
127 | /* @sub_table is a list of 2nd level of commands. If it do not exist, |
128 | * mhandler should be used. If it exist, sub_table[?].mhandler should be | |
129 | * used, and mhandler of 1st level plays the role of help function. | |
130 | */ | |
131 | struct mon_cmd_t *sub_table; | |
bfa40f77 | 132 | void (*command_completion)(ReadLineState *rs, int nb_args, const char *str); |
c227f099 | 133 | } mon_cmd_t; |
9dc39cba | 134 | |
f07918fd | 135 | /* file descriptors passed via SCM_RIGHTS */ |
c227f099 AL |
136 | typedef struct mon_fd_t mon_fd_t; |
137 | struct mon_fd_t { | |
f07918fd MM |
138 | char *name; |
139 | int fd; | |
c227f099 | 140 | QLIST_ENTRY(mon_fd_t) next; |
f07918fd MM |
141 | }; |
142 | ||
ba1c048a CB |
143 | /* file descriptor associated with a file descriptor set */ |
144 | typedef struct MonFdsetFd MonFdsetFd; | |
145 | struct MonFdsetFd { | |
146 | int fd; | |
147 | bool removed; | |
148 | char *opaque; | |
149 | QLIST_ENTRY(MonFdsetFd) next; | |
150 | }; | |
151 | ||
152 | /* file descriptor set containing fds passed via SCM_RIGHTS */ | |
153 | typedef struct MonFdset MonFdset; | |
154 | struct MonFdset { | |
155 | int64_t id; | |
156 | QLIST_HEAD(, MonFdsetFd) fds; | |
adb696f3 | 157 | QLIST_HEAD(, MonFdsetFd) dup_fds; |
ba1c048a CB |
158 | QLIST_ENTRY(MonFdset) next; |
159 | }; | |
160 | ||
74358f2a | 161 | typedef struct { |
5fa737a4 LC |
162 | QObject *id; |
163 | JSONMessageParser parser; | |
f994b258 MA |
164 | /* |
165 | * When a client connects, we're in capabilities negotiation mode. | |
166 | * When command qmp_capabilities succeeds, we go into command | |
167 | * mode. | |
168 | */ | |
169 | bool in_command_mode; /* are we in command mode? */ | |
74358f2a | 170 | } MonitorQMP; |
5fa737a4 | 171 | |
afeecec2 DB |
172 | /* |
173 | * To prevent flooding clients, events can be throttled. The | |
174 | * throttling is calculated globally, rather than per-Monitor | |
175 | * instance. | |
176 | */ | |
43a14cfc WX |
177 | typedef struct MonitorQAPIEventState { |
178 | QAPIEvent event; /* Event being tracked */ | |
179 | int64_t rate; /* Minimum time (in ns) between two events */ | |
180 | int64_t last; /* QEMU_CLOCK_REALTIME value at last emission */ | |
afeecec2 DB |
181 | QEMUTimer *timer; /* Timer for handling delayed events */ |
182 | QObject *data; /* Event pending delayed dispatch */ | |
43a14cfc | 183 | } MonitorQAPIEventState; |
afeecec2 | 184 | |
87127161 AL |
185 | struct Monitor { |
186 | CharDriverState *chr; | |
a7aec5da | 187 | int reset_seen; |
731b0364 AL |
188 | int flags; |
189 | int suspend_cnt; | |
48c043d0 | 190 | bool skip_flush; |
6cff3e85 PB |
191 | |
192 | QemuMutex out_lock; | |
e1f2641b | 193 | QString *outbuf; |
6cff3e85 PB |
194 | guint out_watch; |
195 | ||
196 | /* Read under either BQL or out_lock, written with BQL+out_lock. */ | |
197 | int mux_out; | |
198 | ||
731b0364 | 199 | ReadLineState *rs; |
74358f2a | 200 | MonitorQMP qmp; |
cb446eca | 201 | CPUState *mon_cpu; |
097310b5 | 202 | BlockCompletionFunc *password_completion_cb; |
731b0364 | 203 | void *password_opaque; |
7717239d | 204 | mon_cmd_t *cmd_table; |
8204a918 | 205 | QError *error; |
c227f099 | 206 | QLIST_HEAD(,mon_fd_t) fds; |
72cf2d4f | 207 | QLIST_ENTRY(Monitor) entry; |
87127161 AL |
208 | }; |
209 | ||
2dbc8db0 LC |
210 | /* QMP checker flags */ |
211 | #define QMP_ACCEPT_UNKNOWNS 1 | |
212 | ||
d622cb58 PB |
213 | /* Protects mon_list, monitor_event_state. */ |
214 | static QemuMutex monitor_lock; | |
215 | ||
72cf2d4f | 216 | static QLIST_HEAD(mon_list, Monitor) mon_list; |
ba1c048a | 217 | static QLIST_HEAD(mon_fdsets, MonFdset) mon_fdsets; |
efb87c16 | 218 | static int mon_refcount; |
7e2515e8 | 219 | |
816f8925 WX |
220 | static mon_cmd_t mon_cmds[]; |
221 | static mon_cmd_t info_cmds[]; | |
9dc39cba | 222 | |
f36b4afb LC |
223 | static const mon_cmd_t qmp_cmds[]; |
224 | ||
8631b608 | 225 | Monitor *cur_mon; |
376253ec | 226 | |
c60bf339 SH |
227 | static void monitor_command_cb(void *opaque, const char *cmdline, |
228 | void *readline_opaque); | |
83ab7950 | 229 | |
9f3982f2 MA |
230 | /** |
231 | * Is @mon a QMP monitor? | |
232 | */ | |
233 | static inline bool monitor_is_qmp(const Monitor *mon) | |
418173c7 LC |
234 | { |
235 | return (mon->flags & MONITOR_USE_CONTROL); | |
236 | } | |
237 | ||
489653b5 MA |
238 | /** |
239 | * Is the current monitor, if any, a QMP monitor? | |
240 | */ | |
241 | bool monitor_cur_is_qmp(void) | |
6620d3ce | 242 | { |
9f3982f2 | 243 | return cur_mon && monitor_is_qmp(cur_mon); |
6620d3ce MA |
244 | } |
245 | ||
7060b478 | 246 | void monitor_read_command(Monitor *mon, int show_prompt) |
731b0364 | 247 | { |
183e6e52 LC |
248 | if (!mon->rs) |
249 | return; | |
250 | ||
731b0364 AL |
251 | readline_start(mon->rs, "(qemu) ", 0, monitor_command_cb, NULL); |
252 | if (show_prompt) | |
253 | readline_show_prompt(mon->rs); | |
254 | } | |
6a00d601 | 255 | |
7060b478 AL |
256 | int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, |
257 | void *opaque) | |
bb5fc20f | 258 | { |
bcf5d19c | 259 | if (mon->rs) { |
cde76ee1 AL |
260 | readline_start(mon->rs, "Password: ", 1, readline_func, opaque); |
261 | /* prompt is printed on return from the command handler */ | |
262 | return 0; | |
263 | } else { | |
264 | monitor_printf(mon, "terminal does not support password prompting\n"); | |
265 | return -ENOTTY; | |
266 | } | |
bb5fc20f AL |
267 | } |
268 | ||
6cff3e85 PB |
269 | static void monitor_flush_locked(Monitor *mon); |
270 | ||
f628926b GH |
271 | static gboolean monitor_unblocked(GIOChannel *chan, GIOCondition cond, |
272 | void *opaque) | |
273 | { | |
293d2a00 LE |
274 | Monitor *mon = opaque; |
275 | ||
6cff3e85 PB |
276 | qemu_mutex_lock(&mon->out_lock); |
277 | mon->out_watch = 0; | |
278 | monitor_flush_locked(mon); | |
279 | qemu_mutex_unlock(&mon->out_lock); | |
f628926b GH |
280 | return FALSE; |
281 | } | |
282 | ||
6cff3e85 PB |
283 | /* Called with mon->out_lock held. */ |
284 | static void monitor_flush_locked(Monitor *mon) | |
7e2515e8 | 285 | { |
f628926b | 286 | int rc; |
e1f2641b LC |
287 | size_t len; |
288 | const char *buf; | |
289 | ||
48c043d0 LC |
290 | if (mon->skip_flush) { |
291 | return; | |
292 | } | |
293 | ||
e1f2641b LC |
294 | buf = qstring_get_str(mon->outbuf); |
295 | len = qstring_get_length(mon->outbuf); | |
f628926b | 296 | |
a4cc73d6 | 297 | if (len && !mon->mux_out) { |
e1f2641b | 298 | rc = qemu_chr_fe_write(mon->chr, (const uint8_t *) buf, len); |
056f49ff SP |
299 | if ((rc < 0 && errno != EAGAIN) || (rc == len)) { |
300 | /* all flushed or error */ | |
e1f2641b LC |
301 | QDECREF(mon->outbuf); |
302 | mon->outbuf = qstring_new(); | |
f628926b GH |
303 | return; |
304 | } | |
305 | if (rc > 0) { | |
306 | /* partinal write */ | |
e1f2641b LC |
307 | QString *tmp = qstring_from_str(buf + rc); |
308 | QDECREF(mon->outbuf); | |
309 | mon->outbuf = tmp; | |
f628926b | 310 | } |
6cff3e85 | 311 | if (mon->out_watch == 0) { |
e02bc6de | 312 | mon->out_watch = qemu_chr_fe_add_watch(mon->chr, G_IO_OUT|G_IO_HUP, |
6cff3e85 | 313 | monitor_unblocked, mon); |
293d2a00 | 314 | } |
7e2515e8 FB |
315 | } |
316 | } | |
317 | ||
6cff3e85 PB |
318 | void monitor_flush(Monitor *mon) |
319 | { | |
320 | qemu_mutex_lock(&mon->out_lock); | |
321 | monitor_flush_locked(mon); | |
322 | qemu_mutex_unlock(&mon->out_lock); | |
323 | } | |
324 | ||
e1f2641b | 325 | /* flush at every end of line */ |
376253ec | 326 | static void monitor_puts(Monitor *mon, const char *str) |
7e2515e8 | 327 | { |
60fe76f3 | 328 | char c; |
731b0364 | 329 | |
6cff3e85 | 330 | qemu_mutex_lock(&mon->out_lock); |
7e2515e8 FB |
331 | for(;;) { |
332 | c = *str++; | |
333 | if (c == '\0') | |
334 | break; | |
e1f2641b LC |
335 | if (c == '\n') { |
336 | qstring_append_chr(mon->outbuf, '\r'); | |
337 | } | |
338 | qstring_append_chr(mon->outbuf, c); | |
339 | if (c == '\n') { | |
6cff3e85 | 340 | monitor_flush_locked(mon); |
e1f2641b | 341 | } |
7e2515e8 | 342 | } |
6cff3e85 | 343 | qemu_mutex_unlock(&mon->out_lock); |
7e2515e8 FB |
344 | } |
345 | ||
376253ec | 346 | void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) |
9dc39cba | 347 | { |
e1f2641b | 348 | char *buf; |
b8b08266 | 349 | |
2daa1191 LC |
350 | if (!mon) |
351 | return; | |
352 | ||
9f3982f2 | 353 | if (monitor_is_qmp(mon)) { |
b8b08266 | 354 | return; |
4a29a85d | 355 | } |
b8b08266 | 356 | |
e1f2641b | 357 | buf = g_strdup_vprintf(fmt, ap); |
b8b08266 | 358 | monitor_puts(mon, buf); |
e1f2641b | 359 | g_free(buf); |
9dc39cba FB |
360 | } |
361 | ||
376253ec | 362 | void monitor_printf(Monitor *mon, const char *fmt, ...) |
9dc39cba | 363 | { |
7e2515e8 FB |
364 | va_list ap; |
365 | va_start(ap, fmt); | |
376253ec | 366 | monitor_vprintf(mon, fmt, ap); |
7e2515e8 | 367 | va_end(ap); |
9dc39cba FB |
368 | } |
369 | ||
8b7968f7 SW |
370 | static int GCC_FMT_ATTR(2, 3) monitor_fprintf(FILE *stream, |
371 | const char *fmt, ...) | |
7fe48483 FB |
372 | { |
373 | va_list ap; | |
374 | va_start(ap, fmt); | |
376253ec | 375 | monitor_vprintf((Monitor *)stream, fmt, ap); |
7fe48483 FB |
376 | va_end(ap); |
377 | return 0; | |
378 | } | |
379 | ||
9b57c02e LC |
380 | static void monitor_json_emitter(Monitor *mon, const QObject *data) |
381 | { | |
382 | QString *json; | |
383 | ||
83a27d4d LC |
384 | json = mon->flags & MONITOR_USE_PRETTY ? qobject_to_json_pretty(data) : |
385 | qobject_to_json(data); | |
9b57c02e LC |
386 | assert(json != NULL); |
387 | ||
b8b08266 LC |
388 | qstring_append_chr(json, '\n'); |
389 | monitor_puts(mon, qstring_get_str(json)); | |
4a29a85d | 390 | |
9b57c02e LC |
391 | QDECREF(json); |
392 | } | |
393 | ||
710aec91 | 394 | static QDict *build_qmp_error_dict(Error *err) |
de253f14 LC |
395 | { |
396 | QObject *obj; | |
397 | ||
710aec91 MA |
398 | obj = qobject_from_jsonf("{ 'error': { 'class': %s, 'desc': %s } }", |
399 | ErrorClass_lookup[error_get_class(err)], | |
400 | error_get_pretty(err)); | |
de253f14 LC |
401 | |
402 | return qobject_to_qdict(obj); | |
403 | } | |
404 | ||
70ea0c58 | 405 | static void monitor_protocol_emitter(Monitor *mon, QObject *data, |
710aec91 | 406 | Error *err) |
25b422eb LC |
407 | { |
408 | QDict *qmp; | |
409 | ||
89bd820a SH |
410 | trace_monitor_protocol_emitter(mon); |
411 | ||
70ea0c58 | 412 | if (!err) { |
25b422eb | 413 | /* success response */ |
de253f14 | 414 | qmp = qdict_new(); |
25b422eb LC |
415 | if (data) { |
416 | qobject_incref(data); | |
417 | qdict_put_obj(qmp, "return", data); | |
418 | } else { | |
0abc6579 LC |
419 | /* return an empty QDict by default */ |
420 | qdict_put(qmp, "return", qdict_new()); | |
25b422eb LC |
421 | } |
422 | } else { | |
423 | /* error response */ | |
70ea0c58 | 424 | qmp = build_qmp_error_dict(err); |
25b422eb LC |
425 | } |
426 | ||
74358f2a MA |
427 | if (mon->qmp.id) { |
428 | qdict_put_obj(qmp, "id", mon->qmp.id); | |
429 | mon->qmp.id = NULL; | |
5fa737a4 LC |
430 | } |
431 | ||
25b422eb LC |
432 | monitor_json_emitter(mon, QOBJECT(qmp)); |
433 | QDECREF(qmp); | |
434 | } | |
435 | ||
0d1ea871 | 436 | |
43a14cfc | 437 | static MonitorQAPIEventState monitor_qapi_event_state[QAPI_EVENT_MAX]; |
afeecec2 DB |
438 | |
439 | /* | |
43a14cfc | 440 | * Emits the event to every monitor instance, @event is only used for trace |
d622cb58 | 441 | * Called with monitor_lock held. |
afeecec2 | 442 | */ |
43a14cfc | 443 | static void monitor_qapi_event_emit(QAPIEvent event, QObject *data) |
afeecec2 DB |
444 | { |
445 | Monitor *mon; | |
446 | ||
447 | trace_monitor_protocol_event_emit(event, data); | |
448 | QLIST_FOREACH(mon, &mon_list, entry) { | |
9f3982f2 | 449 | if (monitor_is_qmp(mon) && mon->qmp.in_command_mode) { |
afeecec2 DB |
450 | monitor_json_emitter(mon, data); |
451 | } | |
452 | } | |
453 | } | |
454 | ||
afeecec2 DB |
455 | /* |
456 | * Queue a new event for emission to Monitor instances, | |
457 | * applying any rate limiting if required. | |
458 | */ | |
459 | static void | |
43a14cfc | 460 | monitor_qapi_event_queue(QAPIEvent event, QDict *data, Error **errp) |
afeecec2 | 461 | { |
43a14cfc WX |
462 | MonitorQAPIEventState *evstate; |
463 | assert(event < QAPI_EVENT_MAX); | |
bc72ad67 | 464 | int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); |
afeecec2 | 465 | |
43a14cfc | 466 | evstate = &(monitor_qapi_event_state[event]); |
afeecec2 DB |
467 | trace_monitor_protocol_event_queue(event, |
468 | data, | |
469 | evstate->rate, | |
470 | evstate->last, | |
471 | now); | |
472 | ||
473 | /* Rate limit of 0 indicates no throttling */ | |
d622cb58 | 474 | qemu_mutex_lock(&monitor_lock); |
afeecec2 | 475 | if (!evstate->rate) { |
43a14cfc | 476 | monitor_qapi_event_emit(event, QOBJECT(data)); |
afeecec2 DB |
477 | evstate->last = now; |
478 | } else { | |
479 | int64_t delta = now - evstate->last; | |
480 | if (evstate->data || | |
481 | delta < evstate->rate) { | |
482 | /* If there's an existing event pending, replace | |
483 | * it with the new event, otherwise schedule a | |
484 | * timer for delayed emission | |
485 | */ | |
486 | if (evstate->data) { | |
487 | qobject_decref(evstate->data); | |
488 | } else { | |
489 | int64_t then = evstate->last + evstate->rate; | |
bc72ad67 | 490 | timer_mod_ns(evstate->timer, then); |
afeecec2 | 491 | } |
43a14cfc | 492 | evstate->data = QOBJECT(data); |
afeecec2 DB |
493 | qobject_incref(evstate->data); |
494 | } else { | |
43a14cfc | 495 | monitor_qapi_event_emit(event, QOBJECT(data)); |
afeecec2 DB |
496 | evstate->last = now; |
497 | } | |
498 | } | |
d622cb58 | 499 | qemu_mutex_unlock(&monitor_lock); |
afeecec2 DB |
500 | } |
501 | ||
afeecec2 DB |
502 | /* |
503 | * The callback invoked by QemuTimer when a delayed | |
504 | * event is ready to be emitted | |
505 | */ | |
43a14cfc | 506 | static void monitor_qapi_event_handler(void *opaque) |
afeecec2 | 507 | { |
43a14cfc | 508 | MonitorQAPIEventState *evstate = opaque; |
bc72ad67 | 509 | int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); |
afeecec2 | 510 | |
afeecec2 DB |
511 | trace_monitor_protocol_event_handler(evstate->event, |
512 | evstate->data, | |
513 | evstate->last, | |
514 | now); | |
d622cb58 | 515 | qemu_mutex_lock(&monitor_lock); |
afeecec2 | 516 | if (evstate->data) { |
43a14cfc | 517 | monitor_qapi_event_emit(evstate->event, evstate->data); |
afeecec2 DB |
518 | qobject_decref(evstate->data); |
519 | evstate->data = NULL; | |
520 | } | |
521 | evstate->last = now; | |
d622cb58 | 522 | qemu_mutex_unlock(&monitor_lock); |
afeecec2 DB |
523 | } |
524 | ||
afeecec2 DB |
525 | /* |
526 | * @event: the event ID to be limited | |
527 | * @rate: the rate limit in milliseconds | |
528 | * | |
529 | * Sets a rate limit on a particular event, so no | |
530 | * more than 1 event will be emitted within @rate | |
531 | * milliseconds | |
532 | */ | |
533 | static void | |
43a14cfc | 534 | monitor_qapi_event_throttle(QAPIEvent event, int64_t rate) |
afeecec2 | 535 | { |
43a14cfc WX |
536 | MonitorQAPIEventState *evstate; |
537 | assert(event < QAPI_EVENT_MAX); | |
afeecec2 | 538 | |
43a14cfc | 539 | evstate = &(monitor_qapi_event_state[event]); |
afeecec2 DB |
540 | |
541 | trace_monitor_protocol_event_throttle(event, rate); | |
542 | evstate->event = event; | |
2f44a08b | 543 | assert(rate * SCALE_MS <= INT64_MAX); |
afeecec2 | 544 | evstate->rate = rate * SCALE_MS; |
afeecec2 DB |
545 | evstate->last = 0; |
546 | evstate->data = NULL; | |
43a14cfc WX |
547 | evstate->timer = timer_new(QEMU_CLOCK_REALTIME, |
548 | SCALE_MS, | |
549 | monitor_qapi_event_handler, | |
550 | evstate); | |
afeecec2 DB |
551 | } |
552 | ||
43a14cfc | 553 | static void monitor_qapi_event_init(void) |
afeecec2 | 554 | { |
e010ad8f WX |
555 | /* Limit guest-triggerable events to 1 per second */ |
556 | monitor_qapi_event_throttle(QAPI_EVENT_RTC_CHANGE, 1000); | |
99eaf09c | 557 | monitor_qapi_event_throttle(QAPI_EVENT_WATCHDOG, 1000); |
aef9d311 | 558 | monitor_qapi_event_throttle(QAPI_EVENT_BALLOON_CHANGE, 1000); |
fe069d9d WX |
559 | monitor_qapi_event_throttle(QAPI_EVENT_QUORUM_REPORT_BAD, 1000); |
560 | monitor_qapi_event_throttle(QAPI_EVENT_QUORUM_FAILURE, 1000); | |
e2ae6159 | 561 | monitor_qapi_event_throttle(QAPI_EVENT_VSERPORT_CHANGE, 1000); |
0d1ea871 | 562 | |
43a14cfc | 563 | qmp_event_set_func_emit(monitor_qapi_event_queue); |
0d1ea871 LC |
564 | } |
565 | ||
ef4b7eee LC |
566 | static int do_qmp_capabilities(Monitor *mon, const QDict *params, |
567 | QObject **ret_data) | |
4a7e1190 | 568 | { |
f994b258 | 569 | mon->qmp.in_command_mode = true; |
ef4b7eee | 570 | return 0; |
4a7e1190 LC |
571 | } |
572 | ||
7ef6cf63 | 573 | static void handle_hmp_command(Monitor *mon, const char *cmdline); |
0268d97c | 574 | |
b01fe89e WX |
575 | static void monitor_data_init(Monitor *mon) |
576 | { | |
577 | memset(mon, 0, sizeof(Monitor)); | |
6cff3e85 | 578 | qemu_mutex_init(&mon->out_lock); |
b01fe89e | 579 | mon->outbuf = qstring_new(); |
7717239d WX |
580 | /* Use *mon_cmds by default. */ |
581 | mon->cmd_table = mon_cmds; | |
b01fe89e WX |
582 | } |
583 | ||
584 | static void monitor_data_destroy(Monitor *mon) | |
585 | { | |
586 | QDECREF(mon->outbuf); | |
6cff3e85 | 587 | qemu_mutex_destroy(&mon->out_lock); |
b01fe89e WX |
588 | } |
589 | ||
d51a67b4 LC |
590 | char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index, |
591 | int64_t cpu_index, Error **errp) | |
0268d97c | 592 | { |
d51a67b4 | 593 | char *output = NULL; |
0268d97c | 594 | Monitor *old_mon, hmp; |
0268d97c | 595 | |
b01fe89e | 596 | monitor_data_init(&hmp); |
48c043d0 | 597 | hmp.skip_flush = true; |
0268d97c LC |
598 | |
599 | old_mon = cur_mon; | |
600 | cur_mon = &hmp; | |
601 | ||
d51a67b4 LC |
602 | if (has_cpu_index) { |
603 | int ret = monitor_set_cpu(cpu_index); | |
0268d97c LC |
604 | if (ret < 0) { |
605 | cur_mon = old_mon; | |
d51a67b4 LC |
606 | error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", |
607 | "a CPU number"); | |
0268d97c LC |
608 | goto out; |
609 | } | |
610 | } | |
611 | ||
7ef6cf63 | 612 | handle_hmp_command(&hmp, command_line); |
0268d97c LC |
613 | cur_mon = old_mon; |
614 | ||
6cff3e85 | 615 | qemu_mutex_lock(&hmp.out_lock); |
48c043d0 LC |
616 | if (qstring_get_length(hmp.outbuf) > 0) { |
617 | output = g_strdup(qstring_get_str(hmp.outbuf)); | |
d51a67b4 LC |
618 | } else { |
619 | output = g_strdup(""); | |
0268d97c | 620 | } |
6cff3e85 | 621 | qemu_mutex_unlock(&hmp.out_lock); |
0268d97c LC |
622 | |
623 | out: | |
b01fe89e | 624 | monitor_data_destroy(&hmp); |
d51a67b4 | 625 | return output; |
0268d97c LC |
626 | } |
627 | ||
9dc39cba FB |
628 | static int compare_cmd(const char *name, const char *list) |
629 | { | |
630 | const char *p, *pstart; | |
631 | int len; | |
632 | len = strlen(name); | |
633 | p = list; | |
634 | for(;;) { | |
635 | pstart = p; | |
636 | p = strchr(p, '|'); | |
637 | if (!p) | |
638 | p = pstart + strlen(pstart); | |
639 | if ((p - pstart) == len && !memcmp(pstart, name, len)) | |
640 | return 1; | |
641 | if (*p == '\0') | |
642 | break; | |
643 | p++; | |
644 | } | |
645 | return 0; | |
646 | } | |
647 | ||
f5438c05 WX |
648 | static int get_str(char *buf, int buf_size, const char **pp) |
649 | { | |
650 | const char *p; | |
651 | char *q; | |
652 | int c; | |
653 | ||
654 | q = buf; | |
655 | p = *pp; | |
656 | while (qemu_isspace(*p)) { | |
657 | p++; | |
658 | } | |
659 | if (*p == '\0') { | |
660 | fail: | |
661 | *q = '\0'; | |
662 | *pp = p; | |
663 | return -1; | |
664 | } | |
665 | if (*p == '\"') { | |
666 | p++; | |
667 | while (*p != '\0' && *p != '\"') { | |
668 | if (*p == '\\') { | |
669 | p++; | |
670 | c = *p++; | |
671 | switch (c) { | |
672 | case 'n': | |
673 | c = '\n'; | |
674 | break; | |
675 | case 'r': | |
676 | c = '\r'; | |
677 | break; | |
678 | case '\\': | |
679 | case '\'': | |
680 | case '\"': | |
681 | break; | |
682 | default: | |
683 | qemu_printf("unsupported escape code: '\\%c'\n", c); | |
684 | goto fail; | |
685 | } | |
686 | if ((q - buf) < buf_size - 1) { | |
687 | *q++ = c; | |
688 | } | |
689 | } else { | |
690 | if ((q - buf) < buf_size - 1) { | |
691 | *q++ = *p; | |
692 | } | |
693 | p++; | |
694 | } | |
695 | } | |
696 | if (*p != '\"') { | |
697 | qemu_printf("unterminated string\n"); | |
698 | goto fail; | |
699 | } | |
700 | p++; | |
701 | } else { | |
702 | while (*p != '\0' && !qemu_isspace(*p)) { | |
703 | if ((q - buf) < buf_size - 1) { | |
704 | *q++ = *p; | |
705 | } | |
706 | p++; | |
707 | } | |
708 | } | |
709 | *q = '\0'; | |
710 | *pp = p; | |
711 | return 0; | |
712 | } | |
713 | ||
714 | #define MAX_ARGS 16 | |
715 | ||
dcc70cdf WX |
716 | static void free_cmdline_args(char **args, int nb_args) |
717 | { | |
718 | int i; | |
719 | ||
720 | assert(nb_args <= MAX_ARGS); | |
721 | ||
722 | for (i = 0; i < nb_args; i++) { | |
723 | g_free(args[i]); | |
724 | } | |
725 | ||
726 | } | |
727 | ||
728 | /* | |
729 | * Parse the command line to get valid args. | |
730 | * @cmdline: command line to be parsed. | |
731 | * @pnb_args: location to store the number of args, must NOT be NULL. | |
732 | * @args: location to store the args, which should be freed by caller, must | |
733 | * NOT be NULL. | |
734 | * | |
735 | * Returns 0 on success, negative on failure. | |
736 | * | |
737 | * NOTE: this parser is an approximate form of the real command parser. Number | |
738 | * of args have a limit of MAX_ARGS. If cmdline contains more, it will | |
739 | * return with failure. | |
740 | */ | |
741 | static int parse_cmdline(const char *cmdline, | |
742 | int *pnb_args, char **args) | |
f5438c05 WX |
743 | { |
744 | const char *p; | |
745 | int nb_args, ret; | |
746 | char buf[1024]; | |
747 | ||
748 | p = cmdline; | |
749 | nb_args = 0; | |
750 | for (;;) { | |
751 | while (qemu_isspace(*p)) { | |
752 | p++; | |
753 | } | |
754 | if (*p == '\0') { | |
755 | break; | |
756 | } | |
757 | if (nb_args >= MAX_ARGS) { | |
dcc70cdf | 758 | goto fail; |
f5438c05 WX |
759 | } |
760 | ret = get_str(buf, sizeof(buf), &p); | |
f5438c05 | 761 | if (ret < 0) { |
dcc70cdf | 762 | goto fail; |
f5438c05 | 763 | } |
dcc70cdf WX |
764 | args[nb_args] = g_strdup(buf); |
765 | nb_args++; | |
f5438c05 WX |
766 | } |
767 | *pnb_args = nb_args; | |
dcc70cdf WX |
768 | return 0; |
769 | ||
770 | fail: | |
771 | free_cmdline_args(args, nb_args); | |
772 | return -1; | |
f5438c05 WX |
773 | } |
774 | ||
66855495 WX |
775 | static void help_cmd_dump_one(Monitor *mon, |
776 | const mon_cmd_t *cmd, | |
777 | char **prefix_args, | |
778 | int prefix_args_nb) | |
779 | { | |
780 | int i; | |
781 | ||
782 | for (i = 0; i < prefix_args_nb; i++) { | |
783 | monitor_printf(mon, "%s ", prefix_args[i]); | |
784 | } | |
785 | monitor_printf(mon, "%s %s -- %s\n", cmd->name, cmd->params, cmd->help); | |
786 | } | |
787 | ||
788 | /* @args[@arg_index] is the valid command need to find in @cmds */ | |
c227f099 | 789 | static void help_cmd_dump(Monitor *mon, const mon_cmd_t *cmds, |
66855495 | 790 | char **args, int nb_args, int arg_index) |
9dc39cba | 791 | { |
c227f099 | 792 | const mon_cmd_t *cmd; |
9dc39cba | 793 | |
66855495 WX |
794 | /* No valid arg need to compare with, dump all in *cmds */ |
795 | if (arg_index >= nb_args) { | |
796 | for (cmd = cmds; cmd->name != NULL; cmd++) { | |
797 | help_cmd_dump_one(mon, cmd, args, arg_index); | |
798 | } | |
799 | return; | |
800 | } | |
801 | ||
802 | /* Find one entry to dump */ | |
803 | for (cmd = cmds; cmd->name != NULL; cmd++) { | |
804 | if (compare_cmd(args[arg_index], cmd->name)) { | |
805 | if (cmd->sub_table) { | |
806 | /* continue with next arg */ | |
807 | help_cmd_dump(mon, cmd->sub_table, | |
808 | args, nb_args, arg_index + 1); | |
809 | } else { | |
810 | help_cmd_dump_one(mon, cmd, args, arg_index); | |
811 | } | |
812 | break; | |
813 | } | |
9dc39cba FB |
814 | } |
815 | } | |
816 | ||
376253ec | 817 | static void help_cmd(Monitor *mon, const char *name) |
9dc39cba | 818 | { |
66855495 WX |
819 | char *args[MAX_ARGS]; |
820 | int nb_args = 0; | |
821 | ||
822 | /* 1. parse user input */ | |
823 | if (name) { | |
824 | /* special case for log, directly dump and return */ | |
825 | if (!strcmp(name, "log")) { | |
38dad9e5 | 826 | const QEMULogItem *item; |
376253ec AL |
827 | monitor_printf(mon, "Log items (comma separated):\n"); |
828 | monitor_printf(mon, "%-10s %s\n", "none", "remove all logs"); | |
38dad9e5 | 829 | for (item = qemu_log_items; item->mask != 0; item++) { |
376253ec | 830 | monitor_printf(mon, "%-10s %s\n", item->name, item->help); |
f193c797 | 831 | } |
66855495 WX |
832 | return; |
833 | } | |
834 | ||
835 | if (parse_cmdline(name, &nb_args, args) < 0) { | |
836 | return; | |
f193c797 | 837 | } |
9dc39cba | 838 | } |
66855495 WX |
839 | |
840 | /* 2. dump the contents according to parsed args */ | |
841 | help_cmd_dump(mon, mon->cmd_table, args, nb_args, 0); | |
842 | ||
843 | free_cmdline_args(args, nb_args); | |
9dc39cba FB |
844 | } |
845 | ||
d54908a5 | 846 | static void do_help_cmd(Monitor *mon, const QDict *qdict) |
38183186 | 847 | { |
d54908a5 | 848 | help_cmd(mon, qdict_get_try_str(qdict, "name")); |
38183186 LC |
849 | } |
850 | ||
3e5a50d6 | 851 | static void hmp_trace_event(Monitor *mon, const QDict *qdict) |
22890ab5 PS |
852 | { |
853 | const char *tp_name = qdict_get_str(qdict, "name"); | |
854 | bool new_state = qdict_get_bool(qdict, "option"); | |
14101d02 | 855 | Error *local_err = NULL; |
f871d689 | 856 | |
14101d02 LV |
857 | qmp_trace_event_set_state(tp_name, new_state, true, true, &local_err); |
858 | if (local_err) { | |
091e38b7 | 859 | error_report_err(local_err); |
f871d689 | 860 | } |
22890ab5 | 861 | } |
c5ceb523 | 862 | |
c45a8168 | 863 | #ifdef CONFIG_TRACE_SIMPLE |
3e5a50d6 | 864 | static void hmp_trace_file(Monitor *mon, const QDict *qdict) |
c5ceb523 SH |
865 | { |
866 | const char *op = qdict_get_try_str(qdict, "op"); | |
867 | const char *arg = qdict_get_try_str(qdict, "arg"); | |
868 | ||
869 | if (!op) { | |
870 | st_print_trace_file_status((FILE *)mon, &monitor_fprintf); | |
871 | } else if (!strcmp(op, "on")) { | |
872 | st_set_trace_file_enabled(true); | |
873 | } else if (!strcmp(op, "off")) { | |
874 | st_set_trace_file_enabled(false); | |
875 | } else if (!strcmp(op, "flush")) { | |
876 | st_flush_trace_buffer(); | |
877 | } else if (!strcmp(op, "set")) { | |
878 | if (arg) { | |
879 | st_set_trace_file(arg); | |
880 | } | |
881 | } else { | |
882 | monitor_printf(mon, "unexpected argument \"%s\"\n", op); | |
883 | help_cmd(mon, "trace-file"); | |
884 | } | |
885 | } | |
22890ab5 PS |
886 | #endif |
887 | ||
3e5a50d6 | 888 | static void hmp_info_help(Monitor *mon, const QDict *qdict) |
9dc39cba | 889 | { |
13c7425e | 890 | help_cmd(mon, "info"); |
9dc39cba FB |
891 | } |
892 | ||
aa9b79bc | 893 | CommandInfoList *qmp_query_commands(Error **errp) |
e3bba9d0 | 894 | { |
aa9b79bc | 895 | CommandInfoList *info, *cmd_list = NULL; |
e3bba9d0 LC |
896 | const mon_cmd_t *cmd; |
897 | ||
f36b4afb | 898 | for (cmd = qmp_cmds; cmd->name != NULL; cmd++) { |
40e5a01d LC |
899 | info = g_malloc0(sizeof(*info)); |
900 | info->value = g_malloc0(sizeof(*info->value)); | |
901 | info->value->name = g_strdup(cmd->name); | |
e3bba9d0 | 902 | |
aa9b79bc LC |
903 | info->next = cmd_list; |
904 | cmd_list = info; | |
e3bba9d0 LC |
905 | } |
906 | ||
aa9b79bc | 907 | return cmd_list; |
a36e69dd TS |
908 | } |
909 | ||
4860853d DB |
910 | EventInfoList *qmp_query_events(Error **errp) |
911 | { | |
912 | EventInfoList *info, *ev_list = NULL; | |
75175173 | 913 | QAPIEvent e; |
4860853d | 914 | |
75175173 WX |
915 | for (e = 0 ; e < QAPI_EVENT_MAX ; e++) { |
916 | const char *event_name = QAPIEvent_lookup[e]; | |
4860853d DB |
917 | assert(event_name != NULL); |
918 | info = g_malloc0(sizeof(*info)); | |
919 | info->value = g_malloc0(sizeof(*info->value)); | |
920 | info->value->name = g_strdup(event_name); | |
921 | ||
922 | info->next = ev_list; | |
923 | ev_list = info; | |
924 | } | |
925 | ||
926 | return ev_list; | |
927 | } | |
928 | ||
b025c8b4 LC |
929 | /* set the current CPU defined by the user */ |
930 | int monitor_set_cpu(int cpu_index) | |
6a00d601 | 931 | { |
55e5c285 | 932 | CPUState *cpu; |
6a00d601 | 933 | |
1c8bb3cc AF |
934 | cpu = qemu_get_cpu(cpu_index); |
935 | if (cpu == NULL) { | |
936 | return -1; | |
6a00d601 | 937 | } |
cb446eca | 938 | cur_mon->mon_cpu = cpu; |
1c8bb3cc | 939 | return 0; |
6a00d601 FB |
940 | } |
941 | ||
9349b4f9 | 942 | static CPUArchState *mon_get_cpu(void) |
6a00d601 | 943 | { |
731b0364 | 944 | if (!cur_mon->mon_cpu) { |
b025c8b4 | 945 | monitor_set_cpu(0); |
6a00d601 | 946 | } |
4c0960c0 | 947 | cpu_synchronize_state(cur_mon->mon_cpu); |
cb446eca | 948 | return cur_mon->mon_cpu->env_ptr; |
6a00d601 FB |
949 | } |
950 | ||
99b7796f LC |
951 | int monitor_get_cpu_index(void) |
952 | { | |
55e5c285 AF |
953 | CPUState *cpu = ENV_GET_CPU(mon_get_cpu()); |
954 | return cpu->cpu_index; | |
99b7796f LC |
955 | } |
956 | ||
1ce6be24 | 957 | static void hmp_info_registers(Monitor *mon, const QDict *qdict) |
9307c4c1 | 958 | { |
878096ee | 959 | CPUState *cpu; |
9349b4f9 | 960 | CPUArchState *env; |
6a00d601 | 961 | env = mon_get_cpu(); |
878096ee AF |
962 | cpu = ENV_GET_CPU(env); |
963 | cpu_dump_state(cpu, (FILE *)mon, monitor_fprintf, CPU_DUMP_FPU); | |
9307c4c1 FB |
964 | } |
965 | ||
1ce6be24 | 966 | static void hmp_info_jit(Monitor *mon, const QDict *qdict) |
e3db7226 | 967 | { |
376253ec | 968 | dump_exec_info((FILE *)mon, monitor_fprintf); |
27498bef | 969 | dump_drift_info((FILE *)mon, monitor_fprintf); |
e3db7226 FB |
970 | } |
971 | ||
1ce6be24 | 972 | static void hmp_info_opcount(Monitor *mon, const QDict *qdict) |
246ae24d MF |
973 | { |
974 | dump_opcount_info((FILE *)mon, monitor_fprintf); | |
975 | } | |
976 | ||
1ce6be24 | 977 | static void hmp_info_history(Monitor *mon, const QDict *qdict) |
aa455485 FB |
978 | { |
979 | int i; | |
7e2515e8 | 980 | const char *str; |
3b46e624 | 981 | |
cde76ee1 AL |
982 | if (!mon->rs) |
983 | return; | |
7e2515e8 FB |
984 | i = 0; |
985 | for(;;) { | |
731b0364 | 986 | str = readline_get_history(mon->rs, i); |
7e2515e8 FB |
987 | if (!str) |
988 | break; | |
376253ec | 989 | monitor_printf(mon, "%d: '%s'\n", i, str); |
8e3a9fd2 | 990 | i++; |
aa455485 FB |
991 | } |
992 | } | |
993 | ||
1ce6be24 | 994 | static void hmp_info_cpustats(Monitor *mon, const QDict *qdict) |
76a66253 | 995 | { |
878096ee | 996 | CPUState *cpu; |
9349b4f9 | 997 | CPUArchState *env; |
76a66253 JM |
998 | |
999 | env = mon_get_cpu(); | |
878096ee AF |
1000 | cpu = ENV_GET_CPU(env); |
1001 | cpu_dump_statistics(cpu, (FILE *)mon, &monitor_fprintf, 0); | |
76a66253 | 1002 | } |
76a66253 | 1003 | |
1ce6be24 | 1004 | static void hmp_info_trace_events(Monitor *mon, const QDict *qdict) |
22890ab5 | 1005 | { |
14101d02 LV |
1006 | TraceEventInfoList *events = qmp_trace_event_get_state("*", NULL); |
1007 | TraceEventInfoList *elem; | |
1008 | ||
1009 | for (elem = events; elem != NULL; elem = elem->next) { | |
1010 | monitor_printf(mon, "%s : state %u\n", | |
1011 | elem->value->name, | |
1012 | elem->value->state == TRACE_EVENT_STATE_ENABLED ? 1 : 0); | |
1013 | } | |
1014 | qapi_free_TraceEventInfoList(events); | |
22890ab5 | 1015 | } |
22890ab5 | 1016 | |
b8a185bc MA |
1017 | void qmp_client_migrate_info(const char *protocol, const char *hostname, |
1018 | bool has_port, int64_t port, | |
1019 | bool has_tls_port, int64_t tls_port, | |
1020 | bool has_cert_subject, const char *cert_subject, | |
1021 | Error **errp) | |
e866e239 | 1022 | { |
e866e239 | 1023 | if (strcmp(protocol, "spice") == 0) { |
b8a185bc MA |
1024 | if (!qemu_using_spice(errp)) { |
1025 | return; | |
e866e239 GH |
1026 | } |
1027 | ||
b8a185bc MA |
1028 | if (!has_port && !has_tls_port) { |
1029 | error_set(errp, QERR_MISSING_PARAMETER, "port/tls-port"); | |
1030 | return; | |
6ec5dae5 YH |
1031 | } |
1032 | ||
b8a185bc MA |
1033 | if (qemu_spice_migrate_info(hostname, |
1034 | has_port ? port : -1, | |
1035 | has_tls_port ? tls_port : -1, | |
1036 | cert_subject)) { | |
1037 | error_set(errp, QERR_UNDEFINED_ERROR); | |
1038 | return; | |
e866e239 | 1039 | } |
b8a185bc | 1040 | return; |
e866e239 GH |
1041 | } |
1042 | ||
b8a185bc | 1043 | error_set(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", "spice"); |
e866e239 GH |
1044 | } |
1045 | ||
3e5a50d6 | 1046 | static void hmp_logfile(Monitor *mon, const QDict *qdict) |
e735b91c | 1047 | { |
9a7e5424 | 1048 | qemu_set_log_filename(qdict_get_str(qdict, "filename")); |
e735b91c PB |
1049 | } |
1050 | ||
3e5a50d6 | 1051 | static void hmp_log(Monitor *mon, const QDict *qdict) |
f193c797 FB |
1052 | { |
1053 | int mask; | |
d54908a5 | 1054 | const char *items = qdict_get_str(qdict, "items"); |
3b46e624 | 1055 | |
9307c4c1 | 1056 | if (!strcmp(items, "none")) { |
f193c797 FB |
1057 | mask = 0; |
1058 | } else { | |
4fde1eba | 1059 | mask = qemu_str_to_log_mask(items); |
f193c797 | 1060 | if (!mask) { |
376253ec | 1061 | help_cmd(mon, "log"); |
f193c797 FB |
1062 | return; |
1063 | } | |
1064 | } | |
24537a01 | 1065 | qemu_set_log(mask); |
f193c797 FB |
1066 | } |
1067 | ||
3e5a50d6 | 1068 | static void hmp_singlestep(Monitor *mon, const QDict *qdict) |
1b530a6d | 1069 | { |
d54908a5 | 1070 | const char *option = qdict_get_try_str(qdict, "option"); |
1b530a6d AJ |
1071 | if (!option || !strcmp(option, "on")) { |
1072 | singlestep = 1; | |
1073 | } else if (!strcmp(option, "off")) { | |
1074 | singlestep = 0; | |
1075 | } else { | |
1076 | monitor_printf(mon, "unexpected option %s\n", option); | |
1077 | } | |
1078 | } | |
1079 | ||
3e5a50d6 | 1080 | static void hmp_gdbserver(Monitor *mon, const QDict *qdict) |
59030a8c | 1081 | { |
d54908a5 | 1082 | const char *device = qdict_get_try_str(qdict, "device"); |
59030a8c AL |
1083 | if (!device) |
1084 | device = "tcp::" DEFAULT_GDBSTUB_PORT; | |
1085 | if (gdbserver_start(device) < 0) { | |
1086 | monitor_printf(mon, "Could not open gdbserver on device '%s'\n", | |
1087 | device); | |
1088 | } else if (strcmp(device, "none") == 0) { | |
36556b20 | 1089 | monitor_printf(mon, "Disabled gdbserver\n"); |
8a7ddc38 | 1090 | } else { |
59030a8c AL |
1091 | monitor_printf(mon, "Waiting for gdb connection on device '%s'\n", |
1092 | device); | |
8a7ddc38 FB |
1093 | } |
1094 | } | |
1095 | ||
3e5a50d6 | 1096 | static void hmp_watchdog_action(Monitor *mon, const QDict *qdict) |
9dd986cc | 1097 | { |
d54908a5 | 1098 | const char *action = qdict_get_str(qdict, "action"); |
9dd986cc RJ |
1099 | if (select_watchdog_action(action) == -1) { |
1100 | monitor_printf(mon, "Unknown watchdog action '%s'\n", action); | |
1101 | } | |
1102 | } | |
1103 | ||
376253ec | 1104 | static void monitor_printc(Monitor *mon, int c) |
9307c4c1 | 1105 | { |
376253ec | 1106 | monitor_printf(mon, "'"); |
9307c4c1 FB |
1107 | switch(c) { |
1108 | case '\'': | |
376253ec | 1109 | monitor_printf(mon, "\\'"); |
9307c4c1 FB |
1110 | break; |
1111 | case '\\': | |
376253ec | 1112 | monitor_printf(mon, "\\\\"); |
9307c4c1 FB |
1113 | break; |
1114 | case '\n': | |
376253ec | 1115 | monitor_printf(mon, "\\n"); |
9307c4c1 FB |
1116 | break; |
1117 | case '\r': | |
376253ec | 1118 | monitor_printf(mon, "\\r"); |
9307c4c1 FB |
1119 | break; |
1120 | default: | |
1121 | if (c >= 32 && c <= 126) { | |
376253ec | 1122 | monitor_printf(mon, "%c", c); |
9307c4c1 | 1123 | } else { |
376253ec | 1124 | monitor_printf(mon, "\\x%02x", c); |
9307c4c1 FB |
1125 | } |
1126 | break; | |
1127 | } | |
376253ec | 1128 | monitor_printf(mon, "'"); |
9307c4c1 FB |
1129 | } |
1130 | ||
376253ec | 1131 | static void memory_dump(Monitor *mon, int count, int format, int wsize, |
a8170e5e | 1132 | hwaddr addr, int is_physical) |
9307c4c1 | 1133 | { |
9349b4f9 | 1134 | CPUArchState *env; |
23842aab | 1135 | int l, line_size, i, max_digits, len; |
9307c4c1 FB |
1136 | uint8_t buf[16]; |
1137 | uint64_t v; | |
1138 | ||
1139 | if (format == 'i') { | |
1140 | int flags; | |
1141 | flags = 0; | |
6a00d601 | 1142 | env = mon_get_cpu(); |
9307c4c1 | 1143 | #ifdef TARGET_I386 |
4c27ba27 | 1144 | if (wsize == 2) { |
9307c4c1 | 1145 | flags = 1; |
4c27ba27 FB |
1146 | } else if (wsize == 4) { |
1147 | flags = 0; | |
1148 | } else { | |
6a15fd12 | 1149 | /* as default we use the current CS size */ |
4c27ba27 | 1150 | flags = 0; |
6a15fd12 FB |
1151 | if (env) { |
1152 | #ifdef TARGET_X86_64 | |
5fafdf24 | 1153 | if ((env->efer & MSR_EFER_LMA) && |
6a15fd12 FB |
1154 | (env->segs[R_CS].flags & DESC_L_MASK)) |
1155 | flags = 2; | |
1156 | else | |
1157 | #endif | |
1158 | if (!(env->segs[R_CS].flags & DESC_B_MASK)) | |
1159 | flags = 1; | |
1160 | } | |
4c27ba27 | 1161 | } |
1c38f843 TM |
1162 | #endif |
1163 | #ifdef TARGET_PPC | |
1164 | flags = msr_le << 16; | |
1165 | flags |= env->bfd_mach; | |
4c27ba27 | 1166 | #endif |
376253ec | 1167 | monitor_disas(mon, env, addr, count, is_physical, flags); |
9307c4c1 FB |
1168 | return; |
1169 | } | |
1170 | ||
1171 | len = wsize * count; | |
1172 | if (wsize == 1) | |
1173 | line_size = 8; | |
1174 | else | |
1175 | line_size = 16; | |
9307c4c1 FB |
1176 | max_digits = 0; |
1177 | ||
1178 | switch(format) { | |
1179 | case 'o': | |
1180 | max_digits = (wsize * 8 + 2) / 3; | |
1181 | break; | |
1182 | default: | |
1183 | case 'x': | |
1184 | max_digits = (wsize * 8) / 4; | |
1185 | break; | |
1186 | case 'u': | |
1187 | case 'd': | |
1188 | max_digits = (wsize * 8 * 10 + 32) / 33; | |
1189 | break; | |
1190 | case 'c': | |
1191 | wsize = 1; | |
1192 | break; | |
1193 | } | |
1194 | ||
1195 | while (len > 0) { | |
7743e588 | 1196 | if (is_physical) |
376253ec | 1197 | monitor_printf(mon, TARGET_FMT_plx ":", addr); |
7743e588 | 1198 | else |
376253ec | 1199 | monitor_printf(mon, TARGET_FMT_lx ":", (target_ulong)addr); |
9307c4c1 FB |
1200 | l = len; |
1201 | if (l > line_size) | |
1202 | l = line_size; | |
1203 | if (is_physical) { | |
54f7b4a3 | 1204 | cpu_physical_memory_read(addr, buf, l); |
9307c4c1 | 1205 | } else { |
6a00d601 | 1206 | env = mon_get_cpu(); |
f17ec444 | 1207 | if (cpu_memory_rw_debug(ENV_GET_CPU(env), addr, buf, l, 0) < 0) { |
376253ec | 1208 | monitor_printf(mon, " Cannot access memory\n"); |
c8f79b67 AL |
1209 | break; |
1210 | } | |
9307c4c1 | 1211 | } |
5fafdf24 | 1212 | i = 0; |
9307c4c1 FB |
1213 | while (i < l) { |
1214 | switch(wsize) { | |
1215 | default: | |
1216 | case 1: | |
24e60305 | 1217 | v = ldub_p(buf + i); |
9307c4c1 FB |
1218 | break; |
1219 | case 2: | |
24e60305 | 1220 | v = lduw_p(buf + i); |
9307c4c1 FB |
1221 | break; |
1222 | case 4: | |
24e60305 | 1223 | v = (uint32_t)ldl_p(buf + i); |
9307c4c1 FB |
1224 | break; |
1225 | case 8: | |
24e60305 | 1226 | v = ldq_p(buf + i); |
9307c4c1 FB |
1227 | break; |
1228 | } | |
376253ec | 1229 | monitor_printf(mon, " "); |
9307c4c1 FB |
1230 | switch(format) { |
1231 | case 'o': | |
376253ec | 1232 | monitor_printf(mon, "%#*" PRIo64, max_digits, v); |
9307c4c1 FB |
1233 | break; |
1234 | case 'x': | |
376253ec | 1235 | monitor_printf(mon, "0x%0*" PRIx64, max_digits, v); |
9307c4c1 FB |
1236 | break; |
1237 | case 'u': | |
376253ec | 1238 | monitor_printf(mon, "%*" PRIu64, max_digits, v); |
9307c4c1 FB |
1239 | break; |
1240 | case 'd': | |
376253ec | 1241 | monitor_printf(mon, "%*" PRId64, max_digits, v); |
9307c4c1 FB |
1242 | break; |
1243 | case 'c': | |
376253ec | 1244 | monitor_printc(mon, v); |
9307c4c1 FB |
1245 | break; |
1246 | } | |
1247 | i += wsize; | |
1248 | } | |
376253ec | 1249 | monitor_printf(mon, "\n"); |
9307c4c1 FB |
1250 | addr += l; |
1251 | len -= l; | |
1252 | } | |
1253 | } | |
1254 | ||
3e5a50d6 | 1255 | static void hmp_memory_dump(Monitor *mon, const QDict *qdict) |
9307c4c1 | 1256 | { |
1bd1442e LC |
1257 | int count = qdict_get_int(qdict, "count"); |
1258 | int format = qdict_get_int(qdict, "format"); | |
1259 | int size = qdict_get_int(qdict, "size"); | |
1260 | target_long addr = qdict_get_int(qdict, "addr"); | |
1261 | ||
376253ec | 1262 | memory_dump(mon, count, format, size, addr, 0); |
9307c4c1 FB |
1263 | } |
1264 | ||
3e5a50d6 | 1265 | static void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict) |
9307c4c1 | 1266 | { |
1bd1442e LC |
1267 | int count = qdict_get_int(qdict, "count"); |
1268 | int format = qdict_get_int(qdict, "format"); | |
1269 | int size = qdict_get_int(qdict, "size"); | |
a8170e5e | 1270 | hwaddr addr = qdict_get_int(qdict, "addr"); |
1bd1442e | 1271 | |
376253ec | 1272 | memory_dump(mon, count, format, size, addr, 1); |
9307c4c1 FB |
1273 | } |
1274 | ||
1bd1442e | 1275 | static void do_print(Monitor *mon, const QDict *qdict) |
9307c4c1 | 1276 | { |
1bd1442e | 1277 | int format = qdict_get_int(qdict, "format"); |
a8170e5e | 1278 | hwaddr val = qdict_get_int(qdict, "val"); |
1bd1442e | 1279 | |
9307c4c1 FB |
1280 | switch(format) { |
1281 | case 'o': | |
a8170e5e | 1282 | monitor_printf(mon, "%#" HWADDR_PRIo, val); |
9307c4c1 FB |
1283 | break; |
1284 | case 'x': | |
a8170e5e | 1285 | monitor_printf(mon, "%#" HWADDR_PRIx, val); |
9307c4c1 FB |
1286 | break; |
1287 | case 'u': | |
a8170e5e | 1288 | monitor_printf(mon, "%" HWADDR_PRIu, val); |
9307c4c1 FB |
1289 | break; |
1290 | default: | |
1291 | case 'd': | |
a8170e5e | 1292 | monitor_printf(mon, "%" HWADDR_PRId, val); |
9307c4c1 FB |
1293 | break; |
1294 | case 'c': | |
376253ec | 1295 | monitor_printc(mon, val); |
9307c4c1 FB |
1296 | break; |
1297 | } | |
376253ec | 1298 | monitor_printf(mon, "\n"); |
9307c4c1 FB |
1299 | } |
1300 | ||
3e5a50d6 | 1301 | static void hmp_sum(Monitor *mon, const QDict *qdict) |
e4cf1adc FB |
1302 | { |
1303 | uint32_t addr; | |
e4cf1adc | 1304 | uint16_t sum; |
f18c16de LC |
1305 | uint32_t start = qdict_get_int(qdict, "start"); |
1306 | uint32_t size = qdict_get_int(qdict, "size"); | |
e4cf1adc FB |
1307 | |
1308 | sum = 0; | |
1309 | for(addr = start; addr < (start + size); addr++) { | |
42874d3a PM |
1310 | uint8_t val = address_space_ldub(&address_space_memory, addr, |
1311 | MEMTXATTRS_UNSPECIFIED, NULL); | |
e4cf1adc FB |
1312 | /* BSD sum algorithm ('sum' Unix command) */ |
1313 | sum = (sum >> 1) | (sum << 15); | |
54f7b4a3 | 1314 | sum += val; |
e4cf1adc | 1315 | } |
376253ec | 1316 | monitor_printf(mon, "%05d\n", sum); |
e4cf1adc FB |
1317 | } |
1318 | ||
13224a87 FB |
1319 | static int mouse_button_state; |
1320 | ||
3e5a50d6 | 1321 | static void hmp_mouse_move(Monitor *mon, const QDict *qdict) |
13224a87 | 1322 | { |
c751a74a | 1323 | int dx, dy, dz, button; |
1d4daa91 LC |
1324 | const char *dx_str = qdict_get_str(qdict, "dx_str"); |
1325 | const char *dy_str = qdict_get_str(qdict, "dy_str"); | |
1326 | const char *dz_str = qdict_get_try_str(qdict, "dz_str"); | |
c751a74a | 1327 | |
13224a87 FB |
1328 | dx = strtol(dx_str, NULL, 0); |
1329 | dy = strtol(dy_str, NULL, 0); | |
c751a74a GH |
1330 | qemu_input_queue_rel(NULL, INPUT_AXIS_X, dx); |
1331 | qemu_input_queue_rel(NULL, INPUT_AXIS_Y, dy); | |
1332 | ||
1333 | if (dz_str) { | |
13224a87 | 1334 | dz = strtol(dz_str, NULL, 0); |
c751a74a GH |
1335 | if (dz != 0) { |
1336 | button = (dz > 0) ? INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN; | |
1337 | qemu_input_queue_btn(NULL, button, true); | |
1338 | qemu_input_event_sync(); | |
1339 | qemu_input_queue_btn(NULL, button, false); | |
1340 | } | |
1341 | } | |
1342 | qemu_input_event_sync(); | |
13224a87 FB |
1343 | } |
1344 | ||
3e5a50d6 | 1345 | static void hmp_mouse_button(Monitor *mon, const QDict *qdict) |
13224a87 | 1346 | { |
c751a74a GH |
1347 | static uint32_t bmap[INPUT_BUTTON_MAX] = { |
1348 | [INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON, | |
1349 | [INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON, | |
1350 | [INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON, | |
1351 | }; | |
d54908a5 | 1352 | int button_state = qdict_get_int(qdict, "button_state"); |
c751a74a GH |
1353 | |
1354 | if (mouse_button_state == button_state) { | |
1355 | return; | |
1356 | } | |
1357 | qemu_input_update_buttons(NULL, bmap, mouse_button_state, button_state); | |
1358 | qemu_input_event_sync(); | |
13224a87 | 1359 | mouse_button_state = button_state; |
13224a87 FB |
1360 | } |
1361 | ||
3e5a50d6 | 1362 | static void hmp_ioport_read(Monitor *mon, const QDict *qdict) |
3440557b | 1363 | { |
aa93e39c LC |
1364 | int size = qdict_get_int(qdict, "size"); |
1365 | int addr = qdict_get_int(qdict, "addr"); | |
1366 | int has_index = qdict_haskey(qdict, "index"); | |
3440557b FB |
1367 | uint32_t val; |
1368 | int suffix; | |
1369 | ||
1370 | if (has_index) { | |
aa93e39c | 1371 | int index = qdict_get_int(qdict, "index"); |
afcea8cb | 1372 | cpu_outb(addr & IOPORTS_MASK, index & 0xff); |
3440557b FB |
1373 | addr++; |
1374 | } | |
1375 | addr &= 0xffff; | |
1376 | ||
1377 | switch(size) { | |
1378 | default: | |
1379 | case 1: | |
afcea8cb | 1380 | val = cpu_inb(addr); |
3440557b FB |
1381 | suffix = 'b'; |
1382 | break; | |
1383 | case 2: | |
afcea8cb | 1384 | val = cpu_inw(addr); |
3440557b FB |
1385 | suffix = 'w'; |
1386 | break; | |
1387 | case 4: | |
afcea8cb | 1388 | val = cpu_inl(addr); |
3440557b FB |
1389 | suffix = 'l'; |
1390 | break; | |
1391 | } | |
376253ec AL |
1392 | monitor_printf(mon, "port%c[0x%04x] = %#0*x\n", |
1393 | suffix, addr, size * 2, val); | |
3440557b | 1394 | } |
a3a91a35 | 1395 | |
3e5a50d6 | 1396 | static void hmp_ioport_write(Monitor *mon, const QDict *qdict) |
f114784f | 1397 | { |
1bd1442e LC |
1398 | int size = qdict_get_int(qdict, "size"); |
1399 | int addr = qdict_get_int(qdict, "addr"); | |
1400 | int val = qdict_get_int(qdict, "val"); | |
1401 | ||
f114784f JK |
1402 | addr &= IOPORTS_MASK; |
1403 | ||
1404 | switch (size) { | |
1405 | default: | |
1406 | case 1: | |
afcea8cb | 1407 | cpu_outb(addr, val); |
f114784f JK |
1408 | break; |
1409 | case 2: | |
afcea8cb | 1410 | cpu_outw(addr, val); |
f114784f JK |
1411 | break; |
1412 | case 4: | |
afcea8cb | 1413 | cpu_outl(addr, val); |
f114784f JK |
1414 | break; |
1415 | } | |
1416 | } | |
1417 | ||
3e5a50d6 | 1418 | static void hmp_boot_set(Monitor *mon, const QDict *qdict) |
0ecdffbb | 1419 | { |
f1839938 | 1420 | Error *local_err = NULL; |
d54908a5 | 1421 | const char *bootdevice = qdict_get_str(qdict, "bootdevice"); |
0ecdffbb | 1422 | |
f1839938 GA |
1423 | qemu_boot_set(bootdevice, &local_err); |
1424 | if (local_err) { | |
1425 | monitor_printf(mon, "%s\n", error_get_pretty(local_err)); | |
1426 | error_free(local_err); | |
0ecdffbb | 1427 | } else { |
f1839938 | 1428 | monitor_printf(mon, "boot device list now set to %s\n", bootdevice); |
0ecdffbb AJ |
1429 | } |
1430 | } | |
1431 | ||
b86bda5b | 1432 | #if defined(TARGET_I386) |
a8170e5e AK |
1433 | static void print_pte(Monitor *mon, hwaddr addr, |
1434 | hwaddr pte, | |
1435 | hwaddr mask) | |
b86bda5b | 1436 | { |
d65aaf37 BS |
1437 | #ifdef TARGET_X86_64 |
1438 | if (addr & (1ULL << 47)) { | |
1439 | addr |= -1LL << 48; | |
1440 | } | |
1441 | #endif | |
1442 | monitor_printf(mon, TARGET_FMT_plx ": " TARGET_FMT_plx | |
1443 | " %c%c%c%c%c%c%c%c%c\n", | |
376253ec AL |
1444 | addr, |
1445 | pte & mask, | |
d65aaf37 | 1446 | pte & PG_NX_MASK ? 'X' : '-', |
376253ec AL |
1447 | pte & PG_GLOBAL_MASK ? 'G' : '-', |
1448 | pte & PG_PSE_MASK ? 'P' : '-', | |
1449 | pte & PG_DIRTY_MASK ? 'D' : '-', | |
1450 | pte & PG_ACCESSED_MASK ? 'A' : '-', | |
1451 | pte & PG_PCD_MASK ? 'C' : '-', | |
1452 | pte & PG_PWT_MASK ? 'T' : '-', | |
1453 | pte & PG_USER_MASK ? 'U' : '-', | |
1454 | pte & PG_RW_MASK ? 'W' : '-'); | |
b86bda5b FB |
1455 | } |
1456 | ||
9349b4f9 | 1457 | static void tlb_info_32(Monitor *mon, CPUArchState *env) |
b86bda5b | 1458 | { |
94ac5cd2 | 1459 | unsigned int l1, l2; |
b86bda5b FB |
1460 | uint32_t pgd, pde, pte; |
1461 | ||
b86bda5b FB |
1462 | pgd = env->cr[3] & ~0xfff; |
1463 | for(l1 = 0; l1 < 1024; l1++) { | |
b8b79323 | 1464 | cpu_physical_memory_read(pgd + l1 * 4, &pde, 4); |
b86bda5b FB |
1465 | pde = le32_to_cpu(pde); |
1466 | if (pde & PG_PRESENT_MASK) { | |
1467 | if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { | |
d65aaf37 BS |
1468 | /* 4M pages */ |
1469 | print_pte(mon, (l1 << 22), pde, ~((1 << 21) - 1)); | |
b86bda5b FB |
1470 | } else { |
1471 | for(l2 = 0; l2 < 1024; l2++) { | |
b8b79323 | 1472 | cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, &pte, 4); |
b86bda5b FB |
1473 | pte = le32_to_cpu(pte); |
1474 | if (pte & PG_PRESENT_MASK) { | |
376253ec | 1475 | print_pte(mon, (l1 << 22) + (l2 << 12), |
5fafdf24 | 1476 | pte & ~PG_PSE_MASK, |
b86bda5b FB |
1477 | ~0xfff); |
1478 | } | |
1479 | } | |
1480 | } | |
1481 | } | |
1482 | } | |
1483 | } | |
1484 | ||
9349b4f9 | 1485 | static void tlb_info_pae32(Monitor *mon, CPUArchState *env) |
d65aaf37 | 1486 | { |
94ac5cd2 | 1487 | unsigned int l1, l2, l3; |
d65aaf37 BS |
1488 | uint64_t pdpe, pde, pte; |
1489 | uint64_t pdp_addr, pd_addr, pt_addr; | |
1490 | ||
1491 | pdp_addr = env->cr[3] & ~0x1f; | |
1492 | for (l1 = 0; l1 < 4; l1++) { | |
b8b79323 | 1493 | cpu_physical_memory_read(pdp_addr + l1 * 8, &pdpe, 8); |
d65aaf37 BS |
1494 | pdpe = le64_to_cpu(pdpe); |
1495 | if (pdpe & PG_PRESENT_MASK) { | |
1496 | pd_addr = pdpe & 0x3fffffffff000ULL; | |
1497 | for (l2 = 0; l2 < 512; l2++) { | |
b8b79323 | 1498 | cpu_physical_memory_read(pd_addr + l2 * 8, &pde, 8); |
d65aaf37 BS |
1499 | pde = le64_to_cpu(pde); |
1500 | if (pde & PG_PRESENT_MASK) { | |
1501 | if (pde & PG_PSE_MASK) { | |
1502 | /* 2M pages with PAE, CR4.PSE is ignored */ | |
1503 | print_pte(mon, (l1 << 30 ) + (l2 << 21), pde, | |
a8170e5e | 1504 | ~((hwaddr)(1 << 20) - 1)); |
d65aaf37 BS |
1505 | } else { |
1506 | pt_addr = pde & 0x3fffffffff000ULL; | |
1507 | for (l3 = 0; l3 < 512; l3++) { | |
b8b79323 | 1508 | cpu_physical_memory_read(pt_addr + l3 * 8, &pte, 8); |
d65aaf37 BS |
1509 | pte = le64_to_cpu(pte); |
1510 | if (pte & PG_PRESENT_MASK) { | |
1511 | print_pte(mon, (l1 << 30 ) + (l2 << 21) | |
1512 | + (l3 << 12), | |
1513 | pte & ~PG_PSE_MASK, | |
a8170e5e | 1514 | ~(hwaddr)0xfff); |
d65aaf37 BS |
1515 | } |
1516 | } | |
1517 | } | |
1518 | } | |
1519 | } | |
1520 | } | |
1521 | } | |
1522 | } | |
1523 | ||
1524 | #ifdef TARGET_X86_64 | |
9349b4f9 | 1525 | static void tlb_info_64(Monitor *mon, CPUArchState *env) |
d65aaf37 BS |
1526 | { |
1527 | uint64_t l1, l2, l3, l4; | |
1528 | uint64_t pml4e, pdpe, pde, pte; | |
1529 | uint64_t pml4_addr, pdp_addr, pd_addr, pt_addr; | |
1530 | ||
1531 | pml4_addr = env->cr[3] & 0x3fffffffff000ULL; | |
1532 | for (l1 = 0; l1 < 512; l1++) { | |
b8b79323 | 1533 | cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8); |
d65aaf37 BS |
1534 | pml4e = le64_to_cpu(pml4e); |
1535 | if (pml4e & PG_PRESENT_MASK) { | |
1536 | pdp_addr = pml4e & 0x3fffffffff000ULL; | |
1537 | for (l2 = 0; l2 < 512; l2++) { | |
b8b79323 | 1538 | cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8); |
d65aaf37 BS |
1539 | pdpe = le64_to_cpu(pdpe); |
1540 | if (pdpe & PG_PRESENT_MASK) { | |
1541 | if (pdpe & PG_PSE_MASK) { | |
1542 | /* 1G pages, CR4.PSE is ignored */ | |
1543 | print_pte(mon, (l1 << 39) + (l2 << 30), pdpe, | |
1544 | 0x3ffffc0000000ULL); | |
1545 | } else { | |
1546 | pd_addr = pdpe & 0x3fffffffff000ULL; | |
1547 | for (l3 = 0; l3 < 512; l3++) { | |
b8b79323 | 1548 | cpu_physical_memory_read(pd_addr + l3 * 8, &pde, 8); |
d65aaf37 BS |
1549 | pde = le64_to_cpu(pde); |
1550 | if (pde & PG_PRESENT_MASK) { | |
1551 | if (pde & PG_PSE_MASK) { | |
1552 | /* 2M pages, CR4.PSE is ignored */ | |
1553 | print_pte(mon, (l1 << 39) + (l2 << 30) + | |
1554 | (l3 << 21), pde, | |
1555 | 0x3ffffffe00000ULL); | |
1556 | } else { | |
1557 | pt_addr = pde & 0x3fffffffff000ULL; | |
1558 | for (l4 = 0; l4 < 512; l4++) { | |
1559 | cpu_physical_memory_read(pt_addr | |
1560 | + l4 * 8, | |
b8b79323 | 1561 | &pte, 8); |
d65aaf37 BS |
1562 | pte = le64_to_cpu(pte); |
1563 | if (pte & PG_PRESENT_MASK) { | |
1564 | print_pte(mon, (l1 << 39) + | |
1565 | (l2 << 30) + | |
1566 | (l3 << 21) + (l4 << 12), | |
1567 | pte & ~PG_PSE_MASK, | |
1568 | 0x3fffffffff000ULL); | |
1569 | } | |
1570 | } | |
1571 | } | |
1572 | } | |
1573 | } | |
1574 | } | |
1575 | } | |
1576 | } | |
1577 | } | |
1578 | } | |
1579 | } | |
1580 | #endif | |
1581 | ||
1ce6be24 | 1582 | static void hmp_info_tlb(Monitor *mon, const QDict *qdict) |
d65aaf37 | 1583 | { |
9349b4f9 | 1584 | CPUArchState *env; |
d65aaf37 BS |
1585 | |
1586 | env = mon_get_cpu(); | |
1587 | ||
1588 | if (!(env->cr[0] & CR0_PG_MASK)) { | |
1589 | monitor_printf(mon, "PG disabled\n"); | |
1590 | return; | |
1591 | } | |
1592 | if (env->cr[4] & CR4_PAE_MASK) { | |
1593 | #ifdef TARGET_X86_64 | |
1594 | if (env->hflags & HF_LMA_MASK) { | |
1595 | tlb_info_64(mon, env); | |
1596 | } else | |
1597 | #endif | |
1598 | { | |
1599 | tlb_info_pae32(mon, env); | |
1600 | } | |
1601 | } else { | |
1602 | tlb_info_32(mon, env); | |
1603 | } | |
1604 | } | |
1605 | ||
a8170e5e | 1606 | static void mem_print(Monitor *mon, hwaddr *pstart, |
1b3cba6e | 1607 | int *plast_prot, |
a8170e5e | 1608 | hwaddr end, int prot) |
b86bda5b | 1609 | { |
9746b15b FB |
1610 | int prot1; |
1611 | prot1 = *plast_prot; | |
1612 | if (prot != prot1) { | |
b86bda5b | 1613 | if (*pstart != -1) { |
1b3cba6e BS |
1614 | monitor_printf(mon, TARGET_FMT_plx "-" TARGET_FMT_plx " " |
1615 | TARGET_FMT_plx " %c%c%c\n", | |
376253ec AL |
1616 | *pstart, end, end - *pstart, |
1617 | prot1 & PG_USER_MASK ? 'u' : '-', | |
1618 | 'r', | |
1619 | prot1 & PG_RW_MASK ? 'w' : '-'); | |
b86bda5b FB |
1620 | } |
1621 | if (prot != 0) | |
1622 | *pstart = end; | |
1623 | else | |
1624 | *pstart = -1; | |
1625 | *plast_prot = prot; | |
1626 | } | |
1627 | } | |
1628 | ||
9349b4f9 | 1629 | static void mem_info_32(Monitor *mon, CPUArchState *env) |
b86bda5b | 1630 | { |
b49ca72d AC |
1631 | unsigned int l1, l2; |
1632 | int prot, last_prot; | |
1b3cba6e | 1633 | uint32_t pgd, pde, pte; |
a8170e5e | 1634 | hwaddr start, end; |
6a00d601 | 1635 | |
b86bda5b FB |
1636 | pgd = env->cr[3] & ~0xfff; |
1637 | last_prot = 0; | |
1638 | start = -1; | |
1639 | for(l1 = 0; l1 < 1024; l1++) { | |
b8b79323 | 1640 | cpu_physical_memory_read(pgd + l1 * 4, &pde, 4); |
b86bda5b FB |
1641 | pde = le32_to_cpu(pde); |
1642 | end = l1 << 22; | |
1643 | if (pde & PG_PRESENT_MASK) { | |
1644 | if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { | |
1645 | prot = pde & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK); | |
376253ec | 1646 | mem_print(mon, &start, &last_prot, end, prot); |
b86bda5b FB |
1647 | } else { |
1648 | for(l2 = 0; l2 < 1024; l2++) { | |
b8b79323 | 1649 | cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, &pte, 4); |
b86bda5b FB |
1650 | pte = le32_to_cpu(pte); |
1651 | end = (l1 << 22) + (l2 << 12); | |
1652 | if (pte & PG_PRESENT_MASK) { | |
c76c8416 AC |
1653 | prot = pte & pde & |
1654 | (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK); | |
b86bda5b FB |
1655 | } else { |
1656 | prot = 0; | |
1657 | } | |
376253ec | 1658 | mem_print(mon, &start, &last_prot, end, prot); |
b86bda5b FB |
1659 | } |
1660 | } | |
1661 | } else { | |
1662 | prot = 0; | |
376253ec | 1663 | mem_print(mon, &start, &last_prot, end, prot); |
b86bda5b FB |
1664 | } |
1665 | } | |
8a94b8ca | 1666 | /* Flush last range */ |
a8170e5e | 1667 | mem_print(mon, &start, &last_prot, (hwaddr)1 << 32, 0); |
b86bda5b | 1668 | } |
1b3cba6e | 1669 | |
9349b4f9 | 1670 | static void mem_info_pae32(Monitor *mon, CPUArchState *env) |
1b3cba6e | 1671 | { |
b49ca72d AC |
1672 | unsigned int l1, l2, l3; |
1673 | int prot, last_prot; | |
1b3cba6e BS |
1674 | uint64_t pdpe, pde, pte; |
1675 | uint64_t pdp_addr, pd_addr, pt_addr; | |
a8170e5e | 1676 | hwaddr start, end; |
1b3cba6e BS |
1677 | |
1678 | pdp_addr = env->cr[3] & ~0x1f; | |
1679 | last_prot = 0; | |
1680 | start = -1; | |
1681 | for (l1 = 0; l1 < 4; l1++) { | |
b8b79323 | 1682 | cpu_physical_memory_read(pdp_addr + l1 * 8, &pdpe, 8); |
1b3cba6e BS |
1683 | pdpe = le64_to_cpu(pdpe); |
1684 | end = l1 << 30; | |
1685 | if (pdpe & PG_PRESENT_MASK) { | |
1686 | pd_addr = pdpe & 0x3fffffffff000ULL; | |
1687 | for (l2 = 0; l2 < 512; l2++) { | |
b8b79323 | 1688 | cpu_physical_memory_read(pd_addr + l2 * 8, &pde, 8); |
1b3cba6e BS |
1689 | pde = le64_to_cpu(pde); |
1690 | end = (l1 << 30) + (l2 << 21); | |
1691 | if (pde & PG_PRESENT_MASK) { | |
1692 | if (pde & PG_PSE_MASK) { | |
1693 | prot = pde & (PG_USER_MASK | PG_RW_MASK | | |
1694 | PG_PRESENT_MASK); | |
1695 | mem_print(mon, &start, &last_prot, end, prot); | |
1696 | } else { | |
1697 | pt_addr = pde & 0x3fffffffff000ULL; | |
1698 | for (l3 = 0; l3 < 512; l3++) { | |
b8b79323 | 1699 | cpu_physical_memory_read(pt_addr + l3 * 8, &pte, 8); |
1b3cba6e BS |
1700 | pte = le64_to_cpu(pte); |
1701 | end = (l1 << 30) + (l2 << 21) + (l3 << 12); | |
1702 | if (pte & PG_PRESENT_MASK) { | |
c76c8416 AC |
1703 | prot = pte & pde & (PG_USER_MASK | PG_RW_MASK | |
1704 | PG_PRESENT_MASK); | |
1b3cba6e BS |
1705 | } else { |
1706 | prot = 0; | |
1707 | } | |
1708 | mem_print(mon, &start, &last_prot, end, prot); | |
1709 | } | |
1710 | } | |
1711 | } else { | |
1712 | prot = 0; | |
1713 | mem_print(mon, &start, &last_prot, end, prot); | |
1714 | } | |
1715 | } | |
1716 | } else { | |
1717 | prot = 0; | |
1718 | mem_print(mon, &start, &last_prot, end, prot); | |
1719 | } | |
1720 | } | |
8a94b8ca | 1721 | /* Flush last range */ |
a8170e5e | 1722 | mem_print(mon, &start, &last_prot, (hwaddr)1 << 32, 0); |
1b3cba6e BS |
1723 | } |
1724 | ||
1725 | ||
1726 | #ifdef TARGET_X86_64 | |
9349b4f9 | 1727 | static void mem_info_64(Monitor *mon, CPUArchState *env) |
1b3cba6e BS |
1728 | { |
1729 | int prot, last_prot; | |
1730 | uint64_t l1, l2, l3, l4; | |
1731 | uint64_t pml4e, pdpe, pde, pte; | |
1732 | uint64_t pml4_addr, pdp_addr, pd_addr, pt_addr, start, end; | |
1733 | ||
1734 | pml4_addr = env->cr[3] & 0x3fffffffff000ULL; | |
1735 | last_prot = 0; | |
1736 | start = -1; | |
1737 | for (l1 = 0; l1 < 512; l1++) { | |
b8b79323 | 1738 | cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8); |
1b3cba6e BS |
1739 | pml4e = le64_to_cpu(pml4e); |
1740 | end = l1 << 39; | |
1741 | if (pml4e & PG_PRESENT_MASK) { | |
1742 | pdp_addr = pml4e & 0x3fffffffff000ULL; | |
1743 | for (l2 = 0; l2 < 512; l2++) { | |
b8b79323 | 1744 | cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8); |
1b3cba6e BS |
1745 | pdpe = le64_to_cpu(pdpe); |
1746 | end = (l1 << 39) + (l2 << 30); | |
1747 | if (pdpe & PG_PRESENT_MASK) { | |
1748 | if (pdpe & PG_PSE_MASK) { | |
2d5b5074 BS |
1749 | prot = pdpe & (PG_USER_MASK | PG_RW_MASK | |
1750 | PG_PRESENT_MASK); | |
c76c8416 | 1751 | prot &= pml4e; |
1b3cba6e BS |
1752 | mem_print(mon, &start, &last_prot, end, prot); |
1753 | } else { | |
1754 | pd_addr = pdpe & 0x3fffffffff000ULL; | |
1755 | for (l3 = 0; l3 < 512; l3++) { | |
b8b79323 | 1756 | cpu_physical_memory_read(pd_addr + l3 * 8, &pde, 8); |
1b3cba6e BS |
1757 | pde = le64_to_cpu(pde); |
1758 | end = (l1 << 39) + (l2 << 30) + (l3 << 21); | |
1759 | if (pde & PG_PRESENT_MASK) { | |
1760 | if (pde & PG_PSE_MASK) { | |
1761 | prot = pde & (PG_USER_MASK | PG_RW_MASK | | |
1762 | PG_PRESENT_MASK); | |
c76c8416 | 1763 | prot &= pml4e & pdpe; |
1b3cba6e BS |
1764 | mem_print(mon, &start, &last_prot, end, prot); |
1765 | } else { | |
1766 | pt_addr = pde & 0x3fffffffff000ULL; | |
1767 | for (l4 = 0; l4 < 512; l4++) { | |
1768 | cpu_physical_memory_read(pt_addr | |
1769 | + l4 * 8, | |
b8b79323 | 1770 | &pte, 8); |
1b3cba6e BS |
1771 | pte = le64_to_cpu(pte); |
1772 | end = (l1 << 39) + (l2 << 30) + | |
1773 | (l3 << 21) + (l4 << 12); | |
1774 | if (pte & PG_PRESENT_MASK) { | |
1775 | prot = pte & (PG_USER_MASK | PG_RW_MASK | | |
1776 | PG_PRESENT_MASK); | |
c76c8416 | 1777 | prot &= pml4e & pdpe & pde; |
1b3cba6e BS |
1778 | } else { |
1779 | prot = 0; | |
1780 | } | |
1781 | mem_print(mon, &start, &last_prot, end, prot); | |
1782 | } | |
1783 | } | |
1784 | } else { | |
1785 | prot = 0; | |
1786 | mem_print(mon, &start, &last_prot, end, prot); | |
1787 | } | |
1788 | } | |
1789 | } | |
1790 | } else { | |
1791 | prot = 0; | |
1792 | mem_print(mon, &start, &last_prot, end, prot); | |
1793 | } | |
1794 | } | |
1795 | } else { | |
1796 | prot = 0; | |
1797 | mem_print(mon, &start, &last_prot, end, prot); | |
1798 | } | |
1799 | } | |
8a94b8ca | 1800 | /* Flush last range */ |
a8170e5e | 1801 | mem_print(mon, &start, &last_prot, (hwaddr)1 << 48, 0); |
1b3cba6e BS |
1802 | } |
1803 | #endif | |
1804 | ||
1ce6be24 | 1805 | static void hmp_info_mem(Monitor *mon, const QDict *qdict) |
1b3cba6e | 1806 | { |
9349b4f9 | 1807 | CPUArchState *env; |
1b3cba6e BS |
1808 | |
1809 | env = mon_get_cpu(); | |
1810 | ||
1811 | if (!(env->cr[0] & CR0_PG_MASK)) { | |
1812 | monitor_printf(mon, "PG disabled\n"); | |
1813 | return; | |
1814 | } | |
1815 | if (env->cr[4] & CR4_PAE_MASK) { | |
1816 | #ifdef TARGET_X86_64 | |
1817 | if (env->hflags & HF_LMA_MASK) { | |
1818 | mem_info_64(mon, env); | |
1819 | } else | |
1820 | #endif | |
1821 | { | |
1822 | mem_info_pae32(mon, env); | |
1823 | } | |
1824 | } else { | |
1825 | mem_info_32(mon, env); | |
1826 | } | |
1827 | } | |
b86bda5b FB |
1828 | #endif |
1829 | ||
7c664e2f AJ |
1830 | #if defined(TARGET_SH4) |
1831 | ||
376253ec | 1832 | static void print_tlb(Monitor *mon, int idx, tlb_t *tlb) |
7c664e2f | 1833 | { |
376253ec AL |
1834 | monitor_printf(mon, " tlb%i:\t" |
1835 | "asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t" | |
1836 | "v=%hhu shared=%hhu cached=%hhu prot=%hhu " | |
1837 | "dirty=%hhu writethrough=%hhu\n", | |
1838 | idx, | |
1839 | tlb->asid, tlb->vpn, tlb->ppn, tlb->sz, tlb->size, | |
1840 | tlb->v, tlb->sh, tlb->c, tlb->pr, | |
1841 | tlb->d, tlb->wt); | |
7c664e2f AJ |
1842 | } |
1843 | ||
1ce6be24 | 1844 | static void hmp_info_tlb(Monitor *mon, const QDict *qdict) |
7c664e2f | 1845 | { |
9349b4f9 | 1846 | CPUArchState *env = mon_get_cpu(); |
7c664e2f AJ |
1847 | int i; |
1848 | ||
376253ec | 1849 | monitor_printf (mon, "ITLB:\n"); |
7c664e2f | 1850 | for (i = 0 ; i < ITLB_SIZE ; i++) |
376253ec AL |
1851 | print_tlb (mon, i, &env->itlb[i]); |
1852 | monitor_printf (mon, "UTLB:\n"); | |
7c664e2f | 1853 | for (i = 0 ; i < UTLB_SIZE ; i++) |
376253ec | 1854 | print_tlb (mon, i, &env->utlb[i]); |
7c664e2f AJ |
1855 | } |
1856 | ||
1857 | #endif | |
1858 | ||
692f737c | 1859 | #if defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_XTENSA) |
1ce6be24 | 1860 | static void hmp_info_tlb(Monitor *mon, const QDict *qdict) |
d41160a3 | 1861 | { |
9349b4f9 | 1862 | CPUArchState *env1 = mon_get_cpu(); |
d41160a3 BS |
1863 | |
1864 | dump_mmu((FILE*)mon, (fprintf_function)monitor_printf, env1); | |
1865 | } | |
1866 | #endif | |
1867 | ||
1ce6be24 | 1868 | static void hmp_info_mtree(Monitor *mon, const QDict *qdict) |
314e2987 BS |
1869 | { |
1870 | mtree_info((fprintf_function)monitor_printf, mon); | |
1871 | } | |
1872 | ||
1ce6be24 | 1873 | static void hmp_info_numa(Monitor *mon, const QDict *qdict) |
030ea37b | 1874 | { |
b28b6230 | 1875 | int i; |
1b1ed8dc | 1876 | CPUState *cpu; |
5b009e40 | 1877 | uint64_t *node_mem; |
030ea37b | 1878 | |
5b009e40 HZ |
1879 | node_mem = g_new0(uint64_t, nb_numa_nodes); |
1880 | query_numa_node_mem(node_mem); | |
030ea37b AL |
1881 | monitor_printf(mon, "%d nodes\n", nb_numa_nodes); |
1882 | for (i = 0; i < nb_numa_nodes; i++) { | |
1883 | monitor_printf(mon, "node %d cpus:", i); | |
bdc44640 | 1884 | CPU_FOREACH(cpu) { |
1b1ed8dc | 1885 | if (cpu->numa_node == i) { |
55e5c285 | 1886 | monitor_printf(mon, " %d", cpu->cpu_index); |
030ea37b AL |
1887 | } |
1888 | } | |
1889 | monitor_printf(mon, "\n"); | |
1890 | monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i, | |
5b009e40 | 1891 | node_mem[i] >> 20); |
030ea37b | 1892 | } |
5b009e40 | 1893 | g_free(node_mem); |
030ea37b AL |
1894 | } |
1895 | ||
5f1ce948 FB |
1896 | #ifdef CONFIG_PROFILER |
1897 | ||
89d5cbdd | 1898 | int64_t tcg_time; |
e9a6625e AJ |
1899 | int64_t dev_time; |
1900 | ||
1ce6be24 | 1901 | static void hmp_info_profile(Monitor *mon, const QDict *qdict) |
5f1ce948 | 1902 | { |
376253ec | 1903 | monitor_printf(mon, "async time %" PRId64 " (%0.3f)\n", |
6ee093c9 | 1904 | dev_time, dev_time / (double)get_ticks_per_sec()); |
376253ec | 1905 | monitor_printf(mon, "qemu time %" PRId64 " (%0.3f)\n", |
89d5cbdd AK |
1906 | tcg_time, tcg_time / (double)get_ticks_per_sec()); |
1907 | tcg_time = 0; | |
5f1ce948 | 1908 | dev_time = 0; |
5f1ce948 FB |
1909 | } |
1910 | #else | |
1ce6be24 | 1911 | static void hmp_info_profile(Monitor *mon, const QDict *qdict) |
5f1ce948 | 1912 | { |
376253ec | 1913 | monitor_printf(mon, "Internal profiler not compiled\n"); |
5f1ce948 FB |
1914 | } |
1915 | #endif | |
1916 | ||
ec36b695 | 1917 | /* Capture support */ |
72cf2d4f | 1918 | static QLIST_HEAD (capture_list_head, CaptureState) capture_head; |
ec36b695 | 1919 | |
1ce6be24 | 1920 | static void hmp_info_capture(Monitor *mon, const QDict *qdict) |
ec36b695 FB |
1921 | { |
1922 | int i; | |
1923 | CaptureState *s; | |
1924 | ||
1925 | for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) { | |
376253ec | 1926 | monitor_printf(mon, "[%d]: ", i); |
ec36b695 FB |
1927 | s->ops.info (s->opaque); |
1928 | } | |
1929 | } | |
1930 | ||
3e5a50d6 | 1931 | static void hmp_stopcapture(Monitor *mon, const QDict *qdict) |
ec36b695 FB |
1932 | { |
1933 | int i; | |
d54908a5 | 1934 | int n = qdict_get_int(qdict, "n"); |
ec36b695 FB |
1935 | CaptureState *s; |
1936 | ||
1937 | for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) { | |
1938 | if (i == n) { | |
1939 | s->ops.destroy (s->opaque); | |
72cf2d4f | 1940 | QLIST_REMOVE (s, entries); |
7267c094 | 1941 | g_free (s); |
ec36b695 FB |
1942 | return; |
1943 | } | |
1944 | } | |
1945 | } | |
1946 | ||
3e5a50d6 | 1947 | static void hmp_wavcapture(Monitor *mon, const QDict *qdict) |
c1925484 LC |
1948 | { |
1949 | const char *path = qdict_get_str(qdict, "path"); | |
1950 | int has_freq = qdict_haskey(qdict, "freq"); | |
1951 | int freq = qdict_get_try_int(qdict, "freq", -1); | |
1952 | int has_bits = qdict_haskey(qdict, "bits"); | |
1953 | int bits = qdict_get_try_int(qdict, "bits", -1); | |
1954 | int has_channels = qdict_haskey(qdict, "nchannels"); | |
1955 | int nchannels = qdict_get_try_int(qdict, "nchannels", -1); | |
ec36b695 FB |
1956 | CaptureState *s; |
1957 | ||
7267c094 | 1958 | s = g_malloc0 (sizeof (*s)); |
ec36b695 FB |
1959 | |
1960 | freq = has_freq ? freq : 44100; | |
1961 | bits = has_bits ? bits : 16; | |
1962 | nchannels = has_channels ? nchannels : 2; | |
1963 | ||
1964 | if (wav_start_capture (s, path, freq, bits, nchannels)) { | |
d00b2618 | 1965 | monitor_printf(mon, "Failed to add wave capture\n"); |
7267c094 | 1966 | g_free (s); |
d00b2618 | 1967 | return; |
ec36b695 | 1968 | } |
72cf2d4f | 1969 | QLIST_INSERT_HEAD (&capture_head, s, entries); |
ec36b695 | 1970 | } |
ec36b695 | 1971 | |
15dfcd45 | 1972 | static qemu_acl *find_acl(Monitor *mon, const char *name) |
76655d6d | 1973 | { |
15dfcd45 | 1974 | qemu_acl *acl = qemu_acl_find(name); |
76655d6d | 1975 | |
76655d6d | 1976 | if (!acl) { |
15dfcd45 | 1977 | monitor_printf(mon, "acl: unknown list '%s'\n", name); |
76655d6d | 1978 | } |
15dfcd45 JK |
1979 | return acl; |
1980 | } | |
1981 | ||
3e5a50d6 | 1982 | static void hmp_acl_show(Monitor *mon, const QDict *qdict) |
15dfcd45 | 1983 | { |
d54908a5 | 1984 | const char *aclname = qdict_get_str(qdict, "aclname"); |
15dfcd45 JK |
1985 | qemu_acl *acl = find_acl(mon, aclname); |
1986 | qemu_acl_entry *entry; | |
1987 | int i = 0; | |
76655d6d | 1988 | |
15dfcd45 | 1989 | if (acl) { |
28a76be8 | 1990 | monitor_printf(mon, "policy: %s\n", |
76655d6d | 1991 | acl->defaultDeny ? "deny" : "allow"); |
72cf2d4f | 1992 | QTAILQ_FOREACH(entry, &acl->entries, next) { |
28a76be8 AL |
1993 | i++; |
1994 | monitor_printf(mon, "%d: %s %s\n", i, | |
15dfcd45 | 1995 | entry->deny ? "deny" : "allow", entry->match); |
28a76be8 | 1996 | } |
15dfcd45 JK |
1997 | } |
1998 | } | |
1999 | ||
3e5a50d6 | 2000 | static void hmp_acl_reset(Monitor *mon, const QDict *qdict) |
15dfcd45 | 2001 | { |
d54908a5 | 2002 | const char *aclname = qdict_get_str(qdict, "aclname"); |
15dfcd45 JK |
2003 | qemu_acl *acl = find_acl(mon, aclname); |
2004 | ||
2005 | if (acl) { | |
28a76be8 AL |
2006 | qemu_acl_reset(acl); |
2007 | monitor_printf(mon, "acl: removed all rules\n"); | |
15dfcd45 JK |
2008 | } |
2009 | } | |
2010 | ||
3e5a50d6 | 2011 | static void hmp_acl_policy(Monitor *mon, const QDict *qdict) |
15dfcd45 | 2012 | { |
f18c16de LC |
2013 | const char *aclname = qdict_get_str(qdict, "aclname"); |
2014 | const char *policy = qdict_get_str(qdict, "policy"); | |
15dfcd45 | 2015 | qemu_acl *acl = find_acl(mon, aclname); |
28a76be8 | 2016 | |
15dfcd45 JK |
2017 | if (acl) { |
2018 | if (strcmp(policy, "allow") == 0) { | |
28a76be8 AL |
2019 | acl->defaultDeny = 0; |
2020 | monitor_printf(mon, "acl: policy set to 'allow'\n"); | |
15dfcd45 | 2021 | } else if (strcmp(policy, "deny") == 0) { |
28a76be8 AL |
2022 | acl->defaultDeny = 1; |
2023 | monitor_printf(mon, "acl: policy set to 'deny'\n"); | |
2024 | } else { | |
15dfcd45 JK |
2025 | monitor_printf(mon, "acl: unknown policy '%s', " |
2026 | "expected 'deny' or 'allow'\n", policy); | |
28a76be8 | 2027 | } |
15dfcd45 JK |
2028 | } |
2029 | } | |
28a76be8 | 2030 | |
3e5a50d6 | 2031 | static void hmp_acl_add(Monitor *mon, const QDict *qdict) |
15dfcd45 | 2032 | { |
1bd1442e LC |
2033 | const char *aclname = qdict_get_str(qdict, "aclname"); |
2034 | const char *match = qdict_get_str(qdict, "match"); | |
2035 | const char *policy = qdict_get_str(qdict, "policy"); | |
2036 | int has_index = qdict_haskey(qdict, "index"); | |
2037 | int index = qdict_get_try_int(qdict, "index", -1); | |
15dfcd45 JK |
2038 | qemu_acl *acl = find_acl(mon, aclname); |
2039 | int deny, ret; | |
2040 | ||
2041 | if (acl) { | |
2042 | if (strcmp(policy, "allow") == 0) { | |
2043 | deny = 0; | |
2044 | } else if (strcmp(policy, "deny") == 0) { | |
2045 | deny = 1; | |
2046 | } else { | |
2047 | monitor_printf(mon, "acl: unknown policy '%s', " | |
2048 | "expected 'deny' or 'allow'\n", policy); | |
28a76be8 AL |
2049 | return; |
2050 | } | |
28a76be8 AL |
2051 | if (has_index) |
2052 | ret = qemu_acl_insert(acl, deny, match, index); | |
2053 | else | |
2054 | ret = qemu_acl_append(acl, deny, match); | |
2055 | if (ret < 0) | |
2056 | monitor_printf(mon, "acl: unable to add acl entry\n"); | |
2057 | else | |
2058 | monitor_printf(mon, "acl: added rule at position %d\n", ret); | |
15dfcd45 JK |
2059 | } |
2060 | } | |
28a76be8 | 2061 | |
3e5a50d6 | 2062 | static void hmp_acl_remove(Monitor *mon, const QDict *qdict) |
15dfcd45 | 2063 | { |
f18c16de LC |
2064 | const char *aclname = qdict_get_str(qdict, "aclname"); |
2065 | const char *match = qdict_get_str(qdict, "match"); | |
15dfcd45 JK |
2066 | qemu_acl *acl = find_acl(mon, aclname); |
2067 | int ret; | |
28a76be8 | 2068 | |
15dfcd45 | 2069 | if (acl) { |
28a76be8 AL |
2070 | ret = qemu_acl_remove(acl, match); |
2071 | if (ret < 0) | |
2072 | monitor_printf(mon, "acl: no matching acl entry\n"); | |
2073 | else | |
2074 | monitor_printf(mon, "acl: removed rule at position %d\n", ret); | |
76655d6d AL |
2075 | } |
2076 | } | |
2077 | ||
79c4f6b0 | 2078 | #if defined(TARGET_I386) |
3e5a50d6 | 2079 | static void hmp_mce(Monitor *mon, const QDict *qdict) |
79c4f6b0 | 2080 | { |
8c5cf3b6 | 2081 | X86CPU *cpu; |
55e5c285 | 2082 | CPUState *cs; |
37b7ad48 LC |
2083 | int cpu_index = qdict_get_int(qdict, "cpu_index"); |
2084 | int bank = qdict_get_int(qdict, "bank"); | |
2085 | uint64_t status = qdict_get_int(qdict, "status"); | |
2086 | uint64_t mcg_status = qdict_get_int(qdict, "mcg_status"); | |
2087 | uint64_t addr = qdict_get_int(qdict, "addr"); | |
2088 | uint64_t misc = qdict_get_int(qdict, "misc"); | |
747461c7 | 2089 | int flags = MCE_INJECT_UNCOND_AO; |
79c4f6b0 | 2090 | |
34acbc95 | 2091 | if (qdict_get_try_bool(qdict, "broadcast", false)) { |
747461c7 JK |
2092 | flags |= MCE_INJECT_BROADCAST; |
2093 | } | |
c51a944b AF |
2094 | cs = qemu_get_cpu(cpu_index); |
2095 | if (cs != NULL) { | |
2096 | cpu = X86_CPU(cs); | |
2097 | cpu_x86_inject_mce(mon, cpu, bank, status, mcg_status, addr, misc, | |
2098 | flags); | |
31ce5e0c | 2099 | } |
79c4f6b0 HY |
2100 | } |
2101 | #endif | |
2102 | ||
208c9d1b | 2103 | void qmp_getfd(const char *fdname, Error **errp) |
f07918fd | 2104 | { |
c227f099 | 2105 | mon_fd_t *monfd; |
f07918fd MM |
2106 | int fd; |
2107 | ||
208c9d1b | 2108 | fd = qemu_chr_fe_get_msgfd(cur_mon->chr); |
f07918fd | 2109 | if (fd == -1) { |
208c9d1b CB |
2110 | error_set(errp, QERR_FD_NOT_SUPPLIED); |
2111 | return; | |
f07918fd MM |
2112 | } |
2113 | ||
2114 | if (qemu_isdigit(fdname[0])) { | |
0b9f0e2f | 2115 | close(fd); |
208c9d1b CB |
2116 | error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdname", |
2117 | "a name not starting with a digit"); | |
2118 | return; | |
f07918fd MM |
2119 | } |
2120 | ||
208c9d1b | 2121 | QLIST_FOREACH(monfd, &cur_mon->fds, next) { |
f07918fd MM |
2122 | if (strcmp(monfd->name, fdname) != 0) { |
2123 | continue; | |
2124 | } | |
2125 | ||
2126 | close(monfd->fd); | |
2127 | monfd->fd = fd; | |
208c9d1b | 2128 | return; |
f07918fd MM |
2129 | } |
2130 | ||
7267c094 AL |
2131 | monfd = g_malloc0(sizeof(mon_fd_t)); |
2132 | monfd->name = g_strdup(fdname); | |
f07918fd MM |
2133 | monfd->fd = fd; |
2134 | ||
208c9d1b | 2135 | QLIST_INSERT_HEAD(&cur_mon->fds, monfd, next); |
f07918fd MM |
2136 | } |
2137 | ||
208c9d1b | 2138 | void qmp_closefd(const char *fdname, Error **errp) |
f07918fd | 2139 | { |
c227f099 | 2140 | mon_fd_t *monfd; |
f07918fd | 2141 | |
208c9d1b | 2142 | QLIST_FOREACH(monfd, &cur_mon->fds, next) { |
f07918fd MM |
2143 | if (strcmp(monfd->name, fdname) != 0) { |
2144 | continue; | |
2145 | } | |
2146 | ||
72cf2d4f | 2147 | QLIST_REMOVE(monfd, next); |
f07918fd | 2148 | close(monfd->fd); |
7267c094 AL |
2149 | g_free(monfd->name); |
2150 | g_free(monfd); | |
208c9d1b | 2151 | return; |
f07918fd MM |
2152 | } |
2153 | ||
208c9d1b | 2154 | error_set(errp, QERR_FD_NOT_FOUND, fdname); |
f07918fd MM |
2155 | } |
2156 | ||
3e5a50d6 | 2157 | static void hmp_loadvm(Monitor *mon, const QDict *qdict) |
c8d41b2c | 2158 | { |
1354869c | 2159 | int saved_vm_running = runstate_is_running(); |
d54908a5 | 2160 | const char *name = qdict_get_str(qdict, "name"); |
c8d41b2c | 2161 | |
0461d5a6 | 2162 | vm_stop(RUN_STATE_RESTORE_VM); |
c8d41b2c | 2163 | |
f0aa7a8b | 2164 | if (load_vmstate(name) == 0 && saved_vm_running) { |
c8d41b2c | 2165 | vm_start(); |
f0aa7a8b | 2166 | } |
c8d41b2c JQ |
2167 | } |
2168 | ||
a9940fc4 | 2169 | int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp) |
7768e04c | 2170 | { |
c227f099 | 2171 | mon_fd_t *monfd; |
7768e04c | 2172 | |
72cf2d4f | 2173 | QLIST_FOREACH(monfd, &mon->fds, next) { |
7768e04c MM |
2174 | int fd; |
2175 | ||
2176 | if (strcmp(monfd->name, fdname) != 0) { | |
2177 | continue; | |
2178 | } | |
2179 | ||
2180 | fd = monfd->fd; | |
2181 | ||
2182 | /* caller takes ownership of fd */ | |
72cf2d4f | 2183 | QLIST_REMOVE(monfd, next); |
7267c094 AL |
2184 | g_free(monfd->name); |
2185 | g_free(monfd); | |
7768e04c MM |
2186 | |
2187 | return fd; | |
2188 | } | |
2189 | ||
a9940fc4 | 2190 | error_setg(errp, "File descriptor named '%s' has not been found", fdname); |
7768e04c MM |
2191 | return -1; |
2192 | } | |
2193 | ||
ba1c048a CB |
2194 | static void monitor_fdset_cleanup(MonFdset *mon_fdset) |
2195 | { | |
2196 | MonFdsetFd *mon_fdset_fd; | |
2197 | MonFdsetFd *mon_fdset_fd_next; | |
2198 | ||
2199 | QLIST_FOREACH_SAFE(mon_fdset_fd, &mon_fdset->fds, next, mon_fdset_fd_next) { | |
ebe52b59 CB |
2200 | if ((mon_fdset_fd->removed || |
2201 | (QLIST_EMPTY(&mon_fdset->dup_fds) && mon_refcount == 0)) && | |
2202 | runstate_is_running()) { | |
ba1c048a CB |
2203 | close(mon_fdset_fd->fd); |
2204 | g_free(mon_fdset_fd->opaque); | |
2205 | QLIST_REMOVE(mon_fdset_fd, next); | |
2206 | g_free(mon_fdset_fd); | |
2207 | } | |
2208 | } | |
2209 | ||
adb696f3 | 2210 | if (QLIST_EMPTY(&mon_fdset->fds) && QLIST_EMPTY(&mon_fdset->dup_fds)) { |
ba1c048a CB |
2211 | QLIST_REMOVE(mon_fdset, next); |
2212 | g_free(mon_fdset); | |
2213 | } | |
2214 | } | |
2215 | ||
efb87c16 CB |
2216 | static void monitor_fdsets_cleanup(void) |
2217 | { | |
2218 | MonFdset *mon_fdset; | |
2219 | MonFdset *mon_fdset_next; | |
2220 | ||
2221 | QLIST_FOREACH_SAFE(mon_fdset, &mon_fdsets, next, mon_fdset_next) { | |
2222 | monitor_fdset_cleanup(mon_fdset); | |
2223 | } | |
2224 | } | |
2225 | ||
ba1c048a CB |
2226 | AddfdInfo *qmp_add_fd(bool has_fdset_id, int64_t fdset_id, bool has_opaque, |
2227 | const char *opaque, Error **errp) | |
2228 | { | |
2229 | int fd; | |
2230 | Monitor *mon = cur_mon; | |
ba1c048a CB |
2231 | AddfdInfo *fdinfo; |
2232 | ||
2233 | fd = qemu_chr_fe_get_msgfd(mon->chr); | |
2234 | if (fd == -1) { | |
2235 | error_set(errp, QERR_FD_NOT_SUPPLIED); | |
2236 | goto error; | |
2237 | } | |
2238 | ||
e446f70d CB |
2239 | fdinfo = monitor_fdset_add_fd(fd, has_fdset_id, fdset_id, |
2240 | has_opaque, opaque, errp); | |
2241 | if (fdinfo) { | |
2242 | return fdinfo; | |
ba1c048a | 2243 | } |
ba1c048a CB |
2244 | |
2245 | error: | |
2246 | if (fd != -1) { | |
2247 | close(fd); | |
2248 | } | |
2249 | return NULL; | |
2250 | } | |
2251 | ||
2252 | void qmp_remove_fd(int64_t fdset_id, bool has_fd, int64_t fd, Error **errp) | |
2253 | { | |
2254 | MonFdset *mon_fdset; | |
2255 | MonFdsetFd *mon_fdset_fd; | |
2256 | char fd_str[60]; | |
2257 | ||
2258 | QLIST_FOREACH(mon_fdset, &mon_fdsets, next) { | |
2259 | if (mon_fdset->id != fdset_id) { | |
2260 | continue; | |
2261 | } | |
2262 | QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) { | |
2263 | if (has_fd) { | |
2264 | if (mon_fdset_fd->fd != fd) { | |
2265 | continue; | |
2266 | } | |
2267 | mon_fdset_fd->removed = true; | |
2268 | break; | |
2269 | } else { | |
2270 | mon_fdset_fd->removed = true; | |
2271 | } | |
2272 | } | |
2273 | if (has_fd && !mon_fdset_fd) { | |
2274 | goto error; | |
2275 | } | |
2276 | monitor_fdset_cleanup(mon_fdset); | |
2277 | return; | |
2278 | } | |
2279 | ||
2280 | error: | |
2281 | if (has_fd) { | |
2282 | snprintf(fd_str, sizeof(fd_str), "fdset-id:%" PRId64 ", fd:%" PRId64, | |
2283 | fdset_id, fd); | |
2284 | } else { | |
2285 | snprintf(fd_str, sizeof(fd_str), "fdset-id:%" PRId64, fdset_id); | |
2286 | } | |
2287 | error_set(errp, QERR_FD_NOT_FOUND, fd_str); | |
2288 | } | |
2289 | ||
2290 | FdsetInfoList *qmp_query_fdsets(Error **errp) | |
2291 | { | |
2292 | MonFdset *mon_fdset; | |
2293 | MonFdsetFd *mon_fdset_fd; | |
2294 | FdsetInfoList *fdset_list = NULL; | |
2295 | ||
2296 | QLIST_FOREACH(mon_fdset, &mon_fdsets, next) { | |
2297 | FdsetInfoList *fdset_info = g_malloc0(sizeof(*fdset_info)); | |
2298 | FdsetFdInfoList *fdsetfd_list = NULL; | |
2299 | ||
2300 | fdset_info->value = g_malloc0(sizeof(*fdset_info->value)); | |
2301 | fdset_info->value->fdset_id = mon_fdset->id; | |
2302 | ||
2303 | QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) { | |
2304 | FdsetFdInfoList *fdsetfd_info; | |
2305 | ||
2306 | fdsetfd_info = g_malloc0(sizeof(*fdsetfd_info)); | |
2307 | fdsetfd_info->value = g_malloc0(sizeof(*fdsetfd_info->value)); | |
2308 | fdsetfd_info->value->fd = mon_fdset_fd->fd; | |
2309 | if (mon_fdset_fd->opaque) { | |
2310 | fdsetfd_info->value->has_opaque = true; | |
2311 | fdsetfd_info->value->opaque = g_strdup(mon_fdset_fd->opaque); | |
2312 | } else { | |
2313 | fdsetfd_info->value->has_opaque = false; | |
2314 | } | |
2315 | ||
2316 | fdsetfd_info->next = fdsetfd_list; | |
2317 | fdsetfd_list = fdsetfd_info; | |
2318 | } | |
2319 | ||
2320 | fdset_info->value->fds = fdsetfd_list; | |
2321 | ||
2322 | fdset_info->next = fdset_list; | |
2323 | fdset_list = fdset_info; | |
2324 | } | |
2325 | ||
2326 | return fdset_list; | |
2327 | } | |
2328 | ||
e446f70d CB |
2329 | AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id, |
2330 | bool has_opaque, const char *opaque, | |
2331 | Error **errp) | |
2332 | { | |
2333 | MonFdset *mon_fdset = NULL; | |
2334 | MonFdsetFd *mon_fdset_fd; | |
2335 | AddfdInfo *fdinfo; | |
2336 | ||
2337 | if (has_fdset_id) { | |
2338 | QLIST_FOREACH(mon_fdset, &mon_fdsets, next) { | |
2339 | /* Break if match found or match impossible due to ordering by ID */ | |
2340 | if (fdset_id <= mon_fdset->id) { | |
2341 | if (fdset_id < mon_fdset->id) { | |
2342 | mon_fdset = NULL; | |
2343 | } | |
2344 | break; | |
2345 | } | |
2346 | } | |
2347 | } | |
2348 | ||
2349 | if (mon_fdset == NULL) { | |
2350 | int64_t fdset_id_prev = -1; | |
2351 | MonFdset *mon_fdset_cur = QLIST_FIRST(&mon_fdsets); | |
2352 | ||
2353 | if (has_fdset_id) { | |
2354 | if (fdset_id < 0) { | |
2355 | error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdset-id", | |
2356 | "a non-negative value"); | |
2357 | return NULL; | |
2358 | } | |
2359 | /* Use specified fdset ID */ | |
2360 | QLIST_FOREACH(mon_fdset, &mon_fdsets, next) { | |
2361 | mon_fdset_cur = mon_fdset; | |
2362 | if (fdset_id < mon_fdset_cur->id) { | |
2363 | break; | |
2364 | } | |
2365 | } | |
2366 | } else { | |
2367 | /* Use first available fdset ID */ | |
2368 | QLIST_FOREACH(mon_fdset, &mon_fdsets, next) { | |
2369 | mon_fdset_cur = mon_fdset; | |
2370 | if (fdset_id_prev == mon_fdset_cur->id - 1) { | |
2371 | fdset_id_prev = mon_fdset_cur->id; | |
2372 | continue; | |
2373 | } | |
2374 | break; | |
2375 | } | |
2376 | } | |
2377 | ||
2378 | mon_fdset = g_malloc0(sizeof(*mon_fdset)); | |
2379 | if (has_fdset_id) { | |
2380 | mon_fdset->id = fdset_id; | |
2381 | } else { | |
2382 | mon_fdset->id = fdset_id_prev + 1; | |
2383 | } | |
2384 | ||
2385 | /* The fdset list is ordered by fdset ID */ | |
2386 | if (!mon_fdset_cur) { | |
2387 | QLIST_INSERT_HEAD(&mon_fdsets, mon_fdset, next); | |
2388 | } else if (mon_fdset->id < mon_fdset_cur->id) { | |
2389 | QLIST_INSERT_BEFORE(mon_fdset_cur, mon_fdset, next); | |
2390 | } else { | |
2391 | QLIST_INSERT_AFTER(mon_fdset_cur, mon_fdset, next); | |
2392 | } | |
2393 | } | |
2394 | ||
2395 | mon_fdset_fd = g_malloc0(sizeof(*mon_fdset_fd)); | |
2396 | mon_fdset_fd->fd = fd; | |
2397 | mon_fdset_fd->removed = false; | |
2398 | if (has_opaque) { | |
2399 | mon_fdset_fd->opaque = g_strdup(opaque); | |
2400 | } | |
2401 | QLIST_INSERT_HEAD(&mon_fdset->fds, mon_fdset_fd, next); | |
2402 | ||
2403 | fdinfo = g_malloc0(sizeof(*fdinfo)); | |
2404 | fdinfo->fdset_id = mon_fdset->id; | |
2405 | fdinfo->fd = mon_fdset_fd->fd; | |
2406 | ||
2407 | return fdinfo; | |
2408 | } | |
2409 | ||
adb696f3 CB |
2410 | int monitor_fdset_get_fd(int64_t fdset_id, int flags) |
2411 | { | |
b2dc64c3 | 2412 | #ifndef _WIN32 |
adb696f3 CB |
2413 | MonFdset *mon_fdset; |
2414 | MonFdsetFd *mon_fdset_fd; | |
2415 | int mon_fd_flags; | |
2416 | ||
adb696f3 CB |
2417 | QLIST_FOREACH(mon_fdset, &mon_fdsets, next) { |
2418 | if (mon_fdset->id != fdset_id) { | |
2419 | continue; | |
2420 | } | |
2421 | QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) { | |
2422 | mon_fd_flags = fcntl(mon_fdset_fd->fd, F_GETFL); | |
2423 | if (mon_fd_flags == -1) { | |
2424 | return -1; | |
2425 | } | |
2426 | ||
2427 | if ((flags & O_ACCMODE) == (mon_fd_flags & O_ACCMODE)) { | |
2428 | return mon_fdset_fd->fd; | |
2429 | } | |
2430 | } | |
2431 | errno = EACCES; | |
2432 | return -1; | |
2433 | } | |
2434 | #endif | |
2435 | ||
2436 | errno = ENOENT; | |
2437 | return -1; | |
2438 | } | |
2439 | ||
2440 | int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd) | |
2441 | { | |
2442 | MonFdset *mon_fdset; | |
2443 | MonFdsetFd *mon_fdset_fd_dup; | |
2444 | ||
2445 | QLIST_FOREACH(mon_fdset, &mon_fdsets, next) { | |
2446 | if (mon_fdset->id != fdset_id) { | |
2447 | continue; | |
2448 | } | |
2449 | QLIST_FOREACH(mon_fdset_fd_dup, &mon_fdset->dup_fds, next) { | |
2450 | if (mon_fdset_fd_dup->fd == dup_fd) { | |
2451 | return -1; | |
2452 | } | |
2453 | } | |
2454 | mon_fdset_fd_dup = g_malloc0(sizeof(*mon_fdset_fd_dup)); | |
2455 | mon_fdset_fd_dup->fd = dup_fd; | |
2456 | QLIST_INSERT_HEAD(&mon_fdset->dup_fds, mon_fdset_fd_dup, next); | |
2457 | return 0; | |
2458 | } | |
2459 | return -1; | |
2460 | } | |
2461 | ||
2462 | static int monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove) | |
2463 | { | |
2464 | MonFdset *mon_fdset; | |
2465 | MonFdsetFd *mon_fdset_fd_dup; | |
2466 | ||
2467 | QLIST_FOREACH(mon_fdset, &mon_fdsets, next) { | |
2468 | QLIST_FOREACH(mon_fdset_fd_dup, &mon_fdset->dup_fds, next) { | |
2469 | if (mon_fdset_fd_dup->fd == dup_fd) { | |
2470 | if (remove) { | |
2471 | QLIST_REMOVE(mon_fdset_fd_dup, next); | |
2472 | if (QLIST_EMPTY(&mon_fdset->dup_fds)) { | |
2473 | monitor_fdset_cleanup(mon_fdset); | |
2474 | } | |
b3dd1b8c MT |
2475 | return -1; |
2476 | } else { | |
2477 | return mon_fdset->id; | |
adb696f3 | 2478 | } |
adb696f3 CB |
2479 | } |
2480 | } | |
2481 | } | |
2482 | return -1; | |
2483 | } | |
2484 | ||
2485 | int monitor_fdset_dup_fd_find(int dup_fd) | |
2486 | { | |
2487 | return monitor_fdset_dup_fd_find_remove(dup_fd, false); | |
2488 | } | |
2489 | ||
b3dd1b8c | 2490 | void monitor_fdset_dup_fd_remove(int dup_fd) |
adb696f3 | 2491 | { |
b3dd1b8c | 2492 | monitor_fdset_dup_fd_find_remove(dup_fd, true); |
adb696f3 CB |
2493 | } |
2494 | ||
1677f4c6 | 2495 | int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp) |
5906366e LE |
2496 | { |
2497 | int fd; | |
2498 | Error *local_err = NULL; | |
a96ed02f | 2499 | |
5906366e | 2500 | if (!qemu_isdigit(fdname[0]) && mon) { |
a9940fc4 | 2501 | fd = monitor_get_fd(mon, fdname, &local_err); |
5906366e LE |
2502 | } else { |
2503 | fd = qemu_parse_fd(fdname); | |
a96ed02f | 2504 | if (fd == -1) { |
5906366e LE |
2505 | error_setg(&local_err, "Invalid file descriptor number '%s'", |
2506 | fdname); | |
a96ed02f | 2507 | } |
5906366e LE |
2508 | } |
2509 | if (local_err) { | |
2510 | error_propagate(errp, local_err); | |
2511 | assert(fd == -1); | |
a96ed02f | 2512 | } else { |
5906366e | 2513 | assert(fd != -1); |
a96ed02f NB |
2514 | } |
2515 | ||
2516 | return fd; | |
2517 | } | |
2518 | ||
acd0a093 | 2519 | /* Please update hmp-commands.hx when adding or changing commands */ |
816f8925 | 2520 | static mon_cmd_t info_cmds[] = { |
d7f9b689 LC |
2521 | { |
2522 | .name = "version", | |
2523 | .args_type = "", | |
d7f9b689 LC |
2524 | .params = "", |
2525 | .help = "show the version of QEMU", | |
5f11cb00 | 2526 | .mhandler.cmd = hmp_info_version, |
d7f9b689 LC |
2527 | }, |
2528 | { | |
2529 | .name = "network", | |
2530 | .args_type = "", | |
d7f9b689 LC |
2531 | .params = "", |
2532 | .help = "show the network state", | |
1ce6be24 | 2533 | .mhandler.cmd = hmp_info_network, |
d7f9b689 LC |
2534 | }, |
2535 | { | |
2536 | .name = "chardev", | |
2537 | .args_type = "", | |
d7f9b689 LC |
2538 | .params = "", |
2539 | .help = "show the character devices", | |
5f11cb00 | 2540 | .mhandler.cmd = hmp_info_chardev, |
d7f9b689 LC |
2541 | }, |
2542 | { | |
2543 | .name = "block", | |
e6bb31ec KW |
2544 | .args_type = "nodes:-n,verbose:-v,device:B?", |
2545 | .params = "[-n] [-v] [device]", | |
e73fe2b4 | 2546 | .help = "show info of one block device or all block devices " |
e6bb31ec | 2547 | "(-n: show named nodes; -v: show details)", |
5f11cb00 | 2548 | .mhandler.cmd = hmp_info_block, |
d7f9b689 LC |
2549 | }, |
2550 | { | |
2551 | .name = "blockstats", | |
2552 | .args_type = "", | |
d7f9b689 LC |
2553 | .params = "", |
2554 | .help = "show block device statistics", | |
5f11cb00 | 2555 | .mhandler.cmd = hmp_info_blockstats, |
d7f9b689 | 2556 | }, |
fb5458cd SH |
2557 | { |
2558 | .name = "block-jobs", | |
2559 | .args_type = "", | |
2560 | .params = "", | |
2561 | .help = "show progress of ongoing block device operations", | |
5f11cb00 | 2562 | .mhandler.cmd = hmp_info_block_jobs, |
fb5458cd | 2563 | }, |
d7f9b689 LC |
2564 | { |
2565 | .name = "registers", | |
2566 | .args_type = "", | |
d7f9b689 LC |
2567 | .params = "", |
2568 | .help = "show the cpu registers", | |
1ce6be24 | 2569 | .mhandler.cmd = hmp_info_registers, |
d7f9b689 LC |
2570 | }, |
2571 | { | |
2572 | .name = "cpus", | |
2573 | .args_type = "", | |
d7f9b689 LC |
2574 | .params = "", |
2575 | .help = "show infos for each CPU", | |
5f11cb00 | 2576 | .mhandler.cmd = hmp_info_cpus, |
d7f9b689 LC |
2577 | }, |
2578 | { | |
2579 | .name = "history", | |
2580 | .args_type = "", | |
d7f9b689 LC |
2581 | .params = "", |
2582 | .help = "show the command line history", | |
1ce6be24 | 2583 | .mhandler.cmd = hmp_info_history, |
d7f9b689 | 2584 | }, |
661f1929 JK |
2585 | #if defined(TARGET_I386) || defined(TARGET_PPC) || defined(TARGET_MIPS) || \ |
2586 | defined(TARGET_LM32) || (defined(TARGET_SPARC) && !defined(TARGET_SPARC64)) | |
d7f9b689 LC |
2587 | { |
2588 | .name = "irq", | |
2589 | .args_type = "", | |
d7f9b689 LC |
2590 | .params = "", |
2591 | .help = "show the interrupts statistics (if available)", | |
661f1929 | 2592 | #ifdef TARGET_SPARC |
1ce6be24 | 2593 | .mhandler.cmd = sun4m_hmp_info_irq, |
661f1929 | 2594 | #elif defined(TARGET_LM32) |
1ce6be24 | 2595 | .mhandler.cmd = lm32_hmp_info_irq, |
661f1929 | 2596 | #else |
1ce6be24 | 2597 | .mhandler.cmd = hmp_info_irq, |
661f1929 | 2598 | #endif |
d7f9b689 LC |
2599 | }, |
2600 | { | |
2601 | .name = "pic", | |
2602 | .args_type = "", | |
d7f9b689 LC |
2603 | .params = "", |
2604 | .help = "show i8259 (PIC) state", | |
661f1929 | 2605 | #ifdef TARGET_SPARC |
1ce6be24 | 2606 | .mhandler.cmd = sun4m_hmp_info_pic, |
661f1929 | 2607 | #elif defined(TARGET_LM32) |
1ce6be24 | 2608 | .mhandler.cmd = lm32_hmp_info_pic, |
661f1929 | 2609 | #else |
1ce6be24 | 2610 | .mhandler.cmd = hmp_info_pic, |
661f1929 | 2611 | #endif |
d7f9b689 | 2612 | }, |
661f1929 | 2613 | #endif |
d7f9b689 LC |
2614 | { |
2615 | .name = "pci", | |
2616 | .args_type = "", | |
d7f9b689 LC |
2617 | .params = "", |
2618 | .help = "show PCI info", | |
5f11cb00 | 2619 | .mhandler.cmd = hmp_info_pci, |
d7f9b689 | 2620 | }, |
bebabbc7 | 2621 | #if defined(TARGET_I386) || defined(TARGET_SH4) || defined(TARGET_SPARC) || \ |
692f737c | 2622 | defined(TARGET_PPC) || defined(TARGET_XTENSA) |
d7f9b689 LC |
2623 | { |
2624 | .name = "tlb", | |
2625 | .args_type = "", | |
d7f9b689 LC |
2626 | .params = "", |
2627 | .help = "show virtual to physical memory mappings", | |
1ce6be24 | 2628 | .mhandler.cmd = hmp_info_tlb, |
d7f9b689 | 2629 | }, |
7c664e2f AJ |
2630 | #endif |
2631 | #if defined(TARGET_I386) | |
d7f9b689 LC |
2632 | { |
2633 | .name = "mem", | |
2634 | .args_type = "", | |
d7f9b689 LC |
2635 | .params = "", |
2636 | .help = "show the active virtual memory mappings", | |
1ce6be24 | 2637 | .mhandler.cmd = hmp_info_mem, |
d7f9b689 | 2638 | }, |
b86bda5b | 2639 | #endif |
314e2987 BS |
2640 | { |
2641 | .name = "mtree", | |
2642 | .args_type = "", | |
2643 | .params = "", | |
2644 | .help = "show memory tree", | |
1ce6be24 | 2645 | .mhandler.cmd = hmp_info_mtree, |
314e2987 | 2646 | }, |
d7f9b689 LC |
2647 | { |
2648 | .name = "jit", | |
2649 | .args_type = "", | |
d7f9b689 LC |
2650 | .params = "", |
2651 | .help = "show dynamic compiler info", | |
1ce6be24 | 2652 | .mhandler.cmd = hmp_info_jit, |
d7f9b689 | 2653 | }, |
246ae24d MF |
2654 | { |
2655 | .name = "opcount", | |
2656 | .args_type = "", | |
2657 | .params = "", | |
2658 | .help = "show dynamic compiler opcode counters", | |
1ce6be24 | 2659 | .mhandler.cmd = hmp_info_opcount, |
246ae24d | 2660 | }, |
d7f9b689 LC |
2661 | { |
2662 | .name = "kvm", | |
2663 | .args_type = "", | |
d7f9b689 LC |
2664 | .params = "", |
2665 | .help = "show KVM information", | |
5f11cb00 | 2666 | .mhandler.cmd = hmp_info_kvm, |
d7f9b689 LC |
2667 | }, |
2668 | { | |
2669 | .name = "numa", | |
2670 | .args_type = "", | |
d7f9b689 LC |
2671 | .params = "", |
2672 | .help = "show NUMA information", | |
1ce6be24 | 2673 | .mhandler.cmd = hmp_info_numa, |
d7f9b689 LC |
2674 | }, |
2675 | { | |
2676 | .name = "usb", | |
2677 | .args_type = "", | |
d7f9b689 LC |
2678 | .params = "", |
2679 | .help = "show guest USB devices", | |
1ce6be24 | 2680 | .mhandler.cmd = hmp_info_usb, |
d7f9b689 LC |
2681 | }, |
2682 | { | |
2683 | .name = "usbhost", | |
2684 | .args_type = "", | |
d7f9b689 LC |
2685 | .params = "", |
2686 | .help = "show host USB devices", | |
1ce6be24 | 2687 | .mhandler.cmd = hmp_info_usbhost, |
d7f9b689 LC |
2688 | }, |
2689 | { | |
2690 | .name = "profile", | |
2691 | .args_type = "", | |
d7f9b689 LC |
2692 | .params = "", |
2693 | .help = "show profiling information", | |
1ce6be24 | 2694 | .mhandler.cmd = hmp_info_profile, |
d7f9b689 LC |
2695 | }, |
2696 | { | |
2697 | .name = "capture", | |
2698 | .args_type = "", | |
d7f9b689 LC |
2699 | .params = "", |
2700 | .help = "show capture information", | |
1ce6be24 | 2701 | .mhandler.cmd = hmp_info_capture, |
d7f9b689 LC |
2702 | }, |
2703 | { | |
2704 | .name = "snapshots", | |
2705 | .args_type = "", | |
d7f9b689 LC |
2706 | .params = "", |
2707 | .help = "show the currently saved VM snapshots", | |
1ce6be24 | 2708 | .mhandler.cmd = hmp_info_snapshots, |
d7f9b689 LC |
2709 | }, |
2710 | { | |
2711 | .name = "status", | |
2712 | .args_type = "", | |
d7f9b689 LC |
2713 | .params = "", |
2714 | .help = "show the current VM status (running|paused)", | |
5f11cb00 | 2715 | .mhandler.cmd = hmp_info_status, |
d7f9b689 | 2716 | }, |
d7f9b689 LC |
2717 | { |
2718 | .name = "mice", | |
2719 | .args_type = "", | |
d7f9b689 LC |
2720 | .params = "", |
2721 | .help = "show which guest mouse is receiving events", | |
5f11cb00 | 2722 | .mhandler.cmd = hmp_info_mice, |
d7f9b689 LC |
2723 | }, |
2724 | { | |
2725 | .name = "vnc", | |
2726 | .args_type = "", | |
d7f9b689 LC |
2727 | .params = "", |
2728 | .help = "show the vnc server status", | |
5f11cb00 | 2729 | .mhandler.cmd = hmp_info_vnc, |
d7f9b689 | 2730 | }, |
cb42a870 GH |
2731 | #if defined(CONFIG_SPICE) |
2732 | { | |
2733 | .name = "spice", | |
2734 | .args_type = "", | |
2735 | .params = "", | |
2736 | .help = "show the spice server status", | |
5f11cb00 | 2737 | .mhandler.cmd = hmp_info_spice, |
cb42a870 GH |
2738 | }, |
2739 | #endif | |
d7f9b689 LC |
2740 | { |
2741 | .name = "name", | |
2742 | .args_type = "", | |
d7f9b689 LC |
2743 | .params = "", |
2744 | .help = "show the current VM name", | |
5f11cb00 | 2745 | .mhandler.cmd = hmp_info_name, |
d7f9b689 LC |
2746 | }, |
2747 | { | |
2748 | .name = "uuid", | |
2749 | .args_type = "", | |
d7f9b689 LC |
2750 | .params = "", |
2751 | .help = "show the current VM UUID", | |
5f11cb00 | 2752 | .mhandler.cmd = hmp_info_uuid, |
d7f9b689 | 2753 | }, |
d7f9b689 LC |
2754 | { |
2755 | .name = "cpustats", | |
2756 | .args_type = "", | |
d7f9b689 LC |
2757 | .params = "", |
2758 | .help = "show CPU statistics", | |
1ce6be24 | 2759 | .mhandler.cmd = hmp_info_cpustats, |
d7f9b689 | 2760 | }, |
31a60e22 | 2761 | #if defined(CONFIG_SLIRP) |
d7f9b689 LC |
2762 | { |
2763 | .name = "usernet", | |
2764 | .args_type = "", | |
d7f9b689 LC |
2765 | .params = "", |
2766 | .help = "show user network stack connection states", | |
1ce6be24 | 2767 | .mhandler.cmd = hmp_info_usernet, |
d7f9b689 | 2768 | }, |
31a60e22 | 2769 | #endif |
d7f9b689 LC |
2770 | { |
2771 | .name = "migrate", | |
2772 | .args_type = "", | |
d7f9b689 LC |
2773 | .params = "", |
2774 | .help = "show migration status", | |
5f11cb00 | 2775 | .mhandler.cmd = hmp_info_migrate, |
d7f9b689 | 2776 | }, |
bbf6da32 OW |
2777 | { |
2778 | .name = "migrate_capabilities", | |
2779 | .args_type = "", | |
2780 | .params = "", | |
2781 | .help = "show current migration capabilities", | |
5f11cb00 | 2782 | .mhandler.cmd = hmp_info_migrate_capabilities, |
bbf6da32 | 2783 | }, |
50e9a629 LL |
2784 | { |
2785 | .name = "migrate_parameters", | |
2786 | .args_type = "", | |
2787 | .params = "", | |
2788 | .help = "show current migration parameters", | |
2789 | .mhandler.cmd = hmp_info_migrate_parameters, | |
2790 | }, | |
9e1ba4cc OW |
2791 | { |
2792 | .name = "migrate_cache_size", | |
2793 | .args_type = "", | |
2794 | .params = "", | |
2795 | .help = "show current migration xbzrle cache size", | |
5f11cb00 | 2796 | .mhandler.cmd = hmp_info_migrate_cache_size, |
9e1ba4cc | 2797 | }, |
d7f9b689 LC |
2798 | { |
2799 | .name = "balloon", | |
2800 | .args_type = "", | |
d7f9b689 LC |
2801 | .params = "", |
2802 | .help = "show balloon information", | |
5f11cb00 | 2803 | .mhandler.cmd = hmp_info_balloon, |
d7f9b689 LC |
2804 | }, |
2805 | { | |
2806 | .name = "qtree", | |
2807 | .args_type = "", | |
d7f9b689 LC |
2808 | .params = "", |
2809 | .help = "show device tree", | |
1ce6be24 | 2810 | .mhandler.cmd = hmp_info_qtree, |
d7f9b689 LC |
2811 | }, |
2812 | { | |
2813 | .name = "qdm", | |
2814 | .args_type = "", | |
d7f9b689 LC |
2815 | .params = "", |
2816 | .help = "show qdev device model list", | |
1ce6be24 | 2817 | .mhandler.cmd = hmp_info_qdm, |
d7f9b689 | 2818 | }, |
a01ff75f AF |
2819 | { |
2820 | .name = "qom-tree", | |
2821 | .args_type = "path:s?", | |
2822 | .params = "[path]", | |
2823 | .help = "show QOM composition tree", | |
2824 | .mhandler.cmd = hmp_info_qom_tree, | |
2825 | }, | |
d7f9b689 LC |
2826 | { |
2827 | .name = "roms", | |
2828 | .args_type = "", | |
d7f9b689 LC |
2829 | .params = "", |
2830 | .help = "show roms", | |
1ce6be24 | 2831 | .mhandler.cmd = hmp_info_roms, |
d7f9b689 | 2832 | }, |
22890ab5 PS |
2833 | { |
2834 | .name = "trace-events", | |
2835 | .args_type = "", | |
2836 | .params = "", | |
2837 | .help = "show available trace-events & their state", | |
1ce6be24 | 2838 | .mhandler.cmd = hmp_info_trace_events, |
22890ab5 | 2839 | }, |
d1a0cf73 SB |
2840 | { |
2841 | .name = "tpm", | |
2842 | .args_type = "", | |
2843 | .params = "", | |
2844 | .help = "show the TPM device", | |
2845 | .mhandler.cmd = hmp_info_tpm, | |
2846 | }, | |
eb1539b2 HT |
2847 | { |
2848 | .name = "memdev", | |
2849 | .args_type = "", | |
2850 | .params = "", | |
8f4e5ac3 | 2851 | .help = "show memory backends", |
eb1539b2 HT |
2852 | .mhandler.cmd = hmp_info_memdev, |
2853 | }, | |
a631892f ZG |
2854 | { |
2855 | .name = "memory-devices", | |
2856 | .args_type = "", | |
2857 | .params = "", | |
2858 | .help = "show memory devices", | |
2859 | .mhandler.cmd = hmp_info_memory_devices, | |
2860 | }, | |
fafa4d50 SF |
2861 | { |
2862 | .name = "rocker", | |
2863 | .args_type = "name:s", | |
2864 | .params = "name", | |
2865 | .help = "Show rocker switch", | |
2866 | .mhandler.cmd = hmp_rocker, | |
2867 | }, | |
2868 | { | |
2869 | .name = "rocker-ports", | |
2870 | .args_type = "name:s", | |
2871 | .params = "name", | |
2872 | .help = "Show rocker ports", | |
2873 | .mhandler.cmd = hmp_rocker_ports, | |
2874 | }, | |
2875 | { | |
2876 | .name = "rocker-of-dpa-flows", | |
2877 | .args_type = "name:s,tbl_id:i?", | |
2878 | .params = "name [tbl_id]", | |
2879 | .help = "Show rocker OF-DPA flow tables", | |
2880 | .mhandler.cmd = hmp_rocker_of_dpa_flows, | |
2881 | }, | |
2882 | { | |
2883 | .name = "rocker-of-dpa-groups", | |
2884 | .args_type = "name:s,type:i?", | |
2885 | .params = "name [type]", | |
2886 | .help = "Show rocker OF-DPA groups", | |
2887 | .mhandler.cmd = hmp_rocker_of_dpa_groups, | |
2888 | }, | |
d7f9b689 LC |
2889 | { |
2890 | .name = NULL, | |
2891 | }, | |
9dc39cba FB |
2892 | }; |
2893 | ||
a13ced59 WX |
2894 | /* mon_cmds and info_cmds would be sorted at runtime */ |
2895 | static mon_cmd_t mon_cmds[] = { | |
2896 | #include "hmp-commands.h" | |
2897 | { NULL, NULL, }, | |
2898 | }; | |
2899 | ||
f36b4afb | 2900 | static const mon_cmd_t qmp_cmds[] = { |
e3193601 | 2901 | #include "qmp-commands-old.h" |
f36b4afb LC |
2902 | { /* NULL */ }, |
2903 | }; | |
2904 | ||
9307c4c1 FB |
2905 | /*******************************************************************/ |
2906 | ||
2907 | static const char *pch; | |
6ab7e546 | 2908 | static sigjmp_buf expr_env; |
9307c4c1 | 2909 | |
92a31b1f FB |
2910 | #define MD_TLONG 0 |
2911 | #define MD_I32 1 | |
2912 | ||
9307c4c1 FB |
2913 | typedef struct MonitorDef { |
2914 | const char *name; | |
2915 | int offset; | |
8662d656 | 2916 | target_long (*get_value)(const struct MonitorDef *md, int val); |
92a31b1f | 2917 | int type; |
9307c4c1 FB |
2918 | } MonitorDef; |
2919 | ||
57206fd4 | 2920 | #if defined(TARGET_I386) |
8662d656 | 2921 | static target_long monitor_get_pc (const struct MonitorDef *md, int val) |
57206fd4 | 2922 | { |
9349b4f9 | 2923 | CPUArchState *env = mon_get_cpu(); |
6a00d601 | 2924 | return env->eip + env->segs[R_CS].base; |
57206fd4 FB |
2925 | } |
2926 | #endif | |
2927 | ||
a541f297 | 2928 | #if defined(TARGET_PPC) |
8662d656 | 2929 | static target_long monitor_get_ccr (const struct MonitorDef *md, int val) |
a541f297 | 2930 | { |
9349b4f9 | 2931 | CPUArchState *env = mon_get_cpu(); |
a541f297 FB |
2932 | unsigned int u; |
2933 | int i; | |
2934 | ||
2935 | u = 0; | |
2936 | for (i = 0; i < 8; i++) | |
d2981180 | 2937 | u |= env->crf[i] << (32 - (4 * (i + 1))); |
a541f297 FB |
2938 | |
2939 | return u; | |
2940 | } | |
2941 | ||
8662d656 | 2942 | static target_long monitor_get_msr (const struct MonitorDef *md, int val) |
a541f297 | 2943 | { |
9349b4f9 | 2944 | CPUArchState *env = mon_get_cpu(); |
0411a972 | 2945 | return env->msr; |
a541f297 FB |
2946 | } |
2947 | ||
8662d656 | 2948 | static target_long monitor_get_xer (const struct MonitorDef *md, int val) |
a541f297 | 2949 | { |
9349b4f9 | 2950 | CPUArchState *env = mon_get_cpu(); |
3d7b417e | 2951 | return env->xer; |
a541f297 | 2952 | } |
9fddaa0c | 2953 | |
8662d656 | 2954 | static target_long monitor_get_decr (const struct MonitorDef *md, int val) |
9fddaa0c | 2955 | { |
9349b4f9 | 2956 | CPUArchState *env = mon_get_cpu(); |
6a00d601 | 2957 | return cpu_ppc_load_decr(env); |
9fddaa0c FB |
2958 | } |
2959 | ||
8662d656 | 2960 | static target_long monitor_get_tbu (const struct MonitorDef *md, int val) |
9fddaa0c | 2961 | { |
9349b4f9 | 2962 | CPUArchState *env = mon_get_cpu(); |
6a00d601 | 2963 | return cpu_ppc_load_tbu(env); |
9fddaa0c FB |
2964 | } |
2965 | ||
8662d656 | 2966 | static target_long monitor_get_tbl (const struct MonitorDef *md, int val) |
9fddaa0c | 2967 | { |
9349b4f9 | 2968 | CPUArchState *env = mon_get_cpu(); |
6a00d601 | 2969 | return cpu_ppc_load_tbl(env); |
9fddaa0c | 2970 | } |
a541f297 FB |
2971 | #endif |
2972 | ||
e95c8d51 | 2973 | #if defined(TARGET_SPARC) |
7b936c0c | 2974 | #ifndef TARGET_SPARC64 |
8662d656 | 2975 | static target_long monitor_get_psr (const struct MonitorDef *md, int val) |
e95c8d51 | 2976 | { |
9349b4f9 | 2977 | CPUArchState *env = mon_get_cpu(); |
5a834bb4 BS |
2978 | |
2979 | return cpu_get_psr(env); | |
e95c8d51 | 2980 | } |
7b936c0c | 2981 | #endif |
e95c8d51 | 2982 | |
8662d656 | 2983 | static target_long monitor_get_reg(const struct MonitorDef *md, int val) |
e95c8d51 | 2984 | { |
9349b4f9 | 2985 | CPUArchState *env = mon_get_cpu(); |
6a00d601 | 2986 | return env->regwptr[val]; |
e95c8d51 FB |
2987 | } |
2988 | #endif | |
2989 | ||
8662d656 | 2990 | static const MonitorDef monitor_defs[] = { |
9307c4c1 | 2991 | #ifdef TARGET_I386 |
57206fd4 FB |
2992 | |
2993 | #define SEG(name, seg) \ | |
e59d167f AF |
2994 | { name, offsetof(CPUX86State, segs[seg].selector), NULL, MD_I32 },\ |
2995 | { name ".base", offsetof(CPUX86State, segs[seg].base) },\ | |
2996 | { name ".limit", offsetof(CPUX86State, segs[seg].limit), NULL, MD_I32 }, | |
2997 | ||
2998 | { "eax", offsetof(CPUX86State, regs[0]) }, | |
2999 | { "ecx", offsetof(CPUX86State, regs[1]) }, | |
3000 | { "edx", offsetof(CPUX86State, regs[2]) }, | |
3001 | { "ebx", offsetof(CPUX86State, regs[3]) }, | |
3002 | { "esp|sp", offsetof(CPUX86State, regs[4]) }, | |
3003 | { "ebp|fp", offsetof(CPUX86State, regs[5]) }, | |
3004 | { "esi", offsetof(CPUX86State, regs[6]) }, | |
3005 | { "edi", offsetof(CPUX86State, regs[7]) }, | |
92a31b1f | 3006 | #ifdef TARGET_X86_64 |
e59d167f AF |
3007 | { "r8", offsetof(CPUX86State, regs[8]) }, |
3008 | { "r9", offsetof(CPUX86State, regs[9]) }, | |
3009 | { "r10", offsetof(CPUX86State, regs[10]) }, | |
3010 | { "r11", offsetof(CPUX86State, regs[11]) }, | |
3011 | { "r12", offsetof(CPUX86State, regs[12]) }, | |
3012 | { "r13", offsetof(CPUX86State, regs[13]) }, | |
3013 | { "r14", offsetof(CPUX86State, regs[14]) }, | |
3014 | { "r15", offsetof(CPUX86State, regs[15]) }, | |
92a31b1f | 3015 | #endif |
e59d167f AF |
3016 | { "eflags", offsetof(CPUX86State, eflags) }, |
3017 | { "eip", offsetof(CPUX86State, eip) }, | |
57206fd4 FB |
3018 | SEG("cs", R_CS) |
3019 | SEG("ds", R_DS) | |
3020 | SEG("es", R_ES) | |
01038d2a | 3021 | SEG("ss", R_SS) |
57206fd4 FB |
3022 | SEG("fs", R_FS) |
3023 | SEG("gs", R_GS) | |
3024 | { "pc", 0, monitor_get_pc, }, | |
a541f297 | 3025 | #elif defined(TARGET_PPC) |
ff937dba | 3026 | /* General purpose registers */ |
e59d167f AF |
3027 | { "r0", offsetof(CPUPPCState, gpr[0]) }, |
3028 | { "r1", offsetof(CPUPPCState, gpr[1]) }, | |
3029 | { "r2", offsetof(CPUPPCState, gpr[2]) }, | |
3030 | { "r3", offsetof(CPUPPCState, gpr[3]) }, | |
3031 | { "r4", offsetof(CPUPPCState, gpr[4]) }, | |
3032 | { "r5", offsetof(CPUPPCState, gpr[5]) }, | |
3033 | { "r6", offsetof(CPUPPCState, gpr[6]) }, | |
3034 | { "r7", offsetof(CPUPPCState, gpr[7]) }, | |
3035 | { "r8", offsetof(CPUPPCState, gpr[8]) }, | |
3036 | { "r9", offsetof(CPUPPCState, gpr[9]) }, | |
3037 | { "r10", offsetof(CPUPPCState, gpr[10]) }, | |
3038 | { "r11", offsetof(CPUPPCState, gpr[11]) }, | |
3039 | { "r12", offsetof(CPUPPCState, gpr[12]) }, | |
3040 | { "r13", offsetof(CPUPPCState, gpr[13]) }, | |
3041 | { "r14", offsetof(CPUPPCState, gpr[14]) }, | |
3042 | { "r15", offsetof(CPUPPCState, gpr[15]) }, | |
3043 | { "r16", offsetof(CPUPPCState, gpr[16]) }, | |
3044 | { "r17", offsetof(CPUPPCState, gpr[17]) }, | |
3045 | { "r18", offsetof(CPUPPCState, gpr[18]) }, | |
3046 | { "r19", offsetof(CPUPPCState, gpr[19]) }, | |
3047 | { "r20", offsetof(CPUPPCState, gpr[20]) }, | |
3048 | { "r21", offsetof(CPUPPCState, gpr[21]) }, | |
3049 | { "r22", offsetof(CPUPPCState, gpr[22]) }, | |
3050 | { "r23", offsetof(CPUPPCState, gpr[23]) }, | |
3051 | { "r24", offsetof(CPUPPCState, gpr[24]) }, | |
3052 | { "r25", offsetof(CPUPPCState, gpr[25]) }, | |
3053 | { "r26", offsetof(CPUPPCState, gpr[26]) }, | |
3054 | { "r27", offsetof(CPUPPCState, gpr[27]) }, | |
3055 | { "r28", offsetof(CPUPPCState, gpr[28]) }, | |
3056 | { "r29", offsetof(CPUPPCState, gpr[29]) }, | |
3057 | { "r30", offsetof(CPUPPCState, gpr[30]) }, | |
3058 | { "r31", offsetof(CPUPPCState, gpr[31]) }, | |
ff937dba | 3059 | /* Floating point registers */ |
e59d167f AF |
3060 | { "f0", offsetof(CPUPPCState, fpr[0]) }, |
3061 | { "f1", offsetof(CPUPPCState, fpr[1]) }, | |
3062 | { "f2", offsetof(CPUPPCState, fpr[2]) }, | |
3063 | { "f3", offsetof(CPUPPCState, fpr[3]) }, | |
3064 | { "f4", offsetof(CPUPPCState, fpr[4]) }, | |
3065 | { "f5", offsetof(CPUPPCState, fpr[5]) }, | |
3066 | { "f6", offsetof(CPUPPCState, fpr[6]) }, | |
3067 | { "f7", offsetof(CPUPPCState, fpr[7]) }, | |
3068 | { "f8", offsetof(CPUPPCState, fpr[8]) }, | |
3069 | { "f9", offsetof(CPUPPCState, fpr[9]) }, | |
3070 | { "f10", offsetof(CPUPPCState, fpr[10]) }, | |
3071 | { "f11", offsetof(CPUPPCState, fpr[11]) }, | |
3072 | { "f12", offsetof(CPUPPCState, fpr[12]) }, | |
3073 | { "f13", offsetof(CPUPPCState, fpr[13]) }, | |
3074 | { "f14", offsetof(CPUPPCState, fpr[14]) }, | |
3075 | { "f15", offsetof(CPUPPCState, fpr[15]) }, | |
3076 | { "f16", offsetof(CPUPPCState, fpr[16]) }, | |
3077 | { "f17", offsetof(CPUPPCState, fpr[17]) }, | |
3078 | { "f18", offsetof(CPUPPCState, fpr[18]) }, | |
3079 | { "f19", offsetof(CPUPPCState, fpr[19]) }, | |
3080 | { "f20", offsetof(CPUPPCState, fpr[20]) }, | |
3081 | { "f21", offsetof(CPUPPCState, fpr[21]) }, | |
3082 | { "f22", offsetof(CPUPPCState, fpr[22]) }, | |
3083 | { "f23", offsetof(CPUPPCState, fpr[23]) }, | |
3084 | { "f24", offsetof(CPUPPCState, fpr[24]) }, | |
3085 | { "f25", offsetof(CPUPPCState, fpr[25]) }, | |
3086 | { "f26", offsetof(CPUPPCState, fpr[26]) }, | |
3087 | { "f27", offsetof(CPUPPCState, fpr[27]) }, | |
3088 | { "f28", offsetof(CPUPPCState, fpr[28]) }, | |
3089 | { "f29", offsetof(CPUPPCState, fpr[29]) }, | |
3090 | { "f30", offsetof(CPUPPCState, fpr[30]) }, | |
3091 | { "f31", offsetof(CPUPPCState, fpr[31]) }, | |
3092 | { "fpscr", offsetof(CPUPPCState, fpscr) }, | |
ff937dba | 3093 | /* Next instruction pointer */ |
e59d167f AF |
3094 | { "nip|pc", offsetof(CPUPPCState, nip) }, |
3095 | { "lr", offsetof(CPUPPCState, lr) }, | |
3096 | { "ctr", offsetof(CPUPPCState, ctr) }, | |
9fddaa0c | 3097 | { "decr", 0, &monitor_get_decr, }, |
a541f297 | 3098 | { "ccr", 0, &monitor_get_ccr, }, |
ff937dba | 3099 | /* Machine state register */ |
a541f297 FB |
3100 | { "msr", 0, &monitor_get_msr, }, |
3101 | { "xer", 0, &monitor_get_xer, }, | |
9fddaa0c FB |
3102 | { "tbu", 0, &monitor_get_tbu, }, |
3103 | { "tbl", 0, &monitor_get_tbl, }, | |
ff937dba | 3104 | /* Segment registers */ |
e59d167f AF |
3105 | { "sdr1", offsetof(CPUPPCState, spr[SPR_SDR1]) }, |
3106 | { "sr0", offsetof(CPUPPCState, sr[0]) }, | |
3107 | { "sr1", offsetof(CPUPPCState, sr[1]) }, | |
3108 | { "sr2", offsetof(CPUPPCState, sr[2]) }, | |
3109 | { "sr3", offsetof(CPUPPCState, sr[3]) }, | |
3110 | { "sr4", offsetof(CPUPPCState, sr[4]) }, | |
3111 | { "sr5", offsetof(CPUPPCState, sr[5]) }, | |
3112 | { "sr6", offsetof(CPUPPCState, sr[6]) }, | |
3113 | { "sr7", offsetof(CPUPPCState, sr[7]) }, | |
3114 | { "sr8", offsetof(CPUPPCState, sr[8]) }, | |
3115 | { "sr9", offsetof(CPUPPCState, sr[9]) }, | |
3116 | { "sr10", offsetof(CPUPPCState, sr[10]) }, | |
3117 | { "sr11", offsetof(CPUPPCState, sr[11]) }, | |
3118 | { "sr12", offsetof(CPUPPCState, sr[12]) }, | |
3119 | { "sr13", offsetof(CPUPPCState, sr[13]) }, | |
3120 | { "sr14", offsetof(CPUPPCState, sr[14]) }, | |
3121 | { "sr15", offsetof(CPUPPCState, sr[15]) }, | |
90dc8812 | 3122 | /* Too lazy to put BATs... */ |
e59d167f AF |
3123 | { "pvr", offsetof(CPUPPCState, spr[SPR_PVR]) }, |
3124 | ||
3125 | { "srr0", offsetof(CPUPPCState, spr[SPR_SRR0]) }, | |
3126 | { "srr1", offsetof(CPUPPCState, spr[SPR_SRR1]) }, | |
04f1f784 TM |
3127 | { "dar", offsetof(CPUPPCState, spr[SPR_DAR]) }, |
3128 | { "dsisr", offsetof(CPUPPCState, spr[SPR_DSISR]) }, | |
3129 | { "cfar", offsetof(CPUPPCState, spr[SPR_CFAR]) }, | |
e59d167f AF |
3130 | { "sprg0", offsetof(CPUPPCState, spr[SPR_SPRG0]) }, |
3131 | { "sprg1", offsetof(CPUPPCState, spr[SPR_SPRG1]) }, | |
3132 | { "sprg2", offsetof(CPUPPCState, spr[SPR_SPRG2]) }, | |
3133 | { "sprg3", offsetof(CPUPPCState, spr[SPR_SPRG3]) }, | |
3134 | { "sprg4", offsetof(CPUPPCState, spr[SPR_SPRG4]) }, | |
3135 | { "sprg5", offsetof(CPUPPCState, spr[SPR_SPRG5]) }, | |
3136 | { "sprg6", offsetof(CPUPPCState, spr[SPR_SPRG6]) }, | |
3137 | { "sprg7", offsetof(CPUPPCState, spr[SPR_SPRG7]) }, | |
3138 | { "pid", offsetof(CPUPPCState, spr[SPR_BOOKE_PID]) }, | |
3139 | { "csrr0", offsetof(CPUPPCState, spr[SPR_BOOKE_CSRR0]) }, | |
3140 | { "csrr1", offsetof(CPUPPCState, spr[SPR_BOOKE_CSRR1]) }, | |
3141 | { "esr", offsetof(CPUPPCState, spr[SPR_BOOKE_ESR]) }, | |
3142 | { "dear", offsetof(CPUPPCState, spr[SPR_BOOKE_DEAR]) }, | |
3143 | { "mcsr", offsetof(CPUPPCState, spr[SPR_BOOKE_MCSR]) }, | |
3144 | { "tsr", offsetof(CPUPPCState, spr[SPR_BOOKE_TSR]) }, | |
3145 | { "tcr", offsetof(CPUPPCState, spr[SPR_BOOKE_TCR]) }, | |
3146 | { "vrsave", offsetof(CPUPPCState, spr[SPR_VRSAVE]) }, | |
3147 | { "pir", offsetof(CPUPPCState, spr[SPR_BOOKE_PIR]) }, | |
3148 | { "mcsrr0", offsetof(CPUPPCState, spr[SPR_BOOKE_MCSRR0]) }, | |
3149 | { "mcsrr1", offsetof(CPUPPCState, spr[SPR_BOOKE_MCSRR1]) }, | |
3150 | { "decar", offsetof(CPUPPCState, spr[SPR_BOOKE_DECAR]) }, | |
3151 | { "ivpr", offsetof(CPUPPCState, spr[SPR_BOOKE_IVPR]) }, | |
3152 | { "epcr", offsetof(CPUPPCState, spr[SPR_BOOKE_EPCR]) }, | |
3153 | { "sprg8", offsetof(CPUPPCState, spr[SPR_BOOKE_SPRG8]) }, | |
3154 | { "ivor0", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR0]) }, | |
3155 | { "ivor1", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR1]) }, | |
3156 | { "ivor2", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR2]) }, | |
3157 | { "ivor3", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR3]) }, | |
3158 | { "ivor4", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR4]) }, | |
3159 | { "ivor5", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR5]) }, | |
3160 | { "ivor6", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR6]) }, | |
3161 | { "ivor7", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR7]) }, | |
3162 | { "ivor8", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR8]) }, | |
3163 | { "ivor9", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR9]) }, | |
3164 | { "ivor10", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR10]) }, | |
3165 | { "ivor11", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR11]) }, | |
3166 | { "ivor12", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR12]) }, | |
3167 | { "ivor13", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR13]) }, | |
3168 | { "ivor14", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR14]) }, | |
3169 | { "ivor15", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR15]) }, | |
3170 | { "ivor32", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR32]) }, | |
3171 | { "ivor33", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR33]) }, | |
3172 | { "ivor34", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR34]) }, | |
3173 | { "ivor35", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR35]) }, | |
3174 | { "ivor36", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR36]) }, | |
3175 | { "ivor37", offsetof(CPUPPCState, spr[SPR_BOOKE_IVOR37]) }, | |
3176 | { "mas0", offsetof(CPUPPCState, spr[SPR_BOOKE_MAS0]) }, | |
3177 | { "mas1", offsetof(CPUPPCState, spr[SPR_BOOKE_MAS1]) }, | |
3178 | { "mas2", offsetof(CPUPPCState, spr[SPR_BOOKE_MAS2]) }, | |
3179 | { "mas3", offsetof(CPUPPCState, spr[SPR_BOOKE_MAS3]) }, | |
3180 | { "mas4", offsetof(CPUPPCState, spr[SPR_BOOKE_MAS4]) }, | |
3181 | { "mas6", offsetof(CPUPPCState, spr[SPR_BOOKE_MAS6]) }, | |
3182 | { "mas7", offsetof(CPUPPCState, spr[SPR_BOOKE_MAS7]) }, | |
3183 | { "mmucfg", offsetof(CPUPPCState, spr[SPR_MMUCFG]) }, | |
3184 | { "tlb0cfg", offsetof(CPUPPCState, spr[SPR_BOOKE_TLB0CFG]) }, | |
3185 | { "tlb1cfg", offsetof(CPUPPCState, spr[SPR_BOOKE_TLB1CFG]) }, | |
3186 | { "epr", offsetof(CPUPPCState, spr[SPR_BOOKE_EPR]) }, | |
3187 | { "eplc", offsetof(CPUPPCState, spr[SPR_BOOKE_EPLC]) }, | |
3188 | { "epsc", offsetof(CPUPPCState, spr[SPR_BOOKE_EPSC]) }, | |
3189 | { "svr", offsetof(CPUPPCState, spr[SPR_E500_SVR]) }, | |
3190 | { "mcar", offsetof(CPUPPCState, spr[SPR_Exxx_MCAR]) }, | |
3191 | { "pid1", offsetof(CPUPPCState, spr[SPR_BOOKE_PID1]) }, | |
3192 | { "pid2", offsetof(CPUPPCState, spr[SPR_BOOKE_PID2]) }, | |
3193 | { "hid0", offsetof(CPUPPCState, spr[SPR_HID0]) }, | |
90dc8812 | 3194 | |
e95c8d51 | 3195 | #elif defined(TARGET_SPARC) |
e59d167f AF |
3196 | { "g0", offsetof(CPUSPARCState, gregs[0]) }, |
3197 | { "g1", offsetof(CPUSPARCState, gregs[1]) }, | |
3198 | { "g2", offsetof(CPUSPARCState, gregs[2]) }, | |
3199 | { "g3", offsetof(CPUSPARCState, gregs[3]) }, | |
3200 | { "g4", offsetof(CPUSPARCState, gregs[4]) }, | |
3201 | { "g5", offsetof(CPUSPARCState, gregs[5]) }, | |
3202 | { "g6", offsetof(CPUSPARCState, gregs[6]) }, | |
3203 | { "g7", offsetof(CPUSPARCState, gregs[7]) }, | |
e95c8d51 FB |
3204 | { "o0", 0, monitor_get_reg }, |
3205 | { "o1", 1, monitor_get_reg }, | |
3206 | { "o2", 2, monitor_get_reg }, | |
3207 | { "o3", 3, monitor_get_reg }, | |
3208 | { "o4", 4, monitor_get_reg }, | |
3209 | { "o5", 5, monitor_get_reg }, | |
3210 | { "o6", 6, monitor_get_reg }, | |
3211 | { "o7", 7, monitor_get_reg }, | |
3212 | { "l0", 8, monitor_get_reg }, | |
3213 | { "l1", 9, monitor_get_reg }, | |
3214 | { "l2", 10, monitor_get_reg }, | |
3215 | { "l3", 11, monitor_get_reg }, | |
3216 | { "l4", 12, monitor_get_reg }, | |
3217 | { "l5", 13, monitor_get_reg }, | |
3218 | { "l6", 14, monitor_get_reg }, | |
3219 | { "l7", 15, monitor_get_reg }, | |
3220 | { "i0", 16, monitor_get_reg }, | |
3221 | { "i1", 17, monitor_get_reg }, | |
3222 | { "i2", 18, monitor_get_reg }, | |
3223 | { "i3", 19, monitor_get_reg }, | |
3224 | { "i4", 20, monitor_get_reg }, | |
3225 | { "i5", 21, monitor_get_reg }, | |
3226 | { "i6", 22, monitor_get_reg }, | |
3227 | { "i7", 23, monitor_get_reg }, | |
e59d167f AF |
3228 | { "pc", offsetof(CPUSPARCState, pc) }, |
3229 | { "npc", offsetof(CPUSPARCState, npc) }, | |
3230 | { "y", offsetof(CPUSPARCState, y) }, | |
7b936c0c | 3231 | #ifndef TARGET_SPARC64 |
e95c8d51 | 3232 | { "psr", 0, &monitor_get_psr, }, |
e59d167f | 3233 | { "wim", offsetof(CPUSPARCState, wim) }, |
7b936c0c | 3234 | #endif |
e59d167f AF |
3235 | { "tbr", offsetof(CPUSPARCState, tbr) }, |
3236 | { "fsr", offsetof(CPUSPARCState, fsr) }, | |
3237 | { "f0", offsetof(CPUSPARCState, fpr[0].l.upper) }, | |
3238 | { "f1", offsetof(CPUSPARCState, fpr[0].l.lower) }, | |
3239 | { "f2", offsetof(CPUSPARCState, fpr[1].l.upper) }, | |
3240 | { "f3", offsetof(CPUSPARCState, fpr[1].l.lower) }, | |
3241 | { "f4", offsetof(CPUSPARCState, fpr[2].l.upper) }, | |
3242 | { "f5", offsetof(CPUSPARCState, fpr[2].l.lower) }, | |
3243 | { "f6", offsetof(CPUSPARCState, fpr[3].l.upper) }, | |
3244 | { "f7", offsetof(CPUSPARCState, fpr[3].l.lower) }, | |
3245 | { "f8", offsetof(CPUSPARCState, fpr[4].l.upper) }, | |
3246 | { "f9", offsetof(CPUSPARCState, fpr[4].l.lower) }, | |
3247 | { "f10", offsetof(CPUSPARCState, fpr[5].l.upper) }, | |
3248 | { "f11", offsetof(CPUSPARCState, fpr[5].l.lower) }, | |
3249 | { "f12", offsetof(CPUSPARCState, fpr[6].l.upper) }, | |
3250 | { "f13", offsetof(CPUSPARCState, fpr[6].l.lower) }, | |
3251 | { "f14", offsetof(CPUSPARCState, fpr[7].l.upper) }, | |
3252 | { "f15", offsetof(CPUSPARCState, fpr[7].l.lower) }, | |
3253 | { "f16", offsetof(CPUSPARCState, fpr[8].l.upper) }, | |
3254 | { "f17", offsetof(CPUSPARCState, fpr[8].l.lower) }, | |
3255 | { "f18", offsetof(CPUSPARCState, fpr[9].l.upper) }, | |
3256 | { "f19", offsetof(CPUSPARCState, fpr[9].l.lower) }, | |
3257 | { "f20", offsetof(CPUSPARCState, fpr[10].l.upper) }, | |
3258 | { "f21", offsetof(CPUSPARCState, fpr[10].l.lower) }, | |
3259 | { "f22", offsetof(CPUSPARCState, fpr[11].l.upper) }, | |
3260 | { "f23", offsetof(CPUSPARCState, fpr[11].l.lower) }, | |
3261 | { "f24", offsetof(CPUSPARCState, fpr[12].l.upper) }, | |
3262 | { "f25", offsetof(CPUSPARCState, fpr[12].l.lower) }, | |
3263 | { "f26", offsetof(CPUSPARCState, fpr[13].l.upper) }, | |
3264 | { "f27", offsetof(CPUSPARCState, fpr[13].l.lower) }, | |
3265 | { "f28", offsetof(CPUSPARCState, fpr[14].l.upper) }, | |
3266 | { "f29", offsetof(CPUSPARCState, fpr[14].l.lower) }, | |
3267 | { "f30", offsetof(CPUSPARCState, fpr[15].l.upper) }, | |
3268 | { "f31", offsetof(CPUSPARCState, fpr[15].l.lower) }, | |
7b936c0c | 3269 | #ifdef TARGET_SPARC64 |
e59d167f AF |
3270 | { "f32", offsetof(CPUSPARCState, fpr[16]) }, |
3271 | { "f34", offsetof(CPUSPARCState, fpr[17]) }, | |
3272 | { "f36", offsetof(CPUSPARCState, fpr[18]) }, | |
3273 | { "f38", offsetof(CPUSPARCState, fpr[19]) }, | |
3274 | { "f40", offsetof(CPUSPARCState, fpr[20]) }, | |
3275 | { "f42", offsetof(CPUSPARCState, fpr[21]) }, | |
3276 | { "f44", offsetof(CPUSPARCState, fpr[22]) }, | |
3277 | { "f46", offsetof(CPUSPARCState, fpr[23]) }, | |
3278 | { "f48", offsetof(CPUSPARCState, fpr[24]) }, | |
3279 | { "f50", offsetof(CPUSPARCState, fpr[25]) }, | |
3280 | { "f52", offsetof(CPUSPARCState, fpr[26]) }, | |
3281 | { "f54", offsetof(CPUSPARCState, fpr[27]) }, | |
3282 | { "f56", offsetof(CPUSPARCState, fpr[28]) }, | |
3283 | { "f58", offsetof(CPUSPARCState, fpr[29]) }, | |
3284 | { "f60", offsetof(CPUSPARCState, fpr[30]) }, | |
3285 | { "f62", offsetof(CPUSPARCState, fpr[31]) }, | |
3286 | { "asi", offsetof(CPUSPARCState, asi) }, | |
3287 | { "pstate", offsetof(CPUSPARCState, pstate) }, | |
3288 | { "cansave", offsetof(CPUSPARCState, cansave) }, | |
3289 | { "canrestore", offsetof(CPUSPARCState, canrestore) }, | |
3290 | { "otherwin", offsetof(CPUSPARCState, otherwin) }, | |
3291 | { "wstate", offsetof(CPUSPARCState, wstate) }, | |
3292 | { "cleanwin", offsetof(CPUSPARCState, cleanwin) }, | |
3293 | { "fprs", offsetof(CPUSPARCState, fprs) }, | |
7b936c0c | 3294 | #endif |
9307c4c1 FB |
3295 | #endif |
3296 | { NULL }, | |
3297 | }; | |
3298 | ||
9c3175cc SW |
3299 | static void GCC_FMT_ATTR(2, 3) QEMU_NORETURN |
3300 | expr_error(Monitor *mon, const char *fmt, ...) | |
9dc39cba | 3301 | { |
277acfe8 FZ |
3302 | va_list ap; |
3303 | va_start(ap, fmt); | |
3304 | monitor_vprintf(mon, fmt, ap); | |
3305 | monitor_printf(mon, "\n"); | |
3306 | va_end(ap); | |
6ab7e546 | 3307 | siglongjmp(expr_env, 1); |
9307c4c1 FB |
3308 | } |
3309 | ||
09b9418c | 3310 | /* return 0 if OK, -1 if not found */ |
92a31b1f | 3311 | static int get_monitor_def(target_long *pval, const char *name) |
9307c4c1 | 3312 | { |
8662d656 | 3313 | const MonitorDef *md; |
92a31b1f FB |
3314 | void *ptr; |
3315 | ||
9307c4c1 FB |
3316 | for(md = monitor_defs; md->name != NULL; md++) { |
3317 | if (compare_cmd(name, md->name)) { | |
3318 | if (md->get_value) { | |
e95c8d51 | 3319 | *pval = md->get_value(md, md->offset); |
9307c4c1 | 3320 | } else { |
9349b4f9 | 3321 | CPUArchState *env = mon_get_cpu(); |
6a00d601 | 3322 | ptr = (uint8_t *)env + md->offset; |
92a31b1f FB |
3323 | switch(md->type) { |
3324 | case MD_I32: | |
3325 | *pval = *(int32_t *)ptr; | |
3326 | break; | |
3327 | case MD_TLONG: | |
3328 | *pval = *(target_long *)ptr; | |
3329 | break; | |
3330 | default: | |
3331 | *pval = 0; | |
3332 | break; | |
3333 | } | |
9307c4c1 FB |
3334 | } |
3335 | return 0; | |
3336 | } | |
3337 | } | |
3338 | return -1; | |
3339 | } | |
3340 | ||
3341 | static void next(void) | |
3342 | { | |
660f11be | 3343 | if (*pch != '\0') { |
9307c4c1 | 3344 | pch++; |
cd390083 | 3345 | while (qemu_isspace(*pch)) |
9307c4c1 FB |
3346 | pch++; |
3347 | } | |
3348 | } | |
3349 | ||
376253ec | 3350 | static int64_t expr_sum(Monitor *mon); |
9307c4c1 | 3351 | |
376253ec | 3352 | static int64_t expr_unary(Monitor *mon) |
9307c4c1 | 3353 | { |
c2efc95d | 3354 | int64_t n; |
9307c4c1 | 3355 | char *p; |
6a00d601 | 3356 | int ret; |
9307c4c1 FB |
3357 | |
3358 | switch(*pch) { | |
3359 | case '+': | |
3360 | next(); | |
376253ec | 3361 | n = expr_unary(mon); |
9307c4c1 FB |
3362 | break; |
3363 | case '-': | |
3364 | next(); | |
376253ec | 3365 | n = -expr_unary(mon); |
9307c4c1 FB |
3366 | break; |
3367 | case '~': | |
3368 | next(); | |
376253ec | 3369 | n = ~expr_unary(mon); |
9307c4c1 FB |
3370 | break; |
3371 | case '(': | |
3372 | next(); | |
376253ec | 3373 | n = expr_sum(mon); |
9307c4c1 | 3374 | if (*pch != ')') { |
376253ec | 3375 | expr_error(mon, "')' expected"); |
9307c4c1 FB |
3376 | } |
3377 | next(); | |
3378 | break; | |
81d0912d FB |
3379 | case '\'': |
3380 | pch++; | |
3381 | if (*pch == '\0') | |
376253ec | 3382 | expr_error(mon, "character constant expected"); |
81d0912d FB |
3383 | n = *pch; |
3384 | pch++; | |
3385 | if (*pch != '\'') | |
376253ec | 3386 | expr_error(mon, "missing terminating \' character"); |
81d0912d FB |
3387 | next(); |
3388 | break; | |
9307c4c1 FB |
3389 | case '$': |
3390 | { | |
3391 | char buf[128], *q; | |
69b34976 | 3392 | target_long reg=0; |
3b46e624 | 3393 | |
9307c4c1 FB |
3394 | pch++; |
3395 | q = buf; | |
3396 | while ((*pch >= 'a' && *pch <= 'z') || | |
3397 | (*pch >= 'A' && *pch <= 'Z') || | |
3398 | (*pch >= '0' && *pch <= '9') || | |
57206fd4 | 3399 | *pch == '_' || *pch == '.') { |
9307c4c1 FB |
3400 | if ((q - buf) < sizeof(buf) - 1) |
3401 | *q++ = *pch; | |
3402 | pch++; | |
3403 | } | |
cd390083 | 3404 | while (qemu_isspace(*pch)) |
9307c4c1 FB |
3405 | pch++; |
3406 | *q = 0; | |
7743e588 | 3407 | ret = get_monitor_def(®, buf); |
09b9418c | 3408 | if (ret < 0) |
376253ec | 3409 | expr_error(mon, "unknown register"); |
7743e588 | 3410 | n = reg; |
9307c4c1 FB |
3411 | } |
3412 | break; | |
3413 | case '\0': | |
376253ec | 3414 | expr_error(mon, "unexpected end of expression"); |
9307c4c1 FB |
3415 | n = 0; |
3416 | break; | |
3417 | default: | |
6b0e33be | 3418 | errno = 0; |
4f4fbf77 | 3419 | n = strtoull(pch, &p, 0); |
6b0e33be LC |
3420 | if (errno == ERANGE) { |
3421 | expr_error(mon, "number too large"); | |
3422 | } | |
9307c4c1 | 3423 | if (pch == p) { |
277acfe8 | 3424 | expr_error(mon, "invalid char '%c' in expression", *p); |
9307c4c1 FB |
3425 | } |
3426 | pch = p; | |
cd390083 | 3427 | while (qemu_isspace(*pch)) |
9307c4c1 FB |
3428 | pch++; |
3429 | break; | |
3430 | } | |
3431 | return n; | |
3432 | } | |
3433 | ||
3434 | ||
376253ec | 3435 | static int64_t expr_prod(Monitor *mon) |
9307c4c1 | 3436 | { |
c2efc95d | 3437 | int64_t val, val2; |
92a31b1f | 3438 | int op; |
3b46e624 | 3439 | |
376253ec | 3440 | val = expr_unary(mon); |
9307c4c1 FB |
3441 | for(;;) { |
3442 | op = *pch; | |
3443 | if (op != '*' && op != '/' && op != '%') | |
3444 | break; | |
3445 | next(); | |
376253ec | 3446 | val2 = expr_unary(mon); |
9307c4c1 FB |
3447 | switch(op) { |
3448 | default: | |
3449 | case '*': | |
3450 | val *= val2; | |
3451 | break; | |
3452 | case '/': | |
3453 | case '%': | |
5fafdf24 | 3454 | if (val2 == 0) |
376253ec | 3455 | expr_error(mon, "division by zero"); |
9307c4c1 FB |
3456 | if (op == '/') |
3457 | val /= val2; | |
3458 | else | |
3459 | val %= val2; | |
3460 | break; | |
3461 | } | |
3462 | } | |
3463 | return val; | |
3464 | } | |
3465 | ||
376253ec | 3466 | static int64_t expr_logic(Monitor *mon) |
9307c4c1 | 3467 | { |
c2efc95d | 3468 | int64_t val, val2; |
92a31b1f | 3469 | int op; |
9307c4c1 | 3470 | |
376253ec | 3471 | val = expr_prod(mon); |
9307c4c1 FB |
3472 | for(;;) { |
3473 | op = *pch; | |
3474 | if (op != '&' && op != '|' && op != '^') | |
3475 | break; | |
3476 | next(); | |
376253ec | 3477 | val2 = expr_prod(mon); |
9307c4c1 FB |
3478 | switch(op) { |
3479 | default: | |
3480 | case '&': | |
3481 | val &= val2; | |
3482 | break; | |
3483 | case '|': | |
3484 | val |= val2; | |
3485 | break; | |
3486 | case '^': | |
3487 | val ^= val2; | |
3488 | break; | |
3489 | } | |
3490 | } | |
3491 | return val; | |
3492 | } | |
3493 | ||
376253ec | 3494 | static int64_t expr_sum(Monitor *mon) |
9307c4c1 | 3495 | { |
c2efc95d | 3496 | int64_t val, val2; |
92a31b1f | 3497 | int op; |
9307c4c1 | 3498 | |
376253ec | 3499 | val = expr_logic(mon); |
9307c4c1 FB |
3500 | for(;;) { |
3501 | op = *pch; | |
3502 | if (op != '+' && op != '-') | |
3503 | break; | |
3504 | next(); | |
376253ec | 3505 | val2 = expr_logic(mon); |
9307c4c1 FB |
3506 | if (op == '+') |
3507 | val += val2; | |
3508 | else | |
3509 | val -= val2; | |
3510 | } | |
3511 | return val; | |
3512 | } | |
3513 | ||
376253ec | 3514 | static int get_expr(Monitor *mon, int64_t *pval, const char **pp) |
9307c4c1 FB |
3515 | { |
3516 | pch = *pp; | |
6ab7e546 | 3517 | if (sigsetjmp(expr_env, 0)) { |
9307c4c1 FB |
3518 | *pp = pch; |
3519 | return -1; | |
3520 | } | |
cd390083 | 3521 | while (qemu_isspace(*pch)) |
9307c4c1 | 3522 | pch++; |
376253ec | 3523 | *pval = expr_sum(mon); |
9307c4c1 FB |
3524 | *pp = pch; |
3525 | return 0; | |
3526 | } | |
3527 | ||
3350a4dd MA |
3528 | static int get_double(Monitor *mon, double *pval, const char **pp) |
3529 | { | |
3530 | const char *p = *pp; | |
3531 | char *tailp; | |
3532 | double d; | |
3533 | ||
3534 | d = strtod(p, &tailp); | |
3535 | if (tailp == p) { | |
3536 | monitor_printf(mon, "Number expected\n"); | |
3537 | return -1; | |
3538 | } | |
3539 | if (d != d || d - d != 0) { | |
3540 | /* NaN or infinity */ | |
3541 | monitor_printf(mon, "Bad number\n"); | |
3542 | return -1; | |
3543 | } | |
3544 | *pval = d; | |
3545 | *pp = tailp; | |
3546 | return 0; | |
3547 | } | |
3548 | ||
4590fd80 LC |
3549 | /* |
3550 | * Store the command-name in cmdname, and return a pointer to | |
3551 | * the remaining of the command string. | |
3552 | */ | |
3553 | static const char *get_command_name(const char *cmdline, | |
3554 | char *cmdname, size_t nlen) | |
3555 | { | |
3556 | size_t len; | |
3557 | const char *p, *pstart; | |
3558 | ||
3559 | p = cmdline; | |
3560 | while (qemu_isspace(*p)) | |
3561 | p++; | |
3562 | if (*p == '\0') | |
3563 | return NULL; | |
3564 | pstart = p; | |
3565 | while (*p != '\0' && *p != '/' && !qemu_isspace(*p)) | |
3566 | p++; | |
3567 | len = p - pstart; | |
3568 | if (len > nlen - 1) | |
3569 | len = nlen - 1; | |
3570 | memcpy(cmdname, pstart, len); | |
3571 | cmdname[len] = '\0'; | |
3572 | return p; | |
3573 | } | |
3574 | ||
4d76d2ba LC |
3575 | /** |
3576 | * Read key of 'type' into 'key' and return the current | |
3577 | * 'type' pointer. | |
3578 | */ | |
3579 | static char *key_get_info(const char *type, char **key) | |
3580 | { | |
3581 | size_t len; | |
3582 | char *p, *str; | |
3583 | ||
3584 | if (*type == ',') | |
3585 | type++; | |
3586 | ||
3587 | p = strchr(type, ':'); | |
3588 | if (!p) { | |
3589 | *key = NULL; | |
3590 | return NULL; | |
3591 | } | |
3592 | len = p - type; | |
3593 | ||
7267c094 | 3594 | str = g_malloc(len + 1); |
4d76d2ba LC |
3595 | memcpy(str, type, len); |
3596 | str[len] = '\0'; | |
3597 | ||
3598 | *key = str; | |
3599 | return ++p; | |
3600 | } | |
3601 | ||
9307c4c1 FB |
3602 | static int default_fmt_format = 'x'; |
3603 | static int default_fmt_size = 4; | |
3604 | ||
fbc3d96c LS |
3605 | static int is_valid_option(const char *c, const char *typestr) |
3606 | { | |
3607 | char option[3]; | |
3608 | ||
3609 | option[0] = '-'; | |
3610 | option[1] = *c; | |
3611 | option[2] = '\0'; | |
3612 | ||
3613 | typestr = strstr(typestr, option); | |
3614 | return (typestr != NULL); | |
3615 | } | |
3616 | ||
945c5ac8 LC |
3617 | static const mon_cmd_t *search_dispatch_table(const mon_cmd_t *disp_table, |
3618 | const char *cmdname) | |
7fd669a1 LC |
3619 | { |
3620 | const mon_cmd_t *cmd; | |
3621 | ||
945c5ac8 | 3622 | for (cmd = disp_table; cmd->name != NULL; cmd++) { |
7fd669a1 LC |
3623 | if (compare_cmd(cmdname, cmd->name)) { |
3624 | return cmd; | |
3625 | } | |
3626 | } | |
3627 | ||
3628 | return NULL; | |
3629 | } | |
3630 | ||
bead3ce1 LC |
3631 | static const mon_cmd_t *qmp_find_cmd(const char *cmdname) |
3632 | { | |
f36b4afb | 3633 | return search_dispatch_table(qmp_cmds, cmdname); |
bead3ce1 LC |
3634 | } |
3635 | ||
5f3d335f WX |
3636 | /* |
3637 | * Parse @cmdline according to command table @table. | |
3638 | * If @cmdline is blank, return NULL. | |
3639 | * If it can't be parsed, report to @mon, and return NULL. | |
3640 | * Else, insert command arguments into @qdict, and return the command. | |
085d8134 PM |
3641 | * If a sub-command table exists, and if @cmdline contains an additional string |
3642 | * for a sub-command, this function will try to search the sub-command table. | |
3643 | * If no additional string for a sub-command is present, this function will | |
3644 | * return the command found in @table. | |
5f3d335f WX |
3645 | * Do not assume the returned command points into @table! It doesn't |
3646 | * when the command is a sub-command. | |
3647 | */ | |
c227f099 | 3648 | static const mon_cmd_t *monitor_parse_command(Monitor *mon, |
55f81d96 | 3649 | const char *cmdline, |
5f3d335f WX |
3650 | int start, |
3651 | mon_cmd_t *table, | |
55f81d96 | 3652 | QDict *qdict) |
9307c4c1 | 3653 | { |
4590fd80 | 3654 | const char *p, *typestr; |
53773581 | 3655 | int c; |
c227f099 | 3656 | const mon_cmd_t *cmd; |
9307c4c1 FB |
3657 | char cmdname[256]; |
3658 | char buf[1024]; | |
4d76d2ba | 3659 | char *key; |
9dc39cba | 3660 | |
9307c4c1 | 3661 | /* extract the command name */ |
5f3d335f | 3662 | p = get_command_name(cmdline + start, cmdname, sizeof(cmdname)); |
4590fd80 | 3663 | if (!p) |
55f81d96 | 3664 | return NULL; |
3b46e624 | 3665 | |
5f3d335f | 3666 | cmd = search_dispatch_table(table, cmdname); |
7fd669a1 | 3667 | if (!cmd) { |
5f3d335f WX |
3668 | monitor_printf(mon, "unknown command: '%.*s'\n", |
3669 | (int)(p - cmdline), cmdline); | |
55f81d96 | 3670 | return NULL; |
9307c4c1 | 3671 | } |
9307c4c1 | 3672 | |
5f3d335f WX |
3673 | /* filter out following useless space */ |
3674 | while (qemu_isspace(*p)) { | |
3675 | p++; | |
3676 | } | |
3677 | /* search sub command */ | |
3678 | if (cmd->sub_table != NULL) { | |
3679 | /* check if user set additional command */ | |
3680 | if (*p == '\0') { | |
3681 | return cmd; | |
3682 | } | |
3683 | return monitor_parse_command(mon, cmdline, p - cmdline, | |
3684 | cmd->sub_table, qdict); | |
3685 | } | |
3686 | ||
9307c4c1 FB |
3687 | /* parse the parameters */ |
3688 | typestr = cmd->args_type; | |
9dc39cba | 3689 | for(;;) { |
4d76d2ba LC |
3690 | typestr = key_get_info(typestr, &key); |
3691 | if (!typestr) | |
9dc39cba | 3692 | break; |
4d76d2ba | 3693 | c = *typestr; |
9307c4c1 FB |
3694 | typestr++; |
3695 | switch(c) { | |
3696 | case 'F': | |
81d0912d | 3697 | case 'B': |
9307c4c1 FB |
3698 | case 's': |
3699 | { | |
3700 | int ret; | |
3b46e624 | 3701 | |
cd390083 | 3702 | while (qemu_isspace(*p)) |
9307c4c1 FB |
3703 | p++; |
3704 | if (*typestr == '?') { | |
3705 | typestr++; | |
3706 | if (*p == '\0') { | |
3707 | /* no optional string: NULL argument */ | |
53773581 | 3708 | break; |
9307c4c1 FB |
3709 | } |
3710 | } | |
3711 | ret = get_str(buf, sizeof(buf), &p); | |
3712 | if (ret < 0) { | |
81d0912d FB |
3713 | switch(c) { |
3714 | case 'F': | |
376253ec AL |
3715 | monitor_printf(mon, "%s: filename expected\n", |
3716 | cmdname); | |
81d0912d FB |
3717 | break; |
3718 | case 'B': | |
376253ec AL |
3719 | monitor_printf(mon, "%s: block device name expected\n", |
3720 | cmdname); | |
81d0912d FB |
3721 | break; |
3722 | default: | |
376253ec | 3723 | monitor_printf(mon, "%s: string expected\n", cmdname); |
81d0912d FB |
3724 | break; |
3725 | } | |
9307c4c1 FB |
3726 | goto fail; |
3727 | } | |
53773581 | 3728 | qdict_put(qdict, key, qstring_from_str(buf)); |
9307c4c1 | 3729 | } |
9dc39cba | 3730 | break; |
361127df MA |
3731 | case 'O': |
3732 | { | |
3733 | QemuOptsList *opts_list; | |
3734 | QemuOpts *opts; | |
3735 | ||
3736 | opts_list = qemu_find_opts(key); | |
3737 | if (!opts_list || opts_list->desc->name) { | |
3738 | goto bad_type; | |
3739 | } | |
3740 | while (qemu_isspace(*p)) { | |
3741 | p++; | |
3742 | } | |
3743 | if (!*p) | |
3744 | break; | |
3745 | if (get_str(buf, sizeof(buf), &p) < 0) { | |
3746 | goto fail; | |
3747 | } | |
3748 | opts = qemu_opts_parse(opts_list, buf, 1); | |
3749 | if (!opts) { | |
3750 | goto fail; | |
3751 | } | |
3752 | qemu_opts_to_qdict(opts, qdict); | |
3753 | qemu_opts_del(opts); | |
3754 | } | |
3755 | break; | |
9307c4c1 FB |
3756 | case '/': |
3757 | { | |
3758 | int count, format, size; | |
3b46e624 | 3759 | |
cd390083 | 3760 | while (qemu_isspace(*p)) |
9307c4c1 FB |
3761 | p++; |
3762 | if (*p == '/') { | |
3763 | /* format found */ | |
3764 | p++; | |
3765 | count = 1; | |
cd390083 | 3766 | if (qemu_isdigit(*p)) { |
9307c4c1 | 3767 | count = 0; |
cd390083 | 3768 | while (qemu_isdigit(*p)) { |
9307c4c1 FB |
3769 | count = count * 10 + (*p - '0'); |
3770 | p++; | |
3771 | } | |
3772 | } | |
3773 | size = -1; | |
3774 | format = -1; | |
3775 | for(;;) { | |
3776 | switch(*p) { | |
3777 | case 'o': | |
3778 | case 'd': | |
3779 | case 'u': | |
3780 | case 'x': | |
3781 | case 'i': | |
3782 | case 'c': | |
3783 | format = *p++; | |
3784 | break; | |
3785 | case 'b': | |
3786 | size = 1; | |
3787 | p++; | |
3788 | break; | |
3789 | case 'h': | |
3790 | size = 2; | |
3791 | p++; | |
3792 | break; | |
3793 | case 'w': | |
3794 | size = 4; | |
3795 | p++; | |
3796 | break; | |
3797 | case 'g': | |
3798 | case 'L': | |
3799 | size = 8; | |
3800 | p++; | |
3801 | break; | |
3802 | default: | |
3803 | goto next; | |
3804 | } | |
3805 | } | |
3806 | next: | |
cd390083 | 3807 | if (*p != '\0' && !qemu_isspace(*p)) { |
376253ec AL |
3808 | monitor_printf(mon, "invalid char in format: '%c'\n", |
3809 | *p); | |
9307c4c1 FB |
3810 | goto fail; |
3811 | } | |
9307c4c1 FB |
3812 | if (format < 0) |
3813 | format = default_fmt_format; | |
4c27ba27 FB |
3814 | if (format != 'i') { |
3815 | /* for 'i', not specifying a size gives -1 as size */ | |
3816 | if (size < 0) | |
3817 | size = default_fmt_size; | |
e90f009b | 3818 | default_fmt_size = size; |
4c27ba27 | 3819 | } |
9307c4c1 FB |
3820 | default_fmt_format = format; |
3821 | } else { | |
3822 | count = 1; | |
3823 | format = default_fmt_format; | |
4c27ba27 FB |
3824 | if (format != 'i') { |
3825 | size = default_fmt_size; | |
3826 | } else { | |
3827 | size = -1; | |
3828 | } | |
9307c4c1 | 3829 | } |
f7188bbe LC |
3830 | qdict_put(qdict, "count", qint_from_int(count)); |
3831 | qdict_put(qdict, "format", qint_from_int(format)); | |
3832 | qdict_put(qdict, "size", qint_from_int(size)); | |
9307c4c1 | 3833 | } |
9dc39cba | 3834 | break; |
9307c4c1 | 3835 | case 'i': |
92a31b1f | 3836 | case 'l': |
b6e098d7 | 3837 | case 'M': |
9307c4c1 | 3838 | { |
c2efc95d | 3839 | int64_t val; |
7743e588 | 3840 | |
cd390083 | 3841 | while (qemu_isspace(*p)) |
9307c4c1 | 3842 | p++; |
3440557b | 3843 | if (*typestr == '?' || *typestr == '.') { |
3440557b | 3844 | if (*typestr == '?') { |
53773581 LC |
3845 | if (*p == '\0') { |
3846 | typestr++; | |
3847 | break; | |
3848 | } | |
3440557b FB |
3849 | } else { |
3850 | if (*p == '.') { | |
3851 | p++; | |
cd390083 | 3852 | while (qemu_isspace(*p)) |
3440557b | 3853 | p++; |
3440557b | 3854 | } else { |
53773581 LC |
3855 | typestr++; |
3856 | break; | |
3440557b FB |
3857 | } |
3858 | } | |
13224a87 | 3859 | typestr++; |
9307c4c1 | 3860 | } |
376253ec | 3861 | if (get_expr(mon, &val, &p)) |
9307c4c1 | 3862 | goto fail; |
675ebef9 LC |
3863 | /* Check if 'i' is greater than 32-bit */ |
3864 | if ((c == 'i') && ((val >> 32) & 0xffffffff)) { | |
3865 | monitor_printf(mon, "\'%s\' has failed: ", cmdname); | |
3866 | monitor_printf(mon, "integer is for 32-bit values\n"); | |
3867 | goto fail; | |
b6e098d7 | 3868 | } else if (c == 'M') { |
91162849 LC |
3869 | if (val < 0) { |
3870 | monitor_printf(mon, "enter a positive value\n"); | |
3871 | goto fail; | |
3872 | } | |
b6e098d7 | 3873 | val <<= 20; |
675ebef9 | 3874 | } |
53773581 | 3875 | qdict_put(qdict, key, qint_from_int(val)); |
9307c4c1 FB |
3876 | } |
3877 | break; | |
dbc0c67f JS |
3878 | case 'o': |
3879 | { | |
70b4f4bb | 3880 | int64_t val; |
dbc0c67f JS |
3881 | char *end; |
3882 | ||
3883 | while (qemu_isspace(*p)) { | |
3884 | p++; | |
3885 | } | |
3886 | if (*typestr == '?') { | |
3887 | typestr++; | |
3888 | if (*p == '\0') { | |
3889 | break; | |
3890 | } | |
3891 | } | |
3892 | val = strtosz(p, &end); | |
3893 | if (val < 0) { | |
3894 | monitor_printf(mon, "invalid size\n"); | |
3895 | goto fail; | |
3896 | } | |
3897 | qdict_put(qdict, key, qint_from_int(val)); | |
3898 | p = end; | |
3899 | } | |
3900 | break; | |
fccfb11e | 3901 | case 'T': |
3350a4dd MA |
3902 | { |
3903 | double val; | |
3904 | ||
3905 | while (qemu_isspace(*p)) | |
3906 | p++; | |
3907 | if (*typestr == '?') { | |
3908 | typestr++; | |
3909 | if (*p == '\0') { | |
3910 | break; | |
3911 | } | |
3912 | } | |
3913 | if (get_double(mon, &val, &p) < 0) { | |
3914 | goto fail; | |
3915 | } | |
07de3e60 | 3916 | if (p[0] && p[1] == 's') { |
fccfb11e MA |
3917 | switch (*p) { |
3918 | case 'm': | |
3919 | val /= 1e3; p += 2; break; | |
3920 | case 'u': | |
3921 | val /= 1e6; p += 2; break; | |
3922 | case 'n': | |
3923 | val /= 1e9; p += 2; break; | |
3924 | } | |
3925 | } | |
3350a4dd MA |
3926 | if (*p && !qemu_isspace(*p)) { |
3927 | monitor_printf(mon, "Unknown unit suffix\n"); | |
3928 | goto fail; | |
3929 | } | |
3930 | qdict_put(qdict, key, qfloat_from_double(val)); | |
3931 | } | |
3932 | break; | |
942cd1f2 MA |
3933 | case 'b': |
3934 | { | |
3935 | const char *beg; | |
fc48ffc3 | 3936 | bool val; |
942cd1f2 MA |
3937 | |
3938 | while (qemu_isspace(*p)) { | |
3939 | p++; | |
3940 | } | |
3941 | beg = p; | |
3942 | while (qemu_isgraph(*p)) { | |
3943 | p++; | |
3944 | } | |
3945 | if (p - beg == 2 && !memcmp(beg, "on", p - beg)) { | |
fc48ffc3 | 3946 | val = true; |
942cd1f2 | 3947 | } else if (p - beg == 3 && !memcmp(beg, "off", p - beg)) { |
fc48ffc3 | 3948 | val = false; |
942cd1f2 MA |
3949 | } else { |
3950 | monitor_printf(mon, "Expected 'on' or 'off'\n"); | |
3951 | goto fail; | |
3952 | } | |
fc48ffc3 | 3953 | qdict_put(qdict, key, qbool_from_bool(val)); |
942cd1f2 MA |
3954 | } |
3955 | break; | |
9307c4c1 FB |
3956 | case '-': |
3957 | { | |
fbc3d96c | 3958 | const char *tmp = p; |
eb159d13 | 3959 | int skip_key = 0; |
9307c4c1 | 3960 | /* option */ |
3b46e624 | 3961 | |
9307c4c1 FB |
3962 | c = *typestr++; |
3963 | if (c == '\0') | |
3964 | goto bad_type; | |
cd390083 | 3965 | while (qemu_isspace(*p)) |
9307c4c1 | 3966 | p++; |
9307c4c1 FB |
3967 | if (*p == '-') { |
3968 | p++; | |
fbc3d96c LS |
3969 | if(c != *p) { |
3970 | if(!is_valid_option(p, typestr)) { | |
3971 | ||
3972 | monitor_printf(mon, "%s: unsupported option -%c\n", | |
3973 | cmdname, *p); | |
3974 | goto fail; | |
3975 | } else { | |
3976 | skip_key = 1; | |
3977 | } | |
3978 | } | |
3979 | if(skip_key) { | |
3980 | p = tmp; | |
3981 | } else { | |
eb159d13 | 3982 | /* has option */ |
fbc3d96c | 3983 | p++; |
fc48ffc3 | 3984 | qdict_put(qdict, key, qbool_from_bool(true)); |
9307c4c1 | 3985 | } |
9307c4c1 | 3986 | } |
9307c4c1 FB |
3987 | } |
3988 | break; | |
129be006 WX |
3989 | case 'S': |
3990 | { | |
3991 | /* package all remaining string */ | |
3992 | int len; | |
3993 | ||
3994 | while (qemu_isspace(*p)) { | |
3995 | p++; | |
3996 | } | |
3997 | if (*typestr == '?') { | |
3998 | typestr++; | |
3999 | if (*p == '\0') { | |
4000 | /* no remaining string: NULL argument */ | |
4001 | break; | |
4002 | } | |
4003 | } | |
4004 | len = strlen(p); | |
4005 | if (len <= 0) { | |
4006 | monitor_printf(mon, "%s: string expected\n", | |
4007 | cmdname); | |
4008 | break; | |
4009 | } | |
4010 | qdict_put(qdict, key, qstring_from_str(p)); | |
4011 | p += len; | |
4012 | } | |
4013 | break; | |
9307c4c1 FB |
4014 | default: |
4015 | bad_type: | |
376253ec | 4016 | monitor_printf(mon, "%s: unknown type '%c'\n", cmdname, c); |
9307c4c1 FB |
4017 | goto fail; |
4018 | } | |
7267c094 | 4019 | g_free(key); |
4d76d2ba | 4020 | key = NULL; |
9dc39cba | 4021 | } |
9307c4c1 | 4022 | /* check that all arguments were parsed */ |
cd390083 | 4023 | while (qemu_isspace(*p)) |
9307c4c1 FB |
4024 | p++; |
4025 | if (*p != '\0') { | |
376253ec AL |
4026 | monitor_printf(mon, "%s: extraneous characters at the end of line\n", |
4027 | cmdname); | |
9307c4c1 | 4028 | goto fail; |
9dc39cba | 4029 | } |
9307c4c1 | 4030 | |
55f81d96 | 4031 | return cmd; |
ac7531ec | 4032 | |
55f81d96 | 4033 | fail: |
7267c094 | 4034 | g_free(key); |
55f81d96 LC |
4035 | return NULL; |
4036 | } | |
4037 | ||
d6f46833 MA |
4038 | void monitor_set_error(Monitor *mon, QError *qerror) |
4039 | { | |
4040 | /* report only the first error */ | |
4041 | if (!mon->error) { | |
4042 | mon->error = qerror; | |
4043 | } else { | |
d6f46833 MA |
4044 | QDECREF(qerror); |
4045 | } | |
4046 | } | |
4047 | ||
7ef6cf63 | 4048 | static void handle_hmp_command(Monitor *mon, const char *cmdline) |
55f81d96 | 4049 | { |
55f81d96 | 4050 | QDict *qdict; |
c227f099 | 4051 | const mon_cmd_t *cmd; |
55f81d96 LC |
4052 | |
4053 | qdict = qdict_new(); | |
4054 | ||
7717239d | 4055 | cmd = monitor_parse_command(mon, cmdline, 0, mon->cmd_table, qdict); |
8a4f501c | 4056 | if (cmd) { |
af4ce882 | 4057 | cmd->mhandler.cmd(mon, qdict); |
55f81d96 LC |
4058 | } |
4059 | ||
f7188bbe | 4060 | QDECREF(qdict); |
9dc39cba FB |
4061 | } |
4062 | ||
cd5c6bba | 4063 | static void cmd_completion(Monitor *mon, const char *name, const char *list) |
81d0912d FB |
4064 | { |
4065 | const char *p, *pstart; | |
4066 | char cmd[128]; | |
4067 | int len; | |
4068 | ||
4069 | p = list; | |
4070 | for(;;) { | |
4071 | pstart = p; | |
4072 | p = strchr(p, '|'); | |
4073 | if (!p) | |
4074 | p = pstart + strlen(pstart); | |
4075 | len = p - pstart; | |
4076 | if (len > sizeof(cmd) - 2) | |
4077 | len = sizeof(cmd) - 2; | |
4078 | memcpy(cmd, pstart, len); | |
4079 | cmd[len] = '\0'; | |
4080 | if (name[0] == '\0' || !strncmp(name, cmd, strlen(name))) { | |
cd5c6bba | 4081 | readline_add_completion(mon->rs, cmd); |
81d0912d FB |
4082 | } |
4083 | if (*p == '\0') | |
4084 | break; | |
4085 | p++; | |
4086 | } | |
4087 | } | |
4088 | ||
cb8f68b1 | 4089 | static void file_completion(Monitor *mon, const char *input) |
81d0912d FB |
4090 | { |
4091 | DIR *ffs; | |
4092 | struct dirent *d; | |
4093 | char path[1024]; | |
4094 | char file[1024], file_prefix[1024]; | |
4095 | int input_path_len; | |
4096 | const char *p; | |
4097 | ||
5fafdf24 | 4098 | p = strrchr(input, '/'); |
81d0912d FB |
4099 | if (!p) { |
4100 | input_path_len = 0; | |
4101 | pstrcpy(file_prefix, sizeof(file_prefix), input); | |
363a37d5 | 4102 | pstrcpy(path, sizeof(path), "."); |
81d0912d FB |
4103 | } else { |
4104 | input_path_len = p - input + 1; | |
4105 | memcpy(path, input, input_path_len); | |
4106 | if (input_path_len > sizeof(path) - 1) | |
4107 | input_path_len = sizeof(path) - 1; | |
4108 | path[input_path_len] = '\0'; | |
4109 | pstrcpy(file_prefix, sizeof(file_prefix), p + 1); | |
4110 | } | |
19f2db5c | 4111 | |
81d0912d FB |
4112 | ffs = opendir(path); |
4113 | if (!ffs) | |
4114 | return; | |
4115 | for(;;) { | |
4116 | struct stat sb; | |
4117 | d = readdir(ffs); | |
4118 | if (!d) | |
4119 | break; | |
46c7fc18 KK |
4120 | |
4121 | if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) { | |
4122 | continue; | |
4123 | } | |
4124 | ||
81d0912d FB |
4125 | if (strstart(d->d_name, file_prefix, NULL)) { |
4126 | memcpy(file, input, input_path_len); | |
363a37d5 BS |
4127 | if (input_path_len < sizeof(file)) |
4128 | pstrcpy(file + input_path_len, sizeof(file) - input_path_len, | |
4129 | d->d_name); | |
81d0912d FB |
4130 | /* stat the file to find out if it's a directory. |
4131 | * In that case add a slash to speed up typing long paths | |
4132 | */ | |
c951d9a6 | 4133 | if (stat(file, &sb) == 0 && S_ISDIR(sb.st_mode)) { |
363a37d5 | 4134 | pstrcat(file, sizeof(file), "/"); |
c951d9a6 | 4135 | } |
cb8f68b1 | 4136 | readline_add_completion(mon->rs, file); |
81d0912d FB |
4137 | } |
4138 | } | |
4139 | closedir(ffs); | |
4140 | } | |
4141 | ||
4d76d2ba LC |
4142 | static const char *next_arg_type(const char *typestr) |
4143 | { | |
4144 | const char *p = strchr(typestr, ':'); | |
4145 | return (p != NULL ? ++p : typestr); | |
4146 | } | |
4147 | ||
40d19394 HB |
4148 | static void add_completion_option(ReadLineState *rs, const char *str, |
4149 | const char *option) | |
4150 | { | |
4151 | if (!str || !option) { | |
4152 | return; | |
4153 | } | |
4154 | if (!strncmp(option, str, strlen(str))) { | |
4155 | readline_add_completion(rs, option); | |
4156 | } | |
4157 | } | |
4158 | ||
13e315da HB |
4159 | void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str) |
4160 | { | |
4161 | size_t len; | |
4162 | ChardevBackendInfoList *list, *start; | |
4163 | ||
4164 | if (nb_args != 2) { | |
4165 | return; | |
4166 | } | |
4167 | len = strlen(str); | |
4168 | readline_set_completion_index(rs, len); | |
4169 | ||
4170 | start = list = qmp_query_chardev_backends(NULL); | |
4171 | while (list) { | |
4172 | const char *chr_name = list->value->name; | |
4173 | ||
4174 | if (!strncmp(chr_name, str, len)) { | |
4175 | readline_add_completion(rs, chr_name); | |
4176 | } | |
4177 | list = list->next; | |
4178 | } | |
4179 | qapi_free_ChardevBackendInfoList(start); | |
4180 | } | |
4181 | ||
b162b49a HB |
4182 | void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str) |
4183 | { | |
4184 | size_t len; | |
4185 | int i; | |
4186 | ||
4187 | if (nb_args != 2) { | |
4188 | return; | |
4189 | } | |
4190 | len = strlen(str); | |
4191 | readline_set_completion_index(rs, len); | |
4192 | for (i = 0; NetClientOptionsKind_lookup[i]; i++) { | |
4193 | add_completion_option(rs, str, NetClientOptionsKind_lookup[i]); | |
4194 | } | |
4195 | } | |
4196 | ||
2da1b3ab | 4197 | void device_add_completion(ReadLineState *rs, int nb_args, const char *str) |
992d3e64 HB |
4198 | { |
4199 | GSList *list, *elt; | |
4200 | size_t len; | |
4201 | ||
2da1b3ab HB |
4202 | if (nb_args != 2) { |
4203 | return; | |
4204 | } | |
4205 | ||
992d3e64 HB |
4206 | len = strlen(str); |
4207 | readline_set_completion_index(rs, len); | |
4208 | list = elt = object_class_get_list(TYPE_DEVICE, false); | |
4209 | while (elt) { | |
4210 | const char *name; | |
4211 | DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, elt->data, | |
4212 | TYPE_DEVICE); | |
4213 | name = object_class_get_name(OBJECT_CLASS(dc)); | |
2da1b3ab HB |
4214 | |
4215 | if (!dc->cannot_instantiate_with_device_add_yet | |
4216 | && !strncmp(name, str, len)) { | |
992d3e64 HB |
4217 | readline_add_completion(rs, name); |
4218 | } | |
4219 | elt = elt->next; | |
4220 | } | |
4221 | g_slist_free(list); | |
4222 | } | |
4223 | ||
bfa40f77 | 4224 | void object_add_completion(ReadLineState *rs, int nb_args, const char *str) |
1094fd3a HB |
4225 | { |
4226 | GSList *list, *elt; | |
4227 | size_t len; | |
4228 | ||
bfa40f77 HB |
4229 | if (nb_args != 2) { |
4230 | return; | |
4231 | } | |
4232 | ||
1094fd3a HB |
4233 | len = strlen(str); |
4234 | readline_set_completion_index(rs, len); | |
4235 | list = elt = object_class_get_list(TYPE_USER_CREATABLE, false); | |
4236 | while (elt) { | |
4237 | const char *name; | |
4238 | ||
4239 | name = object_class_get_name(OBJECT_CLASS(elt->data)); | |
4240 | if (!strncmp(name, str, len) && strcmp(name, TYPE_USER_CREATABLE)) { | |
4241 | readline_add_completion(rs, name); | |
4242 | } | |
4243 | elt = elt->next; | |
4244 | } | |
4245 | g_slist_free(list); | |
4246 | } | |
4247 | ||
6a1fa9f5 ZG |
4248 | static void peripheral_device_del_completion(ReadLineState *rs, |
4249 | const char *str, size_t len) | |
4250 | { | |
4cae4d5a MA |
4251 | Object *peripheral = container_get(qdev_get_machine(), "/peripheral"); |
4252 | GSList *list, *item; | |
6a1fa9f5 | 4253 | |
4cae4d5a MA |
4254 | list = qdev_build_hotpluggable_device_list(peripheral); |
4255 | if (!list) { | |
6a1fa9f5 ZG |
4256 | return; |
4257 | } | |
4258 | ||
6a1fa9f5 ZG |
4259 | for (item = list; item; item = g_slist_next(item)) { |
4260 | DeviceState *dev = item->data; | |
4261 | ||
4262 | if (dev->id && !strncmp(str, dev->id, len)) { | |
4263 | readline_add_completion(rs, dev->id); | |
4264 | } | |
4265 | } | |
4266 | ||
4267 | g_slist_free(list); | |
4268 | } | |
4269 | ||
6297d9a2 HB |
4270 | void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str) |
4271 | { | |
4272 | size_t len; | |
4273 | ChardevInfoList *list, *start; | |
4274 | ||
4275 | if (nb_args != 2) { | |
4276 | return; | |
4277 | } | |
4278 | len = strlen(str); | |
4279 | readline_set_completion_index(rs, len); | |
4280 | ||
4281 | start = list = qmp_query_chardev(NULL); | |
4282 | while (list) { | |
4283 | ChardevInfo *chr = list->value; | |
4284 | ||
4285 | if (!strncmp(chr->label, str, len)) { | |
4286 | readline_add_completion(rs, chr->label); | |
4287 | } | |
4288 | list = list->next; | |
4289 | } | |
4290 | qapi_free_ChardevInfoList(start); | |
4291 | } | |
4292 | ||
8e597779 HB |
4293 | static void ringbuf_completion(ReadLineState *rs, const char *str) |
4294 | { | |
4295 | size_t len; | |
4296 | ChardevInfoList *list, *start; | |
4297 | ||
4298 | len = strlen(str); | |
4299 | readline_set_completion_index(rs, len); | |
4300 | ||
4301 | start = list = qmp_query_chardev(NULL); | |
4302 | while (list) { | |
4303 | ChardevInfo *chr_info = list->value; | |
4304 | ||
4305 | if (!strncmp(chr_info->label, str, len)) { | |
4306 | CharDriverState *chr = qemu_chr_find(chr_info->label); | |
4307 | if (chr && chr_is_ringbuf(chr)) { | |
4308 | readline_add_completion(rs, chr_info->label); | |
4309 | } | |
4310 | } | |
4311 | list = list->next; | |
4312 | } | |
4313 | qapi_free_ChardevInfoList(start); | |
4314 | } | |
4315 | ||
8e597779 HB |
4316 | void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str) |
4317 | { | |
4318 | if (nb_args != 2) { | |
4319 | return; | |
4320 | } | |
4321 | ringbuf_completion(rs, str); | |
4322 | } | |
4323 | ||
2da1b3ab HB |
4324 | void device_del_completion(ReadLineState *rs, int nb_args, const char *str) |
4325 | { | |
4326 | size_t len; | |
4327 | ||
4328 | if (nb_args != 2) { | |
4329 | return; | |
4330 | } | |
4331 | ||
4332 | len = strlen(str); | |
4333 | readline_set_completion_index(rs, len); | |
6a1fa9f5 | 4334 | peripheral_device_del_completion(rs, str, len); |
2da1b3ab HB |
4335 | } |
4336 | ||
bfa40f77 | 4337 | void object_del_completion(ReadLineState *rs, int nb_args, const char *str) |
b48fa074 HB |
4338 | { |
4339 | ObjectPropertyInfoList *list, *start; | |
4340 | size_t len; | |
4341 | ||
bfa40f77 HB |
4342 | if (nb_args != 2) { |
4343 | return; | |
4344 | } | |
b48fa074 HB |
4345 | len = strlen(str); |
4346 | readline_set_completion_index(rs, len); | |
4347 | ||
4348 | start = list = qmp_qom_list("/objects", NULL); | |
4349 | while (list) { | |
4350 | ObjectPropertyInfo *info = list->value; | |
4351 | ||
4352 | if (!strncmp(info->type, "child<", 5) | |
4353 | && !strncmp(info->name, str, len)) { | |
4354 | readline_add_completion(rs, info->name); | |
4355 | } | |
4356 | list = list->next; | |
4357 | } | |
4358 | qapi_free_ObjectPropertyInfoList(start); | |
4359 | } | |
4360 | ||
29136cd8 HB |
4361 | void sendkey_completion(ReadLineState *rs, int nb_args, const char *str) |
4362 | { | |
4363 | int i; | |
4364 | char *sep; | |
4365 | size_t len; | |
4366 | ||
4367 | if (nb_args != 2) { | |
4368 | return; | |
4369 | } | |
4370 | sep = strrchr(str, '-'); | |
4371 | if (sep) { | |
4372 | str = sep + 1; | |
4373 | } | |
4374 | len = strlen(str); | |
4375 | readline_set_completion_index(rs, len); | |
4376 | for (i = 0; i < Q_KEY_CODE_MAX; i++) { | |
4377 | if (!strncmp(str, QKeyCode_lookup[i], len)) { | |
4378 | readline_add_completion(rs, QKeyCode_lookup[i]); | |
4379 | } | |
4380 | } | |
4381 | } | |
4382 | ||
40d19394 HB |
4383 | void set_link_completion(ReadLineState *rs, int nb_args, const char *str) |
4384 | { | |
4385 | size_t len; | |
4386 | ||
4387 | len = strlen(str); | |
4388 | readline_set_completion_index(rs, len); | |
4389 | if (nb_args == 2) { | |
eaed483c | 4390 | NetClientState *ncs[MAX_QUEUE_NUM]; |
40d19394 HB |
4391 | int count, i; |
4392 | count = qemu_find_net_clients_except(NULL, ncs, | |
eaed483c JW |
4393 | NET_CLIENT_OPTIONS_KIND_NONE, |
4394 | MAX_QUEUE_NUM); | |
bcfa4d60 | 4395 | for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) { |
40d19394 HB |
4396 | const char *name = ncs[i]->name; |
4397 | if (!strncmp(str, name, len)) { | |
4398 | readline_add_completion(rs, name); | |
4399 | } | |
4400 | } | |
4401 | } else if (nb_args == 3) { | |
4402 | add_completion_option(rs, str, "on"); | |
4403 | add_completion_option(rs, str, "off"); | |
4404 | } | |
4405 | } | |
4406 | ||
11b389f2 HB |
4407 | void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str) |
4408 | { | |
4409 | int len, count, i; | |
eaed483c | 4410 | NetClientState *ncs[MAX_QUEUE_NUM]; |
11b389f2 HB |
4411 | |
4412 | if (nb_args != 2) { | |
4413 | return; | |
4414 | } | |
4415 | ||
4416 | len = strlen(str); | |
4417 | readline_set_completion_index(rs, len); | |
4418 | count = qemu_find_net_clients_except(NULL, ncs, NET_CLIENT_OPTIONS_KIND_NIC, | |
eaed483c | 4419 | MAX_QUEUE_NUM); |
bcfa4d60 | 4420 | for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) { |
11b389f2 HB |
4421 | QemuOpts *opts; |
4422 | const char *name = ncs[i]->name; | |
4423 | if (strncmp(str, name, len)) { | |
4424 | continue; | |
4425 | } | |
4426 | opts = qemu_opts_find(qemu_find_opts_err("netdev", NULL), name); | |
4427 | if (opts) { | |
4428 | readline_add_completion(rs, name); | |
4429 | } | |
4430 | } | |
4431 | } | |
4432 | ||
d0ece345 HB |
4433 | void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str) |
4434 | { | |
4bb08af3 HB |
4435 | int i; |
4436 | ||
d0ece345 HB |
4437 | if (nb_args != 2) { |
4438 | return; | |
4439 | } | |
4440 | readline_set_completion_index(rs, strlen(str)); | |
4bb08af3 HB |
4441 | for (i = 0; WatchdogExpirationAction_lookup[i]; i++) { |
4442 | add_completion_option(rs, str, WatchdogExpirationAction_lookup[i]); | |
4443 | } | |
d0ece345 HB |
4444 | } |
4445 | ||
c68a0409 HB |
4446 | void migrate_set_capability_completion(ReadLineState *rs, int nb_args, |
4447 | const char *str) | |
4448 | { | |
4449 | size_t len; | |
4450 | ||
4451 | len = strlen(str); | |
4452 | readline_set_completion_index(rs, len); | |
4453 | if (nb_args == 2) { | |
4454 | int i; | |
4455 | for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) { | |
4456 | const char *name = MigrationCapability_lookup[i]; | |
4457 | if (!strncmp(str, name, len)) { | |
4458 | readline_add_completion(rs, name); | |
4459 | } | |
4460 | } | |
4461 | } else if (nb_args == 3) { | |
4462 | add_completion_option(rs, str, "on"); | |
4463 | add_completion_option(rs, str, "off"); | |
4464 | } | |
4465 | } | |
4466 | ||
50e9a629 LL |
4467 | void migrate_set_parameter_completion(ReadLineState *rs, int nb_args, |
4468 | const char *str) | |
4469 | { | |
4470 | size_t len; | |
4471 | ||
4472 | len = strlen(str); | |
4473 | readline_set_completion_index(rs, len); | |
4474 | if (nb_args == 2) { | |
4475 | int i; | |
4476 | for (i = 0; i < MIGRATION_PARAMETER_MAX; i++) { | |
4477 | const char *name = MigrationParameter_lookup[i]; | |
4478 | if (!strncmp(str, name, len)) { | |
4479 | readline_add_completion(rs, name); | |
4480 | } | |
4481 | } | |
4482 | } | |
4483 | } | |
4484 | ||
e3bb532c HB |
4485 | void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str) |
4486 | { | |
4487 | int i; | |
4488 | size_t len; | |
4489 | if (nb_args != 2) { | |
4490 | return; | |
4491 | } | |
4492 | len = strlen(str); | |
4493 | readline_set_completion_index(rs, len); | |
4494 | for (i = 0; host_net_devices[i]; i++) { | |
4495 | if (!strncmp(host_net_devices[i], str, len)) { | |
4496 | readline_add_completion(rs, host_net_devices[i]); | |
4497 | } | |
4498 | } | |
4499 | } | |
4500 | ||
ddd6b45c HB |
4501 | void host_net_remove_completion(ReadLineState *rs, int nb_args, const char *str) |
4502 | { | |
eaed483c | 4503 | NetClientState *ncs[MAX_QUEUE_NUM]; |
ddd6b45c HB |
4504 | int count, i, len; |
4505 | ||
4506 | len = strlen(str); | |
4507 | readline_set_completion_index(rs, len); | |
4508 | if (nb_args == 2) { | |
4509 | count = qemu_find_net_clients_except(NULL, ncs, | |
eaed483c JW |
4510 | NET_CLIENT_OPTIONS_KIND_NONE, |
4511 | MAX_QUEUE_NUM); | |
bcfa4d60 | 4512 | for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) { |
ddd6b45c HB |
4513 | int id; |
4514 | char name[16]; | |
4515 | ||
4516 | if (net_hub_id_for_client(ncs[i], &id)) { | |
4517 | continue; | |
4518 | } | |
4519 | snprintf(name, sizeof(name), "%d", id); | |
4520 | if (!strncmp(str, name, len)) { | |
4521 | readline_add_completion(rs, name); | |
4522 | } | |
4523 | } | |
4524 | return; | |
4525 | } else if (nb_args == 3) { | |
4526 | count = qemu_find_net_clients_except(NULL, ncs, | |
eaed483c JW |
4527 | NET_CLIENT_OPTIONS_KIND_NIC, |
4528 | MAX_QUEUE_NUM); | |
bcfa4d60 | 4529 | for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) { |
2c4681f5 | 4530 | int id; |
ddd6b45c HB |
4531 | const char *name; |
4532 | ||
2c4681f5 JW |
4533 | if (ncs[i]->info->type == NET_CLIENT_OPTIONS_KIND_HUBPORT || |
4534 | net_hub_id_for_client(ncs[i], &id)) { | |
4535 | continue; | |
4536 | } | |
ddd6b45c HB |
4537 | name = ncs[i]->name; |
4538 | if (!strncmp(str, name, len)) { | |
4539 | readline_add_completion(rs, name); | |
4540 | } | |
4541 | } | |
4542 | return; | |
4543 | } | |
4544 | } | |
4545 | ||
b21631f3 HB |
4546 | static void vm_completion(ReadLineState *rs, const char *str) |
4547 | { | |
4548 | size_t len; | |
4549 | BlockDriverState *bs = NULL; | |
4550 | ||
4551 | len = strlen(str); | |
4552 | readline_set_completion_index(rs, len); | |
4553 | while ((bs = bdrv_next(bs))) { | |
4554 | SnapshotInfoList *snapshots, *snapshot; | |
4555 | ||
4556 | if (!bdrv_can_snapshot(bs)) { | |
4557 | continue; | |
4558 | } | |
4559 | if (bdrv_query_snapshot_info_list(bs, &snapshots, NULL)) { | |
4560 | continue; | |
4561 | } | |
4562 | snapshot = snapshots; | |
4563 | while (snapshot) { | |
4564 | char *completion = snapshot->value->name; | |
4565 | if (!strncmp(str, completion, len)) { | |
4566 | readline_add_completion(rs, completion); | |
4567 | } | |
4568 | completion = snapshot->value->id; | |
4569 | if (!strncmp(str, completion, len)) { | |
4570 | readline_add_completion(rs, completion); | |
4571 | } | |
4572 | snapshot = snapshot->next; | |
4573 | } | |
4574 | qapi_free_SnapshotInfoList(snapshots); | |
4575 | } | |
4576 | ||
4577 | } | |
4578 | ||
4579 | void delvm_completion(ReadLineState *rs, int nb_args, const char *str) | |
4580 | { | |
4581 | if (nb_args == 2) { | |
4582 | vm_completion(rs, str); | |
4583 | } | |
4584 | } | |
4585 | ||
4586 | void loadvm_completion(ReadLineState *rs, int nb_args, const char *str) | |
4587 | { | |
4588 | if (nb_args == 2) { | |
4589 | vm_completion(rs, str); | |
4590 | } | |
4591 | } | |
4592 | ||
c35b6400 WX |
4593 | static void monitor_find_completion_by_table(Monitor *mon, |
4594 | const mon_cmd_t *cmd_table, | |
4595 | char **args, | |
4596 | int nb_args) | |
81d0912d FB |
4597 | { |
4598 | const char *cmdname; | |
c35b6400 | 4599 | int i; |
fea68bb6 | 4600 | const char *ptype, *str, *name; |
c227f099 | 4601 | const mon_cmd_t *cmd; |
fea68bb6 | 4602 | BlockDriverState *bs; |
81d0912d | 4603 | |
81d0912d FB |
4604 | if (nb_args <= 1) { |
4605 | /* command completion */ | |
4606 | if (nb_args == 0) | |
4607 | cmdname = ""; | |
4608 | else | |
4609 | cmdname = args[0]; | |
d2674b2c | 4610 | readline_set_completion_index(mon->rs, strlen(cmdname)); |
c35b6400 | 4611 | for (cmd = cmd_table; cmd->name != NULL; cmd++) { |
cd5c6bba | 4612 | cmd_completion(mon, cmdname, cmd->name); |
81d0912d FB |
4613 | } |
4614 | } else { | |
4615 | /* find the command */ | |
c35b6400 | 4616 | for (cmd = cmd_table; cmd->name != NULL; cmd++) { |
03a63484 JK |
4617 | if (compare_cmd(args[0], cmd->name)) { |
4618 | break; | |
4619 | } | |
81d0912d | 4620 | } |
03a63484 | 4621 | if (!cmd->name) { |
c35b6400 | 4622 | return; |
03a63484 JK |
4623 | } |
4624 | ||
d903a779 WX |
4625 | if (cmd->sub_table) { |
4626 | /* do the job again */ | |
e7ae771f SW |
4627 | monitor_find_completion_by_table(mon, cmd->sub_table, |
4628 | &args[1], nb_args - 1); | |
4629 | return; | |
d903a779 | 4630 | } |
bfa40f77 | 4631 | if (cmd->command_completion) { |
e7ae771f SW |
4632 | cmd->command_completion(mon->rs, nb_args, args[nb_args - 1]); |
4633 | return; | |
bfa40f77 | 4634 | } |
d903a779 | 4635 | |
4d76d2ba | 4636 | ptype = next_arg_type(cmd->args_type); |
81d0912d FB |
4637 | for(i = 0; i < nb_args - 2; i++) { |
4638 | if (*ptype != '\0') { | |
4d76d2ba | 4639 | ptype = next_arg_type(ptype); |
81d0912d | 4640 | while (*ptype == '?') |
4d76d2ba | 4641 | ptype = next_arg_type(ptype); |
81d0912d FB |
4642 | } |
4643 | } | |
4644 | str = args[nb_args - 1]; | |
48fe86f6 | 4645 | while (*ptype == '-' && ptype[1] != '\0') { |
3b6dbf27 | 4646 | ptype = next_arg_type(ptype); |
2a1704a7 | 4647 | } |
81d0912d FB |
4648 | switch(*ptype) { |
4649 | case 'F': | |
4650 | /* file completion */ | |
d2674b2c | 4651 | readline_set_completion_index(mon->rs, strlen(str)); |
cb8f68b1 | 4652 | file_completion(mon, str); |
81d0912d FB |
4653 | break; |
4654 | case 'B': | |
4655 | /* block device name completion */ | |
599a926a | 4656 | readline_set_completion_index(mon->rs, strlen(str)); |
fea68bb6 MA |
4657 | for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) { |
4658 | name = bdrv_get_device_name(bs); | |
4659 | if (str[0] == '\0' || | |
4660 | !strncmp(name, str, strlen(str))) { | |
4661 | readline_add_completion(mon->rs, name); | |
4662 | } | |
4663 | } | |
81d0912d | 4664 | break; |
7fe48483 | 4665 | case 's': |
129be006 | 4666 | case 'S': |
29136cd8 | 4667 | if (!strcmp(cmd->name, "help|?")) { |
7ca0e061 WX |
4668 | monitor_find_completion_by_table(mon, cmd_table, |
4669 | &args[1], nb_args - 1); | |
7fe48483 FB |
4670 | } |
4671 | break; | |
81d0912d FB |
4672 | default: |
4673 | break; | |
4674 | } | |
4675 | } | |
c35b6400 WX |
4676 | } |
4677 | ||
c60bf339 | 4678 | static void monitor_find_completion(void *opaque, |
c35b6400 WX |
4679 | const char *cmdline) |
4680 | { | |
c60bf339 | 4681 | Monitor *mon = opaque; |
c35b6400 WX |
4682 | char *args[MAX_ARGS]; |
4683 | int nb_args, len; | |
4684 | ||
4685 | /* 1. parse the cmdline */ | |
4686 | if (parse_cmdline(cmdline, &nb_args, args) < 0) { | |
4687 | return; | |
4688 | } | |
c35b6400 WX |
4689 | |
4690 | /* if the line ends with a space, it means we want to complete the | |
4691 | next arg */ | |
4692 | len = strlen(cmdline); | |
4693 | if (len > 0 && qemu_isspace(cmdline[len - 1])) { | |
4694 | if (nb_args >= MAX_ARGS) { | |
4695 | goto cleanup; | |
4696 | } | |
4697 | args[nb_args++] = g_strdup(""); | |
4698 | } | |
4699 | ||
4700 | /* 2. auto complete according to args */ | |
4701 | monitor_find_completion_by_table(mon, mon->cmd_table, args, nb_args); | |
03a63484 JK |
4702 | |
4703 | cleanup: | |
dcc70cdf | 4704 | free_cmdline_args(args, nb_args); |
81d0912d FB |
4705 | } |
4706 | ||
731b0364 | 4707 | static int monitor_can_read(void *opaque) |
9dc39cba | 4708 | { |
731b0364 AL |
4709 | Monitor *mon = opaque; |
4710 | ||
c62313bb | 4711 | return (mon->suspend_cnt == 0) ? 1 : 0; |
9dc39cba FB |
4712 | } |
4713 | ||
4086182f MA |
4714 | static bool invalid_qmp_mode(const Monitor *mon, const mon_cmd_t *cmd, |
4715 | Error **errp) | |
5fa737a4 | 4716 | { |
2d5a8346 | 4717 | bool is_cap = cmd->mhandler.cmd_new == do_qmp_capabilities; |
f994b258 MA |
4718 | |
4719 | if (is_cap && mon->qmp.in_command_mode) { | |
4086182f MA |
4720 | error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, |
4721 | "Capabilities negotiation is already complete, command " | |
4722 | "'%s' ignored", cmd->name); | |
2d5a8346 EB |
4723 | return true; |
4724 | } | |
f994b258 | 4725 | if (!is_cap && !mon->qmp.in_command_mode) { |
4086182f MA |
4726 | error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, |
4727 | "Expecting capabilities negotiation with " | |
4728 | "'qmp_capabilities' before command '%s'", cmd->name); | |
2d5a8346 EB |
4729 | return true; |
4730 | } | |
4731 | return false; | |
5fa737a4 LC |
4732 | } |
4733 | ||
4af9193a LC |
4734 | /* |
4735 | * Argument validation rules: | |
4736 | * | |
4737 | * 1. The argument must exist in cmd_args qdict | |
4738 | * 2. The argument type must be the expected one | |
4739 | * | |
4740 | * Special case: If the argument doesn't exist in cmd_args and | |
4741 | * the QMP_ACCEPT_UNKNOWNS flag is set, then the | |
4742 | * checking is skipped for it. | |
4743 | */ | |
326283aa MA |
4744 | static void check_client_args_type(const QDict *client_args, |
4745 | const QDict *cmd_args, int flags, | |
4746 | Error **errp) | |
5fa737a4 | 4747 | { |
4af9193a | 4748 | const QDictEntry *ent; |
5fa737a4 | 4749 | |
4af9193a LC |
4750 | for (ent = qdict_first(client_args); ent;ent = qdict_next(client_args,ent)){ |
4751 | QObject *obj; | |
4752 | QString *arg_type; | |
4753 | const QObject *client_arg = qdict_entry_value(ent); | |
4754 | const char *client_arg_name = qdict_entry_key(ent); | |
4755 | ||
4756 | obj = qdict_get(cmd_args, client_arg_name); | |
4757 | if (!obj) { | |
4758 | if (flags & QMP_ACCEPT_UNKNOWNS) { | |
4759 | /* handler accepts unknowns */ | |
4760 | continue; | |
4761 | } | |
4762 | /* client arg doesn't exist */ | |
326283aa MA |
4763 | error_set(errp, QERR_INVALID_PARAMETER, client_arg_name); |
4764 | return; | |
4af9193a | 4765 | } |
5fa737a4 | 4766 | |
4af9193a LC |
4767 | arg_type = qobject_to_qstring(obj); |
4768 | assert(arg_type != NULL); | |
5fa737a4 | 4769 | |
4af9193a LC |
4770 | /* check if argument's type is correct */ |
4771 | switch (qstring_get_str(arg_type)[0]) { | |
5fa737a4 LC |
4772 | case 'F': |
4773 | case 'B': | |
4774 | case 's': | |
4af9193a | 4775 | if (qobject_type(client_arg) != QTYPE_QSTRING) { |
326283aa MA |
4776 | error_set(errp, QERR_INVALID_PARAMETER_TYPE, |
4777 | client_arg_name, "string"); | |
4778 | return; | |
5fa737a4 | 4779 | } |
4af9193a | 4780 | break; |
5fa737a4 LC |
4781 | case 'i': |
4782 | case 'l': | |
b6e098d7 | 4783 | case 'M': |
dbc0c67f | 4784 | case 'o': |
4af9193a | 4785 | if (qobject_type(client_arg) != QTYPE_QINT) { |
326283aa MA |
4786 | error_set(errp, QERR_INVALID_PARAMETER_TYPE, |
4787 | client_arg_name, "int"); | |
4788 | return; | |
5fa737a4 LC |
4789 | } |
4790 | break; | |
fccfb11e | 4791 | case 'T': |
4af9193a LC |
4792 | if (qobject_type(client_arg) != QTYPE_QINT && |
4793 | qobject_type(client_arg) != QTYPE_QFLOAT) { | |
326283aa MA |
4794 | error_set(errp, QERR_INVALID_PARAMETER_TYPE, |
4795 | client_arg_name, "number"); | |
4796 | return; | |
3350a4dd MA |
4797 | } |
4798 | break; | |
942cd1f2 | 4799 | case 'b': |
5fa737a4 | 4800 | case '-': |
4af9193a | 4801 | if (qobject_type(client_arg) != QTYPE_QBOOL) { |
326283aa MA |
4802 | error_set(errp, QERR_INVALID_PARAMETER_TYPE, |
4803 | client_arg_name, "bool"); | |
4804 | return; | |
5fa737a4 LC |
4805 | } |
4806 | break; | |
361127df | 4807 | case 'O': |
4af9193a LC |
4808 | assert(flags & QMP_ACCEPT_UNKNOWNS); |
4809 | break; | |
b9f8978c PB |
4810 | case 'q': |
4811 | /* Any QObject can be passed. */ | |
4812 | break; | |
4af9193a LC |
4813 | case '/': |
4814 | case '.': | |
4815 | /* | |
4816 | * These types are not supported by QMP and thus are not | |
4817 | * handled here. Fall through. | |
4818 | */ | |
5fa737a4 | 4819 | default: |
5fa737a4 | 4820 | abort(); |
4af9193a LC |
4821 | } |
4822 | } | |
4af9193a LC |
4823 | } |
4824 | ||
2dbc8db0 LC |
4825 | /* |
4826 | * - Check if the client has passed all mandatory args | |
4827 | * - Set special flags for argument validation | |
4828 | */ | |
326283aa MA |
4829 | static void check_mandatory_args(const QDict *cmd_args, |
4830 | const QDict *client_args, int *flags, | |
4831 | Error **errp) | |
2dbc8db0 LC |
4832 | { |
4833 | const QDictEntry *ent; | |
4834 | ||
4835 | for (ent = qdict_first(cmd_args); ent; ent = qdict_next(cmd_args, ent)) { | |
4836 | const char *cmd_arg_name = qdict_entry_key(ent); | |
4837 | QString *type = qobject_to_qstring(qdict_entry_value(ent)); | |
4838 | assert(type != NULL); | |
4839 | ||
4840 | if (qstring_get_str(type)[0] == 'O') { | |
4841 | assert((*flags & QMP_ACCEPT_UNKNOWNS) == 0); | |
4842 | *flags |= QMP_ACCEPT_UNKNOWNS; | |
4843 | } else if (qstring_get_str(type)[0] != '-' && | |
4844 | qstring_get_str(type)[1] != '?' && | |
4845 | !qdict_haskey(client_args, cmd_arg_name)) { | |
326283aa MA |
4846 | error_set(errp, QERR_MISSING_PARAMETER, cmd_arg_name); |
4847 | return; | |
2dbc8db0 | 4848 | } |
5fa737a4 | 4849 | } |
5fa737a4 LC |
4850 | } |
4851 | ||
2dbc8db0 | 4852 | static QDict *qdict_from_args_type(const char *args_type) |
5fa737a4 | 4853 | { |
2dbc8db0 LC |
4854 | int i; |
4855 | QDict *qdict; | |
4856 | QString *key, *type, *cur_qs; | |
4857 | ||
4858 | assert(args_type != NULL); | |
4859 | ||
4860 | qdict = qdict_new(); | |
4861 | ||
4862 | if (args_type == NULL || args_type[0] == '\0') { | |
4863 | /* no args, empty qdict */ | |
4864 | goto out; | |
4865 | } | |
4866 | ||
4867 | key = qstring_new(); | |
4868 | type = qstring_new(); | |
4869 | ||
4870 | cur_qs = key; | |
4871 | ||
4872 | for (i = 0;; i++) { | |
4873 | switch (args_type[i]) { | |
4874 | case ',': | |
4875 | case '\0': | |
4876 | qdict_put(qdict, qstring_get_str(key), type); | |
4877 | QDECREF(key); | |
4878 | if (args_type[i] == '\0') { | |
4879 | goto out; | |
4880 | } | |
4881 | type = qstring_new(); /* qdict has ref */ | |
4882 | cur_qs = key = qstring_new(); | |
4883 | break; | |
4884 | case ':': | |
4885 | cur_qs = type; | |
4886 | break; | |
4887 | default: | |
4888 | qstring_append_chr(cur_qs, args_type[i]); | |
4889 | break; | |
4890 | } | |
4891 | } | |
4892 | ||
4893 | out: | |
4894 | return qdict; | |
5fa737a4 LC |
4895 | } |
4896 | ||
2dbc8db0 LC |
4897 | /* |
4898 | * Client argument checking rules: | |
4899 | * | |
4900 | * 1. Client must provide all mandatory arguments | |
4af9193a LC |
4901 | * 2. Each argument provided by the client must be expected |
4902 | * 3. Each argument provided by the client must have the type expected | |
4903 | * by the command | |
2dbc8db0 | 4904 | */ |
326283aa MA |
4905 | static void qmp_check_client_args(const mon_cmd_t *cmd, QDict *client_args, |
4906 | Error **errp) | |
361127df | 4907 | { |
326283aa MA |
4908 | Error *err = NULL; |
4909 | int flags; | |
2dbc8db0 LC |
4910 | QDict *cmd_args; |
4911 | ||
4912 | cmd_args = qdict_from_args_type(cmd->args_type); | |
4913 | ||
4914 | flags = 0; | |
326283aa | 4915 | check_mandatory_args(cmd_args, client_args, &flags, &err); |
2dbc8db0 LC |
4916 | if (err) { |
4917 | goto out; | |
4918 | } | |
4919 | ||
326283aa | 4920 | check_client_args_type(client_args, cmd_args, flags, &err); |
2dbc8db0 LC |
4921 | |
4922 | out: | |
326283aa | 4923 | error_propagate(errp, err); |
2dbc8db0 | 4924 | QDECREF(cmd_args); |
361127df MA |
4925 | } |
4926 | ||
5fa737a4 | 4927 | /* |
c917c8f3 | 4928 | * Input object checking rules |
5fa737a4 | 4929 | * |
c917c8f3 LC |
4930 | * 1. Input object must be a dict |
4931 | * 2. The "execute" key must exist | |
4932 | * 3. The "execute" key must be a string | |
4933 | * 4. If the "arguments" key exists, it must be a dict | |
4934 | * 5. If the "id" key exists, it can be anything (ie. json-value) | |
4935 | * 6. Any argument not listed above is considered invalid | |
5fa737a4 | 4936 | */ |
ba0510aa | 4937 | static QDict *qmp_check_input_obj(QObject *input_obj, Error **errp) |
5fa737a4 | 4938 | { |
c917c8f3 LC |
4939 | const QDictEntry *ent; |
4940 | int has_exec_key = 0; | |
4941 | QDict *input_dict; | |
5fa737a4 | 4942 | |
c917c8f3 | 4943 | if (qobject_type(input_obj) != QTYPE_QDICT) { |
ba0510aa | 4944 | error_set(errp, QERR_QMP_BAD_INPUT_OBJECT, "object"); |
c917c8f3 | 4945 | return NULL; |
5fa737a4 LC |
4946 | } |
4947 | ||
c917c8f3 | 4948 | input_dict = qobject_to_qdict(input_obj); |
5fa737a4 | 4949 | |
c917c8f3 LC |
4950 | for (ent = qdict_first(input_dict); ent; ent = qdict_next(input_dict, ent)){ |
4951 | const char *arg_name = qdict_entry_key(ent); | |
4952 | const QObject *arg_obj = qdict_entry_value(ent); | |
5fa737a4 | 4953 | |
c917c8f3 LC |
4954 | if (!strcmp(arg_name, "execute")) { |
4955 | if (qobject_type(arg_obj) != QTYPE_QSTRING) { | |
ba0510aa MA |
4956 | error_set(errp, QERR_QMP_BAD_INPUT_OBJECT_MEMBER, |
4957 | "execute", "string"); | |
c917c8f3 | 4958 | return NULL; |
361127df | 4959 | } |
c917c8f3 LC |
4960 | has_exec_key = 1; |
4961 | } else if (!strcmp(arg_name, "arguments")) { | |
4962 | if (qobject_type(arg_obj) != QTYPE_QDICT) { | |
ba0510aa MA |
4963 | error_set(errp, QERR_QMP_BAD_INPUT_OBJECT_MEMBER, |
4964 | "arguments", "object"); | |
c917c8f3 | 4965 | return NULL; |
5fa737a4 | 4966 | } |
779cec4d MA |
4967 | } else if (!strcmp(arg_name, "id")) { |
4968 | /* Any string is acceptable as "id", so nothing to check */ | |
5fa737a4 | 4969 | } else { |
ba0510aa | 4970 | error_set(errp, QERR_QMP_EXTRA_MEMBER, arg_name); |
c917c8f3 | 4971 | return NULL; |
5fa737a4 LC |
4972 | } |
4973 | } | |
4974 | ||
c917c8f3 | 4975 | if (!has_exec_key) { |
ba0510aa | 4976 | error_set(errp, QERR_QMP_BAD_INPUT_OBJECT, "execute"); |
c917c8f3 LC |
4977 | return NULL; |
4978 | } | |
5fa737a4 | 4979 | |
c917c8f3 | 4980 | return input_dict; |
09069b19 LC |
4981 | } |
4982 | ||
5fa737a4 LC |
4983 | static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) |
4984 | { | |
326283aa | 4985 | Error *local_err = NULL; |
84add864 | 4986 | QObject *obj, *data; |
5fa737a4 | 4987 | QDict *input, *args; |
5fa737a4 | 4988 | const mon_cmd_t *cmd; |
40e5a01d | 4989 | const char *cmd_name; |
5fa737a4 LC |
4990 | Monitor *mon = cur_mon; |
4991 | ||
e4940c60 | 4992 | args = input = NULL; |
84add864 | 4993 | data = NULL; |
5fa737a4 LC |
4994 | |
4995 | obj = json_parser_parse(tokens, NULL); | |
4996 | if (!obj) { | |
4997 | // FIXME: should be triggered in json_parser_parse() | |
710aec91 | 4998 | error_set(&local_err, QERR_JSON_PARSING); |
5fa737a4 | 4999 | goto err_out; |
5fa737a4 LC |
5000 | } |
5001 | ||
ba0510aa | 5002 | input = qmp_check_input_obj(obj, &local_err); |
c917c8f3 | 5003 | if (!input) { |
5fa737a4 LC |
5004 | qobject_decref(obj); |
5005 | goto err_out; | |
5006 | } | |
5007 | ||
74358f2a MA |
5008 | mon->qmp.id = qdict_get(input, "id"); |
5009 | qobject_incref(mon->qmp.id); | |
5fa737a4 | 5010 | |
0bbab46d | 5011 | cmd_name = qdict_get_str(input, "execute"); |
89bd820a | 5012 | trace_handle_qmp_command(mon, cmd_name); |
e3193601 | 5013 | cmd = qmp_find_cmd(cmd_name); |
2d5a8346 | 5014 | if (!cmd) { |
710aec91 MA |
5015 | error_set(&local_err, ERROR_CLASS_COMMAND_NOT_FOUND, |
5016 | "The command %s has not been found", cmd_name); | |
e4940c60 | 5017 | goto err_out; |
5fa737a4 | 5018 | } |
4086182f | 5019 | if (invalid_qmp_mode(mon, cmd, &local_err)) { |
2d5a8346 EB |
5020 | goto err_out; |
5021 | } | |
5fa737a4 LC |
5022 | |
5023 | obj = qdict_get(input, "arguments"); | |
5024 | if (!obj) { | |
5025 | args = qdict_new(); | |
5026 | } else { | |
5027 | args = qobject_to_qdict(obj); | |
5028 | QINCREF(args); | |
5029 | } | |
5030 | ||
326283aa MA |
5031 | qmp_check_client_args(cmd, args, &local_err); |
5032 | if (local_err) { | |
5fa737a4 LC |
5033 | goto err_out; |
5034 | } | |
5035 | ||
84add864 MA |
5036 | if (cmd->mhandler.cmd_new(mon, args, &data)) { |
5037 | /* Command failed... */ | |
452e0300 | 5038 | if (!mon->error) { |
84add864 | 5039 | /* ... without setting an error, so make one up */ |
710aec91 | 5040 | error_set(&local_err, QERR_UNDEFINED_ERROR); |
84add864 MA |
5041 | } |
5042 | } | |
710aec91 MA |
5043 | if (mon->error) { |
5044 | error_set(&local_err, mon->error->err_class, "%s", | |
5045 | mon->error->err_msg); | |
5046 | } | |
5fa737a4 | 5047 | |
5fa737a4 | 5048 | err_out: |
710aec91 | 5049 | monitor_protocol_emitter(mon, data, local_err); |
84add864 | 5050 | qobject_decref(data); |
70ea0c58 MA |
5051 | QDECREF(mon->error); |
5052 | mon->error = NULL; | |
e4940c60 | 5053 | QDECREF(input); |
5fa737a4 | 5054 | QDECREF(args); |
5fa737a4 LC |
5055 | } |
5056 | ||
c83fe23b | 5057 | static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size) |
9b57c02e LC |
5058 | { |
5059 | Monitor *old_mon = cur_mon; | |
5060 | ||
5061 | cur_mon = opaque; | |
5062 | ||
74358f2a | 5063 | json_message_parser_feed(&cur_mon->qmp.parser, (const char *) buf, size); |
9b57c02e LC |
5064 | |
5065 | cur_mon = old_mon; | |
5066 | } | |
5067 | ||
731b0364 | 5068 | static void monitor_read(void *opaque, const uint8_t *buf, int size) |
9dc39cba | 5069 | { |
731b0364 | 5070 | Monitor *old_mon = cur_mon; |
7e2515e8 | 5071 | int i; |
376253ec | 5072 | |
731b0364 AL |
5073 | cur_mon = opaque; |
5074 | ||
cde76ee1 AL |
5075 | if (cur_mon->rs) { |
5076 | for (i = 0; i < size; i++) | |
5077 | readline_handle_byte(cur_mon->rs, buf[i]); | |
5078 | } else { | |
5079 | if (size == 0 || buf[size - 1] != 0) | |
5080 | monitor_printf(cur_mon, "corrupted command\n"); | |
5081 | else | |
7ef6cf63 | 5082 | handle_hmp_command(cur_mon, (char *)buf); |
cde76ee1 | 5083 | } |
9dc39cba | 5084 | |
731b0364 AL |
5085 | cur_mon = old_mon; |
5086 | } | |
d8f44609 | 5087 | |
c60bf339 SH |
5088 | static void monitor_command_cb(void *opaque, const char *cmdline, |
5089 | void *readline_opaque) | |
aa455485 | 5090 | { |
c60bf339 SH |
5091 | Monitor *mon = opaque; |
5092 | ||
731b0364 | 5093 | monitor_suspend(mon); |
7ef6cf63 | 5094 | handle_hmp_command(mon, cmdline); |
731b0364 | 5095 | monitor_resume(mon); |
d8f44609 AL |
5096 | } |
5097 | ||
cde76ee1 | 5098 | int monitor_suspend(Monitor *mon) |
d8f44609 | 5099 | { |
cde76ee1 AL |
5100 | if (!mon->rs) |
5101 | return -ENOTTY; | |
731b0364 | 5102 | mon->suspend_cnt++; |
cde76ee1 | 5103 | return 0; |
d8f44609 AL |
5104 | } |
5105 | ||
376253ec | 5106 | void monitor_resume(Monitor *mon) |
d8f44609 | 5107 | { |
cde76ee1 AL |
5108 | if (!mon->rs) |
5109 | return; | |
731b0364 AL |
5110 | if (--mon->suspend_cnt == 0) |
5111 | readline_show_prompt(mon->rs); | |
aa455485 FB |
5112 | } |
5113 | ||
ca9567e2 LC |
5114 | static QObject *get_qmp_greeting(void) |
5115 | { | |
b9c15f16 | 5116 | QObject *ver = NULL; |
ca9567e2 | 5117 | |
b9c15f16 | 5118 | qmp_marshal_input_query_version(NULL, NULL, &ver); |
ca9567e2 LC |
5119 | return qobject_from_jsonf("{'QMP':{'version': %p,'capabilities': []}}",ver); |
5120 | } | |
5121 | ||
c83fe23b | 5122 | static void monitor_qmp_event(void *opaque, int event) |
9b57c02e | 5123 | { |
47116d1c LC |
5124 | QObject *data; |
5125 | Monitor *mon = opaque; | |
9b57c02e | 5126 | |
47116d1c LC |
5127 | switch (event) { |
5128 | case CHR_EVENT_OPENED: | |
f994b258 | 5129 | mon->qmp.in_command_mode = false; |
ca9567e2 | 5130 | data = get_qmp_greeting(); |
9b57c02e LC |
5131 | monitor_json_emitter(mon, data); |
5132 | qobject_decref(data); | |
efb87c16 | 5133 | mon_refcount++; |
47116d1c LC |
5134 | break; |
5135 | case CHR_EVENT_CLOSED: | |
74358f2a MA |
5136 | json_message_parser_destroy(&mon->qmp.parser); |
5137 | json_message_parser_init(&mon->qmp.parser, handle_qmp_command); | |
efb87c16 CB |
5138 | mon_refcount--; |
5139 | monitor_fdsets_cleanup(); | |
47116d1c | 5140 | break; |
9b57c02e LC |
5141 | } |
5142 | } | |
5143 | ||
731b0364 | 5144 | static void monitor_event(void *opaque, int event) |
86e94dea | 5145 | { |
376253ec AL |
5146 | Monitor *mon = opaque; |
5147 | ||
2724b180 AL |
5148 | switch (event) { |
5149 | case CHR_EVENT_MUX_IN: | |
6cff3e85 | 5150 | qemu_mutex_lock(&mon->out_lock); |
a7aec5da | 5151 | mon->mux_out = 0; |
6cff3e85 | 5152 | qemu_mutex_unlock(&mon->out_lock); |
a7aec5da GH |
5153 | if (mon->reset_seen) { |
5154 | readline_restart(mon->rs); | |
5155 | monitor_resume(mon); | |
5156 | monitor_flush(mon); | |
5157 | } else { | |
5158 | mon->suspend_cnt = 0; | |
5159 | } | |
2724b180 AL |
5160 | break; |
5161 | ||
5162 | case CHR_EVENT_MUX_OUT: | |
a7aec5da GH |
5163 | if (mon->reset_seen) { |
5164 | if (mon->suspend_cnt == 0) { | |
5165 | monitor_printf(mon, "\n"); | |
5166 | } | |
5167 | monitor_flush(mon); | |
5168 | monitor_suspend(mon); | |
5169 | } else { | |
5170 | mon->suspend_cnt++; | |
5171 | } | |
6cff3e85 | 5172 | qemu_mutex_lock(&mon->out_lock); |
a7aec5da | 5173 | mon->mux_out = 1; |
6cff3e85 | 5174 | qemu_mutex_unlock(&mon->out_lock); |
2724b180 | 5175 | break; |
86e94dea | 5176 | |
b6b8df56 | 5177 | case CHR_EVENT_OPENED: |
2724b180 AL |
5178 | monitor_printf(mon, "QEMU %s monitor - type 'help' for more " |
5179 | "information\n", QEMU_VERSION); | |
a7aec5da | 5180 | if (!mon->mux_out) { |
e5554e20 | 5181 | readline_restart(mon->rs); |
2724b180 | 5182 | readline_show_prompt(mon->rs); |
a7aec5da GH |
5183 | } |
5184 | mon->reset_seen = 1; | |
efb87c16 CB |
5185 | mon_refcount++; |
5186 | break; | |
5187 | ||
5188 | case CHR_EVENT_CLOSED: | |
5189 | mon_refcount--; | |
5190 | monitor_fdsets_cleanup(); | |
2724b180 AL |
5191 | break; |
5192 | } | |
86e94dea TS |
5193 | } |
5194 | ||
816f8925 WX |
5195 | static int |
5196 | compare_mon_cmd(const void *a, const void *b) | |
5197 | { | |
5198 | return strcmp(((const mon_cmd_t *)a)->name, | |
5199 | ((const mon_cmd_t *)b)->name); | |
5200 | } | |
5201 | ||
5202 | static void sortcmdlist(void) | |
5203 | { | |
5204 | int array_num; | |
5205 | int elem_size = sizeof(mon_cmd_t); | |
5206 | ||
5207 | array_num = sizeof(mon_cmds)/elem_size-1; | |
5208 | qsort((void *)mon_cmds, array_num, elem_size, compare_mon_cmd); | |
5209 | ||
5210 | array_num = sizeof(info_cmds)/elem_size-1; | |
5211 | qsort((void *)info_cmds, array_num, elem_size, compare_mon_cmd); | |
5212 | } | |
5213 | ||
76655d6d AL |
5214 | |
5215 | /* | |
5216 | * Local variables: | |
5217 | * c-indent-level: 4 | |
5218 | * c-basic-offset: 4 | |
5219 | * tab-width: 8 | |
5220 | * End: | |
5221 | */ | |
5222 | ||
c60bf339 SH |
5223 | /* These functions just adapt the readline interface in a typesafe way. We |
5224 | * could cast function pointers but that discards compiler checks. | |
5225 | */ | |
d5d1507b SW |
5226 | static void GCC_FMT_ATTR(2, 3) monitor_readline_printf(void *opaque, |
5227 | const char *fmt, ...) | |
c60bf339 SH |
5228 | { |
5229 | va_list ap; | |
5230 | va_start(ap, fmt); | |
5231 | monitor_vprintf(opaque, fmt, ap); | |
5232 | va_end(ap); | |
5233 | } | |
5234 | ||
5235 | static void monitor_readline_flush(void *opaque) | |
5236 | { | |
5237 | monitor_flush(opaque); | |
5238 | } | |
5239 | ||
d622cb58 PB |
5240 | static void __attribute__((constructor)) monitor_lock_init(void) |
5241 | { | |
5242 | qemu_mutex_init(&monitor_lock); | |
5243 | } | |
5244 | ||
731b0364 | 5245 | void monitor_init(CharDriverState *chr, int flags) |
aa455485 | 5246 | { |
731b0364 | 5247 | static int is_first_init = 1; |
87127161 | 5248 | Monitor *mon; |
20d8a3ed TS |
5249 | |
5250 | if (is_first_init) { | |
43a14cfc | 5251 | monitor_qapi_event_init(); |
d038317c | 5252 | sortcmdlist(); |
20d8a3ed TS |
5253 | is_first_init = 0; |
5254 | } | |
87127161 | 5255 | |
b01fe89e WX |
5256 | mon = g_malloc(sizeof(*mon)); |
5257 | monitor_data_init(mon); | |
20d8a3ed | 5258 | |
87127161 | 5259 | mon->chr = chr; |
731b0364 | 5260 | mon->flags = flags; |
cde76ee1 | 5261 | if (flags & MONITOR_USE_READLINE) { |
c60bf339 SH |
5262 | mon->rs = readline_init(monitor_readline_printf, |
5263 | monitor_readline_flush, | |
5264 | mon, | |
5265 | monitor_find_completion); | |
cde76ee1 AL |
5266 | monitor_read_command(mon, 0); |
5267 | } | |
87127161 | 5268 | |
9f3982f2 | 5269 | if (monitor_is_qmp(mon)) { |
c83fe23b MA |
5270 | qemu_chr_add_handlers(chr, monitor_can_read, monitor_qmp_read, |
5271 | monitor_qmp_event, mon); | |
15f31519 | 5272 | qemu_chr_fe_set_echo(chr, true); |
74358f2a | 5273 | json_message_parser_init(&mon->qmp.parser, handle_qmp_command); |
9b57c02e LC |
5274 | } else { |
5275 | qemu_chr_add_handlers(chr, monitor_can_read, monitor_read, | |
5276 | monitor_event, mon); | |
5277 | } | |
87127161 | 5278 | |
d622cb58 | 5279 | qemu_mutex_lock(&monitor_lock); |
72cf2d4f | 5280 | QLIST_INSERT_HEAD(&mon_list, mon, entry); |
d622cb58 | 5281 | qemu_mutex_unlock(&monitor_lock); |
aa455485 FB |
5282 | } |
5283 | ||
c60bf339 SH |
5284 | static void bdrv_password_cb(void *opaque, const char *password, |
5285 | void *readline_opaque) | |
81d0912d | 5286 | { |
c60bf339 SH |
5287 | Monitor *mon = opaque; |
5288 | BlockDriverState *bs = readline_opaque; | |
bb5fc20f | 5289 | int ret = 0; |
4d2855a3 | 5290 | Error *local_err = NULL; |
81d0912d | 5291 | |
4d2855a3 MA |
5292 | bdrv_add_key(bs, password, &local_err); |
5293 | if (local_err) { | |
5294 | monitor_printf(mon, "%s\n", error_get_pretty(local_err)); | |
5295 | error_free(local_err); | |
bb5fc20f | 5296 | ret = -EPERM; |
9dc39cba | 5297 | } |
731b0364 AL |
5298 | if (mon->password_completion_cb) |
5299 | mon->password_completion_cb(mon->password_opaque, ret); | |
bb5fc20f | 5300 | |
731b0364 | 5301 | monitor_read_command(mon, 1); |
9dc39cba | 5302 | } |
c0f4ce77 | 5303 | |
0bbc47bb | 5304 | int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, |
097310b5 | 5305 | BlockCompletionFunc *completion_cb, |
0bbc47bb | 5306 | void *opaque) |
c0f4ce77 | 5307 | { |
cde76ee1 AL |
5308 | int err; |
5309 | ||
376253ec AL |
5310 | monitor_printf(mon, "%s (%s) is encrypted.\n", bdrv_get_device_name(bs), |
5311 | bdrv_get_encrypted_filename(bs)); | |
bb5fc20f | 5312 | |
731b0364 AL |
5313 | mon->password_completion_cb = completion_cb; |
5314 | mon->password_opaque = opaque; | |
bb5fc20f | 5315 | |
cde76ee1 AL |
5316 | err = monitor_read_password(mon, bdrv_password_cb, bs); |
5317 | ||
5318 | if (err && completion_cb) | |
5319 | completion_cb(opaque, err); | |
0bbc47bb LC |
5320 | |
5321 | return err; | |
c0f4ce77 | 5322 | } |
e42e818b LC |
5323 | |
5324 | int monitor_read_block_device_key(Monitor *mon, const char *device, | |
097310b5 | 5325 | BlockCompletionFunc *completion_cb, |
e42e818b LC |
5326 | void *opaque) |
5327 | { | |
9b14e0ef | 5328 | Error *err = NULL; |
5560625b | 5329 | BlockBackend *blk; |
e42e818b | 5330 | |
5560625b FZ |
5331 | blk = blk_by_name(device); |
5332 | if (!blk) { | |
e42e818b LC |
5333 | monitor_printf(mon, "Device not found %s\n", device); |
5334 | return -1; | |
5335 | } | |
5336 | ||
9b14e0ef MA |
5337 | bdrv_add_key(blk_bs(blk), NULL, &err); |
5338 | if (err) { | |
5339 | error_free(err); | |
5340 | return monitor_read_bdrv_key_start(mon, blk_bs(blk), completion_cb, opaque); | |
5341 | } | |
5342 | ||
5343 | if (completion_cb) { | |
5344 | completion_cb(opaque, 0); | |
5345 | } | |
5346 | return 0; | |
e42e818b | 5347 | } |
4d454574 PB |
5348 | |
5349 | QemuOptsList qemu_mon_opts = { | |
5350 | .name = "mon", | |
5351 | .implied_opt_name = "chardev", | |
5352 | .head = QTAILQ_HEAD_INITIALIZER(qemu_mon_opts.head), | |
5353 | .desc = { | |
5354 | { | |
5355 | .name = "mode", | |
5356 | .type = QEMU_OPT_STRING, | |
5357 | },{ | |
5358 | .name = "chardev", | |
5359 | .type = QEMU_OPT_STRING, | |
5360 | },{ | |
5361 | .name = "default", | |
5362 | .type = QEMU_OPT_BOOL, | |
5363 | },{ | |
5364 | .name = "pretty", | |
5365 | .type = QEMU_OPT_BOOL, | |
5366 | }, | |
5367 | { /* end of list */ } | |
5368 | }, | |
5369 | }; | |
f2ae8abf MT |
5370 | |
5371 | #ifndef TARGET_I386 | |
5372 | void qmp_rtc_reset_reinjection(Error **errp) | |
5373 | { | |
5374 | error_set(errp, QERR_FEATURE_DISABLED, "rtc-reset-reinjection"); | |
5375 | } | |
5376 | #endif |