[Qemu-devel] [PULL 1/1] dump-guest-memory.py: fix python 2 support

2018-01-20 Thread Marc-André Lureau
Python GDB support may use Python 2 or 3.

Inferior.read_memory() may return a 'buffer' with Python 2 or a
'memoryview' with Python 3 (see also
https://sourceware.org/gdb/onlinedocs/gdb/Inferiors-In-Python.html)

The elf.add_vmcoreinfo_note() method expects a "bytes" object. Wrap
the returned memory with bytes(), which works with both 'memoryview'
and 'buffer'.

Fixes a regression introduced with commit
d23bfa91b7789534d16ede6cb7d925bfac3f3c4c ("add vmcoreinfo").

Suggested-by: Peter Maydell 
Signed-off-by: Marc-André Lureau 
Acked-by: Laszlo Ersek 
Reviewed-by: Eric Blake 
---
 scripts/dump-guest-memory.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py
index 09bec92b50..03fbf69f8a 100644
--- a/scripts/dump-guest-memory.py
+++ b/scripts/dump-guest-memory.py
@@ -564,7 +564,7 @@ shape and this command should mostly work."""
 
 vmcoreinfo = self.phys_memory_read(addr, size)
 if vmcoreinfo:
-self.elf.add_vmcoreinfo_note(vmcoreinfo.tobytes())
+self.elf.add_vmcoreinfo_note(bytes(vmcoreinfo))
 
 def invoke(self, args, from_tty):
 """Handles command invocation from gdb."""
-- 
2.16.0.rc1.1.gef27df75a1




[Qemu-devel] [PULL 1/1] dump-guest-memory.py: fix python 2 support

2018-01-17 Thread Marc-André Lureau
Python GDB support may use Python 2 or 3.

Inferior.read_memory() may return a buffer with Python 2 or a
memoryview with Python 3 (see also
https://sourceware.org/gdb/onlinedocs/gdb/Inferiors-In-Python.html)

The elf.add_vmcoreinfo_note() method expect a byte string, but Python 2
buffer doesn't provide the tobyes() method. Wrap the read_memory()
result to a memoryview, available in Python 2.7. (if the return object
is already a memoryview, this adds a useless identity view on top)

Fixes a regression introduced with commit
d23bfa91b7789534d16ede6cb7d925bfac3f3c4c ("add vmcoreinfo").

Signed-off-by: Marc-André Lureau 
Reviewed-by: Laszlo Ersek 
---
 scripts/dump-guest-memory.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py
index 09bec92b50..6f7e1a83b3 100644
--- a/scripts/dump-guest-memory.py
+++ b/scripts/dump-guest-memory.py
@@ -564,7 +564,9 @@ shape and this command should mostly work."""
 
 vmcoreinfo = self.phys_memory_read(addr, size)
 if vmcoreinfo:
-self.elf.add_vmcoreinfo_note(vmcoreinfo.tobytes())
+# Python 2.7 returns a buffer
+vmciview = memoryview(vmcoreinfo)
+self.elf.add_vmcoreinfo_note(vmciview.tobytes())
 
 def invoke(self, args, from_tty):
 """Handles command invocation from gdb."""
-- 
2.16.0.rc1.1.gef27df75a1