* [Qemu-devel] [PATCH] dump-guest-memory.py: fix python 2 support
@ 2018-01-17 11:44 Marc-André Lureau
2018-01-17 14:18 ` Laszlo Ersek
2018-01-17 14:46 ` Marc-André Lureau
0 siblings, 2 replies; 5+ messages in thread
From: Marc-André Lureau @ 2018-01-17 11:44 UTC (permalink / raw)
To: qemu-devel; +Cc: lersek, Marc-André Lureau, Eduardo Habkost, Cleber Rosa
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 <marcandre.lureau@redhat.com>
---
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] dump-guest-memory.py: fix python 2 support
2018-01-17 11:44 [Qemu-devel] [PATCH] dump-guest-memory.py: fix python 2 support Marc-André Lureau
@ 2018-01-17 14:18 ` Laszlo Ersek
2018-01-17 14:59 ` Eric Blake
2018-01-17 14:46 ` Marc-André Lureau
1 sibling, 1 reply; 5+ messages in thread
From: Laszlo Ersek @ 2018-01-17 14:18 UTC (permalink / raw)
To: Marc-André Lureau, qemu-devel; +Cc: Eduardo Habkost, Cleber Rosa
On 01/17/18 12:44, Marc-André Lureau wrote:
> 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.
>
> Fixes a regression introduced with commit
> d23bfa91b7789534d16ede6cb7d925bfac3f3c4c ("add vmcoreinfo").
Do you want to CC stable? Commit d23bfa91b778 is part of v2.11.0.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> 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."""
>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Laszlo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] dump-guest-memory.py: fix python 2 support
2018-01-17 11:44 [Qemu-devel] [PATCH] dump-guest-memory.py: fix python 2 support Marc-André Lureau
2018-01-17 14:18 ` Laszlo Ersek
@ 2018-01-17 14:46 ` Marc-André Lureau
1 sibling, 0 replies; 5+ messages in thread
From: Marc-André Lureau @ 2018-01-17 14:46 UTC (permalink / raw)
To: QEMU, qemu-stable
Cc: Marc-André Lureau, Laszlo Ersek, Eduardo Habkost,
Cleber Rosa
On Wed, Jan 17, 2018 at 12:44 PM, Marc-André Lureau
<marcandre.lureau@redhat.com> wrote:
> 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").
CC stable (commit d23bfa91b778 is part of v2.11.0., suggested by Laszlo)
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> 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
>
>
--
Marc-André Lureau
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] dump-guest-memory.py: fix python 2 support
2018-01-17 14:18 ` Laszlo Ersek
@ 2018-01-17 14:59 ` Eric Blake
2018-01-17 15:36 ` Marc-André Lureau
0 siblings, 1 reply; 5+ messages in thread
From: Eric Blake @ 2018-01-17 14:59 UTC (permalink / raw)
To: Laszlo Ersek, Marc-André Lureau, qemu-devel
Cc: Eduardo Habkost, Cleber Rosa
[-- Attachment #1: Type: text/plain, Size: 1039 bytes --]
On 01/17/2018 08:18 AM, Laszlo Ersek wrote:
> On 01/17/18 12:44, Marc-André Lureau wrote:
>> 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.
>
>>
>> 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?
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] dump-guest-memory.py: fix python 2 support
2018-01-17 14:59 ` Eric Blake
@ 2018-01-17 15:36 ` Marc-André Lureau
0 siblings, 0 replies; 5+ messages in thread
From: Marc-André Lureau @ 2018-01-17 15:36 UTC (permalink / raw)
To: Eric Blake; +Cc: Laszlo Ersek, QEMU, Eduardo Habkost, Cleber Rosa
Hi
On Wed, Jan 17, 2018 at 3:59 PM, Eric Blake <eblake@redhat.com> wrote:
> On 01/17/2018 08:18 AM, Laszlo Ersek wrote:
>> On 01/17/18 12:44, Marc-André Lureau wrote:
>>> 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.
>>
>>>
>>> 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?
>
> --
> Eric Blake, Principal Software Engineer
> Red Hat, Inc. +1-919-301-3266
> Virtualization: qemu.org | libvirt.org
>
--
Marc-André Lureau
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-01-17 15:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-17 11:44 [Qemu-devel] [PATCH] dump-guest-memory.py: fix python 2 support Marc-André Lureau
2018-01-17 14:18 ` Laszlo Ersek
2018-01-17 14:59 ` Eric Blake
2018-01-17 15:36 ` Marc-André Lureau
2018-01-17 14:46 ` Marc-André Lureau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).