[Docker-maint] Bug#752662: make the -gdb.py file compatible with python3

Matthias Klose doko at debian.org
Wed Jun 25 12:06:31 UTC 2014


Package: src:golang
Version: 2:1.1.1-4
Tags: patch

please make the -gdb.py file compatible with python3. this version is supposed
to work with both python2 and python3.

-------------- next part --------------
--- runtime-gdb.py.orig	2014-06-25 13:54:12.000000000 +0200
+++ runtime-gdb.py	2014-06-25 13:55:07.000000000 +0200
@@ -16,8 +16,10 @@
 
 
 import sys, re
+if sys.version > '3':
+	long = int
 
-print >>sys.stderr, "Loading Go Runtime support."
+print("Loading Go Runtime support.", file=sys.stderr)
 
 # allow to manually reload while developing
 goobjfile = gdb.current_objfile() or gdb.objfiles()[0]
@@ -90,7 +92,7 @@
 		flags = self.val['flags']
 		inttype = self.val['hash0'].type
 		cnt = 0
-		for bucket in xrange(2 ** B):
+		for bucket in range(2 ** B):
 			bp = buckets + bucket
 			if oldbuckets:
 				oldbucket = bucket & (2 ** (B - 1) - 1)
@@ -101,7 +103,7 @@
 					bp = oldbp
 			while bp:
 				b = bp.dereference()
-				for i in xrange(8):
+				for i in range(8):
 					if b['tophash'][i] != 0:
 						k = b['keys'][i]
 						v = b['values'][i]
@@ -154,7 +156,7 @@
 			pass
 	return matcher
 
-goobjfile.pretty_printers.extend([makematcher(k) for k in vars().values() if hasattr(k, 'pattern')])
+goobjfile.pretty_printers.extend([makematcher(k) for k in list(vars().values()) if hasattr(k, 'pattern')])
 
 #
 #  For reference, this is what we're trying to do:
@@ -355,7 +357,7 @@
 			pc = ptr['sched']['pc'].cast(vp)
 			sp = ptr['sched']['sp'].cast(vp)
 			blk = gdb.block_for_pc(long((pc)))
-			print s, ptr['goid'], "%8s" % sts[long((ptr['status']))], blk.function
+			print(s, ptr['goid'], "%8s" % sts[long((ptr['status']))], blk.function)
 
 def find_goroutine(goid):
 	vp = gdb.lookup_type('void').pointer()
@@ -363,7 +365,7 @@
 		if ptr['status'] == 6:	# 'gdead'
 			continue
 		if ptr['goid'] == goid:
-			return [ptr['sched'][x].cast(vp) for x in 'pc', 'sp']
+			return [ptr['sched'][x].cast(vp) for x in ('pc', 'sp')]
 	return None, None
 
 
@@ -387,7 +389,7 @@
 		goid = gdb.parse_and_eval(goid)
 		pc, sp = find_goroutine(int(goid))
 		if not pc:
-			print "No such goroutine: ", goid
+			print("No such goroutine: ", goid)
 			return
 		save_frame = gdb.selected_frame()
 		gdb.parse_and_eval('$save_pc = $pc')
@@ -413,8 +415,8 @@
 			try:
 				#TODO fix quoting for qualified variable names
 				obj = gdb.parse_and_eval("%s" % obj)
-			except Exception, e:
-				print "Can't parse ", obj, ": ", e
+			except Exception as e:
+				print("Can't parse ", obj, ": ", e)
 				continue
 
 			if obj['data'] == 0:
@@ -423,10 +425,10 @@
 				dtype = iface_dtype(obj)
 				
 			if dtype is None:
-				print "Not an interface: ", obj.type
+				print("Not an interface: ", obj.type)
 				continue
 
-			print "%s: %s" % (obj.type, dtype)
+			print("%s: %s" % (obj.type, dtype))
 
 # TODO: print interface's methods and dynamic type's func pointers thereof.
 #rsc: "to find the number of entries in the itab's Fn field look at itab.inter->numMethods


More information about the Docker-maint mailing list