[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 6/7] qmp: add pmemload command
From: |
Simon Ruderich |
Subject: |
[Qemu-devel] [PATCH v7 6/7] qmp: add pmemload command |
Date: |
Thu, 15 Nov 2018 14:22:39 +0100 |
Adapted patch from Baojun Wang [1] with the following commit message:
I found this could be useful to have qemu-softmmu as a cross
debugger (launch with -s -S command line option), then if we can
have a command to load guest physical memory, we can use cross gdb
to do some target debug which gdb cannot do directly.
This patch contains only the qmp changes of the original patch.
pmemload is necessary to directly write physical memory which is not
possible with gdb alone as it uses only logical addresses.
The QAPI for pmemload uses "val" as parameter name for the physical
address. This name is not very descriptive but is consistent with the
existing pmemsave. Changing the parameter name of pmemsave is not
possible without breaking the existing API.
[1]: https://lists.gnu.org/archive/html/qemu-trivial/2014-04/msg00074.html
Based-on-patch-by: Baojun Wang <address@hidden>
Signed-off-by: Simon Ruderich <address@hidden>
---
cpus.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
qapi/misc.json | 20 ++++++++++++++++++++
2 files changed, 71 insertions(+)
diff --git a/cpus.c b/cpus.c
index ee54595733..a12076dc68 100644
--- a/cpus.c
+++ b/cpus.c
@@ -2445,6 +2445,57 @@ exit:
qemu_close(fd);
}
+void qmp_pmemload(int64_t addr, const char *filename,
+ bool has_size, int64_t size,
+ bool has_offset, int64_t offset,
+ Error **errp)
+{
+ int fd;
+ size_t l;
+ ssize_t r;
+ uint8_t buf[1024];
+
+ fd = qemu_open(filename, O_RDONLY | O_BINARY);
+ if (fd < 0) {
+ error_setg_file_open(errp, errno, filename);
+ return;
+ }
+ if (has_offset && offset > 0) {
+ if (lseek(fd, offset, SEEK_SET) != offset) {
+ error_setg_errno(errp, errno,
+ "could not seek to offset %" PRIx64, offset);
+ goto exit;
+ }
+ }
+ if (!has_size) {
+ struct stat s;
+ if (fstat(fd, &s)) {
+ error_setg_errno(errp, errno, "could not fstat fd to get size");
+ goto exit;
+ }
+ size = s.st_size;
+ }
+
+ while (size != 0) {
+ l = sizeof(buf);
+ if (l > size) {
+ l = size;
+ }
+ r = read(fd, buf, l);
+ if (r <= 0) {
+ error_setg(errp, QERR_IO_ERROR);
+ goto exit;
+ }
+ l = r; /* in case of short read */
+ cpu_physical_memory_write(addr, buf, l);
+ addr += l;
+ size -= l;
+ }
+
+exit:
+ qemu_close(fd);
+}
+
void qmp_inject_nmi(Error **errp)
{
nmi_monitor_handle(monitor_get_cpu_index(), errp);
diff --git a/qapi/misc.json b/qapi/misc.json
index 6c1c5c0a37..6eb9d29339 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -1186,6 +1186,26 @@
{ 'command': 'pmemsave',
'data': {'val': 'int', 'size': 'int', 'filename': 'str'} }
+##
+# @pmemload:
+#
+# Load a portion of guest physical memory from a file.
+#
+# @val: the physical address of the guest to start from
+#
+# @filename: the file to load the memory from as binary data
+#
+# @size: the size of memory region to load (defaults to whole file)
+#
+# @offset: the offset in the file to start from (defaults to 0)
+#
+# Returns: Nothing on success
+#
+# Since: 3.1
+##
+{ 'command': 'pmemload',
+ 'data': {'val': 'int', 'filename': 'str', '*size': 'int', '*offset': 'int'} }
+
##
# @cont:
#
--
2.19.1
- [Qemu-devel] [PATCH v7 0/7] qmp: add pmemload command, Simon Ruderich, 2018/11/15
- [Qemu-devel] [PATCH v7 3/7] cpus: use size_t in qmp_memsave/qmp_pmemsave, Simon Ruderich, 2018/11/15
- [Qemu-devel] [PATCH v7 5/7] hmp: use F for filename arguments in memsave/pmemsave, Simon Ruderich, 2018/11/15
- [Qemu-devel] [PATCH v7 2/7] cpus: convert qmp_memsave/qmp_pmemsave to use qemu_open, Simon Ruderich, 2018/11/15
- [Qemu-devel] [PATCH v7 1/7] cpus: correct coding style in qmp_memsave/qmp_pmemsave, Simon Ruderich, 2018/11/15
- [Qemu-devel] [PATCH v7 4/7] hmp: use l for size argument in memsave/pmemsave, Simon Ruderich, 2018/11/15
- [Qemu-devel] [PATCH v7 7/7] hmp: add pmemload command, Simon Ruderich, 2018/11/15
- [Qemu-devel] [PATCH v7 6/7] qmp: add pmemload command,
Simon Ruderich <=
- Re: [Qemu-devel] [PATCH v7 0/7] qmp: add pmemload command, Eric Blake, 2018/11/15