9ae3a8
From 58efb548d48964d4ff7bdcebdb97ec10e708e5ed Mon Sep 17 00:00:00 2001
9ae3a8
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
9ae3a8
Date: Wed, 13 Dec 2017 13:39:06 +0100
9ae3a8
Subject: [PATCH 35/41] scripts/dump-guest-memory.py: Improve python 3
9ae3a8
 compatibility
9ae3a8
MIME-Version: 1.0
9ae3a8
Content-Type: text/plain; charset=UTF-8
9ae3a8
Content-Transfer-Encoding: 8bit
9ae3a8
9ae3a8
RH-Author: Marc-André Lureau <marcandre.lureau@redhat.com>
9ae3a8
Message-id: <20171213133912.26176-36-marcandre.lureau@redhat.com>
9ae3a8
Patchwork-id: 78385
9ae3a8
O-Subject: [RHEL-7.5 qemu-kvm PATCH v3 35/41] scripts/dump-guest-memory.py: Improve python 3 compatibility
9ae3a8
Bugzilla: 1411490
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
9ae3a8
From: Janosch Frank <frankja@linux.vnet.ibm.com>
9ae3a8
9ae3a8
This commit does not make the script python 3 compatible, it is a
9ae3a8
preparation that fixes the easy and common incompatibilities.
9ae3a8
9ae3a8
Print is a function in python 3 and therefore needs braces around its
9ae3a8
arguments.
9ae3a8
9ae3a8
Range does not cast a gdb.Value object to int in python 3, we have to
9ae3a8
do it ourselves.
9ae3a8
9ae3a8
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Signed-off-by: Janosch Frank <frankja@linux.vnet.ibm.com>
9ae3a8
Message-Id: <1453464520-3882-4-git-send-email-frankja@linux.vnet.ibm.com>
9ae3a8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
9ae3a8
(cherry picked from commit 7cb1089d5fbd7b2d9497f111ce948edef41df32d)
9ae3a8
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 scripts/dump-guest-memory.py | 26 +++++++++++++++-----------
9ae3a8
 1 file changed, 15 insertions(+), 11 deletions(-)
9ae3a8
9ae3a8
diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py
9ae3a8
index 7d93d86..d44de99 100644
9ae3a8
--- a/scripts/dump-guest-memory.py
9ae3a8
+++ b/scripts/dump-guest-memory.py
9ae3a8
@@ -98,15 +98,19 @@ def memory_region_get_ram_ptr(mr):
9ae3a8
 
9ae3a8
 def get_guest_phys_blocks():
9ae3a8
     guest_phys_blocks = []
9ae3a8
-    print "guest RAM blocks:"
9ae3a8
-    print ("target_start     target_end       host_addr        message "
9ae3a8
-           "count")
9ae3a8
-    print ("---------------- ---------------- ---------------- ------- "
9ae3a8
-           "-----")
9ae3a8
+    print("guest RAM blocks:")
9ae3a8
+    print("target_start     target_end       host_addr        message "
9ae3a8
+          "count")
9ae3a8
+    print("---------------- ---------------- ---------------- ------- "
9ae3a8
+          "-----")
9ae3a8
 
9ae3a8
     current_map_p = gdb.parse_and_eval("address_space_memory.current_map")
9ae3a8
     current_map = current_map_p.dereference()
9ae3a8
-    for cur in range(current_map["nr"]):
9ae3a8
+
9ae3a8
+    # Conversion to int is needed for python 3
9ae3a8
+    # compatibility. Otherwise range doesn't cast the value itself and
9ae3a8
+    # breaks.
9ae3a8
+    for cur in range(int(current_map["nr"])):
9ae3a8
         flat_range   = (current_map["ranges"] + cur).dereference()
9ae3a8
         mr           = flat_range["mr"].dereference()
9ae3a8
 
9ae3a8
@@ -149,9 +153,9 @@ def get_guest_phys_blocks():
9ae3a8
             predecessor["target_end"] = target_end
9ae3a8
             message = "joined"
9ae3a8
 
9ae3a8
-        print ("%016x %016x %016x %-7s %5u" %
9ae3a8
-               (target_start, target_end, host_addr.cast(UINTPTR_T),
9ae3a8
-                message, len(guest_phys_blocks)))
9ae3a8
+        print("%016x %016x %016x %-7s %5u" %
9ae3a8
+              (target_start, target_end, host_addr.cast(UINTPTR_T),
9ae3a8
+               message, len(guest_phys_blocks)))
9ae3a8
 
9ae3a8
     return guest_phys_blocks
9ae3a8
 
9ae3a8
@@ -311,8 +315,8 @@ shape and this command should mostly work."""
9ae3a8
         for block in self.guest_phys_blocks:
9ae3a8
             cur  = block["host_addr"]
9ae3a8
             left = block["target_end"] - block["target_start"]
9ae3a8
-            print ("dumping range at %016x for length %016x" %
9ae3a8
-                   (cur.cast(UINTPTR_T), left))
9ae3a8
+            print("dumping range at %016x for length %016x" %
9ae3a8
+                  (cur.cast(UINTPTR_T), left))
9ae3a8
             while (left > 0):
9ae3a8
                 chunk_size = min(TARGET_PAGE_SIZE, left)
9ae3a8
                 chunk = qemu_core.read_memory(cur, chunk_size)
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8