| 1 | /* |
| 2 | * HMP commands related to run state |
| 3 | * |
| 4 | * Copyright IBM, Corp. 2011 |
| 5 | * |
| 6 | * Authors: |
| 7 | * Anthony Liguori <aliguori@us.ibm.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2. See |
| 10 | * the COPYING file in the top-level directory. |
| 11 | * |
| 12 | * Contributions after 2012-01-13 are licensed under the terms of the |
| 13 | * GNU GPL, version 2 or (at your option) any later version. |
| 14 | */ |
| 15 | |
| 16 | #include "qemu/osdep.h" |
| 17 | #include "exec/cpu-common.h" |
| 18 | #include "monitor/hmp.h" |
| 19 | #include "monitor/hmp-completion.h" |
| 20 | #include "monitor/monitor.h" |
| 21 | #include "qapi/error.h" |
| 22 | #include "qapi/qapi-commands-run-state.h" |
| 23 | #include "qobject/qdict.h" |
| 24 | #include "qemu/accel.h" |
| 25 | |
| 26 | void hmp_info_status(MonitorHMP *hmp, const QDict *qdict) |
| 27 | { |
| 28 | StatusInfo *info; |
| 29 | |
| 30 | info = qmp_query_status(NULL); |
| 31 | |
| 32 | monitor_hmp_printf(hmp, "VM status: %s", |
| 33 | info->running ? "running" : "paused"); |
| 34 | |
| 35 | if (!info->running && info->status != RUN_STATE_PAUSED) { |
| 36 | monitor_hmp_printf(hmp, " (%s)", RunState_str(info->status)); |
| 37 | } |
| 38 | |
| 39 | monitor_hmp_printf(hmp, "\n"); |
| 40 | |
| 41 | qapi_free_StatusInfo(info); |
| 42 | } |
| 43 | |
| 44 | void hmp_one_insn_per_tb(MonitorHMP *hmp, const QDict *qdict) |
| 45 | { |
| 46 | const char *option = qdict_get_try_str(qdict, "option"); |
| 47 | AccelState *accel = current_accel(); |
| 48 | bool newval; |
| 49 | |
| 50 | if (!object_property_find(OBJECT(accel), "one-insn-per-tb")) { |
| 51 | monitor_hmp_printf(hmp, |
| 52 | "This accelerator does not support setting one-insn-per-tb\n"); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | if (!option || !strcmp(option, "on")) { |
| 57 | newval = true; |
| 58 | } else if (!strcmp(option, "off")) { |
| 59 | newval = false; |
| 60 | } else { |
| 61 | monitor_hmp_printf(hmp, "unexpected option %s\n", option); |
| 62 | return; |
| 63 | } |
| 64 | /* If the property exists then setting it can never fail */ |
| 65 | object_property_set_bool(OBJECT(accel), "one-insn-per-tb", |
| 66 | newval, &error_abort); |
| 67 | } |
| 68 | |
| 69 | void hmp_watchdog_action(MonitorHMP *hmp, const QDict *qdict) |
| 70 | { |
| 71 | Error *err = NULL; |
| 72 | WatchdogAction action; |
| 73 | char *qapi_value; |
| 74 | |
| 75 | qapi_value = g_ascii_strdown(qdict_get_str(qdict, "action"), -1); |
| 76 | action = qapi_enum_parse(&WatchdogAction_lookup, qapi_value, -1, &err); |
| 77 | g_free(qapi_value); |
| 78 | if (err) { |
| 79 | hmp_handle_error(hmp, err); |
| 80 | return; |
| 81 | } |
| 82 | qmp_watchdog_set_action(action, &error_abort); |
| 83 | } |
| 84 | |
| 85 | void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str) |
| 86 | { |
| 87 | int i; |
| 88 | |
| 89 | if (nb_args != 2) { |
| 90 | return; |
| 91 | } |
| 92 | readline_set_completion_index(rs, strlen(str)); |
| 93 | for (i = 0; i < WATCHDOG_ACTION__MAX; i++) { |
| 94 | readline_add_completion_of(rs, str, WatchdogAction_str(i)); |
| 95 | } |
| 96 | } |