2
0

dump-hmp-cmds.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Human Monitor Interface commands
  3. *
  4. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  5. * See the COPYING file in the top-level directory.
  6. */
  7. #include "qemu/osdep.h"
  8. #include "monitor/hmp.h"
  9. #include "monitor/monitor.h"
  10. #include "qapi/error.h"
  11. #include "qapi/qapi-commands-dump.h"
  12. #include "qapi/qmp/qdict.h"
  13. void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
  14. {
  15. Error *err = NULL;
  16. bool win_dmp = qdict_get_try_bool(qdict, "windmp", false);
  17. bool paging = qdict_get_try_bool(qdict, "paging", false);
  18. bool zlib = qdict_get_try_bool(qdict, "zlib", false);
  19. bool lzo = qdict_get_try_bool(qdict, "lzo", false);
  20. bool snappy = qdict_get_try_bool(qdict, "snappy", false);
  21. const char *file = qdict_get_str(qdict, "filename");
  22. bool has_begin = qdict_haskey(qdict, "begin");
  23. bool has_length = qdict_haskey(qdict, "length");
  24. bool has_detach = qdict_haskey(qdict, "detach");
  25. int64_t begin = 0;
  26. int64_t length = 0;
  27. bool detach = false;
  28. enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
  29. char *prot;
  30. if (zlib + lzo + snappy + win_dmp > 1) {
  31. error_setg(&err, "only one of '-z|-l|-s|-w' can be set");
  32. hmp_handle_error(mon, &err);
  33. return;
  34. }
  35. if (win_dmp) {
  36. dump_format = DUMP_GUEST_MEMORY_FORMAT_WIN_DMP;
  37. }
  38. if (zlib) {
  39. dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
  40. }
  41. if (lzo) {
  42. dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
  43. }
  44. if (snappy) {
  45. dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
  46. }
  47. if (has_begin) {
  48. begin = qdict_get_int(qdict, "begin");
  49. }
  50. if (has_length) {
  51. length = qdict_get_int(qdict, "length");
  52. }
  53. if (has_detach) {
  54. detach = qdict_get_bool(qdict, "detach");
  55. }
  56. prot = g_strconcat("file:", file, NULL);
  57. qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
  58. has_length, length, true, dump_format, &err);
  59. hmp_handle_error(mon, &err);
  60. g_free(prot);
  61. }
  62. void hmp_info_dump(Monitor *mon, const QDict *qdict)
  63. {
  64. DumpQueryResult *result = qmp_query_dump(NULL);
  65. assert(result && result->status < DUMP_STATUS__MAX);
  66. monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
  67. if (result->status == DUMP_STATUS_ACTIVE) {
  68. float percent = 0;
  69. assert(result->total != 0);
  70. percent = 100.0 * result->completed / result->total;
  71. monitor_printf(mon, "Finished: %.2f %%\n", percent);
  72. }
  73. qapi_free_DumpQueryResult(result);
  74. }