Skip to contentSkip to conversation

dump-guest-memory.py: fix python 2 support

PATCH Superseded Marc-André Lureau 4 participants 5 messages Jan 17, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dump-guest-memory.py: fix python 2 support

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").

---
 scripts/dump-guest-memory.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/dump-guest-memory.py +3 -1
index 09bec92b50..6f7e1a83b3 100644
@@ -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."""
Signature · 1 line
2.16.0.rc1.1.gef27df75a1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · 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)

OOP is awesome.

Quoted 3 lines

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

Do you want to CC stable? Commit d23bfa91b778 is part of v2.11.0.

Quoted 12 lines
---
 scripts/dump-guest-memory.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/dump-guest-memory.py +0 -0
index 09bec92b50..6f7e1a83b3 100644

scripts/dump-guest-memory.py shape and this command should mostly work.""" · line 572

Quoted 10 lines
scripts/dump-guest-memory.py +3 -1
@@ -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."""

Laszlo

#2 lore raw
Quoted 12 lines · Laszlo Ersek
Quoted 10 lines · 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)

Quoted 7 lines

OOP is awesome.

Quoted 3 lines

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

Do you want to CC stable? Commit d23bfa91b778 is part of v2.11.0.

Configure says we still support python 2.6; does this still work there?

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#3 lore raw

Hi

Quoted 16 lines · Eric Blake
Quoted 15 lines · Laszlo Ersek
Quoted 10 lines · 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)

OOP is awesome.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

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

Do you want to CC stable? Commit d23bfa91b778 is part of v2.11.0.

Configure says we still support python 2.6; does this still work there?

memoryview is not available with python 2.6.

Is the configure version check a configure-time check, or are we suppose to support that version for gdb scripts as well?

Quoted 6 lines

--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org

Signature · 1 line
Marc-André Lureau
#4 lore raw
In reply to Marc-André Lureau
Quoted 6 lines · 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)

Quoted 7 lines

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").

CC stable (commit d23bfa91b778 is part of v2.11.0., suggested by Laszlo)

Quoted 25 lines
---
 scripts/dump-guest-memory.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/dump-guest-memory.py +3 -2
index 09bec92b50..6f7e1a83b3 100644
@@ -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

Signature · 1 line
Marc-André Lureau