From 0cfd6a9ab4356cd2c69bb29b1d70e1fd037bc1f2 Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Tue, 22 Nov 2011 16:32:37 -0200 Subject: qapi: Convert memsave Please, note that the QMP command has a new 'cpu-index' parameter. Signed-off-by: Anthony Liguori Signed-off-by: Luiz Capitulino --- cpus.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'cpus.c') diff --git a/cpus.c b/cpus.c index ca46ec6523..0f2ce60a36 100644 --- a/cpus.c +++ b/cpus.c @@ -1136,3 +1136,50 @@ CpuInfoList *qmp_query_cpus(Error **errp) return head; } + +void qmp_memsave(int64_t addr, int64_t size, const char *filename, + bool has_cpu, int64_t cpu_index, Error **errp) +{ + FILE *f; + uint32_t l; + CPUState *env; + uint8_t buf[1024]; + + if (!has_cpu) { + cpu_index = 0; + } + + for (env = first_cpu; env; env = env->next_cpu) { + if (cpu_index == env->cpu_index) { + break; + } + } + + if (env == NULL) { + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", + "a CPU number"); + return; + } + + f = fopen(filename, "wb"); + if (!f) { + error_set(errp, QERR_OPEN_FILE_FAILED, filename); + return; + } + + while (size != 0) { + l = sizeof(buf); + if (l > size) + l = size; + cpu_memory_rw_debug(env, addr, buf, l, 0); + if (fwrite(buf, 1, l, f) != l) { + error_set(errp, QERR_IO_ERROR); + goto exit; + } + addr += l; + size -= l; + } + +exit: + fclose(f); +} -- cgit v1.2.1