Skip to content

Instantly share code, notes, and snippets.

@syohex
Last active December 26, 2015 20:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save syohex/7207967 to your computer and use it in GitHub Desktop.
Save syohex/7207967 to your computer and use it in GitHub Desktop.
Support python3 for runtime-gdb.py
diff --git a/runtime-gdb.py b/runtime-gdb.py
index cb70ca0..ac940c3 100644
--- a/runtime-gdb.py
+++ b/runtime-gdb.py
@@ -17,7 +17,7 @@ path to this file based on the path to the runtime package.
import sys, re
-print >>sys.stderr, "Loading Go Runtime support."
+sys.stderr.write("Loading Go Runtime support.\n")
# allow to manually reload while developing
goobjfile = gdb.current_objfile() or gdb.objfiles()[0]
@@ -355,7 +355,7 @@ class GoroutinesCmd(gdb.Command):
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'], "{0:8s}".format(sts[long((ptr['status']))]), blk.function)
def find_goroutine(goid):
vp = gdb.lookup_type('void').pointer()
@@ -363,7 +363,7 @@ def find_goroutine(goid):
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 +387,7 @@ class GoroutineCmd(gdb.Command):
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 +413,8 @@ class GoIfaceCmd(gdb.Command):
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 +423,10 @@ class GoIfaceCmd(gdb.Command):
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("{0}: {1}".format(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
@@ -436,6 +436,7 @@ class GoIfaceCmd(gdb.Command):
#
# Register all convenience functions and CLI commands
#
-for k in vars().values():
+var_dict = vars().copy()
+for k in var_dict.values():
if hasattr(k, 'invoke'):
k()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment