qapi: allow unions to contain further unions
[qemu/armbru.git] / dump / dump-hmp-cmds.c
blobb038785fee378402e321235867141c193b29ee14
1 /*
2 * Windows crashdump (Human Monitor Interface commands)
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 */
8 #include "qemu/osdep.h"
9 #include "monitor/hmp.h"
10 #include "monitor/monitor.h"
11 #include "qapi/error.h"
12 #include "qapi/qapi-commands-dump.h"
13 #include "qapi/qmp/qdict.h"
15 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
17 Error *err = NULL;
18 bool win_dmp = qdict_get_try_bool(qdict, "windmp", false);
19 bool paging = qdict_get_try_bool(qdict, "paging", false);
20 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
21 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
22 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
23 const char *file = qdict_get_str(qdict, "filename");
24 bool has_begin = qdict_haskey(qdict, "begin");
25 bool has_length = qdict_haskey(qdict, "length");
26 bool has_detach = qdict_haskey(qdict, "detach");
27 int64_t begin = 0;
28 int64_t length = 0;
29 bool detach = false;
30 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
31 char *prot;
33 if (zlib + lzo + snappy + win_dmp > 1) {
34 error_setg(&err, "only one of '-z|-l|-s|-w' can be set");
35 hmp_handle_error(mon, err);
36 return;
39 if (win_dmp) {
40 dump_format = DUMP_GUEST_MEMORY_FORMAT_WIN_DMP;
43 if (zlib) {
44 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
47 if (lzo) {
48 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
51 if (snappy) {
52 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
55 if (has_begin) {
56 begin = qdict_get_int(qdict, "begin");
58 if (has_length) {
59 length = qdict_get_int(qdict, "length");
61 if (has_detach) {
62 detach = qdict_get_bool(qdict, "detach");
65 prot = g_strconcat("file:", file, NULL);
67 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
68 has_length, length, true, dump_format, &err);
69 hmp_handle_error(mon, err);
70 g_free(prot);
73 void hmp_info_dump(Monitor *mon, const QDict *qdict)
75 DumpQueryResult *result = qmp_query_dump(NULL);
77 assert(result && result->status < DUMP_STATUS__MAX);
78 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);
87 qapi_free_DumpQueryResult(result);