dump-hmp-cmds.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Windows crashdump (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 raw = qdict_get_try_bool(qdict, "raw", false);
  21. bool snappy = qdict_get_try_bool(qdict, "snappy", false);
  22. const char *file = qdict_get_str(qdict, "filename");
  23. bool has_begin = qdict_haskey(qdict, "begin");
  24. bool has_length = qdict_haskey(qdict, "length");
  25. bool has_detach = qdict_haskey(qdict, "detach");
  26. int64_t begin = 0;
  27. int64_t length = 0;
  28. bool detach = false;
  29. enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
  30. char *prot;
  31. if (zlib + lzo + snappy + win_dmp > 1) {
  32. error_setg(&err, "only one of '-z|-l|-s|-w' can be set");
  33. hmp_handle_error(mon, err);
  34. return;
  35. }
  36. if (win_dmp) {
  37. dump_format = DUMP_GUEST_MEMORY_FORMAT_WIN_DMP;
  38. }
  39. if (zlib) {
  40. if (raw) {
  41. dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_RAW_ZLIB;
  42. } else {
  43. dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
  44. }
  45. }
  46. if (lzo) {
  47. if (raw) {
  48. dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_RAW_LZO;
  49. } else {
  50. dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
  51. }
  52. }
  53. if (snappy) {
  54. if (raw) {
  55. dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_RAW_SNAPPY;
  56. } else {
  57. dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
  58. }
  59. }
  60. if (has_begin) {
  61. begin = qdict_get_int(qdict, "begin");
  62. }
  63. if (has_length) {
  64. length = qdict_get_int(qdict, "length");
  65. }
  66. if (has_detach) {
  67. detach = qdict_get_bool(qdict, "detach");
  68. }
  69. prot = g_strconcat("file:", file, NULL);
  70. qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
  71. has_length, length, true, dump_format, &err);
  72. hmp_handle_error(mon, err);
  73. g_free(prot);
  74. }
  75. void hmp_info_dump(Monitor *mon, const QDict *qdict)
  76. {
  77. DumpQueryResult *result = qmp_query_dump(NULL);
  78. assert(result && result->status < DUMP_STATUS__MAX);
  79. monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
  80. if (result->status == DUMP_STATUS_ACTIVE) {
  81. float percent = 0;
  82. assert(result->total != 0);
  83. percent = 100.0 * result->completed / result->total;
  84. monitor_printf(mon, "Finished: %.2f %%\n", percent);
  85. }
  86. qapi_free_DumpQueryResult(result);
  87. }