From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLsPh-0001nw-3m for qemu-devel@nongnu.org; Wed, 20 Jan 2016 08:03:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLsPc-0007Da-76 for qemu-devel@nongnu.org; Wed, 20 Jan 2016 08:03:05 -0500 Received: from e06smtp16.uk.ibm.com ([195.75.94.112]:50324) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLsPb-0007CN-U4 for qemu-devel@nongnu.org; Wed, 20 Jan 2016 08:03:00 -0500 Received: from localhost by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 20 Jan 2016 13:02:56 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 115D22190067 for ; Wed, 20 Jan 2016 13:02:41 +0000 (GMT) Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u0KD2ro163111310 for ; Wed, 20 Jan 2016 13:02:53 GMT Received: from d06av05.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u0KD2qAI015111 for ; Wed, 20 Jan 2016 06:02:52 -0700 References: <1452761307-57200-1-git-send-email-frankja@linux.vnet.ibm.com> <1452761307-57200-4-git-send-email-frankja@linux.vnet.ibm.com> <569F6D19.4040406@redhat.com> From: Janosch Frank Message-ID: <569F857C.2040901@linux.vnet.ibm.com> Date: Wed, 20 Jan 2016 14:02:52 +0100 MIME-Version: 1.0 In-Reply-To: <569F6D19.4040406@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC 3/5] scripts/dump-guest-memory.py: Improve python 3 compatibility List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Cc: frankja@linux.vnet.ibm.com, lersek@redhat.com On 01/20/2016 12:18 PM, Paolo Bonzini wrote: > > > On 14/01/2016 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. > > Would it make sense to make kvm_stat Py3-compatible too? Well, if you don't enforce it for any patches afterwards it might get broken and therefore unnecessary. But I do not expect a huge number of patches for those small scripts. For compatibility we need to (quick check and test): fix all prints exchange dict.iteritems() with dict.items(). decode the regex to utf-8 I'll add a patch for it into my next patch series for kvm_stat if you want. I still need to add functionality and documentation to it. Initially I did not chose to make dump guest memory compatible to both versions. As my gdb was compiled with py 3, I decided to fix it until it worked. Surprisingly it then was also py 2 compatible. > > Paolo > >> Signed-off-by: Janosch Frank >> --- >> 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"])): >> 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) >> >