Skip to contentSkip to conversation

Handle gdb.MemoryError exception in dump-guest-memory.py

PATCH Superseded Kevin Buettner 2 participants 2 messages Feb 14, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Handle gdb.MemoryError exception in dump-guest-memory.py

I recently investigated a bug in which the dump-guest-memory.py script sees a gdb.MemoryError exception while attempting to dump memory obtained from a QEMU core dump. (And, yes, dump-guest-core=on was specified in the -machine option of the QEMU invocation.)

It turns out that memory region in question is not being placed in the core dump and, after stepping through the kernel core dumping code responsible for making this decision, it looks reasonable to me to not include that region in the core dump. The region in question consists of all zeros and, according to the kernel's logic, has never been written to.

This commit makes a small change to the dump-guest-memory script to cause inaccessible memory to be dumped as zeroes. This avoids the exception and places the correct values in the guest memory dump.

---
 scripts/dump-guest-memory.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
scripts/dump-guest-memory.py +6 -1
index 4177261d33..fbdfba458b 100644
@@ -539,7 +539,12 @@ shape and this command should mostly work."""
 
             while left > 0:
                 chunk_size = min(TARGET_PAGE_SIZE, left)
-                chunk = qemu_core.read_memory(cur, chunk_size)
+                try:
+                    chunk = qemu_core.read_memory(cur, chunk_size)
+                except gdb.MemoryError:
+                    # Consider blocks of memory absent from a core file
+                    # as being zeroed.
+                    chunk = bytes(chunk_size)
                 vmcore.write(chunk)
                 cur += chunk_size
                 left -= chunk_size
Signature · 1 line
2.24.1
#1 lore raw
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Subject: [PATCH] Handle gdb.MemoryError exception in dump-guest-memory.py
Message-id: [email protected]
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
b41300a Handle gdb.MemoryError exception in dump-guest-memory.py

=== OUTPUT BEGIN ===
ERROR: Missing Signed-off-by: line(s)

total: 1 errors, 0 warnings, 13 lines checked

Commit b41300af0818 (Handle gdb.MemoryError exception in dump-guest-memory.py) has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]