[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC 3/5] scripts/dump-guest-memory.py: Improve python
From: |
Janosch Frank |
Subject: |
Re: [Qemu-devel] [RFC 3/5] scripts/dump-guest-memory.py: Improve python 3 compatibility |
Date: |
Fri, 15 Jan 2016 11:05:02 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 |
On 01/14/2016 05:03 PM, Laszlo Ersek wrote:
> On 01/14/16 09:48, Janosch Frank wrote:
>> This commit does not make the script python 3 compatible, it is a
>> preparation that fixes the easy and common incompatibilities.
>>
>> Print is a function in python 3 and therefore needs braces around its
>> arguments.
>>
>> Range does not cast a gdb.Value object to int in python 3, we have to
>> do it ourselves.
>>
>> Signed-off-by: Janosch Frank <address@hidden>
>> ---
>> scripts/dump-guest-memory.py | 22 +++++++++++-----------
>> 1 file changed, 11 insertions(+), 11 deletions(-)
>>
>> diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py
>> index 76a6ecb..fe93135 100644
>> --- a/scripts/dump-guest-memory.py
>> +++ b/scripts/dump-guest-memory.py
>> @@ -98,15 +98,15 @@ def memory_region_get_ram_ptr(mr):
>>
>> def get_guest_phys_blocks():
>> guest_phys_blocks = []
>> - print "guest RAM blocks:"
>> - print ("target_start target_end host_addr message "
>> - "count")
>> - print ("---------------- ---------------- ---------------- ------- "
>> - "-----")
>> + print("guest RAM blocks:")
>> + print("target_start target_end host_addr message "
>> + "count")
>> + print("---------------- ---------------- ---------------- ------- "
>> + "-----")
>>
>> current_map_p = gdb.parse_and_eval("address_space_memory.current_map")
>> current_map = current_map_p.dereference()
>> - for cur in range(current_map["nr"]):
>> + for cur in range(int(current_map["nr"])):
>
> FlatView.nr has type "unsigned" in C -- is this int cast safe in python?
> (I don't expect a >= 2G value in "nr", but still.)
>From the python point of view it shouldn't matter, short int is at least
32bit, long is arbitrary sized:
The function int() will return a short or a long int depending on
the argument value.
pep-0237
But I do not have enough cpython knowledge to validate what gdb does in
gdb/python/py-value.c as the value is a gdb.Value that gets cast to
integer or long.
>
> Thanks
> Laszlo
>
>> flat_range = (current_map["ranges"] + cur).dereference()
>> mr = flat_range["mr"].dereference()
>>
>> @@ -149,9 +149,9 @@ def get_guest_phys_blocks():
>> predecessor["target_end"] = target_end
>> message = "joined"
>>
>> - print ("%016x %016x %016x %-7s %5u" %
>> - (target_start, target_end, host_addr.cast(UINTPTR_T),
>> - message, len(guest_phys_blocks)))
>> + print("%016x %016x %016x %-7s %5u" %
>> + (target_start, target_end, host_addr.cast(UINTPTR_T),
>> + message, len(guest_phys_blocks)))
>>
>> return guest_phys_blocks
>>
>> @@ -311,8 +311,8 @@ shape and this command should mostly work."""
>> for block in self.guest_phys_blocks:
>> cur = block["host_addr"]
>> left = block["target_end"] - block["target_start"]
>> - print ("dumping range at %016x for length %016x" %
>> - (cur.cast(UINTPTR_T), left))
>> + print("dumping range at %016x for length %016x" %
>> + (cur.cast(UINTPTR_T), left))
>> while (left > 0):
>> chunk_size = min(TARGET_PAGE_SIZE, left)
>> chunk = qemu_core.read_memory(cur, chunk_size)
>>
>
- [Qemu-devel] [RFC 0/5] scripts/dump-guest-memory.py: Add multi-arch support, Janosch Frank, 2016/01/14
- [Qemu-devel] [RFC 4/5] scripts/dump-guest-memory.py: Cleanup functions, Janosch Frank, 2016/01/14
- [Qemu-devel] [RFC 3/5] scripts/dump-guest-memory.py: Improve python 3 compatibility, Janosch Frank, 2016/01/14
- [Qemu-devel] [RFC 2/5] scripts/dump-guest-memory.py: Make methods functions, Janosch Frank, 2016/01/14
- [Qemu-devel] [RFC 5/5] scripts/dump-guest-memory.py: Introduce multi-arch support, Janosch Frank, 2016/01/14
- [Qemu-devel] [RFC 1/5] scripts/dump-guest-memory.py: Move constants to the top, Janosch Frank, 2016/01/14
- Re: [Qemu-devel] [RFC 0/5] scripts/dump-guest-memory.py: Add multi-arch support, Laszlo Ersek, 2016/01/14