runstate-hmp-cmds.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include "qemu/osdep.h"
  16. #include "exec/cpu-common.h"
  17. #include "monitor/hmp.h"
  18. #include "monitor/monitor.h"
  19. #include "qapi/error.h"
  20. #include "qapi/qapi-commands-run-state.h"
  21. #include "qobject/qdict.h"
  22. #include "qemu/accel.h"
  23. void hmp_info_status(Monitor *mon, const QDict *qdict)
  24. {
  25. StatusInfo *info;
  26. info = qmp_query_status(NULL);
  27. monitor_printf(mon, "VM status: %s",
  28. info->running ? "running" : "paused");
  29. if (!info->running && info->status != RUN_STATE_PAUSED) {
  30. monitor_printf(mon, " (%s)", RunState_str(info->status));
  31. }
  32. monitor_printf(mon, "\n");
  33. qapi_free_StatusInfo(info);
  34. }
  35. void hmp_one_insn_per_tb(Monitor *mon, const QDict *qdict)
  36. {
  37. const char *option = qdict_get_try_str(qdict, "option");
  38. AccelState *accel = current_accel();
  39. bool newval;
  40. if (!object_property_find(OBJECT(accel), "one-insn-per-tb")) {
  41. monitor_printf(mon,
  42. "This accelerator does not support setting one-insn-per-tb\n");
  43. return;
  44. }
  45. if (!option || !strcmp(option, "on")) {
  46. newval = true;
  47. } else if (!strcmp(option, "off")) {
  48. newval = false;
  49. } else {
  50. monitor_printf(mon, "unexpected option %s\n", option);
  51. return;
  52. }
  53. /* If the property exists then setting it can never fail */
  54. object_property_set_bool(OBJECT(accel), "one-insn-per-tb",
  55. newval, &error_abort);
  56. }
  57. void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
  58. {
  59. Error *err = NULL;
  60. WatchdogAction action;
  61. char *qapi_value;
  62. qapi_value = g_ascii_strdown(qdict_get_str(qdict, "action"), -1);
  63. action = qapi_enum_parse(&WatchdogAction_lookup, qapi_value, -1, &err);
  64. g_free(qapi_value);
  65. if (err) {
  66. hmp_handle_error(mon, err);
  67. return;
  68. }
  69. qmp_watchdog_set_action(action, &error_abort);
  70. }
  71. void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
  72. {
  73. int i;
  74. if (nb_args != 2) {
  75. return;
  76. }
  77. readline_set_completion_index(rs, strlen(str));
  78. for (i = 0; i < WATCHDOG_ACTION__MAX; i++) {
  79. readline_add_completion_of(rs, str, WatchdogAction_str(i));
  80. }
  81. }